Intel 4004 architecture overview - CodeAbbey/intel4004-emu GitHub Wiki

In its core the Intel 4004 processor contains few amount of memory cells, which could be used for various operations. Look at the picture below. Though at first you may think "there are too much stuff" - but after reading few explanations below you will agree it is far simpler than it looks.

Intel 4004 registers etc.

###Registers

You may see them in the left of the picture.

These are 4-bit memory cells inside the processor. CPU may operate on them even if it have no other memory (e.g. external RAM). As you see, there are 16 (registers) of them in two groups and 1 accumulator :

  • sixteen general (or index) registers marked from R0 to R15 - they are identical to each other;
  • single accumulator which is more "powerful" than remaining ones.

Accumulator (or Acc) is the most often used register because CPU can do with it more "tricks" than with others. It could be incremented or decremented, it could be store its value to any other register or fetch it back. Content of any other register could be added (or subtracted) to Acc. It could be shifted left or right, tested for zero etc, etc.

General registers on the other hand are mainly used as a secondary operands with some instructions involving Acc. Though also there are few instructions working on them directly. Sometimes they are used in pairs - in such cases pair could only consist of two registers placed side-by-side at the picture.

Carry (or CY) is the last memory cell in registers block. It keeps a single bit which is mainly used as fifth bit of Acc in arithmetic operations. I.e. if we add 10+10 result is greater than 15 (maximum value which could be stored in 4 bits) so the highest bit is stored in the CY flag. From there it could be added to next 4-bit fragment of the value so allowing to operate with large numbers.

###Special registers

In the right part of the picture we have outlined three special memory cells. They could not be used in general operations and serve a single purpose each.

  • data pointer is 8-bit register keeping the number (address) of the external memory cell which could be loaded or stored to accumulator; these cells are 4-bit each we can address 256 of them;
  • code pointer (or instruction pointer) points to code memory so that CPU knows which instruction should be fetched next; after execution of almost any instruction this pointer is automatically advanced - however various "jump" instructions may change its value arbitrarily; it has size of 12 bits so up to 4096 code cells could be addressed (each instruction takes either 1 or 2 cells);
  • return stack saves copies of code pointer for returning from subroutines (we'll see how it works later).

Next: Let's try to run some instructions