1 data segment
2 hh db 0dh,0ah,‘$‘
3 m1 db ‘please enter a number:‘,0dh,0ah,‘$‘
4 m2 db ‘please enter another number:‘,0dh,0ah,‘$‘
5 m3 db ‘gong yue shu:‘,0dh,0ah,‘$‘
6 m4 db ‘ping fang cha:‘,0dh,0ah,‘$‘
7 m5 db ‘num1/sum is:‘,0dh,0ah,‘$‘
8 m6 db ‘num2/sum is:‘,0dh,0ah,‘$‘
9 sum dw 0
10 x dw 0
11 y dw 0
12 z dw 0
13 sign db 0h
14 s db 6 dup(0h),‘$‘
15 data ends
16
17 code segment
18 assume cs:code,ds:data
19 main proc far
20 start:
21 mov ax,data
22 mov ds,ax
23 mov ax,offset m1
24 call print
25 call enternumber
26 mov bx,ax
27 mov x,bx
28 mov sum,bx
29
30 mov ax,offset m2
31 call print
32 call enternumber
33 mov cx,ax
34 mov y,cx
35 add sum,cx
36
37 call find
38 mov ax,offset m3
39 call print
40 mov ax,cx
41
42 mov bl,al
43 mov bh,1
44 l1:
45 mov al,bl
46 xor ah,ah
47 div bh
48 cmp ah,0
49 jnz next2
50 mov al,bh
51 aam
52 mov cx,ax
53 add ch,30h
54 mov dl,ch
55 mov ah,2
56 int 21h
57 add cl,30h
58 mov dl,cl
59 mov ah,2
60 int 21h
61 mov dx,offset hh
62 mov ah,09h
63 int 21h
64
65 next2:
66 inc bh
67 cmp bl,bh
68 jl done
69 jmp l1
70 done:
71 mov ax,offset m4
72 call print
73 call pfc
74
75
76 mov ax,offset hh
77 call print
78 mov ax,offset m5
79 call print
80 mov al,byte ptr x
81 mov bh,100
82 mul bh
83 mov bl,byte ptr sum
84 div bl
85 mov bl,al
86
87 call disp10
88
89 mov dl,‘%‘
90 mov ah,02h
91 int 21h
92
93 mov ax,offset hh
94 call print
95 mov ax,offset m6
96 call print
97
98 mov al,byte ptr y
99 mov bh,100
100 mul bh
101 mov bl,byte ptr sum
102 div bl
103 mov bl,al
104 call disp10
105 mov dl,‘%‘
106 mov ah,02h
107 int 21h
108
109 mov ah,4ch
110 int 21h
111
112 main endp
113
114 print proc near
115
116 mov dx,ax
117 mov ah,09h
118 int 21h
119 ret
120
121 print endp
122
123 enternumber proc near
124
125 mov ah,01h
126 int 21h
127 mov dh,al
128 sub dh,30h
129
130 mov ah,01h
131 int 21h
132 cmp al,0dh
133 jz next1
134 sub al,30h
135 shl dh,1
136 mov dl,dh
137 shl dh,1
138 shl dh,1
139 add dh,dl
140 add dh,al
141
142 next1:
143 mov cl,dh
144 mov dx,offset hh
145 mov ah,09h
146 int 21h
147 mov al,cl
148 xor ah,ah
149 ret
150 enternumber endp
151
152 find proc near
153
154 cmp bx,cx
155 jnl first
156 xchg bx,cx
157 first:
158 xor dx,dx
159 mov ax,bx
160 div cx
161 cmp dx,0
162 jz equal
163 mov bx,cx
164 mov cx,dx
165 jmp first
166
167 equal:
168 ret
169 find endp
170
171 pfc proc near; 计算平方差
172 work:
173 mov al,byte ptr x
174 mul al
175 mov z,ax
176 mov al,byte ptr y
177 mul al
178 cmp z,ax
179 jb n1
180 sub z,ax
181 jmp n2
182
183 n1:
184 sub ax,z
185 mov z,ax
186 mov sign,‘-‘
187 n2:
188 mov cx,5h
189 mov di,4h
190 mov bx,0ah
191 mov ax,z
192
193 w2:
194 mov dx,0
195 div bx
196 add dl,30h
197 mov s[di],dl
198 dec di
199 cmp ax,0h
200 jz w2exit
201 loop w2
202 w2exit:
203 mov al,sign
204 mov s[di],al
205 mov di,0
206
207 w3:
208 inc di
209 cmp s[di],0h
210 jz w3
211 lea dx,s[di]
212 mov ah,09h
213 int 21h
214 ret
215 pfc endp
216
217 disp10 proc near ;计算占和百分比
218 mov ah,0
219 mov al,bl
220 mov bh,100
221 div bh
222 mov bl,ah
223 mov dl,al
224 cmp dl,0
225 jz jump1
226 add dl,30h
227 mov ah,02
228 int 21h
229 jump1:
230 mov al,bl
231 mov ah,0
232 mov bh,10
233 div bh
234 mov bl,ah
235 mov dl,al
236 cmp dl,0
237 jz jump2
238 add dl,30h
239 mov ah,02
240 int 21h
241 jump2:
242 mov dl,bl
243 add dl,30h
244 mov ah,02h
245 int 21h
246 ret
247
248 disp10 endp
249 code ends
250 end start