41
MICROCOMPUTER CONCEPTS

chapter 12.doc · Web viewdata on the data bus. The data is then read and utilized by the microprocessor

  • Upload
    vannga

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

MICROCOMPUTERCONCEPTS

The first step in understanding microcomputers is under -standing computer terminology, concepts, and methods. This chapter lays a basic foundation of computer fundamentals so that the student will be prepared for more advanced concepts in other courses.

12.0 INTRODUCTION

Upon completion of this chapter you should be able to:

• Define microcomputer in relation to mainframes andminicomputers.

• Understand the basic organization of a microcomputer.

• Explain how microcomputers are programmed.

• Understand the basics of microcomputer interfacing.

12.1 OBJECTIVES

12.2 WHAT IS A MICROCOMPUTER?

A microcomputer is a small, versatile computer that is generally used in process control, robotic, military, and specific industrial applications. Microcomputers usually have limited data entry and display capabilities. Some microcomputers use very little power, which makes them ideal for battery operation.

To understand where the microcomputer fits into the computer family tree, see Figure 12-1.

As shown in Figure 12-1, the mainframe is the largest and most powerful member of the computer family. Mainframes are used in applications where speed and precision are very important and size and power consumption are of much lesser concern. Mainframes are typically used by such organizations as NASA, universities, and the government to store and process large amounts of data. The miniframe is a scaled-down version of the mainframe. The miniframe is generally used in smaller businesses and at multi-user workstations that do not require extensive speed or memory capabilities. The miniframe is slightly less powerful than the mainframe and much smaller. The miniframe is generally used in applications where storage space, speed, and cost are important.

The microcomputer is the next lower step in performance from the miniframe. One might wonder why the microcomputer has become so popular over the years in light of the superior speed and storage capabilities of the mainframe and miniframe. One reason is the performance/cost ratio. Microcomputers are very inexpensive when compared to the mainframe or miniframe. It is possible to have many single-

user microcomputer systems, rather than a single minicomputer with multiple users for the same cost. Another reason for the popularity of microcomputers is inherent flexibility. Micro-computers are, for the most part, constructed on a single circuit-board, whereas main and miniframes are big and usually consist of a chassis with several highly-specialized circuit boards to perform computer functions. It is easily understood why microprocessors have found their way into small, portable computer systems and many military, and industrial ap -plications.

The microcontroller is a step lower in performance than the microcomputer. The microcontroller is designed for a specific control-oriented application. Microcontrollers are typ-ically found in modern appliances and cars where semi-intelligent, adaptable control is desired. Microcontrollers usually have just enough speed and storage capabilites to meet a specific requirement in order to keep costs down.

Figure 12-1 shows the computer heirarchy. The student should realize that, as with most definitions, gray areas exist. There are some miniframes that approach performance levels of mainframes and so forth. Advancements in technology are largely responsible for producing gray areas of performance standards.

Now that the microcomputer has been located in the computer family, the basic workings of the microcomputer can be examined. This section introduces major subsystems that are common to virtually every microcomputer system. Figure 12-2 shows the organization of a generalized microcomputer.

Until approximately the mid-sixties computers did not use bus structures to transfer information. Prior to the mid-sixties computers had no defined data, address, or control paths and often these signals shared common lines. Today's com-

12.2.0Organization of the Microcomputer

puters, particularly microcomputers, use what is called a bus structure to transfer data, address, and control information. As shown in Figure 12-2, three buses (address, control and data) are common between all devices of the microcomputer. Buses are pre-defined electrical paths of communications between devices in the microcomputer.

The address originates from the microprocessor to select a particular device, via the address bus, to read information from or to write information to. The data bus transfers information between the microprocessor and other devices on the data bus. The control bus qualifies a data transfer as either to (read) or from (write) the microprocessor.

If, for example, data is to be a read from the RAM (random access or read/write memory) to the microprocessor, the address bus supplies the RAM address where the data is stored. The control bus "tells" the RAM with specialized logic-enable signals that data, specified by the address bus, is to be read by the microprocessor. The RAM responds by placing the appropriate

data on the data bus. The data is then read and utilized by the microprocessor.

The microprocessor is the heart of the microcomputer. Microprocessors continually read, process, and output data under program control. The microprocessor systematically fetches instructions from memory, then interprets and executes the instructions accordingly. Some instructions require multiple fetches from memory. An add instruction, for example, requires the microprocessor to first read the add instruction, fetch the two arguments to be added, add them, and then store the result. The add instruction, therefore, requires a total of three fetches and therefore is called a three-byte instruction.

As shown in Figure 12-2, the microprocessor can be divided into four primary functional areas: timing, control, arithmetic-logic unit (ALU), and registers.

The timing portion of the microprocessor serves to coordinate all activities of the microprocessor and the micro-computer system. A stable clock oscillator (usually in the low megahertz range) drives sequencing circuitry inside the microprocessor that causes address generation, instruction, fetching, etc. Every operation that takes place inside the microprocessor, and even the entire microcomputer, is synchronized with the clock.

The control portion of the microprocessor uses timing signals to coordinate microcomputer activities. When the microprocessor encounters an instruction in program memory, the control circuitry directs data to the ALU, causes another memory read, or writes data to a port, for example, to complete the instruction encountered as specified. The control portion of a microcomputer generally consists of registers and random logic that run a program internal to the microcomputer called microcode. Microcode is the microprocessors program that is continually running to read and execute commands in external program memory. For a simple instruction, like a port write, the microcode performs the following generalized sequence of events:

1. Fetch the instruction.

2. Perform a series of comparisons to determine that theinstruction is a port write.

3. Obtain the value to be written to the port from the ALU.

4. Generate control and address signals for the port writeopera tionn.

5. Write the value to the designated port.

6. Fetch the next instruction.

It is easy to see that the microcode is a very specific closed loop program that directs the activity of the microprocessor under timing control.

The ALU performs all arithmetic oriented and logic oriented operations of the microprocessor, as specified by timing and control. Some examples of arithmetic operations performed by the ALU are add and subtract (and, in some microprocessors, multiply and divide). An add command executed by the microprocessor involves reading the two values to be added by the control section of the microprocessor. The two values read are sent to the ALU where they are added. The sum is then written to either the ALU's designated holding register (the accumulator) for multiple addition requirements, or to a memory location. The ALU also performs logic related tasks as specified by the microprocessor's control and timing sections. Some examples of logic operations are: inverting the contents of the accumulator, ANDing and ORing two arguments, and other logical comparisons.

Special registers inside the microprocessor hold important memory locations, storage locations, and are also used for temporary storage in calculation during program execution. Listed below are specialized registers that are common to virtually every microcomputer.

PROGRAM COUNTER (PC): The PC register holds the address of the next instruction line to be executed.STACK POINTER (SP): The SP register holds the location of the 'top of the stack.' The stack is a portion of RAM memory set aside for temporary storage of registers and other important information. The stack area is used when the microprocessor is interrupted from regular program operation to service a

subroutine. After the subroutine has been serviced the values on the stack are 'popped off and returned to their original location, regular program operation then continues.

ACCUMULATOR (A): The A register is a register that is used in virtually all arithmatic and data manipulation instructions.

Together, timing, control, ALU, and registers make up the microprocessor which is the central point of activity in the microcomputer.

As shown in Figure 12-2, there are two types of memory used in the microcomputer. Random access memory (RAM) is a non- permanent storage medium in which "random" memory locations in the RAM can be read or written by the microprocessor at any time. RAM is a temporary form of memory and the contents of the RAM are lost when power is removed from the chip. Figure 12-2 shows that the address, control, and data buses interface to the RAM. The address bus supplies the location of the memory location that is accessed. The control bus directs the RAM to supply, from a location specified by the address bus, either data to the data bus (memory read), or accept data from the data bus (memory write). Note that data flow is bidirectional on the data bus. Read only memory (ROM) is s imilar to RAM except that the microprocessor can only perform memory read operations on the ROM, and the ROM is a permanent memory.

ROM contains programs and information that doesn't change, like equation constants or specialized subroutines that read the keyboard and update the display, etc. The control bus to the ROM supplies signals to distinguish between memory and input/output (I/O) access. When the control and address buses have specified a valid ROM location, data is output to the data bus and is read by the microprocessor.

RAM and ROM are vital elements of any microcomputer. RAM provides the user with a changeable storage medium in which programs are developed. ROM ,on the other hand, is transparent to the user and provides the necessary instructions to the microprocessor to operate and interface with the user.

Input/output ports allow the microcomputer to interface 12.2.1 Interfacing

