Zilog Z80 Deep Dive - How does it work?

preview_player
Показать описание

Let's go right inside a CPU and watch it execute code at the transistor level!

As a programmer I have often wondered exactly what the CPU is doing when I give it some code. Being a computer science teacher I know all about the fetch-execute cycle and what is supposed to be inside a CPU but what it actually does is glossed over.

So I set about finding out using the Visual6502 project's simulation of the Zilog Z80. This is not an emulator of the chip like you might be used to. This simulates the actual physical layout of the chip down to the wiring and transistors.

It's possible to step through the chip's sequencing logic and watch parts of it switch on and off. It's completely fascinating. And once you figure out what's going on, it's possible to watch the CPU work.

This deep dive into the inner workings of the Z80 was inspired by one of my students asking me the innocent question of "how does a CPU work?" and then being persistent in wanting to know what it actually does.

I had no idea and I had to find out. This video is the result.

Video Title: Zilog Z80 Deep Dive - How's it actually work a the transistor level?
Рекомендации по теме
Комментарии
Автор

perhaps you'd be interested to know that, in trouble shooting odd defects in chips, we do something quite similar to the software you have shown, but do it in reality. If the chip is in a package, the package is removed as well as the upper parts of the chip so as to expose the actual circuitry. the circuits that are suspected to be involved "wired up" and powered with instructions to match the failure conditions.A camera is used capture photon emissions and you can actually SEE the transistors turning on and off.

johnforguites
Автор

Well done. I asked the same question for 30 years. I finally understood when watching Ben Eaters excellent video series "SAP-1" breadboard computer.

thek
Автор

I'm a chip engineer and I have to say, it's sometimes hard for even us to answer that question. We all specialize so far into our specific parts of a CPU that we may not know how a whole thing works. I did my PhD on ways to optimize active interposer design, which is basically a chip you put other chips on top of to allow them to talk together. Think about a Vega64 or Radeon VII. Those have passive interposers, just a bunch of tiny wires through a hunk of silicon to connect memory to the GPU. My work was on effective ways to implement some logic into that chip, like moving the memory controller down there, or the PCIE bus, or maybe a huge chunk of SRAM for a cache.

I actually work on CPUs, not GPUs, but most people are more familiar with the Vega64 or VII than they are with Intel's Lakefield, which is actually something I worked on. I do regret the awful performance of those chips. A single Sunny Cove core with no hyperthreading paired with 4 old atom cores was never destined for greatness. Up next for me was the bridge dies in Sapphire Rapids, and now the topic of my PhD itself becomes a product in Meteor Lake. The architects make it all work inside, I'm just a glorified electrician wiring shit together.

DigitalJedi
Автор

I've been hand assembling machine since 1980: Z-80a, 6502 and x86. decoding the instructions and actually performing the movement of bits, this is a great question. I always thought the bit pattern in each instruction perhaps had something to do with the decoding. This is a great video. Thank You!

kevinrickey
Автор

Might be worth mentioning, when you jump from 4004 to Z80. Those are related chips. The 4004 begot the 8008, the 8008 begot the 8080, the 8080 begot the Z80. All within a very very short period of time.

RetroAnachronist
Автор

Z80 is amazing! I had a MSX back in the day. Thanks for your videos!

drogokhan
Автор

Us old timers call that, level of CPU function, parsing the Micro Code. Coding to emulate real or fantasy micro code was a favorite assignment of mine. Bare metal programming today is close but not quite the Micro Code level. Great video, really liked the dynamic operation footage. I didn't get rich but I've loved every moment of working in our digital world.

bitse
Автор

Now I know why I’m a subscriber. One of the best videos I’ve ever watched on YouTube. Bravo maestro.

pic
Автор

This was absolutely fantastic. I'm currently trying to teach myself Z80 Assembly as a hobby, many, many years after playing about with Basic as a kid in the 80s. This video has really helped turn the abstract concept of what's going on into a real visual way of seeing it happen. Superb. 😎👍

