> for example, one can easily see that this algorithm has a Y2K1 > problem It's well past important now, but what problem did you see ? I've got this rough draft, seems to be working (so far) and tried a few 2000 dates For example 1st Jan comes back as day 1, 31st Dec comes back as day 366, 29th Feb as day 60 Anyway, it appears I have got the calculation correct now. Because of the limited range of results there some assumptions and shortcuts that can be made, which will help to streamline it. I decided on an addition method for the /9 because the * 0.111111 I got from PIClist was drifting away from the correct result as the dividend got larger, and speed isn't an issue Thanks for the help. Gives me confidence in the rest of the algorithm Now for the triggy bit ........... ;-) Joe ;1. first calculate the day of the year ; ; N1 =3D floor(275 * month / 9) ; N2 =3D floor((month + 9) / 12) ; N3 =3D (1 + floor((year - 4 * floor(year / 4) + 2) / 3)) ; N =3D N1 - (N2 * N3) + day - 30 date movlw .1 movwf day movlw .1 movwf month movlw high(.2000) movwf year_hi movlw low(.2000) movwf year_lo ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; N1 =3D (275 * month)/9 ; ; month * 275 ;=3D month * 256 + (2 * (month * 8)) + 3 * month movff month,temp1 clrf temp2 movff month,temp3 ;month * 256 clrc rlncf temp1 ;month * 8 rlncf temp1 rlncf temp1 add_m8 clrc ;add month * 8 movfw temp1 addwf temp2 ;once addwf temp2 ;twice movfw month addwf temp2 ;add 3 * month addwf temp2 addwf temp2 call div9 movff temp0,n1_hi ;N1 movff temp1,n1_lo ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; N2 =3D floor((month + 9) / 12) movlw .1 ;pre-set N2 movwf n2 movlw .3 ;if month < April, n2 =3D 0 subwf month,w bnn do_n3 clrf n2 ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; N3 =3D (1 + floor((year - 4 * floor(year / 4) + 2) / 3)) do_n3 movff year_lo,temp1 ;copy movff year_hi,temp0 clrc ;floor(year/4) rrcf temp0 rrcf temp1 clrc rrcf temp0 rrcf temp1 clrc rlcf temp1 ;4 * floor(year/4) rlcf temp0 clrc rlcf temp1 rlcf temp0 movff year_lo,temp3 ;copy movff year_hi,temp2 movfw temp1 ;subtract temp0:temp1 subwf temp3 ;from temp2:temp3 movfw temp0 skpc incfsz temp0,w subwf temp2 ;result in temp2:temp3 movlw .2 ;pre-set N3 movwf n3 movf temp3 ;if result =3D 0 then N3 will be 1 skpnz decf n3 ;else N3 will be 2 ; N =3D N1 - (N2 * N3) + day - 30 clrf temp0 clrf temp1 movf n2 bz n1_sub ;if N2 =3D 0, skip (N2 * N3) movfw n3 ;N2 * N3 addwf temp1 n1_sub movfw temp1 ;N1 - (N2 * N3) subwf n1_lo movfw temp0 skpc incfsz temp0,w subwf n1_hi movfw day ;+ day clrc addwf n1_lo skpnc incf n1_hi movlw .30 ;- 30 subwf n1_lo movlw .0 skpc movlw .1 subwf n1_hi nop ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; Integer /9 ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D div9 comf temp2 ;complement for count up comf temp3 incf temp2 clrf temp0 ;addition counter clrf temp1 add9 movlw .9 addwf temp2 ;add 9 to low byte skpnc incf temp3 ;if *275 low byte > 255 incf temp1 ;increment counter low movf temp1 skpnz ;if <> 0 incf temp0 ;else increment counter high test0 movf temp3 bnz add9 ;if *275 high byte <> 0 movf temp2 skpz ;if month =3D 9 decf temp1 ;else decrement count return --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .