首页 > 解决方案 > 如何编写一系列 MIPS 指令以将 X 处的浮点数除以 (-4),而不使用任何浮点指令。

问题描述

我不明白如何在不使用任何浮点指令的情况下使用 -4 将浮点加载到整数中。我们假设没有溢出。我问这个问题是因为我真的迷失在这个 Mips 代码中.如果有人能启发我,我将非常感激。另外浮点在X中我需要再次将结果写在X中。

    ##
## template for your assembly programs
##
##

#################################################
#                       #
#       text segment            #
#                       #
#################################################

    .text       
       .globl __start 
__start:        # execution starts here


    # say hello
    la $a0,starting
    li $v0,4
    syscall


    #############################
    # load the fp number in a fp register (just for printing)
    l.d $f0, X
    jal message5a
    # print X
    mov.d $f12, $f0
    li $v0, 3
    syscall


    # load the fp number in an integer register $t0 and $t1 (the operations must be performed on $t0 and $t1)
    mfc1 $t0, $f0
    mfc1 $t1, $f1


    # YOUR CODE GOES HERE

    mtc1 $t0,$f0
    mtc1 $t1,$f1

    jal message5b


    # store the $f0 result in memory
    # print X/(-4)
    mov.d $f12, $f0
    li $v0, 3
    syscall


    #######################
    #######################
    # say good bye
    la $a0,endl
    li $v0,4
    syscall

    # exit call
    li $v0,10
    syscall     # au revoir...


############## messages


message5a:
    la $a0,mes5a
    j message   

message5b:
    la $a0,mes5b
    j message

message:
    li $v0,4
    syscall
    jr $ra

#################################################
#                       #
#           data segment            #
#                       #
#################################################

    .data
starting:   .asciiz "\n\nProgram Starts Here ...\n"
endl:   .asciiz "\n\nexiting ..."


X: .double 10.00


mes5a:  .asciiz "\n\nX: "
mes5b:  .asciiz "\n\nX/4: "
##
## end of file fib.a

标签: assemblyfloating-pointmipsieee-754mips32

解决方案


推荐阅读