第三遍,一次成功。
.486
DATA SEGMENT USE16
MSG DB 'HELLO',0DH,0AH,'$'
OLD1C DD ?
ICOUNT DB 18 ;中断服务子程序的
COUNT DB 10 ;显示的行数
DATA ENDS
CODE SEGMENT USE16
ASSUME CS:CODE,DS:DATA
BEG: MOV AX,DATA
MOV DS,AX
CLI
CALL READ1C
CALL WRITE1C
STI
AGA: CMP COUNT,0
JNZ AGA
CALL RESET
MOV AH,4CH
INT 21H
;-------------------------
READ1C PROC
MOV AH,35H
MOV AL,1CH
INT 21H
MOV WORD PTR OLD1C,BX
MOV WORD PTR OLD1C+2,ES
RET
READ1C ENDP
;-------------------------
WRITE1C PROC
PUSH DS
MOV AX,CODE
MOV DS,AX
MOV DX,OFFSET SERVICE
MOV AH,25H
MOV AL,1CH
INT 21H
POP DS
RET
WRITE1C ENDP
;-----------------------------
SERVICE PROC
PUSHA
PUSH DS
MOV AX,DATA
MOV DS,AX
DEC ICOUNT
JNZ EXIT
MOV ICOUNT,18
DEC COUNT
MOV AH,9
MOV DX,OFFSET MSG
INT 21H
EXIT:POP DS
POPA
IRET
SERVICE ENDP
;-----------------------------
RESET PROC
MOV AH,25H
MOV AL,1CH
MOV DX,WORD PTR OLD1C
MOV DS,WORD PTR OLD1C+2
RET
RESET ENDP
CODE ENDS
END BEG
第二遍,看了一下课本,重新写了一下,运行正确。
;实现每隔1s在屏幕上显示你好,显示10次后退出
.486
DATA SEGMENT USE16
ICOUNT DB 18 ;中断计数器初值
ICOUNT1 DB 10 ;显示行数控制
OLD1C DD ?
MSG DB 'HELLO,HELLO!',0DH,0AH,'$'
DATA ENDS
CODE SEGMENT USE16
ASSUME DS:DATA,CS:CODE
BEG: MOV AX,DATA
MOV DS,AX
CLI ;关中断
CALL READ1C ;读出老的1CH中断
CALL WRITE1C ;写入新的1CH中断
STI ;开中断
AGA: CMP ICOUNT1,0
JNZ AGA
CALL RESET ;把旧的中断重写进去
MOV AH,4CH
INT 21H
;----------------------------
READ1C PROC ;读老的1CH中断
MOV AH,35H
MOV AL,1CH
INT 21H
MOV WORD PTR OLD1C,BX
MOV WORD PTR OLD1C+2,ES
RET
READ1C ENDP
;------------------------------------
SERVICE PROC ;中断服务程序
PUSHA
PUSH DS ;DS=40H
MOV AX,DATA
MOV DS,AX
DEC ICOUNT
JNZ EXIT ;不满18次结束
MOV ICOUNT,18
DEC ICOUNT1 ;显示的行数减1
MOV AH,9
MOV DX,OFFSET MSG
INT 21H
EXIT: POP DS
POPA
IRET
SERVICE ENDP
;-----------------------------------
WRITE1C PROC
PUSH DS
MOV AX,CODE
MOV DS,AX
MOV DX,OFFSET SERVICE
MOV AH,25H
MOV AL,1CH
INT 21H
POP DS
RET
WRITE1C ENDP
;-----------------------------------
RESET PROC
MOV AH,25H
MOV AL,1CH
MOV DX,WORD PTR OLD1C
MOV DS,WORD PTR OLD1C+2
INT 21H
RET
RESET ENDP
CODE ENDS
END BEG
开始凭感觉写,什么都不懂写的乱七八糟的代码。
;实现每隔1s在屏幕上显示你好,显示10次后退出
.486
DATA SEGMENT USE16
ICOUNT DB 18
ICOUNT1 DB 10
OLD1C DB '?','?'
MSG DB 'HELLO,HELLO!',ODH,0AH,'$'
DATA ENDS
CODE SEGMENT USE16
ASSUME DS:DATA,CS:CODE
BEG: MOV AX,DATA
MOV DS,AX
CLI ;关中断
CALL READ1C ;读出老的1CH中断
CALL WRITE1C ;写入新的1CH中断
AGA: CMP ICOUNT1,0
JNC AGA
CALL RESET ;把旧的中断重写进去
MOV AH,4CH
INT 21H
;----------------------------
PROC READ1C
MOV AH,35H
MOV AL,1CH
INT 21H
MOV WORD PTR OLD1C,BX
MOV WORD PTR OLD1C+2,ES
IRET
READ1C ENDP
;------------------------------------
PROC WRITE1C
PUSHF
PUSH DS ;DS=40H
MOV AX,CS
MOV DS,AX
MOV DX,0FFSET SERVICE
DEC ICOUNT
DEC ICOUNT1
JNZ EXIT ;不满18次结束
MOV AH,9
MOV DX,0FFSET MEG
INT 21H
EXIT:POP DS
POPA
IRET
WRITE1C ENDP
;------------------------------------
PROC RESET
MOV AH,25H
MOV AL,1CH
MOV DX,WORD PTR 0LD1C
MOV DS,WORD PTR OLD1C+2
INT 21H
RESET ENDP
;-----------------------------------