# days.s -- Determine the number of days in a month, given the month # number (1-12). Assume it's not a leap year. # This program illustrates an if-then-else structure that has an # "OR" condition requiring several consecutive branch instructions. # This program does not perform any error checking -- we assume the # user will be nice and not go outside the range 1-12. .data prompt: .asciiz "Please enter month number (1-12): " intro_output: .asciiz "Your month has " days_string: .asciiz " days.\n" # $s0 = month number # $s1 = number of days in that month .text main: li $v0, 4 # Print the prompt la $a0, prompt syscall li $v0, 5 # input month number, and put into $s0 syscall move $s0, $v0 bne $s0, 2, not_feb # Check to see if it's February (2) li $s1, 28 # Fall thru: Feb has 28 days j output not_feb: beq $s0, 4, thirty # Check for cases April, June, Sept, Nov beq $s0, 6, thirty beq $s0, 9, thirty beq $s0, 11, thirty li $s1, 31 # Fall thru: Other months have 31 days j output thirty: li $s1, 30 # Handle case for 30 days output: li $v0, 4 # Introduce output la $a0, intro_output syscall li $v0, 1 # print the number of days move $a0, $s1 syscall li $v0, 4 # print "days" la $a0, days_string syscall li $v0, 10 # end of program syscall