2017-05-25 137 views
1

我有一个MIPS程序集中的程序,它应该在我的消息中交换一个字符。Mips程序不打印任何东西

如果字符是'a',它会被字符'b'交换。

所以我有:“霍拉”,它必须打印“hollb”。

有我有什么:

.data 
string: .asciiz "holla" 
a: .ascii "a" 
a1: .ascii "b" 
tam: .word 5 

.text 

main: 
lw $t6, tam #string length 
lb $t1, string($t0) #read bit by bit 

lb $s0, a #save in register the char that we want to search 
lb $s1, a1 #save in register the char that we want to replace 

beq $t0, $t6, done 

beq $t1, $s0, continua #if the char of (bit by bit) its like the char of chars, swap it 
bne $t1, $s0, store #if not, saves 

continua: 
sb $s1, string($t0) #do the swap 
addi $t0, $t0, 1 #+1 in the index 
j main 

store: 
    sb $t1, string($t0) #saves 
    addi $t0, $t0, 1 #+1 in the index 
    j main 
done: 
    li $v0, 4 
    li $v0, 10 
    syscall 

但代码犯规打印我在火星什么。

+2

为什么_would_它会打印任何东西?您执行的唯一系统调用是10(即'退出')。另外,你正在假设你可能不应该做的'$ t0'的初始值。在使用它们的值之前初始化所有寄存器。 – Michael

回答

0

您可能已经写过li $v0, 4,但这在MIPS的打印工作中无法说明。下面是它应该如何一直:

li $v0, 4 #to print a string la $a0, string #load string's address syscall

然后li $v0, 10 syscall,终止程序。