FASM:如何将结构发送到proc?

时间:2012-01-23 18:22:35

标签: assembly fasm

我有这样的结构:

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

我需要将它发送到一个proc,它会在屏幕上显示一行:

proc OutMes, pMESG:MESGE

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

  ret
endp

我该怎么做?如果我在参数中使用MESGE类型,则fasm报告错误。如果我使用dword类型(将MESGE作为ptr发送)我不知道如何检索此结构的成员(实际上,它们可以通过偏移检索,但我不喜欢这样方法 - 如果struct中有很多成员,那么构造就会很复杂)

在MASM,可以这样做:

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

但是在FASM建设中

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

报告为错误。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

也许您正在寻找虚拟指令:

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