Skip to main content

SPU

·349 words·2 mins
Killar
Author
Killar
I’m a Java, Godot and Rust dev. I do games/mods projects. I’m currently a french student. I do some Youtube videos.

About
#

The SPU (or Simple Processing Unit) is a small custom 16-bit CPU I made inspired by the famous 6502.

The main goal of this CPU is to be the easiest CPU to use. The SPU have only 16 instructions as follows:

SPU Instruction Set
#

InstructionArgumentWhat it does
ADDNoneDo X + Y and return the value to X.
SUBNoneDo X - Y and return the value to X.
ANDNoneDo X & Y and return the value to X.
ORNoneDo X or Y and return the value to X.
XORNoneDo X ^ Y and return the value to X.
NOTNoneInverse the X register.
LDXim12/adr12Change the value of X.
LDYim12/adr12Change the value of Y.
STXadr12Store the X register to the ram address.
STYadr12Store the Y register to the ram address.
JMPadr12Jump to the label/address.
JICadr12Jump to the label/address if the carry flag is set.
JIZadr12Jump to the label/address if the zero flag is set.
HLTNoneStops the proccessor.

I made an Assembler in Rust and made the full CPU circuit in Logisim Evolution. I didn’t made an emulator beacause I was too lazy… But it was a cool project to make.

Here is an exemple program witch do the fibonacci sequence:

/*
  Do the fibonacci sequence.
  The end result goes into the ram address $0001.
*/

;Init variables
ldx 0
stx $0001   ; prev1 = 0
ldx 1
stx $0002   ; prev2 = 1
ldx 9
stx $0000   ; n = 9

loop:
  ldy 3
  sub
  ldy 128
  add
  jic stop  ; if n < 3 { stop(); }

  ldx $0002
  ldy $0001
  add
  sty $0002 ; prev2 = prev1
  stx $0001 ; prev1 = prev2 + prev1

  ldx $0000
  ldy 1
  sub
  stx $0000 ; n -= 1

  jmp loop
stop:
  hlt

For the frenchies I made a video about how I made the assembler:

Assembler repo
#

Killarexe/SPU-Assembler

An assembler for the SPU using rust

Rust
0
0