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, minimal registers to be
used, nor the need to save any. It is for valid Gregorian dates from 1582,
as of the Ides of October, to 4004 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
even on the lowliest 68k device: having no need of extra instructions for
data stored in tables as in Babwani's Method nor for redundant operations
as in Zeller's or Tondering's--nor even a C compiler running on a bloated
development system as in Mike Keith's--yet executing in less than 2 dozen
operations, and needing just 2 registers.
The function below returns the corresponding ISO-compatible weekday number
when called with 2 inputs loaded from the following 2 locations:
; WDN, an address for storing result d0
; DATE, basic ISO-format date-stamp cymd as 2 pairs of base-100 bytes
;
movem.l DATE,d1,d2
;
; STEP 1
andi.l #$f00,d1
divu #100,d1
add.w #$7a,d1
andi.l #$7f,d1 ; Month Index
;
; STEP 2
add.b d2,d1
swap d2
add.b d2,d1
swap d2
subi.l #$300,d2
lsl #6,d2
rol #3,d2
addq.b #8,d1
sub.b d2,d1
movi.l #27,d0
lsr d0,d2
add.b d1,d2 ; QRdiv4 + y + MI + d + under+under
;
divu #7,d2
swap d2 ; D2.W BECOMES THE WEEKDAY NUMBER
;
; RETURN THE WEEKDAY NUMBER TO LOCATION WDN
move.b d2,WDN
rts
;
; Days of the week correspond to weekday 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.
--
REFERENCES
http://oz.ccnet.us/dayofweek/
http://www.guernsey.net/~sgibbs/roman.html
http://www.merlyn.demon.co.uk/zel-like.htm#Keith
http://www.tondering.dk/claus/cal/node3.html#SECTION00360000000000000000
babwani-congruence.blogspot.com/search/label/Frequently%20Asked%20Questions
TEXAS 2-STEP 2.2 TO CALCULATE THE DAY OF THE WEEK AS OF 1582 TO 2Y2K2
- via transfiguration of Hans Lachman's Method of Congruence -
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, minimal registers to be
used, nor the need to save any. It is for valid Gregorian dates from 1582,
as of the Ides of October, to 4004 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
even on the lowliest 68k device: having no need of extra instructions for
data stored in tables as in Babwani's Method nor for redundant operations
as in Zeller's or Tondering's--nor even a C compiler running on a bloated
development system as in Mike Keith's--yet executing in less than 2 dozen
operations, and needing just 2 registers.
The function below returns the corresponding ISO-compatible weekday number
when called with 2 inputs loaded from the following 2 locations:
; WDN, an address for storing result d2
; DATE, basic ISO-format date-stamp CYmd as 2 pairs of base-10^2 bytes
;
movem.l DATE,d1,d2
;
; APPLY STEP 1 OF HANS LACHMAN'S METHOD OF CONGRUENCE
andi.l #$f00,d1
divu #100,d1
add.w #94,d1
andi.l #$ff,d1
divu #100,d1 ; Month Index
;
; STEP 2
add.l d2,d1
swap d1
add.b d2,d1
subi.l #$300,d2
lsl #6,d2
rol #3,d2
addq.b #8,d1
sub.b d2,d1
lsr #7,d2
lsr #7,d2
lsr #7,d2
lsr #6,d2
add.w d1,d2 ; QRdiv4 + Y + MI + d + under+under
TEXAS 2-STEP 2.2 TO CALCULATE THE DAY OF THE WEEK AS OF 1582 TO 2Y2K2
- via an elaboration of Hans Lachman's Method of Congruence -
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, minimal registers to be
used, nor the need to save any. It is for valid Gregorian dates from 1582,
as of the Ides of October, to 4004 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
even on the lowliest 68k device: having no need of extra instructions for
data stored in tables as in Babwani's Method nor for redundant operations
as in Zeller's or Tondering's--nor even a C compiler running on a bloated
development system as in Mike Keith's--yet executing in less than 2 dozen
operations, and needing just 2 registers.
The function below returns the corresponding ISO-compatible weekday number
when called with 2 inputs loaded from the following 2 locations:
; WDN, an address for storing result d2
; DATE, basic ISO-format date-stamp CYmd as 2 pairs of base-10^2 bytes
;
movem.l DATE,d1,d2
;
; APPLY STEP 1 (HANS LACHMAN'S METHOD OF CONGRUENCE)
andi.l #$f00,d1
divu #100,d1
add.w #94,d1
andi.l #$ff,d1
divu #100,d1 ; Month Index
;
; STEP 2
add.l d2,d1
swap d1
add.b d2,d1
subi.l #$300,d2
lsl #6,d2
rol #3,d2
addq.b #8,d1
sub.b d2,d1
lsr #7,d2
lsr #7,d2
lsr #7,d2
lsr #6,d2
add.b d1,d2 ; QRdiv4 + Y + MI + d + under+under