News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Arrgggh! Arrays of structures

Started by Astro, August 09, 2009, 11:05:11 PM

Previous topic - Next topic

Astro

Quote200000005h
:eek

How does 0x2 translate to 0x200000000 ????  :eek

Oh... wait... EDX:EAX = 0x2:0x0 = 2000000000h ?

Arrghhh so I was trying to divide 200000000h by 5 ?

OMG... I'm destined to never get this.  :'(

Best regards,
Astro.

dedndave

sounds like you got it, to me   :U

ecube

anything faster than simply doing add edi,sizeof struct to point to the next entry? even if that means making the structure  larger, e.g divisiable by 16 exactly?

Astro

 :dazzled:

I'll be back tomorrow to have a good read.

Best regards,
Astro.

Astro

 :dazzled:

; Allocate memory for ServiceTable structure
push 8h
push 8h
push hProcHeap
call HeapAlloc
mov ServiceTable,eax

; Populate structure with data
mov ServiceTable, offset ServiceName
mov ServiceTable+4, ServiceMain


The handle to the memory stored in ServiceTable from HeapAlloc is being trashed.

After HeapAlloc call:

eax = 001429D0

00403000  00 00 14 00 00 00 00 00  .......
00403008  00 00 00 00 00 00 00 00  ........


After storing of pointer:

00403000  00 00 14 00 D0 29 14 00  ...Р).
00403008  00 00 00 00 00 00 00 00  ........


After moving offset to the string to the first dword of the memory block (I hoped) pointed to by ServiceTable:

00403000  00 00 14 00 00 10 40 00  ....@.
00403008  00 00 00 00 00 00 00 00  ........


You will see the location was trashed and over-written.

I can't see how to reference the new memory.  :(

Best regards,
Astro.

dedndave

first of all, HeapCreate returns a handle

        INVOKE  HeapCreate,NULL,dwInitialSize,dwMaximumSize
        mov     hHeap,eax

secondly, if you are creating a heap of only 8 bytes, you don't need a heap
but, if you DID need a heap, you now have a handle for one
after that, you need to allocate a block in the heap

        INVOKE  HeapAlloc,hHeap,NULL,dwBytes
        mov     ServiceTablePointer,eax

finally, you are still trying to access memory through an address that is stored in memory
no, no, no ! - can't do that

        mov     edx,ServiceTablePointer
        mov     [edx],offset ServiceName
        mov     [edx+4],offset ServiceMain

Astro

Quotefinally, you are still trying to access memory through an address that is stored in memory
no, no, no ! - can't do that
OK.

So to ensure I finally get this - memory can only *store* pointers, they can't be used directly, ever?

To be more technical, I think I'm attempting to use indirect memory addressing?

Best regards,
Astro.

Astro

call HeapAlloc
mov ServiceTable,eax

; Populate structure with data
mov edx, ServiceTable
mov [edx], offset ServiceName
mov [edx+4], offset ServiceMain


:U

Best regards,
Astro.

dedndave

the problem you are having, my friend, is this:
when you define data in the data segments, you can assign a label to it and access it with that label

        .data

SomeData dd 7

        .code

        mov     eax,SomeData  ;eax = 7

BUT, when you allocate memory in the heap, the assembler cannot assign labels to those addresses
because the assembler has no idea where they will be located
SO, you must use some other form of addressing to access that memory   :U

Astro

OK!  :thumbu

Thanks.

Best regards,
Astro.