作者yesa315 (XD)
看板Grad-ProbAsk
标题Re: [理工] [计组]-MIPS
时间Sat Oct 17 09:25:58 2009
※ 引述《a124136906 (小麦)》之铭言:
: In MIPS assembly,write an assembly language version of the following C code
: segment:
: intA[100],B[100];
: for(i=1;i<100;i++) {
: A[i]= A[i-1]+B[i];
: }
: At the beginning of this code segment,the only values in registers are the
: base address of arrays A and B in registers $a0 and $a1.
: Avoid the use of multiplication instructions-they are unnecessary.
: 小弟有点不知道这题要怎麽写
: 希望有高手可以帮我解!!!
: 自己MIPS程度很低
: 希望帮解><"
题目说不能用乘法
MIPS aligment 为4的倍数 每次指令抓取4byte(32bit)
以下s0=i
addi s0 , zero ,4 //s0初始化 设为4(因为i=1*4)
addi s1 , s0 ,-4 //s1为i-1 减1就是扣4
loop:
lw t0 , s1(a0) //t0=A[i-1]
lw t1 , s0(a1) //t1=B[i]
add t0 , t0,t1 //t0=t1+t2
sw t0 , s0(a0) //A[i]=t0
addi s0 , s0 , 4 //i=i+1
addi s1 , s1 , 4 //s1=i-1
bne s0,400,loop //100*4=400 等於100就跳出回圈
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.127.208.96
1F:推 a124136906:感谢大大解答!!虽然不是很懂!还是努力了解中>< 10/17 22:10
※ 编辑: yesa315 来自: 140.127.208.96 (10/18 13:58)