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 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;
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
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two integers. Ideally, the program would ask for the user to type in the two integers. Then, the program would calculate the hamming distance. Afterward, it would ask if you'd like to find another hamming distance. If the user says yes, it would loop back to the beginning and ask for two new integers. Below is the code that I've created so far. Guidance with...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT