\ Calculating the day of the week for a given date \ ================================================ \ mdfs.net/Info/Comp/ARM/ProgTips/Date/DayOfWeek - J.G.Harston \ \ Based on code at http://6502.org/source/misc/dow.htm by Paul Guertin. \ \ This routine works for any date from 1900-01-01 to 2155-12-31. \ No range checking is done, so validate input before calling. \ \ It uses the formula \ Weekday = (day + offset[month] + year + year/4 + fudge) mod 7 \ offset[month] adjusts the day count so 1st of a month is effectively \ the (lastday+1)-th of the previous month. \ fudge is -1 when after 2099 as 2100 is not a leap year. \ \ On entry R0=day, 1..31 \ R1=month, 1..12 \ R2=year-1900, 0..255 \ On exit R0=day of week 0..6 for Sun..Sat, needs incrementing with \ ADD R0,R0,#1 after calling to become standard 1..7 range \ Size 76 bytes (68 bytes if year 1900 reduction removed) \ .DayOfWeek0 SUB R2,R2,#1900 AND &FF00 :\ Reduce year 1900+y to y SUB R2,R2,#1900 AND &00FF .DayOfWeek CMP R1,#3 SUBLOS R2,R2,#1 :\ If Jan or Feb, decrement year MOVMI R2,#5 :\ 1900 is not a leap year ADD R0,R0,R2 :\ R0=day+year ADD R0,R0,R2,LSR #2 :\ R0=day+year+year/4 CMP R2,#2100-1900 :\ 2100 is not a leap year SUBHS R0,R0,#1 :\ R0=day+year+year/4-(year>2099) ADR R2,dowMonths-1 :\ R2=>month offsets LDRB R1,[R2,R1] :\ R1=month offset ADD R0,R0,R1 :\ R0=day+year+year/4-(year>2099)+offset[month] .dowMOD7 SUBS R0,R0,#7 BCS dowMOD7 :\ Reduce MOD 7 ADD R0,R0,#7 :\ Restore for last SUB, change to ADD R0,R0,#8 MOV PC,R14 :\ to return 1..7 : .dowMonths EQUB 1:EQUB 4:EQUB 3:EQUB 6 :\ Month offsets EQUB 1:EQUB 4:EQUB 6:EQUB 2 EQUB 5:EQUB 0:EQUB 3:EQUB 5 \