1

I have a project of making a stop watch in assembly language using masm. The stop watch starts on program startup and continues on. I want to implement feature like stop,pause and play. I can't ask user to input any value when the stopwatch is running as it is a loop and on each iteration the text on console updates every passing millisecond. I was thinking that it would be nice that before each iteration of the loop, I could check keyboard buffer or something like that which indicates that a certain key was pressed and use that value to detect and stop,puase or play the stop watch. I know its not true asynchronous solution but I can't find anything descriptive regarding my issue over the Internet.

My Code for stop watch: I want to do what I asked before doing call clrscr

    Include Irvine32.inc
.data
milisec dword 0
sec dword 0
min dword 0
milidiv dword 100
secdiv  dword 60
colon   byte  " : " , 0
.code
main proc


PR :
call clrscr

mov eax, min
call WriteDec


mov edx, offset colon
call WriteString

mov eax , sec
call WriteDec

mov edx, offset colon
call WriteString

mov eax , milisec
call WriteDec

;mili= mili+1
mov eax, milisec
add eax,1
mov milisec , eax

mov edx , 0     ;storing value 0 to remove the garbadge value
div milidiv     ;divide eax by 100 and getting the quotionet from edx
mov ebx , sec   ;move the value of second in ebx
add eax, ebx    ;now adding the previous value of second and the next quotiont value
mov edx , 0     ;storing value 0 to remove the garbadge value
div secdiv      ;dividing the ebx by 60
mov sec, edx    ;moving the quotiont from edx to second

mov eax, milisec    ;moving milisec to eax
mov edx , 0         
div milidiv         ;dividde by mili
mov milisec, edx

mov eax,sec
mov edx , 0
div secdiv
add eax, min
mov min, eax

mov eax , 100
call Delay
jmp PR

exit
main endp
end main
Syed Ahmed Jamil
  • 1,881
  • 3
  • 18
  • 34
  • If you can use the WinAPI, try the [SetTimer](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644906(v=vs.85).aspx) function. – zx485 Dec 19 '17 at 19:47
  • 1
    Don't do it like this, upon start of stopwatch read some time service (there are several available time sources in x86 + win32 API), and store the starting time somewhere. Then when you want to update screen, or when user will push stop, read current/ending time, subtract the starting time, and display the difference. Meanwhile your app can sleep much more aggressively, like even sleep 100ms a display only per 0.1s time, and let it wake by keyboard event (I don't know how win32 events work, together with Irvine32 lib, haven't worked with MS windows for 10+ years, so no details from me). – Ped7g Dec 19 '17 at 21:08

0 Answers0