0
section .data
    message db 'hello world', 0

section .text
    global _start

_start:
    mov eax, 4
    mov ebx, 1
    mov ecx, message
    mov edx, 13
    int 0x80
    mov eax, 1
    xor ebx, ebx
    int 0x80
commands used :

1 - nasm -f win32 codes.asm -o codes.obj

2 - gcc codes.obj -o codes.exe

C:\Users\unknown\Documents\CODING>nasm -f win32 codes.asm -o codes.obj

C:\Users\unknown\Documents\CODING>gcc codes.obj -o codes.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `codes.obj' is incompatible with i386:x86-64 output
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o): in function `main':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:70: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

C:\Users\unknown\Documents\CODING>

i created hello world in assembly but i am struggling to compile it from an object file to exe as shown i am getting errors how to fix it ?

Bishop
  • 55
  • 6
  • 3
    Since you have 32 bit code, use `gcc -m32 -nostdlib`. Note that it is 32 bit code for linux so it will not work natively on windows anyway. You might also be interested in [How to write hello world in assembly under Windows?](https://stackoverflow.com/q/1023593/547981) – Jester Aug 08 '23 at 21:53
  • yaaaaay worked but one more issue i don't see hello world i get the exe file but no hello when i do in cmd codes.exe – Bishop Aug 08 '23 at 21:58
  • 4
    You are trying to use Linux system calls in a Windows program. This won't work. Either assemble as a Linux binary and run in WSL or use Win32 system calls. – fuz Aug 08 '23 at 22:01
  • Once you're on a Linux system, either real Linux or WSL2, use `gcc -m32 -static -nostdlib`. In modern Linux distros, GCC is configured with `-pie` by default, and `-nostdlib` doesn't override that (so you'd still get the dynamic linker's `_start` if you use GDB's `starti`, not your program's). `-static` does. – Peter Cordes Aug 10 '23 at 22:34

0 Answers0