我的问题是,有可能以mips的一个字节存储2个字符吗?
如果是,我该怎么做?我已经在互联网上搜索了很多,我找不到怎么做,我也试图复制到一个空的字符串数组,但它不起作用。
.data
string: .asciiz "ola"
string2: .asciiz ""
a: .ascii "a"
a1: .ascii "b"
e: .ascii "e"
e1: .ascii "f"
i: .ascii "i"
i1: .ascii "j"
o: .ascii "o"
o1: .ascii "p"
u: .ascii "u"
u1: .ascii "v"
tam: .word 3
.text
main:
lw $t6, tam #string length
lb $t1, string($t0) #read bit by bit
la $a0, string
la $a1, string2
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, else #if not, saves
else:
lb $s0, e
lbu $s1, e1
beq $t1, $s0, continua
bne $t1, $s0, else2
else2:
lb $s0, i
lb $s1, i1
beq $t1, $s0, continua
bne $t1, $s0, else3
else3:
lb $s0, o
lb $s1, o1
beq $t1, $s0, continua
bne $t1, $s0, else4
else4:
lb $s0, u
lb $s1, u1
beq $t1, $s0, continua
bne $t1, $s0, store
continua:
move $v0, $a0
sb $s1, string($t0) #do the swap
addi $t0, $t0, 1 #+1 in the index
j main
store:
move $v0, $a0
sb $t1, string($t0) #saves
addi $t0, $t0, 1 #+1 in the index
j main
done:
move $a1, $v0
la $a0, string
li $v0, 4
syscall
li $v0, 10
syscall
亲切的问候。