TEXAS 2-STEP TO CALCULATE THE DAY OF THE WEEK FROM 1901 TO 2099 - based on Hans Lachman's Method of Conversion - Strictly adhering to Lachman's Maxim (Complexity is a diseconomy of scale) a reworking of Hans' Method has been coded as a stand-alone function when your only recourse is to call a 68k Asm program via AMS on TI calculators: i.e. no values looked up in tables, files or libraries when executing, no kernel, no system calls, no exception processing, maximal registers to be used with no need to save any. It is for valid Gregorian dates from 1901, as of New Year's Day, to New Year's Eve 2099 A.D. Although using as unsophisticated a processor as a 68k on programmable TI calculators, this reworking of Hans' Method is more efficient than others. It succeeds where other methods do not when computing the day of the week on the lowliest 68k device: calculating the day-number in 16 arithmetic operations, while staying within the register limit for nostub routines. The function below returns a day-number compatible with ISO 8601 when called with the following two absolute addresses: ; WDN, for copying the result from d0 ; DATE, for a basic ISO-format date stamp CYmd as four base-100 bytes ; moveq #0,d0 move.l DATE,d1 move.l d1,d2 ; ; APPLY STEP 1 - LACHMAN'S CONGRUENCE--MOD 100 andi.l #$f00,d1 divu #100,d1 addi.b #94,d1 andi.l #$ff,d1 divu #100,d1 ; MonthIndex in the upper word (mod100) ; ; APPLY STEP 2 swap d1 ; MI add.b d2,d1 ; d + MI addi.l #$3fd00,d2 lsl #8,d2 ; under*2 mod7 - 1 in CCR's X-bit abcd d0,d0 ; under*2 mod7 - 1 rol #6, d2 ; QR/4 + 1 in d2.b add.w DATE,d2 ; Y + QR/4 + 1 in d2.b add.b d2,d0 ; Y + QR/4 + under*2 mod7 add.w d1,d0 ; d + MI + Y + QR/4 + under*2 mod7 ; divu #7,d0 swap d0 ; d0.w becomes the day-number ; ; RETURN THE DAY-NUMBER TO LOCATION WDN move.w d0,WDN rts ; ; Days of the week correspond to day-numbers as: ; Sun=0 Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6 Inputs are to be passed in the proper format: No component of a Date may be passed as a pair of base 10 nibbles. -- REFERENCE gopher://gopherite.org/0/users/retroburrowers/TemporalRetrology/cc/g4