Hi,
I wrote a program for my assigment in assembly language class. However, I don't know how to continue to write the program which is use to compress the file into smaller size. Since I am new to assembly, I hope you guys can help me out to debug and revise this program. Thank you.
Allen
The program are the following:
title datacompression
.model small
.stack 100h
.data
err_openfile db 0dh, 0ah, 'Error opening file! $'
err_closefile db 0dh, 0ah, 'Error closing file! $'
err_createfile db 0dh, 0ah, 'Error creating file!$'
in_file db 13 dup (?)
out_file db 13 dup (?)
command_line db 26 dup (?), '$'
compress_code db 3 dup (?)
Buffer db ?
tmpBuffer db ?
cCounter db 0
rCounter db 0
tmpCounter db 0
in_handle dw ?
out_handle dw ?
.code
Main proc
mov ax, @data
mov es, ax
xor cx, cx
xor ah, ah
mov si, 82h
cld
SaveCommandLine:
lodsb
cmp al, 0dh
je EndofCommandLine
push ax
inc cx
jmp SaveCommandLine
EndofCommandLine:
std
lea di, command_line
add di, cx
dec di
mov bx, di
GetCommandLine:
pop ax
stosb
Loop GetCommandLine
mov di, bx
inc di
mov al, '$'
stosb
cld
lea si, command_line
lea di, in_file
mov ax, @data
mov ds, ax
mov ah, 2
WHILE1:
movsb
cmp byte ptr [si], ' '
jne WHILE1
mov byte ptr [di], 0
inc si
lea di, out_file
WHILE2:
movsb
cmp byte ptr [si], 0dh
jne WHILE2
mov byte ptr [di], 0
call RLEcompression
mov ah, 4ch
int 21h
Main endp
RLEcompression proc
mov ah,3dh ; open file
lea dx, in_file
mov al, 0
int 21h
jc tmpFileReadError
mov in_handle, ax
;;output file
mov ah, 3ch
lea dx, out_file
mov cx, 0
int 21h
jc tmpFileCreateError
mov out_handle, ax
mov cx, 1
jmp Begin
tmpFileReadError:
jmp FileReadError
tmpFileCreateError:
jmp FileCreateError
Begin:
and cCounter, 0
and rCounter, 0
and tmpCounter, 0
ReadChar:
mov bx, in_handle
lea dx, Buffer
mov ah, 3fh; read file
int 21h
jc tmpEOF
cmp ax, cx
jne tmpEOF
inc cCounter
cmp cCounter, 1
jne CheckCounter
mov bl, Buffer
mov tmpBuffer, bl
jmp ReadChar
tmpEOF:
jmp EOF
CheckCounter:
mov bl, Buffer
cmp tmpBuffer, bl
jne WriteData
inc rCounter
jmp ReadChar
WriteData:
cmp rCounter, 3
jge WriteCompressedCode
mov bx, out_handle
push cx
mov cl, rCounter
mov tmpCounter, cl
inc tmpCounter
cmp tmpCounter, 1
je NoRepeat
LessThanFour:
mov ah, 40h ; write file
mov cx, 1
lea dx, tmpBuffer
int 21h
dec tmpCounter
cmp tmpCounter, 0
jne LessThanFour
jmp Current
NoRepeat:
mov ah, 40h ; write file
mov cx,1
lea dx, tmpBuffer
int 21h
Current:
mov ah, 40h; write file
mov cx, 1
lea dx, Buffer
int 21h
pop cx
jmp Begin
WriteCompressedCode:
push cx
lea di, compress_code
mov byte ptr [di], '*'
mov bl, rCounter
mov byte ptr [di+1], bl
mov bl, tmpBuffer
mov byte ptr [di+2], bl
mov ah, 40h;write file
mov bx, out_handle
lea dx, compress_code
mov cx,3
int 21h
mov ah, 40h; write file
mov cx, 1
lea dx, Buffer
int 21h
pop cx
jmp Begin
EOF:
mov bx, in_handle
call CloseFile
jc Error2
mov bx, out_handle
call CloseFile
jc Error2
jmp Exit
FileReadError:
mov ah, 9 ; display
lea dx, err_openfile
int 21h
jmp Exit
Error2:
mov ah, 9
lea dx, err_closefile
int 21h
jmp Exit
FileCreateError:
mov ah, 9
lea dx, err_createfile
int 21h
Exit:
mov ah, 4ch
int 21h
ret
RLEcompression ENDP
CloseFile PROC
mov ah, 3eh
int 21h
ret
CloseFile Endp
END Main
I wrote a program for my assigment in assembly language class. However, I don't know how to continue to write the program which is use to compress the file into smaller size. Since I am new to assembly, I hope you guys can help me out to debug and revise this program. Thank you.
Allen
The program are the following:
title datacompression
.model small
.stack 100h
.data
err_openfile db 0dh, 0ah, 'Error opening file! $'
err_closefile db 0dh, 0ah, 'Error closing file! $'
err_createfile db 0dh, 0ah, 'Error creating file!$'
in_file db 13 dup (?)
out_file db 13 dup (?)
command_line db 26 dup (?), '$'
compress_code db 3 dup (?)
Buffer db ?
tmpBuffer db ?
cCounter db 0
rCounter db 0
tmpCounter db 0
in_handle dw ?
out_handle dw ?
.code
Main proc
mov ax, @data
mov es, ax
xor cx, cx
xor ah, ah
mov si, 82h
cld
SaveCommandLine:
lodsb
cmp al, 0dh
je EndofCommandLine
push ax
inc cx
jmp SaveCommandLine
EndofCommandLine:
std
lea di, command_line
add di, cx
dec di
mov bx, di
GetCommandLine:
pop ax
stosb
Loop GetCommandLine
mov di, bx
inc di
mov al, '$'
stosb
cld
lea si, command_line
lea di, in_file
mov ax, @data
mov ds, ax
mov ah, 2
WHILE1:
movsb
cmp byte ptr [si], ' '
jne WHILE1
mov byte ptr [di], 0
inc si
lea di, out_file
WHILE2:
movsb
cmp byte ptr [si], 0dh
jne WHILE2
mov byte ptr [di], 0
call RLEcompression
mov ah, 4ch
int 21h
Main endp
RLEcompression proc
mov ah,3dh ; open file
lea dx, in_file
mov al, 0
int 21h
jc tmpFileReadError
mov in_handle, ax
;;output file
mov ah, 3ch
lea dx, out_file
mov cx, 0
int 21h
jc tmpFileCreateError
mov out_handle, ax
mov cx, 1
jmp Begin
tmpFileReadError:
jmp FileReadError
tmpFileCreateError:
jmp FileCreateError
Begin:
and cCounter, 0
and rCounter, 0
and tmpCounter, 0
ReadChar:
mov bx, in_handle
lea dx, Buffer
mov ah, 3fh; read file
int 21h
jc tmpEOF
cmp ax, cx
jne tmpEOF
inc cCounter
cmp cCounter, 1
jne CheckCounter
mov bl, Buffer
mov tmpBuffer, bl
jmp ReadChar
tmpEOF:
jmp EOF
CheckCounter:
mov bl, Buffer
cmp tmpBuffer, bl
jne WriteData
inc rCounter
jmp ReadChar
WriteData:
cmp rCounter, 3
jge WriteCompressedCode
mov bx, out_handle
push cx
mov cl, rCounter
mov tmpCounter, cl
inc tmpCounter
cmp tmpCounter, 1
je NoRepeat
LessThanFour:
mov ah, 40h ; write file
mov cx, 1
lea dx, tmpBuffer
int 21h
dec tmpCounter
cmp tmpCounter, 0
jne LessThanFour
jmp Current
NoRepeat:
mov ah, 40h ; write file
mov cx,1
lea dx, tmpBuffer
int 21h
Current:
mov ah, 40h; write file
mov cx, 1
lea dx, Buffer
int 21h
pop cx
jmp Begin
WriteCompressedCode:
push cx
lea di, compress_code
mov byte ptr [di], '*'
mov bl, rCounter
mov byte ptr [di+1], bl
mov bl, tmpBuffer
mov byte ptr [di+2], bl
mov ah, 40h;write file
mov bx, out_handle
lea dx, compress_code
mov cx,3
int 21h
mov ah, 40h; write file
mov cx, 1
lea dx, Buffer
int 21h
pop cx
jmp Begin
EOF:
mov bx, in_handle
call CloseFile
jc Error2
mov bx, out_handle
call CloseFile
jc Error2
jmp Exit
FileReadError:
mov ah, 9 ; display
lea dx, err_openfile
int 21h
jmp Exit
Error2:
mov ah, 9
lea dx, err_closefile
int 21h
jmp Exit
FileCreateError:
mov ah, 9
lea dx, err_createfile
int 21h
Exit:
mov ah, 4ch
int 21h
ret
RLEcompression ENDP
CloseFile PROC
mov ah, 3eh
int 21h
ret
CloseFile Endp
END Main