汇编语言带C循环,如何将此C for循环转换为汇编语言?

我需要编写一个程序集程序,在-2 < = x < = 8的范围内查找x^3 -14x^2 + 56x -64的最大值,并且最大值应在其中一个寄存器中该程序。如何将此C for循环转换为汇编语言?

我用C编写了代码,但是我不知道如何将它自己转换成Assembly。我现在很困惑。顺便说一句,我必须自己转换它。我无法使用gcc转换为程序集。这是用于SPARC

#include

int main()

{

int i;

int ans;

for (i = -2; i < 9; i++){

ans = (i * i * i) - (14 * i * i) + (56 * i) - 64;

}

}

我试图编写程序集。有人可以批评它,并告诉我,如果我在正确的方向。另外,我将如何去测试最大数量?

main:

save %sp, -96, %sp

ba test

mov -2, %a_r

loop:

mov %a_r, %o0 !a_r moved into o0

mov %a_r, %o1 !a_r moved into o1

call .mul !they are multiplied and stored in o0

call .mul !they are multiplied again and stored in o0

mov %o0, r0 !results stored in r0

mov %a_r, %o0 !a_r moved into o0 and o1

mov %a_r, %o1

call .mul !they are multiplied and stored in o0

mov 14, %o1

call .mul !o0 result is multiplied by 14 and stored in r1

mov %o0, r1

mov 56, %o0 !56 moved into o0

mov %a_r, %01 !a_r moved into o1

call .mul !they are multiplied and stored in r2

mov %o0, r2

Sub r0,r1,r0 !r0-r1 stored in r0

Add r0,r2,r0 !r0+r2 stored in r0

Sub r0,64,r0 !r0-64 stored in r0

add %a_r, 1, %a_r !a_r + 1

test:

cmp %a_r %b_r ! a_r<=8?

ble loop

+1

[你有什么试过?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) –

2013-02-17 00:13:39

+3

'gcc -S prog.c -o prog.s'是一个开始。你可以研究生成的程序集来获得一些想法。 –

2013-02-17 00:14:32

+0

是x86汇编,MIPS,ARM还是什么? –

2013-02-17 00:38:20

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值