Top Banner
Introduction to Computer Design Memory Review of simple processor and memory Fetch and execute cycle Processor organization Executing instructions Processor implementation Read MK 399-427, 449-464
38

Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

Jan 17, 2016

Download

Documents

Joy Dean
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

Introduction to Computer Design

MemoryReview of simple processor and

memoryFetch and execute cycleProcessor organizationExecuting instructionsProcessor implementation

Read MK 399-427, 449-464

Page 2: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.2 - Jon Turner - 04/21/23

Random Access Memory

Logically, a random access memory contains an array of numbered storage locations, called words.»when read/write is high, data_out is equal to the value

stored in word specified by address inputs»when read/write is low, the value on data_in replaces the

value in word specified by address outputs»separate enable signal also usually provided

Simplest RAMs are asynchronous - no clock input»synchronous circuits using RAMs must ensure that RAM

timing requirements are satisfied to ensure correct operation

data_in

address

read/writedata_out

. . .

0123

Page 3: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.3 - Jon Turner - 04/21/23

Timing of RAM Operations Read cycle

»access time: time from “last” address change until output data is valid

r/w

data_in data valid

t1 t2 t3

Write cycle» t1 is min time from address

stable and enable asserted until r/w is lowered

» t2 is min time that input data must remain stable before r/w can be raised

» t3 is min time that address stays valid after r/w is raised

»cycle time is t1+t2+t3

address validaddress

enable

Write cycle

address validaddress

enable

d_outdata valid

access timer/w

Read cycle

Circuits using RAM must ensure timing conditions are met.

Page 4: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.4 - Jon Turner - 04/21/23

Implementing a RAM4 word RAM with 4 bits per word

addressbits select

row

row

deco

der

data_in

data_out

address

r/w’

.

.

..

.

.0

. . .. . . .

. . . .

. . . .

. . . .. . . .

. . . .. . . .

. . . .

D

C

.

.

.

Page 5: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.5 - Jon Turner - 04/21/23

VHDL Model for SRAMentity lram16x64 is port ( reset, en, r_w: in STD_LOGIC; aBus: in STD_LOGIC_VECTOR(adrLength-1 downto 0); dBus: inout STD_LOGIC_VECTOR(wordSize-1 downto 0));end lram16x64;architecture arch of lram16x64 istype ram_typ is array(0 to memSize-1)

of STD_LOGIC_VECTOR(wordSize-1 downto 0);signal ram: ram_typ;begin

process(reset, en, r_w, aBus, dBus) begin if reset = '1' then

ram(0) <= x"aaaa"; ram(1) <= x"5555";

elsif en = '1' and r_w = '0' then ram(conv_integer(unsigned(aBus))) <= dBus;

end if;end process;dBus <= ram(conv_integer(unsigned(aBus)))

when reset = '0' and en = '1' and r_w = '1' else(dbus’range => 'Z');

end arch;

array of 16 bit words

for memory

initialize memory write to

location specified by address bus

read from location

specified by address bus

Page 6: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.6 - Jon Turner - 04/21/23

Functional Simulationread

cycleswrite cycle

s

read cycles

details of

write

Page 7: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.7 - Jon Turner - 04/21/23

Timing SimulationOverview

Read Cycle Detail Write Cycle Detail

Page 8: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.8 - Jon Turner - 04/21/23

Shrinking the Memory Cell Computers and other digital systems generally use large

amounts of memory. Specialized memory cells have been developed to pack

more memory in given amount of space. Typical static RAM uses 6 transistor cell using pair of

inverters and pair of pass transistors. Bit line asserted to read or

write the cell. Complementary data lines

used for input and output. Column drivers enabled when

writing.» large current capacity allows

them to force cell to desired state

data_in

data_out

SRAM cell

columndrivers

sense amplifier

bitline

Page 9: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.9 - Jon Turner - 04/21/23

Tri-State Buffers

A tri-state buffer has a data input and a control input.»when control input is asserted, output equals input»when control input is not asserted, output is disconnected

from input - called high impedance state

data_in data_out

control

Tri-state buffers, can be used to build “distributed”multiplexors.

