【发布时间】:2012-11-30 23:48:35
【问题描述】:
我的任务是将 IA32 代码转换为 Y86。原始程序是用 C 编写的,旨在获取一个整数数组,其中偶数定位值调用三个函数之一,奇数定位值在该函数内进行操作。这些函数包括数字的否定、数字的平方以及从 1 到提供的数字的总和。
大部分指令都可以轻松地从 IA32 转换为 Y86,但也有一些指令让我很难过。
0000001e <negation>:
1e: 55 push %ebp
1f: 89 e5 mov %esp,%ebp
21: 8b 45 08 mov 0x8(%ebp),%eax
24: f7 d8 neg %eax
26: 5d pop %ebp
27: c3 ret
neg 指令不是 Y86 中的有效指令。这就是我在 Y86 中所拥有的:
# int Negation(int x)
Negation:
pushl %ebp
pushl %esi
rrmovl %esp,%ebp
mrmovl 0x8(%ebp),%eax
irmovl %esi,$0
subl %eax, %esi
rrmovl %esi, %eax
popl %esi
popl %ebp
ret
这是解决这个问题的正确方法吗?
另一个指令是我的平方函数中的 imul 指令:
00000028 <square>:
28: 55 push %ebp
29: 89 e5 mov %esp,%ebp
2b: 8b 45 08 mov 0x8(%ebp),%eax
2e: 0f af c0 imul %eax,%eax
31: 5d pop %ebp
32: c3 ret
有谁知道在这种情况下如何转换“imul”指令?
感谢您的帮助!任何有关 IA32/Y86 转换的提示也将不胜感激。
【问题讨论】:
-
明确一点,IA32中给出了square函数代码
-
我不知道 Y86 的详细信息,但看起来至少
mrmovl 0x8(%ebp),%eax应该是mrmovl 0xc(%ebp),%eax,因为您在设置ebp之前要推送一个额外的寄存器。
标签: c assembly instructions y86