【问题标题】:How do you add in mips?你如何添加mips?
【发布时间】:2018-02-03 05:30:47
【问题描述】:

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

我正在使用火星模拟器进行一些辅助项目学习。 我一直对汇编很感兴趣,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

【问题讨论】:

标签: mips mars-simulator


【解决方案1】:

您需要添加一个作为函数名称的标签。在我下面提供的代码中,函数名称是 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

【讨论】:

    猜你喜欢
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多