Skip to content

Instantly share code, notes, and snippets.

@castleberrysam
Last active April 25, 2017 20:54
Show Gist options
  • Save castleberrysam/0514628bc38c24088380d9c12212a0db to your computer and use it in GitHub Desktop.
Save castleberrysam/0514628bc38c24088380d9c12212a0db to your computer and use it in GitHub Desktop.
All registers are 16 bits and are initialized to all zeros.
Registers: pc, sp, fp, ax, bx, cx, dx, ex
pc (000): program counter
sp (001): stack pointer
fp (010): frame pointer
ax (011): general purpose A
bx (100): general purpose B
cx (101): general purpose C
dx (110): general purpose D
ex (111): general purpose E
All instructions are 16 bits.
Big R is r1, little r is r2, big G is r3, little c is 8-bit immediate in bit encodings.
PC is incremented after each instruction except when PC is written to during its execution (branches, etc.)
(add r1 c) 0b00000RRRcccccccc R1 += C
(andl r1 c) 0b00001RRRcccccccc R1[7:0] &= C
(andh r1 c) 0b00010RRRcccccccc R1[15:8] &= C
(orl r1 c) 0b00011RRRcccccccc R1[7:0] |= C
(orh r1 c) 0b00100RRRcccccccc R1[15:8] |= C
(movl r1 c) 0b00101RRRcccccccc R1[7:0] = C
(movh r1 c) 0b00110RRRcccccccc R1[15:8] = C
(brnz r1 c) 0b00111RRRcccccccc if(R1 != 0) PC += C
(not r1 r2) 0b01000RRRrrrxxxxx R1 = ~R2
(add r1 r2 r3) 0b01001RRRrrrGGGxx R1 = R2 + R3
(and r1 r2 r3) 0b01010RRRrrrGGGxx R1 = R2 & R3
(or r1 r2 r3) 0b01011RRRrrrGGGxx R1 = R2 | R3
(mov (@+ r1 c) r2) 0b10RRRrrrcccccccc *(R1 + C) = R2
(mov r1 (@+ r2 c)) 0b11RRRrrrcccccccc R1 = *(R2 + C)
All memory locations are 16 bits wide.
0x0000 - 0x1fff 8Kword ROM (program/constant storage)
0x2000 Input pins
0x2001 Output pins
0xf000 - 0xffff 4Kword RAM (volatile program/data storage)
Assembler directives begin with the . character and are case insensitive.
The special symbol @ equals the current address that is being assembled into.
(.align N) Align the following code to the 2^N word boundary (increment @ until 2^N LSBs are zero).
(.ascii "text") Emit the null-terminated string given. Each word contains 2 characters, and the result must be word aligned.
(.word C N) Emit the word C, N times.
(.if symbol) If symbol is not defined or zero, disable emission.
(.else) If emission is enabled, disable emission. If emission is disabled, enable emission.
(.endif) Enable emission.
(.include "file") If the file given exists and is readable, assemble the file at the current location.
(.macro name) Disable emission and start defining a macro (name). name must be unique among other macros and opcodes.
Within the macro, use the symbol $N to denote the Nth positional argument to the macro.
(.endmacro) Stop defining a macro and enable emission. The macro can be invoked using (name arg1 arg2 ...).
(.print "text") Print the null-terminated string given to the standard output.
(.set symbol C) Define or set the value of the given symbol to the given word C.
(.label label) Equivalent to (.set label @).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment