In: Computer Science
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )
Sample Execution 1: Enter some number of cents: 118
118 cents is equivalent to 4 quarter(s), 1 dime(s), 1 nickel(s), and 3 penny(s).
Sample Execution 2: Enter some number of cents: -8
Error! You must enter a positive number. Please try again.
(Make sure to write a program where both sample execution should run. )
The required MIPS program is provided below. Please comment if you have any doubt.
MIPS Program:
.text
main:
# Prompt
li $v0, 4
la $a0, inp
syscall
# Read integer
li $v0, 5
syscall
move $t2, $v0
li $s1, 25
div $t2,$s1
mfhi $t0 # Remainder
mflo $t1 # Quotient
# Print string
li $v0, 4
la $a0, output
syscall
# Output result quarters
li $v0, 1
move $a0, $t1
syscall
li $s1, 10
div $t0,$s1
mfhi $t0 # Remainder
mflo $t1 # Quotient
# Output string
li $v0, 4
la $a0, output1
syscall
# Output result dimes
li $v0, 1
move $a0, $t1
syscall
li $s1, 5
div $t0,$s1
mfhi $t0 # Remainder
mflo $t1 # Quotient
# Output string
li $v0, 4
la $a0, output2
syscall
# Output result nickels
li $v0, 1
move $a0, $t1
syscall
# Output string
li $v0, 4
la $a0, output3
syscall
# Output result pennies
li $v0, 1
move $a0, $t0
syscall
# Exit the program
li $v0, 10
syscall
.data
inp: .asciiz "Enter number of cent: "
output: .asciiz "\nNumber of quarters: "
output1: .asciiz "\nNumber of dimes: "
output2: .asciiz "\nNumber of nickels: "
output3: .asciiz "\nNumber of pennies: "
Output:
NOTE : PLEASE GIVE ME UP VOTE. THANK YOU.