News:

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

(32 bit) example needed please

Started by wossname, October 29, 2005, 06:41:08 PM

Previous topic - Next topic

wossname

Can someone show me a simple example of a STRUCT that contains a DWORD and a null-terminated string.  Passing a pointer to that struct into a PROCedure that prints the string on the console.

all I have at the moment is this...


MyStruct STRUCT
itsAge DWORD 50
itsName BYTE 21 DUP(0)
MyStruct ENDS

...
.DATA
fred MyStruct <30, "Fred">
.CODE

...

INVOKE DisplayIt, OFFSET fred           ; the call that passed the pointer to the proc

...

DisplayIt PROC,
thing:PTR MyStruct

; ???????

ret
DisplayIt ENDP


The book I'm working through does not tell you how to find the address of fields inside the struct if it is passed in as a pointer.

Please help.

Jeff

if you wanted to the address of a field in a structure:


DisplayIt PROC,
thing:PTR MyStruct

mov eax,thing ;move the address of the structure into eax
lea edx,(MyStruct ptr [eax]).itsName ;load the address of the itsName field into edx
;you have the address of your string in edx

ret
DisplayIt ENDP

hope that helps

rags

This may help you:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *
MyStruct STRUCT             ; changed name member to 24 bytes
        itsAge DWORD 50     ; to keep alignment
        itsName BYTE 24 DUP(0)
MyStruct ENDS

DisplayIt PROTO :DWORD



    .data
      Fred MyStruct <30,"Fred">         ; initialize struct

    .code

start:
    call main
    inkey
    exit

main proc

    cls
    INVOKE DisplayIt, ADDR Fred     ; pass ADDRESS of STRUCT MEMBER to Function
    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DisplayIt PROC   StructPtr:DWORD
mov eax, StructPtr      ; EAX == ADDRESS of Fred
ASSUME eax: PTR MyStruct

lea edx,[eax].itsName   ; get the ADDRESS of Fred.itsName
print edx,13,10         ; edx == ADRESS of itsName struct member

ASSUME eax: NOTHING

ret
DisplayIt  ENDP
end start



Regards,
         Rags
God made Man, but the monkey applied the glue -DEVO

Ratch

wossname,
     This example covers a lot of things about STRUC's.  Ratch

[attachment deleted by admin]

wossname

Cool, cheers for the help.  Got it working now.

Thanks alot  :)