QuestionQuestion

Project Description:
Compressing files using the huffman algorithm. Reads a file, converts character using the huffman algorithm, and stores that into a new file.
We also have to uncompress the file. We take in the compressed file and get back the original file.
Hints:
1) frequency table:
-source file
-read character by character
-increment
2)Represent the tree using arrays data structures
3)Reading command line:
c> compr   infile.dat outfile.dat
for OS | give to you in PSP
         | 80h - length
         | 81h - actual command line ends with CR(13)
   
            ^
            |
            |

Point a register to 81h
1) skip spaces               --
2) copy nonspace to inname    |---> watch for 13
3) skip spaces                |
4) copy nonspace to outcome --
space =0...32 (except for 13)

4)Reading and writing bits:
outbyte db ?
outcnt db ? initially must be 0
-Write-bit:
;input : aL
shl outbyte, 1
or outbyte, aL
inc outcnt   ;increment counter
cmp outcnt, 8
jb skip
;write byte
mov outcnt, 0
skip:
ret

5)Read compressed data
6)Write compressed data
7)Uncompress:
read cmd line
open input
create output
read freq table
build the tree
uncompress
close infile, outfile

8)257 input chars:                  |write freq table
256+EOF mark     |build the tree
all array must have 513 elements    |compress
    flush bits
    close infile, outfile

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

org 100h
jmp start      

    fileToEncode db 256 dup(?)
    fileToDecode db 256 dup(?)
    outH         dw ?    ;Create File Handle
    openH       dw ?    ;Open File Handle
    closeH       dw ?    ;Close File Handle
    freq         dw 512   dup(0)
    upkid       dw 512   dup(0)
    downkid      dw 512   dup(0)
    parent       dw 512   dup(0)
    code         dw 512   dup(?)
    root         dw 400h                                                            
    last_point   dw 0
    min_pos1    dw 0            ;Position of first minimum to be initialized
    min_pos2    dw 0            ;Position of second minimum to be initialized
    message      dw 'This is a test',0
    messageR    dw ?
    encodeMessage    dw 512 dup(?)
    encodeMessageptr dw 0
    encodeMessagelnt dw 0               
    bits         db ?
    bitcount    dw ?
    endbitcount dw ?   
    huffmanmsg dw 'Huffman $'            
    ParseMessageError dw "Unrecognized instructions. $"
    CreateFileMsgError dw "File name must be less than 8 chars!. $"
    minCount    dd 0   
    total       dd 0            ;BYTE LIMITATION IS 65536. TOTAL CANNOT BE MORE!
    value_min_p1 dd 0            ;Value of what's in position 1
    value_min_p2 dd 0            ;Value of what's in position 2   
    min_count_t dd 0      
    word_segment dw ?            ;These indicate the offset and the segments
    word_offset dw ?      
    errorMEssage dw 'Error at: ',0
    i            dw 0   
    prev_i       dw 0
   
start:         
    call GetFileNames
    call OpenInputFile                                 
    call CreateOutputFile   
    call InitFreqTable         
    call WriteTable   
    call TotalFreq
    call Huffman
    call Encode                                                
    jmp exit
   
;Getting file names from command prompt
GetFileNames:
    push ax
    push bx
    push cx
    push dx
    push si
    push di
    mov si, 81h
    mov di, offset fileToEncode
L1:
    xor ax, ax
    mov al, byte ptr [si]
    inc si
    cmp al, 0Dh
    je errorParseFile
    cmp al, 20h ;Space
    je L1
L2:                                        ;Input file               
    mov byte ptr [di], al
    inc di
    mov al, byte ptr [si]
    inc si
    cmp al, 0dh
    je errorParseFile
    cmp al, 20h
    jne L2
    inc di
    mov byte ptr [di], 0                   ;Null terminated string
    mov di, offset fileToDecode      
L3:   
    mov al, byte ptr [si]   
    inc si
    cmp al, 0dh
    je endParse
    mov byte ptr [di], al
    inc di      
    jmp L3   
endParse:
    inc di
    mov byte ptr [di], 0      
    pop di   
    pop si
    pop dx
    pop cx
    pop bx
    pop ax
    ret   
errorParseFile:
    xor ax, ax
    mov ah, 9h
    mov dx, offset ParseMessageError...
$75.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats