The MASM Forum

General => The Campus => Topic started by: kcvinu on June 06, 2024, 07:03:03 AM

Title: New member here, need some guidance to start
Post by: kcvinu on June 06, 2024, 07:03:03 AM
Hi all,
I am a hobby programmer from India. Probably somebody from this forum might know me since I am a member of FreeBasic forum.
Now, I would like to wet my toe in MASM64 with my Windows 11. I have Visual Studio 2022 and I ran a test asm code successfully. But I would like to know how to run my asm file without the help of VS2022. Now the linker is complaining that it can't find the 'msvcrt.lib'
What I did ?
1. Write code in an .asm file and save it.
2. Run ml64.exe with this asm file and created .obj file.
3. Rum link.exe with this code - "link /SUBSYSTEM:CONSOLE /OUT:t1.exe t1.obj msvcrt.lib"

 
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 06, 2024, 09:01:52 AM
Quote from: kcvinu on June 06, 2024, 07:03:03 AM3. Rum link.exe with this code - "link /SUBSYSTEM:CONSOLE /OUT:t1.exe t1.obj msvcrt.lib"
Dumb question, I know, but do you actually have msvcrt.lib?
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 06, 2024, 10:14:02 AM
kcvinu, could you post your source code? There may be another way to do what you are trying to achieve.

I have asked that this thread be moved to the Campus...
Title: Re: New member here, need some guidance to start
Post by: StrykerX on June 06, 2024, 10:25:20 AM
Moved to The Campus.  :mrgreen:
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 06, 2024, 11:26:43 AM
link needs library path for libraries.
with /LIBPATH:dir is possible to point folder for library
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 06, 2024, 11:38:27 PM
Quote from: NoCforMe on June 06, 2024, 09:01:52 AM
Quote from: kcvinu on June 06, 2024, 07:03:03 AM3. Rum link.exe with this code - "link /SUBSYSTEM:CONSOLE /OUT:t1.exe t1.obj msvcrt.lib"
Dumb question, I know, but do you actually have msvcrt.lib?

Yes, I have that lib.
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 06, 2024, 11:39:34 PM
Quote from: sudoku on June 06, 2024, 10:14:02 AMkcvinu, could you post your source code? There may be another way to do what you are trying to achieve.

I have asked that this thread be moved to the Campus...
Sure. This is my code.
.code
main proc
    mov rax, 125
    ret
main endp

end
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 06, 2024, 11:55:26 PM
Quote from: kcvinu on June 06, 2024, 11:39:34 PMSure. This is my code.
.code
main proc
    mov rax, 125
    ret
main endp

end
if that is your entire code, you don't need msvcrt.lib for that.

Quote from: kcvinu on June 06, 2024, 11:38:27 PMYes, I have that lib.
what is the path to it, where is it located?
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 02:03:56 AM
Quote from: sudoku on June 06, 2024, 11:55:26 PM
Quote from: kcvinu on June 06, 2024, 11:39:34 PMSure. This is my code.
.code
main proc
    mov rax, 125
    ret
main endp

end
if that is your entire code, you don't need msvcrt.lib for that.
What he wrote.

Since you definitely do not need that library to assemble and link that code, just remove the reference to msvcrt.lib for now. Worry about that later ...

One thing, though: I believe you need to set the program's entry point. (You definitely need to do this for 32-bit code, and I assume the same for 64-bit code.)
.code
main proc
start:
    mov rax, 125
    ret
main endp

end start
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 07, 2024, 02:18:53 AM
what is the path to it, where is it located?
[/quote]

That file resides more than one place
One location is this - C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\lib\x64\msvcrt.lib
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 07, 2024, 02:21:30 AM
Quote from: NoCforMe on June 07, 2024, 02:03:56 AM
Quote from: sudoku on June 06, 2024, 11:55:26 PM
Quote from: kcvinu on June 06, 2024, 11:39:34 PMSure. This is my code.
.code
main proc
    mov rax, 125
    ret
main endp

end
if that is your entire code, you don't need msvcrt.lib for that.
What he wrote.

