0
\$\begingroup\$

I am a software developer now interested in the electronic implementation of computers.

When I think about computers, the thing performing the action is the "processor". But the processor is technically the CPU. So looking within that, what looks like is doing the actual processing is the Control Unit (CU). It turns out the GPU also has a CU(s).

The CU receives external instructions or commands which it converts into a sequence of control signals that the CU applies to the data path to implement a sequence of register-transfer level operations... Hardwired control units are implemented through use of combinational logic units, featuring a finite number of gates that can generate specific results based on the instructions that were used to invoke those responses. Hardwired control units are generally faster than microprogrammed designs... The algorithm for the microprogram control unit is usually specified by flowchart description.

It is said that the control unit is what actually reads instructions from memory and runs them. But I'm wondering how exactly this works. Maybe not specifically the circuits because that seems highly dependent. But at a high level, what is the "spark" that actually is moving around electronically. What types of circuits there are involved. Whereas disk storage has a very detailed description (below), CU's don't (on Wikipedia).

My questions are:

  1. On a modern computer like the MacBook Pro, if the CU is hardwired or a microprogram.
  2. What is the actual spark or piece of electricity that is doing the "processing", i.e. "moving around the memory". How it actually "fetches from memory" and "stores to memory" and "fetches an instruction" and "executes an instruction". How it "reads an opcode", etc.. Wondering what is actually going on at the electronics level. Don't need to know each piece in detail if it's too complicated, just at a high level the electronics involved of any one of them.

While flip-flops have a detailed description so you can understand how actually a "bit" is stored, the CU is lacking so I can't actually tell how the program is "running". I would like to be able to explain how the computer runs, at a deeper level than that instruction cycle, down to the electronics.


Magnetic disk storage demo of how detailed the description is, to show you how it works.

...Due to the polycrystalline nature of the magnetic material each of these magnetic regions is composed of a few hundred magnetic grains. Magnetic grains are typically 10 nm in size and each form a single true magnetic domain. Each magnetic region in total forms a magnetic dipole which generates a magnetic field....

\$\endgroup\$
  • \$\begingroup\$ Are you familiar with the OSI model? \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Jun 9 '18 at 2:03
  • \$\begingroup\$ No I haven't heard of that. \$\endgroup\$ – Lance Pollard Jun 9 '18 at 2:11
  • \$\begingroup\$ When read that, it will define how the design supports 7 layers of communication without the nuts and bolts \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Jun 9 '18 at 3:48
2
\$\begingroup\$

If you understand how a flip-flop (FF) works, the rest might be more understandable.

As Wikipedia states, a CU, or "control unit", is "digital circuitry contained within the processor that coordinates the sequence of data movements into, out of, and between a processor's many sub-units". In other words, it is a hard-wired sequencer, a machine that moves from one state to another as external clock ticks.

The CU is a collection of FFs with combinatorial logic wrapped around, which forms so-called "finite state machine". A set of FFs defines the states of this sequencer, each binary value defines a state. Different states of CU result in different actions for associated "sub-units", and define the next state.

As soon as the external hardware reset ends, the sequencer starts moving along a pre-defined sequence with each clock tick. Roughly speaking, the first state is to generate a signal to memory controller to "fetch" the very first instruction from a pre-defined memory location. This memory must contain a meaningful code sequence pre-loaded there somehow.

Then the CU waits for the memory controller (one of its "sub-units") to deliver the first instruction. The instruction is fetched into another set of FFs called "register", and is fed into another "sub-unit" called "instruction decoder". Depending on results of decoding, the CU proceeds with appropriate actions by moving to appropriate "next state", like instructing the same memory unit to fetch another argument from memory, or storing the result.

The above is just a basic idea. In reality everything is much-much more complicated. The Internet, however, should have plenty of animations for basic CPU behavior, like this video. This link might give you a better hint how the basic sequencer works.

Regarding whether a CU is "hardwired" or "microcoded", details of sequencer implementation are inconsequential. Typically the core of CU is "hardwired", but certain functions can be controlled by "microcode", and can be modified via "CPU patch".

\$\endgroup\$
  • \$\begingroup\$ Wondering if you could go into more detail on "Depending on results of decoding, the CU proceeds with appropriate actions by moving to appropriate "next state"". Wondering how the shift to the next state works at the electronics level. \$\endgroup\$ – Lance Pollard Jun 9 '18 at 2:59
  • \$\begingroup\$ @LancePollard, it is not a "shift" to the next state. FSM always has "current state" and "next state". The bit value of "next state" is assigned on next clock edge depending "current state" and the results of operand's decoding, just like in CASE{} statement. The flip-flops in "next state" assume certain value, and "current state" is loaded with "next state", and so on. You might want to take a look at Verilog, which describes transfer of bits at register (FFs) level, or RTL, see example here courses.cs.washington.edu/courses/cse370/99sp/sections/may18/… \$\endgroup\$ – Ale..chenski Jun 9 '18 at 3:49
4
\$\begingroup\$

