Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 0x4 do in "movl $0x2d, 0x4(%esp)"?

I am looking into assembly code generated by GCC. But I don't understand:

movl $0x2d, 0x4(%esp)

In the second operand, what does 0x4 stands for? offset address? And what the use of register EAX?

like image 733
martin Avatar asked Mar 05 '10 12:03

martin


1 Answers

movl $0x2d, 0x4(%esp) means to take the current value of the stack pointer (%esp), add 4 (0x4) then store the long (32-bit) value 0x2d into that location.

The eax register is one of the general purpose 32-bit registers. x86 architecture specifies the following 32-bit registers:

eax  Accumulator Register
ebx  Base Register
ecx  Counter Register
edx  Data Register
esi  Source Index
edi  Destination Index
ebp  Base Pointer
esp  Stack Pointer

and the names and purposes of some of then harken back to the days of the Intel 8080.

This page gives a good overview on the Intel-type registers. The first four of those in the above list can also be accessed as a 16-bit or two 8-bit values as well. For example:

3322222222221111111111
10987654321098765432109876543210
<-             eax            ->
                <-     ax     ->
                <- ah -><- al ->

The pointer and index registers do not allow use of 8-bit parts but you can have, for example, the 16-bit bp.

like image 79
paxdiablo Avatar answered Oct 08 '22 05:10

paxdiablo