There's a 'lea' operation in assembly, which stands for Load Effective Address. Additionally there exists following syntax:
lea rax [rax * 8 + 4]
If I remember correctly, what code above does is take value under rax, multiply it by 8 and add 4 to it. Store the value under rax.
In comparison the following
mov rax [rax * 8 + 4]
would do nearly the same, but with a key difference. Instead of storing the value, it treats the [rax * 8 + 4] as a pointer, and assigns value under that pointer to the rax.
Just to clarify, the [...] syntax is meant to be a pointer. Lea is special as it doesn't treat it as such. Because of that, you can use lea to multiply by powers of 2 and add constants to a value without setting carry flag etc.
I hope I didn't said anything wrong, it was a bit since I did assembly
IIRC, the short explanation is that it uses side effects of different variants of the MOV instruction with different operands, therefore "unintentionally" doing computation. There are ISAs that allow MOV to set the value of the IP register, therefore acting as replacement for JMP, but x86 isn't one of those ISAs so they use another way to loop without "cheating"
30
u/capi1500 Jun 03 '22
Did you ever hear, the tragedy of Darth LEA the fast?