Assembler (hcasm)

Multi-target assembler supporting Z80, 8080/8085, and 8086 instruction sets. Produces relocatable object files (.obj) for linking with hclink. Syntax is inspired by NASM with platform-specific extensions.

BinaryTarget
hcasm-z80Zilog Z80
hcasm-8086Intel 8086 (also used for 8086exe)
hcasm-8080Intel 8080
hcasm-8085Intel 8085

Usage

hcasm-{target} [options] <input.s>

Options:
  -o <file>       Output object file (default: a.obj)
  -dump <file>    Generate assembly listing dump
  -h              Show help

Source Format

label: mnemonic arg1, arg2 ; comment

Labels

global _start       ; export symbol for linker
extern printf       ; import symbol from another module

_start:             ; global label
.loop:              ; sub-label (becomes _start.loop)
    jp .loop        ; references _start.loop

Sections

section text        ; executable code
section data        ; initialized data (db, dw, dd)
section bss         ; uninitialized data (ds, rb, resb, rw, resw)

Output order: text → data → bss. BSS is zero-filled at load time.


Data Directives

DirectiveDescriptionExamples
dbDefine byte(s)db 0x12, "Hello", 0
dwDefine word(s), 16-bit LEdw 0x1234, label, "AB"
ddDefine dword(s), 32-bit LEdd 0x12345678
ds / rb / resbReserve bytesds 256
rw / reswReserve words (size × 2 bytes)rw 128
equDefine constantSIZE equ 512
timesRepeat directive/instructiontimes 256 db 0

Expressions and Number Formats

FormatExampleNotes
Decimal42Standard
Hexadecimal0xFF, 0FFh0x prefix or trailing h
Binary0b10100b prefix
Octal0o7770o prefix

Operators: + - * / %$ = current position — </LOBYTE>/HIBYTE


Z80 — Syntax and Examples

FeatureSyntax
Memory accessAlways square brackets [] - ld a, [hl], ld [ix+5], a
Indexed addressingld a, [ix+10] / ld a, [iy-4] (signed displacement)
16-bit loadld hl, 0x1234
16-bit arithmeticadd hl, de / sbc hl, bc (HL only destination)
Exchangeex de, hl / ex (sp), hl / ex af, af'
Block operationsldi, ldd, cpi, cpir
Bit operationsset 0, a / res 1, [hl] / bit 2, b
; Z80 CP/M "Hello World"
section text
global _start
_start:
    ld de, msg
    ld c, 9             ; BDOS print string
    call 5
    ld c, 0             ; BDOS exit
    call 5

section data
msg: db "Hello, World!$"

8080/8085 — Syntax and Examples

FeatureSyntax
Memory via HLmov a, m = mov a, [hl] = mov a, [m] (all equivalent)
Memory via BC/DE (store)stax b = stax bc = stax [bc] = stax [b]
Memory via BC/DE (load)ldax b = ldax bc = ldax [bc] = ldax [b]
16-bit loadlxi h, 0x1234
16-bit adddad d (HL only destination)
Direct address loadlhld 0x1234 (load HL from memory)
8085 extrasrim, sim (interrupt mask)
; 8080 CP/M "Hello World"
section text
global _start
_start:
    lxi d, msg
    mvi c, 9
    call 5
    mvi c, 0
    call 5

section data
msg: db "Hello, World!$"

8086 — Syntax and Examples

FeatureSyntax
Memory via registermov ax, [bx] / mov [si], ax
Based addressingmov ax, [bp-2] / mov ax, [bp+4]
Based+indexedmov ax, [bx+si] / mov ax, [bp+di+4]
Direct addressmov ax, [0x1234]
Immediate to memorymov word [bp-2], 42 / mov byte [bx], 0
Size prefixesbyte, word, dword (when operand size ambiguous)
Distance prefixesshort, near, far (override jump/call distance)
Segment overrideses mov ax, [bx] (use ES instead of DS)
Repeat prefixesrep movsb / repe cmpsb / repne scasb
; 8086 MS-DOS "Hello World"
section text
global _start
_start:
    mov ah, 9
    mov dx, msg
    int 0x21
    mov ah, 0x4C
    int 0x21

section data
msg: db "Hello, World!$"

Target Comparison

FeatureZ808080/80858086
Memory brackets[][] or m[]
Indexed addressing[ix+d], [iy+d]None[bp+N], [bx+si]
Imm to memoryld [ix+N], immNot nativemov word [mem], imm
SegmentsN/AN/Aes, cs, ss, ds
Size prefixesN/AN/Abyte, word, dword
16-bit immediateld hl, immlxi h, immmov ax, imm
Direct addr loadld hl, (addr)lhld addrmov ax, [addr]
Return value reghlhlax
16-bit arithmeticadd hl, rr
adc/sbc hl, rr
dad rradd ax, rx

[B Compiler] · [Linker] · [Target CPUs] © 2025-2026 HC SDK