我想将整数值转换为字符,然后将该字符打印为“字符”。
# 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
输出:
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.
程序似乎无法正常工作。可能是由于整数(单词)和字符(字节)之间的大小差异。