Question

In: Computer Science

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

Solutions

Expert Solution

ANSWER :

MIPS code

addi $s0, $0 , 6       //$s0 = 6
add $t0, $s0 , $0       //$t0 = $s0
mult $t0, $s0
mflo $t0           //$t0 = ($s0)^2
mult $t0, $s0
mflo $t0           //$t0 = ($s0)^3
addi $t0, $t0, -93       //$t0 = ($s0)^3 - 93
mult $t0, $t0
mflo $t0           //$t0 = (($s0)^3 - 93)^2
add $t0, $t0, $s0       //$t0 = (($s0)^3 - 93)^2 + $s0
sll $t0, $t0, 2           //$t0 = ((($s0)^3 - 93)^2 + $s0) << 2  
srl $t1, $t0, 2           //$t1 = $t0/4

$t0 = 60540
$t1 = 15135

( PLEASE VOTE FOR THIS ANSWER )

I THINK IT WILL BE USEFULL TO YOU .......

PLZZZZ COMMENT IF YOU HAVE ANY PROBLEM I WILL TRY TO SOLVE IT ............

THANK YOU .........


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; }
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; }
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
MIPS assembly code: procedure:                   addi $s0,$zero,0 loop:                   slt
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) Code: int add(int a, int b) {       return a+b; } int sub(int a, int b) {      ...
a) Write C code initialize an array of ints to the last four digits of your...
a) Write C code initialize an array of ints to the last four digits of your phone number. Use a loop to add the digits. Calculate and display the average of the digits. b) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa
For c++ Write the code to initialize an array such that each element gets two times...
For c++ Write the code to initialize an array such that each element gets two times the value of its index (e.g. 0, 2, 4, 6, …)
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;
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:" <<...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a,...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds the base address of the array A (add comments to your MIPS code). j = 0; for(i=0 ; i<a ; i++) A[i]=i+j++;
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i]; 6.Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT