assemblyx86-64masm

Print hello in 64-bit masm


I'm a noob for programing.
I want to write a program to show hello in 64-bit masm.
I use VS code with ml64.exe and gcc.
The following is what I write:

;; file name: hello.asm
printf proto

.data
    messenge dq "hello", 0

.code
main proc
    sub rsp, 40h
    mov rcx, messenge
    call printf
    add rsp, 40h
    ret
main endp

end

And I write a script to assemble, link ,and execute:

@:: file name: run.cmd
@ml64 /c hello.asm
@gcc -o hello.exe hello.obj
@del *.obj
@hello.exe

It goes like this:

C:\code\MASM>run.cmd
Microsoft (R) Macro Assembler (x64) Version 14.25.28614.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: hello.asm

It didn't output hello string.
How could I fix it?


Solution

  • I build this with just ml64 hello.asm (no gcc).

    ;; file name: hello.asm
    printf proto
    includelib msvcrt.lib
    includelib legacy_stdio_definitions.lib
    
    .data
        messenge db "hello", 13, 0
    
    .code
    main proc
        sub rsp, 40h
        mov rcx, offset messenge
        call printf
        add rsp, 40h
        ret
    main endp
    
    end
    

    Basically what Michael said.