NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Alvin_Sanchez12 on September 18, 2020, 01:28:46 PM
-
Hi there, my name is alvin and im 15 years old and i was beginer in assembly and i want to ask a quesion how i fix test.exe is not valid win32 application currently im using windows
-
If you show us your code and how you are creating your exe file someone may be able to help you. Without any more info it's impossible to know what the problem is.
-
this my test.asm code
section .data
msg db "hello worlds",0
msg_len equ $-msg
section .text
global _start
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_len
syscall
mov eax, 1
mov ebx, 1
syscall
i trying run with nasm
nasm -f win64 -o test.obj test.asm
and link with ld
ld -m i386pe -s -o test.exe test.obj
did i get wrong?
-
currently im using windows 7
-
I'm not a Windows coder (yet), but it looks like you are writing 32-bit code, and telling nasm to generate a 64-bit object file, which you then try linking as a 32-bit executable. I don't know if that is the problem though, hopefully someone with Windows and 64-bit experience will be along soon.
-
Looks like you are compiling Linux code on Windows.
And not sure if you invoke the GNU linker (ld) correctly.
-
so what is the code for windows looks like?
-
so what is the code for windows looks like?
You need to use Win32 API and MinGW (or Cygwin):
bits 64
default rel
STD_OUTPUT_HANDLE equ -11
section .rodata
msg:
db `Hello, world.\n`
msg_size equ $ - msg
section .text
extern __imp_GetStdHandle
extern __imp_WriteConsoleA
extern __imp_ExitProcess
global _start
_start:
mov ecx,STD_OUTPUT_HANDLE
call [__imp_GetStdHandle]
mov rcx,rax
lea rdx,[msg]
mov r8d,msg_size
xor r9d,r9d
push 0
call [__imp_WriteConsoleA]
xor ecx,ecx
jmp [__imp_ExitProcess]
To compile and link:
$ nasm -fwin64 -o win.o win.asm
$ x86_64-w64-mingw32-ld -e _start -o win.exe win.o \
-L /usr/x86_64-w64-mingw32/lib -lkernel32