我正在尝试使用MIPS在字符串数组中逐个打印字符。但它只打印系统调用。请帮忙
.text
main:
la $a0, myarray
li $v0, 4
syscall
lbu $t0,0($a0)
lbu $t1,0($a0)
lbu $t2,0($a0)
lbu $t3,0($a0)
jr $ra
.data
myarray:.asciiz "Hello\n"
答案 0 :(得分:2)
这绝对可以用更简洁的方式完成,但我希望你明白这个想法!
.data
myarray: .asciiz "Hello\n"
newline: .asciiz "\n"
.text
main:
la $a0, myarray #load address of original string
li $v0, 4 #syscall for print string
syscall
la $s1, myarray #save base address of string
lb $a0, ($s1) #load 1st char byte as arg
jal printchar #print char and return
addi $s1, $s1, 1 #increment address to next char byte
lb $a0, ($s1) #load 2nd char byte as arg
jal printchar #print char and return
addi $s1, $s1, 1 #increment address to next char byte
lb $a0, ($s1) #load 3rd char byte as arg
jal printchar #print char and return
addi $s1, $s1, 1 #increment address to next char byte
lb $a0, ($s1) #load 4th char byte as arg
jal printchar #print char and return
addi $s1, $s1, 1 #increment address to next char byte
lb $a0, ($s1) #load 5th char byte as arg
jal printchar #print char and return
li $v0, 10 #syscall for exit
syscall
printchar: #expects that charater byte is loaded into $a0
li $v0, 11 #syscall for printchar
syscall
la $a0, newline #load address of new line string
li $v0, 4 #syscall for print string
syscall
jr $ra #return to main