Instruction Sets

36
Instruction Sets Instruction Sets

description

Instruction Sets. Instruction set. It is a list of all instructions that a processor can execute. Element of an instruction: Operation Code (Op Code) {Determine what will be done} Source Operand {Determine which data will be manipulated} - PowerPoint PPT Presentation

Transcript of Instruction Sets

Page 1: Instruction Sets

Instruction SetsInstruction Sets

Page 2: Instruction Sets

Instruction setInstruction set

It is a list of all instructions that a It is a list of all instructions that a processor can execute.processor can execute.

Element of an instruction:Element of an instruction: Operation Code (Op Code) {Determine what Operation Code (Op Code) {Determine what

will be done}will be done} Source Operand {Determine which data will Source Operand {Determine which data will

be manipulated}be manipulated} Destination Operand {Determine where the Destination Operand {Determine where the

data will be stored}data will be stored} Next Instruction {Determine the next Next Instruction {Determine the next

instruction to be executed} instruction to be executed}

Page 3: Instruction Sets

Instruction Cycle State Instruction Cycle State DiagramDiagram

Page 4: Instruction Sets

Instruction CycleInstruction Cycle

Fetch (Instruction is copied from memory Fetch (Instruction is copied from memory to the Instruction Register (IR) )to the Instruction Register (IR) )

Decode (In order to figure out what the Decode (In order to figure out what the instruction should do, it needs to be instruction should do, it needs to be decoded. )decoded. )

Data Operations (Do the operations Data Operations (Do the operations needed) (example: adding two values, needed) (example: adding two values, access ALU)access ALU)

Write-back (The result of the operation is Write-back (The result of the operation is written in the registers) written in the registers)

Page 5: Instruction Sets

Instruction Instruction RepresentationRepresentation

Example of InstructionsExample of Instructions ADD, SUB, LOAD, MPY, DIV, STORADD, SUB, LOAD, MPY, DIV, STOR

Example of OperandsExample of Operands ADD A, BADD A, B LOAD C, XLOAD C, X

Page 6: Instruction Sets

Instruction TypesInstruction Types The set of instruction in a computer must be The set of instruction in a computer must be

sufficient to allow the user to manage all the sufficient to allow the user to manage all the information neededinformation needed

Data processing:Data processing: Arithmetic and logic instruction. This instruction is used Arithmetic and logic instruction. This instruction is used

in the computer registers. in the computer registers. Data storage Data storage

They are memory instructions which allow the They are memory instructions which allow the movement of data between memory and registersmovement of data between memory and registers

Data movement (I/O)Data movement (I/O) Carries the data from the internal registers to the user.Carries the data from the internal registers to the user.

Program flow control:Program flow control: It can use test and branch instructionsIt can use test and branch instructions

Page 7: Instruction Sets

Number of Address Number of Address InstructionInstruction

Three-address InstructionThree-address Instruction Two-address InstructionTwo-address Instruction One-address InstructionOne-address Instruction

Page 8: Instruction Sets

Three-address Three-address InstructionInstruction

Operand 1, Operand 2, ResultOperand 1, Operand 2, Result ADD X,A,B (X = A + B);ADD X,A,B (X = A + B); May be a forth - next instruction May be a forth - next instruction

(usually implicit)(usually implicit) Needs very long words to hold Needs very long words to hold

everythingeverything

Page 9: Instruction Sets

Two-address InstructionTwo-address Instruction

Move Y, AMove Y, A Y =AY =A ADD Y, BADD Y, B Y = Y + BY = Y + B

A MOVE instruction is introduced to do A MOVE instruction is introduced to do an operation an operation

Reduces length of instructionReduces length of instruction Requires some extra workRequires some extra work

Page 10: Instruction Sets

One addressOne address

The second address is Implicit The second address is Implicit Usually a register accumulator (AC)Usually a register accumulator (AC) The AC is used to store the resultsThe AC is used to store the results Common on early machinesCommon on early machines

It can be possible to process It can be possible to process information with Zero- address information with Zero- address Instructions. All the address are Instructions. All the address are implicit.implicit.

Page 11: Instruction Sets

How Many AddressesHow Many Addresses

More addressesMore addresses More complex instructions. More PowerfulMore complex instructions. More Powerful More registersMore registers

operations are quickeroperations are quicker Fewer instructions per programFewer instructions per program

Fewer addressesFewer addresses Less complex instructions. Less PowerfulLess complex instructions. Less Powerful More instructions per programMore instructions per program Faster fetch/execution of instructionsFaster fetch/execution of instructions

Page 12: Instruction Sets

Design DecisionsDesign Decisions

OperationOperation How many ops?How many ops? What can they do?What can they do? How complex are they?How complex are they?

Data typesData types Number of CPU registers available. More Number of CPU registers available. More

operationsoperations Instruction formatsInstruction formats

Length of op code fieldLength of op code field Number of addresses and the addressing modesNumber of addresses and the addressing modes

Page 13: Instruction Sets

Types of OperandTypes of Operand AddressesAddresses NumbersNumbers

Integer/floating pointInteger/floating point CharactersCharacters

ASCII etc.ASCII etc. Logical DataLogical Data

Bits or flagsBits or flags (Aside: Is there any difference between numbers (Aside: Is there any difference between numbers

and characters? Ask a C programmer!)and characters? Ask a C programmer!)

Page 14: Instruction Sets

Pentium Data TypesPentium Data Types 8 bit Byte8 bit Byte 16 bit word16 bit word 32 bit double word32 bit double word 64 bit quad word64 bit quad word Addressing is by 8 bit unitAddressing is by 8 bit unit A 32 bit double word is read at A 32 bit double word is read at

addresses divisible by 4addresses divisible by 4

Page 15: Instruction Sets

Specific Data TypesSpecific Data Types General - arbitrary binary contentsGeneral - arbitrary binary contents Integer - single binary valueInteger - single binary value Ordinal - unsigned integerOrdinal - unsigned integer Unpacked BCD - One digit per byteUnpacked BCD - One digit per byte Packed BCD - 2 BCD digits per bytePacked BCD - 2 BCD digits per byte Near Pointer - 32 bit offset within segmentNear Pointer - 32 bit offset within segment Bit fieldBit field Byte StringByte String Floating PointFloating Point

Page 16: Instruction Sets

Pentium Numeric Data Pentium Numeric Data FormatsFormats

Page 17: Instruction Sets

PowerPC Data TypesPowerPC Data Types 8 (byte), 16 (halfword), 32 (word) and 64 8 (byte), 16 (halfword), 32 (word) and 64

(doubleword) length data types(doubleword) length data types Some instructions need operand aligned on Some instructions need operand aligned on

32 bit boundary32 bit boundary Can be big- or little-endianCan be big- or little-endian Fixed point processor recognises:Fixed point processor recognises:

Unsigned byte, unsigned halfword, signed Unsigned byte, unsigned halfword, signed halfword, unsigned word, signed word, halfword, unsigned word, signed word, unsigned doubleword, byte string (<128 bytes)unsigned doubleword, byte string (<128 bytes)

Floating pointFloating point IEEE 754, Single or double precisionIEEE 754, Single or double precision

Page 18: Instruction Sets

Types of Operation for Types of Operation for Instruction SetsInstruction Sets

1. Data Transfer1. Data Transfer

2. Arithmetic2. Arithmetic

3. Logical3. Logical

4. Conversion4. Conversion

5. I/O5. I/O

6. System Control6. System Control

7. Transfer of Control7. Transfer of Control

Page 19: Instruction Sets

Data TransferData Transfer Specify:Specify:

Source (Register, Memory)Source (Register, Memory) Destination (Register, Memory)Destination (Register, Memory) Amount of dataAmount of data Examples: Examples: movmov src, dest src, dest movmov dest, src dest, src

There are different instructions for different There are different instructions for different movementsmovements Data MoveData Move

movmov src, dest src, dest Data SwapData Swap

xchgxchg src, dest src, dest

Page 20: Instruction Sets

ArithmeticArithmetic Add, Subtract, Multiply, DivideAdd, Subtract, Multiply, Divide

(8- and 16-bit operations are supported (8- and 16-bit operations are supported directly and can easily be extended)directly and can easily be extended)

Signed IntegerSigned Integer Floating point (Floating point (sinesine, , cosinecosine, , square rootsquare root, ,

etc.)etc.) OthersOthers

Increment (a++), ex. PC<-[PC]+1 Increment (a++), ex. PC<-[PC]+1 Decrement (a--)Decrement (a--) Negate (-a)Negate (-a)

Page 21: Instruction Sets

Increment and Increment and decrementdecrement

Page 22: Instruction Sets

ArithmeticArithmetic

Complex Operations (Complex Operations (SIMDSIMD or or Single-Instruction Stream Multiple-Single-Instruction Stream Multiple-Data or Data or vector instructionvector instruction).).

It performs the same arithmetic It performs the same arithmetic operations in multiple pieces of data operations in multiple pieces of data at the same time.at the same time.

SIMD can be used to implement SIMD can be used to implement algorithms involved in sound, images algorithms involved in sound, images and video processing.and video processing.

Page 23: Instruction Sets

Shift and Rotate Shift and Rotate OperationsOperations

“S” is a copy of the sign bit

Rotate = circular shiftingRotate = circular shifting

Page 24: Instruction Sets

Logical and Arithmetic ShiftingLogical and Arithmetic Shifting Logical shifting are used for unsigned binary Logical shifting are used for unsigned binary

numbers.numbers. Arithmetic shifting is used for signed binary Arithmetic shifting is used for signed binary

numbersnumbers

Rotate OperationRotate Operation It is also known as the circular shiftingIt is also known as the circular shifting This operation is useful if it is necessary to retain This operation is useful if it is necessary to retain

all the existing bits. all the existing bits. It is frequently used in digital cryptography.It is frequently used in digital cryptography.

Page 25: Instruction Sets

LogicalLogical Bitwise operator:Bitwise operator:

AND, OR, NOTAND, OR, NOT This operations are faster than arithmetic This operations are faster than arithmetic

operations (+,-,*,/)operations (+,-,*,/) Examples:Examples:

NOT 0111 = 1000 (NOT 0111 = 1000 (It is used for forming the It is used for forming the ones' complementones' complement which is used for addition and subtraction) which is used for addition and subtraction)

0101 OR 0011 = 0111(0101 OR 0011 = 0111(It is used as a flag in programming It is used as a flag in programming cycles)cycles)

0101 AND 0011 = 0001 (0101 AND 0011 = 0001 (The bitwise AND may be used to The bitwise AND may be used to

perform a perform a bit maskbit mask operation and operation and to determine whether a particular to determine whether a particular

bit is 1 or 0bit is 1 or 0 ) )

Page 26: Instruction Sets

Application for Bit Mask Application for Bit Mask Using ANDUsing AND

given a bit pattern: 0010given a bit pattern: 0010 It will be determined whether the It will be determined whether the

third bit is 1, a bitwise AND is third bit is 1, a bitwise AND is applied to it.applied to it.

0010 AND 1010 = 0010 0010 AND 1010 = 0010

Page 27: Instruction Sets

Conversion & I/OConversion & I/O

Convert decimal to binaryConvert decimal to binary May be specific instructionsMay be specific instructions May be done using data movement May be done using data movement

instructions (memory mapped)instructions (memory mapped) May be done by a separate May be done by a separate

controller (DMA)controller (DMA)

Page 28: Instruction Sets

ConversionConversion Example: Binary to DecimalExample: Binary to Decimal 0101 = 4+1=50101 = 4+1=5 2^3, 2^2, 2^1, 2^02^3, 2^2, 2^1, 2^0

Page 29: Instruction Sets

System Control and System Control and Transfer of ControlTransfer of Control

Privileged instructionsPrivileged instructions For operating systems useFor operating systems use Change the sequence of instruction Change the sequence of instruction

executionexecution BranchBranch

branch to x if result is zerobranch to x if result is zero SkipSkip

e.g. increment and skip if zeroe.g. increment and skip if zero

Page 30: Instruction Sets

Branch InstructionsBranch Instructions

Conditional BranchConditional Branch Unconditional BranchUnconditional Branch BRP XBRP X

Branch to location X if result is postiveBranch to location X if result is postive BRZ XBRZ X

Branch to location X if result is zeroBranch to location X if result is zero

Page 31: Instruction Sets

Branch InstructionsBranch Instructions

Page 32: Instruction Sets

Procedure Call Procedure Call InstructionsInstructions

Self contained program that is Self contained program that is incorporated into a larger programincorporated into a larger program Economy and modularityEconomy and modularity

Call instructionCall instruction Branches from the current location to Branches from the current location to

the procedurethe procedure Return InstructionReturn Instruction

Returns from the procedure to the place Returns from the procedure to the place from which it was calledfrom which it was called

Page 33: Instruction Sets

Procedure Call Procedure Call InsructionsInsructions

Page 34: Instruction Sets

QuestionsQuestions

1.1. Give one example were can be used Give one example were can be used increment operation? increment operation? PC<-[PC]+1PC<-[PC]+1

2.2. Mention three examples of bitwise Mention three examples of bitwise operator?operator?

AND, OR, NOTAND, OR, NOT

3.3. Mention three Instruction types?Mention three Instruction types?Data processing, Data storage, Data movementData processing, Data storage, Data movement

4.4. What type of branch instruction is always What type of branch instruction is always executed? Unconditional branchexecuted? Unconditional branch

5.5. What are the two principal reasons for the What are the two principal reasons for the use of the procedure call instructions? use of the procedure call instructions? Economy and ModularityEconomy and Modularity

Page 35: Instruction Sets

QuestionsQuestions

6. What is an example of data transfer?6. What is an example of data transfer?movmov src, dest src, dest

7. What would be the decimal value of 0101?7. What would be the decimal value of 0101?0101 = 4+1=50101 = 4+1=5

8. When you have one address which register is 8. When you have one address which register is usually used?usually used?

accumulator (AC)accumulator (AC)9. What is another name for opcode abbreviations? 9. What is another name for opcode abbreviations?

MnemonicsMnemonics10. What kind of instructions provide 10. What kind of instructions provide

computational capabilities for processing computational capabilities for processing numeric data? Arithmetic Instructionsnumeric data? Arithmetic Instructions

Page 36: Instruction Sets

11. What are the Pentium data types? 11. What are the Pentium data types? Answer: 8 bit Byte, 16 bit word, 32 bit double word, Answer: 8 bit Byte, 16 bit word, 32 bit double word,

64bit quad, 8 bit addressing, 32 bit double word is 64bit quad, 8 bit addressing, 32 bit double word is read and divisible by 4.read and divisible by 4.

12. What are the existing types of operand?12. What are the existing types of operand? Answer: Addresses, Numbers, characters, logical Answer: Addresses, Numbers, characters, logical

data.data. 13. What are the PowerPC data types?13. What are the PowerPC data types? Answer: 8 (byte), 16 (half-word), 32 (word) and 64 Answer: 8 (byte), 16 (half-word), 32 (word) and 64

(double-word) length data types(double-word) length data types 14 What are the specific data types?14 What are the specific data types? Answer: General, Integer, Ordinary, Unpacked BCD,Answer: General, Integer, Ordinary, Unpacked BCD, Packed BCD, Near Point, Bit field, Byte String, Packed BCD, Near Point, Bit field, Byte String,

Floating Point Floating Point