问题
I am studying how to convert IA32 assembly code to Y86 assembly code, and I am stuck in the following instruction which is in IA32 code:
leal(%edx, %eax), %eax
I cannot find the equivalent instructions for the Y86 code. I have though of two version as the following ones, but I am not sure which is right:
Version 1:
mrmovl (%edx), %ebx
mrmovl (%eax), %esi
addl %ebx, %esi
rrmovl %esi, 5eax
Version 2:
addl %edx, %eax
Does anyone have a better idea?
回答1:
LEA
doesn't access memory, it only does (address) arithmetic. As such your version #2 is correct.
Note that on x86 LEA
doesn't affect flags, while ADD
does. LEA
also supports more complex effective address syntax, which is nevertheless quite straight-forward to transcribe to y86. For example,
leal offset(%eax, %ebx, 4), %edx
becomes:
rrmovl %ebx, %edx
addl %edx, %edx
addl %edx, %edx
addl %eax, %edx
pushl %eax # save eax which used as temporary for adding the offset
irmovl $offset, %eax
addl %eax, %edx
popl %eax # restore eax
来源:https://stackoverflow.com/questions/13545606/ia32-assembly-code-to-y86-assembly-code-leal-instruction