News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Quick play with UASM

Started by hutch--, July 21, 2019, 07:04:08 PM

Previous topic - Next topic

hutch--

Documentation is lousy by UASM seems to work OK. I could not find the reference for => OPTION PROC:NONE. I could not find a reason why it had to have "main" as its entry point. I just used an equate to get the name I wanted.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    option casemap:none

    includelib \masm32\lib64\kernel32.lib
    includelib \masm32\lib64\user32.lib

    MessageBoxA PROTO :QWORD,:QWORD,:QWORD,:QWORD
    MessageBox equ <MessageBoxA>
    ExitProcess PROTO :QWORD

    MB_OK equ <0>
    entry_point equ <main>

    .data
      caption db " The UASM Assembler", 0
      text    db "Bare Bones MessageBox", 0

    .code

    OPTION PROC:NONE

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    add rsp, 8

    invoke MessageBox,0,ADDR text,ADDR caption,MB_OK
    invoke ExitProcess,0

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

The build batch file.

@echo off

set appname=UASM1

del %appname%.obj
del %appname%.exe

\uasm\uasm64 -win64 %appname%.asm

\masm32\bin64\polink.exe /SUBSYSTEM:WINDOWS /entry:main /LARGEADDRESSAWARE %appname%.obj

dir %appname%.exe

pause

TimoVJL

as link.exe and polink.exe understand those basic entry points mainCRTStartup, wmainCRTStartup, WinMainCRTStartup, wWinMainCRTStartup, why not use one of them ?
so only -subsystem is necessary for link.exe, but M$ must be a reason for that.
May the source be with you

hutch--

If you don't need them, why use them. Assemblers do not need to assume C technology.

TimoVJL

Quote from: hutch-- on July 21, 2019, 08:49:28 PM
If you don't need them, why use them. Assemblers do not need to assume C technology.
You missed something, those don't depend of C
Even i know something about compilers, like C, it's a linker that i was talking about.
As i said, it's a M$ linker issue, not a C issue.

Your site, your rules, but try to be in truth :skrewy:
May the source be with you

hutch--

 :biggrin:

mainCRTStartup, wmainCRTStartup, WinMainCRTStartup, wWinMainCRTStartup is not assembler technology, it is C technology. Assembler modules only need an entry point which you specify on the linker command line. I am not sure what you are trying to prove here.

hutch--

Here is a slightly tweaked version.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    option casemap:none

    includelib \masm32\lib64\kernel32.lib
    includelib \masm32\lib64\user32.lib

    MessageBoxA PROTO :QWORD,:QWORD,:QWORD,:QWORD
    MessageBox equ <MessageBoxA>
    ExitProcess PROTO :QWORD

    MB_OK equ <0>
    entry_point equ <main>
    NULL equ <0>

    t MACRO quoted
      LOCAL text
      LOCAL ptxt
      .data
        text db quoted,0
        ptxt dq text
      .code
      EXITM <ptxt>
    ENDM

    OPTION PROC:NONE

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

entry_point proc

    sub rsp, 8

    invoke MessageBox,NULL,t("Bare Bones MessageBox"),t(" The UASM Assembler"),MB_OK
    invoke ExitProcess,0

entry_point endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

TimoVJL

As i said, a linker issue, predefined names in linker, not a C issue.
https://docs.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol
May the source be with you

morgot

TimoVJL but why Masm32 don't need it? In masm I can write
.code
start:
...
nop
..
end start

Without any proc.
Sorry for the bad English

felipe

From the link above (provided by timo):
Quote
It is recommended that you let the linker set the entry point so that the C run-time library is initialized correctly, and C++ constructors for static objects are executed.

By default, the starting address is a function name from the C run-time library. The linker selects it according to the attributes of the program, as shown in the following table.
Function name    Default for
mainCRTStartup (or wmainCRTStartup)    An application that uses /SUBSYSTEM:CONSOLE; calls main (or wmain)
WinMainCRTStartup (or wWinMainCRTStartup)    An application that uses /SUBSYSTEM:WINDOWS; calls WinMain (or wWinMain), which must be defined to use __stdcall
_DllMainCRTStartup    A DLL; calls DllMain if it exists, which must be defined to use __stdcall

Looks a lot like a c related issue...

aw27

Polink and Link.exe will accept any entry point  set in UASM with a correct syntax name, the same as in MASM. This includes the "entry_point" name. It will also accept labels as entry points but is not recommended for 64-bit when you want the OPTION for automatic stack alignment to work.

hutch--

Timo,

I am not sure what you are getting at, what have you missed with *****CRT***** = C runtime. Now I have no doubt that you can start an app with a C runtime procedure but the obvious is that an assembler does not need it.

I confess it seems like a waste of time posting a simple experiment with UASM as it ends up in yet another nonsense argument over very old technology from the Petzold era that aped a technique where a WinMain had 4 arguments which followed from the format of a 16 bit Win3.0 era code design and YES it was in C.

I was looking for some of the UASM folks who knew more of the reference material that I have yet to find. All I have so far is some old stuff from the data that Japheth wrote.

TimoVJL

Quote from: morgot on July 22, 2019, 03:56:17 AM
TimoVJL but why Masm32 don't need it? In masm I can write
.code
start:
...
nop
..
end start

Without any proc.
just look inside of .obj and find out why M$ link find that entry point, no magic.
May the source be with you

hutch--

I knew I had stuff this old somewhere. This is how you ape a 16 bit Windows WinMain in early 32 bit.

start:
        invoke GetModuleHandle, NULL
        mov hInstance, eax

        invoke GetCommandLine
        mov CommandLine, eax

        invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
        invoke ExitProcess,eax

; #########################################################################

WinMain proc hInst     :DWORD,
             hPrevInst :DWORD,
             CmdLine   :DWORD,
             CmdShow   :DWORD

Most of it is redundant in Win32 and certainly in Win64. You do not need hPrevInst and CmdShow. It was just a pseudo compatibility with 16 bit Windows while updating to Win32.

TimoVJL

Linker don't care about language, only symbol names,just  learn object file basics with wrj's PEView.exe.
It seems that i just waste my time here to teach some professionals to update their knowledge of some basic things.
I haven't been a professional programmer in my life, only a hobbyist, but some of my programs are still important part of production line in one factory.
My role was a IT support and a system expert person at that time.
I even created a C code to read Vertex Systems databases.


May the source be with you

felipe

Quote from: TimoVJL on July 22, 2019, 04:53:49 AM
It seems that i just waste my time here to teach some professionals to update their knowledge of some basic things.
I haven't been a professional programmer in my life, only a hobbyist, but some of my programs are still important part of production line in one factory.
My role was a IT support and a system expert person at that time.
I even created a C code to read Vertex Systems databases.

:biggrin: And you have never learned assembly language?