# Digital design 4-bit ALU. Submission for Tiny Tapeout 03.
This is a digital design for a 4-bit ALU inspired by classical Z80, 6502 and 8085 processors.
I wanted design to be visually easy to understand and closer to perhaps how it would've been done back in the days,
so I chose to design logic circuit in Wokwi instead of HDL.
## How does it work?
Each clock cycles ALU performs one of the 8 possible operations and stores result in the 4-bit accumulator register.
```
accumulator <4 bit> = accumulator <4 bit> (operation) operand <4 bit>
```
### Supported operations
```
000xxxx lda imm :: imm -> accumulator
001xxxx neg imm :: 0x0F - imm -> accumulator
010.... shr :: accumulator / 2 -> accumulator
011xxxx sub imm :: accumulator - imm -> accumulator
100xxxx and imm :: accumulator & imm -> accumulator
101xxxx xor imm :: accumulator ^ imm -> accumulator
110xxxx or imm :: accumulator | imm -> accumulator
111xxxx add imm :: accumulator + imm -> accumulator
```
### Input
```
IN0 clk
IN1..IN3 operation type [3 bit] (see below)
IN4..IN7 operand value [4 bit]
```
### Output
```
OUT0..OUT3 value stored in the accumulator [4 bit]
OUT4..OUT6 unused (todo: zero, overflow flags)
OUT7 carry flag
```
### Control signals
Map between operation type (opcode) and control signals
```
mux1 mux2 mux3 AtoX negX setC outC invC
000 lda - - 1 0 0 - 0 -
001 neg - - 1 0 1 - 0 -
010 shr - - 1 1 0 - 0 -
011 sub 1 1 0 0 1 1 1 1
100 and 0 0 0 0 0 - 0 -
101 xor 0 1 0 0 0 - 0 -
110 or 1 0 0 0 0 - 0 -
111 add 1 1 0 0 0 0 1 0
```
Bit slice 1
Loading
tt-block-input-8
tt-block-input-8
Loading
tt-block-output
tt-block-output
Bit slice 2
Bit slice 3
Bit slice 4
negX
AtoX
setC
outC
invC
mux3
mux1
mux2
clock
accumulator_0
accumulator_1
accumulator_2
accumulator_3
carry
Opcode
Operand
Output
flag
clock