"8086 Assembler for DOS" (or ASM.COM
for short) is a small 16-bit DOS-based
two-pass self-hosting assembler for the x86 assembly language. -- It was
created by Stephen Duffy in 2001. In December 2020 Robert Riebisch started
maintaining his own fork at
https://github.com/bttrx/8086-assembler/.
- Supports the Intel i8086 instruction set.
- Supports the
EQU
pseudo-op to define constants. - Directly generates
.COM
files. (No separate linker required.) - 10 KiB small. (6 KiB after UPX-ing.)
- Free and open-source software.
- No support for
.EXE
or.OBJ
files. - No support for FPU instructions.
- No support for i80186 (or higher) instructions.
- No support for declaring uninitialized data.
- No support for macros.
- No support for including other source files.
- No support for listings.
- Very limited support for expressions, i.e., only something like
mov al,[bx+di]
andmov ax,word ptr[codestore+2]
works. - Supports only DOS line endings (CRLF) in source file.
- Maximum line length in source file is 78 characters.
- ...
dec r/m8
,dec r/m16
, andinc r/m8
instructions are encoded incorrectly. This also applies to thebyte ptr
orword ptr
variants ofdiv
,idiv
,imul
,mul
,neg
,not
, andpush
.- Better avoid whitespace around the comma between instruction operands.
lds
andles
instructions always (?) give errors. -- Reported by Japheth.- Neither duplicate symbols nor non-existent symbols are recognized. -- Reported by Japheth.
- Intel i8086/88 microprocessor (or compatibles)
- ~256 KiB total RAM
- ~20 KiB disk space
- Microsoft MS-DOS 2.0 (or compatibles)
Type at the command prompt:
asm.com infile.a
This will generate infile.com
.
On success, ASM.COM
prints "NNN bytes written" and exits to DOS with
errorlevel 0. On error, ASM.COM
prints a relevant error message and exits
with errorlevel<=200 for source code errors or >200 for all other errors. For
details see ASM.A
file.
label: instruction operands ; comment
See ASM.A
file for real-world examples until this paragraph has been
written.
Register names in alphabetical order, grouped by first letter.
- A
ah
,al
,ax
- B
bh
,bl
,bp
,bx
- C
ch
,cl
,cs
,cx
- D
dh
,di
,dl
,ds
,dx
- E
es
- S
si
,sp
,ss
Conventional instructions in alphabetical order, grouped by first letter.
- A
aaa
,aad
,aam
,aas
,adc
,add
,and
- C
call
,cbw
,clc
,cld
,cli
,cmc
,cmp
,cmpsb
,cmpsw
,cs:
,cwd
- D
daa
,das
,dec
,div
,ds:
- E
es:
- H
hlt
- I
idiv
,imul
,in
,inc
,int
,into
,iret
- J
ja
,jae
,jb
,jbe
,jc
,jcxz
,je
,jg
,jge
,jl
,jle
,jmp
,jna
,jnae
,jnb
,jnbe
,jnc
,jne
,jng
,jnge
,jnl
,jnle
,jno
,jnp
,jns
,jnz
,jo
,jp
,jpe
,jpo
,js
,jz
- L
lahf
,lds
,lea
,les
,lock
,lodsb
,lodsw
,loop
,loope
,loopne
,loopnz
,loopz
- M
mov
,movsb
,movsw
,mul
- N
neg
,nop
,not
- O:
or
,out
- P:
pop
,popf
,push
,pushf
- R
rcl
,rcr
,rep
,repe
,repne
,repnz
,repz
,ret
,retf
,rol
,ror
- S
sahf
,sar
,sbb
,scasb
,scasw
,shl
,shr
,ss:
,stc
,std
,sti
,stosb
,stosw
,sub
- T
test
- W
wait
- X
xchg
,xlat
,xor
Notes:
- Prefix instructions
lock
andrepCC
have to be on its own line. - You can use
int 3
to emit the specialint3
instruction. rep
is an alias torepe
.
For a detailed description of each instruction, see, e.g., Complete 8086 instruction set, NASM 2.05 based x86 Instruction Reference, or NASM 2.05 based x86 Instruction Reference (different layout).
byte
Use withptr
to specify a variable as a byte (8 bits).db
Declare initialized byte (8 bits).dw
Declare initialized word (2 bytes).dword
Use withptr
to specify a variable as a doubleword (4 bytes).equ
(or=
) Define constant.ptr
Use withbyte
,dword
,qword
, orword
to specify the data type of a variable.qword
Use withptr
to specify a variable as a quadword (8 bytes).word
Use withptr
to specify a variable as a word (2 bytes).
ASM.COM
always sets a program's origin address to 100h. The pseudo-op org
,
known from other assemblers, e.g., NASM, is not
supported.
File hello.a
:
; print message to stdout
mov ah,9
mov dx,msg
int 21h
; return to DOS
ret
; message string
msg:
db 'hello, world',13,10,'$'
Type to build:
asm hello.a
While generating HELLO.COM
8086 Assembler will show the following:
8086 Assembler for DOS
Copyright (c) 2001 Stephen Duffy
Copyright (c) 2020-2021 Robert Riebisch
[Under GNU GPL v2]
>> Pass 1 started
12 lines processed
<< Finished successfully
>> Pass 2 started
12 lines processed
23 bytes written
<< Finished successfully
Running HELLO.COM
will then produce:
hello, world
To build ASM.COM
no external tools are required.
Just type:
asm asm.a
That's all.
Copyright (c) 2001 Stephen Duffy [email protected]
Copyright (c) 2020-2021 Robert Riebisch [email protected]
Usage of the works is permitted under the terms of the GNU GPL v2.
See LICENSE
file for details.