Since you definitely do not need that library to assemble and link that code, just remove the reference to msvcrt.lib for now. Worry about that later ...

One thing, though: I believe you need to set the program's entry point. (You definitely need to do this for 32-bit code, and I assume the same for 64-bit code.)
.code
main proc
start:
    mov rax, 125
    ret
main endp

end start

Thanks for the reply. Let me try that.
Title: Re: New member here, need some guidance to start
Post by: sinsi on June 07, 2024, 02:36:32 AM
Quote from: NoCforMe on June 07, 2024, 02:03:56 AM
Quote from: sudoku on June 06, 2024, 11:55:26 PM
Quote from: kcvinu on June 06, 2024, 11:39:34 PMSure. This is my code.
.code
main proc
    mov rax, 125
    ret
main endp

end
if that is your entire code, you don't need msvcrt.lib for that.
What he wrote.

Since you definitely do not need that library to assemble and link that code, just remove the reference to msvcrt.lib for now. Worry about that later ...

One thing, though: I believe you need to set the program's entry point. (You definitely need to do this for 32-bit code, and I assume the same for 64-bit code.)
.code
main proc
start:
    mov rax, 125
    ret
main endp

end start

In 64-bit code, using ML64, end start will actually throw an error.
Microsoft (R) Macro Assembler (x64) Version 14.40.33811.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: C:\masm32\crap.asm
C:\masm32\crap.asm(5) : error A2008:syntax error : start
C:\masm32\crap.asm(5) : error A2088:END directive required at end of file
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 02:41:41 AM
Quote from: sinsi on June 07, 2024, 02:36:32 AMIn 64-bit code, using ML64, end start will actually throw an error.
Quite right. Plus you need to tell link.exe the entry point that you are using example
  /ENTRY:<label_name> if different than the "C" default entry point (WinMainCRTStartup or whatever it is, I cannot remember offhand), else link will give an error message indicating the entry point cannot be found.

In your link switches for your example code posted above, add "/ENTRY:main"...
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 02:59:05 AM
Quote from: sinsi on June 07, 2024, 02:36:32 AMIn 64-bit code, using ML64, end start will actually throw an error.
Microsoft (R) Macro Assembler (x64) Version 14.40.33811.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: C:\masm32\crap.asm
C:\masm32\crap.asm(5) : error A2008:syntax error : start
C:\masm32\crap.asm(5) : error A2088:END directive required at end of file
But why the error for having start: there? Isn't it legal to have a label in your code? or is there something special about "start"?

(I do now understand that the setting-the-entry-point thing is different from 32-bit code.)
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 07, 2024, 02:59:39 AM
Quote from: sudoku on June 07, 2024, 02:41:41 AMIn your link switches for your example code posted above, add "/ENTRY:main"...


Thanks. Let me try.
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 07, 2024, 03:01:49 AM
@sudoku,
Thank you, it worked.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 03:03:02 AM
I have made you a small example based on your code.

include \masm64\include64\masm64rt.inc

.code
main proc
    mov rax, 125
    invoke MessageBox, 0, str$(rax), 0, 0
    invoke ExitProcess, 0
    ret
main endp

end
Run the program, a MessageBox will pop up with a string of the value in rax. Then the program will exit gracefully using ExitProcess.

and a batch file to assemble and link it
\masm64\bin64\ml64.exe /c test.asm

\masm64\bin64\link.exe /SUBSYSTEM:WINDOWS /ENTRY:main test.obj

pause

Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 07, 2024, 03:20:57 AM
Quote from: sudoku on June 07, 2024, 03:03:02 AMI assume that you have the masm64 SDK installed??


Unfortunately, that's the important thing I missed. Where can I download masm64 SDK ?