to the outside world through keyboards, disk storage, modems, displays and other devices. Figure 12-2 shows how the I/O port provides an interface between the microcomputer and the outside world. There are two fundamental types of I/O ports: serial and parallel. Both serial and parallel I/O ports utilize the three microcomputer buses shown in Figure 12-2. Most I/O ports are semi-intelligent and therefore require minimal interraction with the microcomputer.

An I/O write, for example, usually requires only that the microcomputer write the appropriate data word to the I/O interface chip(s). The I/O interface chip(s) then performs any control operations necessary to transfer the data to the external device while the microcomputer is free to continue normal operation. An I/O read, on the other hand, usually involves the I/O interface interrupting the microprocessors normal operation. The I/O port is then read in much the same way as a memory device except that the control bus signals an I/O read rather than a memory read.

Figure 12-2 shows some typical peripheral devices connected to the microcomputer's I/O port with data flow direction indicated by the arrows. Peripheral devices provide an interface between the microcomputer and the user. The keyboard allows the user to enter data and key-in programs. The display provides the user with visual information on the status of the microcomputer. Printers provide a hard copy of program or data, etc. Modems allow the user to communicate with other computers. It is easy to see that peripherals are essential to the microcomputer/human interface. Peripherals use either serial port or parallel port data transfer for interface with the outside world. Serial port data transfer implies that data words are sent in sequential parts. Computer data words are broken-down by the microcomputer into individual bits and then sent, by the serial port, over a single electrical transmission line. It is easy to see that serial transmission is inherently slow. Parallel port data transfer is very similar to data transfer that takes place over the microcomputer data bus to a memory location or I/O port. Whole computer words are sent to the parallel port and then over a set of parallel electrical transmission lines. Although parallel port data transfer is much faster than serial data transfer, many more electrical wires are required, increasing both size and cost of the transmission medium.

In order for the microcomputer to communicate with the outside world and peripherals, either parallel or serial data transmission must be used. This section provides a brief introduction to the basic concepts of parallel and serial data transmission techniques.

Parallel data transmission is very similar to 'com-munication' over the data bus between the microprocessor and memory, I/O, etc. In parallel transmission, data is either written-to or read from a port address just as if the port was a memory location. Data written to an I/O port is buff erred and output in whole byte form to an external device. Similarly, data read from an I/O port is buff erred, input to the data bus, and read by the microprocessor. Interface control lines, referred to as handshake lines, originate from the microprocessor's control bus and are used to coordinate the data transfer. Figure 12-3 shows a typical parallel port interface functional diagram. Parallel ports are useful in short transmission paths because of their high data transfer rates but suffer in longer transmission paths because of noise problems and physically large and expensive cables.

12.2.1.0 Parallel and Serial Data Transmission

Serial data transmission is much more complex and slower than parallel data transmission, but it has some advantages over parallel transmission. The main advantage of serial transmission is that transmitted data over a single electrical line, rather than many l ines as in parallel transmission. This means that the cabling for serial transmission is much less expensive and bulky than that of parallel transmission. Also, serial transmission is not as easily affected by noise as is parallel transmission. Serial data transmission requires much more microprocessor interaction than does parallel transmission although there are some chips available that relieve the microprocessor of the transmission burden. Figure 12-4 shows a functional diagram of a typical serial I/O interface.

Figure 12-4 shows that data is either read from or written to the serial port in a parallel manner. When data is written to an external device, the address bus selects the serial port and data is written to the parallel-to-serial (PISO) shift register. Data is

sequentially shifted through the buffer and out over the single data line to the external device. The buffer portion of the serial port modulates or level shifts the incoming data bits for better signal integrity over the data line. The data is shifted under control of the shift clock and the direction control bit. In a similar manner, data is read over the serial interface. Data is shifted in over the single data line, bufferred, and shifted into the shift register. When a complete byte has been received, the microprocessor performs a data read of the serial port. For either the serial data write or serial data read, handshake lines provide information of the status of both the transmitting and receiving devices. On the transmitting end, the sending device uses handshake lines to signal that data is ready and waiting to be transmitted. On the receiving end, the receiving device uses handshake lines to signal that the receiver is ready to begin accepting data.

