实验四 接口实验
w88 石光 981239
源程序1;
STACK SEGMENT PARA STACK 'STACK'
DB 256 DUP(0)
STACK ENDS
DATA SEGMENT
SEG8 DW?
OFF8 DW?
IMR DB?
COUNT DB 100
TENH DB '2'
HOUR DB '3:'
TENM DB '5'
MINUTE DB '9:'
TENS DB '5'
SECOND DB '0',0DH,'$'
DATA ENDS
CODE SEGMENT
START PROC FAR
ASSUME CS:CODE,DS:DATA
MOV AX,DATA
MOV DS,AX
MOV AH,0
INT 16H
MOV AL,08H
MOV AH,35H
INT 21H
MOV SEG8,DS ;中断向量应返回在[DS]∶[BX]中
MOV OFF8,BX
CLI
PUSH DS
MOV AX,SEG TIMER
MOV DS,AX
MOV DX,OFFSET TIMER
MOV AL,8;此处遗漏中断号
MOV AH,25H
INT 21H
POP DS
MOV AL,00110110B
OUT 43H,AL
MOV AX,11932
OUT 40H,AL
MOV AL,AH
OUT 40H,AL
IN AL,21H
MOV IMR,AL
AND AL,0FCH ;重写IMR应该用“And”
OUT 21H,AL
STI
FOREVER:
MOV AH,1
INT 16H
CMP AL,20H
JZ EXIT
MOV DX,OFFSET TENH
MOV AH,09H
INT 21H
MOV AL,SECOND
WAITCHA:
CMP AL,SECOND
JZ WAITCHA
JMP FOREVER
EXIT: CLI
MOV AL,IMR
OUT 21H,AL
MOV AL,36H
OUT 43H,AL
MOV AL,0
OUT 40H,AL
OUT 40H,AL
CLI
PUSH DS
MOV AX,SEG8
MOV DS,AX
MOV DX,OFF8
MOV AH,25H
MOV AL,08H
INT 21H
STI
POP DS ;DS出栈
MOV AH,4CH ;功能号有误
INT 21H
TIMER PROC FAR
PUSH AX
DEC COUNT
JNZ L2
MOV COUNT,100
INC SECOND
CMP SECOND,'9'
JNE TIMEXT
MOV SECOND,'0'
INC TENS
CMP TENS,'6'
JL TIMEXT
MOV TENS,'0'
INC MINUTE
CMP MINUTE,'9'
JLE TIMEXT
MOV MINUTE,'0'
INC TENM
CMP TENM,'6'
JL TIMEXT
MOV TENM,'0'
JMP L3
L2: JMP TIMEXT
L3, MOV AL,HOUR
AND AL,0FH
MOV AH,TENH
AND AH,0FH ;应将后四位全保留
MOV CL,4
ROL AH,CL
OR AL,AH
ADD AL,1
DAA
CMP AL,24H ;此时AL中存的是BCD码
JL L1
MOV TENH,'0'
MOV HOUR,'0'
JMP TIMEXT
L1: MOV AH,AL
AND AL,0FH
OR AL,30H
MOV HOUR,AL
MOV CL,4
ROR AH,CL
AND AH,0FH
OR AH,30H
MOV TENH,AH
TIMEXT:
MOV AL,20H
OUT 20H,AL
POP AX
IRET
TIMER ENDP
START ENDP
CODE ENDS
END START
源程序二;
CODE SEGMENT;NO DATA SEGMENT
MOV DX,3FBH
MOV AL,80H
OUT DX,AL
MOV DX,3F8H
MOV AL,12
OUT DX,AL;写入对应波特率9600的波特因子的低八位
INC DX
MOV AL,0
OUT DX,AL;写入对应波特率9600的波特因子的低八位
MOV AL,0BH
MOV DX,3FBH
OUT DX,AL
MOV AL,13H
MOV DX,3FCH
OUT DX,AL ;循环测试
EMPTY:MOV AH,1
INT 16H
JNZ EMPTY
CHECK:MOV DX,3FDH
IN AL,DX
TEST AL,1H
JNZ REV
TEST AL,20H
JZ CHECK
TR: MOV AH,0
INT 16H
JZ CHECK
CMP AL,03H
JZ EXIT
MOV DX,3F8H
OUT DX,AL
JMP CHECK
REV: MOV DX,3F8H
IN AL,DX
AND AL,7FH
MOV BX,0041H
MOV AH,14
INT 10H
JMP CHECK
EXIT,MOV AH,4CH
INT 21H
CODE ENDS
END MAIN
w88 石光 981239
源程序1;
STACK SEGMENT PARA STACK 'STACK'
DB 256 DUP(0)
STACK ENDS
DATA SEGMENT
SEG8 DW?
OFF8 DW?
IMR DB?
COUNT DB 100
TENH DB '2'
HOUR DB '3:'
TENM DB '5'
MINUTE DB '9:'
TENS DB '5'
SECOND DB '0',0DH,'$'
DATA ENDS
CODE SEGMENT
START PROC FAR
ASSUME CS:CODE,DS:DATA
MOV AX,DATA
MOV DS,AX
MOV AH,0
INT 16H
MOV AL,08H
MOV AH,35H
INT 21H
MOV SEG8,DS ;中断向量应返回在[DS]∶[BX]中
MOV OFF8,BX
CLI
PUSH DS
MOV AX,SEG TIMER
MOV DS,AX
MOV DX,OFFSET TIMER
MOV AL,8;此处遗漏中断号
MOV AH,25H
INT 21H
POP DS
MOV AL,00110110B
OUT 43H,AL
MOV AX,11932
OUT 40H,AL
MOV AL,AH
OUT 40H,AL
IN AL,21H
MOV IMR,AL
AND AL,0FCH ;重写IMR应该用“And”
OUT 21H,AL
STI
FOREVER:
MOV AH,1
INT 16H
CMP AL,20H
JZ EXIT
MOV DX,OFFSET TENH
MOV AH,09H
INT 21H
MOV AL,SECOND
WAITCHA:
CMP AL,SECOND
JZ WAITCHA
JMP FOREVER
EXIT: CLI
MOV AL,IMR
OUT 21H,AL
MOV AL,36H
OUT 43H,AL
MOV AL,0
OUT 40H,AL
OUT 40H,AL
CLI
PUSH DS
MOV AX,SEG8
MOV DS,AX
MOV DX,OFF8
MOV AH,25H
MOV AL,08H
INT 21H
STI
POP DS ;DS出栈
MOV AH,4CH ;功能号有误
INT 21H
TIMER PROC FAR
PUSH AX
DEC COUNT
JNZ L2
MOV COUNT,100
INC SECOND
CMP SECOND,'9'
JNE TIMEXT
MOV SECOND,'0'
INC TENS
CMP TENS,'6'
JL TIMEXT
MOV TENS,'0'
INC MINUTE
CMP MINUTE,'9'
JLE TIMEXT
MOV MINUTE,'0'
INC TENM
CMP TENM,'6'
JL TIMEXT
MOV TENM,'0'
JMP L3
L2: JMP TIMEXT
L3, MOV AL,HOUR
AND AL,0FH
MOV AH,TENH
AND AH,0FH ;应将后四位全保留
MOV CL,4
ROL AH,CL
OR AL,AH
ADD AL,1
DAA
CMP AL,24H ;此时AL中存的是BCD码
JL L1
MOV TENH,'0'
MOV HOUR,'0'
JMP TIMEXT
L1: MOV AH,AL
AND AL,0FH
OR AL,30H
MOV HOUR,AL
MOV CL,4
ROR AH,CL
AND AH,0FH
OR AH,30H
MOV TENH,AH
TIMEXT:
MOV AL,20H
OUT 20H,AL
POP AX
IRET
TIMER ENDP
START ENDP
CODE ENDS
END START
源程序二;
CODE SEGMENT;NO DATA SEGMENT
MOV DX,3FBH
MOV AL,80H
OUT DX,AL
MOV DX,3F8H
MOV AL,12
OUT DX,AL;写入对应波特率9600的波特因子的低八位
INC DX
MOV AL,0
OUT DX,AL;写入对应波特率9600的波特因子的低八位
MOV AL,0BH
MOV DX,3FBH
OUT DX,AL
MOV AL,13H
MOV DX,3FCH
OUT DX,AL ;循环测试
EMPTY:MOV AH,1
INT 16H
JNZ EMPTY
CHECK:MOV DX,3FDH
IN AL,DX
TEST AL,1H
JNZ REV
TEST AL,20H
JZ CHECK
TR: MOV AH,0
INT 16H
JZ CHECK
CMP AL,03H
JZ EXIT
MOV DX,3F8H
OUT DX,AL
JMP CHECK
REV: MOV DX,3F8H
IN AL,DX
AND AL,7FH
MOV BX,0041H
MOV AH,14
INT 10H
JMP CHECK
EXIT,MOV AH,4CH
INT 21H
CODE ENDS
END MAIN