【问题标题】:Mips div.s syntax errorMips div.s 语法错误
【发布时间】:2013-05-22 00:26:02
【问题描述】:

我正在使用 QtSpim 9.9.1 编写我的计算机体系结构课程作业 使用 div.s 运算符时出现语法错误,但使用 div 时没问题。尝试从用户获取浮点数时会出现另一个错误,但在获取整数时也会消失。这是我的代码:

.text
    main:
        # Print "This program solves an equation of style a*x + c = 0, print out the result on console."
        la $a0, hello_msg           # load the address of hello_msg into $a0.
        li $v0, 4                       # 4 is the print_string syscall.
        syscall                         # do the syscall.

        # Print "Enter (a) value please :"
        la $a0, enter_a_msg         # load the address of enter_a_msg into $a0.
        li $v0, 4                       # 4 is the print_string syscall.
        syscall                         # do the syscall.

        ## Get (a) from user, put into $t0.
        li $v0, 6                       # load syscall read_float into $v0.
        syscall                         # make the syscall.
        move $t0, $f0               # move the number read into $t0.////////here got error//////

        # Print "Enter (c) value please :"
        la $a0, enter_c_msg         # load the address of enter_c_msg into $a0.
        li $v0, 4                       # 4 is the print_string syscall.
        syscall                         # do the syscall.

        ## Get (c) from user, put into $t1.
        li $v0, 6                       # load syscall read_float into $v0.
        syscall                         # make the syscall.
        move $t1, $f0               # move the number read into $t1.///////also here 

        # Compute (x), put into $t2.
        neg $t3, $t1                    # get -c into $t3.
        div.s $t2, $t3, $t0             # get x = -c / a into $t2.//// also here Error


        # Print "Value of (x) is :"
        la $a0, result_msg      # load the address of result_msg into $a0.
        li $v0, 4                       # 4 is the print_string syscall.
        syscall                         # do the syscall.

        # Print (x) value .
        move $a0, $t2               # move (x) value into $a0.
        li $v0, 1                       # load syscall print_int into $v0.
        syscall                         # make the syscall.

        li $v0, 10                      # 10 is the exit syscall.
        syscall                         # do the syscall.

# Data for the program:
.data
    hello_msg:      .asciiz "This program solves an equation of style a*x + c = 0,\nprints out the result on console.\n"
    enter_a_msg:    .asciiz "Enter (a) value please :"
    enter_c_msg:    .asciiz "Enter (c) value please :"
    result_msg:     .asciiz "Value of (x) is :"

# end Equation.asm

【问题讨论】:

    标签: mips spim


    【解决方案1】:
    • move $t0, $f0

    要将浮点寄存器转换为整数并将其移至通用寄存器,您应该使用以下内容:

    cvt.w.s $f0, $f0
    mfc1 $t0, $f0
    

    如果您想将 $f0 移动到另一个浮点寄存器,您应该使用例如:

    mov.s $f1,$f0
    

    • div.s $t2, $t3, $t0

    div.s 适用于浮点寄存器 ($f0-$f31),不适用于通用寄存器 ($an$tn$vn 等)。参考MIPS floating-point instruction set list

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-02
      • 2015-07-09
      • 1970-01-01
      • 2018-07-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多