Gdb assembly language instruction add

I need to understand the add instruction in assembly code:

=> 0x08048bff <+43>:    add    0x14(%esp,%ebx,4),%eax
(gdb) i r
eax            0x1      1
ecx            0x0      0
edx            0x0      0
ebx            0x1      1
esp            0xffffcd70       0xffffcd70
ebp            0xffffcdc8       0xffffcdc8
esi            0x0      0
edi            0x0      0
eip            0x8048bff        0x8048bff <phase_2+43>
eflags         0x202    [ IF ]
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x63     99

I think the answer for 0x14(%esp,%ebx,4) is (%ebx*4)+%esp+0x14 but what I got was 0xffffcd82 and I don't know what address that is from the registers. Can someone explain to be what value I'm supposed to put in %eax?


Yes, you are right that 0x14(%esp,%ebx,4) is at&t syntax for (%ebx*4)+%esp+0x14. As such, the address is 0xffffcd88. You can have gdb calculate that for you using p/x $ebx*4+$esp+0x14. The add instruction will fetch the 4 byte integer in memory at that address and add it to whatever is already in %eax. You can check the memory contents in gdb using for example x/d 0xffffcd88.

PS: you can switch gdb to use intel syntax which should be easier to read using set disassembly-flavor intel.

Need Your Help

Learning Pascal FC

pascal pascal-fc

I'm looking for tutorials and examples on Pascal FC's channels and rendesvouz mechanisms.

XML Module Parsing Differences Between 2.7.6 and 2.7.3 in Python

python xml python-2.7

I am using this this tutorial to go through some concepts of Python, however, I ran into this problem trying to use this line of a code in 2.76. Dave is using 2.73 at the 53 minute part of the vide...