Question

In: Computer Science

MIPS assembly code: procedure:                   addi $s0,$zero,0 loop:                   slt

  1. MIPS assembly code:

procedure:

                  addi $s0,$zero,0

loop:

                  slti $t1, $s0, 7

                  beq $t1, $zero, exit

                  addi $s0,$s0,1

                  j loop

exit:

                  add $v0, $zero, $s0

                  jr $ra

     

What is the corresponding high-level programming language code? Write a code in your preferred language. What is the result? (5 pts)

  1. Code:

int add(int a, int b) {

      return a+b;

}

int sub(int a, int b) {

      return a-b;

}

void main(){

      int x=11, y=4;

      add(x, y);

      sub(x, y);

}

     

What is the corresponding MIPS code? (5 pts)

Solutions

Expert Solution

1. Following image contains the explanation of mips instruction used in the above code and it's corresponding C code with in line comments.

The result is 7.

2.Following mips code perform addition and subtraction but it is performed through a function. And the value is returned in registery v0 and v1

The output will be,

V0= s0+s1

V0=11+4

V0=15

V1=s0-s1=11-4

V1=7

Thanks and kindly upvote.


Related Solutions

Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0...
Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0 and initially containing 0 . Also assume base of array Arr is in $s3 while ( k < = 10 ) { Arr[k] = k ; k = k + 1; }
Convert the following to machine code and then back to MIPS instructions: 1) a. addi $s0,...
Convert the following to machine code and then back to MIPS instructions: 1) a. addi $s0, $zero, -15 b. slt $t0, $s0, $s1 c. beq $t0, $zero, LEEQ d. j GRT
Translate the following C code into MIPS assembly code. Assume a in $s0, i in $s1,...
Translate the following C code into MIPS assembly code. Assume a in $s0, i in $s1, and base address of b[] in $s2, respectively. Note that the element’s data type in array b is integer (word). Please do not change the C code structure and please comment your MIPS code. for (i = 100; i>a; i--) {          b[i] = 16*i; b[i+1] = 16*(i+1); b[i+2] = 2*i + 16; }
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”;...
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”; cin >> $s0; cout << “\n Please input a number for $s1”; cin >> $s1; cout << “\n Please input a number for $s2”; cin >> $s2; $t0 = $s0 / 8 - 2 * $s1 + $s2; cout << “\n the Value of the expression “$s0 / 8 - 2 * $s1 + $s2” is ”; cout >> $t0; return;
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute...
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute six T[i] and display aproper message about roots .the the program should store all T[i] as memory array a = [1, 1, 1, 1, 1, 1]; b = [1, 2, 4, 8, 16, 32]; c = [-6, -4, -2, 2, 4, 6]; d = [-1, -3, -5, -7, -9, -11]; for (i=0 ; i<=6; i++) { T[i] =-4 *b [i] * d[i] +c[i] *...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered...
MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered by the user in a 300-byte buffer. The function must return the actual size of the entered text in number of bytes. The text could contain lines, that is to say that the symbol '\ n' could be present. The end of reading is defined by both consecutive '\ n' '\ n' symbols. 2) Code in MIPS a function that helps identify if the...
Consider the following C code: (10 marks) // write a MIPS instruction to initialize s0 to...
Consider the following C code: // write a MIPS instruction to initialize s0 to 6 t0 = ((s03 - 93)2 + s0 ) << 2 t1 = t0 / 4 Q2.1: Write a MIPS program that performs the operation of the above C program. Q2.2: What is the value of $t0 and $t1 after running your MIPS program (write your answer in a comment at the end of the code). Submit your answer to Q2 in a file named A2_Q2.asm
Write assembly code for the following C procedure: i = 1; sum = 0; while (i...
Write assembly code for the following C procedure: i = 1; sum = 0; while (i ≤ n) { sum += i; ++i; } i and sum corresponds to $s1 and $s2. n is preloaded into $s3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT