Подтвердить что ты не робот

Mips: вычисление суммы двух входов

Кажется очень простым, но я думаю, что моя программа не будет компилироваться, потому что я переписываю регистр $v0? Спасибо заранее

UPDATE: никогда не получилось, мой заказ был неправильным, когда я сделал 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

        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
4b9b3361

Ответ 1

.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

Ответ 2

На самом деле вы перепутались в этом разделе:

#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

Позволяет делать это по строкам:
li $v0, 4 #You are ready to indicate that you want to print string
la $a0, result #you have loaded the address of string now
syscall # Now you will see: "The result is:

Теперь давайте напечатаем номер li $v0, 1
move $a0, $t2
syscall

Сноска: каждый раз, когда вы указываете, что вы используете syscall, вы должны сначала выполнить эту команду. например, если вы хотите что-то напечатать, вы должны выполнить syscall для этого набора, а затем перейти к печати целого числа.

Пример: Допустим, мы хотим напечатать что-то подобное. Номер: 1

Код MIPS будет:
.data prompt: .asciiz "Number : " .text main: #Now lets read a number li $v0, 5 syscall # -> note syscall is done for each instruction #Lets complete printing first li $v0, 4 la $a0, prompt syscall

# У нас есть число в $t0 прямо сейчас  #если мы делаем   li $v0, 1 la $a0, prompt syscall
 # вопрос вопрос и ответ самостоятельно. что будет напечатано.  # номер, который мы ввели, или адрес подсказки  # что вам нужно изменить здесь?

Ответ 3

.text
main:
    #print the msg1
    li $v0 4
    la $a0 msg1
    syscall 

    #read the num 1
    li $v0 5
    syscall

    sw $v0 a1

    #print the msg2
    li $v0 4
    la $a0 msg2
    syscall 

    #read the Num 2
    li $v0 5
    syscall

    sw $v0 a2

    #print the msg3
    li $v0 4
    la $a0 msg3
    syscall 

    lw $t0 a1
    lw $t1 a2


    li $v0 1
    add $a0 $t0 $t1
    syscall  
.data
    msg1: .asciiz "Enter the first number :"
    msg2: .asciiz "Enter the second number :"
    a1 : .word 0
    a2 : .word 0
    msg3: .asciiz  "The sum is = "