• Please review our updated Terms and Rules here

How I would describe a CPU to someone without ASM knowledge

per

Veteran Member
Joined
Jan 21, 2008
Messages
3,052
Location
Western Norway
One of the most fundamental things in assmebly programming is to know how the CPU works. Many people don't know this, and any beginners in assmebly programming should start with this point.

There are several ways to explain it. Of course you have the general way, like it is explained in any thechnical referance. This may be quite accurate, but it may be rather difficult to understand for people compleetely without any previous knowledge on the field.

The other wat to explain it is more "general", and is basically not bound to any spesific CPU since most CPU's generally works in quite similar ways. How this explanation works is that it explains the workings of a CPU by illustrating a similar scenario from the real world. The point is to think about the CPU as a clerk and the memory as a huge library of index cards. I may not be the best person to describe it, but a book I got describes it rather well in the eyes of a beginner. I may get far to detailed, so please excuse me if I do.

The scenario:
The clerk is sitting by a table in front of the index-card library. On his desk are some boxes (there is one index card in each box), a pencil, an ereaser (or eventually unused index-cards), a book, and an intercom central. There is also a firealarm on the wall.

Now, imagine that the clerk takes an index-card from the library (he can only hold one card from the library at a time). This index-card contains a value, and the value corresponds to a command. Therefore the clerk looks up the value in the book, and the book explains what the clerk must do. Sometimes the clerk have to take several of the following index cards before he can be certain (but remember that he still only can hold one at a time so he has to put the card he has read back before taking a new one). After doing an command, he will keep taking new cards where he left off, unless the previous command stated that he should start taking cards from a different location.

Then he does the action described by the command. This action is usually standard clerk-based tasks, like:
  • Write a new value on a card
  • Copy the value of one card to another card
  • Manipulate the value of a card
  • Swap two cards
  • Start to take cards from a different location
  • Start to take cards from a different location only if...
  • Send a value over the intercom
  • Listen to an incoming value over the intercom
  • Wait for an incoming request over the intercom
  • Turn on/off request indicators on the intercom
Since the clerk can only hold one card from the library at a time, he has to copy it to one of the cards in one of the boxes on the table if he needs to work with several values.


Additional stuff added to better represent x86 class CPU's:
Sometimes he is also instructed to move the desk, because he doesn't have long enough arms to reach the whole library from one place (AKA: segementation).

Last, if the fire-alarm goes off, he is instructed to start taking cards from one known location. It is intended that those commands should make the clerk read out the entire library over the intercom as fast as possible (AKA: NMI).
 

Attachments

  • CPU.JPG
    CPU.JPG
    34.1 KB · Views: 1
Last edited:
Woops, forgot much of the explanation:
  • Library = Memory (RAM/ROM/etc...)
  • Part of library reachable from the desk = Segment
  • Desk = BiU (Bus interface Unit)
  • Clerk = EU (Execution Unit)
  • Boxes = Registers
  • Intercom = I/O, interrupts, misc. handshaking
  • Book = Instruction set
  • Fire-alarm = NMI (Non-Maskable Interrupt)

DMA would have appeard as a slave clerk with only an intercom without request indicators, which task would have been to just take a series of cards and read out over the limited intercom, or write down a series of values received from the limited intercom on a series of cards.

A 8087 math coprocessor would appear as an additional clerk working on the same desk as the main clerk, but with his own book and his own special boxes that store lots of cards. The main clerk passes commands to this additional clerk if the command says so.
 
This is how Sune Windisch (illustrated by Göran Wikhäll) described the 6502 addressing modes in his book "Assembler på VIC", (c) 1982.
 
That's a good explanation.

A book I liked which I thought explained it pretty well was Assembly Language Step-By-Step It's a beginner book but I really enjoyed it after sifting through lots of other books who unfortunately dive right into assembly without a beginner orientation. Although I knew chunks of various languages already assembly wasn't clicking like I was hoping so this book had a very nice intro to commands and the carry flag, etc with simple examples using a fake intro language. Normally I dislike that method but for whatever reason assembly was quite different and knowing the processors architecture was a newer thing for me. In basic I just told it what to do and it did it for me, Pascal, I told it to do things and stop doing things but still mostly done for me. Assembly, you tell it everything to do then tell it to do it (macro assembly is certainly a good word for it) as it's still mostly running already made functions (bios or OS interrupts).

I simplified the processor much more to a person once who commented how easy it was to understand but that was more electrical understanding I was somewhat explaining (to the best of my knowledge at the time also). So it was more of just thinking of it as a bunch of latches or a grid between all the pins. So the processor when it needs to send data from pin 1 to 5 it opens up the gates to create that path from pin 1 to pin 5 and the voltage can flow or interact with that path.

Is this something you're having to explain for a reason? Was just curious.

- John
 
The book I am talking about is the IBM PC from the inside-out. I have the revised edition from 1986, which is only around 500 pages and only includes the original PC and AT, but it really gives you a good introduction to ASM. Unlike many other books, this books explains much more about the actual hardware of the PC compared to what it explains about assembly language, but it explains the fundamentals in ASM really well. It was from this book my explanation above derived from. A more recent version of the book with around 800 pages were published in 1994, but I haven't read that one so I can't tell how that is.

The reason I explained it is because I was curious how good an explanation it actually is, or if I went into too much details... The one in the book was way simpler.
 
Back
Top