flat assembler
Message board for the users of flat assembler.

Index > Main > array of pointers

Author
Thread Post new topic Reply to topic
derPENGUIN



Joined: 09 Jul 2006
Posts: 5
derPENGUIN 16 Jul 2006, 06:13
sry, newbie-question...

Good morning.
I want to store some adresses in an array. That is my code:
Code:
DATA
index dd 0x0
offset dd 0x0
count dd 0x0
wp: times 255 dd 0x0

CODE
build_array:
    cmp [index],0
    jnz no_main
    mov [offset],edi
  no_main:
    mov eax,[index]
    inc eax
    mov [wp+eax],edi                ; in edi we got the structure offset
    mov [index],eax
    mov [count],eax
ret

PSEUDO
printf("count:%d\n",[count]); //corrrect
printf("point:%d\n",[wp+someIndex]); //incorrrect
    


I cannot figure out, where it stores the data, but eax counts fine. What is wrong?
The second question will be: how can I access the content of address, which is written to wp+ìndex?

Thanks

PS.: Using FASM 1.66 on MenuetOS
Post 16 Jul 2006, 06:13
View user's profile Send private message Reply with quote
viki



Joined: 03 Jan 2006
Posts: 40
Location: Czestochowa, Poland
viki 16 Jul 2006, 08:04
there is no loop for filling array
Code:

  xor bx,bx
loop:
  mov [array+bx],bx
  inc bx
  cmp bx,5
  jne loop
    
Post 16 Jul 2006, 08:04
View user's profile Send private message Reply with quote
JohnnyReb



Joined: 25 Jun 2006
Posts: 8
JohnnyReb 16 Jul 2006, 10:43
I'm kinda new myself, but try:

mov [wp+eax*4],edi

to index into a DWORD array.

_________________
JohnnyReb
Win if you can, Lose if you must, but always cheat!
Post 16 Jul 2006, 10:43
View user's profile Send private message Reply with quote
viki



Joined: 03 Jan 2006
Posts: 40
Location: Czestochowa, Poland
viki 16 Jul 2006, 17:05
and what about this
Code:
mov esi,src
mov edi,dst
mov cx,len
rep stosd
    
Post 16 Jul 2006, 17:05
View user's profile Send private message Reply with quote
derPENGUIN



Joined: 09 Jul 2006
Posts: 5
derPENGUIN 17 Jul 2006, 08:13
Thank you for reply.
viki:
A loop is not needed, because I use it as a function. Its for a library and I dont know the count of calls. And yuor second example, the same, I dont have len.
Johnny:
yes, tha was it. eax*4 works. Now I will try to access the content of this saved addresses. If you have any idea, please tell me.

Much thanks,
Frank
Post 17 Jul 2006, 08:13
View user's profile Send private message Reply with quote
JohnnyReb



Joined: 25 Jun 2006
Posts: 8
JohnnyReb 17 Jul 2006, 10:46
Access a DWORD array the same way:

printf("point:%d\n",[wp+eax*4]);

or (if it requires pushing on the stack)

mov esi,[wp+eax*4)
printf("point:%d\n",esi);

_________________
JohnnyReb
Win if you can, Lose if you must, but always cheat!
Post 17 Jul 2006, 10:46
View user's profile Send private message Reply with quote
derPENGUIN



Joined: 09 Jul 2006
Posts: 5
derPENGUIN 17 Jul 2006, 21:10
thx, I solved it in this way:
mov edi,[wp+eax*4]
printf("point:%d\n",[edi])

BTW, printf is not an asm keyword, is it? I am really better in C as in asm, but actually I´m coding for Menuet, the output there is with int 40, but I think, that is not related to my problem, therefor I used the C syntax.

Much thanks again and cu with further problems, I´m sure Wink
Post 17 Jul 2006, 21:10
View user's profile Send private message 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.