IA32 assembly code to Y86 assembly code: leal inst

2019-08-07 09:41发布

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?

标签: assembly x86 y86
1条回答
孤傲高冷的网名
2楼-- · 2019-08-07 09:58

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
查看更多
登录 后发表回答