Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # t0 is for current number starting from 1
- # t1 is for user input, ie max loop
- # t2 is for mod by 3
- # t3 is for mod of 5
- # t4 stores 3
- # t5 stores 5
- # t6 stores 0
- # t7 stores 15
- # t8 is for mod of 15
- .data
- instructions: .asciiz "Please enter a number to loop to:"
- feed: .asciiz "FEED"
- babe: .asciiz "BABE"
- feedbabe: .asciiz "FEEDBABE"
- newline: .asciiz "\n"
- .text
- main:
- li $t0, 1 #starting/current number
- li $t4, 3
- li $t5, 5
- li $t7, 15
- # Printing out instructions for user
- li $v0, 4
- la $a0, instructions
- syscall
- # Get the user input
- li $v0, 5
- syscall
- move $t1, $v0
- add $t1,$t1,1 #Loop until one past that number
- Loop:
- beq $t0, $t1, Exit #Exit if they are the same
- #### CHECK IF DIVISIBLE by 15
- div $t0,$t7
- mfhi $t8
- beqz $t8, printfeedbabe
- ### NEXT DIVIDE by 3
- div $t0, $t4 #divide by 3
- mfhi $t2 #store remainder of the above divsion in t2
- beqz $t2,printfeed
- #### THEN DIVIDE by 5
- div $t0, $t5 #divide by 5
- mfhi $t3 #store remainder of the above divsion in t2
- beqz $t3,printbabe
- #### ONLY THEN PRINT NORMAL NUMBER
- li $v0, 1 #Lets system read an int
- move $a0, $t0 #Moves current int to read
- syscall #System call
- #newline --
- li $v0, 4
- la $a0, newline
- syscall
- #-- end newline
- add $t0,$t0,1
- j Loop
- Exit:
- li $v0, 10
- syscall
- printfeedbabe:
- li $v0, 4
- la $a0, feedbabe
- add $t0,$t0,1
- syscall
- #newline --
- li $v0, 4
- la $a0, newline
- syscall
- #-- end newline
- j Loop
- printfeed:
- li $v0, 4
- la $a0, feed
- add $t0,$t0,1
- syscall
- #newline --
- li $v0, 4
- la $a0, newline
- syscall
- #-- end newline
- j Loop
- printbabe:
- li $v0, 4
- la $a0, babe
- add $t0,$t0,1
- syscall
- #newline --
- li $v0, 4
- la $a0, newline
- syscall
- #-- end newline
- j Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement