Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
University Of Hail Community College Electrical Engineering Department Electronics Engineering and Instrumentation Program Digital Circuits II (EEI 200) Dr. Fawzy Hashem Date: INTRODUCTION TO MICROPROCESSORS The Basic Computer Special-purpose computers control various functions in automobiles, consumer appliances, control manufacturing processes in industry, and are used in navigation systems such as GPS (global positioning system), and many other applications. However the most familiar type of computer is the general-purpose computer that can be programmed to do many different tasks. All computers consist of basic functional blocks that include a central processing unit (CPU), memory, and input/output ports. These functional blocks are connected together with internal buses, as shown below: The three buses are the data bus, the address bus, and the control bus. Input and output devices (peripherals) are connected through the input/output ports. A port is a physical interface on computer through which data are passed to and from peripherals. Instruction and data are stored in memory in specific locations determined by the program, a list of instructions designed to solve a specific problem. Each location has unique address associated with it. Instructions are obtained by the CPU by placing an address on the address bus. Instructions are transferred via the data bus as they are requested by the CPU. The CPU executes the instructions sequentially; frequently, the instructions modify data stored in memory or obtained from an input device. Processed data may be stored back in memory or sent to an output device via the data bus. Signals on control bus are generated by the CPU to coordinate all of these operations. 1 Central Processing Unit (CPU) The CPU is the “brain” of the computer; it consists of the microprocessor with associated circuits that control the running of the computer software programs. Basically, the CPU obtains (fetches) each program instruction from memory and carry out (executes) the instruction. After completing one instruction, the CPU moves on the next one and in most cases can operate on more than one instruction at the same time. This “fetch” and “execute” process is repeated until all of the instructions in a specific program have been executed. The Microprocessor The microprocessor is a digital integrated circuit that can be programmed with series of instructions to perform various operations on data. It can do arithmetic and logic operations, move data from one place to another, and make decisions based on certain instructions. A microprocessor consists of several units, each designed for a specific job. Four basic units that are common to all microprocessors are: the arithmetic and logic unit (ALU), the instruction decoder, the register array, and the control unit, as shown below: Arithmetic Logic Unit: the ALU is the key processing elements of the microprocessor. It is directed by the control unit to perform arithmetic operations (addition, subtraction, multiplication, and division) and logic operation (NOT, AND, OR, and exclusive-OR), as well as many other types of operations. Data for the ALU are obtained from the register array. Instruction decoder: the instruction decoder takes each binary instruction in order in which it appears in memory and decodes (translates) it. Register array: the register array is a collection of registers that are contained within the microprocessor. During the execution of a program, data and memory addresses are temporarily stored in registers that make up this array. The ALU can access the registers very quickly, making the program run more efficiently. Some registers are classed as general-purpose, meaning they can be used for any purpose dictated by the program. 2 Other registers have a specific capabilities and functions and cannot be used as general-purpose registers. Still others are called program invisible registers, used only by the microprocessor and not available to the program. Control unit: the control unit is “in charge” of the processing of instructions once they are decoded. It provides the timing and control signals for getting data into and out of microprocessor and for synchronizing the execution of instructions. Microprocessor Buses The three busses mentioned earlier are the connections for microprocessor to allow data, addresses, and instructions to be moved. They are: The address bus: the address bus is a “one-way-street” over which the microprocessor sends an address code to memory or other external device. The size or width of the address bus is specified by the number of conductive paths or bits. The more bits lines there are in the address, the higher the number of memory locations that can be accessed. The number of address bits has advanced to the point where microprocessor have up to 64 address bits and can access over 264 memory locations. The data bus: the data bus is “two-way-street” on which data or instructions codes are transferred into the microprocessor or the result of an operation or computation is sent out. The original microprocessors had 8-bit data busses. Today’s microprocessors have up to 64-bit data buses. The control bus: the control bus is used by the microprocessor to coordinates its operation and to communicate with external devices. The control bus has signals that enable a memory or an input/output operation at the proper time to read or write data. Control lines are also used to insert special wait states for slower devices and prevent bus contention, a condition that occur if two or more devices try to communicate at the same time. Single-Core and Multi-Core Processors A single-core processor has one microprocessor in a chip. When a single-core processor, such as the Pentium, runs multiple programs (multitasking), it has to divide its time between all of the programs by assigning different “time slices” to each one. This process increases the time it takes to complete a given program. A multi-core processor has two or more microprocessor (cores) each with its own memory cash on a single chip, as shown below: 3 The cores operate in parallel and can run programs much faster than a single-core chip with a comparable processor. Most manufactures, such as Intel, offer dual-core and quad-core processors. As technology advances, the number of cores will continue to increase. Pipelining A technique where the microprocessor begins executing the next instructions in a program before the previous instruction has been completed is called pipelining. That is, several instructions are in the pipeline simultaneously, each in different processing stage. Typically, a pipeline is divided into stages or segments, and each stage can execute its operation concurrently with other stages. When a segment completes an operation, it passes the result to the next segment in the pipeline and fetches the next operation from the preceding segment. Thus, pipelining results in much shorter overall execution times. Once the pipeline is “full”, there are no idle processing stages. Multitasking Many computers operating systems, including OS/2 and Windows, are capable of running many tasks (programs) at the same time with a technique called multitasking. In multitasking, only one processor is involved, but it switches from one program to another so quickly that it gives the appearance of executing all of the programs simultaneously (at the same time). Multithreading Multithreading is the process of executing different parts of a single program, called threads, simultaneously. Multithreading is an extension of multitasking concept. Instead of multiple programs, Multithreading involves multiple threads within a single program. A thread is a single sequence of execution within a program. The operating system of a computer not only can run multiple programs but it also can run multiple threads within each program. 4 Basic Microprocessor Operation The original Intel microprocessor family has undergone through a tremendous change over the years from the 8086/8088 to the Pentium family and to the multi-core processors, both in speed and in complexity. However, the concept of the basic register set and other features of the 8086/8088 have been retained (and expanded) throughout the evolutionary process so that all of the newer processors respond to the same instructions as the original devices. A microprocessor executes programs by repeatedly cycling through the following three basic steps: 1. Fetch an instruction from memory and place it in the CPU. 2. Decode the instruction. In decode step, the program counter is updated to point to the next instruction. 3. Execute the instruction. Results are returned to registers and memory during this step. The architecture of the 8086/8088 microprocessor has two separate internal units: the execution unit (EU), which executes instructions, and the bus interface unit (BIU), which interfaces with the system buses and fetches instructions, reads operands, and write results. These units are as shown below: While the EU is executing instructions, the BIU is fetching the next instruction from the memory, and storing the next instruction in a high speed memory called the cache. In the Pentium processors, two execution units (EUs) allow instructions that are independent of each other to execute at the same time. Basic 8086/8088 Architecture The following figure is a block diagram of the architecture (internal organization) of an 8088 microprocessor: 5 The Bus Interface Unit (BIU) The major parts of the BIU are: the 4-byte instruction queue, the segment registers (CS, DS, SS and ES), the instruction pointer (IP), and the address summing block (∑). The 16-bit data bus and the Q bus interconnect the BIU and the EU. Instruction Queue The instruction queue increases the average speed with which a program is executed (called throughput) by storing up to four bytes. This technique allows the 8088 to fetch and execute at the same time (fetch the next instruction to be executed while executing the present instruction). Segment Registers The 8086/8088 processors had four segment registers: code segment (CS), data segment (DS), stack segment (CS), and the extra segment (ES). They are all 16-bit registers used in the process of forming a 20-bit address. A segment is a 64 kB block of memory and can begin at any point in the 1 MB of memory space. Addressing The physical address is formed by combining a 16-bit address in a segment register (CS) with a 16-bit address in the instruction pointer (IP) register. The addresses “overlap” as shown, with an implied 00002 on the right side of the segment register, as shown below: 6 Example Assume CS=A00016 and IP = A0B016, what physical address is formed? Answer When the CS register is shifted and added to the IP register, we get: A00016 + A0B016 = AA0B0 for the physical address, as illustrated below: The Execution Unit The EU decodes instructions fetched by the BIU, generates appropriate control signals, and executes the instructions. The main parts of EU are the arithmetic logic unit (ALU), the general registers, and the flag registers. The ALU This unit does all the arithmetic and logic operations, working with either 8-bit or 16bit operands. The General Registers This set of 16-bit registers is divided into two sets of four register each, as shown below: One set consists of the data registers, and the other set consists of the pointer and index registers. The pointer and index registers are generally used to keep offset addresses. The data registers can be used in most arithmetic and logic operations; also some of the registers are used specifically by certain program instructions. 7 The flag registers The flag registers contain nine independent status and control bits (flags), as indicated below: A status flag is one-bit indicator used to reflect a certain condition after arithmetic or logic operation by the ALU, such as a carry (CF), a zero result (ZF), or the sign of a result (SF), among others. The control flags are used to alter processor operations in certain situations. Microprocessor Programming All microprocessors work with an instruction set that implements the basic operations. Each instruction consists of a group of bits (1s and 0s) that is decoded by the microprocessor before being executed. These binary code instructions are called machine language and are all that the microprocessor recognizes. The first computers were programmed by actually writing instructions in binary codes, which was a tedious job and prone to error. This primitive method of programming in binary code has evolved to higher form where instructions are represented by English-like words to form what is known as assembly language. Assembly Language To avoid having to write out a long string of 1s and 0s to represent microprocessor instructions, English-like terms called mnemonics or op-codes are used. Each type of microprocessor has its own mnemonics instructions that represent binary codes for the instructions. All of the mnemonic instructions for a given microprocessor are called the instruction set. Assembly language uses the instruction set to create programs for the microprocessor. Like the compiler in high-level programming languages, an assembler must be used to convert the assembly program instructions into machine language, in order for the microprocessor to “recognize” these instruction, as illustrated below: 8 Assembly language is rarely used to create large application programs. However, assembly language is often used in subroutine (a small program within a larger program) that can be called from a high-level language program and runs faster. Assembly language Program For a simple assembly language program, let’s say that we want the computer to add a list of numbers from the memory and place the sum of the numbers back to the memory. A zero is used as the last number in the list to indicate the end of the list of numbers. The steps required to accomplish this task is as follows: 1. Clear a register (in the microprocessor) for the total or sum of the numbers. 2. Point to the first number in the memory (RAM). 3. Check to see if the number is zero. If it is a zero, then all the numbers have been already added. 4. If the number is not zero, add the number in the memory to the total in the register. 5. Point to the next number in the memory. 6. Repeat steps 3, 4, and 5. A flowchart that represents the sequence of executing the above steps is shown below: 9 Using two of the microprocessor’s internal registers ax and bx, the assembly code for the addition subroutine (program) will be as follows: mov ax, 0 ; Replace the content of the ax register with zero. ; Register ax will store the total of the addition. mov bx, 50H ; Place memory address hexadecimal 50 into the bx register. next: cmp word ptr [bx], 0 ; Compare the number in the memory location pointed to by the bx register to zero. Jz done ; If the number in the memory location is zero, jump to “done”. add ax, [bx] ; Add the number in the memory location pointed to by the bx register to the number in the ax register and place the sum into the ax register. Jmp next ; Loop back to “next” and repeat the process. done: mov [bx], ax ; Replace the zero last number in the memory location pointed to by the bx register with the total in the ax register. nop ;No operation, this indicates the end of the program. 10