News:

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

Main Menu

New member here, need some guidance to start

Started by kcvinu, June 06, 2024, 07:03:03 AM

Previous topic - Next topic

TimoVJL

Quote from: NoCforMe on June 07, 2024, 04:53:49 AMWell, those are predefined names, right, Timo? Meaning you don't have to use them in an assembly-language program.

Timo, you are so C-centric:
QuoteBy default, the starting address is a function name from the C run-time library.

But we don't have to use that library.

If you don't use crt / RTL, you can use those predefined names for own startup code
msvcrt.lib is an import library for dll, like OS msvcrt.dll
masm32 / masm64 msvcrt.lib don't have those predefined function names ?
May the source be with you

NoCforMe

Quote from: TimoVJL on June 07, 2024, 05:51:22 AMIf you don't use crt / RTL, you can use those predefined names for own startup code
Yes, you can.
But why would you want to, unless you're writing code that will interface with C?
Just use whatever name you want.

Quotemasm32 / masm64 msvcrt.lib don't have those predefined function names ?
That I couldn't tell you.

Ah, the wonderful anarchy of assembly language, where we're not (yet) forced into a programming straitjacket ...
Assembly language programming should be fun. That's why I do it.

kcvinu

@sudoku, @NoCforMe and others, Thanks to all.
It worked when I pasted the SDK folder in "C:\" and used absolute path in asm file.

NoCforMe

Congratulations!
Hope you have fun with it.
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: kcvinu on June 07, 2024, 06:00:37 AM@sudoku, @NoCforMe and others, Thanks to all.
It worked when I pasted the SDK folder in "C:\" and used absolute path in asm file.
Great!  :thumbsup:
:biggrin:

TimoVJL

Without masm64 straitjacket  :biggrin: ;hello64m.asm
;ml64 hello64m.asm -link -subsystem:console
includelib msvcrt
extern printf : proc
extern exit : proc

.data
msg   db "Hello world!",0

.code

mainCRTStartup proc
sub rsp, 28h
mov rcx, offset msg
call printf
call exit
mainCRTStartup endp
end
May the source be with you

jj2007

Quote from: NoCforMe on June 07, 2024, 04:13:24 AMdoesn't the MASM64 package come with a \bin folder

Attention, it's \bin64

Some of my early problems with 64-bit code resulted from using stuff from \Masm32 or \Masm32\lib etc, so make sure it's all \Masm64\...

kcvinu

Quote from: TimoVJL on June 07, 2024, 03:23:57 PMWithout masm64 straitjacket  :biggrin: ;hello64m.asm
;ml64 hello64m.asm -link -subsystem:console
includelib msvcrt
extern printf : proc
extern exit : proc

.data
msg   db "Hello world!",0

.code

mainCRTStartup proc
sub rsp, 28h
mov rcx, offset msg
call printf
call exit
mainCRTStartup endp
end
So you don't use "/ENTRY:<proc name>" here, right ?

TimoVJL

no need for /ENTRY: while using predefined names, as link.exe knows them.
May the source be with you


jj2007

Quote from: TimoVJL on June 08, 2024, 01:54:22 AMno need for /ENTRY: while using predefined names, as link.exe knows them.

In the Masm64 SDK, Hutch frequently used entry_point proc

zedd151

Quote from: jj2007 on June 08, 2024, 05:07:10 AM
Quote from: TimoVJL on June 08, 2024, 01:54:22 AMno need for /ENTRY: while using predefined names, as link.exe knows them.
In the Masm64 SDK, Hutch frequently used entry_point proc
Don't forget, hutch also used
/ENTRY:entry_point
for link in the batch file, since link does not know that one.  :icon_idea:
@echo off
set appname=bmpbtns

del %appname%.obj
del %appname%.exe
\masm64\bin64\rc.exe rsrc.rc
\masm64\bin64\ml64.exe /c /nologo %appname%.asm
\masm64\bin64\link.exe /SUBSYSTEM:WINDOWS /ENTRY:entry_point /nologo /LARGEADDRESSAWARE %appname%.obj rsrc.res
dir %appname%.*
pause

:biggrin:

jj2007

Quote from: sudoku on June 08, 2024, 05:18:02 AMDon't forget, hutch also used
Code Select Expand
/ENTRY:entry_point
for link in the batch file, since link does not know that one.  :icon_idea:

Yes, that's the whole point.

EP_strings db "Init", 0, "CRTStartup", 0, "WinMain", 0, "start", 0, "entry_point", 0, "entry", 0, 0
From the RichMasm source.

zedd151

@jj2007:
Since you quoted TimoVJL, it could be misinterpreted that link also knows "entry_point". That was my point.
:biggrin:

Mikl__

Found it in Jeffrey Richter's book "Windows. Creating effective Win32 applications taking into account the specifics of 64-bit versions of Windows" the following lines
Quote...not many people know that in a project you don't have to specify the /SUBSYSTEM linker switch at all... the linker itself will determine the subsystem of your application if it checks which of the four functions (WinMain, wWinMain, main or wmain) is present in your code, and Based on this, it will select a subsystem...
|                    Application type                           |entry function|  linker key      |
+-------------------+-------------------------------------------+--------------+------------------+
|GUI application    |working with ANSI characters and strings   |WinMain       |/SUBSYSTEM:WINDOWS|
|GUI application    |working with Unicode characters and strings|wWinMain      |/SUBSYSTEM:WINDOWS|
|console application|working with ANSI characters and strings   |main          |/SUBSYSTEM:CONSOLE|
|console application|working with Unicode characters and strings|wmain         |/SUBSYSTEM:CONSOLE|
bat-file that can build both CONSOLE and GUI applications
cls
set masm64_path=C:\masm64\ <-- name of your masm-dir
set filename= . . . <-- name of your asm-file
if exist errors.txt del errors.txt
if exist %filename%.exe del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm >> errors.txt
if errorlevel 1 exit
:CONSOLE
%masm64_path%bin\link /LIBPATH:"%masm64_path%Lib" /entry:main  >> errors.txt
if errorlevel 1120 goto GUI
if errorlevel 1 exit
goto exit0
:GUI
%masm64_path%bin\link /LIBPATH:"%masm64_path%Lib" /entry:WinMain >> errors.txt
if errorlevel 1 exit
:exit0
if exist errors.txt del errors.txt <-- removing "software junk"
if exist %filename%.obj del %filename%.obj
The point is that at /entry:main (if there is such an input label) - a console application will be created, if there is no such label (errorlevel returns with code 1120) - this means the input label is WinMain and a GUI application will be created