Question

Please answer the following questions involving MIPS assembly code: A) For the C statement below, what...

Please answer the following questions involving MIPS assembly code:

A) For the C statement below, what is the corresponding MIPS assembly code? Assume f, g are stored in S1 and S2.

f = g + (-f -5)

B)

For the C statement below, what is the corresponding MIPS assembly code? Assume i and j are assigned in registers S1 and S2 respectively and base of address of arrays A and B are in registers S6 and S7.

B[8] = A[i –j]

C)

For the instruction below, show the binary then hexadecimal representation of these instructions.

sw $t, 32 ($t2)

sll $s1, $2, 4

D)

For the lines below, what is the value of $t2 for the following sequence of instructions?

Sll $t2, $t0, 4

andi $t2, $t2, -1

Assume, t0 stores a value of x000020A1

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

A)

f = g + (-f -5)

addi $s1,$s1,5 # add 5 to f i.e, f+5 and assign it to $s1
sub $s1,$s2,$s1 # subtract f from g and assign it to f => f= g + (-f - 5) = g-(f+5)

B)

B[8] = A[i –j]

sub $s1,$s1,$s2 # subtract j from i and assign it to $s1 = i-j  
li $t1,8
li $t2,4

mul $t1,$t1,$t2 # $t1=32
mul $t3,$s1,$t2 # $t3 = (i-j)*4

add $t1,$t1,$s7 #add B array base address to $t1 which gives address B[8]
add $t3,$t3,$s6 #add A array address to $t3 which gives address A[i-j]

lw $t4,0($t3) #load A[i-j] to $t4
sw $t4,O($t1) # store $t4 in address $t1 i.e B[8]

D) value of $t2= 0x000

sll $t2, $t0, 4 #shift left 4 bits bu the number is hex so it will shift to => t2 = 00020A10
andi $t2, $t2, -1 # do and operation $t2,-1 =>t2= 0x000

Add a comment
Know the answer?
Add Answer to:
Please answer the following questions involving MIPS assembly code: A) For the C statement below, what...
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