Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .include "java_util4.1-2.asm"
- .data
- .text
- li $t0, 0 #comparison for number of times to print
- li $t2, 1 #$t2 will be our line number variable
- li $t3, 0 #$t3 will be number of times printed
- System_out_print("How many times should the message be printed?")
- Keyboard_next_int($t1) #This is the number of times to be printed. Subtract 1 from it repeatedly to get to 0
- sub $t1, $t1, 1 #Since bge counts for equals to as well, take 1 away to count for $t1 = 0 (otherwise 1 extra will print)
- bge $t1, $t0, ifGreaterThan
- ifGreaterThan:
- System_out_print("\n") #start a new line
- printInt($t2) #print line number
- System_out_print(" ") #spacing for format
- add $t2, $t2, 1 #increment line number
- System_out_print("I love Computer Science!!") #print message
- add $t3, $t3, 1
- sub $t1, $t1, 1 #take 1 away from number of times to print
- bge $t1, $t0, ifGreaterThan #check if there's still more times to print
- b endDisplay
- endDisplay:
- System_out_print("\n") #formatting
- System_out_print("Number of times printed: ")
- printInt($t3) #print $t3, the register with number of times printed
- b summationDisplay
- summationDisplay:
- System_out_print("\n")
- System_out_print("The sum of the numbers from 1 to ")
- printInt($t3)
- System_out_print(" is: ")
- li $t4, 0 #the actual summation
- li $t5, 1 #the first number included in the summation. This will be incremented each time
- li $t6, 1 #count for the summation
- b summation
- summation:
- add $t4, $t4, $t5
- add $t5, $t5, 1
- add $t6, $t6, 1
- ble $t6, $t3, summation #if the index of number of numbers added is less than total number of times displayed, continue
- b endProgram
- endProgram:
- printInt($t4)
- li $v0, 10
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement