Question

Convert the below C code to basic MIPS. The result of this code should be a^b...

Convert the below C code to basic MIPS. The result of this code should be a^b of the two numbers that you input. For example if you input the numbers 3 and 5 you should get a result of 3^5=6

#include


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"
   xorsym:    .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

   xor $t2, $t0, $t1  # c = a ^ b

   # print a
   move $a0, $t0
   li $v0, 1
   syscall

   # print ^
   la $a0, xorsym
   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. The result of this code should be a^b...
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
  • 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; }

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

    Convert the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b; scanf("%d",&a); scanf("%d",&b); a=a<<2; b=b<<2; printf("%d&%d\n",a,b); return 0; }

  • Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin,...

    Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin, cout, cin.getline) . Re-make the func function by the following prototype: void func( double, double &); #include int user_interface(); double func(double); void print_table(); int main (int argc, char *argv[]) {    print_table(user_interface());    return 0 ; } int user_interface(int val){    int input = 0;    printf("This function takes in x and returns an output\n");    printf("Enter Maximum Number of X:");    scanf("%d", &input);...

  • This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following...

    This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following c code into mips #include <stdio.h> #include <string.h> char cipherText[200] = "anything"; int countNumberOfCharInCipher(char*); int countNumberOfCharInCipher(char* cText) { return strlen(cText);    } int countSpaces(int numberOfChar, char input[]) { int spaceCounter =0; for(int i=0; i < numberOfChar; i++) { if(input[i] == 32) spaceCounter++; } return spaceCounter; } void decrypt(int numberOfChar, int key, char * cipherText, char * plainText) { int j = 0; int i =0;...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • Fix the code. Use Valgrind to compile below code with no warning and no memory error....

    Fix the code. Use Valgrind to compile below code with no warning and no memory error. Also give a comment about how you fix the code. gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 $* -o question5 question5.c && ./question5 gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 -fsanitize=address -o question5 question5.c && ./question5 Both of these should get the same output . For example if we input 65535 4 3 2 1 it should give us a output with What is...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • I have a question on an assignment for C++. I have my code available here and...

    I have a question on an assignment for C++. I have my code available here and just want someone to look over it using MS VS 2010 express, for that is what my instructor is using. Write a program that mimics a calculator. The program should take as input two integers and the opreation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.) //**This...

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