-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.asm
78 lines (62 loc) · 1.06 KB
/
io.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
; change the video mode
; al [in] - (00h, 03h, 13h) the desired video mode
set_video_mode:
pusha
mov ah, 0
int 10h
popa
ret
; print a char to the console
; al [in] - char to be printed
putch:
pusha
mov ah, 0eh
int 10h
cmp al, 0dh ; in case a CR was detected
jne .putch_end
mov al, 0ah ; insert a LF as well
int 10h
.putch_end:
popa
ret
; print a string to the console
; bx [in] - string to be printed
print:
pusha ; save all registers
.print_loop:
mov al, [bx]
cmp al, 0
je .print_end
call putch
inc bx
jmp .print_loop
.print_end:
popa
ret
; read a character from the console (with echo)
; al [out] - read character
getch:
pusha
mov ah, 00h
int 16h
call putch
mov [_getch_tmp], al
popa
mov al, [_getch_tmp]
ret
_getch_tmp db 0
; read a string from the console (with echo)
; di:es [out] - pointer in mem for the read string
scan:
pusha
.scan_loop:
call getch
cmp al, 0dh
je .scan_end
stosb
jmp .scan_loop
.scan_end:
mov al, 0
stosb
popa
ret