Mips 我想打印istring=0a1b2c3d4e5f6g7h8i9j,但我的程序无法运行

Mips 我想打印istring=0a1b2c3d4e5f6g7h8i9j,但我的程序无法运行,mips,Mips,对于这样的工作,您的代码似乎太难了 那么 .data mstring: .asciiz "0123456789" nstring: .asciiz "abcdefghij" istring: .asciiz "--------------------" endl: .asciiz "\n" # i want to print istring=0a1b2c3d4e5f6g7h8i9j .text .globl __start __start:

对于这样的工作,您的代码似乎太难了

那么

.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

到底什么是“不起作用”意思是?当我尝试执行它时,我看到:异常发生在PC=0x00400074数据/堆栈读取中的错误地址:0x00000002尝试在0x80000180执行非指令请看我的答案。我尝试了它,它说:异常发生在PC=0x00400038数据/堆栈读取中的错误地址:0x00000000尝试执行非指令在0x80000180@nikosio7错误一定在别处。我尝试了代码(查看我的编辑),它工作正常,打印了请求的字符串。我再次尝试,它说:指令引用0x00400014[0x00400014]0x0000000JAL 0x00000000[main]处未定义的符号;188:日航main@nikosio7您可能已经从错误消息中注意到,这与我写的内容无关,而是与您写的内容有关。我没有
main
标签。
.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