Assembler reference document
(This document does not reflect all new features in R5 yet.)
An MVM assembler source is a text file containing at most one instruction or declaration per line. Descriptions of the allowed types of constructs follow.
Comments
Comments begin with ' and extend to the end of the line.
Device declarations
Syntax: device [<shorthand>] <TYPE>
This declaration states that the MVM program requires a device of a certain type in order to run properly. The execution environment is responsible for providing a device of the requested type. Device implementations have to provide a well-defined interface (each device type has a fixed interface). However, each implementation may operate differently. For example, if a certain service is unavailable, a dummy device may be provided instead.
These device types are currently defined:
- ALU: arithmetic & logic unit for accelerated math and bit operations
- SYSTEMTIME: a device reporting the current time & date
- VIDEO: a virtual text display with variable size (current max: 80*50 chars)
- MOVEMENT: a device allowing processes to move stepwise in four directions, in case they reside in a grid-like environment
The optional shorthand name is used to refer to device registers, e.g.:
device vid VIDEO 'Text display device vid.cols = 9 'Power up the cathode tube vid.rows = 1 vid.enable = 1 vid.buf[4] = ':' 'Put a colon in the middle
Device registers can be read and written. Some of them behave like standard memory (every value written can be read out unchanged). Some registers, however, perform special functions and may produce varying values with every access.
Device registers
VIDEO
- .cols, .rows: columns, rows of screen (r/w)
- .enable: 0=screen off, 1=screen on (r/w)
- .buf: linear array holding screen contents (r/w)
SYSTEMTIME
- .time_lo: lower 32 bits of time (in milliseconds, read-only)
- .time_hi: upper 32 bits of time (in milliseconds, read-only)
MOVEMENT
- .direction: direction to look/walk. 0=north, 1=east, 2=south, 3=west (r/w)
- .available: 0=spot in direction taken, 1=spot in direction available (read-only)
- .go: 0=default value (no action), 1=walk in selected direction (r/w)
- .result: 0=moved successfully, 1=spot was taken, 2=other problem
Variable declarations
Syntax: var <name>
This declaration introduces a variable. A variable represents a signed 32-bit integer and is assigned to a fixed memory cell at compile time.
Label declarations
Syntax: <name>:
This declaration assigns a label to the next code line. The label can be used as a jump target in branches.
Branches
Syntax: if <lhs> <op> <rhs> goto <label>
Branches to a given label if a condition is met. The condition is a comparison of two values (constants/variables), with the operator <op> being "<", ">", "<=", ">=" or "=".
Example:
if ax > 0 goto loop
Unconditional branch
Syntax: goto <label>
Jump to the specified label. You may consider this good or evil at your own discretion.
Assignments
Syntax 1: <target> = <source>
Syntax 2: <target> = <target> <op> <argument>
The assembler's primary workhorse. Does everything from copying values, I/O reads/writes, loading constants, performing additions, subtractions, divisions to bit operations.
Here are some examples covering all the operators currently defined):
ax = ax - 1 ax = ax + bx ax = ax / 1000 'requires ALU device ax = ax * bx 'requires ALU device bx = bx % 10 'requires ALU device ax = ax & $1234 'requires ALU device
The modifier [atomic] may be added at the end of the statement in order to use a different subleq encoding (the default encoding writes to the target memory cell twice which may cause problems with I/O writes).