Instruction Set Architectures CS301 Prof. Szajda Instruction - - PowerPoint PPT Presentation

instruction set architectures
SMART_READER_LITE
LIVE PREVIEW

Instruction Set Architectures CS301 Prof. Szajda Instruction - - PowerPoint PPT Presentation

Instruction Set Architectures CS301 Prof. Szajda Instruction Categories Arithmetic w x = x + 1 Memory w mem[addr] = x; Control w for(int i = 0; i < 10 ; i++) Arguments to Arithmetic Operations Constant: x = x + 1


slide-1
SLIDE 1

Instruction Set Architectures

CS301

  • Prof. Szajda
slide-2
SLIDE 2

Instruction Categories

  • Arithmetic

w x = x + 1

  • Memory

w mem[addr] = x;

  • Control

w for(int i = 0; i < 10 ; i++)

slide-3
SLIDE 3

Arguments to Arithmetic Operations

  • Constant: x = x + 1

w Immediate addressing

§ Data appears in constant part of instruction

  • Data stored in register

w Register direct or register addressing

§ Data is in register specified in instruction

  • Data stored in memory: mem[addr] = x

w Direct addressing

§ Explicitly state address in instruction

w Register indirect

§ Register holds address of data in memor

slide-4
SLIDE 4

Memory Aside: Memory Hierarchy

  • Registers

w Small, fast to access, right next to circuitry that performs calculation w Few in number w Expensive!

§ Both in circuitry and real-estate!

  • Memory (logical and physical)

w Larger, slower, further away than registers

4

slide-5
SLIDE 5

Memory Aside: Data

  • Each program has memory

associated with it where data is stored

  • That data is just like an array
  • f memory cells

w Smallest addressable component is a byte w Each cell is addressable by its byte location

Memory

0x0 0x7fffffff

argc is 4B

0x7ff3fa8bc

slide-6
SLIDE 6

Memory Aside: Data

  • Each program has memory

associated with it where data is stored

  • That data is just like an array
  • f memory cells

w Smallest addressable component is a byte w Each cell is addressable by its byte location

Memory

0x0 0x7fffffff

8 char string

0x5ffffd420

slide-7
SLIDE 7

Memory Aside: Instructions

  • Each program has memory

associated with it where data is stored

  • That data is just like an array
  • f memory cells

w Smallest addressable component is a byte w Each cell is addressable by its byte location

  • Instructions are also allocated

space in memory

Memory

0x0 0x7fffffff

4 byte instr.

0xf5fd780

slide-8
SLIDE 8

Stored Program Concept

  • Very important: efgectively allows the

development of general purpose computer

  • Treat instructions the same way as data
  • Simplifies memory hardware and the

software of computers

  • Ex. Memory can contain source code for

editing app, corresponding machine code, text program is using, and compiler that generated machine code!

8

slide-9
SLIDE 9

Instruction Set Architecture
 (ISA)

  • Specifies the instructions that the

architecture understands

  • Represents the interface between HW

and SW

  • Classified by number of addresses

included in instructions

  • Difgerentiated by how registers /

memory used to specify data

slide-10
SLIDE 10

Difgerent Addressing Architectures

  • 0 address architecture: Stack

w Push operands onto stack w Operations automatically take operands from top of stack (pop) w Push result on to stack

slide-11
SLIDE 11

Difgerent Addressing Architectures

  • Accumulator

w Special register where results stored w accum = accum op addr1 … addrn w Advantage: don’t have to specify as many addresses in instructions

  • 1 address architecture

w Assume one operand is in accumulator w Other address is specified w accum = accum op addr1

slide-12
SLIDE 12

Difgerent Addressing Architectures

  • 3 address architecture: MIPS

w 2 inputs to operation w 1 output from operation w add addr1, addr2, addr3 // addr1 = addr2+addr3

Nothing is implicit!

slide-13
SLIDE 13

Addresses are Registers or Memory?

  • Accumulator Architecture

w 1 register for arithmetic (the accumulator) w 1 operand for memory

§ add addr // acc = acc + mem[addr] w Accumulator both source and destination

  • Dedicated Register Architecture

w More registers w Each register with dedicated purpose

§ Stack pointer § Array index w Has both accumulator-like instructions and MIPS-like instructions w Multiply/div accumulator separate from other accumulators

  • General Purpose Register Architecture

w All registers used for any purpose w Two Kinds:

§ Register-memory: one operand in memory § Load-store: all operands in registers

slide-14
SLIDE 14

From Source Code to Machine Language

High Level Language Program Assembly Language Program Machine Language Program Hardware Compiler Assembler Machine Interpretation lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; 1000110001100010000000000000000 1000110011110010000000000000100 1010110011110010000000000000000 1010110001100010000000000000100 ALUOP[0:3] <= InstReg[9:11] & MASK

ISA

slide-15
SLIDE 15

