Author Topic: Quick play with UASM  (Read 2385 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6769
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Quick play with UASM
« on: July 21, 2019, 07:04:08 PM »
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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Quick play with UASM
« Reply #1 on: July 21, 2019, 08:05:02 PM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 6769
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Quick play with UASM
« Reply #2 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Quick play with UASM
« Reply #3 on: July 21, 2019, 08:59:02 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--

  • Administrator
  • Member
  • ******
  • Posts: 6769
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Quick play with UASM
« Reply #4 on: July 21, 2019, 10:24:33 PM »
 :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 at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6769
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Quick play with UASM
« Reply #5 on: July 22, 2019, 01:40:44 AM »
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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Quick play with UASM
« Reply #6 on: July 22, 2019, 03:07:35 AM »
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

  • Regular Member
  • *
  • Posts: 46
Re: Quick play with UASM
« Reply #7 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.
Sorry for the bad English

felipe

  • Member
  • *****
  • Posts: 1249
  • Eagles are just great!
Re: Quick play with UASM
« Reply #8 on: July 22, 2019, 03:59:30 AM »
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...
Felipe.

AW

  • Member
  • *****
  • Posts: 2442
  • Let's Make ASM Great Again!
Re: Quick play with UASM
« Reply #9 on: July 22, 2019, 04:03:47 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 6769
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Quick play with UASM
« Reply #10 on: July 22, 2019, 04:27:09 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Quick play with UASM
« Reply #11 on: July 22, 2019, 04:34:37 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--

  • Administrator
  • Member
  • ******
  • Posts: 6769
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Quick play with UASM
« Reply #12 on: July 22, 2019, 04:48:50 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Quick play with UASM
« Reply #13 on: July 22, 2019, 04:53:49 AM »
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

  • Member
  • *****
  • Posts: 1249
  • Eagles are just great!
Re: Quick play with UASM
« Reply #14 on: July 22, 2019, 05:03:12 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?
Felipe.