Wilberon_McBane
Автор

Amazing! This is really amazing. I've been wanting to take a deep dive into the Z80 for quite some time now.

petermasse
Автор

I've not watched your channel for a few months and I love the progress you've made with editing and sound and script. Really informative. Kids at school are very lucky to have you as their teacher.

Roy-kfgv
Автор

1:35 I don't know about anyone else, but to me there's just something beautiful about seeing the raw silicon of an IC, especially a CPU. And I mean that in the same way that I can see beauty in some pieces of art, purely aesthetically.

8:44 "does stuff, and give outputs in a predictable and noble way"

"Noble way" That makes me smile.

DefaultFlame
Автор

Programmers that actually KNOW (I mean like an engineer) how a cpu works are rare, let alone programmers have an idea what CPU instructions actually are. Many programmers don't even know in to string and visa versa is actually ....I WEEP FOR THE

stevenbliss
Автор

Thank you and your student so much! This question has been haunting me literally for decades. I really enjoy the answer and your presentation - you have one subscriber more 👍 Greetings from Germany 🙂

mwienzek
Автор

10:36 Nothing says "I am not an electrical engineeer." as almost spilling some welding wire randomly in a PC motherboard for no reason at all. =) That made me pretty anxious and then I just started laughing XD

rulojuka
Автор

Love these informational CPU videos. More please :D

RetroGren
Автор

The inner workings of a Z80 CPU are registers, ROM and functional units (like the ALU (Arithmetic Logic Unit), memory unit etc). The CPU first loads an instruction into the instruction register, which connects to ROM. The ROM is also connected to a step counter, which is reset at the start of each instruction. Each step in the ROM is a list of signals to send to parts of the chip (e.g. use the memory unit to fetch the next byte of the instruction, then store the result in a register). The last step of each sequence in the ROM is to load the next instruction into the instruction register and the cycle repeats.

All CPUs come down to the basic building blocks of logic (AND, OR, NOT), implemented in transistors, wired together and sequenced by the clock. Just like normal programming you break the task down into components, sub components etc, and build each part from simpler parts connected together to achieve the required effect. A register for example is made from a bunch of Flip-Flop units, a Flip-Flop (at its simplest) is made from a couple of NOR gates (that is OR gates with their outputs NOT’ed). The difference with normal programming is that many things happen in parallel (so you can be fetching something from memory, moving the contents of one register to another and adding two registers together at the same time for example).

If you’re interested at that kind of level then take a look at FPGAs, which are basically a bunch of uncommitted logic that your program can wire up any way that you like. You can implement a Z80, 6502, RISC-V etc, or even your own CPU design on them by defining the logic for each unit and how they are wired together. There’s also code available on the web for implementations of the above CPUs, so (once you learn to read the language used - typically Verilog or VHDL) you can see what is happening.

stevetodd
Автор

Wow. Thank you for a masterclass into the inner workings of the Z80! Instant subscriber!

I had so much fun back in the 80s writing a lot of Z80 assembler. This is the deepest I’ve ever looked into its inner workings though.

stevef.
Автор

When i studied this at uni before we even looked at assembly and CPU architectures we build a finite state machine using an EEPROM. Learning how you can use a computer or dip switches to control the address bus and then control outputs attached to the data bus. Then if you got more advanced and had clicking you could take bits from the data bus and feed them back to the address bus and you've got a hardware finite state machine. Which as we found out later on is how you build an instruction decoder. Of course it seemed pointless in first year. Anyway I'm glad I learnt all of this. Helps me understand what the CPU vendors are talking about they talk about branch prediction, out of order execution and super scalar design. Also makes me appreciate just how much work goes into a compiler.

vkfbab
Автор

I was until recently quite ignorant of how computer hardware really works. Videos like this really help understanding this fascinating subject.Amazing content, keep it up

perthDev
join shbcf.ru