• Edit
  • Delete

Ben Eater 8 Bit Breadboard Computer SAP1

BEN'S INFOS

Homepage: https://eater.net/8bit

YouTube Playlist: https://www.youtube.com/watch?v=HyznrdDSSGM&list=PLowKtXNTBypGqImE405J2565dvjafglHU

COMMUNITY / FORUMS

https://www.reddit.com/r/beneater/

Questions

  • Is control Flags in (FI) really necessary? Can't it be auto done with sum out (EO)

DIAGRAMS

 

INSTRUCTIONS

OPC   DEC HEX         DESCRIPTION
-------------------------------------------------------------------------------------
NOP   00  0000
LDA   01  0001 aaaa   Load contents of memory address aaaa into register A.
ADD   02  0010 aaaa   Put content of memory address aaaa into register B, 
                      add A + B, store result in A.
SUB   03  0011 aaaa   Put content of memory address aaaa into register B,
                      substract A - B, store result in register A.
STA   04  0100 aaaa   Store contents of register A at memory address aaaa.
LDI   05  0101 vvvv   Load 4 bit immediate value in register A (loads 'vvvv' in A).
JMP   06  0110 aaaa   Unconditional jump. Set program counter (PC) to aaaa, 
                      resume execution from that memory address.
JC    07  0111 aaaa   Jump if carry. Set PC to aaaa when carry flag is set and resume 
                      from there. When carry flag is not set resume normally.
JZ    08  1000 aaaa   Jump if zero. As above, but when zero flag is set.
      09  1001
      10  1010
      11  1011
      12  1100
      13  1101
OUT   14  1110        Output register A to 7 segment LED display as decimal.
HLT   15  1111        Halt execution.

Instructions that could be added:

  • LDB aaaa - Load content of memory adress aaaa into register B
  • STB aaaa - Store content of register B at memory adress aaaa
  • ADI vvvv - Add immediate value (could save memory)
  • CMP aaaa - Compare. Similar to substract but do not update register A, only set zero flag

CONTROLS

HLT   Halt the computer
MI    Memory address register in
RI    RAM in
RO    RAM out
II    Instruction register in
IO    Instruction register out
AI    Register A in
AO    Register A out
EO    ALU sum out
SU    Switch ALU to substract (otherwise add)
BI    Register B in  
OI    Output in (display bus value on 7segment display as decimal value)
CE    Counter enable (increment program counter PC)
CO    Counter out (Put program counter value on bus)
J     Jump (Read program counter in from bus)
FI    Flags register in (store alu flags in flags register)

Controls signals that could be added:

  • BO - Register B out (control signal hardware is there, but not used)
  • RIC - Reset micro instruction counter (performance gain for instructions with few microcode steps)
  • KYI - Bus switches / "Keyboard" in

ASSEMBLY / MACHINE CODE

Tricks

  • Substracting 1 from any positive number except 0 will enable the carry bit
  •  

Example Programs

Add two numbers

   OPC    VAL     MEMAD   INST VALUE  DESCRIPTION
----------------------------------------------------------
00 LDA    14      0000    0001 1110   Put value "28" from mem addr 14 into A
01 ADD    15      0001    0010 1111   Add value "14" from mem addr 15 to A
02 OUT            0010    1110 xxxx   Output result ("42") 
...
14        28      1110    0001 1100   Value 28 in memory
15        14      1111    0000 1110   Value 14 in memory

Add two 16bit numbers

Add 12473 + 48089

MSB / LSB = most/least significant byte

Notes

  • Too long, not possible without register overwriting.
  • LDI cannot be used for immediate loading, because it loads 4bit values only.
  • No output, 7segment display can only display 1 8bit integer, no place in memory.
    Examine output by manual setting memory address register.

 

   ASSEMBLER      MEMAD   INST VALUE  DESCRIPTION
----------------------------------------------------------
00 LDA    (13)    0000    0001 1001   Load LSB part of 12473 from mem addr 13 in A.
01 ADD    (15)    0001    0010 1111   Add LSB part of 48049, overflow -S> carry is set.
02 STA    (15)    0010    0100 1111   Store result from A into mem addr 15
                                      (Overwrite to save memory, can run only once).
03 JC     (08)    0011    0111 1000   Jump to mem addr 8 when carry is set,
                                      otherwise continue with next instruction. 

04 LDA    (12)    0100    0001 1100   Load MSB part of 12473 in A.
05 ADD    (14)    0101    0010 1110   Add MSB part of 48089.
06 STA    (14)    0110    0100 1110   Store result in mem addr 14 (overwrites).
07 HLT            0111    1111 xxxx   Halt the computer, result is in (14,15).
                                      =60562 (1110 1100 1001 0010).
08 LDI    1       1000    0101 0001   Load value "1" (carry) in A
09 ADD    (12)    1001    0010 1100   Add MSB part of 12473 from mem addr 12
10 STA    (12)    1010    0100 1100   Store in mem addr 12
11 JMP    (04)    1011    0110 0100   Jump to addr 04 to finish calculation
  
12                1100    0011 0000   MSB part of 12473
13                1101    1011 1001   LSB part of 12473
14                1110    1011 1011   MSB part of 48089
15                1111    1101 1001   LSB part of 48089

Ideas

  • Add two 16 bit numbers

Arduino EEPROM Programmer

https://github.com/beneater/eeprom-programmer

MISC

Google Calc Spreadsheet Emulator

https://www.youtube.com/watch?v=wB8R0oOkaAw

https://docs.google.com/spreadsheets/d/19bIGZXmD_VY89bpfnw9qf1uBbb2Kua-rAPWddzYNm7Y/edit#gid=653976056