Lab 5 – Single-Cycle Microprocessor Design

advertisement
Lab 5 – Single-Cycle Microprocessor Design
(Using SMOK and Cebollita)
25 possible points
Due Wednesday, Nov 9th by midnight
Credit for this lab goes in part to: John Zahorjan
zahorjan@cs.washington.edu
Department of Computer Science & Engineering
University of Washington
Goal:
The purpose of this assignment is to familiarize you with the workings of an
actual microprocessor. Up to this point in the class, you’ve been exposed to
various aspects of computer architecture. These were basic skills necessary
to be able to delve further into the specifics of an actual engineering design.
It is essential that you understand these concept fully to be able to continue
further. Please contact me if you still have any questions about any of these
topics:








Base conversion:Binary,hex,decimal
Negative numbers: 1’s complement /2’s complement /signedmagnitude
Bitwise operations (AND/OR/XOR/NOT/NAND/NOR/XNOR)
Procedure Calls (JSR/JSRR/RET)
Stack Operations-Push/Pop
Queue Operations-Enqueue/Dequeue
Array indexing operations
Memory Modes (direct,indirect,register, indexed etc)
In this lab, we will build an actual microprocessor! – sort of. We will leave
the design of a real microprocessor implementation (in a programmable logic
device or otherwise) to the real hardware designers for the moment.
However, we will still be able to design our own simple, single-cycle
microprocessor and see it run in a simulator.
In following the serious of steps outlined in this lab, you will gain a new
appreciation of the steps involved in the creation of a microprocessor in
some HDL (Hardware Description Language) like Verilog or VHDL. Further,
this lab will solidify your understanding of the various parts of a simple CPU.
In the end, you will see a simple program run on your own microprocessor!
Note: Although not required, it will be very useful to have some background
in C for the next several assignments. Your Tutor/TA would be happy to
provide a simple tutorial. At its most basic, C is an extremely easy language
to understand and write. For the programs that we will be writing, a twentyminute tutorial will be more than adequate for even those of you who have no
programming background prior to this class. 
Problem:
You are doing to design a single-cycle implementation of a small
portion of the Cebollita ISA (You can find the full documentation here). You
will be given a skeleton datapath. It will be your responsibility to build the
different portions of the actual control. Specifically, you will be designing
the main control for the datapath, ALU controls, and Branch Control.
The Cebollita ISA Subset
Arithmetic
ADD, ADDI, SUB, MULT*, DIV*, SLT
Logic
OR, ORI, AND, XOR, SLL, SRAV, SLLV
Memory
LW, SW, LB, SB
Control
J, JAL, JSR, BEQ, BNE, HALT
*Our multiply and divide instructions will be R-type instructions. That is, we
will never have an instruction MUL R0, R0, 10, it will always be MUL R0, R0,
R1, where R1 equals 10.
With this subset, we will be able to use the cebollita compiler to build some
real benchmarking/test programs.
How to get started:
Before we actually get into the creation of the microprocessor, we are going
to create a simple calculator. That’s right. This will be a fully working
calculator – known as a “Stack Machine”.
The machine has 6.5 instructions: add, sub, mult, div, pop, push, and stop, with 8bit opcodes 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, and 0x08 respectively.
All instructions other than push are 8-bits long, and consist of just the opcode. A push
instruction is 32-bits long: an 8-bit opcode followed by 24-bits of immediate data.
Here is the way the machine works, if we want to calculate A+B, we say:
Push A
Push B
Add
This will push the value A and B onto the stack, then Add will pop the two previous
values, add them, and store the result. Thus, the stack state will be the following (SP
refers to stack pointer). Note that each value is 16-bits wide:
SP=0 PUSH A ; push A to memory location [0], increment SP by 1
SP=1 PUSH B ; push B to memory location [1], increment SP by 1
SP=2 ADD
; get the data from memory locations [0] and [1]
; add them, store to memory location SP-2=[0]
; set the SP to SP-1=[1]
A Sample Program
One way to express programs for this machine is as a postfix expression. For
instance,
12*3*4*$
computes 4!. (The '$' means stop.)
The program that we write is listed next. The data on the left is the hexadecimal
number that corresponds to each instruction. Notice the Opcodes correspond to
those listed above (0x05 at the beginning of the push command is equal to the
opcode 0x05 of the push instruction as shown above).
The machine code is:
05000001
05000002
02
05000003
02
05000004
02
08
#
#
#
#
#
#
#
#
push
push
mult
push
mult
push
mult
stop
0x000001
0x000002
0x000003
0x000004
Describe in your README what the code for the following programs would be. Also
describe the steps involved in its calculation (and the resulting value of course). Describe
in detail the state of the stack pointer after each iteration. Provide a visual representation
of the state of the stack after each operation (much like we do in lab with the
representation of the state of main memory).
There are three instructions that have errors. Indicate which instructions these are.
Proggie 1: 1 2 3 4 5 + - * / $
Proggie 2: 2 3 4 + 4 - / 55 - $
Proggie 3: 1 5 10 5 POP + + $
Proggie 4: 10 10 10 10 10 + + $
Proggie 5: 5 2 1 + + / $
Proggie 6: 5 6 1 + + + $
Next, please read the information about PLAs (Programmable Logic Arrays).
These will be used in the creation of our machine.
We begin with a skeleton SMOK model that has the majority of the
componenets needed for the datapath. Included, you will also find many of
the connections between the components. In it’s current form, the skeleton
control included has implemented the HALT instruction. Note that this will
cause the machine to halt the minute that a SYSCALL or BREAK instruction
is encountered.
Part 1: The Datapath
Part 2: ALU Control
Part 3: Main Control Unit
Part 4:
Notes:



Non-alphabetic characters such as numbers (1,2,3), punctuation (,.?!),
and other weird stuff (&#$[}\|, etc) should not be altered before
output. That is to say, if I enter '@', I should get '@' back.
To get some test input go to http://tools.geht.net/rot13.html
Search the internet for ROT-13 jokes to share with each other. If
you like store some by
default in your program and let the graders have some fun. 
Requirements
You are required to use a 2D array structure using either Row Major or
Column Major ordering covered in class. Be sure to put this in your
README.
Collaboration:
You are not allowed to discuss this lab with other students.
You are allowed to work in a pair on this assignment.
Figure it out on your own and ask for help from the TA/tutor if needed. The
tutors and TAs will help the instructor check for possible cheating in all
labs.
Example of possible output:
Hello, Welcome to my ROT-13 conversion program
Commands begin with a “:”.
:c
:r #
is 0 to 3
clear the list
apply rot-13 to an element of the list, where #
:p
print the list
:x
quit
:?
show this menu again
or, just enter text (not starting with a :) to store a
line.
> Hello World!
Entered into position 1.
> Fpubby vf sha!!
Entered into position 2.
> :p
1) Hello World!
2) Fpubby vf sha!!
> :r 2
Row 2 ROT-13’ed
> :p
1) Hello World!
2) School is fun!!
> :r 1
Row 1 ROT-13’ed
> :p
1) Uryyb Jbeyq!
2) School is fun!!
> :c
All cleared
> :p
Nothing stored
> :x
Good-bye
Files to Submit:


Lab7.asm
README
Check-off:
You must demonstrate this lab to the TA/tutor, either before submission or
after submission. To be considered on time you must have submitted
everything by the due date.
Grading:
Check out grd_template_lab7.txt to see the break down of how things will
be graded. If this link does not work check back later.
Download