Classifying Instruction Types

  • CISC: Complex Instruction Set Computer

w Create instructions for specific operations

§ Square root

w Create composite instructions

§ Load then add then store

w Allow both memory and register addressing w Allow multiple operands in each instruction w Variable instruction length w Examples: VAX, Motorola 68K, Intel x86

  • RISC: Reduced Instruction Set Computer

w Include small number of basic instructions

§ Load, store, add, subtract

w Small number of operands permitted to instructions w Fixed instruction length w Examples: MIPS, PowerPC, SPARC, HP PA-RISC

slide-16
SLIDE 16

Classifying Instruction Types

  • CISC:

w Make hardware like software to make compilation easier w Also optimize program size

  • RISC:

w VERY much easier to decode instructions

§ Simple instructions have implications for program performance

w Benefit of RISC is really when it comes to hardware

16

slide-17
SLIDE 17

CISC Example

Pentium 4: Note instruction length is variable!

slide-18
SLIDE 18
slide-19
SLIDE 19

RISC Example

I-type: used by immediate and data transfer functions R-type: used for register functions

slide-20
SLIDE 20
slide-21
SLIDE 21

Storing Numbers

slide-22
SLIDE 22

Unsigned Numbers

  • In general, value of ith digit d is

d × Basei w 10112 = 1110

  • 32b allows you to represent 232 difgerent 32b patterns

w 0 to 232-1 (4,294,967,295) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 31 most significant bit least significant bit 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-23
SLIDE 23

Sign and Magnitude

  • Single bit used to represent positive or

negative

  • Problems:

w Which bit for sign? First? Last? w 2 representations for zero w Adders may need additional cycle to figure

  • ut sign
slide-24
SLIDE 24

Signed Numbers:
 Two’s Complement

  • Used in today’s computers
  • Use leading bit to represent positive or negative

w 0: positive w 1: negative

  • Positive numbers have same representation but

have one less bit to use

w 32b: 0 to 231-1 (2,147,483,647)

  • Negative numbers

w 32b: -1 to -231 (-2,147,483,648)

§ -1: 32 1s § -231: 1(31 0s)

slide-25
SLIDE 25

Signed Numbers:
 Two’s Complement

  • Converting from two’s complement to

decimal (x31×-231)+ (x30×230)+... +(x1×21)+ (x0×20) where xi means the ith bit of x

  • Convert between decimal and two’s

complement

w 1(27 1s)1100

slide-26
SLIDE 26

Converting from Positive to Negative

  • Value 6 is represented in 8b as

0 0 0 0 0 1 1 0

  • Value -6 is represented in 8b as

1 1 1 1 1 0 1 0

  • Technique:

w Invert every bit w Add one

  • Works to convert negative to positive

too!

slide-27
SLIDE 27

Examples

  • What is the 2’s complement

representation of (assume 8b)

w -3 w -62

  • What is the decimal value for these 2’s

complement numbers?

w 10010011 w 11110100

slide-28
SLIDE 28
  • Addition of negative number works

correctly

w Add 7 to -5 w Add 2 to -5

Nifty Benefits of Two’s Complement

0 1 1 1 1 0 1 1 0 0 1 0 + 0 0 1 0 1 0 1 1 1 1 0 1 +

slide-29
SLIDE 29

Overflow

  • When can adding/subtracting two numbers

result in overflow?

w Addition: (carry into sign bit)

§ Positive + Positive = Negative

  • 4b values: 0111 + 0111 = 1110

§ Negative + Negative = Positive

  • 4b values: 1001 + 1001 = 0010

w Subtraction: (borrow from sign bit)

§ Positive - Negative = Negative

  • 4b values: 0100 - 1001 = ??

§ Negative - Positive = Positive

  • 4b values: 1001 - 0110 = 0011
  • (This is -7-6, which should be -13, i.e., 10011)
slide-30
SLIDE 30

Overflow w/ Unsigned Numbers

  • Unsigned integers generally used for

memory addresses

  • Want to ignore overflow
  • Two types of add/sub instructions

w add/addi/sub - overflow causes exception w addu/addiu/subu - overflow does not cause exception

slide-31
SLIDE 31

Comparisons

  • Need to distinguish between signed

and unsigned numbers for comparison

  • slt / slti - assumes numbers are signed
  • sltu / sltiu - assumes numbers are

unsigned

slide-32
SLIDE 32

Sign Extension

  • Converting from smaller number of bits to larger

number of bits

w Immediate fields are 16b but registers are 32b

  • Convert 16b to 32b

w Copy most significant bit 16 times and prepend w 0000 0000 0000 0010

§ 0000 0000 0000 0000 0000 0000 0000 0010 § Positive #s have infinite number of preceding 0s

w 1111 1111 1111 1110

§ 1111 1111 1111 1111 1111 1111 1111 1110 § Negative #s have infinite number of preceding 1s