附件1.PCI.ASM
.386
DATA SEGMENT USE16
BUS DB 0
DEVICENO DB 0
FUNC DB 0
VENDOR DW 0
DEVICE DW 0
CLASS DD 0
IRQ DB 0
DEVICETYPE DB 0
ROMBASE DD 0
BASE0 DD 0
COMMAND DW 0
MSG DB 'BUS# DEVICE# FUNC# VENDOR DEVICE CLASS BASE0 IRQ ROM COMMAND', 0
DATA ENDS
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME DS:DATA, CS:CODE, SS:STACK
START:
MOV AX, DATA
MOV DS, AX
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
;显存地址
MOV AX, 0B800H
MOV ES, AX
MOV SI, OFFSET MSG
MOV DI, 80 * 8
CLD
NEXTCHAR:
LODSB
OR AL, AL
JZ OVERCHAR
MOV AH, 7
STOSW
JMP NEXTCHAR
OVERCHAR:
MOV SI, 80 * 10
MOV BUS, 0
MOV DEVICENO,0
MOV FUNC, 0
PCI0:
MOV ROMBASE, 0
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 80000000H
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
CMP AX, 0FFFFH
JZ NEXTPCI
;GET CONFIG SPACE
MOV VENDOR, AX
MOV CL, 16
SHR EAX, CL
MOV DEVICE, AX
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 80000008H
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
MOV CLASS, EAX
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 8000003CH
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
MOV IRQ, AL
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 80000004H
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
MOV COMMAND, AX
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 8000000CH
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
MOV CL, 16
SHR EAX, CL
MOV DEVICETYPE, AL
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 80000030H
MOV DX, 0CF8H
OUT DX, EAX
MOV EBX, EAX
MOV DX, 0CFCH
MOV EAX, 0FFFFFFFEH
OUT DX, EAX
MOV EAX, EBX
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
MOV ROMBASE, EAX
XOR EAX, EAX
MOV AL, BUS
MOV CL, 5
SHL EAX, CL
OR AL, DEVICENO
MOV CL, 3
SHL EAX, CL
OR AL, FUNC
MOV CL, 8
SHL EAX, CL
OR EAX, 80000010H
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
MOV BASE0, EAX
;SIMPLE 0??????
; MOV AL, DEVICETYPE
; AND AL, 07FH
; CMP AL, 0
; JNZ NEXTPCI
;DISPLAY SOMTHING.........
MOV DI, SI
;SHOW BUS#....
MOV AL, BUS
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 10
;SHOW DEVICE#....
MOV AL, DEVICENO
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 16
;SHOW FUNC#....
MOV AL, FUNC
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 14
;SHOW VENDOR ....
MOV AX, VENDOR
MOV CL, 8
ROL AX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL AX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 12
;SHOW DEVICE ....
MOV AX, DEVICE
MOV CL, 8
ROL AX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL AX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 10
;SHOW CLASS.....
MOV EAX, CLASS
MOV CL, 8
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 8
;SHOW BASE0........
MOV EAX, BASE0
MOV CL, 8
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 10
;SHOW IRQ....
MOV AL, IRQ
CALL TOASCII
MOV ES:[DI], EDX
ADD DI,8
;SHOW ROMBASE.........
MOV EAX, ROMBASE
MOV CL, 8
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
ROL EAX, CL
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 12
;SHOW DEVICETYPE.........
MOV AL, DEVICETYPE
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
;SHOW COMAMND.....
MOV AX, COMMAND
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AL, AH
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 8
ADD SI, 80 * 2
NEXTPCI:
CMP FUNC, 7
JNZ PCI1
MOV FUNC, 0
CMP DEVICENO, 31
JNZ PCI2
MOV DEVICENO, 0
CMP BUS, 255
JZ OVER
INC BUS
JMP PCI0
PCI1:
INC FUNC
JMP PCI0
PCI2:
INC DEVICENO
JMP PCI0
;;;;
OVER:
MOV AH, 4CH
INT 21H
;AL->EDX
TOASCII PROC NEAR
PUSH AX
PUSH BX
PUSH CX
XOR EDX, EDX
MOV BL, AL
AND AL, 0FH
CMP AL, 9
JA TO1
ADD AL, '0'
JMP TO2
TO1:
SUB AL, 10
ADD AL, 'A'
TO2:
MOV AH, 7
MOV DX, AX
MOV CL, 16
SHL EDX, CL
MOV CL, 4
SHR BL, CL
CMP BL, 9
JA TO3
ADD BL, '0'
JMP TO4
TO3:
SUB BL, 10
ADD BL, 'A'
TO4:
MOV BH, 7
MOV DX, BX
POP CX
POP BX
POP AX
RET
TOASCII ENDP
CODE ENDS
END START
附件2.R256.ASM
.386
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME CS:CODE, SS:STACK
START:
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
MOV AX, 0B800H
MOV ES, AX
MOV DI, 80 * 10
MOV EBX, 00060000H
MOV CX, 100
NEXTBYTE:
MOV EAX, EBX
MOV DX, 0ECD4H
OUT DX, EAX
PUSH CX
MOV CX, 0FFFFH
LOOP $
POP CX
MOV DX, 0ECD7H
IN AL, DX
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 8
INC EBX
LOOP NEXTBYTE
MOV AH, 4CH
INT 21H
;AL->EDX
TOASCII PROC NEAR
PUSH AX
PUSH BX
PUSH CX
XOR EDX, EDX
MOV BL, AL
AND AL, 0FH
CMP AL, 9
JA TO1
ADD AL, '0'
JMP TO2
TO1:
SUB AL, 10
ADD AL, 'A'
TO2:
MOV AH, 7
MOV DX, AX
MOV CL, 16
SHL EDX, CL
MOV CL, 4
SHR BL, CL
CMP BL, 9
JA TO3
ADD BL, '0'
JMP TO4
TO3:
SUB BL, 10
ADD BL, 'A'
TO4:
MOV BH, 7
MOV DX, BX
POP CX
POP BX
POP AX
RET
TOASCII ENDP
CODE ENDS
END START
附件3.ReadROM.ASM
.386P
DESC STRUC
LIMIT DW 0
BASEL DW 0
BASEM DB 0
ATTR DW 0
BASEH DB 0
DESC ENDS
GDTR STRUC
LIMIT DW 0
BASE DD 0
GDTR ENDS
DATA SEGMENT USE16
GDTNULL DESC <0, 0, 0, 0, 0>
GDTNULLSEL = 0
GDTDATA DESC <0FFFFH, 0, 0, 92H, 0>
GDTDATASEL = OFFSET GDTDATA - OFFSET GDTNULL
GDTCODE DESC <0FFFFH, 0, 0, 98H, 0>
GDTCODESEL = OFFSET GDTCODE - OFFSET GDTNULL
GDTSTACK DESC <0FFFFH, 0, 0, 92H, 0>
GDTSTACKSEL = OFFSET GDTSTACK - OFFSET GDTNULL
GDTDISP DESC <0FFFFH, 8000H, 0BH, 92H, 0>
GDTDISPSEL = OFFSET GDTDISP - OFFSET GDTNULL
GDTREAD DESC <0FFFFH, 0, 00H, 92H, 0FH>
GDTREADSEL = OFFSET GDTREAD - OFFSET GDTNULL
NEWGDTR GDTR <OFFSET NEWGDTR - OFFSET GDTNULL, 0>
DATA ENDS
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME DS:DATA, CS:CODE, SS:STACK
START:
MOV AX, DATA
MOV DS, AX
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
MOV BH, 1 ;PCI总线号为1
MOV BL, 7H ;PCI设备号为7
MOV CH, 0 ;PCI功能号为0
XOR EAX, EAX
MOV AL, BH
MOV CL, 5
SHL EAX, CL
OR AL, BL
MOV CL, 3
SHL EAX, CL
OR AL, CH
MOV CL, 8
SHL EAX, CL
MOV EBX ,EAX
OR EAX, 80000030H
MOV DX, 0CF8H
OUT DX, EAX
MOV EAX, 0F000001H ;设置ROM基地址为0F000000H,并且ROM使能。
; MOV EAX, 0FFFFFFFFH ;可以通过向ROM基地址写入0FFFFFFFH来检查ROM大小
MOV DX, 0CFCH
OUT DX, EAX
;下面使命令寄存器中的存储器空间控制使能
MOV EAX, EBX
OR EAX, 80000004H
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
IN EAX, DX
OR EAX, 2
MOV ECX, EAX
MOV EAX, EBX
OR EAX, 80000004H
MOV DX, 0CF8H
OUT DX, EAX
MOV DX, 0CFCH
MOV EAX, ECX
OUT DX, EAX
;为进入安全模式做准备
MOV AX, DATA
MOV BX, 10H
MUL BX
MOV GDTDATA.BASEL, AX
MOV GDTDATA.BASEM, DL
MOV GDTDATA.BASEH, DH
ADD AX, OFFSET GDTNULL
ADC DX, 0
MOV WORD PTR NEWGDTR.BASE, AX
MOV WORD PTR NEWGDTR.BASE + 2, DX
MOV AX, STACK
MOV BX, 10H
MUL BX
MOV GDTSTACK.BASEL, AX
MOV GDTSTACK.BASEM, DL
MOV GDTSTACK.BASEH, DH
MOV AX, CODE
MOV BX, 10H
MUL BX
MOV GDTCODE.BASEL, AX
MOV GDTCODE.BASEM, DL
MOV GDTCODE.BASEH, DH
CLI
LGDT FWORD PTR NEWGDTR
MOV EAX, CR0
OR EAX, 1
MOV CR0, EAX
DB 0EAH
DW OFFSET PROTECT
DW GDTCODESEL
PROTECT:
MOV AX, GDTSTACKSEL
MOV SS, AX
MOV SP, STACKLEN
MOV AX, GDTREADSEL
MOV FS, AX
MOV AX, GDTDISPSEL
MOV ES, AX
;下面开始读数据了。
MOV SI, 0
MOV CX, 100H
MOV DI, 80 * 10
R1:
MOV AX, FS:[SI]
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AL, AH
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 6
ADD SI, 2
LOOP R1
MOV EAX, CR0
AND EAX, 0FFFFFFFEH
MOV CR0, EAX
DB 0EAH
DW OFFSET REAL
DW SEG REAL
REAL:
MOV AX, DATA
MOV ES, AX
MOV FS, AX
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
MOV AH, 4CH
INT 21H
;AL->EDX
TOASCII PROC NEAR
PUSH AX
PUSH BX
PUSH CX
XOR EDX, EDX
MOV BL, AL
AND AL, 0FH
CMP AL, 9
JA TO1
ADD AL, '0'
JMP TO2
TO1:
SUB AL, 10
ADD AL, 'A'
TO2:
MOV AH, 7
MOV DX, AX
MOV CL, 16
SHL EDX, CL
MOV CL, 4
SHR BL, CL
CMP BL, 9
JA TO3
ADD BL, '0'
JMP TO4
TO3:
SUB BL, 10
ADD BL, 'A'
TO4:
MOV BH, 7
MOV DX, BX
POP CX
POP BX
POP AX
RET
TOASCII ENDP
CODE ENDS
END START
附件4.ROM.ASM
.386P
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME DS:CODE, SS:STACK, CS:CODE
ROMSTART:
;ROM HEADER
HDR_SIG DB 55H, 0AAH
INITSIZE DB (ROMEND - ROMSTART) / 512
INIT DB 0E9H
DW CODESTART - $ -2
RESER1 DB 18 DUP (0)
PPCIDATA DW OFFSET PDS_SIG
;PCI DATA STRUCTURE
PDS_SIG DB 'PCIR'
VENDORID DW 10ECH
DEVICEID DW 8139H
RESER2 DW 0
PDS_LEN DW 24
PDS_VER DB 0
CLSSCODE DB 0, 0, 02H
IMGLEN DW (ROMEND - ROMSTART) / 512
IMGREV DW 0
IMGCLASS DB 0
INDICATOR DB 80H
RESER3 DW 0
;PROCEDURE TOASCII
;AL->EDX
TOASCII PROC NEAR
PUSH AX
PUSH BX
PUSH CX
XOR EDX, EDX
MOV BL, AL
AND AL, 0FH
CMP AL, 9
JA TO1
ADD AL, '0'
JMP TO2
TO1:
SUB AL, 10
ADD AL, 'A'
TO2:
MOV AH, 7
MOV DX, AX
MOV CL, 16
SHL EDX, CL
MOV CL, 4
SHR BL, CL
CMP BL, 9
JA TO3
ADD BL, '0'
JMP TO4
TO3:
SUB BL, 10
ADD BL, 'A'
TO4:
MOV BH, 7
MOV DX, BX
POP CX
POP BX
POP AX
RET
TOASCII ENDP
;NOW CAL CHECKSUM
;PARAM1 DS:SI--> FROM CAL
; DS:DI--> TO CAL
;RETURN AL
CALCS PROC NEAR
PUSH SI
PUSH DI
PUSH CX
MOV CX, DI
SUB CX, SI
MOV AL, 0
NB:
ADD AL, DS:[SI]
INC SI
LOOP NB
NOT AL
INC AL
POP CX
POP DI
POP SI
RET
CALCS ENDP
;#################################
TSRSTART:
PUSHA
MOV AX, 0B800H
MOV ES, AX
MOV AX, CS
MOV DS, AX
CALL TT
TSRMSG DB 'CAN YOU SEE ME?', 0
TT:
POP SI
MOV DI, 80 * 10
;DISPLAY ADDRESS
MOV AX, CS
MOV AL, AH
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AX, CS
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AH, 7
MOV AL, ':'
MOV ES:[DI], AX
ADD DI, 2
MOV AX, SI
MOV AL, AH
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AX, SI
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 6
;;
CLD
NC:
LODSB
OR AL, AL
JZ OVER
MOV AH, 7
STOSW
JMP NC
OVER:
POPA
IRET
TSREND = $
;##################################
;##################################
CODESTART:
PUSHA
MOV AX, 0B800H
MOV ES, AX
MOV AX, CS
MOV DS, AX
CALL CT
;1. DISPLAY SOME MESSAGE
MSG DB 'HELLO WORLD:)', 0
CT:
POP SI
MOV DI, 80 * 10
;DISPLAY ADDRESS
MOV AX, CS
MOV AL, AH
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AX, CS
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AH, 7
MOV AL, ':'
MOV ES:[DI], AX
ADD DI, 2
MOV AX, SI
MOV AL, AH
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 4
MOV AX, SI
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 6
;;
CLD
NC1:
LODSB
OR AL, AL
JZ OVER1
MOV AH, 7
STOSW
JMP NC1
OVER1:
;2. CHANGE IVT
MOV AX, 0
MOV ES, AX
MOV AX, OFFSET TSRSTART
MOV ES:[98H * 4], AX
MOV AX, CS
MOV ES:[98H * 4 + 2], AX
;3.NOW SET INIT SIZE = 0
MOV AL, (TSREND - ROMSTART + 511) / 512
MOV INITSIZE, AL
;4.CAL NEWCHECKSUM
MOV SI, ROMSTART
XOR AH, AH
MOV DI, AX
MOV CL, 9
SHL DI, CL
SUB DI, 2
ADD DI, SI
CALL CALCS
MOV DS:[DI + 1], AL
POPA
RETF
CODEEND = $
DB (512 - ((CODEEND - ROMSTART) AND 1FFH)) - 1 DUP (0)
CHECKSUM DB 0
ROMEND = $
;#####################################
;#####################################
;MYDATE
;********************
WRITEREG DW 0ECD4H
READREG DW 0ECD7H
OKMSG DB 'OK! WRITE SUCCESSFULLY!', 0
ERRMSG DB 'WRITE ERROR! OVER!', 0
START:
MOV AX, CODE
MOV DS, AX
MOV AX, 0B800H
MOV ES, AX
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
; DB 09AH
; DW 3
; DW SEG CODE
MOV SI, ROMSTART
MOV DI, ROMEND
CALL CALCS
MOV CHECKSUM, AL
;NOW WRITE TO ROM AND VERIFY ROM*************
MOV AX, 0B800H
MOV ES, AX
MOV BP, 14 * 80
MOV SI, OFFSET ROMSTART
MOV DI, 0
MOV BX, ROMEND
SUB BX, ROMSTART
NB2:
MOV AL, DS:[SI]
;*********DISPLAY THE BYTE
CALL TOASCII
MOV ES:[BP], EDX
ADD BP, 4
;***********
MOV CL, 24
SHL EAX, CL
MOV AX, DI
MOV DX, WRITEREG
OR EAX, 000A0000H
OUT DX, EAX
;WAIT ....
MOV CX, 0FFFFH
LOOP $
MOV DX, WRITEREG
MOV EAX, 00040000H
MOV AX, DI
OUT DX, EAX
;WAIT ....
MOV CX, 0FFFFH
LOOP $
;.........
MOV DX, READREG
IN AL, DX
CMP AL, DS:[SI]
JNZ ERRDISP
INC SI
INC DI
DEC BX
JNZ NB2
;;;;;;;;;FINISHED! DISP OK!
MOV SI, OFFSET OKMSG
JMP DISP
ERRDISP:
MOV SI, OFFSET ERRMSG
DISP:
MOV DI, 80 * 12
CLD
NEXTCHAR0:
LODSB
OR AL, AL
JZ GOOUT
MOV AH, 7
STOSW
JMP NEXTCHAR0
GOOUT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
附件5.TROM.ASM
.386P
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME CS:CODE, SS:STACK
START:
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
INT 98H
MOV AH, 4CH
INT 21H
CODE ENDS
END START
附件6.W256.ASM
.386
DATA SEGMENT USE16
MSG1 DB 'OK!', 0
MSG2 DB 'ERROR', 0
DATA ENDS
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME CS:CODE, SS:STACK, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AX, 0B800H
MOV ES, AX
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
MOV ESI, 0CC0A0000H ;将0CCH写入到ROM开头
MOV BX, 6 ;的几个字节中
NEXTBYTE:
MOV EAX, ESI
MOV DX, 0ECD4H
OUT DX, EAX
MOV CX, 0FFFFH ;等待一下,以确保写入。
LOOP $
;下面将写入的数据读出,进行校验。
AND EAX, 0FFF7FFFFH
MOV DX, 0ECD4H
OUT DX, EAX
MOV CX, 0FFFFH ;等待一下,以确保写入。
LOOP $
MOV DX, 0ECD7H
IN AL, DX
CMP AL, 0CCH
JNZ ERROR ;校验不通过。出错。
INC ESI ;下一个地址
DEC BX ;减少计数器
JNZ NEXTBYTE
MOV SI, OFFSET MSG1
JMP DISP
ERROR:
MOV SI, OFFSET MSG2
DISP:
MOV DI, 80 * 10
CLD
NEXTCHAR:
LODSB
OR AL, AL
JZ OVER
MOV AH, 7
STOSW
JMP NEXTCHAR
OVER:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
附件7:R128.ASM
.386
STACK SEGMENT USE16
DB 256 DUP (0)
STACKLEN = $
STACK ENDS
CODE SEGMENT USE16
ASSUME CS:CODE, SS:STACK
START:
CLI
MOV AX, STACK
MOV SS, AX
MOV SP, STACKLEN
STI
MOV AX, 0B800H
MOV ES, AX
MOV DI, 80 * 10
MOV EBX, 00064000H
MOV CX, 100
NEXTBYTE:
MOV EAX, EBX
MOV DX, 0ECD4H
OUT DX, EAX
PUSH CX
MOV CX, 0FFFFH
LOOP $
POP CX
PUSH CX
MOV CX, 0FFFFH
LOOP $
POP CX
PUSH CX
MOV CX, 0FFFFH
LOOP $
POP CX
MOV DX, 0ECD7H
IN AL, DX
CALL TOASCII
MOV ES:[DI], EDX
ADD DI, 6
INC EBX
LOOP NEXTBYTE
MOV AH, 4CH
INT 21H
;AL->EDX
TOASCII PROC NEAR
PUSH AX
PUSH BX
PUSH CX
XOR EDX, EDX
MOV BL, AL
AND AL, 0FH
CMP AL, 9
JA TO1
ADD AL, '0'
JMP TO2
TO1:
SUB AL, 10
ADD AL, 'A'
TO2:
MOV AH, 7
MOV DX, AX
MOV CL, 16
SHL EDX, CL
MOV CL, 4
SHR BL, CL
CMP BL, 9
JA TO3
ADD BL, '0'
JMP TO4
TO3:
SUB BL, 10
ADD BL, 'A'
TO4:
MOV BH, 7
MOV DX, BX
POP CX
POP BX
POP AX
RET
TOASCII ENDP
CODE ENDS
END START