Reduced Instruction Set Microcontroller, Five-Bit Opcodes (RCM5) Manual

© 2026 Kevan Hashemi, Open Source Instruments Inc.

Contents

Description
Instruction Set
Design

Description

[26-NOV-26] The RMC5 (RISC Microcontroller, Five-Bit Opcodes) is an open-source, reconfigurable eight-bit processor described in VHDL (VHSIC Hardware Description Language). The RMC5 is designed for use in miniature, micropower devices, in which we want to devote as little as possible of the logic chip to the processor itself, leaving the rest of the logic available for program memory, process memory, and peripheral functions. The RMC5 uses five-bit opcodes to define thirty-two instructions. Most of these instructions execute in one clock cycle. The microcontroller uses separate instruction and process memories with separate address and data buses, but the instruction and process addresses are always the same length. An RMC5 instruction contains a five-bit opcode and an operand that is the length of one address. We can configure the RCM5 with address length 4 to 16 bits, so the instructions will be anywhere from 9 to 21 bits long. The process memory locations are always eight bits wide. The processor contains its own internal stack with locations wide enough to accommodate an address or a byte. The depth of the stack is configurable.

The RCM5 code is available in the RMC5 GitHub repository. This repository includes a Lattice Diamond deployment of the processor that we use to measure the size of the processor core. The RMC5 is designed for use in miniature, micropower devices such as the Lattice Semiconductor LCMXO2-640ZE. When configured with ten-bit instruction and process addresses and equipped with for a 1024-location instruction memory, 16-location stack, the RMC5 occupies at most 247 four-bit look-up tables (LUTs). If we do not use all of its port signals, the size will drop. If we do not use the Read Data Strobe (RDS), for example, the size drops to 233 LUTs. When served by an Embedded Block RAM instruction memory, the RMC5 runs at up to 10 MHz in LCMXO2ZE devices.

The RMC5 supports multiple interrupt sources through its IRQ input. Upon entering the interrupt routine, the processor sets the I flag, thereby inhibiting further interrupts during execution of the routine. The interrupt routine must not clear the I flag, either explicitly with the clri instruction or implicitly with the pop F instruction. The rti instruction restores the program counter and clears I. If IRQ remains asserted, the processor executes the interrupt routine again before executing the interrupted instruction. Each invocation of the interrupt routine should remove at least one source of interrupt request, until no requests remain outstanding. Alternatively, the interrupt routine may service multiple interrupt sources in a single invocation.

The RMC5 provides an eight-bit accumulator, A, and a flags register, F. The flags are zero (Z), carry (C), and interrupt disable (I). It provides one index register, IX, that we use to hold a process memory pointer for moving bytes between process memory and A. It provides a stack pointer, SP, that operates with push and pop operations to manage a stack internal to the processor. A program counter, PC, steps through instructions in program memory and jumps to subroutines and interrupts. We can load IX with an address constant, increment IX, and decrement IX. The arithmetic logic unit (ALU) provides eight-bit addition and subtraction of A and the contents of a process memory location, with and without carry or borrow in. The ALU also provides rotation of A left and right through carry, which facilitates multiplication and long addition, as well as logical AND, OR, and XOR between A and the contents of a process memory location. The RMC5 assembly language is similar to that of the Z80 in the way the instructions are written out.

The RMC5 provides thirty-two instructions, each occupying one location in program memory. Each instruction consists of a five-bit operation code in the top bits and an address operand in the bottom bits. We specify the address length with the generic constant addr_len, which may be from five to sixteen bits. With a ten-bit address, for example, we can have up to 1024 fifteen-bit locations in program memory and 1024 eight-bit locations in process memory. We need not provide physical memory for all these locations. Unlike the OSR8, the RMC5 does not provide instructions containing data constants. We obtain data constants from process memory. We can provide these constants in read-only memory, in initialized locations in random-access memory, or by having the memory manager return the bottom eight bits of the address for a range of 256 process memory locations.

The RMC5 stack is separate from process memory. Each stack location is wide enough to hold either an eight-bit data value or an entire program address. We specify the number of bits in SP with the generic constant sp_len. With sp_len equal to four, for example, we have sixteen stack locations. When we push a value onto the stack, we write the value to the location pointed to by SP and increment SP. When we pop a value off the stack, we decrement SP and read the location pointed to by the decremented SP. We can push and pop A and F. Subroutine calls and interrupts each make use of one stack location to store the program counter. The stack extends upwards, and the programmer must make sure that the stack is large enough for the program.

