我试图为sparc机器编写以下代码。
y=(x-7)(x-11) for the range 0<=x<=10我想打印出下面的代码,比如这个for input of x=0 output y=77,等等,最多十。
我成功地完成了循环。但我的问题是把输出打印出来。
/*
This program will compute y=(x-7)(x-11)
for the range 0<=x<=10
*/
/*
these are the variables
*/
.section ".data"
mystring:.asciz "for input of x=%d and output y=%d"
define(a1,7)
define(a2,11)
define(x_r,l0)
define(x_r,l1)
.section ".text"
main:
save %sp,-96,%sp
clr %x_r
loop:
sub %x_r,a1,%o0 !(x-a1)
sub %x_r,a2,%o1 !(x-a2)
call .mul
nop
mov %o0,%y_r
add %x_r,1,%x_r
cmp %x_r,10
ble loop
nop
ret
restore我知道我必须在我的代码上打印这样的东西,但我不确定在哪里。
set mystring,%o0
move %x_r,%o1
move %y_r,%o2
call printf
nop我现在得到的THe输出是
输入x=0输出y=77输入x=1输出y=60输入x=2输出输入y=45输入x=3输出y=32输入x=4输出y=21输入x=5输出y=12输入x=6输出y=12输入x=7输出y=5输入x=7输出y=0输入x=8输出y=-3输入y=5输出y=-4输入y=5输出y=-4输入x=4输出y=-3
我想要这样
x=0输出y=77输入x=1输出y=60 ..输入x=10 y=-3
发布于 2014-02-07 20:27:26
上次我看到SPARC组装已经有一段时间了。现在CPU要么是x86,要么是ARM。我对SPARC组装的了解很生疏.
y_r的
定义(x_r,l0)定义(x_r,l1)mov %o0,%y_r,可以将乘法结果存储到%y_r中。而下一行add %x_r,1,%x_r是C中的++x,因此应该在这两者之间调用printf。https://stackoverflow.com/questions/21635763
复制相似问题