.COM vs .EXE in Emu8086: Which Template to Choose

Emu8086 offers two templates for a new program, and choosing the wrong one is a common first error: the directives that are correct in one template are rejected in the other. This tutorial compares them directly, with a minimal working example of each, so you can choose confidently. Emu8086 setup is in the install guide.

.COM: small, simple, one segment

A .COM program is a single segment of at most 64 KB. It starts with ORG 100h, because the first 256 bytes of the segment hold the program segment prefix, and it ends with RET. All segment registers start out pointing at the same segment, so you do not set DS yourself. This is the right template for almost every beginner exercise in this series, including the Hello World program.

ORG 100h

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

msg DB 'Hello from a .COM program!$'

.EXE: segments you control

A .EXE program has separate code, data and stack segments, and can be larger than 64 KB in total. You declare them with the simplified segment directives .MODEL, .STACK, .DATA and .CODE, and you must set DS to your data segment at the start, because the loader does not do it for you. The program ends with function 4Ch rather than a plain RET.

.MODEL SMALL
.STACK 100h
.DATA
msg DB 'Hello from an .EXE program!$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, msg
MOV AH, 09h
INT 21h
MOV AX, 4C00h
INT 21h
MAIN ENDP
END MAIN

What you should see

Both programs should print their greeting and stop. The visible difference is in the setup, not the output: the .COM version needs no segment setup and ends with RET, while the .EXE version sets DS, uses a named procedure, and exits through function 4Ch with a return code of zero in AL. If the .EXE version prints garbage, the usual cause is a missing MOV DS, AX pair, so DS still points somewhere unrelated to your string.

Which template to choose

  • Choose .COM for short exercises, single-file examples, and anything in this tutorial series unless it says otherwise.
  • Choose .EXE when a program needs more than one segment, a larger stack, or a structure that mirrors a real multi-segment program.
  • Never mix the two conventions in one file: ORG 100h with .MODEL SMALL, or a .COM program that tries to set DS with @DATA, will not assemble cleanly.

Converting between them

To convert a small .COM program to .EXE, move its data after the code into a .DATA section, add the .MODEL, .STACK and .CODE directives, add the DS setup at the start, and replace the final RET with the 4Ch exit. To go the other way, remove the segment directives, add ORG 100h, drop the DS setup, and end with RET. Doing one conversion by hand is the best way to fix the difference in your memory.

Next steps

Both templates appear throughout the series: most tutorials use .COM, and the registers and segments tutorial explains why DS matters. For input and output details, see INT 21h input and output. The opcode reference and the home page complete the picture.

Similar Posts