微机期末复习之实验源代码


微机期末复习之实验源代码

1

1.2

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
include io.inc
.model small
.stack
.data

.code
start:
mov ax,@data
mov ds,ax
mov ax,0d000h;段地址
mov es,ax
mov bx,6000h;偏移地址
mov cx,5fh;字符个数
mov dx,20h;ASCII开始字符

;写入ASCII表
write:
mov es:[bx],dx
inc bx
inc dx
cmp dx,7fh
jnz write

mov bx,6000h

;读出ASCII表
read:
mov ax,es:[bx]
call dispc
inc bx
loop read

.exit 0
end start

4

4.1

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
	include io.inc
.model small
.stack
.data
intmsg byte 'TPCA Interrupt No.3!',0dh,0ah,0
counter byte 0
.code
start:
mov ax,@data
mov ds,ax
mov ax,350Bh
int 21h
push es
push bx
cli
push ds
mov ax,seg new0Bh
mov ds,ax
mov dx,offset new0Bh
mov ax,250Bh
int 21h
pop ds
in al,21h
push ax
and al,0f7h
out 21h,al
mov counter,0
sti
;
start1:
cmp counter,5
jb start1
;
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,250Bh
int 21h
sti
.exit 0

;中断服务程序
new0Bh proc
sti
push ax
push si
push ds
mov ax,@data
mov ds,ax
inc counter
mov si,offset intmsg
call dpstri
mov al,20h
out 20h,al
pop ds
pop si
pop ax
iret
new0Bh endp
dpstri proc
push ax
push bx
dps1: mov al,[si]
cmp al,0
jz dps2
mov bx,0
mov ah,0eh
int 10h
inc si
jmp dps1
dps2: pop bx
pop ax
ret
dpstri endp
end start

4.2

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
 	include io.inc
.model small
.stack
.data
intmsg byte 'TPCA Interrupt No.10!',0dh,0ah,0
counter byte 0
.code
start:mov ax,@data
mov ds,ax
mov ax,3572h
int 21h
push es
push bx
cli
push ds
mov ax,seg new72h
mov ds,ax
mov dx,offset new72h
mov ax,2572h
int 21h
pop ds
in al,0a1h
push ax
and al,0fbh
out 0a1h,al
mov counter,0
sti
;
start1:
cmp counter,5
jb start1
;
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,2572h
int 21h
sti
.exit 0

;中断服务程序
new72h proc
sti
push ax
push si
push ds
mov ax,@data
mov ds,ax
inc counter
mov si,offset intmsg
call dpstri
mov al,20h
out 0a0h,al
out 20h,al
pop ds
pop si
pop ax
iret
new72h endp
dpstri proc
push ax
push bx
dps1: mov al,[si]
cmp al,0
jz dps2
mov bx,0
mov ah,0eh
int 10h
inc si
jmp dps1
dps2: pop bx
pop ax
ret
dpstri endp
end start

4.3

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
140
141
142
  	include io.inc
.model small
.stack
.data
intmsg3 byte 'TPCA Interrupt No.3!',0dh,0ah,0
intmsg10 byte 'TPCA Interrupt No.10!',0dh,0ah,0
counter byte 0
.code
start:
mov ax,@data
mov ds,ax
mov ax,350Bh
int 21h
push es
push bx
cli
push ds
mov ax,seg new0Bh
mov ds,ax
mov dx,offset new0Bh
mov ax,250Bh
int 21h
pop ds
in al,21h
push ax
and al,0f7h
out 21h,al
mov counter,0
sti
;
mov ax,@data
mov ds,ax
mov ax,3572h
int 21h
push es
push bx
cli
push ds
mov ax,seg new72h
mov ds,ax
mov dx,offset new72h
mov ax,2572h
int 21h
pop ds
in al,0a1h
push ax
and al,0fbh
out 0a1h,al
mov counter,0
sti
start1:
cmp counter,5
jb start1
;
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,2572h
int 21h
sti
;
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,250Bh
int 21h
sti
.exit 0

;中断服务程序
new72h proc
sti
push ax
push si
push ds
mov ax,@data
mov ds,ax
inc counter
mov si,offset intmsg10
call dpstri

