MOV CX,N ; 字节数
CALL LOAD ; 从 "input1.dat"中读取数据
; **** BEGIN ****
LEA SI,RESULT
LEA DI,SOURCE
CLD
INC DI
L0: mov al,[di-1]
;____________________
CMP AL,0
JE QUIT
MOV CX,0FFFFH ; SET THE COUNTER TO 0FFFFH
rep scasb
;____________________ ; 字符串重复搜索, CX=0FFFFH-n
NEG CX ; 10000H-CX->CX
dec cx
;____________________ ; 获得重复次数n
CMP CX,1
ja compress
;J__ COMPRESS
MOV [SI],AL
INC SI
jmp L0
;JMP ________
COMPRESS: MOV [SI],BYTE PTR ESC_CODE
MOV [SI+1],CL
MOV [SI+2],AL
add si,3
;____________________
JMP L0
QUIT:
MOV [SI],AL ; STORE THE ’’00H’’
; **** END ****
LEA DX,RESULT ; 结果数据区首址
LEA SI,NAME1 ; 结果文件名起始地址
MOV CX,N ; 字节数
CALL SAVE ; 保存结果到"output1.dat"文件中
RET
START ENDP
CODE ENDS
END START
input1.dat 文件内容如下:
41 42 42 42 65 42 42 42 42 42 42 42 42 42 42 42
42 42 42 42 42 42 42 42 42 42 42 42 42 42 43 44
44 44 45 48 48 48 48 48 48 48 48 48 48 48 48 48