Version 6

A project log for Hardware Controlled 4 bit CPU

A hardware controlled 4 bit CPU based on lessons learnt from the TD4 and the CHUMP CPUs

agpcooperagp.cooper 12/26/2022 at 10:280 Comments

Version 6

Version 6 is like version 5 except the expanded ALU is not used. Here are the op codes:

I wrote up an 8 bit multiplication routine, first in C:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

unsigned short mul(unsigned char A,unsigned char B)
  // Returns:
  //   A = A * B
  unsigned short res=0;
  unsigned char i=8;  // 8 bit

    if (A>=0x80) {
  if (i>0) goto LOOP;
  return res;

int main(void)
  unsigned char A,B;
  unsigned short M;
  int i,j;

  for (i=0;i<=255;i++) {
    for (j=0;j<=255;j++) {
      A=(unsigned char)i;
      B=(unsigned char)j;
      if (i*j!=M) printf("%6d %6d\n",i*j,M);

  return 0;

I tested all cases so I know it works. I then dumbed it down to 4 bits:

unsigned short mult(unsigned char A,unsigned char B)
  // Returns:
  //   C = A * B
  unsigned short C=0;
  unsigned char D=4;  // 4 bit

    C=(C+C)&0X0F;     // 4 bit adjustment
    if (A>=8) {       // MSB of 4 bit
      C=(C+B)&0X0F;   // 4 bit adjustment
    A=(A+A)&0X0F;     // 4 bit adjustment
    D=(D-1)&0X0F;     // 4 bit adjustment 
  if (D>0) goto LOOP; // 4 bit adjustment
  return C;

int main(void)
  unsigned char A,B;
  unsigned short C;

  A=(unsigned char)5;
  B=(unsigned char)3;
  printf("C=5*3 %d\n",C);
  return 0;

Although the code handles overflow into the high order bit of the result variable (C), in this implementation, I have not considered overflow of C. Therefore 3x5 is big as the algorithm can handle:

Here is the code running:

In the RAM window: A, B, C & D are updated as the program runs. At the end, the output port displays the answer.

The run starts with: 

At the end:

Here is a version that handles lager numbers:

If you used A=13 (D) and B=15 (F), then the result would be C=3 and D=12 (C) or 195.

Refer to the Simulation below:

Unfortunately both of these programs are too big for my 32 byte PROM design.

I will check the schematic tomorrow for any missed errors.

Yeah, found two errors, fixed and forwarded for manufacture.