home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / datetime / cmosdate / time_is.asm < prev    next >
Assembly Source File  |  1992-12-01  |  5KB  |  103 lines

  1. ;; TIME_IS.ASM - simple CMOS time display program.
  2. ;;
  3. ;; This program can be assembled using the A86 or TASM assemblers 
  4. ;;
  5. ;; Not tested with Masm, should work?
  6. ;;
  7. ;; This code is "PUBLIC DOMAIN"
  8. ;;
  9. ;; by William Cravener 11/28/92
  10. ;;
  11. ;---------------------------------------------------------
  12. ;;
  13. code                    SEGMENT
  14. ASSUME          cs:code, ds:code, es:code, ss:code
  15. ORG             100h                    ; COM files begin here
  16. start:
  17.         jmp     time                    ; go show the current system time
  18. ;;
  19. ;;==========================================================================
  20. ;;
  21. say_time                DB      0dh, 0ah, 'Time is '
  22. table                   DB      '00:00:00', 0dh, 0ah
  23. ;;
  24. ;;==========================================================================
  25. ;;  retrieve and display time
  26. time:
  27.         mov     ah, 2                   ; function 2
  28.         int     1ah                     ; BIO's get CMOS time
  29.         push    dx                      ; save SECONDS 
  30.         push    cx                      ; save MINUTES
  31.         cmp     ch, 12h                 ; past noon ?
  32.         jb      meridian
  33.         sub     ch, 12h                 ; if yes, adjust.
  34. meridian: 
  35.         cmp     ch, 0                   ; midnight ?
  36.         jnz     notmidnight
  37.         mov     ch, 12h                 ; if yes, adjust.
  38. notmidnight:
  39.         mov     al, ch                  ; CH = HOURS/unpack_bcd uses AL
  40.         call    unpack_bcd              ; go upack BCD value
  41.                                         ; result returned in AL
  42.         call    make_it_ascii           ; make em ASCII characters
  43.         mov     [table+0], al           ; store upper 
  44.         mov     [table+1], ah           ; store lower
  45.         pop     cx                      ; retrieve MINUTES
  46.         mov     al, cl                  ; CL = MINUTES/unpack_bcd uses AL
  47.         call    unpack_bcd              ; go upack BCD
  48.                                         ; result returned in AL
  49.         call    make_it_ascii           ; make em ASCII characters
  50.         mov     [table+3], al           ; store upper 
  51.         mov     [table+4], ah           ; store lower
  52.         pop     dx                      ; retrieve SECONDS
  53.         mov     al, dh                  ; DH = SECONDS/unpack_bcd uses AL
  54.         call    unpack_bcd              ; go upack BCD
  55.                                         ; result returned in AL
  56.         call    make_it_ascii           ; make em ASCII characters
  57.         mov     [table+6], al           ; store upper 
  58.         mov     [table+7], ah           ; store lower
  59. ;;
  60.         mov     si, OFFSET say_time     ; point to "Time is"
  61.         mov     ah, 0eh                 ; use BIO's teletype service
  62.         mov     bh, 0                   ; page 0
  63.         mov     cx, 10                  ; 10 characters
  64. loop1:
  65.         lodsb                           ; get character
  66.         int     10h                     ; BIO's interrupt
  67.         loop    loop1                   ; all 10 characters
  68. ;;
  69.         mov     si, OFFSET table        ; point to time table
  70.         mov     ah, 0eh                 ; use BIO's teletype service
  71.         mov     bh, 0                   ; page 0
  72.         mov     cx, 10                  ; 10 characters
  73. loop2:
  74.         lodsb                           ; get character
  75.         int     10h                     ; BIO's interrupt
  76.         loop    loop2                   ; all 10 characters
  77.  
  78.         int     20h                     ; exit to DOS
  79. ;---------------------------------
  80. ; unpacked binary result returned in AL
  81. unpack_bcd:
  82.         mov     ch, al                  ; save low digit in CH
  83.         and     ch, 0fh                 ; by clearing the high
  84.         mov     cl, 4                   ; shift high digit
  85.         shr     al, cl                  ; to low bits
  86.         mov     cl, 0ah                 ; and multiply by 10
  87.         mul     cl                      ; multiply
  88.         add     al, ch                  ; add the digits
  89.         ret
  90. ;---------------------------------
  91. make_it_ascii:
  92. ; binary value in AL
  93.         xor     ah, ah                  ; zero out AH
  94.         mov     cl, 0ah                 ; divide
  95.         div     cl                      ; by 10
  96.         add     al, 30h                 ; make it a
  97.         add     ah, 30h                 ; ASCII value
  98.         ret
  99. ;---------------------------------
  100. code                    ENDS
  101. END             start
  102.  
  103.