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.
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
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
wossname,
This example covers a lot of things about STRUC's. Ratch
[attachment deleted by admin]
Cool, cheers for the help. Got it working now.
Thanks alot :)