Old Article

This is an old article which is only being kept for historical purposes.

Please navigate and update any links to the new article: SUBLEQ - A One Instructin Set Computer (OISC).

The SUBLEQ URISC (Ultimate RISC) / OISC (One Instruction Set Computer) Architecture

I have been interested in the limits of RISC (Reduced Instruction Set Computer) architecture for a while and recently came across OISC (One Instruction Set Computer) \ URISC (Ultimate RISC) architecture when looking for a simple way to implement a Virtual Machine for an A.I. project I was working on. It has to be one of the easiest architectures to implement in either software or hardware and this is the main reason for its design as a teaching aid. It has only one instruction, hence the name, which isn't the best name considering that most processors have one instruction set. URISC is good, but perhaps OIC (One Instruction Computer) would have been more accurate.

There are a number of types of OISCs, but this article will concentrate on those using the SUBLEQ instruction, as this is the one that I favour. Mention should also be made of those using the SUBNEG instruction which is very similar. Because there is only one instruction, only the operands are specified, which in this case consists of 3 memory addresses that are acted on as explained below:

SUBLEQ (Subtract and Branch if Less then or Equal to zero)

SUBLEQ a, b, c
Mem[b] := Mem[b] - Mem[a]
if (Mem[b] ≤ 0) goto c

SUBNEG (Subtract and Branch if Negative)

SUBNEG a, b, c
Mem[b] := Mem[b] - Mem[a]
if (Mem[b] < 0) goto c

Implementation Options

There are a number of implementation options for a SUBLEQ processor:

  • Negative numbers could refer to Input/Output ports.
  • Relative addressing could be used rather than direct addressing.
  • If an address is used as an Input/Output port, then this could copy the data rather than run SUBLEQ on it.
  • The branch destination could refer to a memory location that contains the actual branch destination, i.e. goto mem[c] instead of goto c.

Programming Using Macros

To program the SUBLEQ OISC machine we can create a set of Macros to ease development. Below are some simple examples of useful macros that could be implemented. The contents of each Macro consists of previously defined macros or 3 memory location references to be executed by the SUBLEQ instruction. Where the third operand is missing, it is assumed to be the location of the next instruction, i.e. it doesn't conditionally branch. Mem[Z] is assumed by most of the macros to contain zero.

Macro Jmp c     ; Jump directly to c (Resets mem[Z] to zero)
  Z, Z, c       ; mem[Z] := zero and jumps as result is 0
EndMacro

Macro Sub a, b  ; Subtract mem[a] from mem[b]
  a, b          ; Trivial Macro, but can make things clearer
EndMacro

Macro Add a, b  ; Add mem[a] to mem[b] (Assumes mem[Z] = 0)
  Sub a, Z      ; As mem[Z] contains zero, stores negative of mem[a] at mem[Z]
  Sub Z, b      ; Equivalent of: mem[b] := mem[b] - -mem[a] i.e. mem[b] := mem[b] + mem[a]
  Sub Z, Z      ; Set mem[Z] to zero
EndMacro

Macro Mov a, b  ; Copy mem[a] to mem[b] (Assumes mem[Z] = 0)
  Sub b, b      ; Set mem[b] to zero
  Add a,b       ; Add mem[a] to mem[b]
EndMacro

Macro Jge b, c  ; Jump to c if mem[b] ≥ 0
  b, Z, c       ; (Assumes mem[Z] = 0, leaves mem[Z] := -mem[b])
EndMacro

Macro Jle b, c  ; Jump to c if mem[b] ≤ 0 (Assumes mem[Z] = 0)
  Z, b, c
EndMacro

Macro Jz b, c   ; Jump to c if mem[b] = 0 (Assumes mem[Z] = 0)
  Jge b, GE0    ; If b ≥ 0 Jump to GE0
  Jmp NotZero   ; Jump to NotZero and mem[Z] := 0
GE0:
  Sub Z, Z      ; mem[Z] := 0
  Jle b, c      ; If b ≤ 0 Jump to c.  As b is ≥ 0, therefore: If b = 0 jump to c
NotZero:
EndMacro

It can been seen that by building up macros and using certain memory locations in a standard way, that it is relatively easy to program this type of machine.

Parallelization Possibilities

There are, of course, many more memory accesses per operation than most standard processors which will make object code larger and will have a negative speed impact. The speed of the processor could be increased, however, by running some instructions in parallel. This could be done by running several instructions at the same time if they are using different operands and aren't branching.

Further Information

There isn't much about SUBLEQ OISC computers on the internet. However I have found the following to be useful:

I have also written a follow up article: Hello, World! in SUBLEQ Assembly.

I hope that you find this interesting and would love to hear of any uses that you find for it.

Creative Commons License
The SUBLEQ URISC (Ultimate RISC) / OISC (One Instruction Set Computer) Architecture by Lawrence Woodman is licensed under a Creative Commons Attribution 4.0 International License.

Share This Post

Feedback/Discuss

Related Articles

Is SUBLEQ the Right Choice for a VM?

SUBLEQ is an interesting architecture because of its simplicity, adaptability and power. It is therefore an attractive choice for a simple virtual machine. However, this comes at a cost which we will...   Read More

SUBLEQ on the Commodore VIC-20

I have created a SUBLEQ Virtual Machine for the Commodore VIC-20. SUBLEQ is a computer architecture that has only one instruction: SUBLEQ. The instruction stands for SUbtract and Branch if Less than ...   Read More

SUBLEQ - A One Instruction Set Computer (OISC)

SUBLEQ has to be one of the easiest architectures to implement in either software or hardware and this is the main reason for its design as a teaching aid. It has only one instruction, hence why it is...   Read More

Improving the Standard SUBLEQ OISC (One Instruction Set Computer) Architecture

When I first came across SUBLEQ, I really liked the beauty and simplicity of the design. However, I have now been experimenting with it for quite a while and have noticed one aspect of the standard im...   Read More

Modula-2 Compilers on CP/M

Modula-2 is a great language in general and is a good choice for programming on CP/M. There are three good compilers available for CP/M which all require a Z80 processor and we'll compare each in turn...   Read More