??? 02/25/08 07:01 Read: times |
#151374 - Day Of Week calculation Responding to: ???'s previous message |
The routine calcualtes day of week for a given date. Inputs are: r7 - year (00-99 for 2000-2099), r6 - month (01-12), r5 - day (01-31, as appropriate for the given month). Returns day in a (00-06 for Monday-Sunday). No sanity check performed on the input data. No Gregorian correction (that's why it will fail in Y2K1) - this seems to be appropriate for a small embedded application (I wonder how many '51-based calendar-containing appliances will be in use in 2100... ;-) ). Another limitation: incorrect before 1.3.2000.
I have received 6 or 7 absolutely correct answers via mail. Thanks to all for comments. It was very enlightening to read your findings. What came to me as a surprise, in two answers it was pointed out that the table (determining number of days since 1.January in leap year) can be found on google... Submitted to code library. The two instructions which could be spared: - there was no need to move r6 (the month) into accumulator for cjne (to calculate the leap day after 1.3); cjne r6 is sufficient here - the final correction for the starting day, 1.1.2000 - addition of a constant (4) - can be of course done "cheaper", by correcting the table I know there is little effect in optimising such algorithm so aggressively, as it is not used very often in a typical application; but believe me, it was fun... Jan Waclawek |
Topic | Author | Date |
Weekend Quiz | 01/01/70 00:00 | |
This is only Thursday | 01/01/70 00:00 | |
initial conditions? | 01/01/70 00:00 | |
I can't tell... | 01/01/70 00:00 | |
It gives an error | 01/01/70 00:00 | |
it depends on the assembler | 01/01/70 00:00 | |
Jan, I sent an email clue | 01/01/70 00:00 | |
One Instruction... | 01/01/70 00:00 | |
well, I have a plenty of points... | 01/01/70 00:00 | |
Dedicated HW | 01/01/70 00:00 | |
I don\'t understand... | 01/01/70 00:00 | |
could these two be related? | 01/01/70 00:00 | |
Carry bit is used | 01/01/70 00:00 | |
Thanks Craig... | 01/01/70 00:00 | |
next time I will try to obfuscate... | 01/01/70 00:00 | |
Day Of Week calculation![]() | 01/01/70 00:00 |