Shared outputs are called buses. Also allows single wire to be used as data

input and output.

D1

SEL1

D0

. . OUT

data_in

CMOS implementation

control data_out

Page 10: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.10 - Jon Turner - 04/21/23

Data Transfer Using Buses

A bus is a shared set of wires used to transfer data among any of several sources/destinations.

Register 1

Q D

LD

Register 2

Q D

LD

Register 3

Q D

LD

»enabling source to place data on the bus

Data transfers involve:

»loading data into destination

Page 11: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.11 - Jon Turner - 04/21/23

Static RAM Array (4x4)data_in

data_out

row

deco

der

address

r/w’

. ... ..

.. ..

Page 12: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.12 - Jon Turner - 04/21/23

Static RAM Array (8x2)..data_in

data_out

row

deco

der

address

r/w’

.. ...... .

.. . ..

.

.

... .

columndecoder/demux

columndecoder/mux

Page 13: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.13 - Jon Turner - 04/21/23

Building Larger RAMs Systems often require larger RAMs than can be

constructed using a single SRAM component. The use of an external decoder and the enable

input allows larger RAMs to be constructed.

Alternative design uses 64Kx4 RAM chips.»no external decoder needed in this case

SRAM16Kx16

SRAM16Kx16

SRAM16Kx16

SRAM16Kx16

data

address24

read/write’

EN

AD

DR

DA

TA

R/W

EN

AD

DR

DA

TA

R/W

EN

AD

DR

DA

TA

R/W

EN

AD

DR

DA

TA

R/W

64Kx16 RAM

Page 14: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.14 - Jon Turner - 04/21/23

Dynamic RAMs

»each storage cell consists of a passtransistor and a capacitor

» reading contents, destroys value– need to write back after reading

»stored charge leaks from capacitorafter 10-100 ms– requires periodic refresh of memory contents

DRAM cells are organized in 2D arrays, much like those for SRAM.»single data line rather than pair» requires sensitive sense amplifiers to detect stored

charge» takes more time (10x) to read values than with SRAM

select

data

storagecapacitor

Dynamic RAMs use a simpler memory cell to enable more bits to be stored in a single chip (4-8x).

Page 15: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.15 - Jon Turner - 04/21/23

Addressing in Dynamic RAMs Large memory chips require lots of address pins. Many DRAM chips reduce number of address pins by

dividing address into two parts.» row address determines which row in 2D array is selected»column address selects one or more bits in the row

Column address can be provided after row address without slowing down memory access.»so, same address pins can be used to supply both row and

column addresses»Row Address Strobe (RAS), Column Address Strobe (CAS)

used to load row and column addresses into on-chip registers Refresh circuitry periodically reads each row in

memory array and writes it back - often built into chip.

Page 16: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.16 - Jon Turner - 04/21/23

Basic Processor & Memory

Memory stores programs and data.»organized as set of numbered storage slots»each memory word can hold a number»processor can read from or write to any word

Fetch & execute cycle» read word whose address is in Program Counter (PC)

and increment PC» interpret stored value as instruction (decoding)»perform instruction using Accumulator (ACC) and

Arithmetic & Logic Unit (ALU)

Controller

PC Data Bus

Address Bus

Memory

0000000100020003000400050006000700080009000a

ffff

. . .

IR IAR ACC

read/writeALU

Page 17: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.17 - Jon Turner - 04/21/23

Instruction Set0000 halt - halt execution0001 negate - ACC := ACC1xxx immediate load – if sign bit of xxx is 0 then

ACC := 0xxx else ACC := fxxx2xxx direct load - ACC := M[0xxx]3xxx indirect load - ACC := M[M[0xxx]]4xxx direct store - M[0xxx] := ACC5xxx indirect store – M[M[0xxx]] := ACC6xxx branch - PC := 0xxx7xxx branch if zero - if ACC = 0 then PC := 0xxx8xxx branch if positive - if ACC > 0 then PC := 0xxx9xxx branch if negative - if ACC < 0 then PC := 0xxxaxxx add - ACC := ACC + M[0xxx]

