Instruction Sets in computer architecture

52
Computer Organization and Architecture Chapter 10 (UNIT-3) Instruction Sets: Characteristics and Functions

Transcript of Instruction Sets in computer architecture

Page 1: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 1/52

Computer Organization

and Architecture

Chapter 10 (UNIT-3)

Instruction Sets:

Characteristics

and Functions

Page 2: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 2/52

Machine Instruction Characteristics:

M/C Instructions:

The operation of CPU – determined by theinstructions- called M/C instructions

What is an instruction set?

• The complete collection of instructions that areunderstood by a CPU

• Machine Code

• Binary• Usually represented by assembly codes

Page 3: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 3/52

Elements of an Instruction

• Operation code (Op code)

- Specify the operation to be performed. ex: ADD

• Source Operand reference

 —Operands that are inputs for the operation

• Result Operand reference —The operation may produce result

• Next Instruction Reference

- tells the CPU , where to fetch the next instruction

Page 4: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 4/52

 cont… 

Source and result operands cab be in one of threeareas

• Main memory (or virtual memory or cache)

• CPU register

• I/O device

Page 5: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 5/52

Instruction Cycle State Diagram

Page 6: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 6/52

Instruction Representation

• In machine code each instruction has a uniquebit pattern

• For human consumption (well, programmersanyway) a symbolic representation is used

 —e.g. ADD, SUB, LOAD• Operands can also be represented in this way

 — ADD A,B

Page 7: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 7/52

Simple Instruction Format

Page 8: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 8/52

Instruction Types

• Data processing

- ALU instructions

• Data storage (main memory)

- memory instructions

• Data movement (I/O)

- I/O instructions

• Control

-Test and Branch instructions

Page 9: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 9/52

Number of Addresses

• 3 addresses

 —Operand 1, Operand 2, Result

 —a = b + c;

 —May be a forth - next instruction (usually implicit)

 —Not common —Needs very long words to hold everything

Example:

SUB Y,A,B ( Y <- A  – B)

Page 10: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 10/52

cont..

• 2 addresses

 —One address doubles as operand and result

 —a = a + b

 —Reduces length of instruction

 —Requires some extra work  – Temporary storage to hold some results

Example: Move Y,A ( Y <- A)

Page 11: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 11/52

Cont..

• 1 address

 —Implicit second address

 —Usually a register (accumulator)

 —Common on early machines

Example: LOAD D ( AC <- D)

Page 12: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 12/52

Cont..

• 0 (zero) addresses

 — All addresses implicit

 —Uses a stack 

 —e.g. push a

 — push b — add

 — pop c

 —c = a + b

Page 13: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 13/52

How Many Addresses

• Fewer addresses per instruction

 — requires Less complex CPU

 —Instructions of shorter length

 —Faster fetch/execution of instructions

• More addresses per instructions- results in longer execution time

- Instructions of Longer length

- More complex programs

Page 14: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 14/52

Instruction Set Design

Fundamental Design Issues include the following

• Operation repertoire

 —How many ops?

 —What can they do?

 —How complex are they?• Data types

- various types of data

• Instruction formats —Length of op code field

 —Number of addresses

Page 15: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 15/52

Cont… 

• Registers

 —Number of CPU registers available

 —Which operations can be performed on whichregisters?

•  Addressing modes- modes by which the address of an operand is

specified

• RISC v CISC

Page 16: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 16/52

Types of Operand

•  Addresses

• Numbers

 —Integer/floating point

• Characters

 — ASCII etc.

• Logical Data

 —Bits or flags

• (Aside: Is there any difference between numbers and characters?

 Ask a C programmer!)

Page 17: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 17/52

(cont..)

Numbers:

•  All M/C Languages include numeric data types

• Even in Non-numeric Data Processing

- Need for Numbers to act as a counters , field

widths etc.• Three types of Numerical data – common in

computers

- Integer or Fixed point- Floating point

- Decimal

Page 18: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 18/52

(cont..)

• All internal computer operations are binary in

nature.

• Human users – deal with that decimal numbers

• The most common representation is Packed

Decimal.• Packed Decimal  –  each decimal digit is

represented by 4-bit code

for example: 0 – 0000, 1- 0001, 2-0010…. •  In Multiples of 8 bits

-the code for 246 is 0000 0010 0100 0110

For Negative Numbers, the first 4-bit sign is 1111

Page 19: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 19/52

(cont..)

Characters:

•   A common form of data is text or characterstrings

• Textual data – common for human beings

• Most commonly used character codes are- IRA (International Reference Alphabet)

- ASCII(American Standard Code for

Information Interchange)

Page 20: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 20/52

 cont… 

• IRA code:

- widely used code outside the US

-Each character is represented by 7 bitpattern

- 128 different characters can be represented- IRA encoded characters- stored and

transmitted using 8 bit per character

- The eighth bit- used as a parity bit for errorcorrection