mov ah,86h
mov cx,0ffh
mov dx,8480h
int 15h

mov al,20h
out 0a0h,al
out 20h,al
pop ds
pop si
pop ax
iret
new72h endp
;
new0Bh proc
sti
push ax
push si
push ds
mov ax,@data
mov ds,ax
inc counter
mov si,offset intmsg3
call dpstri
mov al,20h
out 20h,al
pop ds
pop si
pop ax
iret
new0Bh endp
;
dpstri proc
push ax
push bx
push cx
push dx
dps1: mov al,[si]
cmp al,0
jz dps2
mov bx,0
mov ah,0eh
int 10h
inc si
jmp dps1
dps2:
mov ah,86h
mov cx,0ffh
mov dx,8480h
int 15h
pop dx
pop cx
pop bx
pop ax
ret
dpstri endp
end start

5

5.1

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
	include io.inc
.model small
.stack
.code
start:
mov ax,@data
mov ds,ax
mov al,10h
mov dx,283h
out dx,al
mov ax,8
mov dx,280h
out dx,al
mov ah,al
again:
call wait
in al,dx
cmp al,ah
jz again
push ax
call dispuib
call dispcrlf
pop ax
mov ah,al
cmp al,0
jnz again
.exit 0
wait proc
push cx
mov cx,1000
wait1:
loop wait1
pop cx
ret
wait endp
end start

5.2

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
	include io.inc
.model small
.stack
.code
start:
mov ax,@data
mov ds,ax

;设置计数器0
mov dx,283h
mov al,36h
out dx,al

mov dx,280h
mov ax,1000
out dx,al
mov al,ah
out dx,al

;设置计数器1
mov dx,283h
mov al,76h
out dx,al

mov ax,1000
mov dx,281h
out dx,al
mov al,ah
out dx,al

.exit 0
end start

5.3

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
	include io.inc
.model small
.data
msg byte 'Interrupt 1s!',13,10,0
counter byte 0
.code
;280计数器0
start:
mov ax,@data
mov ds,ax
;设置计数器0
mov al,36h
mov dx,283h
out dx,al
;设置计数初值
mov dx,280h
mov ax,1000
out dx,al
mov al,ah
out dx,al
;设置计数器1
mov al,76h
mov dx,283h
out dx,al
mov dx,281h
mov ax,1000
out dx,al
mov al,ah
out dx,al
;获取并设置新的中断程序(0bh)
mov ax,3508h
int 21h
push es
push bx
cli
push ds
mov ax,seg new0bh
mov ds,ax
mov dx,offset new0bh
mov ax,2508h
int 21h
pop ds
in al,21h
push ax
and al,0f7h
out 21h,al
mov counter,0
sti
start1:
cmp counter,5
jb start1
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,2508h
int 21h
sti
.exit 0
new0bh proc
push ax
push si
push ds
mov ax,@data
mov ds,ax
inc counter
mov si,offset msg
call dpstri
mov al,20h
out 20h,al
pop ds
pop si
pop ax
iret
new0bh endp
dpstri proc
push ax
push bx
dps1:
mov al,[si]
cmp al,0
jz dps2
mov bx,0
mov ah,0eh
int 10h
inc si
jmp dps1
dps2:
pop bx
pop ax
ret
dpstri endp
end start

6

6.1

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
	 include io.inc
.model small
.stack
.data
msg byte 'Please connext correctly!',13,10,0
.code
start:
mov ax,@data
mov ds,ax
mov ax,offset msg
call dispmsg

again: mov dx,28Bh
mov al,89H
out dx,al

mov dx,28Ah
in al,dx
mov dx,288h
out dx,al

call readkey
jz again

.exit 0
end start

6.2

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
	include io.inc
.model small
.stack
.data
counter byte 0
.code
start:

mov ax,350bh
int 21h
push es
push bx

cli
push ds
mov ax,seg new0bh
mov ds,ax
mov dx,offset new0bh
mov ax,250bh
int 21h
pop ds
in al,21h
push ax
and al,0f7h
out 21h,al
mov counter,0

mov dx,28bh
mov al,10100000b
out dx,al

mov al,00001101b
out dx,al
mov counter,0

