Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is register %eiz?

In the following assembly code that I dumped out using objdump:

lea    0x0(%esi,%eiz,1),%esi 

What is register %eiz? What does the preceding code mean?

like image 339
Summer_More_More_Tea Avatar asked Mar 31 '10 13:03

Summer_More_More_Tea


People also ask

What does load effective address do?

Load Effective Address calculates its src operand in the same way as the mov instruction does, but rather than loading the contents of that address into the dest operand, it loads the address itself.

What does the LEA instruction write into a register?

The lea instruction places the address specified by its first operand into the register specified by its second operand. Note, the contents of the memory location are not loaded, only the effective address is computed and placed into the register.

What is Lea used for in assembly language?

The lea (load effective address) instruction is used to put a memory address into the destination.

What is the equivalent assembler directive for the instruction Lea?

So e.g. lea eax,[eax*3] would translate to equivalent of lea eax,[eax+eax*2] .


2 Answers

See Why Does GCC LEA EIZ?:

Apparently %eiz is a pseudo-register that just evaluates to zero at all times (like r0 on MIPS).

...

I eventually found a mailing list post by binutils guru Ian Lance Taylor that reveals the answer. Sometimes GCC inserts NOP instructions into the code stream to ensure proper alignment and stuff like that. The NOP instruction takes one byte, so you would think that you could just add as many as needed. But according to Ian Lance Taylor, it’s faster for the chip to execute one long instruction than many short instructions. So rather than inserting seven NOP instructions, they instead use one bizarro LEA, which uses up seven bytes and is semantically equivalent to a NOP.

like image 142
Sinan Ünür Avatar answered Oct 07 '22 11:10

Sinan Ünür


(Very late to the game, but this seemed like an interesting addition): It's not a register at all, it's a quirk of the Intel instruction encoding. When using a ModRM byte to load from memory, there are 3 bits used for the register field to store 8 possible registers. But the spot where ESP (the stack pointer) "would" be is instead interpreted by the processor as "a SIB byte follows this instruction" (i.e. it's an extended addressing mode, not a reference to ESP). For reasons known only to the authors, the GNU assembler has always represented this "zero where a register would otherwise be" as a "%eiz" register. The Intel syntax just drops it.

like image 24
Andy Ross Avatar answered Oct 07 '22 11:10

Andy Ross