News:

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

Syntax for pointers to fields of struct pointers?

Started by wossname, October 29, 2005, 04:19:23 PM

Previous topic - Next topic

wossname

I'm having some problems with the syntax in this simple procedure.

I'm just trying to get the address of a byte field.  See the highlighted line...


;-----------------------------
WriteGameString PROC USES eax edx,
gameMsg:PTR GAMESTRING
;
; Draws a color and xy position prefixed string
;
; Receives: gameMsg = pointer to a GAMESTRING struct that we want to draw
; Returns: NOTHING
;-----------------------------

mov dl, (GAMESTRING PTR gameMsg).xPos
mov dh, (GAMESTRING PTR gameMsg).yPos
CALL GotoXY

movzx eax, (GAMESTRING PTR gameMsg).color
CALL SetTextColor

[b][color=Red] mov edx, OFFSET gameMsg.message          ;     WRONG :([/color][/b]
CALL WriteString

ret
WriteGameString ENDP


Here is my struct definition...

GAMESTRING STRUCT
color BYTE 16 ; defaults to white on black text
xPos BYTE 0 ; defaults to column 0
yPos BYTE 0 ; defaults to row 0
message BYTE 80 * 25 DUP(0), 0       ; enough to fill a default screen (with the compulsory null terminator)
GAMESTRING ENDS


EDX needs to be set to the absolute offset address of that byte field.  I can't seem to work out the right syntax for it.  I keep getting "invalid operand for OFFSET" errors so i'm obviously missing some vital bit of syntax somewhere.

I did think of simply adding a number of bytes to the pointer itself but somehow that seems a bit of a dirty way to do it.

Can anyone help a struggling old C# coder? :)

arafel

how about
mov     eax, gameMsg
lea     edx, [eax.GAMESTRING.message]

wossname

Thanks, but it doesn't seem to make any difference. 

tenkey

Your usage of gameMsg in the other instructions is in error.

According to your PROC, gameMsg is a pointer argument. That is stored in memory (stack is memory). The x86 processor does not support data pointer usage from memory. You need to copy the pointer value into a register.

In addition to what arafel posted, you need:


mov eax, gameMsg
mov dl, [eax.GAMESTRING.xPos]
mov dh, [eax.GAMESTRING.yPos]
CALL GotoXY

mov eax, gameMsg
movzx eax, [eax.GAMESTRING.color]
CALL SetTextColor
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

Retsim_X

helo
wossname

have a look at this post and check out my code in the zip fille

it dosnt have any comments and i am having a different problem with my app but if you want to look at a way to use registers as ptrs to memory.
and accessing structures through it aswell :)

i might not be relevent but have a look any way it may be of some use

http://www.masmforum.com/simple/index.php?topic=3086.0


wossname