View Full Version : Help with assembly code

09-29-2014, 09:40 PM
Consider the following code

0x080493c4 <+0>: sub $0x2c,%esp
0x080493c7 <+3>: mov 0x34(%esp),%eax
0x080493cb <+7>: lea 0x14(%eax),%edx
0x080493ce <+10>: mov %edx,0x1c(%esp)
0x080493d2 <+14>: lea 0x10(%eax),%edx
0x080493d5 <+17>: mov %edx,0x18(%esp)
0x080493d9 <+21>: lea 0xc(%eax),%edx
0x080493dc <+24>: mov %edx,0x14(%esp)
0x080493e0 <+28>: lea 0x8(%eax),%edx
0x080493e3 <+31>: mov %edx,0x10(%esp)
0x080493e7 <+35>: lea 0x4(%eax),%edx
0x080493ea <+38>: mov %edx,0xc(%esp)
0x080493ee <+42>: mov %eax,0x8(%esp)
0x080493f2 <+46>: movl $0x804a681,0x4(%esp)
0x080493fa <+54>: mov 0x30(%esp),%eax
0x080493fe <+58>: mov %eax,(%esp)
0x08049401 <+61>: call 0x80488d0 <__isoc99_sscanf@plt>
0x08049406 <+66>: cmp $0x5,%eax
0x08049409 <+69>: jg 0x8049410 <read_six_numbers+76>
0x0804940b <+71>: call 0x8049385 <explode_bomb>
0x08049410 <+76>: add $0x2c,%esp
0x08049413 <+79>: ret

The function is called read_six_numbers

I get what most of it is doing, but my question is what is the 0xYY doing?

For example in the line

mov 0x34(%esp),%eax

what is the 0x34 doing to %esp?

I am an assembly noob

09-30-2014, 01:18 AM
That's an example of the base-plus-offset addressing mode (https://en.wikipedia.org/wiki/Addressing_mode#Base_plus_offset.2C_and_variations ). In that case, %esp is the base and 0x34 is the offset, so the value at address [%esp + 0x36] will be loaded and stored into %eax.