微机原理实验程序设计集锦

实验一
(1)1.将给定的一个二进制数,转换成二-十进制(BCD)码:
要求将AX拆为三个BCD码,并存入result开始的三个单元。
data segment
result db 3 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,345
mov cl,100
div cl
mov result,al
mov al,ah
mov ah,0
mov cl,10
div cl
mov result+1,al
mov result+2,ah
jmp $
code ends
end start

(2)2.将给定的一个BCD数,将其转换成ASCII值:
将AX拆为两个ASCII码,并存入result开始的两个单元
data segment
result db 2 dup(?)
ASCIIab:
db"0123456789ABCDEF"
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,23h
mov bl,al
shr bl,4
mov bh,0
mov ah,byte ptr ASCIIab[bx]
mov result,ah
or al,00h
mov bl,al
mov ah,byte ptr ASCIIab[bx]
mov result+1,ah
jmp $
code ends
end start

实验二
(1)742451.利用板上的集成电路插座,扩展一片74LS245,来读入开关状态。
data segment
result db 3 dup(?)
data ends
code segment
assume cs:code
start:mov dx,200h
in al,dx
not al
mov dx,208h
out dx,al
jmp start
code ends
end start

(2)74273。用74LS273作为输出口,控制八个LED灯循环左移点亮。
data segment
result db 3 dup(?)
data ends
code segment
assume cs:code
start:mov dx,200h
mov cx,20000
mov al,0FEh
begin:out dx,al
delay:loop delay
mov cx,20000
rol al,01
jmp begin
code ends
end start

实验三8253
(1)1.利用8088/8086外接8253可编程定时器/计数器,可以实现对外部事件进行计数:
要求计数5个外部脉冲后,小灯亮。
code segment
assume cs:code
start:mov al,00010000B
out 8000h,al
mov al,5
out 8000h,al
again:mov al,00000000B
out 8000h,al
in al,8000h
mov bl,al
in al,8000h
mov bh,al
jmp again
code ends
end start
code segment
assume cs:code
start:proc near
mov al,00110000B
mov dx,8003h
out dx,al
mov al,5
mov dx,8000h
out dx,al
mov al,0
out dx,al
code ends
end start
(2)应用8253定时器来实现小灯每一秒钟输出状态发生一次反转。
c1 equ 08003h
c2 equ 08000h
c3 equ 08001h
c4 equ 08002h
code segment
assume cs:code
start:proc near
mov al,36h
mov dx,c1
out dx,al
mov ax,1000
mov dx,c2
out dx,al
mov al,ah
out dx,al
mov al,76h
mov dx,c2
out dx,al
mov ax,2000
mov dx,c3
out dx,al
mov al,ah
out dx,al
jmp $
code ends
end start
实验四8255
(1)利用8255可编程并行口芯片,实现输入/输出实验,实验中用PB口输入

开关状态, 用8255PA口作输出,控制小灯亮灭反映开关状态。
code segment
assume cs:code
start:mov al,83h
mov dx,8003h
out dx,al
begin:mov dx,8001h
in al,dx
mov dx,8000h
out dx,al
jmp begin
code ends
end start
(2)2.利用8255PA口输出控制8个小灯循环右移点亮。
code segment
assume cs:code;
start:call delay
mov dx,8003h;
mov al,80h;
out dx,al;
mov al,01h;;
begin:mov dx,8000h;
out dx,al;
ror al,1;
call delay
jmp begin
delay proc near
push cx;
mov cx,0;
loop $;
pop cx;
ret
delay endp;
code ends;
end start;

