nov. 7, 2007sysc 2001* - fall 2007. sysc2001-lecture-ch10.ppt1 william stallings computer...

41
Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction Sets: Characteristics and Functions

Upload: augustine-porter

Post on 28-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 1

William Stallings Computer Organization

and Architecture6th Edition

Chapter 10

Instruction Sets:

Characteristics and Functions

Page 2: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 2

What is an instruction set?

the instructions that are understood by a CPU

Machine Code

• encoded in binary – for machines to work with

for people: represent by assembly codes

• text – for people to work with

Page 3: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 3

(Recall) Elements of an Instruction

Operation code (Op code)

• Do this operation

Source Operand(s) reference(s)

• With this/these operands

Result Operand reference

• Put the answer here

Next Instruction Reference (control flow!)

• When you have done that, do this...

Page 4: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 4

Where Can Operands Be?

Main memory (or cache)

CPU register

I/O device

Page 5: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 5

Instruction Cycle State Diagram

Page 6: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 6

Instruction Representation

In machine code each instruction has a unique bit pattern

For human consumption (well, programmers anyway) a symbolic representation is used

• e.g. ADD, SUB, LOAD

Operands can also be represented symbolically

• e.g. ADD A,B

Page 7: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 7

Simple Instruction Format

Page 8: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 8

Instruction Types

Data processing

Data storage (main memory)

Data movement (I/O)

Program flow control

Page 9: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 9

Number of Addresses (a)

3 addresses

• Operand 1, Operand 2, Result

• a = b + c;

• May be a fourth - next instruction (usually implicit)

• Not common

• Needs very long words to hold everything

Aside: a recent architecture trend (mid-90’s) is to have a Very Long Instruction Word (Search web for “VLIW”)

Page 10: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 10

Number of Addresses (b)

2 addresses

• One address doubles as operand and result

• a = a + b (in C: a += b )

• Reduces length of instruction

• Requires some extra work

– Temporary storage to hold some results

Page 11: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 11

Number of Addresses (c)

1 address

• Implicit second address

• Usually a register (accumulator)

• Common in early machines

• e.g. ADD 10

adds 10 (explicit) to accumulator (implicit)

Page 12: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 12

Number of Addresses (d)

0 (zero) addresses

• operations use implicit stack

• e.g. push a

• push b

• add ( c = a + b )

• pop c

what isa “stack”?

(later!)also see

Appendix 10.A

Java Virtual Machine is stack-based like this!

Page 13: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 13

How Many Addresses ?

More addresses larger instructions

• More complex (powerful?) instructions

• More registers

– Inter-register operations are quicker

• Fewer instructions per program

Fewer addresses smaller instructions

• Less complex (powerful?) instructions

• More instructions per program

• Faster fetch/execution of instructions Why?

Page 14: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 14

Design Decisions (1)

Operation repertoire

• How many ops?

• What can they do?

• How complex are they?

Built-In Data types supported

Instruction formats – how to encode as binary values

• Length of op code field

• Number of addresses

Page 15: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 15

Design Decisions (2)

Registers

• Number of CPU registers available

• Which operations can be performed on which registers?

Addressing modes ( very important! later … Ch. 11)

RISC v CISC

• Reduced Instruction Set Computer

• Complex Instruction Set Computer

Page 16: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 16

Types of Operand

Addresses

Numbers

• Signed Integer / Unsigned Integer / Floating Point

Characters

• ASCII etc.

Logical Data

• Bits or flags

Page 17: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 17

Pentium Data Types

8 bit Byte

16 bit word

32 bit double word

64 bit quad word

Addressing is by 8 bit unit (byte)

A 32 bit double word is read at addresses divisible by 4

N.B. not just anyaddress !

Page 18: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 18

Specific Data Types

General - arbitrary binary contents

Integer - single binary value

Ordinal - unsigned integer

Unpacked BCD - One digit per byte

Packed BCD - 2 BCD digits per byte

Pointer – 32-bit or 64-bit

Bit field

Byte String

Floating Point

BCDBinary Coded Decimal

0000 1001

packed in byte

4-bit 4-bit

BCD1 BCD2

0 0 0 0 BCD

Page 19: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 19

Pentium Integer & FP Data Types

80-bit!10 bytes

(8087 legacy)

Page 20: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 20

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

length data types

Some instructions need operand aligned on 32 bit boundary

Fixed point processor recognises:

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

Floating point

• IEEE 754

• Single or double precision

Page 21: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 21

Types of Operations

Data Transfer

I/O

Arithmetic

Logical

Conversion

System Control

Transfer of Control