Page 18: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.18 - Jon Turner - 04/21/23

Sample Program Add the values in locations 20-2f and write sum in 10.Address Instruction Comment0000 (start)1000 (ACC := 0000) initialize sum0001 4010 (M[0010] := ACC)0002 1020 (ACC := 0020) initialize pointer0003 4011 (M[0011] := ACC)0004 (loop) 1030 (ACC := 0030) if pointer = 030, quit

0005 0001 (ACC := -ACC)0006 a011 (ACC :=ACC+M[0011])0007 700f (if 0 goto 000f)0008 3011 (M[M[0011]] := ACC) sum = sum + *pointer0009 a010 (ACC :=ACC+M[0010])000a 4010 (M[0010] := ACC)000b 1001 (ACC := 0001) pointer = pointer + 1000c a011 (ACC :=ACC+M[0011])000d 4011 (M[011] := ACC)000e 6004 (goto 0004) goto loop000f (end) 0000 (halt) halt0010 Store sum here0011 Pointer to next value

Page 19: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.19 - Jon Turner - 04/21/23

Execution of a Computer Program

resetperiod

execute first

instruction - mload

fetch firstinstructio

nfetch secondinstruction

execute second

instruction – dload

Page 20: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.20 - Jon Turner - 04/21/23

Detailed Processor DiagramIR

EG

deco

de

LD

Addr Bus Data Bus

state tick

Control Logic(combinational circuit)

mem_en

mem_rw

AC

C

ALU

com

pare

LD OP

IAR

LD

PC

LD +

Page 21: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.21 - Jon Turner - 04/21/23

Processing Cycle Instruction fetch

»PC used to read word from memory»PC is incremented

Instruction decode»first 4 bits of retrieved instruction are

decoded to determine what to do»appropriate circuitry activated

Instruction execution»retrieve additional memory words»write to memory»modify PC or ACC contents»may take different amounts of time to

complete

Fetch

halt

Negate

mLoad

dLoad

dStore

iStore

Branch

BrZero

brPos

brNeg

Add

iLoad

Page 22: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.22 - Jon Turner - 04/21/23

Instruction Execution Direct Load

» transfer data from memory to ACC, using low 12 bits of instruction word as memory address

» requires asserting of memory signals and loading ACC Conditional branch

»determine if ACC=0 (or >0 or <0)» if so, transfer low 12 bits of instruction word to PC

Indirect store» transfer data from memory to Indirect Address Register

(IAR) using low 12 bits of instruction word as memory address

» transfer data from ACC to memory, using IAR contents as address

» requires placing IAR value on address bus and asserting signals to perform memory write

Page 23: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.23 - Jon Turner - 04/21/23

IREG

deco

de

LD

Addr Bus Data Bus

state tick

Control Logic(combinational circuit)

mem_en

mem_rw

AC

C

ALU

com

pare

LD OP

IAR

LD

PC

LD +

Instruction Fetch

1. PC value on Abus

3. Load IREG

5. Increment PC

2. Memory contents on Dbus

1. mem_en := 1

4. mem_en := 0

Page 24: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.24 - Jon Turner - 04/21/23

IREG

deco

de

LD

Addr Bus Data Bus

state tick

Control Logic(combinational circuit)

mem_en

mem_rw

AC

C

ALU

com

pare

LD OP

IAR

LD

PC

LD +

Add Instruction Execution

1. mem_en := 1

2. Memory contents on Dbus

1. IREG value on Abus

4. Load sum into ACC

3. ALU adds values

5. mem_en := 0

Page 25: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.25 - Jon Turner - 04/21/23

Signal Timing for Processor

Negate mLoadBranch

enable memory

for reading

IREG loaded

PC incremente

dACC

loaded

PC loaded

ACC loaded

ACC loaded

clk

mem_en

mem_rw

pc

ireg

acc

Fetch

abus

dbus

pc

ram

addclk

mem_enmem_rw

pc

ireg

acc

abus

dbus

ireg

ram

PC value on Abus

Page 26: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.26 - Jon Turner - 04/21/23

