问题描述
我正在研究如何将IA32汇编代码转换为Y86汇编代码,并且受制于以下IA32代码中的指令:
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
我找不到Y86代码的等效指令.我虽然有以下两个版本,但是我不确定哪个是正确的:
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:
版本1:
mrmovl (%edx), %ebx
mrmovl (%eax), %esi
addl %ebx, %esi
rrmovl %esi, 5eax
版本2:
addl %edx, %eax
有人有更好的主意吗?
推荐答案
LEA
不访问内存,仅访问(地址)算术.因此,您的#2版本是正确的.
LEA
doesn't access memory, it only does (address) arithmetic. As such your version #2 is correct.
请注意,在x86上,LEA
不会影响标志,而ADD
会影响标志. LEA
还支持更复杂的有效地址语法,不过,将其转换为y86相当简单.例如,
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
成为:
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
这篇关于IA32汇编代码到Y86汇编代码:Leal指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!