home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / TIME6.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  2KB  |  58 lines

  1.     page    66,132
  2. ;******************************** TIME6.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  TIME  )
  14. DATE_TO_DAYS - get number of days between Jan 1, 1980 and a date.
  15. ;
  16. ; input:  DX        year (1980-2099)
  17. ;      AH        month (1-12)
  18. ;      AL        day (1-31)
  19. ;
  20. ; output: AX        days elapsed since January 1, 1980
  21. ;* * * * * * * * * * * * * *
  22. 
  23.     public        date_to_days
  24. date_to_days    proc    far
  25.         apush    bx,cx,dx,si
  26.         cmp    ah,2        ;is month greater than Feb.?
  27.          ja    date_days_050    ;  y: skip Jan/Feb adjust
  28.         add    ah,12        ;  n: offset Jan/Feb by 1 year
  29.         dec    dx        ;     and dec year
  30. date_days_050:    sub    dx,1976        ;now date is rel to 03-01-1976
  31.         xor    cx,cx        ;CX = 0
  32.         mov    cl,al        ;CX = day of month
  33.         mov    si,dx        ;SI = years since 03-01-76
  34.         xchg    al,ah        ;AL = month
  35.         cbw            ;AX = month
  36.         inc    ax        ;AX = adjusted month
  37.         mov    bx,306        ;div adjusted month by 30.6...
  38.         mul    bx
  39.         mov    bx,10
  40.         div    bx        ;AX = days in year due to months + 122
  41.         add    cx,ax        ;CX = days in year + 122
  42.         mov    ax,si        ;AX = years since 03-01-76
  43.         shr    ax,1        ;div years by 4...
  44.         shr    ax,1        ;AX = leap days
  45.         add    cx,ax        ;CX = days in year + 122 + leap days
  46.         xchg    ax,si        ;AX = years since 03-01-76
  47.         mov    bx,365
  48.         mul    bx        ;AX = days due to years
  49.         add    ax,cx        ;CX = days + 122 + leap days
  50.         sub    ax,1524        ;adjust days: 1401 + 122 + 1
  51.         apop    bx,cx,dx,si    ;          year  month day adjust
  52.         retf
  53. date_to_days    endp
  54.  
  55.  
  56. LIBSEG    ENDS
  57.     end
  58.