[英]IA32 to Y86 Assembly Code Conversion
I've been tasked with converting IA32 code to Y86. 我的任务是将IA32代码转换为Y86。 The original program was written in C and is intended to take an array of integers in which the even positioned values call one of three functions and the odd positioned values are operated on within that function. 原始程序用C编写,旨在采用整数数组,其中偶数位置值调用三个函数之一,而奇数位置值在该函数中进行运算。 The functions include the negation of a number, the square of a number, and the sum from 1 to the supplied number. 函数包括数字的取反,数字的平方以及从1到提供的数字的和。
Most of the instructions are easily converted from IA32 to Y86, but there are a number of instructions that are giving me a really hard time. 大多数指令很容易从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
The neg instruction is not a valid instruction in Y86. neg指令在Y86中不是有效指令。 This is what I have in 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
Is this the correct way to go about this problem? 这是解决此问题的正确方法吗?
Another instruction is the imul instruction in my square function: 另一个指令是我平方函数中的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
Does anyone know how the "imul" instruction can be converted in this situation? 有谁知道在这种情况下如何转换“ imul”指令?
Thanks for the help! 谢谢您的帮助! Any tips on IA32/Y86 Conversion would be greatly appreciated too. IA32 / Y86转换的任何技巧也将不胜感激。
For implementing imul
, you might want to look at using a shift and add routine to implement a mul
routine: 为了实现imul
,您可能希望使用shift并添加例程来实现mul
例程:
Then for imul
just use the following steps: 然后对于imul
只需使用以下步骤:
mul
routine on the positive values 在正值上调用mul
例程 1) is mrmovl 0x4(%esp),%eax allowed? 1)是否允许mrmovl 0x4(%esp),%eax?
ixorl %eax, 0xffffffff
iaddl %eax, 1
should be slightly more efficient (also ebp can be used as GPR -- no need to push esi) 应该稍微更有效(也可以将ebp用作GPR-无需推送esi)
2) for multiplication there are indeed shift and add-options, 2)对于乘法,确实有shift和add-options,
but also a LUT based approach, exploiting the fact that 4*a*b = (a+b)^2 - (ab)^2
. 也是一种基于LUT的方法,利用4*a*b = (a+b)^2 - (ab)^2
的事实。 for each 8x8 bit or NxN bit multiplication. 每个8x8位或NxN位乘法。
For a=h<<8+l, B=H<<8|L, aB = Ll + (hL+Hl)<<8 + hH<<16;
对于a=h<<8+l, B=H<<8|L, aB = Ll + (hL+Hl)<<8 + hH<<16;
could be handled using 3 different tables: 可以使用3个不同的表进行处理:
s1[n] = n^2 >>2; s2[n]=n^2 << 6; s3[n]=n^2 << 14;
For negation, you reversed the operands for the irmovl instruction. 对于求反,您反转了irmovl指令的操作数。
The following code works: 以下代码有效:
#
# 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:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.