EDIT: Ah, I got from this site. Which is the best place to paste the "masm64" folder ? Do I need to set in PATH ?
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 03:40:38 AM
The standard thing to do is to put it (the whole MASM64 package) as the first subdirectory of whatever drive you want to use, like E:\masm64\ .... That way you can share code here with other members and have it work on their setups without having to modify anything. (Don't include the drive letter in your batch file! Your stuff should be drive-agnostic.)

I set my PATH to the folder with the executables (ML.exe, link.exe, etc.), but other folks here frown on that for some reason. So if you don't set the path you'll need to explicitly put the path in either your command line or your batch file. (Please tell us you're going to use a batch file, rather than having to type in all that stuff each and every time!)

BTW, question for regulars here: is this stuff (basic MASMxx setup) explained anywhere here? clearly? in a place that's not hidden, like a "readme" file stuck somewhere where nobody's going to look at it?

Title: Re: New member here, need some guidance to start
Post by: sinsi on June 07, 2024, 03:44:44 AM
Quote from: NoCforMe on June 07, 2024, 02:59:05 AM
Quote from: sinsi on June 07, 2024, 02:36:32 AMIn 64-bit code, using ML64, end start will actually throw an error.
Microsoft (R) Macro Assembler (x64) Version 14.40.33811.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: C:\masm32\crap.asm
C:\masm32\crap.asm(5) : error A2008:syntax error : start
C:\masm32\crap.asm(5) : error A2088:END directive required at end of file
But why the error for having start: there? Isn't it legal to have a label in your code? or is there something special about "start"?

(I do now understand that the setting-the-entry-point thing is different from 32-bit code.)
You notice the two errors are on line 5, which is end start.
What the error is saying is that it parsed the end ok but there's this start thing that shouldn't be there, since end doesn't take any parameters.
That's why the second error complains about no end, since the whole line was invalid.
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 03:45:54 AM
Ah, so. Thanks.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 03:53:55 AM
Quote from: kcvinu on June 07, 2024, 03:20:57 AM
Quote from: sudoku on June 07, 2024, 03:03:02 AMI assume that you have the masm64 SDK installed??


Unfortunately, that's the important thing I missed. Where can I download masm64 SDK ?

EDIT: Ah, I got from this site. Which is the best place to paste the "masm64" folder ? Do I need to set in PATH ?
No just unzip it to the root of the drive where you will keep your projects.
You will then either have to copy ml64 and link (plus their associated dependencies) to \masm64\bin64 or change the paths in the batch file for ml64 and link.

I don't know the paths in Visual Studio otherwise I would have adjusted the batch file accordingly. You should not have to set any environment variables (I.e. PATH)

Other members here that work with both visual studio and Masm64 may be able to help you better than I could in some instances.

Let us know how it is going with your Masm64 SDK install.
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 04:13:24 AM
Quote from: sudoku on June 07, 2024, 03:53:55 AMYou will then either have to copy ml64 and link (plus their associated dependencies) to \masm64\bin64 or change the paths in the batch file for ml64 and link.
Wait a sec: doesn't the MASM64 package come with a \bin folder with all the needed executables in it, like MASM32 does?
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 04:15:44 AM
Unfortunately there are bits and pieces in various threads, and no "One Stop" instructions for setting up Masm64 SDK. 
NoCforMe, no unfortunately hutch did not have permission to do that, due to licensing restrictions.
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 04:17:19 AM
Quote from: sudoku on June 07, 2024, 04:15:44 AMUnfortunately there are bits and pieces in various threads, and no "One Stop" instructions for setting up Masm64 SDK.
Well, there oughta be, dontcha think?
Unless you want to keep fielding questions like this forever.

BTW, I'd be more than happy to edit such instructions for clarity. However, I'm not knowledgeable enough about MASM64 to actually write them.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 04:32:30 AM
Quote from: NoCforMe on June 07, 2024, 04:17:19 AMHowever, I'm not knowledgeable enough about MASM64 to actually write them.
Me neither, but this should be a good starting point...

https://masm32.com/board/index.php?topic=12016.0

If anyone would like to add to or change any of that let it be known please.
NoCforMe, good idea.  :icon_idea:

Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 04:47:24 AM
Rather than continue to clutter this topic (sorry, OP!), I'll start a new discussion in the MASM64 sub-forum.

Done. (sudoku started it) Here it is (https://masm32.com/board/index.php?topic=12016.0).
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 07, 2024, 04:49:37 AM
Just to remind:
/ENTRY (Entry-Point Symbol) (https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=msvc-170)

QuoteFunction 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
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 04:53:49 AM
Well, 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.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 05:13:02 AM
Quote from: NoCforMe on June 07, 2024, 04:53:49 AMBut we don't have to use that library.
Yes, and I suspect that is what led the OP to think that msvcrt.lib was needed.
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 07, 2024, 05:51:22 AM
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 ?
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 05:53:58 AM
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 ...
Title: Re: New member here, need some guidance to start
Post by: 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.
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 07, 2024, 07:14:49 AM
Congratulations!
Hope you have fun with it.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 07, 2024, 11:47:51 AM
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:
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 07, 2024, 03:23:57 PM
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
Title: Re: New member here, need some guidance to start
Post by: jj2007 on June 07, 2024, 04:51:45 PM
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\...
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 08, 2024, 01:12:00 AM
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 ?
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 08, 2024, 01:54:22 AM
no need for /ENTRY: while using predefined names, as link.exe knows them.
Title: Re: New member here, need some guidance to start
Post by: kcvinu on June 08, 2024, 02:08:42 AM
Okay.
Title: Re: New member here, need some guidance to start
Post by: 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
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 08, 2024, 05:18:02 AM
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

Title: Re: New member here, need some guidance to start
Post by: jj2007 on June 08, 2024, 05:44:38 AM
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.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 08, 2024, 06:12:40 AM
@jj2007:
Since you quoted TimoVJL, it could be misinterpreted that link also knows "entry_point". That was my point.
Title: Re: New member here, need some guidance to start
Post by: Mikl__ on June 08, 2024, 08:28:26 AM
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
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 08, 2024, 08:40:21 AM
Very interesting.
Just to be clear, this is only for 64-bit apps, correct?
Title: Re: New member here, need some guidance to start
Post by: Mikl__ on June 08, 2024, 08:59:10 AM
Hi NoCforMe!
Yes, I haven't worked with 32-bit applications for about 10 years. Although Jeffrey Richter may have written this for 32- and 64-bit applications as well
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 08, 2024, 09:36:21 AM
; ml64.exe hello64m.asm
includelib msvcrt
extern printf : proc
extern exit : proc

.data
msg  db "Hello world!",0

.code
mainCRTStartup proc ; for link.exe if main defined
  sub rsp, 28h
  call main
mainCRTStartup endp

main proc
    sub rsp, 28h
    mov rcx, offset msg
    call printf
    call exit
main endp
end
link.exe predefined names
Generated by HexEdit
C:\code\msvc6\bin\link.exe

000082c0  5f 77 6d 61 69 6e 00 00 5f 6d 61 69 6e 00 00 00  _wmain.._main...
000082d0  77 6d 61 69 6e 00 00 00 6d 61 69 6e 00 00 00 00  wmain...main....
000082e0  5f 77 57 69 6e 4d 61 69 6e 00 00 00 5f 57 69 6e  _wWinMain..._Win
000082f0  4d 61 69 6e 00 00 00 00 77 57 69 6e 4d 61 69 6e  Main....wWinMain
00008300  00 00 00 00 57 69 6e 4d 61 69 6e 00 5f 77 57 69  ....WinMain._wWi
00008310  6e 4d 61 69 6e 40 31 36 00 00 00 00 5f 57 69 6e  nMain@16...._Win
00008320  4d 61 69 6e 40 31 36 00 2e 76 78 64 00 00 00 00  Main@16..vxd....

Generated by HexEdit
link.exe

00008440  5f 44 6c 6c 4d 61 69 6e 43 52 54 53 74 61 72 74  _DllMainCRTStart
00008450  75 70 40 31 32 00 00 00 5f 44 6c 6c 4d 61 69 6e  up@12..._DllMain
00008460  43 52 54 53 74 61 72 74 75 70 00 00 5f 5f 50 6f  CRTStartup..__Po
00008470  73 69 78 50 72 6f 63 65 73 73 53 74 61 72 74 75  sixProcessStartu
00008480  70 00 00 00 77 6d 61 69 6e 43 52 54 53 74 61 72  p...wmainCRTStar
00008490  74 75 70 00 6d 61 69 6e 43 52 54 53 74 61 72 74  tup.mainCRTStart
000084a0  75 70 00 00 77 57 69 6e 4d 61 69 6e 43 52 54 53  up..wWinMainCRTS
000084b0  74 61 72 74 75 70 00 00 57 69 6e 4d 61 69 6e 43  tartup..WinMainC
000084c0  52 54 53 74 61 72 74 75 70 00 00 00 4e 74 50 72  RTStartup...NtPr
000084d0  6f 63 65 73 73 53 74 61 72 74 75 70 00 00 00 00  ocessStartup....
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 08, 2024, 09:46:54 AM
Why not simplify things and just do this?

Quote from: TimoVJL on June 08, 2024, 09:36:21 AM; ml64.exe hello64m.asm
includelib msvcrt
extern printf : proc
extern exit : proc

.data
msg  db "Hello world!",0

.code
main proc ; for link.exe so "main()" is defined
  sub rsp, 28h
  mov rcx, offset msg
  call printf
  call exit
main endp

end

In other words, what reason is there to have a proc-within-a-proc? Just put everything in main().

(Not a 64-bit programmer here)
Title: Re: New member here, need some guidance to start
Post by: TimoVJL on June 08, 2024, 09:54:25 AM
Because of this:
LINK : error LNK2001: unresolved external symbol mainCRTStartupmainCRTStartup is default entry
main is default for console mode application
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 08, 2024, 09:57:56 AM
So the linker forces you to have both mainCRTStartup() and main()?

How weird.
Title: Re: New member here, need some guidance to start
Post by: jj2007 on June 08, 2024, 03:08:46 PM
Quote from: Mikl__ on June 08, 2024, 08:28:26 AMin 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

That's good to know, Mikl. However, in my projects I need Subsystem:console for debugging (error messages, deb (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1019)), and Windows for the release version. Therefore I believe in telling the linker explicitly where to enter.

Btw fall thru is another legal option, too:
main proc
main endp
start proc
start endp
mainCRTStartup proc
mainCRTStartup endp
WinMain proc
WinMain endp
entry_point proc
entry_point endp
... meaning "dear linker, pick whatever you like most but please don't generate any extra code"
Title: Re: New member here, need some guidance to start
Post by: Mikl__ on June 08, 2024, 06:30:13 PM
Ciao Jochen! Come stai? Sono felice che ti sia piaciuto il mio post. La conoscenza non è mai superflua... (https://wasm.in/styles/smiles_s/friends.gif)
Title: Re: New member here, need some guidance to start
Post by: jj2007 on June 08, 2024, 07:49:23 PM
Ciao Mikl! Я в порядке, спасибо! Всегда приятно, когда наш величайший 64-битный эксперт оказывает нам честь.
Title: Re: New member here, need some guidance to start
Post by: tenkey on June 08, 2024, 09:34:48 PM
Quote from: NoCforMe on June 08, 2024, 09:57:56 AMSo the linker forces you to have both mainCRTStartup() and main()?
The "problem" with main() is that by default the linker links in the C++ startup code (mainCRTStartup). One way to prevent that: specify /ENTRY:main to the linker.
Title: Re: New member here, need some guidance to start
Post by: zedd151 on June 08, 2024, 11:23:45 PM
@tenkey:  :thumbsup:
Exactly.

This is 64 bit assembly under discussion after all, not C.  :biggrin:
We (assembly language programmers) are not limited to "C language" pre-defined entry points, so must tell the linker where our entry point is located.
Title: Re: New member here, need some guidance to start
Post by: NoCforMe on June 28, 2024, 10:00:59 AM
Quote from: Mikl__ on June 08, 2024, 08:28:26 AMFound 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|

@Mikl_, this is important and useful enough information that it should be made "sticky" somewhere for easy reference.