As a software developer, you understand and apply abstraction and encapsulation. A control unit (CU) is just an abstraction for handling sequential execution and making decisions. You know that Javascript is completely emulated by software and has a software CU. The Javascript CU steps through an array of instructions (i.e., your program) and executes them. The Javascript CU has a concept of "current instruction", which is just an index into the array of instructions. Equivalently, an electrical CU has an instruction pointer register (a bunch of flip-flops) which stores the address of the next instruction. The Javascript CU makes decisions based on variables. An electronic CU uses a fixed number of registers for its variables.

Register values change with each clock cycle. Everyday computers are synchronous and everything changes with the clock: memory is fetched, the instruction pointer is changed, etc. To make a decision, the CU chooses what the next address should be and that address is loaded into the instruction pointer for the next clock cycle. The electronic mechanism of choice can be as simple as a single NAND gate. And now we're down at the electronic level. You can do a lot with NAND gates. Interestingly, you can build a whole computer out of them.

An example of a simple CU is an alarm clock. One register is for the alarm time. One register is a counter for the current time. The clock increments the current time. We use logic gates to compare the registers. An AND gate is &&. An OR gate is ||. An inverter is "!". Just write the logic equation yourself and you have basically wired the comparison. When the comparison is 1, the alarm rings. This very simple CU had to make a decision and the needed electronics exactly matched what you might program.

The fascinating thing about software is that everything can be turned into hardware. A neural net cat be software or hardware. At this point your own curiosity should be your guide. Feel free to search for any concept you can think and search "circuit for X". Try this now. Look for "circuit for comparing". You don't need a book.

NOTE: Although NAND is computationally complete, for clarity I've introduced AND gates, OR gates and inverters. You can also use NOR gates. When I learned this, it unlocked everything.

\$\endgroup\$
  • \$\begingroup\$ I was aware of what you're saying, maybe if you could go into more detail about the last sentence of p1, "An electronic CU uses a fixed number of registers for its variables". I would like to know in more detail how the electronics work for going through a sequence, or perhaps a resource where I should find more. \$\endgroup\$ – Lance Pollard Jun 9 '18 at 2:55
  • 1
    \$\begingroup\$ @LancePollard I added an example. Hope that helps! :D \$\endgroup\$ – OyaMist Jun 9 '18 at 5:40
  • \$\begingroup\$ You're welcome. I've added another paragraph that describes why I think the equivalence of software and hardware is magic. "Lumos!" --Harry Potter \$\endgroup\$ – OyaMist Jun 9 '18 at 12:38
1
\$\begingroup\$

There is plenty of detailed information on the working of CPUs, from the classic books by Henessey and Patterson to the DIY of the home-brew CPU web-ring.

For your understanding you should probably study (finite-) state machines.

\$\endgroup\$
  • 1
    \$\begingroup\$ I have studied finite state machines but they don't talk about electronics. \$\endgroup\$ – Lance Pollard Jun 8 '18 at 22:40
  • \$\begingroup\$ Maybe if you could link to the resource for the web-ring CU that might be helpful, I am new to electronics. \$\endgroup\$ – Lance Pollard Jun 8 '18 at 22:41
1
\$\begingroup\$

The key to all CPU's and MPU's working properly is a 4-phase clock derived from the master clock. It creates a repeating 4-phase step: Fetch, Decode, Execute, and Store/Write-back. This sequence is fundamental to the organizing and implementation of instructions as micro-code.

Extended address modes may cause it to run twice to complete a single instruction, and some have 'wait' states to read or write to slow devices on the board.

During "fetch" a check for interrupts or a reset command is done. If so either the next instruction is saved to a stack, or all registers and stack are cleared.

Decode is where the rubber meets the road. The 16/24 or 40 bit instruction is decoded by firmware that cannot be edited. It decodes these into 100 or more control bits to steer data to/from the ALU and address unit, and external reads and writes. That would be the "Execute" part.

Store also updates the status register with ALU results, and write data back to the ALU for continuous math operations.

That's the short story. There are many old books about "micro-code", and how it is used.

\$\endgroup\$
  • \$\begingroup\$ "The 16/24 or 40 bit instruction is decoded by firmware that cannot be edited." Wondering if you could go into more detail about the electronics of it or point to a resource. I would like to know specifically how the circuits are implemented. \$\endgroup\$ – Lance Pollard Jun 9 '18 at 2:53
  • \$\begingroup\$ A very good book to read is a 1985 printing on the Motorola MC68000 Microprocessor family, published by Motorola. Written by Thomas L Harman and Barbara Lawson. Fine details. \$\endgroup\$ – Sparky256 Jun 9 '18 at 3:32
  • \$\begingroup\$ @LancePollard. Do not mean to sound brash. This is like a ROM chip at the core of the CPU and already has 'perfect' coding. If it fails you throw the CPU away. This is more primitive than BIOS (which can be upgraded), but in a way much more important to be perfect. \$\endgroup\$ – Sparky256 Jun 9 '18 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.