home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FASTDA.ZIP / FASTDATE.ASM next >
Encoding:
Assembly Source File  |  1988-04-16  |  2.8 KB  |  110 lines

  1.           page ,132
  2.  
  3. Code      segment byte public
  4.  
  5.           assume  CS:Code
  6.  
  7.           public  CountDays
  8.  
  9. ;type
  10. ;  DateType = record                            +-------------------------+
  11. ;               Year  : integer;                |   File: FastDate.ASM    |
  12. ;               Month : 1 .. 12;                | Author: David N. Dubois |
  13. ;               Day   : 1 .. 31;                |   Date: 1988.04.16      |
  14. ;             end;                              +-------------------------+
  15. ;
  16. ;function CountDays ( Date : DateType ) : longint;
  17. ;
  18. ;{programmed as a far call, for use in a Unit}
  19. ;
  20.  
  21. DateType  struc
  22.  
  23. Year      DW      ?
  24. Month     DB      ?
  25. Day       DB      ?
  26.  
  27. DateType  ends
  28.  
  29. Date      equ     DateType [ BP + 6 ]
  30.  
  31. DaysIntoYear  dw    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
  32.  
  33. CountDays proc    far
  34.  
  35.           PUSH    BP
  36.           MOV     BP, SP
  37.  
  38.           MOV     AX, Date . Year
  39.           CMP     AX, 0
  40.           JLE     NegYear
  41.  
  42.           MOV     BX, AX            ; save year in BX,
  43.  
  44.           MOV     CL, Date . Month
  45.           CMP     CL, 3
  46.           SBB     AX, 0             ; Decrement Year if Month <= 2
  47.           MOV     SI, AX            ; store this for later
  48.           SHR     AX, 1
  49.           SHR     AX, 1             ; Number of Leap Days
  50.  
  51.           MOV     DI, offset DaysIntoYear - 2
  52.           SHL     CL, 1
  53.           XOR     CH, CH
  54.           ADD     DI, CX
  55.           ADD     AX, CS : [ DI ]   ; Get Days Into Year
  56.  
  57.           MOV     CL, Date . Day    ; CH = 0
  58.           ADD     CX, AX            ; Add Days, save in CX
  59.  
  60.           MOV     AX, 365
  61.           MUL     BX                ; Year was saved in BX
  62.           ADD     AX, CX
  63.           ADC     DX, 0
  64.  
  65.           CMP     SI, 1900          ; Check range of Year-LY
  66.           JB      Adjust            ; Don't need to do division
  67.           CMP     SI, 2100          ; if 20th or 21st century
  68.           JB      Magic
  69.  
  70. Adjust:   MOV     DI, AX
  71.           MOV     CX, DX            ; Save answer so far
  72.           MOV     AX, SI
  73.           XOR     DX, DX
  74.           MOV     BX, 100
  75.           DIV     BX
  76.           MOV     BX, AX            ; Save (Yr-ly) div 100
  77.           SHR     AX, 1
  78.           SHR     AX, 1
  79.           ADD     AX, 15            ; Magic Number
  80.           SUB     AX, BX
  81.           CWD
  82.           ADD     AX, DI            ; add back saved value
  83.           ADC     DX, CX
  84.           JMP     Magic
  85.  
  86. NegYear:  MOV     AX, 0FFFFh        ; return maxlongint if
  87.           MOV     DX,  7FFFh        ; Year <= 0.
  88.           JMP     Fini
  89.  
  90. Magic:    ADD     AX,  0F67h        ; Magic Number
  91.           ADC     DX, 0FFF5h
  92.  
  93. Fini:     POP     BP
  94.           RET     4
  95.  
  96. CountDays endp
  97.  
  98. Code     ends
  99.  
  100.          end
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.