Those are memory operands.
add -0x8(%esi,%ebx,4),%eax
Adds the value stored at address esi + ebx*4 - 8
to eax
.
cmp %eax,-0x4(%esi,%ebx,4)
Compares the value stored at address esi + ebx*4 - 4
with eax
.
Question
I am working on an assignment that requires debugging AT&T assembly. I am having trouble with the following two lines, and just wanted to ask for a little clarification.
add -0x8(%esi,%ebx,4),%eax
cmp %eax,-0x4(%esi,%ebx,4)
I know that %esi
holds the value input by the user, and both %eax
and %ebx
are equal to 2.
For the first line, I am interpreting this as "-8 + %esi + (%ebx*4) + %eax
". Since I know %ebx
is 2, this evaluates to %esi + %eax
. So essentially, the add line just adds 2 to the input value.
The second line I know is comparing %eax
to -0x4(%esi,%ebx,4)
. At this point %eax
equals %esi + 2
, and following the previous logic the right side value equals -4 + %esi + (%ebx*4)
which would evaluate to %esi + 4
since %ebx
is still equal to 2.
If I am correct, the that means the second line is comparing %esi + 2
to %esi + 4
which can never be true for any input value. Yet, it has to be true as per the assignment. Where am I going wrong in my translation?
Solution
Those are memory operands.
add -0x8(%esi,%ebx,4),%eax
Adds the value stored at address esi + ebx*4 - 8
to eax
.
cmp %eax,-0x4(%esi,%ebx,4)
Compares the value stored at address esi + ebx*4 - 4
with eax
.