Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Decompressing RLE Data in Assembly Code

Name: Anonymous 2008-12-13 17:09

Hello, /prog/.  I'm trying to decompress some rle data in this program using a nested inner loop. There's more than one way to do it, but I'm having trouble going in the right direction. Could anyone give me some help/advice as to what I should start with concerning the nested inner loop?  Thanks.

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, over 9000, 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

Name: Anonymous 2008-12-14 8:00

    .text
    .p2align 2,,3
.globl _decode_rle
    .def    _decode_rle;    .scl    2;    .type    32;    .endef
_decode_rle:
    pushl    %ebp
    movl    %esp, %ebp
    pushl    %edi
    pushl    %esi
    pushl    %ebx
    movl    $4108, %eax
    call    __alloca
    leal    -4108(%ebp), %edi
    movl    $4096, %ecx
    xorl    %eax, %eax
    rep stosb
    movl    8(%ebp), %edx
    movl    16(%ebp), %esi
    movl    $1, %ebx
L2:
    movl    %edx, %eax
    subl    8(%ebp), %eax
    cmpl    12(%ebp), %eax
    jge    L3
    movb    (%edx), %al
    movb    %al, -4113(%ebp)
    incl    %edx
    movl    $0, -4120(%ebp)
    jmp    L7
    .p2align 2,,3
L13:
    movb    (%edx), %al
    movb    %al, -4108(%ebp,%ebx)
    movb    %al, (%esi)
    incl    %esi
    incl    %ebx
    incl    %edx
    andl    $4095, %ebx
L5:
    incl    -4120(%ebp)
    cmpl    $8, -4120(%ebp)
    je    L2
    shrb    -4113(%ebp)
L7:
    movl    %esi, %eax
    subl    16(%ebp), %eax
    cmpl    20(%ebp), %eax
    jge    L3
    testb    $1, -4113(%ebp)
    jne    L13
    leal    1(%edx), %eax
    movl    %eax, -4112(%ebp)
    movb    1(%edx), %al
    movb    %al, %cl
    shrb    $4, %cl
    movzbl    %cl, %ecx
    movzbl    (%edx), %edx
    sall    $4, %edx
    andl    $15, %eax
    leal    2(%eax), %edi
    addl    %ecx, %edx
    je    L3
    xorl    %ecx, %ecx
    .p2align 2,,3
L6:
    movb    -4108(%ebp,%edx), %al
    movb    %al, -4108(%ebp,%ebx)
    movb    %al, (%esi)
    incl    %esi
    incl    %ebx
    incl    %edx
    andl    $4095, %edx
    andl    $4095, %ebx
    incl    %ecx
    cmpl    %ecx, %edi
    jg    L6
    movl    -4112(%ebp), %edx
    incl    %edx
    jmp    L5
    .p2align 2,,3
L3:
    movl    16(%ebp), %eax
    addl    $4108, %esp
    popl    %ebx
    popl    %esi
    popl    %edi
    leave
    ret

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List