Hi there, I'm kinda new to making asm programs and i was wondering if you could make a countdown timer where the user is asked for the input and it is displayed in countdown, lets say a max of 59 secs. I was only able to make one that counts down from 9 to 0, is there a way to input 59secs and display the countdown? Using A86 assembler btw.

Here's my code:

MAIN:
		JMP START
		MSG: DB 0A,0D,'ENTER NUMBER OF SECONDS(0-9): $'
		MSG1: DB 0A,0D,'-END- $'

START:	;USER INPUT
		MOV AH,09
		MOV DX,MSG
		INT 21H
SECIN:
		MOV AH,08
		INT 21H
		PUSH AX
		MOV AH,02
		MOV DL,AL
		INT 21H
		MOV AH,02
		MOV DL,0AH
		INT 21H
		POP AX
		MOV BL,AL
		MOV CL,AL
DCOUNT:
		CMP BL,30H
		JE COUNTEND
		PUSH CX
		PUSH BX
		MOV AH,02
		MOV DL,BL
		INT 21H
		POP BX
		DEC BL
		MOV AH,02
		MOV DL,0AH
		INT 21H
		CALL DELAYT
		POP CX
		LOOP DCOUNT
		INT 20H
		
DELAYT:	;DELAY FUNCTION USING SERVICE 2C OF INT 21H
		MOV AH,02CH
		INT 21H
		MOV BH,DH  ; DH has current second
TIMEC:      ; Loops until the current second is not equal to the last, in BH
		MOV AH,02CH
		INT 21H
		CMP BH,DH  ; Here is the comparison to exit the loop continue
		JE TIMEC
		RET
		
COUNTEND:
		MOV AH,09
		MOV DX,MSG1
		INT 21H
		INT 20H

Recommended Answers

All 8 Replies

So you used the ASCII value of the digit character in a count
down variable, limiting the number of seconds from 0-9.
Here's how you could use a two digit number:
For 19 for example, this would come in from the keyboard
as 31h 39h

31h - 30h = 1
39h - 30h = 9

1*10^1 = 10 + 9*10^0 = 19

^ caret symbol represents exponents.
So nineteen is equal to 1 times 10 to the power of 1 plus
9 times 10 to the power of 0.
Anything to the power of zero is 1. Eg, a^0=1

Thnx for replying, so i just have to put the ^caret in my program, I'll go try it out, see if ^caret is supported on a86.

No...
I was implying that you would have to do math.

Here's an example for value 91:

mov al, [char] ; DS:[char]=0x39
sub al, 0x30
xor ah, ah    ; base
mov cx, 0xa ; power
call pow
push ax ; push result
mov al, [char+1] ; DS:[char]=0x31
sub al, 0x30
xor ah, ah
push ax ; push second result
pop ax
pop bx
add ax, bx 
int 0x20 ; terminate

pow:
mov bx, ax
pow_l:
mul bx
dec cx
cmp cx, 0x1
jz pow_e
jmp pow_l
pow_e:
ret

My God, you are awesome, thanks, let me try it out. :D

You can also do it in BCD!
No need for decimal to ASCII conversion!
This is just one way to do this!

mov	bh,'8'
	mov	bl,'4'
	sub	bh,'0'
	sub	bl,'0'
;bh = 10's digit,  bl=1's digit

	mov	al,bl   ; Handle 1's
	sub	al,1
	aas
	mov	bl,al

	mov	al,bh   ; Handle 10's
	sbb	al,0
	aas
	mov	bh,al

	mov	al,bh
	or	al,'0'
                   ; ASCII High digit in AL
	mov	al,bl
	or	al,'0'
                   ; ASCII Low digit in AL

Here's an alternate. Instead of keeping digits separate, keep together in nibbles. Hi nibble, low nibble

mov bh,'8'
	mov bl,'4'
	sub bh,'0'
	sub bl,'0'
;bh = 10's digit,  bl=1's digit

; Now move digits into hi/lo nibbles
	mov al,bh
	shl al,4
	or  al,bl
; al = 99h...01h digits

		; al = bcd value
	sub	al,1
	das	
 ; al = 98h...00 digits
                 mov  cl,al        ; save digits
                 shr al,4
                 or  al,'0'          ; 10's digit
                        ; Print digit
                 mov al,cl
                 and al,0fh
                 or   al,'0'           ; 1's digit
                        ; Print digit

very nice, let me try :D

Sorry I made a mistake in my last post,
it should have been 9*10^1

mov cx, 1
mov ax, 10
call pow
mov bx, 9 ; result is in AX
mul bx

9*10^1=9*10=90

Oh I see what you are saying wildgoose!
With packed BCD's you could use the DAS instruction to count-down
in your program using a decimal value...

mov bh, '8'
mov bl, '0'
sub bh, 0x30
sub bl, 0x30
mov al, bh
shl al, 4 ; Place 8 and 4 into low and hi-nibbles
or al, bl  ; ...
loopz:
dec al     ; a.e. AL=7F
das         ; a.e. AL=79 
or al, al
jnz loopz

That's a neat piece of info.

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.