Question: Using mystery.s given in the assignment page, work on putDec function which will take the argument given in $a0 and interprets it as a 2s

Using mystery.s given in the assignment page, work on putDec function which will take the argument given in $a0 and interprets it as a 2s complement number. Your task is to go figure out character by character of what is the appropriate character to print out. We will be using syscall to accomplish this task. For example, if we want to print out character zero we would use:
li $a0, '0'
li $v0, 11
syscall
$v0 is telling the OS what function to do whereas $a0 is supplying the actual character to print out. If we want to print out that is contained in $t0 then the code would look like: li $a0, '0' add $a0, $a0, $t0 # added 0-9 in $t0 to make char li $v0, 11 syscall We have to do this for every single digit after we figure out what they are. Note that we have to figure out the MSB first and print it out in order. Also, it is easiest to handle printing positive numbers first.
Q1. In terms of characters being printed out what is the difference between -1 and 1?
Q2. What general mathematical function can you think of to handle negative numbers in terms of positive numbers characters?
Code provided for Mystery:
.text
main:
li $a0, 0
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $a0, 1
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $a0, 196
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $a0, -1
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $a0, -452
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $a0, 2
jal mystery
move $a0, $v0
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $a0, 3
jal mystery
move $a0, $v0
jal putDec
li $a0, ' '
li $v0, 11
syscall
li $v0, 10 # terminate program
syscall
putDec:
## FILL IN ##
jr $ra # returnv
mystery: bne $0, $a0, recur #
li $v0, 0 #
jr $ra #
recur: sub $sp, $sp, 8 #
sw $ra, 4($sp) #
sub $a0, $a0, 1 #
jal mystery #
sw $v0, 0($sp) #
jal mystery #
lw $t0, 0($sp) #
addu $v0, $v0, $t0 #
addu $v0, $v0, 1 #
add $a0, $a0, 1 #
lw $ra, 4($sp) #
add $sp, $sp, 8 #
jr $ra #
Using mystery.s given in the assignment page, work on putDec function which will take the argument given in $a0 and interprets it as a 2's complement number. Your task is to go figure out character by character of what is the appropriate character to print out. We will be using syscall to accomplish this task. For example, if we want to print out character zero we would use: li $v0, 11 syscall $vO is telling the OS what function to do whereas $a0 is supplying the actual character to print out. If we want to print out that is contained in $t0 then the code would look like: li $a0, '0 add $a0, $a0, $tO # added 0-9 in $t0 to make char li $v0, 11 syscall We have to do this for every single digit after we figure out what they are. Note that we have to figure out the MSB first and print it out in order. Also, it is easiest to handle printing positive numbers first. Q1. In terms of characters being printed out what is the difference between -1 and 1? Q2. What general mathematical function can you think of to handle negative numbers in terms of positive numbers' characters
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
