Build IA32: lea instruction

I know that the suggestion I'm going to say is probably the best way to become very unpopular in StackOverflow very quickly. Anyway, Iโ€™ll say: why doesnโ€™t it work (completely)?

I tried to figure out what the lea / leal instruction does . As I understand it, lea / leal detects the memory address of the first operand and writes this address to the second operand (which may be a register or so).

This part seems to work. When I run the program below, it says:

The memory address of var is 134518204.

However, right after that, he says something like "memory access error." pushl (% eax) is clearly not working. Why not?

.data
    var:    .long 42
    str1:   .string "The memory address of var is %d.\n"
    str2:   .string "At this memory address we find var value: %d.\n"

.text
.global main
main: 
    leal var, %eax          # Copy the address of var into %eax
    pushl %eax
    pushl $str1
    call printf             # Print str1
    pushl (%eax)
    pushl $str2
    call printf             # Print str2

    # Some stack cleaning should be here :)

    movl $1, %eax
    int $0x80

I'm not even sure that I am right what lea / leal does. Help is appreciated .;)

+4
2

, lea/leal ( ).

. ; , , .


pushl (%eax) . ?

push , , , : printf , %eax, %eax var.

+2

lea (ab) : , , movl $var, %eax ( ), lea.

, , lea .

+2

All Articles