move (copy) & store data

process info

control flow

change system’s ability to process info

Page 22: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 22

Data Transfer

Specify

• Source (src)

• Destination (dest)

• Size of data

E.G. MOVB dest, src

operands

size: B = byteoperation

Page 23: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 23

Arithmetic

Add, Subtract, Multiply, Divide

Signed Integer

Floating point ?

May include

• Increment (a++)

• Decrement (a--)

• Negate (-a)

• BCD add/subtract

Page 24: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 24

Shift and Rotate Operations0

logicalshift

shift in 0

arithmeticshift

keep sign !

rotate

Page 25: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 25

Logical

Bitwise operations

• AND, OR, exclusive-OR (XOR)

• NOT (one’s complement)

1-bit XOR:0 xor 0 = 00 xor 1 = 11 xor 0 = 11 xor 1 = 0

Page 26: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 26

Conversion

size conversion:

• e.g. byte to word – sign extend?

E.G. Binary to BCD

• binary 00001111 (1510) to

• packed BCD 0001 0101

integer to floating

BCD

1

BCD

5

Page 27: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 27

Input/Output

May be specific instructions

• e.g. IN or OUT for I/O

MOV for memory

May be done using data movement instructions

• memory mapped

• e.g. MOV for memory

MOV for I/O

May be done by a separate controller (I/O or DMA)

Page 28: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 28

Systems Control

Privileged instructions

CPU needs to be in specific state

• Ring 0 on 80386+

• Kernel mode

For operating systems use

Page 29: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 29

Transfer of Control Unconditional branch

• e.g. branch to instruction at location xxxx

Conditional Branch

• e.g. branch to instruction at location xxxx if result of

last operation was zero

Skip

• e.g. increment and skip next instruction if result is zero

ISZ Register1 increment & skip if zero

Branch xxxx skip this if result was zero

ADD A

Subroutine (function) call

Page 30: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 30

Branch Instruction

Page 31: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 31

Nested Procedure Calls

startaddressof Proc1

startaddressof Proc2

how does machine

knowwhereto gobackto?

STACK!

Page 32: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 32

Hardware Stack

contiguous block of memory locations to store values

have a pointer to value on “top” of stack

• pointer is typically a register in processor, e.g. SP

PUSH

• puts new value on top of stack

– modifies memory and SP

POP

• removes value from top of stack

– modifies SP only

LIFO storageLast In is the

First Out

Page 33: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 33

X

Stack Example

initially empty

PUSH X

PUSH Y

POP

SP

SP

SP

XY

SP

XY

top of stack

top of stack

top of stack

LIFO:Y is Last In and First Out

???

??????

Page 34: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 34

Use of Stack to Save Return Addresses

address of instruction

AFTER “call” to Proc1

RETURN pop return address off

top of stack and putinto PC !

CALL push address of next

instruction onto top of stack and then set

PC = address of Proc

4000

PC

4500 4800 4601 4800 4651 4101

Page 35: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 35

Exercise For Reader

Find out about instruction set for Pentium and PowerPC

Start with Stallings

Visit web sites

Page 36: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 36

Byte Order – Endian Scheme

What order do we store and fetch values that occupy more than one location?

e.g. (number in hex to make it easy to read)

• 12345678 can be stored in 4x 8-bit locations

• what order should be used?

Page 37: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 37

Byte Order (example: 12345678)

Address Value (1) Value (2)

184 12 78

185 34 56

186 56 34

187 78 12

i.e. read top down or bottom up?

low

high

lsbyte

Big endian: “big end first”

Little endian: “little end first”

each “part” is also stored

according to the endian

scheme

Page 38: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 38

Byte Order Names

The problem is called Endian

Value (1) has the least significant byte in the highest address

• This is called big-endian

Value (2) has the least significant byte in the lowest address

• This is called little-endian

Page 39: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 39

4 bytes

62

Example of C Data Structure

Page 40: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 40

Alternative Endian Views

of Memory Map

int a

double b

int pad

char* c

char d[7]

short e

int f

Page 41: Nov. 7, 2007SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt1 William Stallings Computer Organization and Architecture 6 th Edition Chapter 10 Instruction

Nov. 7, 2007 SYSC 2001* - Fall 2007. SYSC2001-lecture-Ch10.ppt 41

Standard Endian Scheme?

Pentium (80x86), VAX: little-endian

IBM 370, Motorola 680x0 (Mac), most RISC: big-endian

Internet is big-endian

• Makes writing Internet programs on PC more awkward!

• WinSock provides htoi and itoh (Host to Internet & Internet to Host) functions to convert