How do I modify this program so that it only prints out the decompress

How do I modify this program so that it only prints out the decompress

Page 1 of 1

5 Replies - 2224 Views - Last Post: 18 August 2009 - 11:16 AM Rate Topic: -----

#1 CaptKid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 16-August 09

How do I modify this program so that it only prints out the decompress

Posted 16 August 2009 - 10:33 AM

How do I modify this program so that it only prints out the decompressed data?

; 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
mov ax, [bx]

; print it
call print_num

; print a space
mov si, offset space
call print_string

; 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

Is This A Good Question/Topic? 0
  • +

Replies To: How do I modify this program so that it only prints out the decompress

#2 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: How do I modify this program so that it only prints out the decompress

Posted 17 August 2009 - 01:08 AM

What tools are you using?

Is the DataSegment set to the Code Segment as a default?

You do realize that you can use <db> data byte as your values are less then 256? You are using 16-bit values and they are 3-bit values.
rleData db 1, 4, 3, 9, 5, 3, 2, 7, 0



I've reworked this problem after posting because it was incomplete and found your duplicate post had more information!!!

In simple graphics there are runlengths with byte runs. A run code of replicated values, or a count of bytes to copy. It is typically if a negative value versus a positive value +1 .
You do have possible pairs
1,4, 3,9, 5,3, 2,7, 0 terminator

Since I found this.... 4 9 9 9 3 3 3 3 3 7 7 ....in your other post it now makes sense!



I couldn't see anything wrong with your code but I twiddled it to save on your double branch-jump.


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 db 1, 4, 3, 9, 5, 3, 2, 7, 0	 ;  <-- Set to DB

space db ' ', 0



CodeStart:

; put the address of the first rle value in bx
	xor bx,bx

Loop:
	mov cl, rleData[bx]	; run length (1 based)
	mov al, rleData[bx+1] ; char to replicate
	add bx, 2	; Set for next value in list!

; print it
; ??? How well is AX preserved????
	mov ah,0	   ; Don't know which processor you're using
				; so set upper bits the old way.

PrtChr:
	call print_num

	; print a space
	mov si, offset space
	call print_string

	dec	cl
	bne	PrtChr

	cmp	byte ptr rleData[bx],0
	jne	Loop	; continue the loop until a zero is found

EndLabel:
	ret



This post has been edited by wildgoose: 17 August 2009 - 01:20 AM

Was This Post Helpful? 0
  • +
  • -

#3 CaptKid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 16-August 09

Re: How do I modify this program so that it only prints out the decompress

Posted 17 August 2009 - 06:36 AM

EMU8086 application is what we are using.
Was This Post Helpful? 0
  • +
  • -

#4 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: How do I modify this program so that it only prints out the decompress

Posted 17 August 2009 - 06:54 AM

AND? Did the code change work? Or is it still broken and where?
Was This Post Helpful? 0
  • +
  • -

#5 CaptKid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 16-August 09

Re: How do I modify this program so that it only prints out the decompress

Posted 18 August 2009 - 05:54 AM

View Postwildgoose, on 17 Aug, 2009 - 05:54 AM, said:

AND? Did the code change work? Or is it still broken and where?

will i tryed it and nothing happend any more help would be great
Was This Post Helpful? 0
  • +
  • -

#6 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: How do I modify this program so that it only prints out the decompress

Posted 18 August 2009 - 11:16 AM

Seems I had a trial version of EMU8086 installed for someone else's problem. It's expired so I can only compile, not run!

include "emu8086.inc"

org 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 db 1, 4, 3, 9, 5, 3, 2, 7, 0	;  <-- Set to DB

space db ' ', 0



CodeStart:

; put the address of the first rle value in bx
	xor bx,bx

Loop:
	mov cl, rleData[bx]   ; run length (1 based)
	mov al, rleData[bx+1]; char to replicate
	add bx, 2   ; Set for next value in list!

; print it
; ??? How well is AX preserved????
	mov ah,0	  ; Don't know which processor you're using
			   ; so set upper bits the old way.

PrtChr:  call print_num

   ; print a space
	mov si, offset space
	call print_string

	dec	cl
	jne	PrtChr

	cmp	byte ptr rleData[bx],0
	jne	Loop   ; continue the loop until a zero is found

EndLabel:

	ret


DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS 
DEFINE_PRINT_STRING
	end


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1