Microprocessors

You can’t get very far up the ladder in the Slot Department without getting exposed to microprocessors. This world is full of phrases that are a foreign language to many of us before we came here. The younger generation that grew up with this world is exposed to it at an early age, and many phrases and concepts have crept into their culture. (“You’re a nice guy, NOT!” “Byte Me!” “You’re such a zero!”) Those who grew up with it have little trouble grasping it. Some of us grew up with it when it was growing up. Some of us have been around it since the time when the only way you could have a home computer was to build it (pre-microprocessor, bit-slice era). Yea, I’m that old.

The microprocessor world has grown up with few standards of definitions. Since we work in the Gaming Industry, I will try to keep the definitions appropriate to this industry, straying only when necessary to explain popular confusions.

This paper dwells on the 8032 microprocessor, specifically, that is used in the Telpar Printer Control Board talked about in a previous article. This same 8032 is used by IGT in the S-Plus slot machines, and Player’s Edge Video games. The popularity of these devices makes it worthwhile learning this one, if you only learn one in your life.

Definitions

ALU – Arithmetic and Logic Unit. This is the part of the CPU that actually does arithmetic or logical operations on data.

CPU – Central processing Unit. A major portion of the microprocessor that contains the ALU, registers, instruction decoding and program control functions.

MPU – Micro Processing Unit. A larger portion of the microprocessor that includes the CPU, memory and I/O functions. This may be included on one board, or may be an assembly made of many boards. In smaller embedded microprocessor applications, all of these functions may reside on one chip.

Memory – An area where large quantities of data are stored. This may include any place data is stored (RAM, EPROM, disk, tape or cartridge).

RAM – Random Access Memory. Normally a place to store data. In Personal Computers it is also used to store programs. In most systems this is Static RAM chips on the board. In smaller microprocessors it may even be included inside the microprocessor. In personal computers, which use large RAM areas, it is chips or boards on the motherboard.

Program Memory – An area of memory used to store programs (sequences of instructions). In embedded microprocessor applications this is usually ROM or EPROM chips. In smaller microprocessors it may even reside inside the microprocessor, itself, but it is still ROM or EPROM of some sort.

Embedded microprocessor – A microprocessor in an application with no readily accessible user interface. Hopper control boards, Coin Comparators, Coin-In optics assemblies, or such are excellent examples. A Microwave, a cell phone, or a game, may be an example of an embedded microprocessor with a limited user interface. A personal computer would not qualify.

Data memory – The area of memory where data is stored, usually Static RAM in the circuits we see in the gaming industry.

Fetch – A memory reference that loads an instruction in from program memory. The address lines select an address and memory chip. A read-like operation is performed, but instead of using the information as data, it is loaded into the Instruction Register, and is executed as an instruction.

Register – An array of flip-flops with common clock and reset inputs used for a common purpose.

Byte – Eight bits used as one value.

Bit – A single binary digit. It is usually only in one of two possible states, 1 or 0. Normally this is 1 = a high voltage (some positive value), and 0 = a voltage close to ground. Keep in mind that this is not always the case.

Nibble – Four bits used as one value.

Port – A group of I/O lines to move information in or out of the microprocessor.

Word – A number of bits used as one value that is whatever the CPU is designed to handle. Usually this is 16-bits, with 32-bits called a double word, and 64-bits called a quad word. The definition varies depending on the industry you are in. In mainframe size systems (supercomputers) a word is 256-bits, because that is what the CPU is capable of handling at one time.

Accumulator – A register that holds the value of the output of the ALU.

PSW – Processor Status Word. A register that is an accumulation of signals in the CPU that is an easy place to reference the status of the CPU.

Instruction Register – A register that holds the instruction being executed.

Control Section – The section of the CPU that decodes the Instruction Register and derives enable lines to make the instruction perform a specific function.

Program Counter – A register that keeps track of where in Program Memory the next instruction will come from.

Address – A location of a place in memory for an instruction or data, or a location of an I/O device.

I/O – Input / Output. Circuitry that interfaces the real world to the microprocessor. Inputs are sources of information coming into the microprocessor (switches, sensors, for example). Outputs are circuits that the microprocessor can control (lamps, coils, or motors, for example). Many devices have characteristics of both. A hopper has Outputs (motors), and Inputs (Hopper Level Probe, Coin-Out Switch).

Microprocessor – A single chip that contains all the circuitry to make a CPU.

