0

MIPS 汇编语言程序,它以交互方式运行以在十进制、二进制和十六进制之间进行转换。

  1. 请求输入数据类型。

  2. 请求输入数据。

  3. 请求输出数据类型。

  4. 输出数据。使用任何算法

这是我作业的要求,我写了下面的代码,让我知道为什么它在运行时会掉线。

这是我的代码,请告诉我为什么它不能正常工作。

#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
4

0 回答 0