2016-04-13 14 views
0

Ich habe eine Zuordnung, die die Eingabe von einem Benutzer nimmt, um Mittelwert und Bereich von N Werten zu berechnen, die eingegeben werden. Ich habe alles fertig, aber einen Gegenstand, auf dem ich feststecke, den maximalen Wert speicherend. Ich kann anscheinend keine Anweisung finden, um die Eingabe zu testen und dann den Maximalwert zu speichern. Ich habe es den minimalen Wert mit c.lt.s speichern, aber es scheint c.ge.s existiert nicht, also bin ich fest. Hier ist, wo ich so weit bin:vergleichen größer als in MIPS-Assembly

.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 

Antwort

1

Der Befehlssatz nicht c.ge.s braucht, da gibt es auch die bc1f Anweisung. Sie müssen nur in die andere Richtung denken.

Sie mögen:

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

Aber das ist genau das gleiche wie:

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

Beides bietet die gleiche Funktionalität, so dass keine Notwendigkeit für die GE Anweisung gibt. Das gleiche gilt für LE- und GT-Paar.

+0

Ok danke, das macht sehr viel Sinn, aber wenn ich meinen Code zu Ihrem Vorschlag geändert und den Maximalwert gedruckt habe, erfasst er immer noch den min-Wert. Irgendwelche anderen Vorschläge für meinen Code? – Eric

+0

@Eric In der Schleife jedes Mal, wenn Sie eine Zahl lesen, schreiben Sie es in $ F3 und $ F4, wenn ich richtig verstehe, so effektiv Sie immer den letzten Wert nehmen. Sie müssen sie außerhalb der Schleife initialisieren. –

+0

Es hat funktioniert! Dein geiles hah. – Eric