NASM 16-bit EXE file example


This is an example Hello World ASM 16 Bit x86 assembly program which can be compiled and linked into a 16 Bit DOS EXE with freely available tools.
First compile it in Windows with NASM, and then link it to create an EXE using the public domain VAL linker.


; hello.asm
; Compile in Windows
; nasm -f obj -o hello.obj hello.asm
; link in DOSBox / MS DOS
; val hello.obj,hello.exe,,,

BITS 16

segment code

..start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop

mov dx,hello
mov ah,9
int 0x21

mov ax,0x4c00
int 0x21

segment data

hello: db 'Hello World', 13, 10, '$'

segment stack stack
resb 64
stacktop:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s