flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > use proc macro without OS

Author
Thread Post new topic Reply to topic
Byte



Joined: 21 Mar 2026
Posts: 4
Byte 21 Mar 2026, 18:13
I need clean program code in 32-bit mode using 'proc' and 'invoke' macros.
An error occurs during compilation.

Code:
invoke _OutMsg, txtToOut, EAX
/inc/proc32.inc [20] invoke [6]:
   call [proc] }
processed: call[_OutMsgIn12h]
error: operand size not specified    


Code:
Code:
format binary

_OutMsgIn12h% = 2

use32

include '../inc/proc32.inc'

_OutMsg   EQU   _OutMsgIn12h

txtToOut    DB   'Hello from protected mode', 0
.....
.....
.....
xor      eax, eax
mov    ax, 216
shl      eax, 16
mov   ax, 239
invoke _OutMsg, txtToOut, eax
....
....
....
proc _OutMsgIn12h stdcall, txtmsg:DWORD, xy:DWORD
   push  ecx

  mov  ecx, [txtmsg]
  mov  edx, [xy]
  ......
  ......
  ......
omsg_end:
   pop  ecx
   ret
endp

    


Can anyone help? I used MASM before, but I couldn't generate non-PE 32-bit code with it.
Post 21 Mar 2026, 18:13
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4409
Location: vpcmpistri
bitRAKE 21 Mar 2026, 19:30
You left out what tool you're actually using.

stdcall is the general macro to call functions.
invoke is engineered for indirect calls specifically (typically external).
Code:
macro invoke?: proc*,args&
        stdcall [proc],args
end macro    
Post 21 Mar 2026, 19:30
View user's profile Send private message Visit poster's website Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 4
Byte 21 Mar 2026, 20:47
bitRAKE wrote:
You left out what tool you're actually using.

Sorry. I use FASM for DOS. What prevents me from using invoke to call my own functions like I did in MASM?
I can't understand why the error is in the unspecified operand size?
Post 21 Mar 2026, 20:47
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20913
Location: In your JS exploiting you and your system
revolution 21 Mar 2026, 21:03
invoke is an indirect call.
stdcall is a direct call.
Code:
call [my_proc] ; indirect call
call the_proc  ; direct call

my_proc dd the_proc

the_proc:
  ret    
Indirect calls (invoke) is used for DLL linking.
Post 21 Mar 2026, 21:03
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4409
Location: vpcmpistri
bitRAKE 21 Mar 2026, 21:06
The unspecified operand size error is because the call instruction has many forms.

FASM didn't aim for parity with MASM. Of course, it's possible to write your own invoke - I don't use it myself. The way you're using it is little more than an extended CALL instruction.

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 21 Mar 2026, 21:06
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20913
Location: In your JS exploiting you and your system
revolution 21 Mar 2026, 21:13
Rewriting _OutMsg EQU _OutMsgIn12h can make invoke work
Code:
_OutMsg   dd   _OutMsgIn12h    
But it is wasteful. Just use a direct call then the entire line can be removed.
Post 21 Mar 2026, 21:13
View user's profile Send private message Visit poster's website Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 4
Byte 21 Mar 2026, 21:35
Thank you very much everyone for your answers!
This advice solved my issue.
revolution wrote:
Rewriting _OutMsg EQU _OutMsgIn12h can make invoke work
Code:
_OutMsg   dd   _OutMsgIn12h    
But it is wasteful. Just use a direct call then the entire line can be removed.

Using invoke avoids errors when working with variables on the stack. And using proc structures the code better than simply jumping to a label.
MASM is a good assembler. Unfortunately, it is not very suitable for writing OS-independent code (unless it is 16-bit code). I will study FASM.

P . S . Another question: can FASM create a listing file?


Last edited by Byte on 21 Mar 2026, 21:40; edited 1 time in total
Post 21 Mar 2026, 21:35
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20913
Location: In your JS exploiting you and your system
revolution 21 Mar 2026, 21:39
stdcall is a less wasteful option, that provides all the same protections from errors as invoke.
Code:
stdcall _OutMsgIn12h, txtToOut, eax    
Post 21 Mar 2026, 21:39
View user's profile Send private message Visit poster's website Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 4
Byte 21 Mar 2026, 21:42
revolution wrote:
stdcall is a less wasteful option, that provides all the same protections from errors as invoke.

Thank you, I will let you know.
Post 21 Mar 2026, 21:42
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20913
Location: In your JS exploiting you and your system
revolution 21 Mar 2026, 21:44
Byte wrote:
P . S . Another question: can FASM create a listing file?
Look under the "tools\listing" folder in the fasm download.
Post 21 Mar 2026, 21:44
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.