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

  1.     page    66,132
  2. ;******************************** TIME1.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. ;----------------------------------------------------------------------------
  13.  
  14. $day_in_month    db    31        ;days in March
  15.         db    30        ;days in April
  16.         db    31        ;days in May
  17.         db    30        ;days in June
  18.         db    31        ;days in July
  19.         db    31        ;days in August
  20.         db    30        ;days in September
  21.         db    31        ;days in October
  22.         db    30        ;days in November
  23.         db    31        ;days in December
  24.         db    31        ;days in January
  25.         db    -1        ;the rest are in February
  26.  
  27. comment 
  28. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  TIME  )
  29. DAYS_TO_DATE - build date for the number of days since Jan 1, 1980.
  30. ;
  31. ; input:  AX =     days elapsed since January 1, 1980 ("numdays")
  32. ;
  33. ; output: DX        year (1980-2099)
  34. ;      AH        month (1-12)
  35. ;      AL        day (1-31)
  36. ;
  37. ;* * * * * * * * * * * * * *
  38. 
  39.     public        days_to_date
  40. days_to_date    proc    far
  41.         apush    bx,si
  42.         add    ax,1401        ;adjust year to 03-01-1976
  43.         xor    dx,dx        ;DX = 0
  44.         mov    bx,1461
  45.         div    bx        ;AX = leap years, DX = remaining days
  46.         mov    si,ax        ;SI = leap years
  47.         xchg    ax,dx        ;AX = remaining days from last ly
  48.         xor    dx,dx        ;DX = 0
  49.         mov    bx,365
  50.         div    bx        ;AX = years since ly, DX = rem days
  51.         cmp    ax,4        ;is this the leap day?
  52.          jne    dys_dte_050    ;  n: skip day/year adjust
  53.         dec    ax        ;  y: actual year = year - 1
  54.         mov    dx,bx        ;     day of year = 365
  55. dys_dte_050:    shl    si,1        ;mul leap year by 4...
  56.         shl    si,1
  57.         add    ax,si        ;AX = years since 03-01-1976
  58.         xchg    dx,ax        ;DX = years since 03-01-1976, AX =days
  59.         xchg    bx,ax        ;BX = remaining days in adjusted year
  60.         mov    si,offset $day_in_month
  61. dys_dte_100:    lods    byte ptr cs:[si] ;get days/month starting with March
  62.         cbw
  63.         sub    bx,ax        ;all days accounted for?
  64.          jnc    dys_dte_100    ;  n: get next month's days, else...
  65.         add    ax,bx        ;AX = day of month - 1
  66.         inc    ax        ;AX = day of month
  67.         sub    si,offset $day_in_month ;SI = month (1=March)
  68.         mov    bx,si        ;BX = month (1=March)
  69.         inc    bx
  70.         inc    bx        ;BX = month (3=March, 14=Feb)
  71.         mov    ah,bl        ;AL = day of month, AH = month (14=Feb)
  72.         add    dx,1976        ;DX = year
  73.         cmp    ah,12        ;is month greater than 12?
  74.          jbe    days_date_050    ;  n: skip month/year adjust
  75.         inc    dx        ;  y: adjust year and
  76.         sub    ah,12        ;    month, (Jan = 1, Dec = 12)
  77. days_date_050:    apop    bx,si
  78.         retf
  79. days_to_date    endp
  80.  
  81. LIBSEG    ENDS
  82.     end
  83.