Microcomputer – A single chip that contains all the circuitry to make an MPU (CPU, RAM, Program Memory, I/O, and a peripheral, or two).

Peripheral – Circuits, separate from the CPU, which perform major functions (Communications, Time Keeping, and such).

Interrupts – A signal that, by design of the system, is used to temporarily halt normal program execution, perform a special task, then allow the normal execution to continue. (See RTC for an example.) Some Interrupts may be controlled (allowed, or not allowed) under program control. These are called Maskable Interrupts, after the software process of enabling and disabling the interrupts. Other Interrupts have a higher priority and force execution of a special routine that the designers determined is urgent. These are Non-Maskable Interrupts (NMI). The gaming industry, almost religiously, uses NMI to warn the game of an impending power loss.

Reset – A signal that forces the system into a known state, and causes program execution to restart at a specific address in program space. This is hard-wired into the design of the microprocessor. For instance, in most Intel devices Reset clears all registers and causes execution to begin at address 0000. (Yes, I know that is a generalism. There are exceptions.) When power first gets applied to such a microprocessor it will start execution at address 0000, and perform certain tasks, predictably.

Restart – A Restart is similar to an interrupt in function. Pulling on a Restart line, or executing a Restart Instruction, will halt execution of the present program and begin a new routine at a specific address. The address depends on which Restart was executed. After completing that routine, program control continues from where it was before it was interrupted.

RTC – Real Time Clock – A circuit that keeps track of time, as referenced to the human world. The circuit may just give out clock pulses at a given rate (once a second), and the microprocessor gets interrupted once a second to update the time (values stored in data memory that represent what time it is).

The signal goes to an Interrupt line of the microprocessor. The Interrupt disrupts normal program flow, invoking a routine in program memory which updates data values stored in RAM that represent time. After the task is complete, program flow continues where it left off.

Arithmetic and Logic Unit

(See the drawing labeled document number “ALU”.) The Arithmetic and Logic Unit (ALU) is the center of the computer where the primary mathematic and logic operations are done on data. When you hear about a microprocessor being an 8-bit, 16-bit, or 32-bit processor, they are referring to how many bits wide the ALU is. An 8-bit processor can only manipulate 8-bits of data at a time in the ALU. It can Add two 8-bit numbers together (or other mathematical operations), or it can perform a “bit-by-bit logical OR” operation between two 8-bit words (or other logical operations).

In most microprocessors an Internal Bus carries data around inside the processor. All data comes from one register, gets put on the bus, and is transferred to some other register. A single instruction may be such a simple transfer, or may cause a sequence of transfers that perform a more complex function.

For instance an instruction that adds the contents of a register to the contents of some memory address has to break the instruction down into a sequence of steps like the following:

1.Reference the memory address and read the contents of that address into one of the Temporary registers (TMP1).

2.Reference the register to be added to the value that is in TMP1, put that in TMP2, and do an ADD operation.

3.The ALU places the result of the ADD on the Internal Bus, and loads in into the Accumulator.

The Processor Status Word (PSW) is a register than monitors various conditions in the result of the operation. Its inputs come from circuits that sense conditions like:

1.Is the result equal to zero?

2.Is the result a positive number?

3.Is the result a negative number?

4.Are TMP1 and TMP2 of equal value?

5.Is TMP1 greater than TMP2?

6.Did the last mathematical operation generate a Carry?

The PSW can be used by subsequent instructions to decide what will be done next. The example shown is typical for most microprocessors. In covering the MCS-15 family (8032, 8751, and such) we will describe what goes on in the core of almost all microprocessors used in the gaming industry.

There are various other registers in the microprocessor. Some have specific purposes. Some have general use and are manipulated by the program.

B-Register – The B-Register is a special register that can be used to store information, and use it with various instructions that reference the B-Register.

Stack Pointer – Stack is an area of RAM, or in some cases separate memory, that keeps track of where program control came from when it execute exception sequences (Interrupts, Restarts, and such).

Normally a program is being executed in sequential addresses in memory. At the end of each instruction the Control circuit evaluates various conditions and determines what the next operation to be done is. Unless something happens, the next instruction in memory is executed.

If an Interrupt line is pulled active, Control evaluates priorities for execution. If the interrupt requesting control has a higher priority than the current program, program flow is interrupted (the Exception Sequence). The current contents of the Program Counter is stored in the Stack, followed by the PSW. This is called a Push Operation.