实验六0809
code segment
assume cs:code
start:mov al,10100000B;A口输出,方式1
mov dx,9003H
out dx,al;初始化
mov al,0
mov dx,8000H
out dx,al;启动
call delay
mov al,0
mov dx,8000H
next:out dx,al;cs=0
inc al
call delay
jmp next
mov dx,8000H
in al,dx;数据读入
mov dx,9000H
out dx,al;数据输出
delay proc near
push cx
mov cx,100
loop $
pop cx
cx
ret
delay endp
code ends
end start
(1)code segment
assume cs:code
start:mov al,10000000B;A口输出,方式0
mov dx,9003H
out dx,al;初始化
;mov al,0
;mov dx,8000H
;out dx,al;启动
;call delay
next: mov al,00H
mov dx,8000H
out dx,al;启动
call delay
INC al
;call delay
jmp next
mov dx,8000H
in al,dx;数据读入
mov dx,9000H
out dx,al;数据输出
delay proc near
push cx
mov cx,100
loop $
pop cx

ret
delay endp
code ends
end start
(2)code segment
assume cs:code
start:mov al,10000000B;A口输出,方式0
mov dx,9003H
out dx,al;初始化
next: mov al,0
mov dx,8000H
out dx,al;启动
call delay
mov dx,8000H
in al,dx;数据读入
mov dx,9000H
out dx,al;数据输出
jmp next
delay proc near
push cx
mov cx,100
loop $
pop cx
ret
delay endp
code ends
end start

实验七电子时钟
ICW1 equ 00010011B;前4位固定,中断请求是边沿触发,单片8259A,要设置ICW4,A0=0
ICW2 equ 20H;前5位固定,IR2,00000010B,A0=1
ICW4 equ 00000001B;前3位固定,非特殊全嵌套,非缓冲,从片8259A,最后一位固定,A0=1
OCW1 equ 11111110B;除IR0外其他全屏蔽置1,A0=1
OCW2 equ 00100000B;EOI p5,A0=1
CS8259A equ 0A000H;A0=0
CS8259B equ 0A001H;A0=1
outbit equ 8002h
outseg equ 8004h
mov dx,CS8259A
mov al,ICW1;数据放到al
out dx,al;送数据
mov dx,CS8259B
mov al,ICW2
out dx,al;送2号命令字
mov al,ICW4
out dx,al;写入4号命令字
mov al,OCW1
out dx,al;送OCW1
mov ax,0;设置中断向量表
mov ds,ax
mov bx,4*ICW2
mov ax,offset 中断向量程序名
mov [bx],ax;送

IP
mov ax,seg 中断向量程序名
mov [bx+2],ax;送CS
data segment
second db 0;秒从0开始
minute db 0;分从0开始
hour db 0;时从0开始
LEDBUF db 6 dup(?)
LEDMAP db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h
db 7fh,6fh,77h,7ch,39h,5eh,79h,71h
data ends
IEnter proc near
push ax
push dx;保护现场
INC second;秒加1
mov al,second
cmp al,60;比较是否到60
JNE EXIT;不到跳转
mov second,0;秒清零
INC minute;分加1
mov al,minute
cmp al,60
JNE EXIT
mov minute,0;分清零
INC hour;小时加1
mov al,hour
cmp al,24小时是否到24
JNE EXIT
mov hour,0;小时清零
EXIT:mov dx,CS8259A
mov al,OCW2
out dx,al;送命令字
pop dx
pop ax;恢复现场
iret
IEnter endp
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
begin:mov SI,offset NUM;6个数据的首地址
mov BX,offset LEDMAP;表的首地址
mov DI,offset LEDBUF;显示缓冲区的首地址
mov cl,6
aa:mov al,[SI]
call ZH
mov [DI],al
INC SI
INC DI
loop aa
call display
jmp begin
ZH proc near
push SI
mov SI,ax;赋值
mov al,[BX+SI]
pop SI
ret
ZH endp
display proc near;显示子程序
mov DI,offset LEDBUF
mov cl,6
mov ah,00100000B;最左边开始亮 ,6位数码管
AAA:mov dx,outbit;位控地址
mov al,0
out dx,al;全灭
mov al,ah
out dx,al;最左边亮
mov dx,outseg;段控地址
mov al,[DI]
out dx,al
shr ah,1
call delay
INC DI
loop AAA
ret
display endp
delay proc near
push cx
mov cx,200
loop $
pop cx
ret
delay endp
code ends
end start

相关文档
最新文档