Voja4 Instruction Set Reference
The Supercon.6 (2022) “Voja4” badge executes a 12-bit, 4-bit-word CPU implemented in PIC24 firmware. This page is a compact reference for compiler and runtime work. Primary source: the upstream Instruction Set (rev. 4, 2022-11-02). The User Manual covers the programmer’s model.
Machine model
Item |
Value |
|---|---|
Instruction word |
12 bits |
Code space |
4096 words ( |
Data space |
256 nibbles ( |
Registers |
R0-R9 general purpose; R10-R15 are SFRs (R10/R11 recoverable) |
Flags |
|
Stack |
5 subroutine levels, 3 nibbles per return address, in |
Reset entry |
PC = |
Multiply/divide |
None; software only |
All instruction fields are nibbles:
bits 11..8 bits 7..4 bits 3..0
+-----------+-----------+-----------+
| OPCODE | OPERAND X | OPERAND Y |
+-----------+-----------+-----------+
Most instructions use a 4-bit opcode in bits 11..8. Opcode 0x0 is an extended
opcode: bits 7..4 select the operation, bits 3..0 are a 4-bit operand.
Operand notation
Form |
Meaning |
|---|---|
|
Direct register 0-15 (SFR names are valid destinations/sources) |
|
4-bit immediate, |
|
Direct data-memory address, 8-bit, |
|
Indirect data-memory address: |
|
12-bit code address |
|
Skip condition: |
|
Bit number |
|
Manual name for the I/O port selected by |
Instruction summary
4-bit opcodes (bits 11..8)
Op |
Binary |
Mnemonic |
Operation |
Flags |
|---|---|---|---|---|
1 |
|
|
RX <- RX + RY |
V Z C |
2 |
|
|
RX <- RX + RY + C |
V Z C |
3 |
|
|
RX <- RX - RY |
V Z C |
4 |
|
|
RX <- RX - RY - C |
V Z C |
5 |
|
|
RX <- RX OR RY |
Z |
6 |
|
|
RX <- RX AND RY |
Z |
7 |
|
|
RX <- RX XOR RY |
Z |
8 |
|
|
RX <- RY |
none |
9 |
|
|
RX <- N |
none |
A |
|
|
data[RX:RY] <- R0 |
none |
B |
|
|
R0 <- data[RX:RY] |
none |
C |
|
|
data[NN] <- R0 |
none |
D |
|
|
R0 <- data[NN] |
none |
E |
|
|
PCM <- NN[3:0], PCH <- NN[7:4]; does not jump |
none |
F |
|
|
PC <- PC + sign-extend(NN) |
none |
MOV PC,#NN loads only the middle and high PC nibbles. A jump also needs a write
to PCL (0x0D). GOTO and GOSUB generate the full two-word sequence.
Extended opcodes (opcode nibble 0x0)
X |
Binary |
Mnemonic |
Operation |
Flags |
|---|---|---|---|---|
0 |
|
|
flags from R0 - N; result discarded |
C Z |
1 |
|
|
R0 <- R0 + N |
V Z C |
2 |
|
|
RY <- RY + 1 |
Z C |
3 |
|
|
RY <- RY - 1 |
Z C |
4 |
|
|
RY <- RY - 1; if RY=0 skip next word |
none |
5 |
|
|
R0 <- R0 OR N; C <- 1 |
Z C |
6 |
|
|
R0 <- R0 AND N; C <- 0 |
Z C |
7 |
|
|
R0 <- R0 XOR N; C <- ~C |
Z C |
8 |
|
|
swap R0..R(N-1) with |
none |
9 |
|
|
Z <- NOT(bit M of RG) |
Z |
A |
|
|
set bit M |
none |
B |
|
|
clear bit M |
none |
C |
|
|
toggle bit M |
none |
D |
|
|
rotate right through C |
Z C |
E |
|
|
R0 <- N; pop PC from stack |
none |
F |
|
|
if F true, skip M words |
none |
RG is encoded as two bits G in bits 3..2 of the operand nibble:
G |
Hardware register |
Notes |
|---|---|---|
0 |
R0 |
|
1 |
R1 |
|
2 |
R2 |
|
3 |
I/O port |
|
G=3 selects an I/O port, not R3: BIT R3,n reads an input bit, while
BSET R3,n, BCLR R3,n, and BTG R3,n modify an output bit. Use another
register or an explicit MOV/AND/OR sequence to modify R3.
BIT sets Z=1 when the tested bit is zero and Z=0 when it is one.
Flags
Instruction(s) |
C |
Z |
V |
|---|---|---|---|
|
1 on unsigned carry out |
1 if result = 0 |
1 on signed overflow |
|
1 = no borrow; 0 = borrow |
1 if result = 0 |
1 on signed overflow |
|
unchanged |
1 if result = 0 |
unchanged |
|
forced to 1 |
1 if result = 0 |
unchanged |
|
forced to 0 |
1 if result = 0 |
unchanged |
|
toggled |
1 if result = 0 |
unchanged |
|
1 if R0 >= N |
1 if R0 = N |
unchanged |
|
1 only when 15 -> 0 |
1 if result = 0 |
unchanged |
|
0 only when 0 -> 15; else 1 |
1 if result = 0 |
unchanged |
|
unchanged |
unchanged |
unchanged |
|
unchanged |
1 if bit = 0 |
unchanged |
|
old bit 0 |
1 if result = 0 |
unchanged |
|
unchanged |
unchanged |
unchanged |
Notes:
After
CP R0,N:C=1meansR0 >= N,Z=1meansR0 == N. To branch on “less than”, testNC.SUBborrow is inverse carry, soC=0means borrow.SBB RX,RYperformsRX - RY - C. BecauseCis inverse borrow afterSUB, chainingSUBthenSBBrequires an adjustment for a multi-nibble borrow chain.INC/DECuseCas a wrap indicator, not as a general carry.
Compiler-generated sequences
Sequence |
Words |
Generated code |
|---|---|---|
|
2 |
|
|
2 |
|
|
2 |
|
|
1 |
|
The compiler emits flash bytes as pairs of NIBBLE directives. BYTE takes
0..255; NIBBLE and 4-bit immediates take 0..15.
Code-generation notes
Relative jumps
JR NN adds the signed 8-bit NN to the already-incremented PC. The range is
-128..+127, and the target is:
target = address_of_JR + 1 + NN
JR -1 (0xFFF) is an infinite self-loop. JR 0 falls through to the next
instruction. Page crossing wraps modulo 4096, so the code space is a ring.
SKIP
SKIP F,M only skips forward, 1 to 4 words. M=0 encodes a skip of 4:
M field |
Words skipped |
|---|---|
|
4 |
|
1 |
|
2 |
|
3 |
The condition is evaluated against the flags at the time of the SKIP; SKIP
does not modify flags. SKIP cannot be used as a backward branch.
SKIP counts words, not source lines or pseudo-ops. GOTO and GOSUB are two
words, so SKIP cond,1 before a GOTO skips only its first word and executes
the second (MOV PCL/MOV JSR). Use a single-word JR for conditional
branches, or branch around the whole two-word sequence with SKIP cond,2.
DSZ also skips one word; do not place a two-word pseudo-op immediately after
DSZ when the following sequence must be skipped as a unit.
Aliases: GTE = C, LT = NC, EQ = Z, NE = NZ.
Calls, jumps and the hardware stack
GOTOandGOSUBare two-word sequences. They can reach any of the 4096 code words, but both clobberPCMandPCH(0x0E,0x0F).GOSUBwrites the low target nibble toJSR(0x0C). That write pushes the 12-bit return address onto the hardware stack and jumps.RET R0,#Nloads R0 withNand pops the return address. There is noRETwithout an immediate and noPUSH/POP.The stack has 5 levels. Return addresses live at
0x10 + 3*SP, low nibble first. A sixth nested call is a fatal stack overflow (SP indicator blinks110); an extraRETis a fatal underflow (111). Both halt the program.Only
MOV RX,RY,MOV RX,#N,INC RYandDEC RYtrigger a call/jump when their destination isJSR/PCL. Other writes, such asMOV [0x0C],R0orMOV [0x0D],R0(absolute stores to JSR/PCL), are plain memory writes and do not branch.MOV PC,#NNonly loadsPCM/PCH; it does not jump.
R0-only memory access
All data-memory accesses go through R0:
MOV [NN],R0 ; store R0 to absolute data address NN
MOV R0,[NN] ; load R0 from absolute data address NN
MOV [XY],R0 ; store R0 to address (RX << 4) | RY
MOV R0,[XY] ; load R0 from address (RX << 4) | RY
There is no MOV [NN],RY or MOV RY,[NN]. A compiler must move the value into
R0 first, or move a loaded value out of R0. For a pointer held low/high in
R6:R7, the indirect address is written [R7:R6] because X is the high nibble
and Y is the low nibble.
Arithmetic and shifts
No multiply or divide instruction. Use repeated add/subtract or shift-add routines.
ADD RX,RXis a left shift;ADC RX,RXis a left rotate through carry.RRCis the only single-instruction shift. There is noRLC; useADC RX,RX.All arithmetic is 4-bit. Multi-nibble values must be handled as nibble arrays with explicit carry/borrow logic.
EXR NswapsR0..R(N-1)with0xE0..0xE(N-1);N=0means all 16. This is the only block move and it is a swap, not a copy. WithN>10it also swaps the fixed registers (OUT/INor R10/R11, andJSR/PCL/PCM/PCH).EXRis not one of the instructions that triggers a call/jump, so it changes those stored target registers without branching; useN<=10unless that is intended.
Program memory is not writable
MOV [NN],R0 addresses data memory only. There is no instruction that stores to
code memory at runtime, so self-modifying code and run-time patching are not
possible. Constants and lookup tables must be built at assembly/link time.
Timing
One instruction is executed per clock. Clock speed is selected by SFR Clock
(0xF1), from about 0.5 Hz to about 250 kHz. At the fastest setting the badge is
roughly 0.25 MIPS, and the exact rate depends on the instruction mix. There are
no interrupts or cycle-count guarantees beyond “one instruction per clock”.