In: Computer Science
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;
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