Reputation: 25
I tried to debug an assembly code (using GDB), but it behave really weird. I think this high level language of this code is an if statement right? when the content of eax equal to rbx, it will jump to the stated address, otherwise it will execute the statement below it here's the code:
0x000000000040108b <+25>: lea 0x4(%rsp),%rbx
0x0000000000401090 <+30>: mov $0x1,%ebp
0x0000000000401095 <+35>: mov %ebp,%eax
0x0000000000401097 <+37>: add -0x4(%rbx),%eax
0x000000000040109a <+40>: cmp %eax,(%rbx)
=> 0x000000000040109c <+42>: je 0x4010a3 <phase_2+49>
from my understanding, when %eax is equal to %rbx, the statement je shall jump the code to the address 0x4010a3 right? However, when I try to see the content of both register using:
print/c $eax
print/c $rbx
both registers' content are 116. However, instead of jumping to 0x4010a3, it just execute the statement below the je statement. am I doing something wrong? Additionally, I just wonder, what the different between:
cmp %eax, %rbx
and
cmp $eax, (%rbx)
thx
Upvotes: 0
Views: 188
Reputation: 92201
CMP %eax, (%rbx)
compares the value in EAX to the value pointed to by RBX. Similar to if (x == *y)
.
Comparing EAX to RBX is not even possible, as they are of different size (32 vs 64 bits).
Upvotes: 2