Compressing data in 8086?

The code that i am posting is Decompression data code and i was wondin

Page 1 of 1

1 Replies - 1834 Views - Last Post: 23 October 2009 - 10:39 AM Rate Topic: -----

#1 BADBOYJIM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-October 09

Compressing data in 8086?

Posted 20 October 2009 - 04:06 PM

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.

; rle_soln.asm
; sample program to demonstrate decompressing RLE   

include ''

org  100h; set location counter to 100h

jmp CodeStart

   ; 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


   ; 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
   ; 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
   ; 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

Is This A Good Question/Topic? 0
  • +

Replies To: Compressing data in 8086?

#2 wildgoose   User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 468
  • Joined: 29-June 09

Re: Compressing data in 8086?

Posted 23 October 2009 - 10:39 AM

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
   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 October 2009 - 10:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1