问题描述
我正在尝试将十六进制转换为整数,但是我一直收到此错误。
我以此为指南https://github.com/exercism/mips/blob/master/exercises/hexadecimal/example.mips
.data
getHex: .asciiz "Enter 32-bit hex: "
userInput: .space 8
hexvals: .word 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,15
.text
li $v0,4 # put 4 in register $v0 in order to print whats in the address of $a0
la $a0,getHex # put the address of label getHex in $a0 in order for string with null to be printed
syscall
li $v0,8
la $a0,userInput
li $a1,9
syscall
hex_convert:
li $v0,0 # Reset accumulator to 0.
la $t0,hexvals # Load address of lookup into register.
loop:
lb $t1,0($a0) # Load a character,beq $t1,$zero,end # if it is null then return.
sll $v0,$v0,4 # Otherwise first shift accumulator by 4 to multiply by 16.
addi $t2,$t1,-48 # Then find the offset of the char from '0'
sll $t2,$t2,2 # in bytes,addu $t2,$t0 # use it to calcute address in lookup,lw $t3,0($t2) # retrieve its integer value,addu $v0,$t3 # and add that to the accumulator.
addi $a0,$a0,1 # Finally,increment the pointer
j loop # and loop.
end:
jr $ra
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)