-2

Can anyone please provide me an 32-bit Hello World Windows program using printf and compilable using Visual C++(2019). I've search A LOT - NOT found such!

Thx.

Darox99
  • 19
  • 5
  • Do none of the answers on [How to write hello world in assembly under Windows?](https://stackoverflow.com/q/1023593) work with Visual Studio? BTW, Visual C++ is a C++ compiler, if you want to write a program for Visual C++, it has to be a C++ program (or C). Assembly programs are assembled with an assembler like MASM (comes with visual studio) or NASM, not compiled. – Peter Cordes Jul 25 '23 at 23:47
  • @PeterCordes Yes friend DO know that Visual C++ is a C++ compiler above all BUT one can add support for assembly code compiling by using the Build Customization option (masm target) if You don't know;-)... – Darox99 Jul 26 '23 at 10:42
  • If you do that, then you're using MASM, not Visual C++ (from within Visual **Studio**, which is what it sounds like you're actually talking about.) – Peter Cordes Jul 26 '23 at 16:20

1 Answers1

2

Try the following :

.686
.model flat, stdcall

INCLUDELIB kernel32.lib
INCLUDELIB msvcrt.lib

includelib msvcrt.lib
includelib legacy_stdio_definitions.lib
includelib libucrt.lib

printf PROTO C : VARARG

.DATA
    HelloWorld DB 'Hello, World!',0
.CODE
_start:
    ; Initialize the CRT (C Runtime)
    call    InitializeCRT
    
    ; Call printf to display the message
    push    offset HelloWorld
    call    printf
    
    ; Clean up and exit the program
    call    ExitProcess
    
InitializeCRT PROC
    ; Set up the CRT and return
    push    ebp
    mov     ebp, esp
    push    ecx
    call    __CppXcptFilter
    call    _initterm
    pop     ecx
    pop     ebp
    ret
InitializeCRT ENDP

ExitProcess PROC
    ; Terminate the program and return
    push    0
    call    ExitProcess
ExitProcess ENDP

END _start
Lorteau Erwan
  • 81
  • 1
  • 1
  • 6
  • Sorry got: 1>Main.asm(32): error A2006: undefined symbol : __CppXcptFilter 1>Main.asm(33): error A2006: undefined symbol : _initterm...? – Darox99 Jul 25 '23 at 22:52
  • @LLorteau Erwan Why did You down-voted my question buddy!? And also can You help me with the errors? – Darox99 Jul 26 '23 at 10:37
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 01 '23 at 11:13