##Write a program that asks the user how many sets of 2 numbers they have (n).
##input n sets of 2 numbers.
##Output in how many sets the numbers were equal
## Implement a for loop with an iterator. Also, since there apparently isn't a "is exactly equal," I will need to implement a double condition of
## if not greater than, if not less than
## t0 = number of iterations the user wants, t1 = our internal increment counter, t2 = first number user enters
## t3 = second number user enters, t4 = the count of how many equal t2/t3 pairs there are
.globl main
.text
main:
li $v0, 4 #we're telling the program that we are going to be outputting a string and loading it immediately
la $a0, first_prompt #we're telling the program where to look for our message that we defined at the bottom of the program
syscall #go do it
#now, we should read in an integer as done by the user, with syscall 5
li $v0, 5 #syscall for code 5 (reading in an integer)
syscall #go do it
move $t0, $v0 #moving the stored integer from $v0 to $t0 this will be the number of times our loop executes
#we now stored the value that the user input in $t0
li $t1, 0 #we are storing the value 0 in $t1, which will be our incrementor; every time we complete the loop, we increase it by 1
li $t4, 0 #this is going to be how many "equal" values there are
#syscall #go do it
##at this point, we have determined how many sets of two integers the user will want. now we loop the input and "test if equal" step
loop:
li $v0, 4 #we're telling the program that we are going to be outputting a string and loading it immediately
la $a0, second_prompt #we're telling the program where to look for our message that we defined at the bottom of the program
syscall #go do it
#now, we should read in an integer as done by the user, with syscall 5
li $v0, 5 #syscall for code 5 (reading in an integer)
syscall #go do it
move $t2, $v0 #moving the stored integer from $v0 to $t0 this is our first input value
#we now stored the value that the user input in $t3
li $v0, 4 #we're telling the program that we are going to be outputting a string and loading it immediately
la $a0, third_prompt #we're telling the program where to look for our message that we defined at the bottom of the program
syscall #go do it
#now, we should read in an integer as done by the user, with syscall 5
li $v0, 5 #syscall for code 5 (reading in an integer)
syscall #go do it
move $t3, $v0 #moving the stored integer from $v0 to $t0 this is our second input value
#we now stored the value that the user input in $t3
##for our conditional, we want to compare t2 and t3 for equality (by failing a greater than and less than test) and then incrementing t0,
#and increment $t4 whenever the t2 and t3 are equal
addi $t1, $t1, 1 #increment $t1 (our counter) by 1
beq $t2, $t3, pass #go to pass, increase our "equality" counter and proceed
beq $t0, $t1, fail #if the increment is equal to our initial user init, exit
b loop
pass:
addi $t4, $t4, 1 #increment our "equals" variable by 1
beq $t0, $t1, fail #if the increment is equal to our initial user init, exit
b loop
fail:
li $v0, 4 #we're telling the program that we are going to be outputting a string and loading it immediately
la $a0, exit_1 #we're telling the program where to look for our message that we defined at the bottom of the program
syscall #go do it
move $a0, $t4 #move the value stored $t0 to $a0
li $v0, 1 #tell it we're about to print an integer
syscall #go do it
li $v0, 4 #we're telling the program that we are going to be outputting a string and loading it immediately
la $a0, exit_2 #we're telling the program where to look for our message that we defined at the bottom of the program
syscall #go do it
li $v0, 10 #terminate the program
syscall #go do it
.data
first_prompt:
.asciiz "Please tell me how many sets of two integers you would like to compare: "
second_prompt:
.asciiz "\nPlease input your first number: "
third_prompt:
.asciiz "\nPlease input your second number: "
exit_1:
.asciiz "\nThere were "
exit_2:
.asciiz " entries that had equal values. The program is now terminating."
Comments