News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to detect if assembler is MASM or UASM

Started by dannycoh, February 14, 2025, 04:07:09 AM

Previous topic - Next topic

dannycoh

I want to detect during assembler time which assembler is being used: MASM or UASM.
I need it to use UASM advanced capabilities but still have a fallback to MASM with reduced capabilities.
I know about the compatibility macros and command line options, but that's not what I want.
Here is what was suggested to me by various AI bots:
; x64 Assembly program to detect MASM or UASM.

.DATA
    msgMasm BYTE 'MASM', 0
    msgUasm BYTE 'UASM', 0
    ChessSolver BYTE 'ChessSolver', 0

.CODE

    ; Entry point
    MyMainProc PROC
        ; Checks for the assembler using defined macros.
        ; Checks for MASM.
        IFDEF MASM
            lea rdx, msgMasm
        ; Checks for UASM.
        ELSE
            lea rdx, msgUasm
        ENDIF
        ; Calls MessageBoxA to display the message.
        push rbp
        mov rbp, rsp
        sub rsp, 4 * 8; Allocates space for 4 arguments.
        and rsp, -16; Aligns the stack to 16 bytes.
        mov rcx, 0 ; hWnd = NULL.
        lea r8, ChessSolver ; lpCaption.
        mov r9, 0
        EXTERNDEF __imp_MessageBoxA:QWORD
        call __imp_MessageBoxA

        ; Exits the process.
        xor rcx, rcx ; Sets return value to 0.
        EXTERNDEF __imp_ExitProcess:QWORD
        call __imp_ExitProcess
    MyMainProc ENDP

END

Biterider

Hi
You can use this snippet to get the assembler and version at compile time.
The result is stored in the ASSEMBLER symbol.

ifdef __UASM__
  ASSEMBLER CatStr <U>, %__UASM__
elseifdef __JWASM__
  ASSEMBLER CatStr <J>, %__JWASM__
elseifdef __ASMC__
  ASSEMBLER CatStr <A>, %__ASMC__
else
  ASSEMBLER CatStr <M>, @Version
endif

Adapt this snippet to the assemblers you use.

Regards, Biterider

Vortex

Hi dannycoh,

In your example, you don't need to align the stack with and rsp,-16 :

EXTERN MessageBoxA:PROC

MessageBox TEXTEQU <MessageBoxA>

EXTERN ExitProcess:PROC

.data

text    db 'Hello world', 0
caption db '64-bit test', 0

.code

main PROC

    push    rbp         ; This push
    mov     rbp,rsp     ; aligns
    sub     rsp,20h     ; the stack.
    xor     r9d,r9d
    lea     r8,caption
    lea     rdx,text
    xor     rcx,rcx
    call    MessageBox

    xor     ecx,ecx
    call    ExitProcess

main ENDP

END