mov al,0
mov dx,28ah
out dx,al

sti

mov bl,01h

start1:
cmp counter,8
jb start1
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,250bh
int 21h
sti
.exit 0

new0bh proc
push ax
push dx
mov ax,@data
mov ds,ax

mov al,bl
mov dx,288h
out dx,al
rol bl,1
inc counter
;EOI
mov al,20h
out 20h,al
pop dx
pop ax
iret
new0bh endp

end start

6.3

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
	include io.inc
.model small
.stack
.data
counter byte 0
.code
start:
mov ax,@data
mov ds,ax

mov ax,350bh
int 21h
push es
push bx

cli
push ds
mov ax,seg new0bh
mov ds,ax
mov dx,offset new0bh
mov ax,250bh
int 21h
pop ds
in al,21h
push ax
and al,0f7h
out 21h,al
mov counter,0

;
mov dx,28bh
mov al,10110000b
out dx,al

mov al,00001001b
out dx,al
mov counter,0
;
mov al,0
mov dx,28ah
out dx,al

sti
start1:
cmp counter,5
jb start1
cli
pop ax
out 21h,al
pop dx
pop ds
mov ax,250bh
int 21h
sti
.exit 0

new0bh proc
push ax
push dx
mov ax,@data
mov ds,ax

mov dx,288h
in al,dx
call dispbb
call dispcrlf
inc counter
;EOI
mov al,20h
out 20h,al
pop dx
pop ax
iret
new0bh endp

end start

6.4

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
	include io.inc
.model small
.stack
.code
start:
mov ax,@data
mov ds,ax

mov dx,28bh
mov al,10100000b
out dx,al

mov al,00001101b
out dx,al

mov bl,01h
call prints
.exit 0

prints proc
push ax
push dx
mov ax,@data
mov ds,ax

print1:
mov al,bl
mov dx,288h
out dx,al
rol bl,1
call delay

;读取C端口
mov dx,28ah
print2:
in al,dx
test al,10000000b
jz print2
cmp bl,01h
jnz print1
pop dx
pop ax
ret
prints endp

timer=100
;延时子程序
delay proc
push bx
push cx
mov bx,timer
delay1:
xor cx,cx
delay2:
loop delay2
dec bx
jnz delay1
pop cx
pop bx
ret
delay endp

end start

8

8.1

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
	include io.inc
.model small
.stack
.data
ledtb byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh

.code
start:
mov ax,@data
mov ds,ax

mov dx,28bh
mov al,10000001b
out dx,al

xor ax,ax
xor bx,bx
f: call readuib
mov bx,ax
mov al,ledtb[bx]
mov dx,288h
out dx,al
jmp f


.exit 0
end start

8.2

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
 	include io.inc
.model small
.stack
.data
leddt byte 3,4,5,6
ledtb byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
.code
start:
mov ax,@data
mov ds,ax

;8255 method cotrol word
mov dx,28bh
mov al,10000000b
out dx,al

again:
mov si,offset leddt
call displed
jmp again
.exit 0

displed proc
push ax
push bx
push dx
xor bx,bx
;which light
mov ah,00001000b
led1:
;pa
mov bl,[si]
inc si
mov al,ledtb[bx]
mov dx,288h
out dx,al

;pb which light to light
mov al,ah
mov dx,289h
out dx,al

;delay
call delay
;next light
ror ah,1
;all lights light,exit and begin nest round
cmp ah,10000000b
jnz led1
pop dx
pop bx
pop ax
ret
displed endp

time=20
delay proc
push bx
push cx
mov bx,time
delay1:
xor cx,cx
delay2:
loop delay2
dec bx
jnz delay1
pop cx
pop bx
ret
delay endp
end start

8.4

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
  	include io.inc
.model small
.stack
.data
leddt byte 0,0,0,0
ledtb byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
num word 1
.code
start:
mov ax,@data
mov ds,ax

;8255 method cotrol word
mov dx,28bh
mov al,10000000b
out dx,al
again:
mov si,offset leddt
call displed
call numadd
jmp again
.exit 0

displed proc
push ax
push bx
push dx
xor bx,bx
;which light
mov ah,00001000b
led1:
;pa
mov bl,[si]



