pushrbx icon

MIPS ASM Exercise

pushrbx | PRO | 04/17/13 11:56:07 AM UTC | 0 ⭐ | 426 👁️ | Never ⏰ | []
text |

1.62 KB

|

None

|

0 👍

/

0 👎

Question:  What is the output of the following assembly code?
Original: http://i1183.photobucket.com/albums/x479/Szenya/532355_521882794525379_1012823075_n_zpse30e6bec.jpg
 Parsed by me (scarysandwich):
 OutChar:
lui $v0, 10;  /// $v0 = 10 << 16
ori $v0, $v0, 10; /// $v0 | 10  pad it with zeros
syscall
jump to address $ra // jump to return address
 main:
$s0 = $zero + 1    aka s0 = 1
$s0 << 6   // shift left by 6  so  $s0 * (2*6)    = 12
$a0 = $s0 + 1  // 13
jump to OutChar  // OutChar(13)
$s0 += $s0 // 24
$s1 = $zero + 1 // s1 = 1
$s1 << 4  //shift left aka $s0 * (2*4) // s1 = 8
$a0 = $s0 - $s1 // 16
jump OutChar // OutChar(16)
$s0 = 19
$s1 = 3
$s0 * $s1
$a0 = 57
$a0 << 1 // $a0 * 2
jump OutChar // OutChar(114)
$s2 = $zero + $a0 // 16
$s2 -= $s0 // -8
$s2 += 10 // 18
$a0 = $zero + $s2
jump OutChar  // OutChar(18)
$s2 = $s2 + $s1 // 26
$sp = -4 // set stackpointer
memstore $s2 in ($sp + 0)   // store $s2 at -4 memory location
$a0 = $s2
jump OutChar // OutChar(26)
$s0 = 1
$s0 << 5   // $s0 = 10
$a0 = $s0
jump OutChar // OutChar(10)
$a0 = $s2 - 6 
jump OutChar  // OutChar(26) 
$s0 = 37
$s0 * $s1
$a0 = 111
jump Outchar // OutChar(111)   o
jump OutChar // OutChar(111)   o
$a0 = mem[$sp + 0]  // load from address -4  (pop stackpointer)
$sp += 4 // 0
jump OutChar // OutChar(26)
$a0 = 111
$a0 += 4
jump OutChar // OutChar(115)  s
$a0 = $s0 - 4
jump OutChar // OutChar(33)
 // note:  $a0-$a3 -> function argument registers
 // C++
 int OutChar(int v)
{
   // call system to write to screen
}
 int main()
{
   int s0 = 12;
   OutChar(s0 + 1);
   // continue it from here..
}

Comments