如何在“##”之后继续我的程序

How do I continue my program after the "##"

所以我制作了一个程序,允许用户输入他们想要的 hello world 数量,在 ## 之后还有另一个功能,但它不会运行,程序会关闭。

        .data
n:      .space 4
msg:    .asciiz "Hello World"
prom1:  .asciiz "How many Hello World want to be printed: "
mychar1:.byte 'a'
out_string:   .asciiz "\nHello World\n"
prom:   .asciiz "Type a number: "
mychar: .byte 'm'
res:    .asciiz "Result is: "
nl:     .asciiz "\n"

        .text
main:   li $v0, 4
        la $a0, msg
        syscall

        li $v0, 4     # print str
        la $a0, nl    # at nl
        syscall
        li $v0, 4     # print str
        la $a0, nl    # at nl
        syscall
        
        li $v0, 4           
        la $a0, prom1       # Load address of first prompt
        syscall 

        li $v0, 5           # Read int from user
        syscall
        
        li $t1, 0       # Load 0 into $t1 for comparison
        move $t0, $v0       # Move the user input to $t0

loop:
        beq  $t1, $t0, end  # Break If Equal: branch to 'end' when $t1 == $t2
        li $v0, 4       
        la $a0, out_string  # Load address of output string
        syscall
        add $t1, $t1, 1     # Increment $t1
        j loop          # Jump back up to loop
        
end:
        li $v0, 10      # Load syscall 10 to indicate end of program
        syscall 


##


        li $v0, 4     # print str
        la $a0, nl    # at nl
        syscall
        
        li $v0, 4     # print str
        la $a0, prom  # at prom
        syscall

        li $v0, 5     # read int
        syscall
        sw $v0, n     # store in n

        li $v0, 4     # print str
        la $a0, res   # at res
        syscall

        li $v0, 1     # print int
        lw $t0, n          # n
        sub $t1, $t0, 1    # n-1
        mul $t0, $t0, $t1  # *
        sra $a0, $t0, 1    # /2
        syscall


        li $v0, 4     # print str
        la $a0, nl    # at nl
        syscall


        li $v0, 4     # print str
        la $a0, nl    # at nl
        syscall

        li $v0, 10    # exit
        syscall

这里这个地方

end:
            li $v0, 10      # Load syscall 10 to indicate end of program
            syscall 

您正在使用 $v0 寄存器中的 10 调用系统调用。 这告诉计算机停止程序。所以在这种情况下,您只是在执行其余代码之前停止程序。

相反,您可以这样做

loop:
        beq  $t1, $t0, endloop  
        li $v0, 4       
        la $a0, out_string  # Load address of output string
        syscall
        add $t1, $t1, 1     # Increment $t1
        j loop          # Jump back up to loop

endloop:
        # Put rest of code here

这只是结束循环并继续的方法。

然后在程序的最后你可以输入系统调用 10