sirs;
How can I use @ProcName? Any example?
Thanks.
http://masm32.com/board/index.php?topic=6821.msg73122#msg73122 (http://masm32.com/board/index.php?topic=6821.msg73122#msg73122)
Quote from: mineiro on February 19, 2023, 10:35:28 PM
sirs;
How can I use @ProcName? Any example?
Thanks.
ChatGPT :biggrin: :biggrin: :biggrin:
In Microsoft Macro Assembler (MASM), @ProcName is a predefined symbol that can be used to reference the name of the current procedure or function being assembled. Here's an example of how to use @ProcName in MASM:
MyProc PROC
push ebp
mov ebp, esp
; Get the name of the current procedure
mov edx, OFFSET @ProcName
; Print the procedure name to the console
push OFFSET format_string
push edx
call printf
mov esp, ebp
pop ebp
ret
format_string db "%s",0
MyProc ENDP
In the above example, the MyProc procedure gets the name of the current procedure using the @ProcName symbol and prints it to the console using the printf function. Note that @ProcName is an assembler directive and should be used with the OFFSET operator to get the address of the symbol.
When assembled and linked with a C runtime library that provides printf, this program should print the name of the MyProc procedure to the console when executed.
In Microsoft Macro Assembler (MASM), @ProcName can be used for debugging purposes to help identify the name of the current procedure or function being executed. Here's an example of how to use @ProcName for debugging in MASM:
.MODEL flat, stdcall
OPTION casemap:none
MyProc PROC
push ebp
mov ebp, esp
; Get the name of the current procedure
mov edx, OFFSET @ProcName
; Print the procedure name to the debugger
int 3 ; Breakpoint to launch the debugger
; Note: the debugger should display the procedure name in the disassembly view
mov esp, ebp
pop ebp
ret
END MyProc
In the above example, the MyProc procedure gets the name of the current procedure using the @ProcName symbol and prints it to the debugger using the int 3 instruction, which generates a breakpoint interrupt that launches the debugger. When the debugger is launched, it should display the name of the current procedure in the disassembly view.
This technique can be useful for debugging complex programs with many procedures or functions, as it allows you to quickly identify which procedure or function is being executed at a given point in the program.
Note that the int 3 instruction should be used with caution, as it can cause the program to crash if there is no debugger attached. It is recommended to use this technique only during debugging and to remove the int 3 instruction once the debugging is complete.
In Microsoft Macro Assembler (MASM), @ProcName can be used for various purposes, such as generating code that depends on the name of the current procedure, or for generating error messages or logging information that includes the name of the current procedure. Here are some additional examples of how to use @ProcName in MASM:
; Example 1: Generate code based on the name of the current procedure
MyProc PROC
push ebp
mov ebp, esp
; Generate code based on the name of the current procedure
cmp OFFSET @ProcName, OFFSET MyProc
je MyProcIsCurrent
; ...
MyProcIsCurrent:
; ...
mov esp, ebp
pop ebp
ret
END MyProc
In the above example, the MyProc procedure generates different code depending on whether it is the current procedure or not. This could be useful for implementing conditional logic or for optimizing code based on the name of the current procedure.
; Example 2: Generate an error message that includes the name of the current procedure
MyProc PROC
push ebp
mov ebp, esp
; Generate an error message that includes the name of the current procedure
push OFFSET error_message
push OFFSET @ProcName
call ShowErrorMessage
; ...
MyProcCleanup:
; ...
mov esp, ebp
pop ebp
ret
error_message db "Error in procedure %s",0
END MyProc
In the above example, the MyProc procedure generates an error message that includes the name of the current procedure using the @ProcName symbol and passes it to a function called ShowErrorMessage. This could be useful for debugging or for providing more informative error messages to users.
; Example 3: Log information that includes the name of the current procedure
MyProc PROC
push ebp
mov ebp, esp
; Log information that includes the name of the current procedure
push OFFSET log_message
push OFFSET @ProcName
call LogMessage
; ...
MyProcCleanup:
; ...
mov esp, ebp
pop ebp
ret
log_message db "Procedure %s completed successfully",0
END MyProc
In the above example, the MyProc procedure logs information that includes the name of the current procedure using the @ProcName symbol and passes it to a function called LogMessage. This could be useful for debugging or for providing a record of which procedures were executed during the program's operation.
In addition to using @ProcName for debugging purposes or generating code based on the name of the current procedure, Microsoft Macro Assembler (MASM) provides several other uses for @ProcName. Here are a few examples:
; Example 1: Use @ProcName in a conditional statement to test if a procedure is defined
IFDEF MyProc
; MyProc is defined
ELSE
; MyProc is not defined
ENDIF
; Example 2: Use @ProcName to define a label based on the name of the current procedure
MyProc PROC
jmp @LabelName
; ...
@LabelName:
; ...
ret
END MyProc
; Example 3: Use @ProcName to initialize data based on the name of the current procedure
MyProc PROC
push ebp
mov ebp, esp
; Initialize data based on the name of the current procedure
lea eax, OFFSET @ProcName
mov ebx, OFFSET data_segment
mov [ebx], eax
; ...
mov esp, ebp
pop ebp
ret
data_segment db "Data initialized by procedure: ",0,0,0,0,0,0,0,0,0
END MyProc
In the first example, @ProcName is used in a conditional statement to test if a procedure called MyProc is defined. This could be useful for controlling the behavior of the program based on whether or not a particular procedure is present.
In the second example, @ProcName is used to define a label based on the name of the current procedure. This could be useful for generating code that depends on the name of the current procedure, such as for implementing a jump table.
In the third example, @ProcName is used to initialize data based on the name of the current procedure. This could be useful for generating data structures that depend on the name of the current procedure, such as for creating a call stack or tracking the execution history of the program.
MyProcName db ?
MyProc PROC
push ebp
mov ebp, esp
; Initialize a global variable with the name of the current procedure
lea eax, OFFSET @ProcName
mov ebx, OFFSET MyProcName
mov [ebx], eax
; ...
mov esp, ebp
pop ebp
ret
END MyProc
; Access the global variable outside of a procedure
mov eax, OFFSET MyProcName
; ...
MyProc PROC
; ...
cmp eax, ebx
jne Error
; ...
ret
Error:
lea eax, OFFSET @ProcName
invoke MessageBox, NULL, ADDR eax, NULL, MB_OK
; ...
ret
END MyProc
MyProc PROC
lea eax, OFFSET @ProcName
; ...
.if (@ProcName == MyProc)
; Generate code specific to the MyProc procedure
; ...
.elseif (@ProcName == AnotherProc)
; Generate code specific to the AnotherProc procedure
; ...
.endif
; ...
END MyProc
.DATA
MyDataStruct STRUCT
Name DWORD ?
; ... other fields go here ...
MyDataStruct ENDS
.CODE
MyProc PROC
push ebp
mov ebp, esp
; ... procedure code goes here ...
mov eax, OFFSET MyDataStruct
mov DWORD PTR [eax], OFFSET @ProcName
; ... more data structure code goes here ...
pop ebp
ret
ENDP
MyProc PROC
@ProcName MyProc
MyLabel_@ProcName:
; code that references the label MyLabel_MyProc
; procedure code goes here
MyProc ENDP
MyOtherProc PROC
@ProcName MyOtherProc
MyLabel_@ProcName:
; code that references the label MyLabel_MyOtherProc
; procedure code goes here
MyOtherProc ENDP
Thank you sir mabdelouahab , thank you sir LiaoMi.
Sorry for delay in answer, I was doing some tests before post this message.
The code below work with ml v8
;ml64 /c procname.asm
.data
.code
public WinMainCrt
WinMainCrt::
@ProcName textequ <WinMainCrt>
%echo @ProcName
@ProcName textequ <mineiro>
%echo @ProcName
ret
end
Output:
C:\masm64\bin64>ml64 /c procname.asm
Microsoft (R) Macro Assembler (AMD64) Version 8.00.40310.39
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: procname.asm
WinMainCrt
mineiro
But I'm not being able to make this work in linux with uasm.
;uasm -elf64 procname.uasm
.X64
exit PROTO :VARARG
.data
.code
public main
main proc
%echo @ProcName ;@ProcName
;@ProcName textequ <main> ;Error A2143: Symbol redefinition: @ProcName
;%@ProcName textequ <main> ;Error A2143: Symbol redefinition: @ProcName
;myproc textequ %<@ProcName> ;Error A2167: Missing quotation mark in string
myproc textequ %@ProcName
;%myproc textequ <@ProcName>
%echo myproc ;0
;main textequ %@ProcName
;@ProcName CATSTR <main>
;@ProcName textequ <mineiro>
%echo @ProcName ;
invoke exit,0
main endp
end
Output:
@ProcName
0
@ProcName
procname.uasm: 21 lines, 3 passes, 2649 ms, 0 warnings, 0 errors
It looks like we need to create a macro for the 32-bit version of ml.exe
Quote from: Vortex on March 09, 2023, 03:51:02 AM
It looks like we need to create a macro for the 32-bit version of ml.exe
I have a ProcName$() macro but it requires a custom prolog.
Quote from: LiaoMi on March 07, 2023, 11:08:59 AM
ChatGPT :biggrin: :biggrin: :biggrin:
In Microsoft Macro Assembler (MASM), @ProcName is a predefined symbol
Hello LiaoGPT!
What version you used to test that?
(I hope you don't believe what bot say :biggrin: :biggrin:)
Quote from: mineiro on March 08, 2023, 01:56:00 PM
The code below work with ml v8
That is a simple equate, you are not using any @ProcName directive.
Quote from: HSE on March 09, 2023, 07:01:48 AM
That is a simple equate, you are not using any @ProcName directive.
Yes, so how can I use @ProcName directive? Any example?
I tried Liaomi examples, that return to me some values not expected. When I tried to load @ProcName and main offset to registers just to compare if both are equals, the result was not equal. When I tried to %echo @ProcName, nothing happen. I got a lot of redefinition not allowed. So, ... .
Instead of use @ProcName I can use other variable name to work like in a ml64 example.
The main objective is to create a macro. In our source code we know the procedures name, but in others source code we don't know procedures name.
I forgot to say the real purpose;
I was reading dwarf debug information to elf files, and I need all variable names, (including locals) not just procedure name, macros name, line numbers in source code where they are referencied, ... .
Well, for a while I'm just reading specification, I don't have tried to do a simple handmade source code.
Quote from: mineiro on March 09, 2023, 09:01:30 PM
Quote from: HSE on March 09, 2023, 07:01:48 AM
That is a simple equate, you are not using any @ProcName directive.
Yes, so how can I use @ProcName directive? Any example?
@ProcName seems not to be working. As mentioned above, it can be done with a custom prolog macro. This works fine:
include \Masm32\MasmBasic\Res\JBasic.inc ; ## console demo, builds in 32- or 64-bit mode with UAsm, AsmC and ML ##
.code
DefProc SayHi proc argString:SIZE_P, argDword, argDouble:REAL8
Local v1, v2:REAL8, rc:RECT
PrintLine "We are in ", ProcName$()
ret
SayHi endp
SomeTest proc arg
PrintLine "We are in ", ProcName$()
ret
SomeTest endp
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly
Cls 8
PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
jinvoke SomeTest, 123h
jinvoke SayHi, Chr$("Argument #1 is a string"), 222222222, FP8(33333.33333)
MsgBox 0, ProcName$(), "The name of the current proc:", MB_OK
EndOfCode
Output:
This program was assembled with UAsm64 in 64-bit format.
We are in SomeTest
We are in SayHi
(MsgBox:) The name of the current proc: Main
Works with MASM, UAsm and AsmC :cool:
Quote from: mineiro on March 09, 2023, 09:01:30 PM
Yes, so how can I use @ProcName directive? Any example?
There is no @ProcName symbol in MASM. :biggrin: (Could be in 16 bits era, I don't know)
Johnsa maked something in UASM but I never used.
Quote from: HSE on March 09, 2023, 10:37:03 PMJohnsa maked something in UASM but I never used.
The point is that it apparently doesn't exist.
% echo ProcName
% echo @ProcName
.err
Quote from: johnsa on January 08, 2018, 03:20:23 AM
@ProcName is in, the stack alignment issue is sorted and a bunch of other pending changes. 2.46.6 packages are up :)
But look like function was removed:
/* table of predefined numeric equates */
static const struct eqitem eqtab[] = {
{ "__HJWASM__", _UASM_VERSION_INT_, NULL, NULL },
{ "__UASM__", _UASM_VERSION_INT_, NULL, NULL },
{ "__JWASM__", 212, NULL, NULL },
{ "$", 0, UpdateCurPC, &symPC },
{ "@Line", 0, UpdateLineNumber, &LineCur },
{ "@ProcLine", 0, NULL, NULL },
{ "@Arch", ARCH_SSE, NULL, NULL },
{ "@Platform", 0, NULL, NULL },
{ "@LastReturnType", 0, NULL, NULL },
{ "@ProcName", 0, NULL, NULL },
{ "@WordSize", 0, UpdateWordSize, NULL }, /* must be last (see SymInit()) */
};
Thanks for answers sir HSE and sir jj2007.
That @ProcName is in documentation. So, sounds that continue being a reserved word.
Well, maybe creating a macro to everything will be a pain, source code will look ugly.
Again, thank sirs.
Quote from: mineiro on March 10, 2023, 04:01:56 AMsource code will look ugly.
That's a matter of taste, of course.
Print "We are in ", ProcName$()
@ProcName during assembly time :
include \masm32\include\masm32rt.inc
sum PROTO :DWORD,:DWORD,:DWORD
PROCX MACRO procname:REQ,args:VARARG
procname PROC args
@ProcName TEXTEQU <procname>
ENDM
.data
f1 db '10 + 20 + 30 = %u',13,10,0
.data?
.code
start:
invoke sum,10,20,30
invoke crt_printf,ADDR f1,eax
invoke ExitProcess,0
PROCX sum,x:DWORD,y:DWORD,z:DWORD
% echo @ProcName
mov eax,x
add eax,y
add eax,z
ret
sum ENDP
END start
Thank you sir Vortex.
Quote from: HSE on March 09, 2023, 06:44:10 AM
Quote from: LiaoMi on March 07, 2023, 11:08:59 AM
ChatGPT :biggrin: :biggrin: :biggrin:
In Microsoft Macro Assembler (MASM), @ProcName is a predefined symbol
Hello LiaoGPT!
What version you used to test that?
(I hope you don't believe what bot say :biggrin: :biggrin:)
Hi HSE,
so many creative ideas we found in the wrong words :biggrin:
UASM Reference 2.562.17) Additional Built-In Variables
@ProcLine, indicates the current source code line number relative to the start of the current
procedure.
@ProcName
returns the name of the current procedure.
@Platform <0|1|2|3|4> indicating the currently platform target as WIN32, WIN64, ELF32, ELF64,
OSX MACHO64 to support improved cross platform assembly.
IF @Platform EQ 0
xor eax,eax
echo 'im 32bit windows'
ELSEIF @Platform EQ 1
xor rax,rax
echo 'im 64bit windows'
ELSEIF @Platform EQ 2
xor ebx,ebx
echo 'im 32bit linux'
ELSEIF @Platform EQ 3
xor rbx,rbx
echo 'im 64bit linux'
ELSEIF @Platform EQ 4
xor rbx,rbx
echo 'im 64bit OSX'
ENDIF
@LastReturnType, indicates the last function return type following an invoke call. Values are:
enum returntype {
RT_SIGNED = 0x40,
RT_FLOAT = 0x20,
RT_BYTE = 0,
RT_SBYTE = RT_BYTE | RT_SIGNED,
RT_WORD = 1,
RT_SWORD = RT_WORD | RT_SIGNED,
RT_DWORD = 2,
RT_SDWORD = RT_DWORD | RT_SIGNED,
RT_QWORD = 3,
RT_SQWORD = RT_QWORD | RT_SIGNED,
RT_REAL4 = RT_DWORD | RT_FLOAT,
RT_REAL8 = RT_QWORD | RT_FLOAT,
RT_XMM = 6,
RT_YMM = 7,
RT_ZMM = 8,
RT_PTR = 0xc3,
RT_NONE = 0x100
};
Quote from: LiaoMi on March 12, 2023, 03:24:55 AMUASM Reference 2.56
2.17) Additional Built-In Variables
@ProcLine, indicates the current source code line number relative to the start of the current
procedure.
@ProcName returns the name of the current procedure.
Hi LiaoMi,
Can you give us a short but complete working example of @ProcName usage?
Hi LiaoMi!
Quote from: LiaoMi on March 12, 2023, 03:24:55 AM
UASM Reference 2.56
@ProcName returns the name of the current procedure.
:thumbsup: mineiro mention that.
After that I found that reserved word is in source code, apparently there is an offset storage, but I don't know how that can work :biggrin:
HSE
Quote from: jj2007 on March 12, 2023, 03:35:47 AM
Quote from: LiaoMi on March 12, 2023, 03:24:55 AMUASM Reference 2.56
2.17) Additional Built-In Variables
@ProcLine, indicates the current source code line number relative to the start of the current
procedure.
@ProcName returns the name of the current procedure.
Hi LiaoMi,
Can you give us a short but complete working example of @ProcName usage?
Hi jj2007,
for me, like for others, constants do not work :undecided: ..
http://masm32.com/board/index.php?topic=6821.msg73189#msg73189
johnsa
« Reply #6 on: January 08, 2018, 03:20:23 AM »
Quote
@ProcName is in, the stack alignment issue is sorted and a bunch of other pending changes. 2.46.6 packages are up :)
Hi,
I'm using the latest UASM but am unable to figure out how to use @ProcName.
Is it a known bug?
Is it a const, a variable, or a pointer?
Please provide a short example of how to use it.
Please don't use C/C++ libraries.
Use only WinAPI console calls.
Hi danny,
@ProcName is a macro.
Hi danny,
As Vortex wrote, it's a macro. Or rather, it should be a macro, but it doesn't work:
somealgo proc args
tmp$ CATSTR <Myarg=>, <@ProcName> ; echoes Myarg=@ProcName
% echo tmp$
somealgo proc args
tmp$ CATSTR <Myarg=>, @ProcName ; chokes: Error A2144: Text item required
% echo tmp$
somealgo proc args
tmp$ CATSTR <Myarg=>, %@ProcName ; echoes Myarg=0
% echo tmp$
In short: it is not working as it should :cool:
In case this is really important for you: it can be done with a tailored PROLOG macro. For example, in a MasmBasic program:
MbProbe=0 ; default is 1 (no warning)
WndProc proc hWnd, uMsg, wParam:WPARAM, lParam:LPARAM
Local buffer[4444]:BYTE
This will echo the following: *** warning: with 4444 local bytes in WndProc, you might run into guard page problems. Use StackBuffer instead ***
So technically, it's obviously possible. The question is why do you want this feature? How do you want to use it?
Debugging would be my guess.
Quote from: NoCforMe on January 25, 2024, 08:43:33 PMDebugging would be my guess.
WndProc proc hWnd, uMsg, wParam:WPARAM, lParam:LPARAM
print str$(@Line), 13, 10
Quote from: jj2007 on January 25, 2024, 08:13:26 PMHi danny,
As Vortex wrote, it's a macro. Or rather, it should be a macro, but it doesn't work:
somealgo proc args
tmp$ CATSTR <Myarg=>, <@ProcName> ; echoes Myarg=@ProcName
% echo tmp$
somealgo proc args
tmp$ CATSTR <Myarg=>, @ProcName ; chokes: Error A2144: Text item required
% echo tmp$
somealgo proc args
tmp$ CATSTR <Myarg=>, %@ProcName ; echoes Myarg=0
% echo tmp$
In short: it is not working as it should :cool:
In case this is really important for you: it can be done with a tailored PROLOG macro. For example, in a MasmBasic program:
MbProbe=0 ; default is 1 (no warning)
WndProc proc hWnd, uMsg, wParam:WPARAM, lParam:LPARAM
Local buffer[4444]:BYTE
This will echo the following: *** warning: with 4444 local bytes in WndProc, you might run into guard page problems. Use StackBuffer instead ***
So technically, it's obviously possible. The question is why do you want this feature? How do you want to use it?
Yes, I need it for debugging.
If any procedure in my code fails, I want to log it with the @ProcName to know where to look for bugs.
I don't use MASM Basic, only pure UASM with WinAPI.
So, is it a formal bug and is being worked on to be fixed in the next UASM release?
> I don't use MASM Basic
Your choice :biggrin:
> So, is it a formal bug and is being worked on to be fixed in the next UASM release?
The developers have not been very active recently.
Quote from: jj2007 on January 25, 2024, 09:59:18 PMWndProc proc hWnd, uMsg, wParam:WPARAM, lParam:LPARAM
print str$(@Line), 13, 10
Pure UAsm.
Btw it would be very easy to write a preprocessor that checks for procs and inserts its name:
MyAlgo proc args
Local stuff
ProcDebug "#insert_the_proc_name_here@"
ProcDebug MACRO arg
if usePD ; no code generation for usePD=0
print arg, 13, 10
endif
ENDM
I don't need it because I use MasmBasic, but maybe somebody of the bare metal purists volunteers to code it. Shouldn't take longer than 10 minutes (well, with MasmBasic :biggrin: ).
Quote from: jj2007 on January 26, 2024, 08:36:08 PM> So, is it a formal bug and is being worked on to be fixed in the next UASM release?
The developers have not been very active recently.
Oh no, this is very bad news.
Does it mean development has stopped and it's time to ditch and find some other assembler?
Quote from: dannycoh on January 27, 2024, 08:40:55 AMfind some other assembler
Good luck finding a better one. Most of the other assemblers can't even return something from a macro, as in
.if len(esi)>20
MsgBox 0, str$(eax), "The length of esi:", MB_OK
.endif
Any reason you can't use good old MASM?
Quote from: NoCforMe on January 27, 2024, 11:18:17 AMAny reason you can't use good old MASM?
Serious bugs, for example? (https://developercommunity.visualstudio.com/t/masm-140-if-signed-comparison-bug/231914)
Besides, 64-bit MASM is severely crippled, and all MASM versions are a factor 4-5 slower than UAsm.
But but ... they didn't say anything about 64-bit.
Slower? So who give a shit about that? Really? Are you that impatient?
Quote from: NoCforMe on January 27, 2024, 01:30:48 PMSlower? So who give a shit about that?
You are right, for hello world proggies MASM is fast enough. But for assembling RichMasm (https://masm32.com/board/index.php?board=57.0) I would have to stare 12 seconds at a blank output window until the first error messages start to crawl in. Unacceptable :cool:
Omigod, you have my sincerest sympathy. I mean, how can you stand the inconvenience?
Quote from: NoCforMe on January 28, 2024, 09:27:11 AMhow can you stand the inconvenience?
I don't - I use UAsm, like everybody who works on serious assembly projects ;-)
So what's your ranking of all the *asms available out there? (Asking out of ignorance, as MASM is all I've ever used.)
David,
In practice, I use UAsm64. From time to time I check if my bigger sources still assemble with MASM (6.15 is the minimum, 14.x and higher are often buggy). Most of the time it works, but the RichMasm source, for example, can't cope any more with the limitations of MASM. And really: MASM is very, very slow.
Then there is AsmC: about 25-30% faster than UAsm, so roughly a factor 7-8 faster than MASM. Nice, but Nidud has added so much eerie C stuff to his assembler that I don't trust it.
UAsm is fast, less buggy than MASM, and some people do maintain it. Even if nobody worked on it any more, it's so good that it will be sufficient for all assembly coding in my lifetime.
Re FASM, TASM, NASM: the non-MASM assemblers may be even a tick faster than UAsm, but their macro engines are very poor. No chance to do a print str$(ecx) because there they don't implement EXITM <eax>.
I have never tried PoAsm, and I doubt MasmBasic would be possible with it, but it might be an alternative for some people.
JWasm also is working. It is currently been updated by Japheth now.
Quote from: HSE on January 28, 2024, 11:54:36 AMJWasm also is working
Right. There is a Wikipedia page on various versions (https://en.wikipedia.org/wiki/Open_Watcom_Assembler#HJWasm), such as HASM and HJWASM.
Tasm ( Turbo Assembler ) is offered by Embarcadero as a component of RAD Studio :
https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Turbo_Assembler_Options (https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Turbo_Assembler_Options)
Lazy Assembler (LZASM) by Stepan Polovnikov :
QuoteFree TASM clone with support for new CPU instructions
http://www.phatcode.net/downloads.php?sub=compilers (http://www.phatcode.net/downloads.php?sub=compilers)
Quote from: jj2007 on January 28, 2024, 10:45:06 AMRe FASM, TASM, NASM: the non-MASM assemblers may be even a tick faster than UAsm, but their macro engines are very poor. No chance to do a print str$(ecx) because there they don't implement EXITM <eax>.
Searching
"fasm" "macro" "exitm" I found this 2005 post by Tomasz Grysztar, the creator of FASM:
QuoteNo, inlining the macros is something against the fasm's concept. The macro in fasm is just a special kind of "mnemonic", which gets converted into chain of other lines by preprocessor.
So, in FASM
print str$(eax) (invented by Hutch 20 years ago) is impossible
by design.
Same for TASM (https://stackoverflow.com/questions/38940188/does-tasm-allow-a-macro-to-be-used-as-an-operand).
P.S.: More recently, in May 2023, Roman (https://board.flatassembler.net/topic.php?t=22715) posted this:
QuoteBut we could writing exitm to preprocessor_directives Smile
Time to upgrade preprocessor_directives !
Comrades.
exitm
https://www.asmcommunity.net/forums/topic/12375/
I think FASM would be the perfect solution for our bare metal fans and macro haters :thumbsup:
Hi Jochen,
I don't understand why the author of Fasm is against inline macros. In my opinion, inline macros are great tools supported by Masm and compatible assemblers. Asking ChatGPT :
QuoteWhy inline macros are not recommended?
QuoteThe use of inline macros in programming is not inherently discouraged, but there are considerations and trade-offs that developers need to be aware of. Inline macros can have both advantages and disadvantages, and their appropriateness depends on the context and the specific requirements of the codebase. Here are some reasons why inline macros may not be recommended in certain situations:
Code Readability:
Inline macros can make the code harder to read and understand, especially if they are complex or involve multiple expressions. This can impact code maintainability and the ease with which other developers can comprehend and modify the code.
Debugging and Profiling:
Debugging and profiling tools may have difficulty handling inline macros. When stepping through code or analyzing performance, macros can introduce challenges, as they are expanded at compile-time and may not be as straightforward to inspect during debugging.
Namespace Pollution:
Macros are expanded directly in the code, which can lead to namespace pollution. If macro names clash with variable or function names elsewhere in the codebase, it may result in unexpected behavior.
Type Safety:
Macros do not respect type safety, as they operate purely on text substitution. This lack of type checking can lead to subtle bugs that are challenging to identify and debug.
Maintenance Challenges:
Changes to inline macros can have a cascading effect on the entire codebase. If a macro is modified or removed, it may require updates across multiple locations in the code, making maintenance more error-prone.
Compiler Optimizations:
Modern compilers are sophisticated and often perform inline optimizations automatically. Manually inlining code through macros might not provide significant performance benefits and can even hinder the compiler's ability to optimize the code effectively.
Portability:
Macros might rely on compiler-specific features or assumptions about the underlying platform, limiting code portability across different compilers or architectures.
While there are cases where inline macros can be useful, such as for performance-critical sections of code or when used judiciously for code generation, it's essential for developers to carefully consider the implications and weigh the benefits against the drawbacks. In many situations, alternative approaches, such as inline functions or template functions in languages like C++ or Rust, may offer a more readable and maintainable solution without sacrificing performance.
Quote from: Vortex on January 28, 2024, 09:08:53 PMMacros do not respect type safety, as they operate purely on text substitution. This lack of type checking can lead to subtle bugs that are challenging to identify and debug.
Not true, dear ChatGPT; I have plenty of such sequences in my code:
if destType eq MbReal4
fstp REAL4 ptr [edx]
elseif destType eq MbReal8
fstp REAL8 ptr [edx]
elseif destType eq MbReal10
fstp REAL10 ptr [edx]
endif
C/C++ fans are proud of their type safety, but can they do this?
include \masm32\MasmBasic\MasmBasic.inc
somebyte db 123
someword SWORD 33333
somedword dd 123456789
Init
fldpi
movd xmm1, somedword
movd ecx, xmm1
Print Str$("ecx:\t%i\n", ecx)
Print Str$("xmm1:\t%i\n", xmm1)
Print Str$("ST(0):\t%i\n", ST(0))
Print Str$("byte:\t%i\n", somebyte)
Print Str$("word:\t%i\n", someword)
Print Str$("dword:\t%i\n", somedword)
EndOfCode
QuoteIn my opinion, inline macros are great tools supported by Masm and compatible assemblers.
:thumbsup:
Quote from: jj2007 on January 28, 2024, 10:45:06 AMThen there is AsmC: about 25-30% faster than UAsm, so roughly a factor 7-8 faster than MASM. Nice, but Nidud has added so much eerie C stuff to his assembler that I don't trust it.
Warning: recent versions have a bug (https://masm32.com/board/index.php?msg=126640): they don't like empty lines in include files.
Use UAsm instead (https://www.terraspace.co.uk/uasm.html#p2).
As a long time Poasm user, I can tell that it's nearly compatible with Masm except some differences in the macro engine. Poasm supports all the high-level constructs in 64-bit coding.
It would be interesting to try WinInc with Poasm :
Quote7. About WinInc
WinInc is a set of include files for Masm, UASM, JWasm or PoAsm created by h2incx.
It contains all includes required to build Win32 and Win64 applications or dlls.
https://www.terraspace.co.uk/uasm.html#p7 (https://www.terraspace.co.uk/uasm.html#p7)
Hi Jochen,
With thanks to Nidud, the problem is solved. Checking winextra.inc, there is a missing parenthesis on line 1864 :
IS_VALIDSTATEBITS equ (IS_NORMAL or IS_SPLIT or IS_FULLSCREEN or 80000000h or 40000000h
should be change to :
IS_VALIDSTATEBITS equ (IS_NORMAL or IS_SPLIT or IS_FULLSCREEN or 80000000h or 40000000h)
Reading from Nidud's GitHub account :
QuoteI reported this back in 2021 (now deleted) so I assumed the SDK was updated. As one of the key features in Asmc is to span lines within brackets, a missing end bracket may have this consequence.
There was also a tool added for this purpose to detect sloppy code (as Masm doesn't really care).
https://github.com/nidud/asmc/tree/master/source/tools/brackets
I downloaded the SDK from here. There may be newer ones but when I run the tool on winextra.inc it report the following:
C:\masm32\include\winextra.inc(1684)
The line:
IS_VALIDSTATEBITS equ (IS_NORMAL or IS_SPLIT or IS_FULLSCREEN or 80000000h or 40000000h
So what happens here is that lines are added from this point (1684) until the end of the IFDEF statement before the error is reported.
In the latest version of Asmc the dynamic line size code is optimized to consume larger data arrays, limited only by available memory.
Quote from: Vortex on February 01, 2024, 05:25:21 AMI reported this back in 2021 (now deleted)
Nidud himself deleted his posts, as we all know.
So that tricks with the missing brackets works, thanks Erol. Neither Masm nor UAsm had problems with it, apparently they are more error tolerant.
Anyway, Nidud should work on his error detection and reporting. It's just awful, almost as bad as a C++ compiler.
Guys, returning to the original question.
Please provide a minimal-functioning program that uses @ProcName.
Please no 3rd party libraries.
Only pure x64 assembly and WinAPI.