Computers use binary data and instruction words to perform all computational and data manipulation functions. A binary data word in a computer is defined in size by the 'width' of the data bus. If, for instance, the computer data bus consists of eight electrical connections between the microprocessor, memory, and input/output (I/O), then the computer is said to have a word size of eight 'bits.' A data bus consisting of eight data bit lines is called a byte wide data bus. Other data bus bit widths are four bits (called a nibble), sixteen bits (called a word), and even thirty-two bits and beyond. Figure 12-5 lists industry-standard definitions for the computer data bus.

12.2.2 Programming

12.2.2.0 Machine Code

Computers continually process binary numbers. They input binary numbers from input devices and output binary numbers to output devices. For the computer to know what to do with the binary data words there must be processing instructions. Computer processing instructions are called binary instruction words.

Computers perform program instructions sequentially and each program step is called an instruction code. During an instruction code cycle, a complete computer instruction is initiated and completed.

The first part of any instruction cycle is the fetch cycle. The computer fetches a binary instruction word from memory so that it knows what to do next. A memory fetch is initiated by the microprocessor at the start of a new program line or when power is first applied to the microprocessor. The data read by the microprocessor at the start of a new instruction is always a binary instruction, and is sometimes followed by one or more bytes of information that are part of the instruction. The microprocessor always expects the first binary word read from memory to be an instruction. The microprocessor reads the binary data into an internal register and decodes the data as an instruction by performing a series of comparisons to identify the instruction.

Once the instruction is identified, the microprocessor acts accordingly by performing other memory read operations (called multiple-byte instructions), or by performing the designated instruction without any additional modifier bytes (called single-byte instructions). Computers continually fetch and process data, from when power is applied to them to when they are turned off. Even if a computer appears to be idle, it is busy updating the display, performing a computation, or simply scanning the keyboard waiting for an input.

Topics covered up to this point have introduced basic computer architecture, computer words, and interfacing techniques. This section provides fundamental insight into different levels of computer programming from basic to complex.

Software, in any computer, is simply a series of bit patterns representing specific instruction that control the

operation of the computer. Machine code is that bit pattern of 1 's and O's that ultimately controls all activity of the computer.

Machine code instructions are sequentially read from memory and decoded by the microprocessor to perform the desired activity. Different machine code bit patterns represent different microprocessor instructions. Additionally, different microprocessors use unique machine-code bit patterns for similar instructions. The set of instructions that direct the activity of the microprocessor is called the instruction set of the microprocessor. The instruction set of the MOS Technology 6502 8-bit microprocessor is significantly different than the Zilog Z80 8-bit microprocessor. The binary machine code representation of the add-with-carry (ADC) instruction of the 6502, for example, is 01101001 while the Z80's ADC instruction has the binary representation 10001110. Therefore, it can be seen that though different microprocessors may share similar instructions, the difference in machine code can prohibit program compatibility between microprocessors.

There are, of course, some exceptions. The Z80 has what is called a superset of the 8080 8-bit microprocessor instruction set. This means that all 8080 machine codes are included in the Z80 instruction set and all 8080 programs will run on the Z80. Because the Z80's instruction set is larger than the 8080's, programs written on the Z80 are not gauranteed to run on the 8080.

Machine code programming is the most basic and direct form of programming. Machine code programming is rarely used because of the high probability of programming error when entering the codes into computer memory, the difficulty of entering the codes, and the difficulty of the programmer following program flow. Shown below is a sample machine code program that loads the Z80 register pair BC with the binary value 00000000 00000011, adds the contents of the C register (00000011) to the Z80 accumulator (A register), and retains the

sum in A.

It is apparent that machine code programming is very limited. Machine code, also referred to as object code, must be used by the microprocessor because the microprocessor requires binary instructions. Different programming techniques allow the programmer to use a more symbolic, less confusing programming language than machine code.

12.2.2.1 Assembly Language

Assembly language, like machine code, is used to directly program the desired activity of the microprocessor and microcomputer system. Assembly language is the next level of programming above machine code programming. Alphabetic abbreviations called mnemonics are used in place of bits to represent instructions and even the numeric quantities being processed. Shown below is an assembly language program, written in Z80 assembly mnemonics, that performs the same function as the sample machine code program introduced in the previous section.

Notice how easy it is to read the assembly language program and determine the function of the program. Also, the program is more easily entered into the microcomputer and with much less chance of error than the equivalent machine code program. In the assembly language program above, the load command is abbreviated by the mnemonic 'LD' and the add-with-carry command is abbreviated by 'ADC. 1 Also, 'START' and 'END' are called labels and they represent memory address locations. In the example program the START label represents address 0000000000000000 and the end label represents address 0000000000000011. This should be verified by the reader. A label can also represent constants in assembly programs too. The label 'THREE' can be used in place of the 03 quantity in the first line of the program above. The first line will then read:

