//---------------------------------------------------------------- // leapyear.s // // This program determines whether or not a year, specified // by the user as a command-line argument, is a "leap" year // in case it occurs in the 21st Century (i.e., 2001-2099). // // assemble using: $ as leapyear.s -o leapyear.o // and link using: $ ld leapyear.o base10io.o -o leapyear // // programmer: // completion: 01 MAR 2006 //---------------------------------------------------------------- .section .data year: .int 2006 # default-value for year msg0: .ascii "your year falls outside the 21st century\n" len0: .int . - msg0 msg1: .ascii "xxxx is a leap year\n" len1: .int . - msg1 msg2: .ascii "xxxx is not a leap year\n" len2: .int . - msg2 .section .text _start: # check for the presence of a command-line argument cmpl $1, (%esp) # argument is missing? je argok # yes, use our default # convert argument to a number, and save it as 'year' # verify that year falls within the 21st century cmpl $2001, year # year preceeds 2001? jb not21 # yes, year not valid cmpl $2099,year # year follows 2099? ja not21 # yes, year not valid argok: # now determine if the year is divisible by 4 # and branch to display the appropriate message isleap: # insert year in message 1 and write it to the display jmp exit # terminate program noleap: # insert year in message 2 and write it to the display jmp exit # terminate program not21: # show the error-message exit: # terminate this program .end # no more to assemble