×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help in a design of compressor program

Help in a design of compressor program

Help in a design of compressor program

(OP)
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

RE: Help in a design of compressor program

Don't think anyone will read it entirely. Tell what's the problem?

RE: Help in a design of compressor program

(OP)
the problem is the program doesn't work.
I hope some body can check my program

thanks

RE: Help in a design of compressor program

They don't expect you to comment your program in your class?

RE: Help in a design of compressor program

(OP)
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.

RE: Help in a design of compressor program

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.

RE: Help in a design of compressor program

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."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close