Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions