+ All Categories
Home > Documents > Digital Notes

Digital Notes

Date post: 09-Nov-2014
Category:
Upload: michaelchandrasekar
View: 7 times
Download: 0 times
Share this document with a friend
Popular Tags:
13
1 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-1 Electrical & Computer Engineering Digital Systems Design A Simple Computer Design Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-2 Electrical & Computer Engineering Architecture of a Simple Computer System Three main units Processor (CPU) Memory Instruction and data Input/Output hardware Communicates with other devices Processor Memory Input/Ouput Data Bus Address Bus PC IR AC MDR MAR ALU Control Unit CPU contains basic registers PC – program counter IR – instruction register AC – accumulator MAR – memory address register MDR –memory data register
Transcript
Page 1: Digital Notes

1

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-1Electrical & Computer Engineering

Digital Systems Design

A Simple Computer Design

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-2Electrical & Computer Engineering

Architecture of a Simple Computer System

• Three main units– Processor (CPU)– Memory

• Instruction and data

– Input/Output hardware• Communicates with other

devices

Processor

Memory Input/Ouput

Data Bus

Address Bus

PC IR

AC

MDR

MAR

ALU

Control Unit

• CPU contains basic registers– PC – program counter– IR – instruction register– AC – accumulator– MAR – memory address register– MDR –memory data register

Page 2: Digital Notes

2

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-3Electrical & Computer Engineering

Computer Programs and Instructions

Opcode Address

15 8 7 0

• Instructions stored in memory according to a format determined by the processor designer– For the simple DE2 computer, the format is 16 bits

• 8-bit opcode – to determine the instruction• 8-bit address – to determine the address of one of the operands for the

instruction• 256 word x 16-bits/word memory

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-4Electrical & Computer Engineering

Basic DE2 Computer Instructions

Instruction Mnemonic Operation PreformedOpcode Value

ADD address AC <= AC + contents of memory address

00

STORE address Contents of memory address <= AC

01

LOAD address AC <= contents of memory address

02

JUMP address PC <= address 03

JNEG address IF AC<0 THEN PC <= address 04

Page 3: Digital Notes

3

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-5Electrical & Computer Engineering

Processor Fetch, Decode and Execute Cycle

• The CPU– Reads instructions from

memory

– Decodes the instruction

– Carries out the operation

• A state machine (the control unit) controls the operation sequencing

• Implementing the fetch/decode/execute cycle requires– Several register transfers

– Several clock cycles

Fetch Next Instruction

Decode Instruction

Execute Instruction

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-6Electrical & Computer Engineering

Detailed View of DE2 Fetch/Decode/Execute

EXECUTE

MAR=PC IR=MDR

PC=PC+1 Read Memory

MDR=AC Write Memory

AC=MDR AC=AC+MDR

MAR=IR Read

Memory

FETCH

DECODE

Opcode=ADD Opcode=LOAD Opcode=STORE

...

Page 4: Digital Notes

4

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-7Electrical & Computer Engineering

DE2 Data Values at Reset

• Reset forces the processor to a known state

• All registers will be cleared

• Since PC and MAR are reset to 00, the first instruction will be loaded from address 00

00: 02 1101: 00 1202: 01 1003: 03 03

IR

register_AC

PC

MAR

Memory

MDR

ALU

MW = ‘0’

00 00

00

00

00 00

02 11

10: 00 0011: 00 0412: 00 03

16 8 16+1

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-8Electrical & Computer Engineering

Example Instruction Execution (ADD)

• FETCH– MAR=PC prior to fetch

– Read memory

– IR=MDR

– PC=PC+1

• After the memory access delay, the ADD instruction is available at the input to the IR

• At the same time, PC is incremented using a different bus

• In implementation, MAR=PC at the end of the fetch/decode/execute step– This saves a clock cycle in the

FETCH step

00: 02 1101: 00 1202: 01 1003: 03 03

+1

IR

register_AC

PC

MAR

Memory

MDR

ALU

02 11

01

01

00 04

00 12

10: 00 0011: 00 0412: 00 03

16

Page 5: Digital Notes

5

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-9Electrical & Computer Engineering

Example Instruction Execution (ADD)

• DECODE– Decode opcode to determine

next state– MAR=IR (low 8-bits)– Begin memory read

• Instructions are decoded in hardware using– Combinational logic– A small PLA– ROM

• When the address is clocked into the MAR, the data from memory will be available in the MDR

00: 02 1101: 00 1202: 01 1003: 03 03

IR

register_AC

PC

MAR

Memory

MDR

ALU

00 12

02

01

00 04

00 12

10: 00 0011: 00 0412: 00 03

812

12

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-10Electrical & Computer Engineering

Example Instruction Execution (ADD)

• EXECUTE– AC=AC+MDR– MAR=PC*– GOTO FETCH

• The control unit has placed the processor in the execute state for the ADD instruction– Control signals for the ALU

instruct it to perform an ADD instruction

• Depending on the complexity of the instruction, there could be multiple steps (sub-states) for an instruction

• * By setting MAR=PC in every instruction’s final execute state, a clock cycle can be saved in the FETCH state

10: 00 0011: 00 0412: 00 03

00: 02 1101: 00 1202: 01 1003: 03 03

IR

register_AC

PC

MAR

Memory

MDR

ALU

00 12

02

12

00 04

00 03

16 8 16

00 07

02

00 0400 03

Page 6: Digital Notes

6

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-11Electrical & Computer Engineering

DE2 VHDL Source Code

-- Modified by J. Jackson from Hamblen to match Hamblen-- text description and for general readability

LIBRARY ieee;USE ieee.std_logic_1164.ALL;USE ieee.std_logic_signed.ALL;USE ieee.numeric_std.ALL;

ENTITY SCOMP ISGENERIC( ADDRESS_WIDTH : INTEGER := 8;

DATA_WIDTH : INTEGER := 16);PORT(clock, reset : IN STD_LOGIC:= '1';program_counter_out : OUT STD_LOGIC_VECTOR(ADDRESS_WIDTH-1 DOWNTO 0);register_AC_out : OUT STD_LOGIC_VECTOR(DATA_WIDTH-1 DOWNTO 0);memory_data_register_out : OUT STD_LOGIC_VECTOR(DATA_WIDTH-1 DOWNTO 0);memory_address_register_out : OUT STD_LOGIC_VECTOR(ADDRESS_WIDTH-1 DOWNTO 0);memory_write_out : OUT STD_LOGIC);

END SCOMP;

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-12Electrical & Computer Engineering

DE2 VHDL Source Code

ARCHITECTURE rtl OF SCOMP ISTYPE RAM IS ARRAY(0 TO 2 ** ADDRESS_WIDTH-1) OF STD_LOGIC_VECTOR(DATA_WIDTH-1DOWNTO 0);SIGNAL ram_block : RAM;ATTRIBUTE ram_init_file : STRING;ATTRIBUTE ram_init_file OF ram_block : SIGNAL IS "PROGRAM.MIF";

TYPE SCOMP_FSM IS ( reset_pc, fetch, decode, execute_add, execute_load,execute_jneg, execute_jneg2, execute_store, execute_store2,execute_jump );

SIGNAL state SCOMP_FSM;SIGNAL instruction_register : STD_LOGIC_VECTOR(DATA_WIDTH-1 DOWNTO 0);SIGNAL memory_data_register : STD_LOGIC_VECTOR(DATA_WIDTH-1 DOWNTO 0);SIGNAL register_AC : STD_LOGIC_VECTOR(DATA_WIDTH-1 DOWNTO 0);SIGNAL program_counter : STD_LOGIC_VECTOR(ADDRESS_WIDTH-1 DOWNTO 0);SIGNAL memory_address_register : STD_LOGIC_VECTOR(ADDRESS_WIDTH-1 DOWNTO 0);SIGNAL memory_write : STD_LOGIC;

Page 7: Digital Notes

7

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-13Electrical & Computer Engineering

DE2 VHDL Source Code

BEGIN

-- Output major signals

program_counter_out <= program_counter;

register_AC_out <= register_AC;

memory_data_register_out <= memory_data_register;

memory_address_register_out <= memory_address_register;

memory_write_out <= memory_write;

PROCESS (clock)

BEGIN

IF RISING_EDGE(clock) THEN

IF (memory_write = '1') THEN

ram_block(to_integer(unsigned(memory_address_register))) <= Register_AC;

END IF;

memory_data_register <=

ram_block(to_integer(unsigned(memory_address_register)));

END IF;

END PROCESS;

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-14Electrical & Computer Engineering

DE2 VHDL Source Code

PROCESS (clock,reset)

BEGIN

IF reset = '1' THEN

state <= reset_pc;

ELSIF RISING_EDGE(clock) THEN

CASE state IS

-- reset the computer, need to clear some registers

WHEN reset_pc =>

program_counter <= (others => '0');

register_AC <= (others => '0');

state <= fetch;

-- Fetch instruction from memory and add 1 to PC

