比MIPS组件中的比较大

时间:2016-04-13 02:48:40

标签: assembly mips

我有一个分配,它接受用户的输入来计算输入的N值的平均值和范围。我已经完成了所有工作,但是我坚持了一个项目,存储了最大值。我似乎无法找到测试输入然后存储最大值的指令。我将最小值存储为c.lt.s,但似乎c.ge.s不存在,所以我被卡住了。这是我到目前为止的地方:

.data 
prompt: .asciiz "Enter how many numbers you plan to submit:  " 
prompt2: .asciiz "\nEnter the following flotaing point values: "
output: .asciiz "\nFloating Point Mean: " 
summ: .asciiz  "\nFloating Point Sum: "
min: .asciiz  "\nFloating Point Min Value: "
space: .asciiz " "
newline: .asciiz "\n"

.text

main:
    li $t0, 0 # counter for prompt

    ###############################################
        #  Print Prompt
        ###############################################
    la $a0, prompt # Load address of prompt from memory into $a0
    li $v0, 4      # Load Opcode: 4 (print string)
    syscall        # Init syscall


    #############################################
        #  Read User Input Into Address of The Int
    #############################################
    li $v0, 5   # Load Opcode: 5 (Read int)
    syscall
        move $t0, $v0   # Storing counter for number of iterations

        #############################################
        #  Convert counter to float
    #############################################
        mtc1 $t0, $f5
        cvt.s.w $f5, $f5

inputLoop:
    beq $t1, $t0, floatingPoint
    ###############################################
        #  Print Prompt2
        ###############################################
    la $a0, prompt2 # Load address of prompt from memory into $a0
    li $v0, 4       # Load Opcode: 4 (print string)
    syscall         # Init syscall

    #############################################
        #  Read User Input into address of the array
    #############################################
    li $v0, 5   # Load Opcode: 5 (Read int)
    syscall
        move $s1,$v0    # move input from $v0 to $s1

        #############################################
        #  Convert input from int to float and add sum
    #############################################
        mtc1 $s1, $f1
        cvt.s.w $f1, $f1
        add.s $f2, $f2, $f1     # sum = sum + input

    #############################################
    #  Find Max & Min
    #############################################
        mov.s $f3, $f1      # min = input
        mov.s $f4, $f1      # max = input
        c.lt.s $f1, $f3
        bc1t minRange
        nop 
        #c.ge.s $f1 $f4
        #bc1t maxRange
        #nop
        next:

        #############################################
        #  Increasing i=0 by 1 until N input
    #############################################
        addi $t1, $t1, 1 #i++
        j inputLoop

floatingPoint:

    ###############################################
        #  Print Sum
        ###############################################
    la $a0, summ    # Load address of summ from memory into $a0
    li $v0, 4       # Load Opcode: 4 (print string)
    syscall         # Init syscall
    mov.s $f12, $f2
    li $v0, 2
    syscall

    div.s $f6, $f2, $f5 # Calculate mean
    ###############################################
        #  Print Mean
        ###############################################
    la $a0, output  # Load address of output from memory into $a0
    li $v0, 4       # Load Opcode: 4 (print string)
    syscall         # Init syscall
    mov.s $f12, $f6
    li $v0, 2
    syscall

    ###############################################
        #  Print Min
        ###############################################
    la $a0, min     # Load address of min from memory into $a0
    li $v0, 4       # Load Opcode: 4 (print string)
    syscall         # Init syscall
    mov.s $f12, $f3
    li $v0, 2
    syscall

exit:
    ###############################################
        #  System Exit
        ###############################################
    li $v0, 10      # system call code for exit
    syscall

minRange:
    mov.s $f3, $f1
    j next
maxRange:
    mov.s $f4, $f1
    j next

1 个答案:

答案 0 :(得分:1)

指令集不需要c.ge.s,因为还有bc1f指令。你只需要考虑另一种方式。

你想:

c.ge.s $f1, $f4 -- is greater or equal?
bc1t somewhere -- if true, jump 

但这与:

完全相同
c.lt.s $f1, $f4 -- is less than?
bc1f somewhere -- if not true, jump

这两者都提供相同的功能,因此不需要GE指令。 LE和GT对也是如此。

相关问题