The processor is a single VHDL entity, RMC5_MCU, implemented with look-up tables and registers, including distributed RAM for the stack. All other components of the embedded controller are provided by entities peripheral to the RMC5, but residing within the firmware of the logic chip, or by components external to the logic chip. The program memory contains the instructions that will be executed by the processor. The processor reads from program memory with its program counter (prog_cntr) and receives the entire instruction on prog_data. The processor accesses all other peripherals through an external memory management unit (MMU) by means of the processor address bus (mcu_addr) and data buses (mcu_data_out and mcu_data_in). The processor implements a bi-directional eight-bit data bus with eight outgoing data bits and eight incoming data bits.

The processor updates its internal registers and program counter on the rising edge of CK. The process memory address, outgoing data, and read and write strobes are combinatorial outputs. We can use asynchronous program memory, or we can use synchronous program memory that we read on the falling edge of CK. In the MachXO2, we can implement program memory with Embedded Block RAM (EBR). If we want the processor to be able to write to its own synchronous program memory, we provide a second port to the program memory through the memory manager, and arrange for writes to take place on the rising edge of CK while instruction reads take place on the falling edge.

Instruction Memory Process Memory Permissible
Asynchronous Asynchronous Yes
Asynchronous Falling-Edge Synchronous Yes
Falling-Edge Synchronous Asynchronous Yes
Falling-Edge Synchronous Falling-Edge Synchronous No
Falling-Edge Synchronous Rising-Edge Synchronous No
Table: Permissible Memory Configurations for Read Operations.

If the instruction memory is synchronous, process memory must be asynchronous on read cycles. When the processor asserts its Read Data Strobe (RDS), the processor will consume the incoming data on the next rising edge of CK. A peripheral that provides data from a first-in first-out buffer, for example, can use RDS to advance its read pointer on that same edge. When the processor asserts its Write Data Strobe (WDS), the memory manager must write the outgoing data to the specified location on the next rising edge of CK. Consecutive read or write instructions may leave RDS or WDS asserted continuously. With asynchronous process memory reads, the processor is able to execute all but four of its instructions in one clock cycle. The four exceptions are pop A, pop F, ret, and rti.

The Clock Enable (CKEN) input permits us to suspend execution of the processor without stopping CK. When CKEN is false, the processor holds its execution state and inhibits process memory accesses and stack writes. We can use CKEN to suspend the processor while peripheral logic continues to operate.

The Interrupt Request (IRQ) input interrupts the processor, provided the processor's interrupt flag (I) is not set and the processor is enabled and ready to execute its next instruction. The processor pushes the program counter onto the stack, sets I, and jumps to the interrupt routine. The interrupt controller, which is peripheral to the RMC5, can provide interrupt bits for various interrupt sources, mask bits to enable or disable assertion of IRQ by these individual interrupt bits, as well as set and reset bits that the processor can use to clear and assert interrupts. The RMC5 provides an Interrupt Service (ISRV) output that indicates the processor is servicing an interrupt. Changes in interrupt service state appear on ISRV on the falling edge of CK, except that RESET clears ISRV directly. We can use ISRV to control the selection of a fast or slow clock in a micropower device.

The processor does not automatically save A, IX, or the arithmetic flags upon entering an interrupt. The interrupt routine must preserve these values if it changes them and they are required by the interrupted program. We must not clear I during the interrupt routine, either explicitly with clri or implicitly by popping flags with I clear. The rti instruction restores the program counter and clears I. If IRQ remains asserted, the processor will enter the interrupt routine again before executing the interrupted instruction. Each invocation of the interrupt routine should remove at least one source of interrupt request, until no requests remain outstanding. We can also service several sources during one invocation of the interrupt routine.

The RESET input to the processor resets its stack pointer, clears its flags, and sets its program counter to the starting address. We specify the starting address and the interrupt address with the generic constants start_pc and interrupt_pc. Their default values are 0 and 3 respectively. We can place an unconditional jump instruction at each of these locations to take the processor to the corresponding routine. Unlike the OSR8 jump instruction, the RMC5 "jp nn" instruction occupies only one program memory location, so there is no requirement to separate the starting and interrupt addresses by three locations. The RMC5 has no reset instruction. We can provide a software reset bit in the memory manager that the processor can set to cause RESET to be asserted.

Additional internal controller functions may be added and made available to the RMC5 through the memory manager. We can provide an eight-bit multiplier, for example, by arranging for the processor to write two bytes to two locations and read out the sixteen-bit product from two additional locations. The input-output interface provides access to external circuit components. We can provide logic to read and write the registers of a sensor, to convert an analog voltage into a digital value, or to transmit samples through a radio-frequency antenna. We make these functions available to the processor in the form of eight-bit process memory locations. The input-output pins are the signals present on the device pins. The connections between these pins and the peripheral logic are defined by the application in which we deploy the RMC5.

Instruction Set

