een rii
een rii

Reputation: 41

How to display "Hello World" in x86 MASM VS 2022?

I'm new to assembly and I want to learn how to use it without relying to MASM32 SDK or Irvine32 setups and such.
I asked GPT to generate me a code but it kept giving me ones which use .inc files and .lib files from MASM32 SDK.
Is there any way I can display "Hello World" without relying on these setups?

Upvotes: 2

Views: 69

Answers (1)

rcgldr
rcgldr

Reputation: 28808

Create empty console project. Copy asm source file to project directory (if not already there). In project, right click on source file name

Properties

Excluded from build - change to no

Assume file name is x.asm.

Custom build step command line:

ml /c /Fo$(OutDir)\x.obj x.asm

Custom build step outputs:

$(OutDir)\x.obj

includelib legacy_stdio ... is needed for standalone asm program for printf, sscanf, ... . It is not needed if project includes a C source file also (printf will become part of the C object file).

example code.

        .686p                   ;enable instructions
        .xmm                    ;enable instructions
        .model flat,c           ;use C naming convention (stdcall is default)

;       include C libraries
        includelib      msvcrtd
        includelib      oldnames
        includelib      legacy_stdio_definitions.lib    ;for scanf, printf, ...

        .data                   ;initialized data
pfstr   db      "Hello world!",0dh,0ah,0
        .data?                  ;uinitialized data
        .stack  4096            ;stack (optional, linker will default)

        .code                   ;code 
        extrn   printf:near
        public  main

main    proc

        push    offset pfstr
        call    printf
        add     esp,4 

        xor     eax,eax
        ret
main    endp

        end

Upvotes: 2

Related Questions