推 a124136906:感謝大大解答!!雖然不是很懂!還是努力了解中>< 10/17 22:10
※ 編輯: yesa315 來自: 140.127.208.96 (10/18 13:58)
※ 引述《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