.data
mstring: .asciiz "0123456789"
nstring: .asciiz "abcdefghij"
istring: .asciiz "--------------------"
endl: .asciiz "\n"
# i want to print istring=0a1b2c3d4e5f6g7h8i9j
.text
.globl __start
__start:
la $t1, mstring
la $t2, nstring
la $s1, istring
addi $t3,$zero,0 #counter for M
addi $t4,$zero,0 #counter for N
addi $t5,$zero,0 #counter for I
li $t6,20 # max i =20
li $t2,2 #compare for div
li $s4,1 #compare for beq
j Loop
Loop:
beq $t5,$t6,Print
addi $s3,$zero,0 #$s3==0
div $t5,$t2
mflo $s3 # $s3=$t5mod$t6
beq $t3,$zero,Mtogo #if $t5mod$t6==1 go to N
beq $t3,$s4,Ntogo #if $t5mod$t6!=1 go to M
j Loop
Mtogo:
add $s1,$s1,$t5
add $t1,$t1,$t3
lb $s7,0($t1)
sb $s7,0($s1)
addi $t3,$t3,1
addi $t5,$t5,1
Ntogo:
add $s1,$s1,$t5
add $t2,$t2,$t4
lb $s7,0($t2)
sb $s7,0($s1)
addi $t4,$t4,1
addi $t5,$t5,1
Print:
la $a0,0($s1)
li $v0,4
syscall
j Exit
Exit:
li $v0,10
syscall
答案 0 :(得分:0)
你的代码对于这样的工作来说似乎太难了。
怎么样......
.data
mstring: .asciiz "0123456789"
nstring: .asciiz "abcdefghij"
istring: .asciiz "--------------------"
endl: .asciiz "\n"
.text
.globl __start
__start:
la $t1, mstring
la $t2, nstring
la $t3, istring
loop:
lb $t4, 0($t1) # load a byte from mstring
addi $t1, $t1, 1 # increment mstring
sb $t4, 0($t3) # store the byte at istring
beq $t4, $zero, end # if loaded byte == 0, the string was terminated
lb $t4, 0($t2) # load a byte from nstring
addi $t2, $t2, 1 # increment nstring
sb $t4, 1($t3) # store the byte at istring+1
addi $t3, $t3, 2 # increment istring by two, one for each byte we loaded
j loop # loop again
end:
li $v0, 4
la $a0, istring
syscall