assembly - Mips:计算两个输入的总和

标签 assembly mips

看起来很简单,但我认为我的程序无法编译,因为我覆盖了 $v0 寄存器?提前致谢

更新:没关系,当我进行系统调用来打印总和时,我的订单是错误的...... 已修复,以防有人需要引用。

.data
prompt1: .asciiz "\n\n Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"

.text

main:

    #t0-to hold first integer
    #t1-to hold second integer
    #t2- used to hold the sum of t$1 and t$2

        #first number

    li $v0, 4 #syscall to print string
        la $a0, prompt1  #address of string to print
        syscall

        li $v0, 5 #syscall to read an integer
        syscall
        move $t0, $v0  #move the number to read into $t0

    #second number
    li $v0, 4
    la $a0, prompt2
    syscall

    li $v0,5        
        syscall
    move $t1,$v0

        add $t2, $t1, $t0 #compute the sum

    #print out sum of $t2
    li $v0, 4       # load syscall print int into $v0
    move $a0, $t2   #move the number to print into $a0
    li, $v0,1
    la, $a0, result
    syscall


Done:

    li $v0, 10    #syscall to exit
        syscall

最佳答案

.data
prompt1: .asciiz "\n\n Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"

              .text
main:
    #t0-to hold first integer
    #t1-to hold second integer
    #t2- used to hold the sum of t$1 and t$2
        #first number
        li $v0, 4 #syscall to print string
        la $a0, prompt1  #address of string to print
        syscall
#
        li $v0, 5 #syscall to read an integer
        syscall
        move $t0, $v0  #move the number to read into $t0
    #second number
    li $v0, 4
    la $a0, prompt2
    syscall
#
    li $v0,5        
    syscall
    move $t1,$v0
#
    #print out sum of $t2
    li $v0, 4
    la $a0, result
    syscall
#
    add $a0, $t1, $t0 #compute the sum
    li $v0, 1
    syscall
#
    li $v0, 10
    syscall

关于assembly - Mips:计算两个输入的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13576801/

相关文章:

c - x86-64 在寄存器中传递参数的顺序

c - 我应该如何推断 x86-64 机器上 addb 指令的 C 数据类型?

algorithm - MIPS 中二叉树中的最长路径

c - Mips32中的Printf和Scanf以及其他问题

assembly - 帧指针的优点是什么?

assembly - 将程序集应用程序与 glibc 链接时,是否可以依赖 RDX 在 main 中的值

汇编 MOV 指令操作数

c - 将 C 翻译成 MIPS 汇编

c - 我如何为 MIPS 架构编译 nfsutils?

assembly - "shift operates on bits individually"是什么意思?