Question

5. Consider the following C code: int main() int x = 1; switch (x) case 1: i=1; case 2: i=5; return 0; Based on this code, an

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

Please find the code below::

a)

aCtoMips6.asm li $s0,1 # int x-1 1 beq $s0,1,casel #if x==1 jump to case1 2 beq $s0,2, case2 #if x==2 jump to case2 j exit ca

li $s0,1 # int x=1
beq $s0,1,case1 #if x==1 , jump to case1
beq $s0,2,case2 #if x==2 , jump to case2
j exit

case1:
li $s1,1 #i=1
j exit

case2:
li $s1,5 #i=5
j exit


exit:

C)

C code:

int main(){

int x=1;
switch(x)

{

case 1 : i=1;
case 2 : i=5;
default : i=0;
}

return 0
}

mips:

0101 Edit Execute aCtoMips6.asm li $s0,1 # int x-1 1 beq $s0,1,casel #if x==1 jump to case1 2 beq $s0,2, case2 #if x==2 jump

li $s0,1 # int x=1
beq $s0,1,case1 #if x==1 , jump to case1
beq $s0,2,case2 #if x==2 , jump to case2
default:
li $s1,0 #i=0
j exit

case1:
li $s1,1 #i=1
j exit

case2:
li $s1,5 #i=5
j exit


exit:

Add a comment
Know the answer?
Add Answer to:
5. Consider the following C code: int main() int x = 1; switch (x) case 1:...
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