TEXAS TWO-STEP CALCULATION OF THE DAY FOR DATES 00040301 TO 42461231
- using Hans Lachman's Method of Conversion as optimised below -
Strictly adhering to Lachman's Maxim (Complexity is a diseconomy of scale)
this method was designed to run sublimely 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 valid for (historical) Julian dates
as of 1.iii.IV and for Gregorian ones from 1.iii.MCM to 28.ii.MMCC.
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 in under a dozen arithmetic operations.
The function below returns a day-number compatible with ISO 8601 when
called with the following three addresses:
; WDN, for storing result d0
; FLAG, to choose between sets of calendars (121 or 122 as below)
; DATE, for a basic ISO format year0mDA date stamp as binary word&byte&byte
;
move.l DATE,d0
move.l d0,d1
moveq #18,d2
;
; APPLY STEP 1 - LACHMAN'S CONGRUENCE--MOD 128
andi.l #$f00,d1
divu #100,d1
addi.w FLAG,d1
andi.l #127,d1 ; MonthIndex
;
; APPLY STEP 2
add.b d0,d1
add.w DATE,d1
subi.l #$300,d0
lsr d2,d0
add.w d1,d0
divu #7,d0
swap d0 ; d0.w contains 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
The code is streamlined such that parameters are to be passed to it in
proper format. For example, one must pass a flag of 122 for Gregorian
dates as of 1.iii.MCM until 28.ii.MMC, or 121 from 1.iii.MMC until
28.ii.MMCC; as well as 121 for historical Julian dates where years
start on 1.i, and years divisible by 4 are leap years. Some historians
claim that IV A.D. was not a leap year, so that a flag of 121 thereby
applies for Julian dates only as of 1.iii.IV. It still applies for
29.ii.MCM--a valid date for Orthodox countries like Russia & Greece.
This function thereby gives compleat valid historical continuity of
date conversion for SOMEWHERE on the planet for all days from 1.iii.IV
to 28.ii.MMCC. Otherwise, it still gives valid conversions for Julian
dates on the Orthodox calendar until 31.xii.MMMMCCXLVI A.D.
--
REFERENCES
http://en.wikipedia.org/wiki/TI-89_series
http://www.guernsey.net/~sgibbs/roman.html
gopher://gopherite.org/0/users/retroburrowers/TemporalRetrology/cc/jg
Response:
text/plain