NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: kanito73 on November 17, 2018, 02:10:48 AM
-
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.
-
Here's one simple example for you to begin with;
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
Try that out
-
And here's the Win64 Windows version of MessageBox
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
NASM is easy-going :D
-
MessageBox, 32-bit version
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
-
32-bit command-line prompt greeting
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
Have a pleasant journey ;D
-
Thanks all for your time and examples, it will be very helpful for me. Just needed a start point...
-
Thanks alot for your effort from me too.
-
Hi all,
The examples here helped a lot. Mainly about what was needed at the command line to compile with things like printf and scanf.
John
-
Whewww... it has been years past. Glad my simple examples here have helped people getting started painlessly. Havent been programming quite some time but for beginners looking for more advanced "helper" library, I recommend using https://sourceforge.net/projects/baselibs/files/ (https://sourceforge.net/projects/baselibs/files/). A very lightweight library offering debugger-like features. Support both Win and Linux, too.