Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help in a design of compressor program

Status
Not open for further replies.

popohoma

Programmer
Oct 20, 2002
5
0
0
US
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
 
Don't think anyone will read it entirely. Tell what's the problem?
 
the problem is the program doesn't work.
I hope some body can check my program

thanks
 
They don't expect you to comment your program in your class?
 
no, we don't need to present our program in class, i just have to complete this program. However, i am stuck, so i hope somebody can help me.
 
I meant that you MUST make notices in your prog. It's not a matter of class; its about other people who will look at. You can't expect to be help without helping others to understand your code.
 
It would be nice to know WHERE it doesn't work, too...

Does it assemble okay?
Does it link okay?
Does it load and run okay?
Does it load, print a lot of computer-understandable curse words, then go beeping until you press the reset button?
Does it toast your computer? "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top