Eric
Eric

Reputation: 3

compare greater than in MIPS assembly

I have an assignment that takes input from a user to calculate mean and range from N values entered. I have everything completed but one item that I'm stuck on, storing the max value. I can't seem to find an instruction to test the input and then store the max value. I have it storing the min value with c.lt.s but it seems c.ge.s doesn't exist so I'm stuck. Here's where I'm at so far:

.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

Upvotes: 0

Views: 2545

Answers (1)

Sami Kuhmonen
Sami Kuhmonen

Reputation: 31143

The instruction set doesn't need c.ge.s since there is also the bc1f instruction. You just have to think the other way.

You would like:

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

But this is exactly the same as:

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

Both these provide the same functionality so there is no need for the GE instruction. The same goes with LE and GT pair.

Upvotes: 1

Related Questions