-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCount_Key_Presses.asm
More file actions
78 lines (57 loc) · 1.23 KB
/
Count_Key_Presses.asm
File metadata and controls
78 lines (57 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
; Count number of key presses. the result is in bx register.
;
; You must type into the emulator's screen,
; if it closes, press screen button to re-open it.
name "keycount"
org 100h
; print welcome message:
mov dx, offset msg
mov ah, 9
int 21h
xor bx, bx ; zero bx register.
wait: mov ah, 0 ; wait for any key....
int 16h
cmp al, 27 ; if key is 'esc' then exit.
je stop
mov ah, 0eh ; print it.
int 10h
inc bx ; increase bx on every key press.
jmp wait
; print result message:
stop: mov dx, offset msg2
mov ah, 9
int 21h
mov ax, bx
call print_ax
; wait for any key press:
mov ah, 0
int 16h
ret ; exit to operating system.
msg db "I'll count all your keypresses. press 'Esc' to stop...", 0Dh,0Ah, "$"
msg2 db 0Dh,0Ah, "recorded keypresses: $"
print_ax proc
cmp ax, 0
jne print_ax_r
push ax
mov al, '0'
mov ah, 0eh
int 10h
pop ax
ret
print_ax_r:
pusha
mov dx, 0
cmp ax, 0
je pn_done
mov bx, 10
div bx
call print_ax_r
mov ax, dx
add al, 30h
mov ah, 0eh
int 10h
jmp pn_done
pn_done:
popa
ret
endp