NASM Forum > Using NASM
NASM tutorial for Windows (7+), console and windows
kanito73:
Hello everybody
I'm new to NASM and need a good tutorial to start programming on Windows 7. I've just installed NASM for Win64 and the linker GoLink (mentioned in a few forums) but was unsuccessful my first try due the lack of documentation for Windows (99% available is for Linux), I was able to assemble and link a minimalist (do nothing) example just to test, but when I open the EXEcutable with a debugger (x64dbg) the disassembled code is weird and nothing of my code shows there, as if it was just garbage code. Many people uses NASM on Windows, so it should work and by sure the problem it's me.
I would be so grateful if you share a good tutorial or at least an example of a very minimalist program (mov ax,0... and exit, just that) and how to assemble and generate the EXE file IN WINDOWS with a recommended linker.
I already program ASM in DOS using Turbo Assembler and (my favorite) A86 assembler, in fact I choosed NASM due the (relatively) similarity (the concept) with A86, but generating executables now for Windows (first for console, later for windows app)...
The steps I followed:
nasm -f win32 mytest.asm
golink mytest.obj
but did not work...
Thanks for any help, idea or documentation...
P.S. I want to make standalone programs (by now), don't want to use (or interface with) Visual Studio or other compilers.
dreamCoder:
Here's one simple example for you to begin with;
--- Code: ---global start
extern printf ;from msvcrt
extern scanf ;from msvcrt
extern ExitProcess ;from kernel32
section .bss
name: resb 100
section .data
prompt: db 'Enter your name: ',0
frmt: db '%s',0
greet: db 'Hello, %s!',0ah,0
section .text
start:
sub rsp,40
mov rcx,prompt
call printf
mov rdx,name
mov rcx,frmt
call scanf
mov rdx,name
mov rcx,greet
call printf
xor ecx,ecx
call ExitProcess
;nasm -f win64 myprog.asm
;golink /console myprog.obj msvcrt.dll kernel32.dll
--- End code ---
Try that out
dreamCoder:
And here's the Win64 Windows version of MessageBox
--- Code: ---global start
NULL equ 0
MB_OK equ 0
extern MessageBoxA ;from user32
extern ExitProcess ;from kernel32
section .data
hello: db 'Hello, Windows!',0
title: db 'My First Win64',0
section .text
start:
sub rsp,40
mov r9,MB_OK
mov r8,title
mov rdx,hello
mov rcx,NULL
call MessageBoxA
xor ecx,ecx
call ExitProcess
;nasm -f win64 myprog.asm
;golink myprog.obj user32.dll kernel32.dll
--- End code ---
NASM is easy-going :D
dreamCoder:
MessageBox, 32-bit version
--- Code: ---global start
NULL equ 0
MB_OK equ 0
extern MessageBoxA ;from user32
extern ExitProcess ;from kernel32
section .data
hello: db 'Hello, Windows!',0
title: db 'My First Win32',0
section .text
start:
push MB_OK
push title
push hello
push NULL
call MessageBoxA
push 0
call ExitProcess
;nasm -f win myprog.asm
;golink myprog.obj user32.dll kernel32.dll
--- End code ---
dreamCoder:
32-bit command-line prompt greeting
--- Code: ---global start
extern printf ;from msvcrt
extern scanf ;from msvcrt
extern ExitProcess ;from kernel32
section .bss
name: resb 100
section .data
prompt: db 'Enter your name: ',0
frmt: db '%s',0
greet: db 'Hello, %s!',0ah,0
section .text
start:
push prompt
call printf
add esp,4
push name
push frmt
call scanf
add esp,8
push name
push greet
call printf
add esp,8
push 0
call ExitProcess
;nasm -f win myprog.asm
;golink /console myprog.obj msvcrt.dll kernel32.dll
--- End code ---
Have a pleasant journey ;D
Navigation
[0] Message Index
[#] Next page
Go to full version