I am trying to code something that continually takes in an integer from the user and stores the minimum value into $s2.
This is a C code representation of what I am trying to do
if ( $s2 == 0 )
$s2 = $t0
else {
if ( $t0 < $s2 )
$s2 = $t0
}
Basically, I loaded $s2 with zero outside of the input loop. This checks if $s2 has zero, and sets it to the current (first) user input ($t0) since that is the minimum value. If $s2 no longer contains zero then it checks the new user input against what is already in $s2 and if it is less than it becomes the new minimum value.
How can I implement this in MIPS assembly?
I have this so far (this is the end piece of a loop called read) but all it does is when I press the first int, it skips to the end and prints the min without looping over.
read:
...
beq $s2, $zero, LOAD
slt $s6, $t0, $s2
bne $s6, $zero, LOAD
j read
LOAD:
li $s2, 0
addu $s2, $s2, $t0
Aucun commentaire:
Enregistrer un commentaire