-2

输入基数后的第二个值后出现未知输出错误。

希望你们中的一些人可以识别我的错误:

错误:指令在 0x00400060 [0x00400060] 0x102a0000 beq $1, $10, 0 [hex-0x0040005c] 处引用未定义符号

进展:目前停留在第 2 步。

我想做的是,

1)用户输入一个十进制值

2)用户输入转换类型

3)根据之前选择的转换类型转到所需的子程序

4)显示输出

.data 
prompt: .asciiz "Enter the decimal number to convert: "
base: .asciiz "Select type of base (2 for binary,16 for hexadecimal or 8 for octal): " 
ans1: .asciiz "\nBinary Output is equivalent:"
ans2: .asciiz "\nOctal Output is equivalent:"
ans3: .asciiz "\nHexadecimal Output equivalent:0x" 
result1: .space 8 
.text 
.globl main 
main: 

la $a0, prompt #Display message
li $v0, 4 
syscall
li $v0, 5 
syscall
beq $v0, $zero, Exit #Exit if 0 decimal is entered 
move $t0, $v0   #Else copy value entered into temporaries

askbase:

li $v0, 4
la $a0, base #Display message
syscall
li $v0, 5
syscall
add $t1,$zero,$v0   #Add desired value/base entered into t1

beq $t2,16,hex #if base 16 is entered,goto hex subroutine
beq $t2,8,oct
beq $t2,2,bin

la $a0, ans3 
li $v0, 4 
syscall 
li $t0, 8   # counter 
la $t3, result1 # where answer will be stored 

Hex: 

beqz $t0, Exit  # branch to exit if counter is equal to zero 
rol $t2, $t2, 4 # rotate 4 bits to the left 
and $t4, $t2, 0xf   # mask with 1111 
ble $t4, 9, Sum # if less than or equal to nine, branch to sum 
addi $t4, $t4, 55   # if greater than nine, add 55 

b End 

Sum: 
addi $t4, $t4, 48   # add 48 to result 

End: 
sb $t4, 0($t3)  # store hex digit into result 
addi $t3, $t3, 1    # increment address counter 
addi $t0, $t0, -1   # decrement loop counter 
j Loop 

Exit: la $a0, result1 
li $v0, 4 
syscall 
la $v0, 10 
syscall
4

2 回答 2

0

看起来你在第 29 行有一个错字beq $t2,16,hex应该是beq $t2,16,Hex. 注意 上的大写字母Hex。您还有许多未定义的标签:Loop、oct、bin... 如果没有这些标签,您将遇到问题。将一些设置为占位符是个好主意(直到您定义了它们的子例程)。也许让他们都分支到Exit:. 如果没有实际的标签,汇编器就无法解析您的分支指令。

于 2014-08-07T16:17:38.850 回答
0

你没有在 中存储任何东西$t7,所以没有特别的理由期望它$t7等于 16。

你可能想写的是:

beq $t1,16,hex

因为$t1是您存储基数的寄存器。

但是,我真的不明白您为什么希望以当前代码的结构方式进行跳转。该hex子例程依赖于一些已初始化为某些值的寄存器(如$t0$t3),如果采用该初始化,则将跳过该初始化beq

于 2014-08-07T17:10:55.653 回答