Question: Having trouble with my code..... Subroutine & Stack Using MIPS 1. Write a MIPS program that utilizes subroutine. This program should take input of an

Having trouble with my code.....

Subroutine & Stack Using MIPS

1. 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

============================================================

This is what is what I have so far....

.data

str: .asciiz " Input a number in decimal form: "

str1: .asciiz " The number in binary is "

newLine: .asciiz " "

.text

li $v0, 4 # Display prompt

la $a0, str

syscall

li $v0, 5 # User input

syscall

add $s0, $v0, $0 # Store $v0 to $s0

jal binary # Jump to subroutine binary

main:

li $v0, 4

la $a0, str1 # Display final prompt

syscall

li $v0, 1

add $a0, $s5, $0 # Display integer

syscall

li $v0, 4

la $a0, newLine # New line

syscall

li $v0, 10 # Terminate program

syscall

binary:

bne $0, $s0, main

li $t0, 2 # Hardcode to 2 for division

div $s0, $t0 # divide user input by 2

mfhi $s2 # Remainder

mflo $s3 # Quotient

addi $sp, $sp, -4 # Decrement by 4

sw $s2, 0($sp) # Store $sp to $s1

addi $s0, $s0, 1

j binary # Jump back

jr $ra

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!