x86 16bit assembler

A simple tutorial for any beginners in assembler who want to writed 16bit DOS applications

  1. Hello, World!
  2. Input to console

Hello, World!

The "Hello, World!" program is the first that anyone will make when they learn a new programming language or starting a new program to just get the GUI running without errors. This method may seem way too much to just print some text to the screen, right? The answer to that is yes but what you are doing is writing all of the instructions the CPU has to execute to write the text. Instead of printf ("Hello, World!"); where the compiler does all the hard work for you, you have to write the instructions. There are some advantages of assembly rather than C++: it is low level; you control the CPU and everything it does, it is just machine code but more human-readable, it is efficient; since we established that you are controlling the CPU instructions you can choose to implement only the necessary ones to make it work instead of the C++ compiling where there may be some code added that will still work if it was removed. For a lot of stuff C++ is good enough but there may be some applications where assembly may end up being used but this is all just stuff than needs complete control of the the hardware.

What we will use to print the text is the DOS BIOS interrupt, INT 21H. How these are used is you move a value into a register and other registers will have values inputted or outputted. If you set int 21h to do a certain function then you move a value into a different register which will do different things depending on the initial register value.

There are two ways to do this so I will include both. The first method is if you are starting out you may not have the assembler or it may be dawnting. The other method is if you are willing to use the assembler which is much better because you can go back and change it and it is overall a much nicer experience. The beginner method is to use the debug command in DOS and Windows. The second way is to use FASM which is called the Flat ASseMbler you can get FASM here.

Before you enter in debug you want to open up the directory that you want all your work to go to. The best place is the desktop. When you have navigated to the directory you want to work in. To start up debug type in debug when you enter that in you will be greeted with a '-'

Opening up the assembler
Debug FASM
Main screen of debug Main screen of FASM

To start programming in debug type in "a 100" this will start you program at address 100h. Now here os where the two assemblers show their differences.

Writing the code
Debug FASM
db "Hello, World!$"
jmp 115

after that, strike return and you should be yet again greeted with a '-', then type in
a 115
mov ah,
mov dx, 102
int 21h
int 20h
org 100h
msg: db "Hello, World!$"
mov ah, 09h
mov dx, msg
int 21h
int 20h

Going over the code line by line

db "Hello, World!$"

the db instruction is to define bytes. Since there is a string it the assmebler automatically converts it to ascii bytes, the db instruction defines some space in memory with those bytes.

mov ah, 09h

This moves the value of 9 hex into the AH. For the int 21h instruction 09h in the AH register means that it will print text on the console

Input to console

Back
2020 OZFix