Question: Write a MIPS program that utilizes subroutine. This program should take input of an integer from the user and then pass that number to BaseChange
Write a MIPS program that utilizes subroutine. This program should take input of an integer from the user and then pass that number to BaseChange subroutine. The subroutine should then calculate the binary form of that number by use of the stack and display the result to the user. An Example of sample input and output would be:
============================================================
Input a number in decimal form: 5
============================================================
The number 5 in binary is: 00000000000000000000000000000101
============================================================
NEED HELP FIXING MY ERROR
.data str: .asciiz " Input a number in decimal form: " str1: .asciiz " The number in binary is " str2: .asciiz " " .text
main:
li $v0, 4 la $a0, str syscall li $v0, 5 syscall add $s0, $v0, $0 # Store $v0 to $s0 add $a0, $s0, $0 jal binary # Jump to subroutine binary
#add $s1, $v0, $0
#add $a0, $s1, $0
add $a0, $v1, $0 # move zero
jal PRINT0 add $a0, $v0, $0 # move binary
jal print #li $v0, 4 #la $a0, str2 # New line #syscall
binary: add $s0, $a0, $0
li $t0, 2 li $t1, 0 #binary counts li $t9, 32 cal: beq $s0, 0, EXIT
div $s0, $t0 # divide user input by 2 mfhi $s2 # Remainder mflo $s3 # Quotient
add $s0, $s3, $0 # move num divide addi $sp, $sp, -4 # Decrement by 4 sw $s2, 0($sp) # Store $sp to $s1 addi $t1, $t1, 1
bne $t3, $0, EXIT j cal
EXIT: addi $t9, $t9, -1
add $v0, $t1, $0 #bi add $v1, $t9, $0 #0s jr $ra
PRINT0: add $t9, $a0, $0 li $t4,32 li $t3,0 sub $t4,$t4,$t9
#loop to print zeros loop3: beq $t9, $t3,continue li $v0, 4 li $v0,1 li $a0,0 syscall addi $t9,$t9,-1 j loop3 continue: jr $ra
print: add $t1, $a0, $0 loop2: beq $t1, $0, done lw $a0,0($sp) syscall
addi $sp, $sp, 4 addi $t1, $t1, -1 j loop2
#li $v0, 4 #la $a0, str1 # Display final prompt #syscall #lw $a0, 0($sp) #li $v0, 1 #add $a0, $s5, $0 # Display integer #syscall
done: li $v0, 10 syscall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