WHEN fetch =>

instruction_register <= memory_data_register;

program_counter <= program_counter + 1;

state <= decode;

Page 8: Digital Notes

8

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-15Electrical & Computer Engineering

DE2 VHDL Source Code

-- Decode instruction and send out address of any data operandsWHEN decode =>CASE instruction_register( 15 DOWNTO 8 ) ISWHEN "00000000" =>state <= execute_add;

WHEN "00000001" =>state <= execute_store;

WHEN "00000010" =>state <= execute_load;

WHEN "00000011" =>state <= execute_jump;

WHEN "00000100" =>state <= execute_jneg;

WHEN OTHERS =>state <= fetch;

END CASE;-- Execute the ADD instruction

WHEN execute_add =>register_ac <= register_ac + memory_data_register;state <= fetch;

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-16Electrical & Computer Engineering

DE2 VHDL Source Code

-- Execute the STORE instruction-- (needs two clock cycles for memory write and fetch mem setup)WHEN execute_store =>-- enable memory write, write register_AC to memory-- load memory address and data registers for memory writestate <= execute_store2;

-- Finish memory write operation and load memory registers-- for next fetch memory read operationWHEN execute_store2 =>state <= fetch;

-- Execute the LOAD instructionWHEN execute_load =>register_ac <= memory_data_register;state <= fetch;

-- Execute the JUMP instructionWHEN execute_jump =>program_counter <= instruction_register(ADDRESS_WIDTH-1 DOWNTO 0);state <= fetch;

Page 9: Digital Notes

9

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-17Electrical & Computer Engineering

DE2 VHDL Source Code

WHEN execute_jneg =>IF (register_AC < 0) THEN

program_counter <= instruction_register(ADDRESS_WIDTH-1 DOWNTO 0);END IF;state <= execute_jneg2;

WHEN execute_jneg2 =>state <= fetch;

WHEN OTHERS =>state <= fetch;

END CASE;END IF;

END PROCESS;

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-18Electrical & Computer Engineering

DE2 VHDL Source Code

-- memory address register is already inside synchronous memory unit -- need to load its value based on current state-- (no second register is used - not inside a process here)

WITH state SELECTmemory_address_register <= (others => '0') WHEN reset_pc,

program_counter WHEN fetch,instruction_register(ADDRESS_WIDTH-1 DOWNTO 0) WHEN decode,program_counter WHEN execute_add,instruction_register(ADDRESS_WIDTH-1 DOWNTO 0) WHEN execute_store,program_counter WHEN execute_store2,program_counter WHEN execute_load,instruction_register(ADDRESS_WIDTH-1 DOWNTO 0) WHEN execute_jump,program_counter WHEN execute_jneg,program_counter WHEN execute_jneg2;

WITH state SELECTmemory_write <= '1' WHEN execute_store,

'0' WHEN OTHERS;END rtl;

Page 10: Digital Notes

10

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-19Electrical & Computer Engineering

Example DE2 MIF File

DEPTH = 256; % Memory depth and width are required %

WIDTH = 16; % Enter a decimal number %

ADDRESS_RADIX = HEX; % Address and value radixes are optional %

DATA_RADIX = HEX;% Enter BIN, DEC, HEX, or OCT; unless %

CONTENT

BEGIN

[00..FF] : 0000; % Range--Every address from 00 to FF = 0000 %

00 : 0210; % LOAD AC with MEM(10) %

01 : 0011; % ADD MEM(11) to AC %

02 : 0112; % STORE AC in MEM(12) %

03 : 0212; % LOAD AC with MEM(12) %

04 : 04FF; % JNEG FF should jump to FFH %

05 : 0305; % JUMP to 05 (loop forever) %

10 : AAAA; % Data Value %

11 : 5555; % Data Value %

12 : 0000; % Data Value - should be FFFF after program %

FF : 0305; % JUMP to 05 %

END ;

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-20Electrical & Computer Engineering

Simulation of the DE2 Computer

Page 11: Digital Notes

11

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-21Electrical & Computer Engineering

Simulation of the DE2 Computer (continued)

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-22Electrical & Computer Engineering

Simulation of the DE2 Computer (continued)

Page 12: Digital Notes

12

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-23Electrical & Computer Engineering

Simulation of the DE2 Computer (continued)

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-24Electrical & Computer Engineering

Simulation of the DE2 Computer (continued)

Page 13: Digital Notes

13

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 8-25Electrical & Computer Engineering

Simulation of the DE2 Computer (continued)


Recommended