Page 21: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 21/52

cont..

EBCDIC(Extended Binary Coded Decimal

Interchange Code):

- Another code used to encode characters

- EBCDIC –used on IBM S/390 machines.

- IRA,EBCDIC –compatible for packed decimalFor example EBCDIC:

- the codes 11110000 through 11111001

represents the digits 0 through 9.

Page 22: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 22/52

cont..

Logical Data:

•  Each word or addressable unit- treated as asingle unit of data

• Data are viewed in this way- logical data

Two advantages:1) Store an array of Boolean or binary data

(1) – true (0)-False

- with logical data, memory can be usedefficiently for storage

2) Occasions- When we wish to manipulate thedata

Page 23: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 23/52

Types of Operation

The same general types of operations are found

on all machines.

 A typical categorization is the following:

• Data Transfer

•  Arithmetic• Logical

• Conversion

• I/O• System Control

• Transfer of Control

Page 24: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 24/52

(i) Data Transfer 

The most fundamental type of m/c instruction is

data transfer instruction

• Must specify several things

First – location of Source and Destination operands

Second- the length of the data to be transferredThird- modes of addressing for each operand

• The most common IBM S/390 data transferinstruction

- different instructions for register to register,register to memory and memory to register.

Page 25: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 25/52

cont..

• In contrast, the VAX has a move (MOV)

instructions – different amounts of data to bemoved

• The VAX approach – somewhat easier for the

programmer, which has fewer mnemonics todeal with.

• In terms of CPU action – data transferoperations are simplest type.

• If one or both operands are in memory, the CPUmust perform the following actions

Page 26: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 26/52

 cont… 

1) Calculate the memory address, based on the

address mode.

2) If the address refers to virtual memory,transfer from virtual memory to main memory.

3) Determine whether the addressed item is inthe cache.

4) If not, issue a command to the memorymodule

Page 27: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 27/52

(ii) Arithmetic

• Basic arithmetic operations are

- Add, Subtract, Multiply, Divide

- Signed Integer

- Floating point and packed decimal numbers

• Other possible operations include a variety of single-operand instructions

- Increment (a++)

 —Decrement (a--) —Negate (-a)

• The execution of Arithmetic instructions- may involvedata transfer operations - to positions operands for

input to the ALU and deliver o/p of the ALU

Page 28: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 28/52

(iii) Logical

• Basic Logical operations are

(i) Boolean operations or binary data

(ii) NOT operations

(iii) AND, OR, XOR etc..

Examples:

(R1) = 10100101

(R2) = 00001111

Then (R1) AND (R2) = 00000101(For details- refer Table 10.6 in P.No.345 of Tex

Page 29: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 29/52

 cont… 

• In addition to bitwise logical operations – most

m/c ‘s provides shifting and rotatingfunctions

• With a logical shift – the bits of a word are

shifted left or right- On one end, the bit shifted out is lost,

other end, a 0 is shifted in.

•   Arithmetic shift operation- treat the data asa signed integer – does not shift the sign bit

- Right arithmetic shift- the sign bit isreplicated into the bit position to its right

Page 30: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 30/52

Cont… 

- on Left arithmetic shift - logical shift is

performed on all the bits but the sign bit ,which is retained.

- These operations can speedup certain arithmetic

operations•  Rotate or Cyclic operations  – preserves all

of the bits being operated on.

• Shift and Rotate operations are shown in the

following diagram

Page 31: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 31/52

Shift and Rotate Operations

Page 32: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 32/52

Conversion

• Conversion instructions – change the format of 

data

- E.g. Binary to Decimal

• More complex editing instructions is the S/390

Translate(TR) instructions- can be used to convert from one 8-bit code

to another and it takes three operands

for example:

TR R1,R2, L

Page 33: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 33/52

Input/Output

• May be specific instructions

• May be done using data movement instructions(memory mapped)

• May be done by a separate controller (DMA)

Page 34: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 34/52

Systems Control

• System control instructions- can be executed

only in a special privileged area of memory.

• These instructions are reserved for the use of Operating system.

• System control instructions – may read or altera control register

Page 35: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 35/52

Transfer of Control

• Number of Reasons- why transfer-of-control

operations are required

• The most important reasons are following

1) essential to be able to execute each

instruction more than once i.e many thousandsof time

2) Programs involves some decision making

3) helps for- Mechanism for breaking the task into smaller pieces.

Page 36: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 36/52

Cont… 

• Branch Instruction- called jump instruction

 — has one of its operands-the address of the nextinstruction to be executed

 — Most of the instructions are Conditional BranchInstructions

 — Branch is made-only if a certain condition is met,otherwise the next instruction in sequence isexecuted

 — Ex: Four different conditional branch instructions

BRP X Branch to Location X if result is positive

BRN X Branch to Location X if result is negative

BRZ X Branch to Location X if result is Zero

