0

I'm trying to use run length encoding to output multiple, different length, strings. I can output one string, but as soon as I try to modify the code so that multiple strings are output I only get errors. This code below works as expected and allows me to change the values in rle or movement successfully to control the start point and lenght of the string. What I want to do is to be able to read multiple values from rle and then use these to output strings of different lengths. However if I add more than one value to rle (such as rle, dw 2,7,0) I get no output. Likewise if I dont have the zero (such as rle dw 2) I get no output. This code is part of a larger bit of code, all of which works, and this is just the essential part where my issue exists.

section .text

global _start

_start:

    mov     ecx, stars          ; load the output data string into ecx
    mov     edx, dword[rle]     ; define string output length (initially 2)
    mov     eax, 0x4            ; set output type as sys_write
    inc     ecx                 ; move along one position (so go from B not A)
    inc     ecx                 ; move along one position (so go from C not B)
    mov     ebx, dword[movement] ; get the value from movement (1 the first time)
    add     edx, ebx            ; add 1 (ebx via movement) to 2 (edx from rle) >> 3
    mov     ebx, 1               ; now set ebx for printing
    int     80h
    
section .data

    stars db "ABCDE",0
    rle dw 2,0;
    movement dw 1,0,-1,0;
   
segment .bss

I've tried all types of different rle data. Only where I have the initial length (2) followed by a zero terminator does it work successfully (outputs CDE in this example).

What I was expecting was that if I added more comma seperated values into rle, I would be able to point at them and then use those values to control my output length.

Ed G
  • 1
  • Also, I can use rle dw 2,0,1,0; for example, and then use mov edx, dword[rle+4] to select 1 rather than 2 as my value in edx. However, I want to use an incremented variable here rather than a fixed value. this is what I really want to do – Ed G Dec 26 '22 at 23:51
  • 2
    `dw` is not `dword`. You likely want `dd`. You may have other errors but that would the first thing to fix. – Jester Dec 27 '22 at 00:21
  • 1
    See also [How should strace be used?](https://stackoverflow.com/q/174942) - tracing the system calls will make it clear that you'd be passing garbage in the high half of the dword length to the system-call if the 2nd word of `rle` isn't `0`. Also, a debugger would show the value in `ebx` after a load. – Peter Cordes Dec 27 '22 at 04:14

0 Answers0