MICROCOMPUTER, MICROPROCESSOR & MICROCONTROLLER Microcomputer is a small computer (compared to big supercomputers) that has a microprocessor (again, the term 'micro-' in this word is now eliminated and it is just called processor), central processing unit (CPU). Your PC is an example of a microcomputer. Microcontrollers are computer chips that (if you look at its name it becomes obvious) control something. Microcontrollers usually have a processing unit (which usually runs on a low clock speed), internal memory and input/output elements. Pretty much every electronic device has a microcontroller - starting from a game console or electronic clock and ending with personal computers. Microprocessor is also called the Central Processing Unit (CPU). A microprocessor is currently working in your PC and it's either from AMD or Intel (or any other processor manufacturer). Basically, a microprocessor is one of the essential elements of a computer, as it handles all the operations a computer performs. MICROPROCESSOR AND ITS ARCHITECTURE The microprocessor is sometimes referred to as the 'brain' of the personal computer, and is responsible for the processing of the instructions which make up computer software. It houses the central processing unit, commonly referred to as the CPU, and as such is a crucially important part of the home PC. However, how many people really understand how the chip itself works? This tutorial aims to provide an introduction to the various parts of the microprocessor, and to teach the basics of the architecture and workings of the CPU across three specific sections: CPU Structure This section, using a simplified model of a central processing unit as an example, takes you through the role of each of the major constituent parts of the CPU. It also looks more closely at each part, and examines how they are constructed and how they perform their role within the microprocessor. Instruction Execution Once you are familiar with the various elements of the processor, this section looks at how they work together to process and execute a program. It looks at how the various instructions that form the program are recognised, together with the processes and actions that are carried out during the instruction execution cycle itself As there are a great many variations in architecture between the different kinds of CPU, we shall begin my looking at a simplified model of the structure. The model to be used can be seen on the right of this page, and is a good basis on which to build your knowledge of the workings of a microprocessor. The simplified model consists of five parts, which are: 1) Arithmetic & Logic Unit (ALU) 2) 3) 4) 5) The part of the central processing unit that deals with operations such as addition, subtraction, and multiplication of integers and Boolean operations. It receives control signals from the control unit telling it to carry out these operations. For more, click the title above. Control Unit (CU) This controls the movement of instructions in and out of the processor, and also controls the operation of the ALU. It consists of a decoder, control logic circuits, and a clock to ensure everything happens at the correct time. It is also responsible for performing the instruction execution cycle. More on the control unit can be discovered by clicking the title above. Register Array This is a small amount of internal memory that is used for the quick storage and retreival of data and instructions. All processors include some common registers used for specific functions, namely the program counter, instruction register, accumulator, memory address register and stack pointer. For more, click the title above. System Bus This is comprised of the control bus, data bus and address bus. It is used for connections between the processor, memory and peripherals, and transferal of data between the various parts. Click the title above for more. Memory The memory is not an actual part of the CPU itself, and is instead housed elsewhere on the motherboard. However, it is here that the program being executed is stored, and as such is a crucial part of the overall structure involved in program execution. ALU The ALU, or the arithmetic and logic unit, is the section of the processor that is involved with executing operations of an arithmetic or logical nature. It works in conjunction with the register array for many of these, in particular, the accumulator and flag registers. The accumulator holds the results of operations, while the flag register contains a number of individual bits that are used to store information about the last operation carried out by the ALU. More on these registers can be found in theregister array section. You can look at the ALU as comprising many subcomponents for each specific task that it is required to perform. Some of these tasks and their appropriate subcomponents are: Addition and subtraction These two tasks are performed by constructs of logic gates, such as half adders and full adders. While they may be termed 'adders', with the aid of they can also perform subtraction via use of inverters and 'two's complement' arithmetic. The topic of logic gates is too expansive and detailed to be covered in full here. Many resources exist on the internet and elsewhere relating to this topic, however, so it is recommended that you read further into the areas outlined above to aid with your learning. Multiplication and division In most modern processors, the multiplication and division of integer values is handled by specific floating-point hardware within the CPU. Earlier processors used either additional chips known as maths co-processors, or used a completely different method to perform the task. Logical tests Further logic gates are used within the ALU to perform a number of different logical tests, including seeing if an operation produces a result of zero. Most of these logical tests are used to then change the values stored in the flag register, so that they may be checked later by seperate operations or instructions. Others produce a result which is then stored, and used later in further processing. Comparison Comparison operations compare values in order to determine such things as whether one number is greater than, less than or equal to another. These operations can be performed by subtraction of one of the numbers from the other, and as such can be handled by the aforementioned logic gates. However, it is not strictly necessary for the result of the calculation to be stored in this instance.. the amount by which the values differ is not required. Instead, the appropriate status flags in the flag register are set and checked to detemine the result of the operation. Bit shifting Shifting operations move bits left or right within a word, with different operations filling the gaps created in different ways. This is accomplished via the use of a shift register, which uses pulses from the clock within the control unit to trigger a chain reaction of movement across the bits that make up the word. Again, this is a quite complicated logical procedure, and further reading may aid your understanding. CONTROL UNIT The control unit is arguably the most complicated part of this model CPU, and is responsible for controlling much of the operation of the rest of the processor. It does this by issuing control signals to the other areas of the processor, instructing them on what should be performed next. Similarly to the arithmetic and logic unit, the control unit can be broken down further for easier understanding. As such, the three main elements of the control unit are as follows: Decoder This is used to decode the instructions that make up a program when they are being processed, and to determine in what actions must be taken in order to process them. These decisions are normally taken by looking at the opcode of the instruction, together with the addressing mode used. This is covered in greater detail in the instruction execution section of this tutorial. Timer or clock The timer or clock ensures that all processes and instructions are carried out and completed at the right time. Pulses are sent to the other areas of the CPU at regular intervals (related to the processor clock speed), and actions only occur when a pulse is detected. This ensures that the actions themselves also occur at these same regular intervals, meaning that the operations of the CPU are synchronised. Control logic circuits The control logic circuits are used to create the control signals themselves, which are then sent around the processor. These signals inform the arithmetic and logic unit and the register array what they actions and steps they should be performing, what data they should be using to perform said actions, and what should be done with the results. REGISTERS A register is a memory location within the CPU itself, designed to be quickly accessed for purposes of fast data retrieval. Processors normally contain a register array, which houses many such registers. These contain instructions, data and other values that may need to be quickly accessed during the execution of a program. Many different types of registers are common between most microprocessor designs. These are: Program Counter (PC) This register is used to hold the memory address of the next instruction that has to executed in a program. This is to ensure the CPU knows at all times where it has reached, that is able to resume following an execution at the correct point, and that the program is executed correctly. Instruction Register (IR) This is used to hold the current instruction in the processor while it is being decoded and executed, in order for the speed of the whole execution process to be reduced. This is because the time needed to access the instruction register is much less than continual checking of the memory location itself. Accumulator (A, or ACC) The accumulator is used to hold the result of operations performed by the arithmetic and logic unit, as covered in the section on the ALU. Memory Address Register (MAR) Used for storage of memory addresses, usually the addresses involved in the instructions held in the instruction register. The control unit then checks this register when needing to know which memory address to check or obtain data from. Memory Buffer Register (MBR) When an instruction or data is obtained from the memory or elsewhere, it is first placed in the memory buffer register. The next action to take is then determined and carried out, and the data is moved on to the desired location. Flag register / status flags The flag register is specially designed to contain all the appropriate 1-bit status flags, which are changed as a result of operations involving the arithmetic and logic unit. Further information can be found in the section on the ALU. Other general purpose registers These registers have no specific purpose, but are generally used for the quick storage of pieces of data that are required later in the program execution. In the model used here these are assigned the names A and B, with suffixes of L and U indicating the lower and upper sections of the register respectively. The system bus is a cable which carries data communication between the major components of the computer, including the microprocessor. Not all of the communication that uses the bus involves the CPU, although naturally the examples used in this tutorial will centre on such instances. SYSTEM BUS The system bus consists of three different groups of wiring, called the data bus, control bus and address bus. These all have seperate responsibilities and characteristics, which can be outlined as follows: Control Bus The control bus carries the signals relating to the control and co-ordination of the various activities across the computer, which can be sent from the control unit within the CPU. Different architectures result in differing number of lines of wire within the control bus, as each line is used to perform a specific task. For instance, different, specific lines are used for each of read, write and reset requests. Data Bus This is used for the exchange of data between the processor, memory and peripherals, and is bi-directional so that it allows data flow in both directions along the wires. Again, the number of wires used in the data bus (sometimes known as the 'width') can differ. Each wire is used for the transfer of signals corresponding to a single bit of binary data. As such, a greater width allows greater amounts of data to be transferred at the same time. Address Bus The address bus contains the connections between the microprocessor and memory that carry the signals relating to the addresses which the CPU is processing at that time, such as the locations that the CPU is reading from or writing to. The width of the address bus corresponds to the maximum addressing capacity of the bus, or the largest address within memory that the bus can work with. The addresses are transferred in binary format, with each line of the address bus carrying a single binary digit. Therefore the maximum address capacity is equal to two to the power of the number of lines present (2^lines). INSTRUCTION EXECUTION CYCLE The instruction execution cycle can be clearly divided into three different parts, which will now be looked at in more detail. For more on each part of the cycle click the relevant heading, or use the next arrow as before to proceed though each stage in order. Fetch Cycle The fetch cycle takes the address required from memory, stores it in the instruction register, and moves the program counter on one so that it points to the next instruction. Decode Cycle Here, the control unit checks the instruction that is now stored within the instruction register. It determines which opcode and addressing mode have been used, and as such what actions need to be carried out in order to execute the instruction in question. Execute Cycle The actual actions which occur during the execute cycle of an instruction depend on both the instruction itself, and the addressing mode specified to be used to access the data that may be required. However, four main groups of actions do exist, which are discussed in full later on. A program is a set of instructions for performing a particular task. These instructions are just like English words. The computer interprets the instructions as 1's and 0's. A program can be written in assembly language as well as in high-level language. This written program is called the source program. The source program is to be converted to the machine language, which is called an object program. A translator is required for such a translation. Program translator translates source code of programming language into machine languageinstruction code. Generally, computer programs are written in languages like COBOL, C, BASIC and ASSEMBLY LANGUAGE, which should be translated into machine language before execution. Programming language translators are classified as follows. A list of translators is given in Figure 1.8. Translators are as follows. i. Assembler ii. Compiler iii. Interpreter Assembler: An assembler translates the symbolic codes of programs of an assembly language into machine language instructions . The symbolic language is translated to the machine code in the ratio of one is to one symbolic instructions to one machine code instructions. Such types of languages are called low-level languages. The assembler programs translate the low-level language to the machine code. The translation job is performed either manually or with a program called assembler. In hand assembly, the programmer uses the set of instructions supplied by the manufacturer. In this case, the hexadecimal code for the mnemonic instruction is searched from the code sheet. This procedure is tedious and time-consuming. Alternate solution to this is the use of assemblers. The program called assembler provides the codes of the mnemonics. This process is fast and facilitates the user in developing the program speedily. Compiler: Compilers are the translators, which translate all the instructions of the program into machine codes, which can be used again and again. The program, which is to be translated, is called the source program and after translation the object code is generated. The source program is input to the compiler. The object code is output for the secondary storage device. The entire program will be read by the compiler first and generates the object code. However, in interpreter each line is executed and object code is provided. M-BASIC is an example of an interpreter. High-level languages such as C, C++ and Java compilers are employed. The compiler displays the list of errors and warnings for the statements violating the syntax rules of the language. Compilers also have the ability of linking subroutines of the program. Interpreter: Interpreters also come in the group of translators. It helps the user to execute the source program with a few differences as compared to compilers. The source program is just like English statements in both interpreters and compilers. The interpreter generates object codes for the source program. Interpreter reads the program line by line, whereas in compiler the entire program is read by the compiler, which then generates the object codes. Interpreter directly executes the program from its source code. Due to this, every time the source code should be inputted to the interpreter. In other words, each line is converted into the object codes. It takes very less time for execution because no intermediate object code is generated. .