home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n21.zip / CKDATE.ASM < prev    next >
Assembly Source File  |  1991-10-31  |  2KB  |  91 lines

  1. DAYSINMONTH PROCEDURE
  2.  
  3.  
  4. .model medium, basic
  5.  
  6. .code
  7.  
  8. ; This procedure determines the number of days in a given month 
  9. ;
  10. ; Receives: Arg1 month in question
  11. ;           Arg2 year
  12. ; Returns:  AX number of days in month
  13. ; Formula used to determine number of days in month:
  14. ;           if month > 7 and evenly divisible by 2 then days = 31 
  15. ;           if month <= 7 and not evenly divisible by 2 then days = 31 
  16. ;           if month > 7 and not evenly divisible by 2 the days = 30 
  17. ;           if month < 7 and evenly divisible by 2 then days = 30  
  18.  
  19. DaysInMonth Proc Arg1:Word, Arg2:Word
  20.  
  21.     mov  bx,arg1             ;month
  22.     mov  ax,[bx]             ; in AX,
  23.     mov  bx,arg2             ;year
  24.     mov  cx,[bx]             ; in CX
  25.     cmp  ax,2                ;Is the month Feb?
  26.     jz   feb                 ;Yes, go test for leap year
  27.     push ax
  28.     shr  ax,1                ;No, divide AX by 2
  29.     jc   not_div_by_2
  30.  
  31. div_by_2:
  32.     pop  ax                  ;Get original month
  33.     sub  ax,7                ;Compare month to 7
  34.     js   days_equal_30       ;Month is < 7
  35.  
  36. days_equal_31:
  37.     mov  ax,31
  38.     jmp  done
  39.  
  40. days_equal_30:
  41.     mov  ax,30
  42.     jmp  done
  43.  
  44. not_div_by_2:
  45.     pop  ax                  ;Get original month
  46.     cmp  ax,7                ;Compare month to 7
  47.     jbe  days_equal_31
  48.     jmp  days_equal_30
  49.  
  50. feb:
  51.     mov  ax,cx               ;Year in AX
  52.     push ax                  ;Save year for future tests
  53.     mov  bx,100              ;First test, is year evenly
  54.     div  bx                  ; divisible by 100
  55.     or   dx,dx
  56.     jz   check400            ;Yes, check divisibility by 400
  57.  
  58.     pop  ax                  ;No, get year again in AX
  59.     mov  bx,ax               ;Put year in BX for comparison
  60.     mov  cl,2
  61.     shr  ax,cl               ;Divide year by 4
  62.     shl  ax,cl               ; then multiply by 4
  63.     cmp  ax,bx               ;Did we get original year back?
  64.     jz   isleapyear          ;Yes, we have a leap year
  65.     jmp  notleapyear         ;No
  66.  
  67. check400:
  68.  
  69.     pop  ax                  ;Get year back in AX
  70.     mov  bx,400
  71.     div  bx                  ;Divide it by 400
  72.     or   dx,dx               ;Did it divide evenly
  73.     jz   isleapyear          ;Yes, we have a leap year
  74.  
  75. notleapyear:
  76.     mov  ax,28               ;28 = no leap year
  77.     jmp  done
  78.  
  79. isleapyear:
  80.     mov  ax,29               ;29 = leap year
  81.  
  82. done:
  83.     ret
  84.  
  85. DaysInMonth Endp
  86. End
  87.  
  88.  
  89.  
  90.  
  91.