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++ - 为什么在我的 C++ mips 反汇编程序中,没有打印出某些内容?

c++ - MIPS速溶

java - MIPS,处理数组和列表(将 Java 代码转换为 MIPS)

c - 在gdb 下调试汇编代码|平台linux

arrays - 使用while循环遍历数组? - MIPS

assembly - MIPS 中的内存访问

assembly - .-main 表达式的含义

assembly - 学习ARM汇编哪个开发板好?

c - 在执行procprob时,b可以是任何数据类型吗?

assembly - .com 文件格式的详细信息是什么?