inc si
mov al,ledtb[bx]
mov dx,288h
out dx,al

;pb which light to light
mov al,ah
mov dx,289h
out dx,al

;delay
call delay
;next light
ror ah,1
;all lights light,exit and begin nest round
cmp ah,10000000b
jnz led1
pop dx
pop bx
pop ax
ret
displed endp

time=500
delay proc
push bx
push cx
mov bx,time
delay1:
xor cx,cx
delay2:
loop delay2
dec bx
jnz delay1
pop cx
pop bx
ret
delay endp


numadd proc
push ax
push bx
push cx
push si

mov bl,10
mov si,offset leddt
add si,3
inc num
mov ax,num

div bl
;high is yushu
mov [si],ah
sub si,1
push ax
call dispbw
call dispcrlf
pop ax
div bl
;high is yushu
mov [si],ah
sub si,1
push ax
call dispbw
call dispcrlf
pop ax
div bl
;high is yushu
mov [si],ah
sub si,1
push ax
call dispbw
call dispcrlf
pop ax
div bl
;high is yushu
mov [si],ah
sub si,1
push ax
call dispbw
call dispcrlf
pop ax
pop si
pop cx
pop bx
pop ax
ret
numadd endp
end start

10

10.2

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
 	include io.inc
.model small
.stack
.data
msg byte 'press any key to exit',10,13,0
.code
start:
mov ax,@data
mov ds,ax
again:
;active DAC
xor ax,ax
mov dx,298h
out dx,al
mov dx,298h
in al,dx
call delay
call dispuib
call dispcrlf
call readkey
jz again
.exit 0

timer=100
delay proc
push bx
push cx
mov bx,timer
delay1:
xor cx,cx
delay2:
loop delay2
dec bx
jnz delay1
pop cx
pop bx
ret
delay endp
end start

10.3

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
 	include io.inc
.model small
.stack
.data
.code
start:
mov ax,@data
mov ds,ax
;init 8255
mov dx,28bh
mov al,0
out dx,al
;pc7=0
mov al,0
out dx,al

again:
;active DAC
xor ax,ax
mov dx,298h
out dx,al
out dx,al
;pc7
mov dx,28ah
start1:
call delay
in al,dx
test al,10000000b
jz start1

mov dx,298h
in al,dx
call delay
call dispuib
call dispcrlf
call readkey
jz again
.exit 0

timer=1000
delay proc
push bx
push cx
mov bx,timer
delay1:
xor cx,cx
delay2:
loop delay2
dec bx
jnz delay1
pop cx
pop bx
ret
delay endp
end start

10.4

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
	include io.inc
.model small
.stack
.data
temp byte 0
intseg word 0
intoff word 0
.code
start:
mov ax,@data
mov ds,ax
;int
mov ax,350bh
int 21h
mov intseg,es
mov intoff,bx
cli
push ds
mov ax,seg new0Bh
mov ds,ax
mov dx,offset new0Bh
mov ax,250Bh
int 21h
pop ds
;open IRQ3
in al,21h
push ax
and al,0f7h
out 21h,al
sti
again:
mov al,temp
call delay
call dispuib
call dispcrlf
call readkey
jz again

cli
pop ax
out 21h,al
mov ds,intseg
mov dx,intoff
mov ax,250Bh
int 21h
sti
.exit 0

new0Bh proc
sti
push ax
push dx
push ds
mov ax,@data
mov ds,ax

;active DAC
xor ax,ax
mov dx,298h
out dx,al
mov dx,298h
in al,dx
mov temp,al
call delay

;EOI
mov al,20h
out 20h,al
pop ds
pop dx
pop ax
iret
new0Bh endp

timer=100
delay proc
push bx
push cx
mov bx,timer
delay1:
xor cx,cx
delay2:
loop delay2
dec bx
jnz delay1
pop cx
pop bx
ret
delay endp
end start

打印

打印的时候只能打印出一页,这样不好。我们可以这样手动全选打印的区域,右键选择打印就可以了。应该是hexo自己的问题,因为别的网页都可以正常打印全部,不知道这是一个bug还是feature。


文章作者: 崔文耀
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 崔文耀 !
  目录