3
leal(%eax,%ecx,4), %edx

as I was reading from my computer systems book, if there`s premises that $eax contains x value and %ecx contains y, then the above means, x+4y putting into %edx.

then if it is

movl(%eax,%ecx,4), %edx

, then isn`t the same one with leal expression above?

As I know, leal creates address that can be referenced,not referencing by itself like movl, but

when I saw leal(%eax,%ecx,4), %edx equals putting x+4y into edx register, then doesnt it mean that it 'referenced'%eaxand%ecx` and extracted value x and y for using computation??

  • doesn`t it "()" means 'referenced'??
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Swen
  • 79
  • 2
  • 3
  • 8
  • then can I ask you something? what if %eax has integer value that is not address? then if it is leal, the error occurs? although it doesn`t matter for movl? – Swen Nov 27 '12 at 08:31
  • `leal` doesn't know if it is an address or not, it just computes a value. `movl`, on the other hand, will try to read a value from the address, and will notice if it is not valid (inaccessible). – Bo Persson Nov 27 '12 at 09:01

1 Answers1

14

LEA loads an effective address generated by an address calculation into a register. MOV moves something somewhere, when using SIB addressing as source operand, it moves whatever is at the address generated by the address calculation into the target operand.

So:

leal (%eax,%ecx,4), %edx  ←  moves %eax+%ecx*4 into %edx
movl (%eax,%ecx,4), %edx  ←  moves whatever is at address %eax+%ecx*4 into %edx
ninjalj
  • 42,493
  • 9
  • 106
  • 148