Question

2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. Assume that the elements of the arrays A and B are 4-byte words: fAlBg

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

# f = A[B[g]+1]
# f -> $s0, g -> $s1, A -> $s6, B -> $s7

sll $s1, 2       # making g an index
add $t0, $s1, $s7   # $t0 = &(B[g])
lw $t0, 0($t0)       # $t0 = B[g]
addi $t0, $t0, 1   # $t0 = B[g]+1
sll $t0, $t0, 2       # making $t0 an index
add $t0, $t0, $s6   # $t0 = &(A[B[g]+1)
lw $s0, 0($t0)       # $s0 = f = A[B[g]+1]

Add a comment
Know the answer?
Add Answer to:
2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f,...
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