Skip to content

Atom Book 1 — Assembler Reference03

Addresses, Constants and Expressions

Labels and ORG establish logical addresses. Numeric literals, symbols, character literals, the current address, operators, and two byte functions form assembler expressions.

ORG and the logical cursor

ORG sets the address assigned to the next output operation:

asm
ORG 4000H
START:
    NOP

START receives $4000. ORG emits no byte. The append-only output adapter allows a later backward ORG only while the next IMAGE byte remains at or beyond the end of all earlier IMAGE bytes. It retains the greatest address reached for artifact sizing even when the final cursor later moves backward.

The command's --origin option sets the initial target address and ORG may then change the logical cursor within the configured target range.

Current address

$ by itself is the current logical output address:

asm
TABLE:
    DB 1,2,3,4
TABLE_SIZE EQU $-TABLE

Within a DB or DW list, Atom reevaluates $ at the address of each list item.

Numeric forms

Atom accepts decimal, hexadecimal, binary, and one-byte character literals:

FormExampleValue
Decimal4242
$ hexadecimal$2A42
Intel hexadecimal02AH42
% binary%10101042
Intel binary101010B42
Character'A'65

An Intel hexadecimal literal beginning with a letter needs a leading zero. 0FFH is 255; FFH is a symbol name. Literal values range from 0 through 65,535.

A character literal must decode to exactly one byte. It accepts the string escape set: \0, \n, \r, \t, \', \", \\, and \xHH.

Operators and precedence

Precedence runs from lowest to highest:

LevelOperators
1|
2^
3&
4<<, >>
5+, -
6*, /, %
7unary +, unary -, ~
8parentheses and values

Operators at the same level associate from left to right. Division truncates towards zero; remainder has the dividend's sign. Shift counts range from 0 through 23.

Concrete evaluation uses signed 24-bit intermediates. The final word domain is −32,768 through 65,535. The receiving instruction or directive may impose a narrower range.

LOW and HIGH

LOW(EXPR) returns bits 0–7. HIGH(EXPR) returns bits 8–15:

asm
ADDRESS EQU 0C432H
DB LOW(ADDRESS),HIGH(ADDRESS)    ; EMITS $32,$C4

The names are case-insensitive. LOW and HIGH remain legal symbol names when they are not followed by an opening parenthesis.

Forward expressions

Atom reads source once, so it stores unresolved expressions in a deliberately small form: one exact symbol plus a signed-byte addend.

These forms can be retained:

asm
DW TARGET
DW TARGET+5
DB LOW(TARGET-2)
LD HL,TARGET+4

The addend must fit −128 through 127. Two unresolved symbols, multiplication of an unresolved symbol, and unary negation of an unresolved symbol cannot fit the pending record and are rejected.

LOW() or HIGH() may wrap one forward affine expression. The function must be the outermost operation, so LOW(TARGET+1) is valid while LOW(TARGET)+1 is not. Forward byte functions are unavailable for relative branches and IX/IY displacements because those fields require a different range calculation at resolution time.

Range belongs to the receiving field

The expression evaluator produces a value before the instruction or directive checks its field:

ContextAccepted value
Byte immediate or immediate port0 through 255
IX/IY displacement−128 through 127
Relative branch displacement−128 through 127 from the following instruction
Word immediate or absolute address−32,768 through 65,535
DB numeric itemLow eight bits are emitted
DW numeric item−32,768 through 65,535

Negative word values retain their two's-complement encoding. Byte instruction operands do not truncate: LD A,100H is an error, while DB 100H emits $00.