0

We're just starting out with asm and I'm trying to make sense of my lecturer's code:

movl (%esp), %ebx
leal (%esp), %ecx

I don't see how these two instructions are different except for the register they operate on.

This first one moves the address pointed by the Stack Pointer into register BX.

The second one loads effective address pointed by Stack Pointer into register CX.

If I got it right, is there any point in using two different asm instructions, or was the lecturer just trying to show it did the same thing?

nrz
  • 10,435
  • 4
  • 39
  • 71
Juicy
  • 11,840
  • 35
  • 123
  • 212
  • 1
    This is a bad example of how to use lea/mov, that's why you're confused. – SoapBox Nov 17 '13 at 15:09
  • 1
    @Soapbox: agreed. Also, first description is wrong or at least that's the way I read it: it loads the content at the address pointed to by %esp, not the address. – gnometorule Nov 17 '13 at 16:20

1 Answers1

1

They are not similar.

mov ebx, (esp)
lea ecx, (esp)

(in regular assembler, not gas style). The first loads ebx with the contents of esp. The second loads ecx with esp itself. The similar "regular" expression would have been

mov ecx, esp

but using lea you can immediately add a constant, a register, or both to ecx. E.g.,

lea ecx, (esp+4*eax+10h)

sets ecx to esp + 4*eax + 10h -- using 'mov', you would have to add these with more instructions.

Jongware
  • 22,200
  • 8
  • 54
  • 100