Mips程序不打印任何东西

时间:2017-05-25 21:57:28

标签: assembly mips

我在MIPS程序集中有一个程序,它应该在我的消息中交换一个字符。

如果char是'a',它会通过char'b'交换。

所以我有:“holla”,它必须打印“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

但代码不会在火星上打印任何东西。

1 个答案:

答案 0 :(得分:0)

您可能已经写过li $v0, 4,但这并不能说明MIPS中的打印效果如何。这是它应该如何:

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

然后li $v0, 10                   syscall,终止该计划。