我的任务是将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这是解决这个问题的正确方法吗?
另一个指令是我的square函数中的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转换的技巧也将不胜感激。
发布于 2012-12-01 08:52:20
为了实现imul,您可能希望使用shift和add例程来实现mul例程:
然后,对于imul,只需使用以下步骤:
计算出结果应该是什么符号,并将操作数转换为绝对值(在正values
mul例程,如有必要,将结果转换为负值发布于 2012-12-01 23:46:29
1)是否允许mrmovl 0x4(%esp),%eax?
ixorl %eax, 0xffffffff
iaddl %eax, 1 应该稍微更有效( ebp也可以用作GPR --不需要推动esi)
2)对于乘法,确实存在移位和加法选项,
but also a LUT based approach, exploiting the fact that `4*a*b = (a+b)^2 - (a-b)^2`. for each 8x8 bit or NxN bit multiplication.对于a=h<<8+l, B=H<<8|L, aB = Ll + (hL+Hl)<<8 + hH<<16;
could be handled using 3 different tables:s1[n] = n^2 >>2; s2[n]=n^2 << 6; s3[n]=n^2 << 14;
发布于 2015-11-18 10:22:13
对于求反操作,您颠倒了irmovl指令的操作数。
下面的代码可以工作:
#
# Negate a number in %ebx by subtracting it from 0
#
Start:
irmovl $999, %eax // Some random value to prove non-destructiveness
irmovl Stack, %esp // Set the stack
pushl %eax // Preserve
Go:
irmovl $300, %ebx
xorl %eax, %eax
subl %ebx,%eax
rrmovl %eax, %ebx
Finish:
popl %eax // Restore
halt
.pos 0x0100
Stack: https://stackoverflow.com/questions/13654809
复制相似问题