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 hellocom.com

Copy the hellocom.com to c:\temp\ then in DOSBox

mount c c:\temp\
c:
cd \temp
hellocom.com

hellocom.asm

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

section .text 

start:
  ; 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

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