School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,007 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,007 people online right now. Registration is fast and FREE... Join Now!




Compressing data in 8086?

 

Compressing data in 8086?, The code that i am posting is Decompression data code and i was wondin

BADBOYJIM

20 Oct, 2009 - 03:06 PM
Post #1

New D.I.C Head
*

Joined: 20 Oct, 2009
Posts: 2

The code that i am posting is Decompression data code and i was wonding if there was a way that i can change it into Compression data.
I have no clue where to start. Any ideas? Maybe an example? Anything would be greatly appreciated.

CODE
; rle_soln.asm
; sample program to demonstrate decompressing RLE  

include 'emu8086.inc'

org  100h; set location counter to 100h

jmp CodeStart

DataStart:
   ; this is the run length encoded data
   ; notice that it is a list of words (bytes)
   ; with a zero on the end
    rleData dw 1, 4, 3, 9, 5, 3, 2, 7, 0
    
    space db ' ', 0

CodeStart:

   ; put the address of the first rle value in bx
    mov bx, offset rleData
                            
   ; start a loop that will visit each value in rle data
    LoopStart:
    
   ; compare value in list with zer0
    cmp [bx], 0
    
   ; if value was zero, must be end of list so quit
    je EndLabel:
    
   ; move value in list to ax
   ;Moves bx into cx
    mov cx, [bx]
   ;Adds 2 to bx
    add bx, 2
   ;Moves bx into ax
    mov ax, [bx]
    
   ;InnerLoop is used to jump if cx is greater than 0
    InnerLoop:
    
   ; print it
    call print_num
    
   ; print a space
    mov si, offset space
    call print_string
    
   ;Decrement cx by 1
    sub cx, 1
    
   ;Compare cx to 0
    cmp cx, 0            
    
   ;Jumps to InnerLoop if cx is greater than 0
    jg InnerLoop:
    
   ; add 2 bytes to the address in bx to move to the
   ; next value in the list
    add bx, 2  
    
   ; continue the loop until a zero is found
    jmp LoopStart
    
    EndLabel:
    ret
    
DEFINE_PRINT_STRING    
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS  



User is offlineProfile CardPM
+Quote Post


wildgoose

RE: Compressing Data In 8086?

23 Oct, 2009 - 09:39 AM
Post #2

D.I.C Regular
Group Icon

Joined: 29 Jun, 2009
Posts: 429



Thanked: 55 times
Dream Kudos: 25
Expert In: Assembly,C,C++

My Contributions
You're using a simple runlength encoding. Not sure why you're wasting 16-bits for 8-bit values!

But for an initial optimiztion for your run length
CODE

   mov cx, [bx]     ; Get run length encoding
   mov ax, [bx+2]; Get replicated value
   add bx,4


There are other runlength encoding you can use! Do research on some image runlength like PCX or TGA files.

There's no reason to waste a zero slot to indicate end of data! Use an initial start value to indicate # of bytes or # of codelets.

Runlength should be a signed byte. Use positive 127...0 to indicate a 1...128 replicated bytes. Use -128...-1 to indicate 1...128 copied bytes.

This post has been edited by wildgoose: 23 Oct, 2009 - 09:40 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:02AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month