Signal Timing for Processor

clk

mem_en

mem_rw

abus

dbus

iar

acc

dLoad

ireg

ram

clk

mem_en

mem_rw

abus

dbusiar

acc

iLoad

ireg iar

ram ram

dStoreclk

mem_en

mem_rw

iar

abus

dbus acc

ireg

iStoreclk

mem_en

mem_rw

iar

abus

dbus

ireg iar

ram acc

Page 27: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.27 - Jon Turner - 04/21/23

entity cpu is port (clk, reset : in std_logic;m_en, m_rw : out std_logic; aBus : out std_logic_vector(adrLength-1 downto 0);dBus : inout std_logic_vector(wordSize-1 downto 0));

end cpu;

architecture cpuArch of cpu is

type state_type is (reset_state,fetch,halt,negate,mload,dload, ...);signal state: state_type;type tick_type is (t0, t1, t2, t3, t4, t5, t6, t7);signal tick: tick_type;

signal pc: std_logic_vector(adrLength-1 downto 0); -- program countersignal iReg:std_logic_vector(wordSize-1 downto 0); -- instr. registersignal iar: std_logic_vector(adrLength-1 downto 0); -- ind. addr. reg.signal acc: std_logic_vector(wordSize-1 downto 0); -- accumulatorsignal alu: std_logic_vector(wordSize-1 downto 0); -- alu output

Processor VHDL Specification

processor state and

timing definitions

primary process

or register

s

Page 28: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.28 - Jon Turner - 04/21/23

beginalu <= (not acc) + x"0001" when state = negate else

