Vous êtes sur la page 1sur 52

Computer Organization and Architecture

Chapter 10 (UNIT-3) Instruction Sets: Characteristics and Functions

Machine Instruction Characteristics:

M/C Instructions: The operation of CPU determined by the instructions- called M/C instructions What is an instruction set? The complete collection of instructions that are understood by a CPU Machine Code Binary Usually represented by assembly codes

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

cont Source and result operands cab be in one of three areas Main memory (or virtual memory or cache) CPU register I/O device

Instruction Cycle State Diagram

Instruction Representation In machine code each instruction has a unique bit pattern For human consumption (well, programmers anyway) a symbolic representation is used

Operands can also be represented in this way


Simple Instruction Format

Instruction Types Data processing - ALU instructions Data storage (main memory) - memory instructions Data movement (I/O) - I/O instructions Control -Test and Branch instructions

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)

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)

Cont.. 1 address
Implicit second address Usually a register (accumulator) Common on early machines Example: LOAD D ( AC <- D)

Cont.. 0 (zero) addresses

All addresses implicit Uses a stack e.g. push a push b add pop c c = a + b

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

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

Cont Registers
Number of CPU registers available Which operations can be performed on which registers?

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



Types of Operand Addresses Numbers

Integer/floating point

ASCII etc.

Logical Data
Bits or flags
(Aside: Is there any difference between numbers and characters? Ask a C programmer!)

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

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

Characters: A common form of data is text or character strings Textual data common for human beings Most commonly used character codes are - IRA (International Reference Alphabet) - ASCII(American Standard Code for Information Interchange)

IRA code: - widely used code outside the US -Each character is represented by 7 bit pattern - 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 error correction

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 decimal For example EBCDIC: - the codes 11110000 through 11111001 represents the digits 0 through 9.

Logical Data: Each word or addressable unit- treated as a single 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 used efficiently for storage 2) Occasions- When we wish to manipulate the data

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

(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 transferred Third- modes of addressing for each operand

The most common IBM S/390 data transfer instruction - different instructions for register to register, register to memory and memory to register.

In contrast, the VAX has a move (MOV) instructions different amounts of data to be moved The VAX approach somewhat easier for the programmer, which has fewer mnemonics to deal with. In terms of CPU action data transfer operations are simplest type. If one or both operands are in memory, the CPU must perform the following actions

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 in the cache. 4) If not, issue a command to the memory module

(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 involve data transfer operations - to positions operands for input to the ALU and deliver o/p of the ALU

(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

In addition to bitwise logical operations most m/c s provides shifting and rotating functions 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 as a signed integer does not shift the sign bit - Right arithmetic shift- the sign bit is replicated into the bit position to its right

- 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

Shift and Rotate Operations

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

Input/Output May be specific instructions May be done using data movement instructions (memory mapped) May be done by a separate controller (DMA)

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 alter a control register

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 thousands of time 2) Programs involves some decision making 3) helps for- Mechanism for breaking the task into smaller pieces.

Cont Branch Instruction- called jump instruction

has one of its operands-the address of the next instruction to be executed Most of the instructions are Conditional Branch Instructions Branch is made-only if a certain condition is met, otherwise the next instruction in sequence is executed 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

Branch Instruction (Example)

- 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 destination address

A typical example is the increment and skip-if-zero
301 . . 309 ISZ R1 310 BR 301 311

In 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

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 the point from which the call took place. The use of procedures are economy and modularity. The procedure mechanism involves two basic instructions : call instruction , Return instructions

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 in the called program
There are three common places for storing the return address

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

Nested Procedure Calls

Use of Stack

Example: Consider a m/c language instruction CALL X, which stands for call procedure at location x. RN PC + PC X Where PC is the program counter is the instruction length RN to be used for the later return.

Pentium Operation Types

Pentium Provides a complex array of operation types, including a number of specialized instructions Call / Return Instructions Pentium provides four instructions to support procedure call / return

CALL instruction pushes the current instruction pointer value onto the stack and causes a jump to the entry point of the procedure
PUSH EBP MOV EBP, ESP SUB ESP, Space_for_locals

- where EBP is the frame pointer and ESP is the stack pointer The ENTER instruction performs all the aforementioned operations in a single instructions Pentium Operation Types are shown in the table in page No:356-357 Memory Management - Specialized instructions deals with memory management - Privileged instructions can be executed from the operating system

Condition codes condition codes are bits in special registers May be set by certain operations and used in conditional branch instructions These conditions are set by arithmetic and compare operations Table 10.9 shows Pentium condition codes C Carry Bit , P- Parity Bit, A- Auxiliary bit, Z- zero, S- sign, O- Overall

PowerPC Operation types

Provides large collection of operation types Branch oriented Instructions The PowerPC supports- the usual unconditional and conditional branch instructions Conditional branch instructions test a single bit of the condition register for true, false or dont care. Branch instructions can also indicate the address of location following the branch placed in the linked register.

Load /Store Instructions In the PowerPC architecture only load and store 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 or from multiple registers (ii) Sign extension: For Halfword and word loads, the unused bits to the left are filled with zeros and the sign bit

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 statement N=I +J+K - To program in M/c language with the help of binary numbers are very difficult a tedious and very error prone process. - For more improvement we use symbolic name or mnemonic instructions

This results in the symbolic program as shown in the following


I J K N 2 3 4 0


Assembly Program

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 a major milestone in the evolution of computer technology It was the first step to the high level language in use today They are used in system programs such as compilers and I/O routines