2

Currently, I am using Logisim (yes, still Logisim) to build a 4-bit variant of the 8-bit SAP-1 microcomputer. However, I ran into a problem with the instruction register. Let me explain.

The SAP-1 has 5 instructions (LDA, ADD, SUB, OUT, HLT). These 5 instructions amount to 3 bits of data to read those RAM words. But that leaves only 1 bit for the address, and that means only 2 RAM addresses. To fix the problem, I tried to make the RAM words 6-bit instead (I don't know why I chose 6). But then I realized that having 6-bit RAM words would mean a 6-bit bus, and therefore a 6-bit CPU, which isn't good. Yet, 4-bit microprocessors carry on with upwards 40 instructions with kilobytes of memory. How do they do it, and how can I implement it into my 4-bit SAP-1?

winny
  • 13,064
  • 6
  • 46
  • 63
Trevor Mershon
  • 368
  • 2
  • 11
  • 2
    just look at x86, 6502, z80, countless others...as answered variable instruction length, the term 4-bit or 8-bit or 32-bit doesnt necessarily have any limits on number of instructions, size of operations, address space, or other. Using the n-bit terminology is in general bad and creates more confusion than it solves. – old_timer Apr 17 '20 at 15:13
  • Hm? I looked at the 4-bit Intel 4004 instrustion set and it had instructions that were 1 byte or more. Wouldn't 8-bit RAM addresses make the 4004 an 8-bit microprocessor, since those addresses have to go through the bus? – Trevor Mershon Apr 17 '20 at 15:41
  • Again try not to get hung up on terms like "8-bit", "16-bit" and so on, because they have fuzzy definitions at best and really dont mean anything. They create more confusion than use. whatever the vendor called is what you call it there is no definition, if you see a definition in some dictionary or wikipedia, then it is wrong because the term is based on opintion, some folks think the deifnition is register size, some, address bus size, some data bus size, alu size and so on. – old_timer Apr 17 '20 at 16:13
  • since it is rare for a processor to have all of those things the same size then you will generally have a strong difference of opinion on the term. x86 is an 8 bit instruction so do we call it an 8-bit processor? how many people call it that (other than maybe me). the 8088 was really a "16-bit" processor with an 8 bit external bus, but the thing was designed as a "16" bit processor, so do we call it that? it had a 20 bit address bus do we call it 20 bits, now it has 64 bit registers and a really wide data bus do we call it something else? – old_timer Apr 17 '20 at 16:15
  • or just not bother with using terms that mean nothing useful and only cause problems. – old_timer Apr 17 '20 at 16:16
  • think of it as a marketing term and not an engineering term. which is really what it is, and the marketing department for the specific company that makes that product, gets to pick the term with or without any technical backup. Does not have to conform to any other companies definition, instead used to make a product look better than the competitions with a bigger number. And it should be used as a marketing term not an engineering term. Like countless other terms folks get confused about thinking they have some technical meaning or definition. – old_timer Apr 17 '20 at 16:17
  • better terms are 4 bit opcode with variable length instructions, can go into more detail if you choose (this being your thing YOU get to create the definition and you cant be wrong because it is your term/definition for your invention). 4 bit opcode, x bit registers y bit data bus z bit address bus, etc, etc. or if you choose you can simply call it a 4 bit processor and have 256 instructions with 32 bit registers, 64 bit data bus and 128 bit address bus and you wont be wrong because it is your invention and your definition. – old_timer Apr 17 '20 at 16:21
  • The fact that these questions keep happening demonstrates the power of marketing and the value those departments have, they are not just money pits. The term hooked you in caused you to research their product, ask questions about it, marketing success their product is embedded in your brain, good, bad, or otherwise. If they intentionally go off the rails then you spread the word like a joke to friends, etc who then research and get it in their brains, marketing success. Look the new 256-bit risc-v processor from XYZ bench marked at 10 times the performance of an x86-64 – old_timer Apr 17 '20 at 16:25
  • have a look at this reference to Microchip's 8 bit microcontroller that uses 12 bit instruction set ... https://www.cl.cam.ac.uk/research/srg/han/Lambda/webdocs/PIC_Instruction_Reference-1.pdf – jsotola Apr 18 '20 at 02:27
  • You can have 8-bit instructions where the CPU needs to process the first half and then the second half. – user253751 Jun 23 '20 at 16:47

3 Answers3

4

The SAP-1 has 5 instructions(LDA, ADD, SUB, OUT, HLT). These 5 instructions amount to 3 bits of data to read those RAM words. But that leaves only 1 bit for the address, and that means only 2 RAM addresses.

I think there are some serious misconceptions here. Being "4 bit" does not mean that your instructions are necessarily 4 bit, just as being 64 bit does not mean that your instructions are 64 bit. If you want to build a 4 bit CPU, you should look at what your CPU needs to do, and then pick an instruction size that makes sense for the application. Practical CPUs typically have either at least 16 bit instructions or a mechanism to make instructions variable length simply because a 4 bit instruction length doesn't let you do very much.

Yet, 4-bit microprocessors carry on with upwards 40 instructions with kilobytes of memory. How do they do it, and how can I implement it into my 4-bit SAP-1?

First, lets pick a common definition of what "4 bit" means. We'll say it means a system that has the general purpose integer registers all 4 bit. It doesn't mean that all registers are only 4 bit, but we'll assume the basic ones are. In that case, and with byte addressable memory, you would be limited to 16 bytes of RAM.

If you want more you have a few options:

  1. Make the address space larger, in which case you will probably need to make the registers larger, in which case you arguably no longer have a 4 bit processor
  2. Make the address space larger, but introduce a specific address register that is larger than the general purpose registers that can hold larger addresses (e.g. you have 4 bit integer registers and a special 16 bit register for memory pointers). Note that this may require you to be able to do ALU operations on greater than 4 bit values.
  3. Introduce a memory bank mechanism, where you have multiple 4 bit banks you can swap between, possibly by writing to a specific register, using a specific instruction, etc. This effectively just encodes memory addresses in two (or more) register values.
user1850479
  • 14,842
  • 1
  • 21
  • 43
2

Variable-length instructions ---- suppose you want to jump with an offset of 550 from the current program counter? Uses at least 3 of the 4-bit nibbles, just for the JumpOffset. Plus the opcode, which for Jump with Offset may need 2 more nibbles.

winny
  • 13,064
  • 6
  • 46
  • 63
analogsystemsrf
  • 33,703
  • 2
  • 18
  • 46
  • Well, Jump with Offset isn't part of the instruction set. Is there a way to simplify it for a different instruction, like ADD or LDA? – Trevor Mershon Apr 17 '20 at 15:26
1

Also with the address problem, it doesn't mean that a 4 bit CPU can only handle 4 bit addresses, as an 8 bit CPU (like a Commodore 64 in the good old days) can also address 64 KB of memory which is 16 bits.

It just means, it cannot handle it at once, so first 8 bits are loaded, and than another 8 bits.

So if your CPU needs to handle 1 GB, it is still possible with 4 bits, but you need many of those to acquire the final complete address within the 1 GB.

Michel Keijzers
  • 13,867
  • 18
  • 69
  • 139