Hi all,

I need to write a clock. Like 12:01:20 format. When press a key the clock will increase one second.
Here is the code I try.

.MODEL SMALL
.STACK
.DATA
MSG1 DB 0DH,0AH, 'This is a Clock. Press Key once for one second  $' ;Input integers with in 0-9
MSG2 DB 0DH,0AH, '00:00:00 $'
MSG3 DB  ':$'



SUM1 DB 0 ;second
SUM2 DB 0 ;min
SUM3 DB 0 ;hour

.CODE


BEG: MOV AX,@DATA ;data to AX register
MOV DS,AX ;AX to data segment

LEA DX,MSG1 ;load the address of MSG1
MOV AH,09H ;Display the string of MSG1
INT 21H

LEA DX,MSG2 ;load the address of MSG2
MOV AH,09H ;Display the string of MSG2
INT 21H

MOV AL,0 ;set to 0



MOV CX,59
Second:
MOV AH,01H ;input
INT 21H

SUB AL,30H

INC AL

ADD SUM1,AL

CMP AL,59 ;?

JE Min

LEA DX,SUM3 ;display hour
MOV AH,09H
INT 21H

LEA DX,MSG3 ;display :
MOV AH,09H
INT 21H

LEA DX,SUM2 ;display min
MOV AH,09H
INT 21H

LEA DX,MSG3 ;display :
MOV AH,09H
INT 21H

LEA DX,SUM1 ;display second
MOV AH,09H
INT 21H


Loop Second



MOV CX,59
MOV AL,0 ;set to 0

Min:
MOV AH,01H ;input
INT 21H


INC AL

CMP SUM2,59 ;?

JE Hour

LEA DX,SUM3 ;display hour
MOV AH,09H
INT 21H

LEA DX,MSG3 ;display :
MOV AH,09H
INT 21H

LEA DX,SUM2 ;display min
MOV AH,09H
INT 21H

LEA DX,MSG3 ;display :
MOV AH,09H
INT 21H

LEA DX,SUM1 ;display second
MOV AH,09H
INT 21H


Loop Min


Hour:
MOV AL,0 ;set to 0

MOV AH,01H ;input
INT 21H

INC AL

CMP AL,59 ;?

JE Hour

LEA DX,SUM3 ;display hour
MOV AH,09H
INT 21H

LEA DX,MSG3 ;display :
MOV AH,09H
INT 21H

LEA DX,SUM2 ;display min
MOV AH,09H
INT 21H

LEA DX,MSG3 ;display :
MOV AH,09H
INT 21H

LEA DX,SUM1 ;display second
MOV AH,09H
INT 21H


JMP Second




MOV AH,4CH ;end of program
INT 21H

END BEG

Please help me.


Posted on 2006-05-07 02:35:58 by wkawaii
wkawaii, I've notice your recent posts are related to DOS Interrupts. I would like to point out a good resource called "Ralph Brown's Interrupt List".

Check out THIS THREAD for more information. Good luck with your questions :)
Posted on 2006-05-07 02:43:09 by SpooK
One other thing to help you on your way. We have plenty of good programmers here, but it is indeed much harder to evaluate code written in the way you did. It generally lacks commenting and organization. The reason for commenting and organization is that despite the clarity of the instructions, the programmer's intentions are not always clear. It is the best your way of showing us things through "your eyes".

My suggestion is to reorganize your code in a more intuitive fashion, and comment your code with every detail you can. Comment on the intentions and results of subroutines, interrupts, comparisons... everything. This way you can easily find any logic errors yourself, and others can help you much more quickly.

Help us to help yourself :)
Posted on 2006-05-07 03:53:16 by SpooK
OK...you have got me in a good mood... :)  :lol:
Help us to help yourself

Wouldn't that be:
Help us to help you help yourself
Posted on 2006-05-09 09:44:49 by shantanu_gadgil

OK...you have got me in a good mood... :)  :lol:
Help us to help yourself

Wouldn't that be:
Help us to help you help yourself


Yes and no, because "Help us to help yourself" is ambiguous because it means if he "Helps us", then he can be directly helping himself or we could be helping him.

"Help us to help you help yourself" suggests that helping us only results in us helping him, and not him realizing anything he used to help us can help him without us actually helping him.

I think I will go rest my brain now :cry:
Posted on 2006-05-09 15:30:10 by SpooK