Created
December 18, 2013 05:44
-
-
Save vaskaloidis/8017788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .data | |
| break: .asciiz "\n" | |
| ask: .asciiz "Please enter a random a number greater than 0, or enter a negative number to exit: " | |
| input : .word 100 | |
| list : .word 100 | |
| zero: .float 0 | |
| .text | |
| la $t5, list #$t5 array address for first loop | |
| la $t7, list #t7 array address second loop | |
| li $t0, 1 #SLT Compare to see if print loop number is less than final input | |
| li $t1, 1 #SLT Comparison variable | |
| li $t2, 9 #$t2 has loop comparison to stop at 10 inputs | |
| li $t3, 0 #$t3 is Loop1 Count | |
| li $t4, 0 #$t4 is Loop2 Count | |
| li $t8, 0 | |
| l.s $f8, zero | |
| main: #Main Loop | |
| la $a0, ask #Load String to ask user | |
| li $v0, 4 #Load syscall 4 to print string | |
| syscall #Ask for user input | |
| la $t0, input #Load address of input | |
| li $v0, 6 #Get User Input in $v0 | |
| syscall | |
| mfc1 $t8, $f0 #T8 has current number entered | |
| slt $t1, $zero, $t8 #If User input is less than 0 | |
| beq $t1, $zero, finished | |
| beq $t3, $t2, finished | |
| add $t3, $t3, 1 #Add 1 to counter | |
| mfc1 $t4, $f0 #$t4 has Last number entered | |
| swc1 $f0, ($t5) #set $t5 to user input | |
| add $t5, $t5, 4 #Increment array address position by 4 in $t5 | |
| la $a0, break #Print line break string for input | |
| li $v0, 4 #Syscall code to print string | |
| syscall | |
| j main #Starts from beginning of loop | |
| finished: | |
| li $t1, 1 #Set $t1 back to zero for comparison | |
| move $t8, $t4 | |
| li $t4, 0 | |
| printLoop: | |
| slt $t1, $t4, $t3 #if $t4 < 10 keep $t1=1 else 0... was $t2 | |
| addi $t4, $t4, 1 #Add 1 to loop2 counter | |
| beq $t1, $zero, exit | |
| lwc1 $f12, ($t7) #Load number from array spot | |
| addi $t7, $t7, 4 #Add 4 to $t7 array address to update for next array | |
| mfc1 $t9, $f12 | |
| beq $t9, $zero, printLoop #Dont print if its 0 | |
| slt $t0, $t8, $t9 #Set $t0 to 0 if | |
| beq $t0, $zero, printLoop #Dont print numbers from SLT comparison that are less than final input | |
| li $v0, 2 | |
| syscall #Print the integer | |
| la $a0, break #Print line break | |
| li $v0, 4 #Syscall code to print line break | |
| syscall | |
| j printLoop #Loop to top of printLoop() function | |
| exit: | |
| li $v0, 10 #Syscall code to exit | |
| syscall #Exits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment