Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Chapter 7

268 views

Published on

Instruction Set

Published in: Engineering
  • Login to see the comments

  • Be the first to like this

Chapter 7

  1. 1. Er. Nawaraj Bhandari Topic 7 Instruction Set Computer Architecture
  2. 2. Machine Instruction Characteristics  The operation of the processor is determined by the instructions it executes, referred to as machine instructions or computer instructions  The collection of different instructions that the processor can execute is referred to as the processor’s instruction set  Each instruction must contain the information required by the processor for execution
  3. 3. Instruction Representation  Within the computer each instruction is represented by a sequence of bits  The instruction is divided into fields, corresponding to the constituent elements of the instruction
  4. 4. Elements of a Machine Instruction Operation code (opcode) • Specifies the operation to be performed. The operation is specified by a binary code, known as the operation code, or opcode Source operand reference • The operation may involve one or more source operands, that is, operands that are inputs for the operation Result operand reference • The operation may produce a result Next instruction reference • This tells the processor where to fetch the next instruction after the execution of this instruction is complete
  5. 5. Source and result operands can be in one of four areas: 3) Processor register  A processor contains one or more registers that may be referenced by machine instructions.  If more than one register exists each register is assigned a unique name or number and the instruction must contain the number of the desired register 2) I/O device  The instruction must specify the I/O module and device for the operation. If memory-mapped I/O is used, this is just another main or virtual memory address 1) Main or virtual memory  As with next instruction references, the main or virtual memory address must be supplied 4) Immediate  The value of the operand is contained in a field in the instruction being executed
  6. 6. Instruction Types •I/O instructions are needed to transfer programs and data into memory and the results of computations back out to the user •Test instructions are used to test the value of a data word or the status of a computation •Branch instructions are used to branch to a different set of instructions depending on the decision made •Movement of data into or out of register and or memory locations •Arithmetic instructions provide computational capabilities for processing numeric data •Logic (Boolean) instructions operate on the bits of a word as bits rather than as numbers, thus they provide capabilities for processing any other type of data the user may wish to employ Data processing Data storage Data movement Control
  7. 7. Types of Operands
  8. 8. Numbers  All machine languages include numeric data types  Numbers stored in a computer are limited:  Limit to the magnitude of numbers representable on a machine  In the case of floating-point numbers, a limit to their precision  Three types of numerical data are common in computers:  Binary integer or binary fixed point  Binary floating point  Decimal  Packed decimal  Each decimal digit is represented by a 4-bit code with two digits stored per byte  To form numbers 4-bit codes are strung together, usually in multiples of 8 bits
  9. 9. Characters  A common form of data is text or character strings  Textual data in character form cannot be easily stored or transmitted by data processing and communications systems because they are designed for binary data  Most commonly used character code is the International Reference Alphabet (IRA)  Referred to in the United States as the American Standard Code for Information Interchange (ASCII)  Another code used to encode characters is the Extended Binary Coded Decimal Interchange Code (EBCDIC)  EBCDIC is used on IBM mainframes
  10. 10. Logical Data  An n-bit unit consisting of n 1-bit items of data, each item having the value 0 or 1  Two advantages to bit-oriented view:  Memory can be used most efficiently for storing an array of Boolean or binary data items in which each item can take on only the values 1 (true) and 0 (false)  To manipulate the bits of a data item  If floating-point operations are implemented in software, we need to be able to shift significant bits in some operations  To convert from IRA to packed decimal, we need to extract the rightmost 4 bits of each byte
  11. 11. Types of Operation The number of different op codes varies widely from machine to machine. However, the same general types of operations are found on all machines. A useful and typical categorization is the following:  Data transfer  Arithmetic  Logical  Conversion  I/O  System control  Transfer of control
  12. 12. Table 12.4 Processor Actions for Various Types of Operations
  13. 13. Table 12.3 Common Instruction Set Operations (page 1 of 2)
  14. 14. Table 12.3 Common Instruction Set Operations (page 2 of 2)
  15. 15. ASSEMBLY LANGUAGE A processor can understand and execute machine instructions. Such instructions are simply binary numbers stored in the computer. If a programmer wished to program directly in machine language, then it would be necessary to enter the program as binary data.
  16. 16. ASSEMBLY LANGUAGE Consider the simple BASIC statement N = I + J + K Suppose we wished to program this statement in machine language and to initialize I, J, and K to 2, 3, and 4, respectively. The program starts in location 101 (hexadecimal). Memory is reserved for the four variables start- ing at location 201. The program consists of four instructions: Load the contents of location 201 into the AC. Add the contents of location 202 to the AC. Add the contents of location 203 to the AC. Store the contents of the AC in location 204.
  17. 17. Addressing Modes When an instruction requires two operands, the first operand is generally the destination, which contains data in a register or memory location and the second operand is the source. Source contains either the data to be delivered (immediate addressing) or the address (in register or memory) of the data. Generally, the source data remains unaltered after the operation. The three basic modes of addressing are − Register addressing Immediate addressing Memory addressing
  18. 18. Register Addressing In this addressing mode, a register contains the operand. Depending upon the instruction, the register may be the first operand, the second operand or both. For example, MOV DX, TAX_RATE ; Register in first operand MOV COUNT, CX ; Register in second operand MOV EAX, EBX ; Both the operands are in registers As processing data between registers does not involve memory, it provides fastest processing of data.
  19. 19. Immediate Addressing An immediate operand has a constant value or an expression. When an instruction with two operands uses immediate addressing, the first operand may be a register or memory location, and the second operand is an immediate constant. The first operand defines the length of the data. For example, BYTE_VALUE DB 150 ; A byte value is defined WORD_VALUE DW 300 ; A word value is defined ADD BYTE_VALUE, 65 ; An immediate operand 65 is added MOV AX, 45H ; Immediate constant 45H is transferred to AX
  20. 20. Direct Memory Addressing When operands are specified in memory addressing mode, direct access to main memory, usually to the data segment, is required. This way of addressing results in slower processing of data. To locate the exact location of data in memory, we need the segment start address, which is typically found in the DS register and an offset value. This offset value is also called effective address. For example, ADD BYTE_VALUE, DL ; Adds the register in the memory location MOV BX, WORD_VALUE ; Operand from the memory is added to register
  21. 21. Direct-Offset Addressing This addressing mode uses the arithmetic operators to modify an address. For example, look at the following definitions that define tables of data − BYTE_TABLE DB 14, 15, 22, 45 ; Tables of bytes WORD_TABLE DW 134, 345, 564, 123 ; Tables of words
  22. 22. Indirect Memory Addressing This addressing mode utilizes the computer's ability of Segment: Offset addressing. Generally, the base registers EBX, EBP (or BX, BP) and the index registers (DI, SI), coded within square brackets for memory references, are used for this purpose. MY_TABLE TIMES 10 DW 0 ; Allocates 10 words (2 bytes) each initialized to 0 MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX MOV [EBX], 110 ; MY_TABLE[0] = 110 ADD EBX, 2 ; EBX = EBX +2 MOV [EBX], 123 ; MY_TABLE[1] = 123
  23. 23. Addressing Modes
  24. 24. ANY QUESTIONS?

×