0

I created a small project under Win64 without any _printf from standard C library (on pure WinAPI). Code of the program below:

; ------------------------------------------------------------------------------ EXTERNS

extern GetStdHandle
extern WriteConsoleW

; ------------------------------------------------------------------------------ MACROSES

%define NULL 0
%define STD_OUTPUT_HANDLE -11

; ------------------------------------------------------------------------------ PROGRAM DATA

section .bss noexecute
        hStdOut     resq 1
        chWritten   resd 1

section .data noexecute

        ; wchar string!
        msg dw __utf16__('Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї=Ї'), 10, 0
        msg.sizeof equ ($-msg)

section .rodata noexecute

; ------------------------------------------------------------------------------ PROGRAM CODE

section .text
        global __main

        ; prologue
__main: push      rbp
        mov       rbp, rsp

        ; Get hStdOut to print in console
        mov       rcx, STD_OUTPUT_HANDLE
        call      GetStdHandle
        mov qword [hStdOut], rax

        mov       rcx, rax
        mov       rdx, msg
        mov       r8,  msg.sizeof
        mov       r9,  chWritten
        push      NULL
        call      WriteConsoleW
        
        ; epilogue
        pop       rbp
exit0:  xor       rax, rax
        ret

command:

nasm -fwin64 D:\Desktop\Roberto\asm_docs\files\myprog.asm -o myprog.exe

The error is a blue window that says:

Unable to run executable on your PC. To find a version for your computer, contact to developer of the application

No warnings during the preprocessing, compilation and linking. Tried to run with -fwin32 replacing all r- registers on e- but still no effect... What should i do? Thanks in advance!

  • 1
    You are creating an .obj file, but name it *"myprog.exe"*. You cannot execute an object file. A linker will know how to create an executable image. – IInspectable Feb 06 '23 at 12:41
  • oh, I thought nasm like gcc - compiler and linker 2 in 1 – Brain_driver_not_found Feb 06 '23 at 12:43
  • Related: [How to write hello world in assembly under Windows?](https://stackoverflow.com/q/1023593/1889329) – IInspectable Feb 06 '23 at 12:46
  • ```D:\Desktop\myprog.obj:D:\Desktop:(.text+0x14): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.bss' D:/Translators/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Translators/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o): in function `main': C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:70: undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status``` Tried to link with GCC (VS is so heavy for my PC) – Brain_driver_not_found Feb 06 '23 at 12:47

0 Answers0