Ivan
Ivan

Reputation: 649

FASM: How to send struct to proc?

I have a struct like this:

struct MESGE
     TEXT db 'Message',0
     mLen db 8
ends 

And I need to send it to a proc, which will show line on a screen:

proc OutMes, pMESG:MESGE

  push 0
  push chrsWritten
  push [pMESG.mLen]
  push [pMESG.TEXT]
  push [hStdOut]
  call [WriteConsoleA]

  ret
endp

How can I do this? If I use MESGE type in parameter, then fasm reports an error. If I use a dword type (to send MESGE as ptr) I don't know, how to retrieve members of this struct (actually, they can be retrieved by offset's but I don't like this method - if there are many members in struct, constructions will be so complicated)

At MASM it can be done like this:

ShowMessage PROC hMes: dword
mov ebx,hMes
assume ebx:ptr MESG
...

But at FASM construction

assume ebx:ptr MESG
or 
assume ebx:[ptr MESG]

Reported as error. How can I do this?

Upvotes: 1

Views: 1385

Answers (1)

Jens Björnhager
Jens Björnhager

Reputation: 5648

Perhaps you are looking for the virtual directive:

struct MESGE
        TEXT db 'Message',0
        mLen dd 8
ends

.code
        mov     ebx,pMESGE
        call    OutMes
        ret


virtual at ebx
        oMESGE MESGE
end virtual

proc OutMes
        push 0
        push dummy
        push [oMESGE.mLen]
        lea  eax,[oMESGE.TEXT]
        push eax
        push [hout]
        call [WriteConsoleA]
        ret
endp

.data

pMESGE  MESGE
dummy   rd 1
hout    rd 1

Upvotes: 2

Related Questions