Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .globl main
- .text
- main:
- li $v0, 4 #prompt user for number of pairs
- la $a0, prompt_number
- syscall
- li $v0, 5 #read in the number
- syscall
- move $s0, $v0 #store value in t0
- loop:
- li $v0, 4 #ask for and store the first number in t1
- la $a0, prompt_pair_1
- syscall
- li $v0, 5 #read in the number
- syscall
- move $t1, $v0
- li $v0, 4 #ask for and store the second number in t2
- la $a0, prompt_pair_2
- syscall
- li $v0, 5 #read in the number
- syscall
- move $t2, $v0
- add $s1, $s1, 1 #increment s1 every time we receive a pair of numbers
- #our algorithm is going to be: double the second number, subtract it from the first, if the answer is 0 or below 0, we increment our counter
- add $t2, $t2, $t2 #double the second number
- sub $t1, $t1, $t2 #subtract the second number from the first and store it in place of the first number
- blez $t1, bigger #jump to bigger
- beq $s0, $s1, exit #if the counter is equal to our prompt value, move to exit the program
- j loop #else jump to the start of the loop
- bigger:
- add $t3, $t3, 1 #increment the "greater" counter once
- beq $s0, $s1, exit #if the counter is equal to our prompt value, move to exit the program
- j loop #else jump to the start of the loop
- exit:
- la $a0, terminate
- move $a0, $t3 #put the integer into a0
- li $v0, 1 #output the integer
- syscall
- li $v0, 10 #end the program
- syscall
- .data
- prompt_number:
- .asciiz "Please input the total number of pairs you will have: "
- prompt_pair_1:
- .asciiz "Please enter the first number of your pair: "
- prompt_pair_2:
- .asciiz "Please enter the second number of your pair: "
- terminate:
- .asciiz "The program has finished executing. The condition of the second number being at least twice as big as the first has happened this many times: "
Advertisement
Add Comment
Please, Sign In to add comment