[26-NOV-26] The RMC5 is a Reduced Instruction Set Computer (RISC) with five-bit operation codes. There are thirty-two instructions, each occupying one location in instruction memory. All but four instructions execute in one clock cycle, and none takes more than three clock cycles. The working registers are an eight-bit accumulator A and an index register IX. We have a flags register F containing the zero (Z), carry (C), and interrupt disable (I) flags. We can push A, IX, and F onto the internal stack and pop them off again. We can increment IX and decrement IX. We can read and write process memory either by specifying the address in the instruction or by using IX. The IX register is eight bits wide when the address is wider than eight bits, and of the same width as the address when the address is fewer than eight bits. When the address is longer than IX, the RMC5 sets the top bits of the address HI and IX now addresses the top 256 bytes of process memory. We can add, subtract, and, or, and xor A with the contents of any process memory location, and rotate A left or right through carry. We can load IX with A by pushing A onto the stack and popping IX off the stack. The call and ret instructions provide subroutine calls and returns. The rti instruction returns from an interrupt.


Figure: RMC5 Opcode Map. Rows are selected by opcode bits 4-2 and columns by bits 1-0. Colors distinguish the four principal instruction groups. The opcode of each instruction is given in hexadecimal.

Each instruction consists of a five-bit opcode in the top bits and an address operand of addr_len bits in the bottom bits. The operand field is ignored by instructions that do not require an address constant. We use nn for an address constant, either in instruction memory or in process memory. There are no immediate data operands: to load A with a constant or perform arithmetic with a constant, we read the constant from a location in process memory. If the process memory location 0x001 contains the value 0x01, we increment A with the instruction add A,(0x001). If the memory management unit (MMU) outside the RMC5 provides loop-back of the lower eight address lines into the eight RMC5 data lines, this supply of eight-bit constants is guaranteed. We can write "ld A,(n)" to load the value n into A.

SyntaxOpcodeCycles SyntaxOpcodeCycles SyntaxOpcodeCycles SyntaxOpcodeCycles
jp nn0x001 call nn0x011 jp nz,nn0x021 jp z,nn0x031
jp nc,nn0x041 jp c,nn0x051 ret0x063 rti0x072
push A0x081 push F0x091 push IX0x0A1 clri0x0B1
pop A0x0C2 pop F0x0D2 pop IX0x0E2 seti0x0F1
add A,(nn)0x101 adc A,(nn)0x111 sub A,(nn)0x121 sbc A,(nn)0x131
and A,(nn)0x141 or A,(nn)0x151 xor A,(nn)0x161 clrf0x171
ld A,(nn)0x181 ld A,(IX)0x191 ld (nn),A0x1A1 ld (IX),A0x1B1
inc IX0x1C1 dec IX0x1D1 rl A0x1E1 rr A0x1F1
Table: RMC5 Instruction Set, Opcodes, and Execution Times in Clock Cycles.
Table: The RMC5 Instruction Set. We give syntax and hexadecimal opcode for each instruction, with a link to its detailed description and the number of clock cycles required for execution. We use nn for an address constant, (nn) for the byte at process memory location nn, and (IX) for the byte at the process memory location pointed to by IX.

We define the complete set of instructions below. If we do not mention a flag in the description of an instruction, it is unaffected. Clock cycles are cycles of CK during which CKEN is asserted. Instruction memory may be asynchronous or read on the falling edge of CK. Process memory reads must be asynchronous, and process memory writes take place on the rising edge of CK. The processor asserts RDS for instructions that read process memory and WDS for instructions that write process memory, provided the instruction is not displaced by an interrupt and execution is enabled.

The stack is separate from process memory. SP points to the next empty stack location. Each entry is wide enough to hold either an eight-bit data value or a complete program counter. The stack pointer wraps around at the stack depth; there is no overflow or underflow detection. When IRQ is asserted and I is clear, the processor accepts the interrupt in place of the next instruction, pushes the current program counter onto the stack, sets I, and jumps to interrupt_pc. Interrupt entry takes one clock cycle. A, IX, and the arithmetic flags are not saved automatically. There are no instructions to push or pop IX, so an interrupt routine that uses IX must arrange to preserve the interrupted program's index position if required. Nested interrupts are not supported by the interrupt service indication.

jp nn: Unconditional jump to location nn in instruction memory. Clock cycles: 1.

jp nz,nn: If the zero flag (Z) is not set, jump to location nn in instruction memory, otherwise proceed to the next instruction. Clock cycles: 1.

jp z,nn: If the zero flag (Z) is set, jump to location nn in instruction memory, otherwise proceed to the next instruction. Clock cycles: 1.

jp nc,nn: If the carry flag (C) is not set, jump to location nn in instruction memory, otherwise proceed to the next instruction. Clock cycles: 1.

jp c,nn: If the carry flag (C) is set, jump to location nn in instruction memory, otherwise proceed to the next instruction. Clock cycles: 1.