BRO X Branch to Location X if overflow occurs

Page 37: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 37/52

Branch Instruction (Example)

Page 38: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 38/52

cont..

- Note: a branch can be either forward or

backward

• Skip Instructions

 — Another common form of Transfer-of-control

instruction — include an implied address i.e. equals the address of the next instruction plus one instruction length

 — Typically , skip implies that one instruction be

skipped — Skip instruction – does not require destinationaddress

Page 39: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 39/52

cont..

 A typical example is the increment and skip-if-zero

301

.

.

309 ISZ R1

310 BR 301

311In this fragment,R1 is set with the negative of the number of 

iterations

 At the end of the loop, R1 is incremented

If it is not 0,the program branches back to the beginning of the

loop.Otherwise the branch is skipped and the program continues with

the next instruction after the end of the loop

Page 40: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 40/52

 cont… 

Procedure Call Instructions

• The most innovation in the development of programming languages is procedure

• The procedure is instructed to go and execute

their entire procedure and then return to thepoint from which the call took place.

• The use of procedures are economy andmodularity.

• The procedure mechanism involves two basicinstructions : call instruction , Returninstructions

Page 41: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 41/52

cont..

• Figure 10.7 illustrates the use of procedures to

construct a program

• Several points are worth noting

1. A procedure can be called from more than one

location.2. A procedure call can appear in a procedure

3. Each procedure call is matched by a return inthe called program

There are three common places for storing the returnaddress

1) Register 2)Start of called procedure 3)Top of 

stack 

Page 42: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 42/52

Nested Procedure Calls

Page 43: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 43/52

Use of Stack

Page 44: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 44/52

 cont… 

• Example:

Consider a m/c language instruction CALL X,which stands for call procedure at location x.

RN PC + ∆  

PC XWhere PC is the program counter

 ∆ is the instruction length 

RN to be used for the later return.

Page 45: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 45/52

Pentium Operation Types

• Pentium Provides a complex array of operation

types, including a number of specializedinstructions

Call / Return Instructions

• Pentium provides four instructions to supportprocedure call / return

CALL, ENTER, LEAVE, RETURN

• CALL instruction pushes the current instructionpointer value onto the stack and causes a jumpto the entry point of the procedure

PUSH EBP

MOV EBP, ESPSUB ESP S ace for locals

Page 46: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 46/52

 cont… 

- where EBP is the frame pointer and ESP is the

stack pointer

• The ENTER instruction performs all theaforementioned operations in a single

instructions• Pentium Operation Types are shown in the table

in page No:356-357

Memory Management

- Specialized instructions deals with memorymanagement

- Privileged instructions  – can be executed from

the operating system

Page 47: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 47/52

cont..

Condition codes

• condition codes are bits in special registers

• May be set by certain operations and used inconditional branch instructions

• These conditions are set by arithmetic andcompare operations

• Table 10.9 shows Pentium condition codes

C – Carry Bit , P- Parity Bit, A- Auxiliary bit,Z- zero, S- sign, O- Overall

Page 48: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 48/52

PowerPC Operation types

• Provides large collection of operation types

Branch oriented Instructions

• The PowerPC supports- the usual unconditionaland conditional branch instructions

• Conditional branch instructions test a single bitof the condition register for true, false or don’tcare.

• Branch instructions can also indicate  – theaddress of location following the branch  – placed in the linked register.

Page 49: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 49/52

cont..

Load /Store Instructions

• In the PowerPC architecture – only load andstore instructions access memory locations

• There are two Features that characterize the

different load/store instructions(i) Data size: Data can be transferred in units of 

byte, halfword, word, etc.

- loading and storing a string of bytes into orfrom multiple registers

(ii) Sign extension: For Halfword and word loads,the unused bits to the left are filled with zeros

and the sign bit

Page 50: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 50/52

Assembly Language

• A CPU can understand and execute m/c

instructions• Such instructions are simply binary numbers

stored in the computer

• Consider the simple BASIC statementN=I +J+K 

- To program in M/c language with the help of binary numbers are very difficult – a tedious andvery error prone process.

- For more improvement – we use symbolic nameor mnemonic instructions

Page 51: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 51/52

cont..

• This results in the symbolic program as shown

in the followingLabels Operation Operand

FORMUL LDA I

 ADD J

 ADD K 

STA N

I DATA 2

J DATA 3

K DATA 4N DATA 0

 Assembly Program

Page 52: Instruction Sets in computer architecture

7/29/2019 Instruction Sets in computer architecture

http://slidepdf.com/reader/full/instruction-sets-in-computer-architecture 52/52

cont..

• The use of a symbolic program makes life much

easier• Programs written in assembly language are

translated into m/c language by an assembler

• The development of Assembly language was amajor milestone in the evolution of computertechnology

• It was the first step to the high level language

in use today

• They are used in system programs such ascompilers and I/O routines