Click here to Skip to main content
14,699,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following fragment of MIPS code results in “OK” being printed when I run it on QtSpim.

But why is this?

addi	$v0,	$zero,	11
addi	$a0,	$zero,	79
syscall
addi	$v0,	$zero,	11
addi	$a0,	$zero,	75
syscall
addi	$v0,	$zero,	10
syscall


What I have tried:

I expected the register $v0 to store 32 (11 + 11 + 10) and $a0 to store 154 (79 + 75).

But they only store the values temporarily, and the end result is "OK", but I don't know why.
Posted
Updated 3-Dec-18 22:22pm

1 solution

Quote:
I expected the register $v0 to store 32 (11 + 11 + 10) and $a0 to store 154 (79 + 75).
Your assumptions are wrong.
addi $v0, $zero, 11
could be written (pseudocode)
v0 <- ([$zero]+11)
That is: add the immediate integer 11 with the content of register 0 and store the result into register v0.


So the sequence
addi	$v0,	$zero,	11
addi	$a0,	$zero,	79
syscall
is
$v0 <- 11
$a0 <- 79
syscall

syscall is invoked with code 11 ('print_character') and argument 79 (ASCII code of 'O').
A similar argument applies to the remaining lines of the program.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900