hi
can someone tell me how to write a code in assembly language to implement a simple countdown timer (only seconds) display on the command prompt screen?

thanks

Function AH = 2C of the INT 21 Dos interrupt will return the current time.
Seconds are returned in DH.
Here is a simple expample of using this interrupt,
it will print the ascii character 'A' every time a second has passed.
This program is in a infinite loop, modify to suite your needs.

TOP:
MOV AH,2C
INT 21
MOV BH,DH  ; DH has current second
GETSEC:      ; Loops until the current second is not equal to the last, in BH
MOV AH,2C
INT 21
CMP BH,DH  ; Here is the comparison to exit the loop and print 'A'
JNE PRINTA
JMP GETSEC
PRINTA:
MOV AH,02
MOV DL,41
INT 21
JMP TOP

------------------------------
Nicholas Dean Pugh, Coder ........

thanks a lot for the help..
can u tell me how i can wait for a keyboard input from the user while running the timer?
i am making a game where there are 2 players. the first player enters a piece of music.. and the second player has to reproduce the music within a particular time.. so how do i run the timer and wait for the 2nd player's input at the same time?

This code uses the direct I/O functions provided by INT 21h
along with function AH=2Ch of INT 21h.
The code can be used to time how long it took for the user to enter input,
with modification.
Here the code follows, it will allow the user 5 seconds to input a string,
modify to suite your needs.

jmp progstart

text db 0,0,0,0,0,36

progstart:
mov si,offset text ; Move offset of string in data region into SI register
mov ah,02ch        ; Get current second         
int 021h
mov bh,dh          ; Store current second   
readloop:
mov ah,02ch      ; Call function 02C of INT 021 to get new time
int 021h
sub dh,05h         ; Subtract 05 from new second. Giving 5 Secs for input.
                        ; For if old second in BH=05 and new second in DH-5=1,
                        ; four more
                        ; seconds must pass.
cmp bh,dh                    
je endprog         ; Exit when DH is finally equal to BH.
                     ; Example BH=05 and DH - 05 = 05, then DH = 0F and 
                     ; 05 - 0F = Five Seconds
mov ah,06h          ; Function 06h of INT 021 will directly read from the Stdin/Stdout
mov dl,0ffh           ; Move 0ff into the DL register to read from the keyboard
int 21h              
jz readloop           ; If the zero flag of the FLAGS register is set, no key was pressed.
                           ; And this conditional jump will change the offset of IP to the readloop
                           ; label if the zero flag is set, to read again.

mov [si],al            ; If execution made it to here it will move the byte in AL into the offset
                           ; of the string in the data region
inc si                    ; this will increment to the next byte of the string, to store the next
                           ; character
mov bl,[si]            ; Check to see if the end of the string has been reached.
cmp bl,024h
je endprog            ; If so exit.

jmp readloop
endprog:           
mov bx,offset text ; This rest will print out the read in string.
add bx,03h
mov al,024h
mov [bx],al
mov dx,offset text
mov ah,09h
int 21h
int 20h

thanks a lot for the help!!!

hi
can anyone tell me how to write assembly code to program timer1 and timer1 internal interrupt to generate a 50 KHZ square wave on P0.1.

thanks

can anyone tell me how i call the timer in flow chart to countdown timer1 in assembly

Hi there, if I were to implement a timer of 10sec for the user to enter a key as interrupt to the game. How do i structure the code? Should I use the INT 16H or can I use the code that you implemented in this thread using the INT 21H with the change from the offset data to keystroke?

Do hope to get your assistance as soon. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.