-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.asm
102 lines (85 loc) · 1.19 KB
/
keyboard.asm
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
[ORG 0x7C00]
[BITS 16]
%macro read_key_press 0
mov ah, 0x01
int 0x16
%endmacro
xor ax, ax
mov es, ax
cli
mov dword [es:4 * 9], keyboardHandler
mov [es:4 * 9 + 2], cs
sti
jmp $
keyboardHandler:
pusha
in al, 0x60
; test al, 0x80
; jnz .end
and al, ~0x80
call print_int
mov ah, 0x0e
mov al, 10
int 0x10
.end:
mov al, 0x61
out 20h, al
popa
iret
; in al, 0x
print_int:
mov si, ax
call count_digits ; cx = digits number
dec cx
mov ax, 10
call pow_int
mov ax, si
mov si, 10
print_int_loop:
xor dx, dx
div cx
call print_digit
mov ax, dx
mov bx, dx ; save remainder
xor dx, dx
mov ax, cx
div si
mov cx, ax
mov ax, bx
cmp cx, 0
ja print_int_loop
ret
count_digits:
mov cx, 0
cd_loop:
inc cx
xor dx, dx
mov bx, 10
div bx
cmp ax, 0
jne cd_loop
ret
; ax = input
; cx = power
; cx = output
pow_int:
mov bx, ax
mov ax, 1
pow_int_loop:
jcxz pow_int_done
mul bx
loop pow_int_loop
pow_int_done:
mov cx, ax
ret
; ax = input
print_digit:
mov bx, ax
xor ax, ax
add bx, 0x30
mov ah, 0x0e
mov al, bl
int 0x10
ret
times 510 - ($ - $$) db 0
dw 0xaa55