News:

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

oop oops

Started by flipflop, December 17, 2011, 01:16:55 AM

Previous topic - Next topic

flipflop

Hi i'm new to the forum and im struggling to find a solution to a problem im having

i have been trying to create structs and call them correctly however i dont seem to be able to get it to compile
i could do with a few links to tutorials that cover this or an example that i can follow to see where im going wrong

i need a struct that is recursive eg

mystruct STRUCT DWORD
next mystruct ?
value DWORD ?
mystruct ENDS


have i made any mystakes here?
i also would like an example of the code that can set both values correctly and pass these values correctly to other procs

please help i haven't done any coding in assembler for years and its all changed.

p.s. know any good profilers debuggers that display your own source as they step through the programs?

cheers flipflop

qWord

you can not use a structure inside it's definition:
mystruct STRUCT DWORD
next PVOID ?
value DWORD ?
mystruct ENDS
FPU in a trice: SmplMath
It's that simple!

flipflop

if that is the case how would i go about creating a dynamic tree or list

qWord

Quote from: flipflop on December 17, 2011, 01:30:20 AM
if that is the case how would i go about creating a dynamic tree or list
as shown: use pointers
mystruct STRUCT DWORD
next PVOID ?  ; pointer to next node/element. PVOID == DWORD == 32Bit
value DWORD ?
mystruct ENDS
FPU in a trice: SmplMath
It's that simple!

flipflop

cheers

ill give that a try

flipflop

ok so i have my struct

mystruct STRUCT DWORD
next PVOID ?
value DWORD ?
mystruct ENDS


and im setting the value using


initmystruct proc mystruct:PVOID
    mov eax,mystruct
    mov (mystruct PTR [eax]).value,0
    mov (mystruct PTR [eax]).next,0
    ret
initmystruct endp


this compiles but crashes
ive read some where that the angle brackets make no difference :red

qWord

The code is OK - propably you are passing an invalid pointer to the function.
You may show us your full code.
FPU in a trice: SmplMath
It's that simple!

bomz

Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

initmystruct proto :DWORD

mystruct STRUCT
next PVOID ?
value DWORD ?
mystruct ENDS

.data

.data?

.code
start:

invoke ExitProcess,0

initmystruct proc mystruct1:PVOID
    assume eax:ptr mystruct
   mov eax, mystruct1
    mov [eax].value,0
    mov [eax].next,0
   assume eax:nothing
    ret
initmystruct endp

end start

flipflop

thankyou bomz
much better than what i had wrote. very helpful

scanner proc bufferptr:DWORD,buffersize:DWORD
    LOCAL mystruct :PVOID
    invoke initmystruct,mystruct
    .....more code that does not get executed.......
    ret
scanner endp


this is the code fragment that causes the crash (i put print statements all through my code to find this)


clive

Quote from: flipflop on December 17, 2011, 03:23:41 PM
this is the code fragment that causes the crash (i put print statements all through my code to find this)

Presumably because you need to be passing the address of an actual structure to fill, not a pointer to a pointer, or an empty pointer.
It could be a random act of randomness. Those happen a lot as well.

bomz

This in form which make code much READABLE, but mean this:

Quoteinitmystruct proc mystruct1:PVOID
   mov dword ptr[mystruct1],0
   mov dword ptr[mystruct1+4],0
   ret
initmystruct endp

qWord

Your variable mystruct (which has the same name as the structure?), is not initialized.

...
LOCAL pMystruct:PVOID
mov pMyStruct,alloc(SIZEOF MYSTRUCT) ; allocate new structure
invoke initmystruct,pMyStruct
...

or
...
LOCAL Mystruct:MYSTRUCT
invoke initmystruct,ADDR Mystruct  ; pass pointer to structure
...


MASM has several syntax variantion for accessing structure members through pointers. A common way is: [register].STRUCTURENAME.member
FPU in a trice: SmplMath
It's that simple!

flipflop

cheers brilliant just what i was looking for very helpful indeed thankyou everyone for replies  :U