MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal.
Request input data type.
Request input data.
Request output data type.
Output the data. Use any algorithm
This is the requirement of my homework and I have written the below code , let me know why it drops off while running.
This is the code I have please let me know why it doesn't work properly.
#Provide data variable and data as an input and output
.Data
Input1: .asciiz "Kindly enter the input X:"
Input2: .asciiz "Please provide the number system Y details:"
Output: .asciiz "\nThe result will be R:"
#starts global main
.Globl Main
main:
addi $A0, $zero, 2
addi $A1, $zero, 15
#get the input value dropped by the user
getX:
li $M0, 4
la $N0, Input1
syscall
li $M0, 5
syscall
blt $M0, $zero, getX
move $K0, $M0
#get the value of the number system dropped by the user
getY:
li $M0, 4
la $N0, Input2
syscall
li $M0, 5
syscall
blt $M0, $A0, getY
bgt $M0, $A1, getY
add $K1, $zero, $M0
li $M0, 4
la $N0, Output
syscall
add $N0, $zero, $K0
add $N1, $zero, $K1
jal convert
li $M0, 15
syscall
#perform conversion over the respective input and number system
convert:
addi $sp, $sp, -16
sw $A3, 12($sp)
#Applying counter that is used to check that how many
#times values will be popped up from the stack
sw $A0, 8($sp)
sw $A1, 4($sp)
sw $ra, 0($sp)
add $A0, $zero, $N0
add $A1, $zero, $N1
beqz $A0, end
div $K4, $A0, $A1
rem $K3, $A0, $A1
add $sp, $sp, -4
sw $K3, 0($sp)
add $N0, $zero, $K4
add $N1, $zero, $A1
addi $A3, $A3, 1
jal convert
end:
lw $ra, 0($sp)
lw $A1, 4($sp)
lw $A0, 8($sp)
lw $A3, 12($sp)
beqz $A3, done
lw $N0, 16($sp)
li $M0, 1
syscall
#operation performed
done:
addi $sp, $sp, 20
jr $ra