Program execution then proceeds to process the interrupt, executing a routine written for that purpose. After that routine is completed it exits by executing a Return From Interrupt instruction. This pulls the contents of Stack back off and re-establishes the PSW and Program Counter, as they were before the Interrupt was done. Pulling out the contents of Stack is called a Pop Operation.

Data Pointer – The Data Pointer (DPTR) is a register that holds the address of a place in memory where data will be read from, or wrote to. In order to read data from memory, we must put the address we want to reference into the DPTR, then execute an instruction that reads data from memory. If we are reading sequential bytes of information from RAM, we load the data pointer with the address of the first byte to reference, read the data, increment the data pointer, read the data, increment the data pointer, …

Multiplexing – Using a line for more than one purpose, or putting more than one signal on a single line. Timing is where all the magic is done. In the 8032 for example, the lines of Port 0 have two uses. While ALE (Address Latch Enable) is high, Port 0 contains the lower eight address lines for external circuits. When ALE is low, Port 0 doubles as the 8-bit data bus for transferring information in and out of the 8032. An external latch with a negative edge clock is used to latch the outputs of Port 0 on the trailing edge of ALE, latching the lower address bits in the latch.

The MCS-51 engine

Now that we have a few definitions and concepts down, let us take a look at the 8032, and other members of the MCS-51 family. Originally, this was made by Intel, but has been Second-Sourced by dozens of companies.

The 8051 has internal program memory and data memory. The pinout of the 40-pin package includes four 8-bit ports. The instructions reference these ports, and you can write to, or read from, various ports under program control. Most instructions that manipulate data move information between some register and a selected port (Port 1, 2, 3, or 4).

Using the microcomputer in this mode, you can create an embedded microprocessor design with few extra parts other than the microprocessor itself. Everything that is needed to make a microprocessor-based design is included inside the chip. RAM, ROM, or EPROM, Peripheral devices, if you want it, it’s in there.

This is the Internal Mode of operation. The 8051 is not limited to just this mode. An input, named External Access, can be pulled low, putting the 8051 in the External Mode of operation. In this mode, the purpose of some of the ports become Address and Data lines, and the microcomputer becomes a microprocessor. RAM and EPROM are off-the-chip.

The 8032 lacks internal program memory, and must be used in the External mode. With sixteen address lines, the 8032 can directly reference up to 64K (65,536) addresses of external data memory. Using different control lines, it cam also reference up to 64K of external Program memory. References to Program space are done using the PSEN* (Program Strobe Enable, active low) output line. See any schematic using the 8032. Data memory is referenced using RD* and WR* (Read, active low; and Write, active low) lines. Since program memory is EPROM, we can only read information from it. There is no need for a Write line referencing program memory.

The 8751 is an 8051-like device that has EPROM for Program Memory. It has a window, like an EPROM, and the program can be erased and reprogrammed, just like an EPROM.

Any member of the 8051, or 8751, style of devices can be made to work in the External Mode, using the EA line. These can usually be picked up on the surplus market cheaper than peanuts, or may be salvaged from old equipment. Pulling the EA line low just makes the CPU ignore the fact that the device has internal memory.

Other manufacturers make MCS-51 compatible devices that have Flash ROM as the Program Memory. These can be reprogrammed like EEPROMs. Others use the basic MCS-51 engine with only a few I/O lines, and package it in a small DIP package. We see these in use in the gaming industry also. The Flash Programmable Erasable Read Only Memory (PEROM) has a limited number of Write/Erase cycles. The book (Atmel, AT89C51) says that they can only be erased and re-wrote one thousand times. All EEPROM type devices have a limitation on write cycles to some degree.

Instruction set

One good way of getting the grasp of what a microprocessor does is to take a close look at what the instruction set is capable of. Let’s look at a few of the simpler instructions, and describe what they do. The Assembly Code is what the programmer actually writes, using any standard text editor. A program called an Assembler is ran, referencing the name of this file as the input file, and creates another file, the Object Code, which is what the microprocessor actually executes after it is stored into an EPROM. To keep it simple at this point, we will talk about only the Assembly code, and what it accomplishes.

Assembly CodeOperation performed

INC AIncrement A – Increments the Accumulator. TMP1 is loaded with the value “01”. The Accumulator is enabled to pass through TMP2, and the ALU does an Addition operation, adding TMP1 and TMP2. At the end of the process the result is loaded back into the Accumulator. It takes about twelve clock pulses to accomplish this operation.