##Write a program that checks if a year is a leap year #The year can be evenly divided by 4; #If the year can be evenly divided by 100, it is NOT a leap year, unless; #The year is also evenly divisible by 400. Then it is a leap year. #It is to have at least 3 functions #no function is to call another function (we haven't done that yet) #at least 1 function must return at least 1 value #at least 1 function must have at least 1 argument #at least 1 function must be used more than once #(these criteria are not mutually exclusive) #arguments must be passed in "a" registers, returned values must be returned in "v" registers #The program is to keep running, asking for additional years until a year of 0 is entered. Any year entered that is a negative number should be flagged as an error. ##So, in Python this can be evaluated in like, 5 lines of code, with the main function being #if ((year%4 == 0 and year%100 != 0) or (year%4 == 0 and year%100 == 0 and year%400 == 0)), and the default should be that the leap year status should be false #so we will have 3 functions: leap_quad, leap_cent, leap_quant, all of which are going to be 'rem'. #if leap_quad = 1 and leap_cent = 0, it's a leap year; and if leap quad= 0, leap_cent = 0, and leap_quant = 0 then it's a leap year. #since we need to use the a registers, our success value is if ( a1 (leap_quad) = 1 AND a2 (leap_cent) = 0 ) OR ( a1 = 1 a2 = 1 a3 = 1 ) .globl main .text main: li $t0, 0 #we define leap-year status to be false li $t1, 4 #value of leap_quad li $t2, 100 #value of leap_cent li $t3, 4000 #value of Leap_quant li $t4, 0 #this is going to be our user input li $t5, 1 #we will need this to compare thing sin eval li $v0, 5 #string output la $a0, quad syscall li $v0, 5 #user integer input store in t0 syscall move $t4, $v0 leap_quad: $a1, 1 #we have to assume it's true, since we're manipulating the exit conditions rem $s0, $t4, $t1 #we see if there is a remainder when we divide by 4 beqz $s0, leap_cent #if there is no remainder, go to the next function, which will test to see if it's divisible by 100 $a1, 0 #if it's not divisible by 4, then this evaluates to false leap_cent: $a2, 1 #assume it's true rem $s1, $t4, $t2 #test to see if there's a remainder when we divide by 100 beqz $s1, leap_quant #if there is a remainder, go to the next function, which will test if it's divisible by 400 $a2, 0 #if it's not divisible by 100, this becomes false j eval #if we don't go to leap_quant, we can skip it because if it's divisible by 4 and not divisible by 100 then it's a leap year anyway leap_quant: $a3, 1 #assume it's true rem $s2, $t4, $t3 #test to see if it's divisible by 400 beqz $s2, eval #if it is divisible by 400, we can go ahead and evaluate it $a3, 0 #if it's not divisible by 400, this becomes false eval: beqz $a1, fail #if it's not divisible by 4, it will fail beqz $a2, pass_final #if it is divisible by 4 AND NOT divisible by 100, then it IS a leap year beq $a1, $t5, pass_1