home *** CD-ROM | disk | FTP | other *** search
- page ,132
-
- Code segment byte public
-
- assume CS:Code
-
- public CountDays
-
- ;type
- ; DateType = record +-------------------------+
- ; Year : integer; | File: FastDate.ASM |
- ; Month : 1 .. 12; | Author: David N. Dubois |
- ; Day : 1 .. 31; | Date: 1988.04.16 |
- ; end; +-------------------------+
- ;
- ;function CountDays ( Date : DateType ) : longint;
- ;
- ;{programmed as a far call, for use in a Unit}
- ;
-
- DateType struc
-
- Year DW ?
- Month DB ?
- Day DB ?
-
- DateType ends
-
- Date equ DateType [ BP + 6 ]
-
- DaysIntoYear dw 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
-
- CountDays proc far
-
- PUSH BP
- MOV BP, SP
-
- MOV AX, Date . Year
- CMP AX, 0
- JLE NegYear
-
- MOV BX, AX ; save year in BX,
-
- MOV CL, Date . Month
- CMP CL, 3
- SBB AX, 0 ; Decrement Year if Month <= 2
- MOV SI, AX ; store this for later
- SHR AX, 1
- SHR AX, 1 ; Number of Leap Days
-
- MOV DI, offset DaysIntoYear - 2
- SHL CL, 1
- XOR CH, CH
- ADD DI, CX
- ADD AX, CS : [ DI ] ; Get Days Into Year
-
- MOV CL, Date . Day ; CH = 0
- ADD CX, AX ; Add Days, save in CX
-
- MOV AX, 365
- MUL BX ; Year was saved in BX
- ADD AX, CX
- ADC DX, 0
-
- CMP SI, 1900 ; Check range of Year-LY
- JB Adjust ; Don't need to do division
- CMP SI, 2100 ; if 20th or 21st century
- JB Magic
-
- Adjust: MOV DI, AX
- MOV CX, DX ; Save answer so far
- MOV AX, SI
- XOR DX, DX
- MOV BX, 100
- DIV BX
- MOV BX, AX ; Save (Yr-ly) div 100
- SHR AX, 1
- SHR AX, 1
- ADD AX, 15 ; Magic Number
- SUB AX, BX
- CWD
- ADD AX, DI ; add back saved value
- ADC DX, CX
- JMP Magic
-
- NegYear: MOV AX, 0FFFFh ; return maxlongint if
- MOV DX, 7FFFh ; Year <= 0.
- JMP Fini
-
- Magic: ADD AX, 0F67h ; Magic Number
- ADC DX, 0FFF5h
-
- Fini: POP BP
- RET 4
-
- CountDays endp
-
- Code ends
-
- end
-
-
-
-
-
-
-
-
-