Question

Translate C code into MIPS. Do not include an exit syscall int proc1( int a, int...

Translate C code into MIPS. Do not include an exit syscall

int proc1( int a, int b ) {
if ( proc2( a, b ) >= 0 )
return 1;
else
return -1;
}
int proc2( int a, int b ) {
return (a*10) & (b*10);
}
int main() {

int a = 9;
int b = -10;
int c = a + b + proc1( a, b );

printf("%d\n", c );
return 0;
}

Homework Answers

Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

.text
.globl main
main:
li $a0,9 #a=9
li $a1,-10 #b=-10
add $s1,$a0,$a1 #get a+b
jal proc1
add $s1,$s1,$v0 #get a+b+proce1(a,b)
move $a0,$s1
li $v0,1
syscall
li $v0,10
syscall


proc2: # a will be in a0,b will be in a1
mul $a0,$a0,10 #get a*10
mul $a1,$a1,10 #get b*10
and $v0,$a0,$a1 # get (a*10) & (b*10);
jr $ra

proc1:# a will be in a0,b will be in a1
move $s0,$ra #store ra
jal proc2 #call proc2
bgt $v0,0,if
else:
li $v0,-1
jr $s0 #return 01
if:
li $v0,1
jr $s0 #return 01


Know the answer?
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
Similar Questions
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL && pointVar2 == NULL) {       printf("Pointer is null\n");    }    else if (*pointVar2 > *pointVar1) {       printf("%p\n", *pointVar2);    }    else if (*pointVar1 > *pointVar2) {       printf("%p\n", *pointVar1);    } } int main() {    int num1 = 5;    int num2 = 9;       CheckValue(&num1, &num2);           return 0; } a. 0 b. 5 c. 9 d. Pointer is null e....
Compile and run the following code and presuming your executable is in a.out, run this command...
Compile and run the following code and presuming your executable is in a.out, run this command from the shell prompt: ./a.out ; echo "Parent Terminated Normally with a return value of $?" Explain, in your own words, why you see the screen output you do and how that output relates to both the content of the program AND the nature of the shell command used to invoke it. Hint: This has everything to do with how processes “communicate” their exit...
Below is C code and Python code for an algorithm. C code: void foo( int n,...
Below is C code and Python code for an algorithm. C code: void foo( int n, int A, int B, int C ) { if( n==1 ) { printf("%d to %d\n",A,B); return; } foo( n-1, A, C, B ); printf("%d to %d\n",A,B); foo( n-1, B, C, A ); Python code: def foo(n , A, B, C): if n==1: print A, "to", B return foo(n-1, A, C, B) print A, "to", B foo(n-1, B, C, A) Let Hn be the number...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i >...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i > 10) MemArray[i] = 0; else MemArray[i] = - MemArray[i]; Assume that the variable i is bound to register $t0, and that the base address of array MemArray is in register $s0.
q : explain the code for a beginner in c what each line do Question 2....
q : explain the code for a beginner in c what each line do Question 2. The following code defines an array size that sums elements of the defined array through the loop. Analyze the following code, and demonstrate the type of error if found? What we can do to make this code function correctly ? #include <stdio.h> #define A 10 int main(int argc, char** argv) { int Total = 0; int numbers[A]; for (int i=0; i < A; i++)...
Explain this code function by function in detail int menu() {   int choice;   do {     system("cls");...
Explain this code function by function in detail int menu() {   int choice;   do {     system("cls");     printf("1-Insurence Plan Subscription\n");     printf("2-Claim Processing\n");     printf("3-Accounts Information\n");     printf("4-Searching Functionalities\n");     printf("5-Exit\n");     scanf("%d", &choice);   } while (choice > 5 || choice < 1);   return choice; void subscribe() system("cls");   victims[userCount].id = userCount + 1;   printf("Enter age: ");   scanf("%d", &victims[userCount].age);   printf("\n\n%-25sHealth Insurence Plan\n\n", " ");   printf("-----------------------------------------------------------------------------------------------\n");   printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");   printf("-----------------------------------------------------------------------------------------------\n");   printf("|%-30s|%-20d|%-20d|%-20d|\n", "Monthly Premium", 120, 150, 200);   printf("|%-30s|%-20d|%-20d|%-20d|\n", "Annual Claim Limit", 120000,150000,200000);   printf("|%-30s|%-20d|%-20d|%-20d|\n",...
How can i make this lunix code print 3 numbers in reverse it must be in...
How can i make this lunix code print 3 numbers in reverse it must be in printStars format and no loops Here is the code i have but can figure out how to reverse the numbers #include<stdio.h> void printStars(int n) { if (n>0){ printf(""); printStars(n-1); } } int main() { int n; int b; int c; printf("Enter 3 numbers to reverse "); scanf("%d",&n,&b,&c); printf("your reversed numbers are %d",n); printStars(n); return 0;
Run the below code and shift binary left and right and understand the output. #include <stdio.h>...
Run the below code and shift binary left and right and understand the output. #include <stdio.h> int main() {     int num=212, i;     for (i=0; i<=2; i++)         printf("Right shift by %d: %d\n", i, num>>i);      printf("\n");      for (i=0; i<=2; i++)         printf("Left shift by %d: %d\n", i, num<<i);             return 0; } Output:
Convert the following C program to inline assembly int main(){ int i; printf("Hex Dec Oct Ch\n");...
Convert the following C program to inline assembly int main(){ int i; printf("Hex Dec Oct Ch\n"); for (i = 32; i < 256; i++){ printf("%2x %3d %3o %c\n",i,i,i,i); } return 0; } the code below shows where to do the assembly at: int main(){ int i = 0; char *hdr = "Hex Dec Oct Ch\n"; char *msg = " %2x %3d %3o %c\n"; printf("%s\n",hdr); ———asm{ // DO ASSEMBLY HERE } system("pause"); }
#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int...
#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int array[] = { 1, 1, 1, 3 }; unsigned long long r = sum(array, sizeof(array) / sizeof(*array)); printf("Result is: %llu (%s)\n", r, r == 6 ? "correct" : "incorrect"); return 0; } Complete the code for the line that calls the sum function. Write the sum function.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT