assembly 获取错误:未知系统调用20,装配代码

piztneat  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(137)

这是一个程序在MIPS大会通过QTSpim运行,它需要在一个二次函数给定的数字,并显示抛物线。这是我的第一个低级程序之一,我不是一个好的程序员在任何形式。
所以当我运行程序时,它说未知的系统调用:20.这是我输入的范围上限的数字。我用来测试的数字是系数的1,-1,-6,x轴的-10,10,y轴的-10,20。它应该显示抛物线,但它只显示X和Y轴。然而,这是向前迈出的一步,因为昨天它不会显示任何东西。救命啊!

.text
.globl main
main:
    la $a0,prompt1           # display "Enter the coeficiants of the quadratic: "
    li $v0,4
    syscall

    li $v0,5                 # enter A -> v0
    syscall
    move $t0,$v0             # t0 <--- v0

    li $v0,5                 # enter B -> v0
    syscall
    move $t1,$v0             # t1 <--- v0

    li $v0, 5                # enter C -> v0
    syscall
    move $t2,$v0             # t2 <--- v0

    la $a0,prompt2           # display "Enter the lower (first) and upper (second) bounds of the domain: "
    li $v0, 4
    syscall

    li $v0, 5                # enter lower bound -> v0
    syscall
    move $t3, $v0            # t3 <--- v0

    li $v0, 5                # enter upper bound -> v0
    syscall
    move $t4, $v0            # t4 <--- v0

    la $a0, prompt3          # display "Enter the lower (first) and upper (second) bounds of the range: "
    li $v0, 4
    syscall

    li $v0, 5                # enter lower bound -> v0
    syscall
    move $t6, $v0            # t6 <--- v0

    li $v0, 5                # enter upper bound -> v0
    syscall
    move $t7, $v0            # t7 <--- v0

    move $t8, $t7            # t8 <--- t7
    syscall

step10: move $t9, $t3            # t9 <--- t3
    syscall

step11: mul $t5,$t3,$t0          # t0 * t3 -> t5
    add $t5,$t1,$t5          # t5 + t1 -> t5
    mul $t5,$t5,$t3          # t5 * t3 -> t5
    add $t5,$t5,$t2          # t5 + t2 -> t5

    beq $t8, $t5, point      # if y = f(x) goto point marker

    beqz $t9, yaxis          # if x = 0 goto yaxis

    beqz $t8, xaxis          # if y = 0 goto xaxis

    la $a0,space             # display " "
    li $v0,4
    syscall

step16: beq $t9, $t4, newl       # if x = x-max goto newl

    add $t9, $t9, 1          # $t9 += 1

    j step11

step18: beq $t8, $t6, EOP        # if y = y-min end program

    sub $t8, $t8, 1          # $t8 -= 1

    j step10

EOP:    li $v0,10                # EOP
    syscall

newl:   la $a0,endl              # display "\n"
    li $v0,4
    syscall        
    j step18

point:  la $a0,star              # display "*"
    li $v0,4
    syscall
    j step16

yaxis:  la $a0,bar               # display "|"
    li $v0,4
    syscall
    j step16

xaxis:  la $a0,hyph              # display "-"
    li $v0,4
    syscall
    j step16

    .data
prompt1: .asciiz "Enter the coeficiants of the quadratic: "
prompt2: .asciiz "Enter the lower (first) and upper (second) bounds of the domain: "
prompt3: .asciiz "Enter the lower (first) and upper (second) bounds of the range: "
bar:     .asciiz "|"
star:    .asciiz "*"
hyph:    .asciiz "-"
space:   .asciiz " "
endl:    .asciiz "\n"
o4tp2gmn

o4tp2gmn1#

因此,当你阅读输入时,你使用一个系统调用的返回值作为下一个系统调用的调用号:

[...]
    li $v0, 5                # enter upper bound -> v0
    syscall
    move $t7, $v0            # t7 <--- v0

    move $t8, $t7            # t8 <--- t7
    syscall                  #$v0 is still whatever user input for upper bound

step10: move $t9, $t3        # t9 <--- t3
    syscall                  #$v0 is whatever the last (unspecified) syscall returned

我不知道你想叫什么,所以我帮不了你。我建议在编写汇编之前先用高级语言编写代码。
MARS/SPIM系统调用记录在https://courses.missouristate.edu/KenVollmar/MARS/Help/SyscallHelp.html中-决定您想要哪一个,并将其调用号码放入$v0中,并将其传入参数放入文档指定的寄存器中。

相关问题