Question

Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) {...

Convert the below C code to basic MIPS. Leave comments for explanation please

#include <stdio.h>


int main(void)
{
printf("Insert two numbers\n");
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
c=a|b;
printf("%d|%d=%d\n",a,b,c);
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
.data
   prompt:    .asciiz    "Insert two numbers\n"
   orsym: .asciiz    "|"
   eqsym: .asciiz    "="
   newline:.asciiz    "\n"

.text
   # display prompt
   la $a0, prompt
   li $v0, 4
   syscall

   # read a number
   li $v0, 5
   syscall
   
   # store input(a) in $t0
   move $t0, $v0

   # read another number  
   li $v0, 5
   syscall

   # store input(b) in $t1    
   move $t1, $v0  
   
   or $t2, $t0, $t1   # c = a | b

   # print a
   move $a0, $t0
   li $v0, 1
   syscall
   
   # print |
   la $a0, orsym
   li $v0, 4
   syscall

   # print b
   move $a0, $t1
   li $v0, 1
   syscall
   
   # print =
   la $a0, eqsym
   li $v0, 4
   syscall

   # print c
   move $a0, $t2
   li $v0, 1
   syscall

   # print \n 
   la $a0, newline
   li $v0, 4
   syscall
Add a comment
Know the answer?
Add Answer to:
Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) {...
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