call nn: Call the subroutine that begins at instruction memory location nn. Write the current program counter to the internal stack at SP, increment SP by one, and jump to nn. The entire program counter occupies one stack location. Clock cycles: 1.

ret: Return from subroutine. Decrement SP, load the program counter from the stack, then increment the program counter so as to resume execution at the instruction following the call. Clock cycles: 3.

rti: Return from interrupt. Decrement SP and load the program counter from the stack without incrementing the program counter. Clear I to enable interrupts and clear the internal interrupt service flag (ISRV follows on the falling edge of CK). Execution resumes at the instruction that was about to be executed when the interrupt occurred. The interrupt routine must clear the external IRQ request before returning if we are to avoid another interrupt. Clock cycles: 2.

push A: Push A onto the internal stack at SP, then increment SP by one. Clock cycles: 1.

pop A: Pop A off the internal stack. Decrement SP by one, then read the stack location pointed to by SP and load its lower eight bits into A. Clock cycles: 2.

push IX: Push IX onto the internal stack at SP, then increment SP by one. Clock cycles: 1.

pop IX: Pop IX off the internal stack. Decrement SP by one, then read the stack location pointed to by SP and load its lower eight bits into IX. Clock cycles: 2.

push F: Push the flags register onto the internal stack at SP, then increment SP by one. Bit 0 is Z, bit 1 is C, and bit 2 is I. All remaining bits of the stack entry are zero. Clock cycles: 1.

pop F: Pop F off the internal stack. Decrement SP by one, then restore Z, C, and I from bits 0, 1, and 2 of the stack entry respectively. The interrupt service output is not affected by this instruction. Clock cycles: 2.

ld (nn),A: Write the byte in register A to location nn in process memory. Clock cycles: 1.

ld A,(nn): Read the byte at process memory location nn and load it into register A. The zero flag is unaffected. Clock cycles: 1.

ld (IX),A: Indexed load from A using IX. Write the byte in A to the process memory location pointed to by IX. IX is unchanged. Clock cycles: 1.

add A,(nn): Add the byte at process memory location nn to A, leaving the lower eight bits of the sum in A. If the sum exceeds 0xFF, set C, otherwise clear C. If the eight-bit result is zero, set Z, otherwise clear Z. Clock cycles: 1.

adc A,(nn): Add the byte at process memory location nn to A with carry in. If C was set, add one to the sum. Leave the lower eight bits in A. If the sum exceeds 0xFF, set C, otherwise clear C. If the eight-bit result is zero, set Z, otherwise clear Z. Clock cycles: 1.

sub A,(nn): Subtract the byte at process memory location nn from A, leaving the lower eight bits of the difference in A. If the unsigned subtraction requires a borrow, set C, otherwise clear C. If the eight-bit result is zero, set Z, otherwise clear Z. Clock cycles: 1.

sbc A,(nn): Subtract the byte at process memory location nn from A with borrow in. If C was set, subtract one more. Leave the lower eight bits of the difference in A. If the unsigned subtraction requires a borrow, set C, otherwise clear C. If the eight-bit result is zero, set Z, otherwise clear Z. Clock cycles: 1.

and A,(nn): Replace A with the bit-wise logical AND of A and the byte at process memory location nn. If the result is zero, set Z, otherwise clear Z. Clock cycles: 1.

or A,(nn): Replace A with the bit-wise logical OR of A and the byte at process memory location nn. If the result is zero, set Z, otherwise clear Z. Clock cycles: 1.

xor A,(nn): Replace A with the bit-wise logical XOR of A and the byte at process memory location nn. If the result is zero, set Z, otherwise clear Z. Clock cycles: 1.

ld A,(IX): Indexed load of A using IX. Read the byte at the process memory location pointed to by IX and load it into A. IX and the flags are unchanged. Clock cycles: 1.

inc IX: Increment index register IX by one. If IX contains the maximum address, it wraps around to zero. Clock cycles: 1.

dec IX: Decrement index register IX by one. If IX is zero, it wraps around to the maximum address. Clock cycles: 1.

rl A: Rotate A left through carry. A(7..1) := A(6..0), A(0) := C, C := A(7). All values on the right-hand sides are those before the rotation. The zero flag is unaffected. Clock cycles: 1.

rr A: Rotate A right through carry. A(6..0) := A(7..1), A(7) := C, C := A(0). All values on the right-hand sides are those before the rotation. The zero flag is unaffected. Clock cycles: 1.

clrf: Clear the arithmetic flags Z and C to zero. The interrupt flag is unaffected. Clock cycles: 1.

clri: Clear the interrupt disable flag I to zero, thus enabling interrupts. Clock cycles: 1.

seti: Set the interrupt disable flag I to one, thus disabling interrupts. Clock cycles: 1.

Design

[03-NOV-26] For design and development of the RMC5, see its Design Page.