Question

In: Computer Science

Translate the following pseudocode to MIPS assembly programming language cout << “\n Please input a number...

Translate the following pseudocode to MIPS assembly programming 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;

Solutions

Expert Solution

For the following program:

#include <iostream>

using namespace std;

int $s0, $s1, $s2;

int $t0;

int main() {

    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 0;

}

// Corresponding MIPS Assembly language program is as follows

$s0:

$s1:

$s2:

$t0:

$LC0:

        .ascii  "\012 Please input a number for $s0\000"

$LC1:

        .ascii  "\012 Please input a number for $s1\000"

$LC2:

        .ascii  "\012 Please input a number for $s2\000"

$LC3:

        .ascii  "\012 the Value of the expression \342\200\234$s0 / 8 - 2"

        .ascii  " * $s1 + $s2\342\200\235 is \000"

main:

        addiu   $sp,$sp,-32

        sw      $31,28($sp)

        sw      $fp,24($sp)

        move    $fp,$sp

        lui     $2,%hi($LC0)

        addiu   $5,$2,%lo($LC0)

        lui     $2,%hi(_ZSt4cout)

        addiu   $4,$2,%lo(_ZSt4cout)

        jal     std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

        nop

        lui     $2,%hi($s0)

        addiu   $5,$2,%lo($s0)

        lui     $2,%hi(_ZSt3cin)

        addiu   $4,$2,%lo(_ZSt3cin)

        jal     std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

        nop

        lui     $2,%hi($LC1)

        addiu   $5,$2,%lo($LC1)

        lui     $2,%hi(_ZSt4cout)

        addiu   $4,$2,%lo(_ZSt4cout)

        jal     std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

        nop

        lui     $2,%hi($s1)

        addiu   $5,$2,%lo($s1)

        lui     $2,%hi(_ZSt3cin)

        addiu   $4,$2,%lo(_ZSt3cin)

        jal     std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

        nop

        lui     $2,%hi($LC2)

        addiu   $5,$2,%lo($LC2)

        lui     $2,%hi(_ZSt4cout)

        addiu   $4,$2,%lo(_ZSt4cout)

        jal     std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

        nop

        lui     $2,%hi($s2)

        addiu   $5,$2,%lo($s2)

        lui     $2,%hi(_ZSt3cin)

        addiu   $4,$2,%lo(_ZSt3cin)

        jal     std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

        nop

        lui     $2,%hi($s0)

        lw      $2,%lo($s0)($2)

        nop

        bgez    $2,$L2

        nop

        addiu   $2,$2,7

$L2:

        sra     $2,$2,3

        move    $3,$2

        lui     $2,%hi($s1)

        lw      $2,%lo($s1)($2)

        nop

        sll     $2,$2,1

        subu    $3,$3,$2

        lui     $2,%hi($s2)

        lw      $2,%lo($s2)($2)

        nop

        addu    $3,$3,$2

        lui     $2,%hi($t0)

        sw      $3,%lo($t0)($2)

        lui     $2,%hi($LC3)

        addiu   $5,$2,%lo($LC3)

        lui     $2,%hi(_ZSt4cout)

        addiu   $4,$2,%lo(_ZSt4cout)

        jal     std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

        nop

        lui     $2,%hi($t0)

        lw      $2,%lo($t0)($2)

        nop

        move    $5,$2

        lui     $2,%hi(_ZSt4cout)

        addiu   $4,$2,%lo(_ZSt4cout)

        jal     std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        nop

        move    $2,$0

        move    $sp,$fp

        lw      $31,28($sp)

        lw      $fp,24($sp)

        addiu   $sp,$sp,32

        j       $31

        nop


Related Solutions

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;
Translate c++ code into mips assembly: int main() {                 cout << "Numbers:" << endl;            &nbs
Translate c++ code into mips assembly: int main() {                 cout << "Numbers:" << endl;                                 int x[] = {18, 12, 6, 500, 54, 3, 2, 122};                 int i;                                 for (i=0; i<8; i++)                 {                                                 cout << x[i] << endl;                 }                 return 0; } below is my code: .data        str1: .ascii "Numbers:"     str2: .ascii "\n"    x: .word 18,12,6,500,54,3,2,122       .text                      ...
In MIPS Assembly Language in Mars, define a method 1 to check if a number is...
In MIPS Assembly Language in Mars, define a method 1 to check if a number is divisible by 4. Then, define a method 2 to generate a random number, call method 1, and return result(number, yes/no) to main. Lastly, have the main method call method 2, and display the results.
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Translate the following C code to MIPS assembly. The main function and subfunction are translated to...
Translate the following C code to MIPS assembly. The main function and subfunction are translated to two separate .asm files. Finish the assembly code segment for the above requirement. int main() { int x=2; int y=1; int z=0; z=Subfunc(x,y); printf(“Value of z is: %d”, z); } int Subfunc(int x, int y) { int t1=0; t1=x+y+100; return t1;} File 1: .data str: .asciiz "The value of z:" .text #.globl main main: addi $s0, $0,2 #x addi $s1, $0,1 #y addi $s2,...
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
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 }
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...
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code...
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x2fff0004. Loop: lw $t0, 4($s0)             addi $t1, $t1, -15             sll $t1, $t1, 2             beq $t1, $s1, Exit             addi $s0, $s0, 4             j Loop Exit: …
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT