Advertisement
Guest User

Untitled

a guest
May 1st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # t0 is for current number starting from 1
  2. # t1 is for user input, ie max loop
  3. # t2 is for mod by 3
  4. # t3 is for mod of 5
  5. # t4 stores 3
  6. # t5 stores 5
  7. # t6 stores 0
  8. # t7 stores 15
  9. # t8 is for mod of 15
  10. .data
  11.     instructions:   .asciiz "Please enter a number to loop to:"
  12.     feed:   .asciiz "FEED"
  13.     babe:   .asciiz "BABE"
  14.     feedbabe:   .asciiz "FEEDBABE"
  15.     newline:    .asciiz "\n"
  16. .text
  17.  
  18.     main:
  19.         li $t0, 1 #starting/current number
  20.         li $t4, 3
  21.         li $t5, 5
  22.         li $t7, 15
  23.    
  24.         # Printing out instructions for user
  25.         li $v0, 4
  26.         la $a0, instructions
  27.         syscall
  28.        
  29.         # Get the user input
  30.         li $v0, 5
  31.         syscall    
  32.         move $t1, $v0
  33.         add $t1,$t1,1 #Loop until one past that number
  34.         Loop:
  35.             beq $t0, $t1, Exit  #Exit if they are the same
  36.             #### CHECK IF DIVISIBLE by 15
  37.             div $t0,$t7
  38.             mfhi $t8
  39.             beqz $t8, printfeedbabe
  40.             ### NEXT DIVIDE by 3
  41.             div $t0, $t4    #divide by 3
  42.             mfhi $t2    #store remainder of the above divsion in t2
  43.             beqz $t2,printfeed
  44.             #### THEN DIVIDE by 5
  45.             div $t0, $t5    #divide by 5
  46.             mfhi $t3    #store remainder of the above divsion in t2
  47.             beqz $t3,printbabe
  48.             #### ONLY THEN PRINT NORMAL NUMBER
  49.             li $v0, 1 #Lets system read an int
  50.             move $a0, $t0   #Moves current int to read
  51.             syscall #System call
  52.             #newline --
  53.             li $v0, 4
  54.             la $a0, newline
  55.             syscall
  56.             #-- end newline
  57.             add $t0,$t0,1
  58.             j   Loop
  59.        
  60.  
  61.         Exit:
  62.             li $v0, 10
  63.             syscall
  64.        
  65.         printfeedbabe:
  66.             li $v0, 4
  67.             la $a0, feedbabe
  68.             add $t0,$t0,1
  69.             syscall
  70.             #newline --
  71.             li $v0, 4
  72.             la $a0, newline
  73.             syscall
  74.             #-- end newline
  75.             j   Loop
  76.         printfeed:
  77.             li $v0, 4
  78.             la $a0, feed
  79.             add $t0,$t0,1
  80.             syscall
  81.             #newline --
  82.             li $v0, 4
  83.             la $a0, newline
  84.             syscall
  85.             #-- end newline
  86.             j   Loop
  87.        
  88.         printbabe:
  89.             li $v0, 4
  90.             la $a0, babe
  91.             add $t0,$t0,1
  92.             syscall
  93.             #newline --
  94.             li $v0, 4
  95.             la $a0, newline
  96.             syscall
  97.             #-- end newline
  98.             j   Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement