Assembly 我该如何摆脱“我该怎么做?”;“从底部掉落”;当我运行这个程序时,在我的MARS编译器中?

Assembly 我该如何摆脱“我该怎么做?”;“从底部掉落”;当我运行这个程序时,在我的MARS编译器中?,assembly,mips,Assembly,Mips,您只需在末尾添加一个syscall 10 #program for inputting an integer and displaying it. .data prompt: .asciiz "Enter a number: " message: .asciiz "\nNumber entered is: " .text li $v0, 4 #prompts the user to enter an integer.

您只需在末尾添加一个syscall 10

#program for inputting an integer and displaying it.

.data
    prompt:  .asciiz "Enter a number: "
    message: .asciiz "\nNumber entered is: "

.text
    li $v0, 4  #prompts the user to enter an integer.
    la $a0, prompt
    syscall


    li $v0, 5   # Reads in the integer
    syscall
    #Store the integer in $t0 since we need $v0 free
    move $t0,$v0

#Display message now.

    li $v0, 4
    la $a0, message     #prints the variable message.
    syscall

#Display the integer

    li $v0, 1
    move $a0,$t0        #move the contents of $t0 into the argument register.
    syscall
$v0寄存器中10的系统调用告诉计算机程序已完成。所以在你的情况下,你会想要

li $v0, 10
syscall
你甚至可以把它贴在像end这样的标签下。这样,无论何时您想要结束程序,您都可以分支到另一端,然后执行完成代码

.data
    prompt:  .asciiz "Enter a number: "
    message: .asciiz "\nNumber entered is: "

.text
    li $v0, 4  #prompts the user to enter an integer.
    la $a0, prompt
    syscall


    li $v0, 5   # Reads in the integer
    syscall
    #Store the integer in $t0 since we need $v0 free
    move $t0,$v0

    li $v0, 4
    la $a0, message     #prints the variable message.
    syscall

    li $v0, 1
    move $a0,$t0        #move the contents of $t0 into the argument register.
    syscall

    li $v0, 10          # Signal end of program
    syscall

最后你需要一个退出系统调用。而且,我找不到任何好的网站来学习汇编语言。如果你们都知道,请在下面发表评论。如果你认为程序写得不好,请指出,因为我刚开始使用这种语言。代码看起来很好,并且有合理的注释。在函数标题下-你的意思是“标签”。例如,如果您只是
beq end
,那么这只是一个普通的分支,而不是一个函数调用。您可以将其视为对noreturn函数的尾部调用(它不关心在
$ra
中获取返回地址),但将其视为对标签的条件转到更有意义。
end:
    li $v0, 10
    syscall