With ARM I can access a memory location like this:
LDR r0, [r1, #4]!
Meaning I want to load the value pointed to by r1, with an offset of 4 bytes, and the ! means that I want the value of r1 to be updated after this instruction with the new value (i.e., +4).
Is there an equivalent on x86 (AT&T syntax if possible)? For instance:
movl 4(%ebx), %eax
This will load the value pointed by %ebx with an offset of 4 bytes into %eax. How do I update the value of %ebx after the load though?
Thanks.
I think the instruction you're looking for is LODSD
which means "load DWORD from string". You don't get to pick the registers though: The pointer is in ESI
and the destination register is EAX
.
After the byte, word, or doubleword is transferred from the memory location into the AL, AX, or EAX register, the (E)SI register is incremented or decremented automati- cally according to the setting of the DF flag in the EFLAGS register. (If the DF flag is 0, the (E)SI register is incremented; if the DF flag is 1, the ESI register is decre- mented.) The (E)SI register is incremented or decremented by 1 for byte operations, by 2 for word operations, or by 4 for doubleword operations.
Sorry, I've got Intex syntax ingrained in my head right now. Assuming flat 32-bit protected mode:
mov esi, _source_data_ ; ESI points to source data
cld ; Clear the direction flag
; (ESI will increment)
lodsd ; Essentially mov eax, [ds:esi]
; add esi, 4