Hello World in Emu8086: Your First 8086 Program

If Emu8086 is already on your machine, the fastest way to learn it is to write one tiny program and watch it run. If you still need to set it up, start with the install guide, then come back here. This tutorial uses the community mirror linked from this site for the download: Emu8086 download (community mirror). The mirror may ask you to sign in.

What you will build

A program that prints two lines of text in the emulator window, then stops. It uses the small .COM template that most beginner examples start from, and it introduces the two ideas every later tutorial relies on: the program starts at ORG 100h and it finishes with RET.

The complete program

Create a new .COM template in Emu8086, replace its contents with the code below, and assemble it. The include 'emu8086.inc' line is there for a reason: this program uses the PRINT and PRINTN macros from that file, so the include line must stay.

include 'emu8086.inc'
ORG 100h

PRINT 'Hello, World!'
PRINTN
PRINT 'Welcome to 8086 assembly.'
RET

What you should see

When you run the program, the emulator window should show the two lines of text, one after the other. If you single-step instead, watch the instruction pointer move through the PRINT lines and stop at RET. Nothing after RET should run, because RET ends a .COM program.

If the text does not appear, check three things first: the file really is a .COM template, the include line is still at the top, and you have not typed a full stop or a stray character inside a quoted string. A missing closing quote is the most common first-program mistake.

The same idea without macros

Macros are convenient, but it helps to see what they hide. The program below prints the same first line using only a DOS service, interrupt 21h with function 09h. Strings printed this way must end with a $ character, which marks the end of the string. This version does not use any macro, so it does not need the include line.

ORG 100h

LEA DX, msg
MOV AH, 09h
INT 21h
RET

msg DB 'Hello, World!$'

Common first-program mistakes

  • Forgetting ORG 100h in a .COM program, so the code lands at the wrong address.
  • Using PRINT without include 'emu8086.inc', which gives an unknown-symbol error.
  • Ending a .COM program without RET, so execution runs on into whatever bytes follow the code.
  • Saving the file with the wrong template, then wondering why segment directives are rejected.

Next steps

Keep going with 8086 registers and segments to learn where your values live, then MOV, ADD and SUB to start doing arithmetic. The opcode reference explains every instruction used here, and the home page is the starting point for the whole series.

Similar Posts