Tiny8 has two arithmetic instructions:
- ADD a (opcode 3):
ACC ← ACC + M[a] - SUB a (opcode 4):
ACC ← ACC − M[a]
Both take 6 cycles. E1 reads the operand into the MDR, as LOAD does. E2 sends ACC and MDR through the ALU and loads the result into the ACC (ACCsrc = 1, LdACC = 1). The only difference is ALUop: 0 to add, 1 to subtract.
The ALU subtracts using twos complement: A − B = A + B' + 1. XOR gates invert the MDR's bits when ALUop = 1, and ALUop also supplies the carry-in for the + 1.
Results are 8 bits and wrap modulo 256. The carry out of bit 7 is dropped:
- 200 + 100 = 300 → 44;
- 3 − 5 = −2 → 254 (
FE), which is −2 read as two's complement.
Both update the zero flag. SUB plus JZ is Tiny8's way to compare two numbers.