Question

C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...

C to MIPS Conversion
C variable
   h
   i
   j
   k
   x
int a[] or &a[0]
MIPS register replacement
   $s0
   $s1
   $s2
   $s3
   $s4
   $a0
Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE).  Answer MUST use true 32-bit MIPS  instructions:

 Note that all variables (h,i,j,x,a[]) are 32-bit signed integers.
while ( h < 3 ) {
  a[j++]= 0;
  x = i >> 3;  
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note :- I have used addi instead of li and slt and beq instead bge . No pseudo code is used. Please change the rating in the previous too. It will be helpful. Any issue please comment, I will try to help you better. Thank you

Given register file:
h = $s0
i = $s1
j = $s2
k = $s3
x = $s4
&a[0] = $a0

MIPS PROGRAM :-

#while (h<3)
WHILE_LOOP:
addi $t0, zero, 0
slti $t0, $s0, 3
beq $t0, $zero, EXIT_WHILE

#calculating address of a[j]
sll $t0, $s2, 2
add $t0, $t0, $a0
  
#a[j]=0
sw $zero,0($t0)
  
addi $s2, $s2, 1 #j++

srl $s4, $s1, 3 #x=i>>3
j WHILE_LOOP
EXIT_WHILE:

Add a comment
Know the answer?
Add Answer to:
C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...
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