你如何添加mips?

时间:2018-02-03 05:30:47

标签: mips add mars

首先我知道我提出了很多问题但是自从我上次问到以来我已经走了很长一段路。

我正在使用火星模拟器进行一些项目学习。 我一直对装配感兴趣,mips是我的选择。

无论如何,在我尝试移动我的值并添加它们后,我的程序似乎崩溃了,我无法找出原因。 感谢您的关注和提示将是伟大的。 祝你有个美好的一天

    .data
msg0: .asciiz "enter a number:  \n"
msg1: .asciiz "enter another number:  \n"
result: .asciiz "result is:  \n"

.text
li $v0, 4
la $a0, msg0   #load first message
syscall

li $v0 5
move $t0, $v0  #user input
syscall         #store number


li $v0, 4
la $a0, msg1    #second msg
syscall

li $v0, 5
move $t1, $v0   #second input and store number
syscall

li $v0, 4
la $a0, result  #rsult message
syscall

add $t3,$t1,$t0  #and my problem is here for some reason?
syscall

1 个答案:

答案 0 :(得分:0)

您需要添加一个作为函数名称的标签。在我在下面提供的代码中,函数名称是 ma​​in。此外,最后一个系统调用现在没有任何用处。您需要做的是在通过 li $v0,10 进行最后一次系统调用之前表明您的代码已经完成。

    .data
    msg0: .asciiz "enter a number:  \n"
    msg1: .asciiz "enter another number:  \n"
    result: .asciiz "result is:  \n"

    .text
    .globl main

    main:
    li $v0, 4
    la $a0, msg0   #load first message
    syscall

    li $v0 5
    syscall         
    move $t0, $v0  #first input and store number


    li $v0, 4
    la $a0, msg1    #second msg
    syscall

    li $v0, 5
    syscall
    move $t1, $v0   #second input and store number

    li $v0, 4
    la $a0, result  #result message
    syscall

    add $t3,$t1,$t0  

    move $a0, $t3    
    li $v0, 1        
    syscall     #print answer

    li $v0,10
    syscall
相关问题