Transcript Document

EECE 353: Digital Systems Design
Introduction to Lab 4
Cristian Grecu
[email protected]
Course web site: http://courses.ece.ubc.ca/353
Introduction to Lab 4
In this lab, you will design an instruction decoder for the
datapath you created in Lab 3.
You will be able to input encoded assembly language instructions, and
the processor will step through the required steps for each instruction
Since the control signal change over time (while executing an
instruction) will need some sort of state machine to count through the
states of each instruction
You are going to start with your Lab 3. If you didn’t get it working, you
can borrow someone else’s Lab 3. Or use the one I posted on the
course website. You need a working Lab 3 to be able to complete
Lab 4!
Lab 4 Introduction, Page 2
Lab 4 Introduction, Page 3
Lab 4 Introduction, Page 4
Here is a sample instruction encoding:
Instruction
16-bit encoding
add r1,r2,rd
1
0
1
0
0
rd (3 bits)
r1 (3 bits)
r2 (3 bits)
0
0
move r1,rd
1
1
0
1
1
rd (3 bits)
0
0
r1 (3 bits)
0
0
sub r1,r2,rd
1
0
0
0
1
rd (3 bits)
r1 (3 bits)
r2 (3 bits)
0
0
load #value,rd
0
1
0
0
0
rd (3 bits)
mul r1,r2,rd
1
0
1
1
0
rd (3 bits)
r1 (3 bits)
r2 (3 bits)
0
0
and r1,r2,rd
1
0
0
1
0
rd (3 bits)
r1 (3 bits)
r2 (3 bits)
0
0
inc r1,rd
1
1
0
0
0
rd (3 bits)
0
r1 (3 bits)
0
0
0
immediate value (8 bits)
0
0
You can use this one, or come up with your own
Lab 4 Introduction, Page 5
Recall that instructions take different number of clock cycles:
Type 1: one clock cycle to execute
load #
Type 2: three clock cycles to execute
move, inc
Type 3: four clock cycles to execute:
add, mul, and, sub
Lab 4 Introduction, Page 6
Read Cycle 1: assert get_next_instruction
Read Cycle 2: instruction appears, latch it into Instruction Register IR
(assert load_ir)
You could overlap execution a bit: assert get_next_instruction during the last
cycle of the previous instruction. If you want to make this optimization, go
ahead!
Lab 4 Introduction, Page 7
Bonus
Interface the LCD screen (remember Lab 2?) to your processor
This isn’t as hard as it sounds. One way to do it, is to add an
instruction: out r1
When this instruction is executed, it sends the value of r1 to the LCD.
- This could either be a command or data
- Need some other way of indicating whether r1 is a command
or data (perhaps one bit in the instruction encoding)
Then, you can write a “program” that sends messages to the LCD
(don’t forget the 5 initialization command bytes).
Lab 4 Introduction, Page 8
Other hints for this lab
1. Read the handout carefully to understand what is supposed to
happen
2. Be sure to simulate your state machine separately
- That’s where a lot of the errors happen
3. When simulating, be sure to look at internal nodes (i.e. control
signals, current state, etc), so you can see what is happening
- You can do the same when you implement the circuit on
the board! Just wire important signals to lights
- Can even use the 7-segment display to look at the
bus
4. Remember, this is fun!
Lab 4 Introduction, Page 9