START: LD BC/THREE ;Load BC with THREE.

Where the label THREE has the binary representation 0000000000000011.

A natural question that arises is: how does the microprocessor interpret the assembly language program? After all, the microprocessor requires binary machine code to function.

Assembly language programming is a two-step process: first, the programmer develops the assembly language program using mnemonics and labels, etc. Next, the program is 'assembled,' either by hand or by another program, to create binary machine code that the microprocessor understands. When the mnemonics and labels of an assembly language program are translated into machine code directly by a programmer, the process of converting the assembly language program to machine code is referred to as hand assembly. If the assembly languagee program is assembled by another program to automatically generate executable machine code, the program is called an assembler program.

The assembler program examines each line of the assembly language program (called the source code), performs a series of comparisons to determine what the instruction or label represents, and creates the corresponding executable binary object code. Regardless of how the assembly language program is assembled, it is apparent that the use of mnemonics and labels to represent binary program instructions and constant values greatly assists the programmer in creating easily understood, error-free programs.

High level language is the general category of programming that uses english-like program statements to accomplish program goals. Languages like BASIC, FORTRAN, PASCAL, and COBOL use program instruction statements that somewhat remove the programmer from direct control of microprocessor activity. The instruction set used in high level languages allows the programmer to perform scientific calculations, interract with the display, perform character

12.2.2.2 High Level Language

manipulation, and so forth without direct concern with what the microprocessor is doing.

The machine is virtually transparent to the user, that is, the user has no idea what the microprocessor is doing to perform the desired function or what type of processor is used. High level language programs are primarily used in business, scientific and industrial applications where ease of programming is important. High level program statements usually resemble common english words. Shown below is an example of a typical high level language program statement that adds two numbers and stores the resulting sum in 'SUM.'

10 SUM = A+B

It is easy to see that the main advantage of high level language over lower-level languages, like machine code and assembly language, is the ease of programming and understanding of program flow and operation. The main disadvantage of high level language is that the programmer has little or no control over the microprocessor and computer system. As an example of a situation where high level programming is limited is in system interfacing.

If a printer is to be interfaced to a computer it may require a series of control characters before it can accept regular data (as in printing an alternate set of characters). High level languages usually do not support bit-level commands (as required by the printer), therefore a small assembly or machine code program must be written to interface with the printer. High level language programs must be converted into the binary object code format that the microprocessor understands. High level programs are 'passed' through a compiler or program to create the binary object code. The compiler is analogous to the assembler in assembly language programming. The compiler assigns microprocessor registers to variables used in the high level program and generates standardized binary subroutines in place of high-level commands. A command like

100 Y = M»X + B

involves many computational steps. The compiler must set aside memory space for the variables Y, M, X, and B. The

variables M and X are assigned to a multiplication subroutine that may be many machine code lines long. The result of the multiplication of M and X is then added to the variable B to obtain Y. In short, a seemingly simple high level language program line, when compiled, can become many machine code lines long.

This chapter has introduced basic computer concepts with emphasis on how they apply to the microcomputer. The computer was analyzed on a functional level for introduction to some basic computer components: CPU, memory, bus, ports, and peripherals. Computer words were reviewed for insight into how computers uses data and instruction words to process information. Interfacing computers using parallel and serial interface ICs was discussed. Programming methods and levels were reviewed to demonstrate where particular language types relate to different caliber machines. This chapter has provided valuable background information for further building of programming skills and understanding of microcomputers and microprocessor control.

12.3 SUMMARY

1. Give an example of a situation where a mainframecomputer is used. Why?

2. Give an example of a situation where a microcomputeris used. Why?

12.4 REVIEW QUESTIONS

3. Why isn't the address bus in a computer bidirectional?

4. What is microcode?

5. Why is digital logic used in modern computers?

6. What is the primary difference between RAM and ROM?

7. If a serial communications port can transmit at a rate ofeight bits per second, what is the equivalent parallel porttransmission speed?

8. How is object code obtained from an assembly language program?

9. Why are three bytes required for a typical machine code'jump' instruction? Label the three bytes that make upthe typical machine code 'jump' instruction (i.e. data,instruction, or address).