Question

In: Computer Science

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;

Solutions

Expert Solution

C++ Program of Given Pseudo Code ::---

#include <iostream>  

using namespace std;  

int main( ) {  

  int $s0,$s1,$s2,$t0;  

   cout << "\nPlease input a number for $s0";  

   cin >> $s0;  

   cout << "\nPlease input a number for $s1";  

   cin >> $s1;  

   cout << "\nPlease input a number for $s2";  

   cin >> $s2;  

   $t0 = $s0 / 8 - 2 * $s1 + $s2;

   cout << "\nthe value of the expression is <<";  

   cout << $t0;

   return 0;

}

MIPS ASSEMBLY CODE OF GIVEN C++ CODE ::---

.LC0:

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

.LC1:

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

.LC2:

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

.LC3:

        .ascii  "\012the value of the expression is <<\000"

main:

        daddiu  $sp,$sp,-48

        sd      $31,40($sp)

        sd      $fp,32($sp)

        sd      $28,24($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(main)))

        ld      $2,%got_page(.LC0)($28)

        daddiu  $5,$2,%got_ofst(.LC0)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,4

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZNSirsERi)($28)

        move    $25,$2

        nop

        ld      $2,%got_page(.LC1)($28)

        daddiu  $5,$2,%got_ofst(.LC1)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,8

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZNSirsERi)($28)

        move    $25,$2

        nop

        ld      $2,%got_page(.LC2)($28)

        daddiu  $5,$2,%got_ofst(.LC2)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,12

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZNSirsERi)($28)

        move    $25,$2

        nop

        lw      $2,4($fp)

        bgez    $2,.L2

        nop

        addiu   $2,$2,7

.L2:

        sra     $2,$2,3

        move    $3,$2

        lw      $2,8($fp)

        sll     $2,$2,1

        subu    $2,$3,$2

        move    $3,$2

        lw      $2,12($fp)

        addu    $2,$3,$2

        sw      $2,0($fp)

        ld      $2,%got_page(.LC3)($28)

        daddiu  $5,$2,%got_ofst(.LC3)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        lw      $2,0($fp)

        move    $5,$2

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZNSolsEi)($28)

        move    $25,$2

        nop

        move    $2,$0

        move    $sp,$fp

        ld      $31,40($sp)

        ld      $fp,32($sp)

        ld      $28,24($sp)

        daddiu  $sp,$sp,48

        j       $31

        nop

__static_initialization_and_destruction_0(int, int):

        daddiu  $sp,$sp,-48

        sd      $31,40($sp)

        sd      $fp,32($sp)

        sd      $28,24($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        move    $3,$4

        move    $2,$5

        sll     $3,$3,0

        sw      $3,0($fp)

        sll     $2,$2,0

        sw      $2,4($fp)

        lw      $3,0($fp)

        li      $2,1                        # 0x1

        bne     $3,$2,.L6

        nop

        lw      $3,4($fp)

        li      $2,65535                    # 0xffff

        bne     $3,$2,.L6

        nop

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $4,$2,%got_ofst(_ZStL8__ioinit)

        ld      $2,%call16(_ZNSt8ios_base4InitC1Ev)($28)

        move    $25,$2

        nop

        ld      $6,%got_disp(__dso_handle)($28)

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $5,$2,%got_ofst(_ZStL8__ioinit)

        ld      $4,%got_disp(_ZNSt8ios_base4InitD1Ev)($28)

        ld      $2,%call16(__cxa_atexit)($28)

        move    $25,$2

        nop

.L6:

        nop

        move    $sp,$fp

        ld      $31,40($sp)

        ld      $fp,32($sp)

        ld      $28,24($sp)

        daddiu  $sp,$sp,48

        j       $31

        nop

_GLOBAL__sub_I_main:

        daddiu  $sp,$sp,-32

        sd      $31,24($sp)

        sd      $fp,16($sp)

        sd      $28,8($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(_GLOBAL__sub_I_main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(_GLOBAL__sub_I_main)))

        li      $5,65535                    # 0xffff

        li      $4,1                        # 0x1

        ld      $2,%got_page(__static_initialization_and_destruction_0(int, int))($28)

        daddiu  $2,$2,%got_ofst(__static_initialization_and_destruction_0(int, int))

        move    $25,$2

        nop

        move    $sp,$fp

        ld      $31,24($sp)

        ld      $fp,16($sp)

        ld      $28,8($sp)

        daddiu  $sp,$sp,32

        j       $31

        nop

Thankyou :)


Related Solutions

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;
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; }
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                      ...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
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: …
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,...
1.) Translate the following C code to MIPS assembly code. Assume that the variables f, g,...
1.) Translate the following C code to MIPS assembly code. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively   B[8] = A[i-j]; 2.Translate the following C code to MIPS assembly code. Assume that the values of v in $a0, k in $a1, temp in $t0.    // leaf procedure that...
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 }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT