0
#    PROGRAM TO ADD TWO NUMBERS 
        .text           #directive identifying the start of instructions 
        .globl  __start

__start:

    #print
        la      $a0, prompt     #prompt goes in 
        li      $v0, 4         
        syscall

    #read in integer 
        li      $v0, 5          # service code 
        syscall 
        sw      $v0, Num1       # store what was entered 
    #read another 
        li      $v0, 5          # service code 
        syscall 
        sw      $v0, Num2       # store what was entered

    #do the addition
        lw      $t0, Num1 
        add     $a0, $t0, $v0

    #print the sum
        li      $v0, 1          # print integer service call 
        syscall

    #print a final string line 
        la      $a0, final 
        li      $v0, 4 
        syscall

        li      $v0, 10         # exit program service 
        syscall

    #Data segment 

        .data 
Num1:   .word   0 
Num2:   .word   0 
prompt: .ascii  "Please type 2 integers, end each with the " 
        .asciiz "Enter key:\n" 
final:  .asciiz " is the sum.\n"

我正在使用 PCSpim 9.1.9。我试图重新安装 PcSpim 但它仍然无法正常工作。我收到错误“ spim: (parser) syntax error on line 8 file.la $a0, prompt #prompt 进入。

请帮忙

4

0 回答 0