新学了一个产生随机数的指令, 拿来做个练习~~
------------------------------------------------------
1 ;rand.asm
2 assume cs:code
3 code segment
4 start:
5 call clr
6 mov cx,100
7 main: call show
8 in al,60h ;如果有按键Q读入
9 cmp al,10h ;则退出程序
10 jz over ;
11 jmp main
12 loop main
13
14 over: mov ah,4ch
15 int 21h
16 ;
17 show: push ax
18 push bx
19 push cx
20 push dx
21
22 mov bl,160
23 in al,40h
24 and ax,0ffh
25 div bl
26 mov dl,ah
27
28 mov bl,25
29 in al,40h
30 and ax,0ffh
31 div bl
32 mov dh,ah
33
34 mov ah,2
35 mov bh,0
36 mov bl,02
37 int 10h
38
39 s: mov ah,2
40 int 10h
41 cmp dh,50
42 je ok
43 in al,40h
44 and al,0fh
45 cmp al,9
46 ja sa
47 add al,30h
48 jmp sb
49 sa: add al,37h
50 sb: mov ah,9
51 mov cx,1
52 int 10h
53 call delay
54 inc dh
55 jmp s
56 ok:
57 pop dx
58 pop cx
59 pop bx
60 pop ax
61 ret
62 ;
63 clr: push bx
64 push cx
65 push es
66 mov bx,0b800h
67 mov es,bx
68 mov bx,0
69 mov cx,4000
70 c1: mov byte ptr es:[bx],20h
71 add bx,2
72 loop c1
73 pop es
74 pop cx
75 pop bx
76 ret
77 ;
78 delay: push ax
79 push dx
80 mov dx,50h
81 mov ax,0
82 d1: sub ax,1
83 sbb dx,0
84 cmp ax,0
85 jne d1
86 cmp dx,0
87 jne d1
88 pop dx
89 pop ax
90 ret
91 ;
92 code ends
93 end start
------------------------------------------------------
这个版本的加入了退出, 否则, 他就是一死循环。
利用in al,60H,检测按键。
------------------------------------------------------
1 ;rand.asm
2 assume cs:code
3 code segment
4 start:
5 call clr
6 mov cx,100
7 main: call show
8 in al,60h ;如果有按键Q读入
9 cmp al,10h ;则退出程序
10 jz over ;
11 jmp main
12 loop main
13
14 over: mov ah,4ch
15 int 21h
16 ;
17 show: push ax
18 push bx
19 push cx
20 push dx
21
22 mov bl,160
23 in al,40h
24 and ax,0ffh
25 div bl
26 mov dl,ah
27
28 mov bl,25
29 in al,40h
30 and ax,0ffh
31 div bl
32 mov dh,ah
33
34 mov ah,2
35 mov bh,0
36 mov bl,02
37 int 10h
38
39 s: mov ah,2
40 int 10h
41 cmp dh,50
42 je ok
43 in al,40h
44 and al,0fh
45 cmp al,9
46 ja sa
47 add al,30h
48 jmp sb
49 sa: add al,37h
50 sb: mov ah,9
51 mov cx,1
52 int 10h
53 call delay
54 inc dh
55 jmp s
56 ok:
57 pop dx
58 pop cx
59 pop bx
60 pop ax
61 ret
62 ;
63 clr: push bx
64 push cx
65 push es
66 mov bx,0b800h
67 mov es,bx
68 mov bx,0
69 mov cx,4000
70 c1: mov byte ptr es:[bx],20h
71 add bx,2
72 loop c1
73 pop es
74 pop cx
75 pop bx
76 ret
77 ;
78 delay: push ax
79 push dx
80 mov dx,50h
81 mov ax,0
82 d1: sub ax,1
83 sbb dx,0
84 cmp ax,0
85 jne d1
86 cmp dx,0
87 jne d1
88 pop dx
89 pop ax
90 ret
91 ;
92 code ends
93 end start
------------------------------------------------------
这个版本的加入了退出, 否则, 他就是一死循环。
利用in al,60H,检测按键。