flat assembler
Message board for the users of flat assembler.

Index > Windows > C to ASM

Author
Thread Post new topic Reply to topic
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
PSOMESTRUCT *AnyName = NULL;

Thx in advance.
Post 06 Sep 2008, 07:47
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
Code:
AnyName dd 0 ;ptr to SOMESTRUCT    






I like these easy questions too..
Post 06 Sep 2008, 08:07
View user's profile Send private message MSN Messenger Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
i need some sleep before asking haha Wink

But i need more help accesing some values in SOMESTRUCT:

AnyName[dwIndex]->Value
Post 06 Sep 2008, 10:20
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
mov eax,[anyname+dwindex]
mov [value],eax



mov eax,index
mov esi,anyname
mov eax,[esi+eax*4]
mov [value],eax

etc etc...

in 32 bits, all registers can be used as address component.
Post 06 Sep 2008, 11:27
View user's profile Send private message Visit poster's website Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
forgive me if im wrong but i need to acces "value" in structure
Post 06 Sep 2008, 11:41
View user's profile Send private message Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
PSOMESTRUCT *AnyName = NULL;

PSOMESTRUCT typedef ptr SOMESTRUCT

SOMESTRUCT STRUCT
..
..
..
SOMESTRUCT ENDS
Post 06 Sep 2008, 11:44
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
yes, of course.
Post 06 Sep 2008, 12:26
View user's profile Send private message Visit poster's website Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
I still dont get it...

AnyName is a pointer to an array of pointers.

SOMESTRUCT STRUCT

value1 DWORD ?
value2 LPBYTE ?
....
value5 LPSTR ?

SOMESTRUCT ENDS

How i access to value5?

mov eax,index
mov esi,anyname
mov eax,[esi+eax].value5 <- i need something like this

index can be 1,2,3,4 and later i need to INC index and check again value5.

Excuse my poor english.
Post 06 Sep 2008, 13:50
View user's profile Send private message Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
Something like this?

mov esi,AnyName
assume esi:PTR SOMESTRUCT

xor eax,eax
mov ax,Index

mov eax,[esi+eax].SOMESTRUCT.Value5

inc Index

I think i need to MUL the SOMESTRUCT size by index or something.
Post 06 Sep 2008, 14:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
In general:
Code:
mov  ebx, array


mov  esi, index
imul esi, sizeof.structure
mov  {eax|ax|al}, [ebx+esi+structure.field]    
Post 06 Sep 2008, 15:44
View user's profile Send private message Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
ok, seems more clear now...

can you explain me this?

mov eax,[esi+eax*4]

why *4?
Post 06 Sep 2008, 17:16
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
eax*4 is a dword ptr

the processor can apply a scale to registers in addressing.
*1 *2 *3 *4 *5 *8 *9

[eax]
[eax*1+eax]
[eax*2]
[eax*2+eax]
[eax*4]
[eax*4+eax]
[eax*8]
[eax*8+eax]

to access multidimentional arrays, it is the best, use a set of registers to accelerate the addressing.

and to accelerate address calculation, you can use LEA reg,[reg+reg*s+offset]
Post 06 Sep 2008, 17:23
View user's profile Send private message Visit poster's website Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
thx to all who reply! i learned a lot Smile
Post 06 Sep 2008, 20:12
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-2020, Tomasz Grysztar.

Powered by rwasa.