第四部分:精华之作
(源自一人手笔,出于礼貌,没有进行修改。题目会和前面的考题有重复,之所以贴出来,只想让大家有个更广的编程思路,看看人家是怎么做到的……可惜,作者的名字不知道,原创请见谅)
1. 从键盘上输入0~9,通过8255方式0,A口输出,输出在数码管上显示相应数字(即我键盘上输入5,则在数码管上显示5)。
data segment
num1 db 'please input a number(0-9):',0dh,0ah,'$'
led db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov dx,28bh
mov al,80h
out dx,al
l1: call crlf
lea dx,num1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'0'
jb exit
cmp al,'9'
ja exit
sub al,30h
lea bx,led
xlat
mov dx,288h
out dx,al
jmp l1
exit: mov ah,4ch
int 21h
crlf proc near
mov dl,0dh
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
ret
crlf endp
code ends
end start
2. 8255方式0,A口输入,输入的数高4位不变低4位取反,在8255的C口输出,有键按下返回DOS,无键按下继续执行。
code segment
assume cs:code
start: mov dx,28bh
mov al,90h
out dx,al
l1: mov dx,288h
in al,dx
xor al,0fh
mov dx,28ah
out dx,al
mov ah,1
int 16h
jz l1
mov ah,4ch
int 21h
code ends
end start
3.8255方式0,C口低4位输入数据取反,在8255的C口高4位输出,有键按下返回DOS,无键按下继续执行。
code segment
assume cs:code
start: mov dx,28bh
mov al,81h
out dx,al
l1: mov dx,28ah
in al,dx
mov cl,4
shl al,cl
xor al,0f0h
mov dx,28ah
out dx,al
mov ah,1
int 16h
jz l1
mov ah,4ch
int 21h
code ends
4。8255方式0,A口输入,C口输出。如果A口输入的数大于等于128,从C口输出
80H;否则将输入的数高4位不变低4位取反从C口输出,有键按下返回DOS,无键按下继续执行。
code segment
assume cs:code
start: mov dx,28bh
mov al,90h
out dx,al
l3: mov dx,288h
in al,dx
cmp al,80h
jae l1
xor al,0fh
mov dx,28ah
out dx,al
l2: mov ah,1
int 16h
jz l3
mov ah,4ch
int 21h
l1: mov al,80h
mov dx,28ah
out dx,al
jmp l2
code ends
end start