I want to convert an integer value into a character, and then want to print that character as a 'character'.
# convert an word into bye and print it
.data
integer: .word 1
.text
la $a0, integer # load the address of 'integer' into $a0
lw $t0, ($a0) # load the value stored in address
addi $t0, $t0, 31 # convert digit to a character
# print the character
move $a0, $t0 # prepare the value for printing
li $v0, 4 # syscall value for a character
syscall
# exit program
li $v0, 10
syscall
Output:
Assemble: assembling number_to_character.asm
Assemble: operation completed successfully.
Go: running number_to_character.asm
Error in number_to_character.asm line 13: Runtime exception at 0x00400018:
address out of range 0x00000020
Go: execution terminated with errors.
The programs seems to be not working. Probably, because of the size difference between an integer (word) and a character (byte).
User contributions licensed under CC BY-SA 3.0