1

I'm trying to compile such a simple assembly Hello World program:

    global  _main
    extern  _printf

    section .text
_main:
    push    message
    call    _printf
    add     esp, 4
    ret
message:
    db  'Hello, Worldsssss', 10, 0

I'd like to compile it using just the ml.exe from my MSVC 2019 installation but when i run just:

ml .\HelloWorld_5.asm

I'm getting:

.\HelloWorld_5.asm(8) : error A2008:syntax error : global
.\HelloWorld_5.asm(9) : error A2008:syntax error : in directive
.\HelloWorld_5.asm(11) : error A2008:syntax error : section
.\HelloWorld_5.asm(12) : error A2034:must be in segment block
.\HelloWorld_5.asm(13) : error A2034:must be in segment block
.\HelloWorld_5.asm(14) : error A2034:must be in segment block
.\HelloWorld_5.asm(15) : error A2034:must be in segment block
.\HelloWorld_5.asm(16) : error A2034:must be in segment block
.\HelloWorld_5.asm(17) : error A2034:must be in segment block
.\HelloWorld_5.asm(18) : error A2034:must be in segment block
.\HelloWorld_5.asm(18) : error A2088:END directive required at end of file

Please don't tell me to use the masm.exe, I'd like to use ml

What option to usue with the ml to compile without a problems?

darek_911
  • 81
  • 1
  • 7
  • That's NASM (or FASM) syntax, not MASM, so there are no options that would let any version of MASM assemble it (including `ml`). – Peter Cordes Oct 19 '21 at 09:41
  • @Peter Cordes Ok I understand but can You please provide me the simplest Hello World program with printf function to compile with the MASM (ml.exe)? – darek_911 Oct 19 '21 at 09:56
  • Why would you need `printf` just to print a static string? Use `WriteConsole` or `MessageBox`. – Michael Oct 19 '21 at 10:05
  • @PeterCordes Sorry, but I'm just curious how such simple Hello World using the printf would look like in the MASM version... – darek_911 Oct 19 '21 at 10:11
  • Then go search for that instead. There's a MASM answer on [How to write hello world in assembler under Windows?](https://stackoverflow.com/a/1032422). There are MASM `printf` examples elsewhere on SO, if changing that to pass args to printf instead of MessageBoxA or WriteConsole. – Peter Cordes Oct 19 '21 at 10:20

0 Answers0