# Check for leap year (draw the flowchart) # In Gregorian Calendar: "A year is a leap year if it is divisible by 4 with # the exception of century years that are not divisible by 400" # That is: if (Year mod 4 <> 0) then Ordinary # else if (Year mod 100 = 0) and (Year mod 400 <> 0) then Ordinary # else Leap .text .globl __start __start: li $v0, 4 la $a0, Prompt syscall # Print a prompt li $v0, 5 syscall # Read an integer sw $v0, Year # and store it in Year # if (Year mod 4 <> 0) then go to Ordinary lw $t0, Year li $t1, 4 div $t0, $t1 # hi = year mod 4 mfhi $t1 # $t1 = hi bne $t1, $0, Ordinary # if $t1 <> 0 go to Ordinary # if (Year mod 100 = 0) and (year mod 400 <> 0) then go to Ordinary # if (Year mod 100 <> 0) then go to Leap li $t1, 100 div $t0, $t1 # hi = year mod 100 mfhi $t1 # $t1 = hi bne $t1, $0, Leap # if $t1 <> 0 go to Leap # if (Year mod 400 <> 0) then go to Ordinary li $t1, 400 div $t0, $t1 # hi = year mod 400 mfhi $t1 # $t1 = hi bne $t1, $0, Ordinary # if $t1 <> 0 go to Ordinary Leap: lw $a0, Year # Leap year li $v0, 1 syscall # Print Year li $v0, 4 la $a0, LeapMess syscall # Print " is a leap year\n" b End # go to End Ordinary: lw $a0, Year # Ordinary year li $v0, 1 syscall # Print Year li $v0, 4 la $a0, OrdMess syscall # Print " is an ordinary year\n" End: b __start # go to __start (read another year) .data Year: .word 0 Prompt: .asciiz "Enter year: " LeapMess: .asciiz " is a leap year\n" OrdMess: .asciiz " is an ordinary year\n"