Question

2) Write a MIPS assembly language version of the following C code segment: int A[75], B[75];...

2) Write a MIPS assembly language version of the following C code segment:

int A[75], B[75];

for (i = 1; i < 73; i ++) {

C[i] = (A[i + 1] + A[i]) * (B[i + 2] - A[i-1]);

}

Arrays A, B and C start at memory location A000hex, B000hex and C000hex respectively. Try to reduce the total number of instructions and the number of expensive instructions such as multiplies.

WRITE A SIMPLE CODE WORKING FOR MARS 4.5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below:::

.data
A : .word 300 #array of size 75 integer
B : .word 300 #array of size 75 integer
C : .word 300 #array of size 75 integer
.text

la $s0,A #get base address of A
la $s1,B #get base address of B
la $s2,C #get base address of C

li $t0,1 #load i =1
loop:
bge $t0,73,exit #if not i<73 exit
mul $t0,$t0,4 #get base address of i
add $t1,$t0,$s0 #get base address of A[i]
sub $t2,$t1,4 #get base address of A[i-1]
lw $t2,($t2) #get value of A[i-1]
add $t3,$t1,4 #get base address of A[i+1]
lw $t3,($t3) #get value of A[i+1]
add $t4,$t0,8 #get address of i+2
add $t4,$t4,$s1 #get address of B[i+2]
lw $t4,($t4) #get value of A[i]
lw $t1,($t1) #get value of A[i]
add $t5,$t0,$s2 #get address of C[i]

add $t6,$t1,$t3 #get A[i] + A[i+1]
sub $t7,$t4,$t2 #get (B[i+2] -A[i-1])
mul $t6,$t6,$t7 #get (A[i] + A[i+1])*(B[i+2] -A[i-1])
sw $t6,($t5) #store result to c[i]

add $t0,$t0,1 #i++
j loop
exit:

Add a comment
Know the answer?
Add Answer to:
2) Write a MIPS assembly language version of the following C code segment: int A[75], B[75];...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT