NASM 16-bit COM file example

The following is a simple NASM assembly hello world example that produces a 16-bit COM executable.
It will not run in modern windows because they do not support the COM format. You can however run the output in DOSBox.

To compile:

nasm hellocom.asm -fbin -o

Copy the to c:\temp\ then in DOSBox

mount c c:\temp\
cd \temp


; 16-bit COM file example
; nasm hellocom.asm -fbin -o
; to run in MS DOS / DosBox:
  org 100h 

section .text 

  ; program code
  mov  dx, msg;  '$'-terminated string
  mov  ah, 09h; write string to standard output from DS:DX
  int  0x21   ; call dos services

  int 20h

section .data
  ; program data

  msg  db 'Hello world'
  crlf db 0x0d, 0x0a
  endstr db '$'

section .bss
  ; uninitialized data

Leave a Reply

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

You are commenting using your 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