The CPU & Instruction Formats
Total Page:16
File Type:pdf, Size:1020Kb
K Hinds 2018 www.kumarhinds.net Page 1 HEX to Decimal Conversion e.g.: Convert C0DE to Decimal Hexadecimal Digit Notes These values are statically assigned, they Digit Positions (n) 3 2 1 0 grow to the left. This part's easy, plug your hex values in Hex Digits Sorted C 0 D E from right-to-left. Convert A-F 12 0 13 14 Convert hex values A-F to 10-15. Multiply by 16n 12 × 163 0 × 162 13 × 161 14 × 160 The exponent of 16 is the position, n. The product of hex digit and the power of Resulting Products 49152 0 208 14 16. Sum Up All 49374 Our decimal equivalent! Products Computer Organization The Central Processing Unit (CPU) is also known as the microprocessor or processor. The processor contains three sections called the Arithmetic Logic Unit (ALU), the Control Unit and Registers. K Hinds 2018 www.kumarhinds.net Page 2 Random Access Memory (RAM) Read Only Memory (ROM) Definition Random Access Memory or RAM is a Read-only memory or ROM is also a form form of data storage that can be of data storage that can not be easily altered accessed randomly at any time, in any or reprogrammed. Stores instructions that order and from any physical location., are not necessary for re-booting up to make allowing quick access and the computer operate when it is switched manipulation. off. They are hardwired. Use RAM allows the computer to ROM stores the program required to read data quickly to run applications. It initially boot the computer. It only allows allows reading and writing. reading. Volatility RAM is volatile i.e. its contents are lost It is non-volatile i.e. its contents are retained when the device is powered off. even when the device is powered off. Types The two main types of RAM are static The types of ROM include PROM, EPROM RAM and dynamic RAM. and EEPROM. Control unit: The Control Unit makes decisions and sends the appropriate signal down its lines to other parts of the computer. It controls the timing of operations in the computer and controls the instructions sent to the processor and the peripheral devices. Arithmetic/logic unit (ALU): The ALU carries out arithmetic and logic functions. It carries out all the calculations and makes decisions on the data sent to the processor. CPU Registers/Memory Registers are lightning fast computer memory used to speed the execution of computer programs by providing quick access to stored values during program execution. These registers are the top of the memory hierarchy and are the fastest way for the system to manipulate data. They can drive their data onto an internal bus in a single clock cycle. The result of ALU operation is stored here and could be re-used in a subsequent operation or saved into memory. Registers are normally measured by the number of bits they can hold, for example, an “8-bit register” or a “32-bit register”. There are several other classes of registers: Accumulator: It is most frequently used register used to store data taken from memory. Its number varies from microprocessor to microprocessor. General Purpose registers: General purpose registers are used to store data and intermediate results during program execution. Its contents can be accessed through assembly programming. Special purpose Registers: Users do not access these registers. These are used by computer system at the time of program execution. Some types of special purpose registers are given below: Instruction Register (IR): IR holds the instruction currently being executed or decoded. When one instruction is completed, next instruction is fetched in memory for processing. Program Counter (PC): The program counter, PC, is a special-purpose register that is used by the processor to hold the address of the next instruction to be executed. The PC is continually updated to point to the next instruction during the op-code decode cycle. K Hinds 2018 www.kumarhinds.net Page 3 Fetch-decode-execute cycle The main job of the CPU is to execute programs using the fetch-decode-execute cycle (also known as the instruction cycle). This cycle begins as soon as you turn on a computer. To execute a program, the program code is copied from Secondary Storage into Primary Memory. The CPU's PC is set to the memory location where the first instruction in the program has been stored, and execution begins. The program is now running. In a program, each machine code instruction takes up a slot in the main memory. These slots (or memory locations) each have a unique memory address. The PC stores the address of each instruction and tells the CPU in what order they should be carried out. When a program is being executed, the CPU performs the fetch-decode-execute cycle, which repeats repeatedly until reaching the STOP instruction. Summary of the fetch-decode-execute cycle 1. The processor checks the PC to see which instruction to run next. 2. The PC gives an address value in the memory of where the next instruction is. 3. The processor fetches the instruction value from this memory location. 4. Once the instruction has been fetched, it is stored in the IR and it needs to be decoded and executed. For example, this could involve taking one value, putting it into the ALU, then taking a different value from a register and adding the two together. 5. Once this is complete, the processor goes back to the PC to find the next instruction to load into the IR. 6. This cycle is repeated until the program ends. K Hinds 2018 www.kumarhinds.net Page 4 Data Manipulation Data manipulation involves transferring data and operating on data with math Functions, data conversion, data comparison and logical operations. Each instruction requires two or more words of data memory for operation. The words of data memory are referred to as Registers. Input/Output The instruction copies data from a source word to a destination word and vice versa. Data transfer instructions involve the transfer of the contents from one word to another. Data transfer instructions are Output instructions. The MOVE instruction is used to copy the value in one word to another word. Conversely, the LOAD instruction inputs information to a register for processing Input/Output, Arithmetic & Logic commands can be summarized as follows: LOAD (Input) – Loads in a value to main memory MOV (Move) —Moves the source value to the destination. AND (And) —Performs a bitwise AND operation. OR (Or) —Performs a bitwise OR operation. NOT (Not) —Performs a bitwise NOT operation. ADD - MUL - SUB - Instruction Length – Fixed & Variable Fixed Length: On some machines, all instructions have the same length; Having all the instructions be the same length is simpler and make decoding easier but often wastes space Variable Length: On others there may be many different lengths based on the operation required; so, the Opcode and the Operand is varied. This method wastes less space and is more efficient, however they are more difficult to decode. Instruction Format Instructions are decoded as a set of sequenced Operations. These operations instruct the ALU and Control Unit inside the CPU. Operations consist of a set of instructions and data. Operations are made up of Opcodes and Operands. The opcode performs an action on an operand. K Hinds 2018 www.kumarhinds.net Page 5 Opcode The opcode tells the processor the job that needs to be done. A simple operation might be 'ADD', ‘MUL’ or 'SUB'. If we use the analogy of a recipe, the opcode might be 'chop' or 'mix'. Each opcode instruction is very limited in what it can tell the processor to do. A CPU's instruction set contains the opcodes that it will accept. There are two types of opcode: 1. An opcode that tells the circuitry which operation to carry out. E.g. POP, PUSH, ADD, SUB, MUL, MOD, DIV, LOAD 2. An opcode along with some data to be processed: e.g. ADD A,B; LOAD A Zero, One, Two and Three Address Instruction Computer perform task on the basis of instruction provided. An instruction in computer comprises of groups called fields. These field contains different information and depending on the computer – x86 or x64 architecture, everything is in 0 and 1; so each field has different significance on the basis of what a CPU decide to perform. Most machines however have similar instructions sets – instruction sets tell the CPU what to do: ADD, SUB, MOVE, LOAD, etc. An instruction format defines the layout of the bits of an instruction, in terms of its separate parts (Zero, One, two or Three). An instruction format must include an opcode and, implicitly or explicitly, zero or more operands. Typical operations in a computer system may either Infix, Prefix and Postfix Expressions Infix With an arithmetic expression such as B * C, the form of the expression states that variable B is being multiplied by the variable C, since the multiplication operator * appears between them. This type of notation is referred to as infix since the operator is in between the two operands. Order of Operations Consider an infix example, A + B * C. The operators + and * still appear between the operands, each operator has a precedence level. Operators of higher precedence are used before operators of lower precedence. The only thing that can change that order is the presence of parentheses. The precedence order for arithmetic operators’ places multiplication and division above addition and subtraction. If two operators of equal precedence appear, then a left-to-right ordering or associativity is used. Prefix Consider the infix expression A + B.