I am trying to convert hexadecimal to an integer, but I keep getting this error.
The error is: Error in : invalid program counter value: 0x00000000
I am using this as a guide 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, 0, 0, 0, 0, 0, 0, 0,
10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10, 11, 12, 13, 14, 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, $t2, $t0 # use it to calcute address in lookup,
lw $t3, 0($t2) # retrieve its integer value,
addu $v0, $v0, $t3 # and add that to the accumulator.
addi $a0, $a0, 1 # Finally, increment the pointer
j loop # and loop.
end:
jr $ra
User contributions licensed under CC BY-SA 3.0