Home > Enterprise >  x86 asm: How to set a reg to a non-SIB supported offset?
x86 asm: How to set a reg to a non-SIB supported offset?

Time:12-02

I have an array a of 24 byte structs, arranged without padding so that struct 1 begins 24 bytes after struct 0 ((void*) &a[1] == ((void*) &a[0]) 24.

rbx holds the index of the struct. I'd like to set rdi to a rbx*24 and rsi to a rbx*24 8. SIB does not allow multiplying by 24. How should I do this?

(x86, 64 bits, assembly).

CodePudding user response:

You can set RDI and RSI without even changing the index in RBX.

lea  rsi, [rbx   rbx*2]    ; RSI = RBX * 3
lea  rdi, [a   rsi*8]      ; RDI = a   (RBX * 3) * 8
lea  rsi, [rdi   8]        ; RSI = a   (RBX * 3) * 8   8

What's the purpose of the LEA instruction?

  • Related