News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Re: Show date and time

Started by thientansky, May 05, 2006, 03:36:15 PM

Previous topic - Next topic

thientansky

I have written this code but they can not show time in DOS.         
title   CLOCK.ASM
        include macro.asm
scrseg  segment at 0b800h
        org     144
scrvar  label   word
scrseg  ends
;
code    segment para public 'code'
        assume  cs:code,ds:code,ss:code
        org     100h
start:  jmp     main
C_NUM   equ     18
oldi1c  label   dword
oldo1c  dw      ?
olds1c  dw      ?
keycou  dw      C_NUM
scroff  db      0
seco    db      0
minu    db      0
hour    db      0
;
Comment @

@
int1ch  proc    far
        push    ds
        push    cs
        pop     ds
       
        dec     keycou
        jnz     int1c1
        mov     keycou,C_NUM
        inc     seco                   
        cmp     seco,60
        jb      int1c2
        mov     seco,0
        ;
       
        ;
int1c2: call    putscr
int1c1: pop     ds
        jmp     cs:oldi1c
int1ch  endp
;
C_ATTR  equ     8Eh           
strmes  db      '00:00:00'
STRLEN  equ     $-strmes
;
Comment @

@
byt2asc proc
        push    cx
        push    bx
        inc     di
        mov     cx,2
        mov     bl,10
b2a1:   xor     ah,ah
        div     bl
        add     ah,'0'
        mov     [di],ah
        dec     di
        loop    b2a1
        pop     bx
        pop     cx
        ret
byt2asc endp
;
Comment @

@
SEC_IDX equ     6
putscr  proc
        push    es
        push    ax
        push    cx
        push    si
        push    di
        mov     ax,ds
        mov     es,ax
        mov     di,offset strmes+SEC_IDX   
        mov     al,seco
        call    byt2asc
        ;
       
        ;
        mov     ax,scrseg                   
        mov     es,ax                     
        mov     di,offset scrvar
        mov     si,offset cs:strmes
        mov     cx,STRLEN
        cld
putsc2: lodsb
        stosb
        mov     al,C_ATTR
        stosb
        loop    putsc2
        pop     di
        pop     si
        pop     cx
        pop     ax
        pop     es
        ret
putscr  endp
;
stay_res:
mess1   db      'Get system time ...',13,10,36
mess2   db      'Install interrupt vector number 1ch ...',13,10,36
;
Comment @

@
main    proc
        puts    mess1
        mov     ah,2ch                 
        int     21h
        mov     hour,ch
        mov     minu,cl
        mov     seco,dh
        puts    mess2
        call putscr
        mov     ax,351ch               
        int     21h
        mov     oldo1c,bx
        mov     olds1c,es
        mov     dx,offset int1ch     
        mov     ax,251ch
        int     21h
        getch   mess1
        ;
     
        ;
        push    ds                     
        mov     dx,oldo1c             
        mov     ds,olds1c
        mov     ax,251ch
        int     21h
        pop     ds
        exit    0
main    endp
code    ends
        end     start

MichaelW

What OS are you running this under? Under Windows 9x you should not have any problem, but on my Windows 2000 system DOS programs that directly access the alphanumeric display buffer cannot display anything. For running under Windows 2000/XP if you replace the display code in putscr:

        cld
putsc2: lodsb
        stosb
        mov     al,C_ATTR       
        stosb
        loop    putsc2


With something like this:

  MOV AH, 2     ; set cursor position function
  MOV BH, 0     ; page 0
  MOV DX, 0     ; row 0, column 0
  INT 10H
@@:
  MOV AL, [SI]  ; get char
  MOV AH, 0EH   ; write teletype function
  INT 10H
  INC SI        ; increment to next char
  LOOP @B


Then you should be able to check everything other than the display code. If you are running Windows 2000 or XP then one possible method of checking the display code would be to boot from a Windows 9x or DOS boot diskette. You will also need to use this method to check the program as a TSR, if that is what you intend to do.

eschew obfuscation

thientansky

Thank you very much.
But I know that interrupt 2ch is getting system time.
But they don 't display system time in DOS. They display from 00:00:00 to 00:00:59.

MichaelW

You are not calling interrupt 2ch you are calling interrupt 21h, function 2ch, Get Time. The function returns:

CH = Hours in 24-hour format (0 to 23)
CL = Minutes (0 to 59)
DH = Seconds (0 to 59)
DL = Hundredths of a second (0 to 99)

Your code is saving the hours, minutes, and seconds, but converting and displaying only the seconds:

mov di,offset strmes+SEC_IDX
mov al,seco
call byt2asc
...

eschew obfuscation

johnny

Could you confirm that function 2Ch works in windows XP? I did this just for checking but all I got was garbage.

        mov ah,2Ch   
   int 21h
   mov hour,ch
   add hour[0],30h ;To convert to ASCII?
   mov hour[1],'$' ; So the 09h function can work correctly and only display one number.
   
   mov ah,09h
   lea dx,hour
   int 21h