0

Hi, I am taking an Intro to Computer Science course. I have to translate a code to assembly. I was wondering if someone could help me out with the first line of the code. I am not sure what to do since it it ==.

if (x==y) {

thanks!

4
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by Duoas
0

cmp(x,y);//compare x and y
je jmpWhereverYouWant;//je means jump if equal meaning if x and y are equal,if not equal then
//itll skip the second line and go on to the third line(whatever it is usually the else part.

0

ithelp
Cheating never helps anyone learn anything. That, and the code output by the GCC won't be as obvious to read as just doing it right to begin with.

eyehategod
You've got the right idea. Just be careful which jump condition you use. All you need to do now is get x and y into registers.

;somehow set ax = x
;somehow set bx = y
cmp ax, bx
jne somewhere_else
  ;do stuff here if ax==bx
somewhere_else:  ;all done

(Yeah! I got assembly highlighting!)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.