flat assembler
Message board for the users of flat assembler.

Index > Linux > Increasing offset whilst reading/writing

Author
Thread Post new topic Reply to topic
andyz74



Joined: 26 Nov 2007
Posts: 36
Location: Germany
andyz74 17 Oct 2010, 16:27
Hello, it's me again, the noob. :-/

I tried to copy content bitwise from one "array" to another, by increasing the offset of the array, but i got no working version. Sad

As an example, I have...

Code:
  sub [zeugs],18h
     sub [zeugs+1],18h
   sub [zeugs+2],18h
   sub [zeugs+3],18h
   sub [zeugs+4],18h
   sub [zeugs+5],18h
   sub [zeugs+6],18h
   sub [zeugs+7],18h
   sub [zeugs+8],18h
   sub [zeugs+9],18h
   sub [zeugs+10],18h
    

...where U can see, that the increasing of the offset was done by hand ( +1 +2 +3) and so on...
If I do sth like

Code:
    sub [zeugs+cl],18h
    

with "cl" being increased automatically, i get some error by the compiler.

So how can I get a workaround for this problem? Anybody could help me please with this?
Post 17 Oct 2010, 16:27
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Oct 2010, 17:05
Since you posted in Linux, you need 32-bit addresses, therefore you need to use ECX instead of just CL (lower 8 bits of ECX).

For your first code you could do this:
Code:
mov ecx, 0

.loop:
  mov byte [zeugs+ecx], 18h
  inc ecx
  cmp ecx, 10
  jbe .loop    

And to copy one array into another:
Code:
mov ecx, 0
mov edi, dstArray
mov esi, srcArray
.loop:
  mov al, [srcArray+ecx]
  mov [dstArray+ecx], al
  inc ecx
  cmp ecx, srcArraySize
  jb .loop    

Or just:
Code:
mov ecx, srcArraySize
mov edi, dstArray
mov esi, srcArray
rep movs byte[edi], byte[esi]    
In all cases I'm been working with byte arrays.
Post 17 Oct 2010, 17:05
View user's profile Send private message Reply with quote
andyz74



Joined: 26 Nov 2007
Posts: 36
Location: Germany
andyz74 17 Oct 2010, 18:04
OK, this seems to work with the 32-bit-registers. No more compilation-errors.

Many thanks for the fast help! Smile
Post 17 Oct 2010, 18:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.