-
Notifications
You must be signed in to change notification settings - Fork 0
/
put_string.asm
111 lines (111 loc) · 1.46 KB
/
put_string.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
103
104
105
106
107
108
109
110
111
;打印字符串的相关的一系列函数
;输入:ah->高亮;[ds:ebx]->字符串地址(字符串必须以0结尾)
;输出:无
put_string:
mov al,[ebx]
cmp al,0
je _put_string_end
call put_char
inc ebx
jmp put_string
_put_string_end:
retf
;输入:ah->高亮;al->要输出的ascII
put_char:
push eax
push ebx
push ecx
push edx
push ds
push es
;记录当前光标位置
call read_cursor
movzx ebx,bx
cmp al,0x0a
je _put_char_wrap
cmp al,0x0d
je _put_char_wrap
shl ebx,1
mov [gs:ebx],ax
shr ebx,1
inc ebx
jmp _put_char_ifFull
_put_char_wrap:;换行
xor edx,edx
mov eax,ebx
mov ebx,80
div ebx
inc eax
mul ebx
mov ebx,eax
_put_char_ifFull:;判断是否满屏
cmp ebx,80*25
jnae _put_char_end
mov ebx,80*24
mov ax, data_show
mov ds,ax
mov es,ax
xor edi,edi
mov esi,80*2
mov ecx,24*80
rep movsw
mov ecx,80
_put_char_clear_last_line:
mov word [edi],0
add edi,2
loop _put_char_clear_last_line
_put_char_end:
call write_cursor
pop eax
mov es,ax
pop eax
mov ds,ax
pop edx
pop ecx
pop ebx
pop eax
ret
;读光标位置(结果保存到bx)
read_cursor:
push eax
push ecx
push edx
mov dx,0x3d4
mov al,0x0e
out dx,al
mov dx,0x3d5
in al,dx
mov ah,al
mov dx,0x3d4
mov al,0x0f
out dx,al
mov dx,0x3d5
in al,dx
mov bx,ax
pop edx
pop ecx
pop eax
ret
;写光标位置(位置保存在BX)
write_cursor:
push eax
push ebx
push ecx
push edx
mov dx,0x3d4
mov al,0x0e
out dx,al
mov dx,0x3d5
mov al,bh
out dx,al
mov dx,0x3d4
mov al,0x0f
out dx,al
mov dx,0x3d5
mov al,bl
out dx,al
pop edx
pop ecx
pop ebx
pop eax
ret