I was hoping someone could validate my understanding of the following assembly code:
test %esi,%esi
js 17 <build+0x17>
cmp $0x8,%esi
ja 1d <build+0x1d>
lea (&rsi,2),%ecx
shl $0x2,%rdi
mov %rdi,%rax
retq
mov $0x0,%eax //17
retq
mov $0x0,%eax //1d
retq
Here's what I think the code does:
- If esi&esi is negative return item at address 0
- If esi is above 8, return item at address 0
- Else store address of rsi *2 into ecx
- Then right shift rdi right by 2 bits
- Copy rdi to rax and return it
lea (&rsi,8),%ecx
should probably be writtenlea (,%rsi,8),%ecx
and meansECX=RSI*8
and not 'address of rsi`. The rest looks good. – zx485