acc + dbus when state = add else (alu'range => '0');process(clk) -- perform actions that occur on rising clock edgesfunction nextTick(tick: tick_type) return tick_type is begin

case tick iswhen t0 => return t1; when t1 => return t2; when t2 => return t3;when t3 => return t4; when t4 => return t5; when t5 => return t6;when t6 => return t7; when others => return t0;end case;

end function nextTick;procedure decode is begin

case iReg(15 downto 12) iswhen x"0" =>

if iReg(11 downto 0) = x"000" then state <= halt;elsif iReg(11 downto 0) = x"001" then state <= negate;end if;

when x"1" => state <= mload;. . .when x"a" => state <= add;when others => state <= halt;end case;

end procedure decode;

decode instructio

ns

ALU operations

Page 29: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.29 - Jon Turner - 04/21/23

procedure wrapup is beginstate <= fetch; tick <= t0;

end procedure wrapup;begin if clk'event and clk = '1' then if reset = '1' then

state <= reset_state; tick <= t0;pc <= (pc'range => '0'); iReg <= (iReg'range => '0');acc <= (acc'range => '0'); iar <= (iar'range => '0');

elsetick <= nextTick(tick) ; -- advance time by defaultcase state iswhen reset_state => state <= fetch; tick <= t0;when fetch =>

if tick = t1 then iReg <= dBus; end if;if tick = t2 then decode; pc <= pc+'1'; tick <=t0; end if;

when halt => tick <= t0; -- do nothingwhen negate => acc <= alu; wrapup;when mload =>

if iReg(11) = '0' then acc <= x"0" & ireg(11 downto 0); else acc <= x"f" & ireg(11 downto 0); end if;wrapup;

load acc and fetch

next

sign extend for immediate load of negative values

last step of every

instruction

Page 30: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.30 - Jon Turner - 04/21/23

when dload =>if tick = t1 then acc <= dBus; end if;if tick = t2 then wrapup; end if;

when iload =>if tick = t1 then iar <= dBus; end if;if tick = t4 then acc <= dBus; end if;if tick = t5 then wrapup; end if;

when dstore =>if tick = t4 then wrapup; end if;

when istore =>if tick = t1 then iar <= dBus; end if;if tick = t7 then wrapup; end if;

when branch => pc <= x"0" & iReg(11 downto 0); wrapup;

when brZero => if acc=x"0000" then pc <=x"0" & iReg(11 downto 0); end if;wrapup;

when brPos => if acc(15) = '0' and acc /= x"0000" then

pc <= x"0" & iReg(11 downto 0);end if;wrapup;

. . .

load IAR from

memory

load ACC from

address specified by

IAR

Page 31: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.31 - Jon Turner - 04/21/23

process(clk) begin -- perform actions for falling clock edgesif clk'event and clk ='0' then

if reset = '1' thenm_en <= '0'; m_rw <= '1';aBus <= (aBus'range => '0'); dBus <= (dBus'range => 'Z');

elsecase state iswhen fetch =>

if tick = t0 then m_en <= '1'; aBus <= pc; end if;if tick = t2 then m_en <= '0'; aBus <= (aBus'range => '0'); end if;

when dload =>if tick = t0 then

m_en <= '1'; aBus <= x"0" & iReg(11 downto 0); end if;if tick = t2 then

m_en <= '0'; aBus <= (aBus'range => '0'); end if;

when iload =>if tick = t0 then

m_en <= '1'; aBus <= x"0" & iReg(11 downto 0); end if;

synchronized to falling clock edge

use PC to supply

address

use IREG to supply address

Page 32: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.32 - Jon Turner - 04/21/23

if tick = t2 then m_en <= '0'; aBus <= (aBus'range => '0');

end if;if tick = t3 then m_en <= '1'; aBus <= iar; end if;if tick = t5 then

m_en <= '0'; aBus <= (abus'range => '0'); end if;

when dstore =>if tick = t0 then

m_en <= '1'; aBus <= x"0" & iReg(11 downto 0); end if;if tick = t1 then m_rw <= '0'; dBus <= acc; end if;if tick = t3 then m_rw <= '1'; end if;if tick = t4 then m_en <= '0';

aBus <= (abus'range => '0'); dBus <= (dBus'range =>'Z'); end if;

. . .end case;

end if;end if;

end process;

use IAR to

supply address

drop rw after

address is stable

raise rw before

removing address

Page 33: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.33 - Jon Turner - 04/21/23

Processor Test Programram(0) <= x"1a0f"; -- immediate loadram(1) <= x"2010"; -- direct loadram(2) <= x"3030"; -- indirect loadram(3) <= x"4034"; -- direct storeram(4) <= x"0001"; -- negateram(5) <= x"2034"; -- direct loadram(6) <= x"0001"; -- negateram(7) <= x"5032"; -- indirect storeram(8) <= x"0001"; -- negateram(9) <= x"1fff"; -- immediate loadram(10) <= x"a008"; -- addram(11) <= x"700d"; -- brZeroram(12) <= x"0000"; -- haltram(13) <= x"1400"; -- immediate loadram(14) <= x"8010"; -- brPosram(15) <= x"0000"; -- haltram(16) <= x"0001"; -- negateram(17) <= x"9013"; -- brNegram(18) <= x"0000"; -- haltram(19) <= x"6015"; -- branch

ram(20) <= x"0000";-- haltram(21) <= x"8014"; -- brPosram(22) <= x"7014"; -- brZeroram(23) <= x"0001"; -- negateram(24) <= x"9014"; -- brNegram(25) <= x"0000"; -- haltram(48) <= x"0031"; -- pointer for iloadram(49) <= x"5af0"; -- target of iloadram(50) <= x"0033"; -- pointer for istoreram(51) <= x"0000"; -- target of istoreram(52) <= x"f5af"; -- target of dstore

Page 34: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.34 - Jon Turner - 04/21/23

Processor Simulation

Page 35: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.35 - Jon Turner - 04/21/23

Processor Simulation

fetch

mLoad

fetch

dLoad

fetch

Page 36: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.36 - Jon Turner - 04/21/23

Processor Simulation

Page 37: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.37 - Jon Turner - 04/21/23

Processor Simulation

fetch

iload

dstore

fetch

Page 38: Introduction to Computer Design n Memory n Review of simple processor and memory n Fetch and execute cycle n Processor organization n Executing instructions.

6.38 - Jon Turner - 04/21/23

Processor Timing Simulationadd

instruction

ACC=1 initially

adding 1

memory delay

addition delay

FF prop. plus

chip IO delay