-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe1003.asm
139 lines (112 loc) · 1.96 KB
/
e1003.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
assume cs:code
data segment
db 10 dup (0)
data ends
stack segment
db 32 dup (0)
stack ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,32
mov ax,65535
mov si,0
call dtoc
mov dh,8
mov dl,3
mov cl,02h
mov si,0
call show_str
mov ax,4c00h
int 21h
; FUNCTION dtoc
; USAGE converts a word data to its decimal representation
; character string, ending with 0
; PARAMETER (ax) - the word data, "WD"
; (ds:si) - starting address of the string
; RETURNS no return values
dtoc:
push bp
push dx
push cx
push bx
push ax
mov bp,sp
mov bx,10
digits:
mov dx,0
div bx ; (ax) = (WD) / 10, (dx) = (WD) % 10
mov cx,ax
jcxz digits_done
add dx,30h ; digit --> ASCII
push dx ; saves a digit of WD (starting from the least significant end)
jmp digits
digits_done:
add dx,30h
push dx
mov cx,bp
sub cx,sp ; (cx) / 2: number of digits
stack2str:
jcxz stack2str_done
pop ax
mov [si],al
inc si
sub cx,2
jmp stack2str
stack2str_done:
inc si
mov byte ptr [si],0 ; add ending-zero to the string
pop ax
pop bx
pop cx
pop dx
pop bp
ret
; from e1001.asm
; FUNCTION show_str
; USAGE shows a character string that ends with 0,
; with given attributes at given position
; PARAMETER (dh) - line number (0-24)
; (dl) - column number (0-79)
; (cl) - attributes (B-BAC-I-FOR)
; (si) - EA of the given string
; RETURNS no return values
show_str:
push cx
push si
push ax
push es
push bx
push di
mov ax,0b800h
mov es,ax ; es: screen buffer
mov al,dh
mov ah,0a0h
mul ah
mov bx,ax ; bx: EA at the beginning of the given line
mov dh,0
mov di,dx
add di,di ; di: bias of the given column
mov al,cl ; al: attributes
char:
mov cl,[si] ; mov a char...
mov ch,0
jcxz done ; check if it meets the string's end
mov ch,al ; ... and its attributes...
mov es:[bx][di],cx ; ... to the screen
inc si
add di,2
jmp char
done:
pop di
pop bx
pop es
pop ax
pop si
pop cx
ret
code ends
end start