Thu, 2 Dec 2021, 23:55 Re: 2019 Final Exam Problem



A student writes:


> Good evening, Dr. Patt, I'm ************************, and I have questions
> concerning 2019 Final Exam. Could you show me how to do problem 7 please? I
> don't quite understand what the problem is asking me to do. Thank you!
> 
> Best,
> <<name withheld to protect the student not clear what the problem is asking>>


Thanks for the question.  This is not an easy question.  I will try to help, 
but realistically, my 6 TAs can probably help you more quickly than I can 
since there are six of them and one of me.  ...and I appreciate that time is 
of the essence.  In any case, let me at least get you started.

In part a, you are given a piece of code and asked what does this piece of 
code do.  Your job  is to follow the code, until you figure out what the code
is doing.  I have generally found that the best way to handle that sort of
problem is to break the program into pieces and see if I can figure out
what each piece does.  A good starting point might be to look at the piece
starting with the the instruction labeled LOOP until the instruction BRnzp LOOP.
What does each iteration do?  What does the entire sequence do until you finally
get to "BRn DONE" with n = 1.  Then you look at what happens after you get to 
DONE.  The answer is supposed to jump out at you!

If it doesn't, perhaps the next step is to note that before the subroutine 
executed, values were loaded into R0 and R1.  Before we get to LOOP, we did
something to R1.  Why?  We also notice that after we get to DONE, we again did
something to R1.  Why?  Do you now see what is going on?

In part b, you have (in addition to the piece of code) a table consisting of 
8 entries where each entry is associated with a state and the clock cycle that 
that state is in.  Since you know the state machine for the LC-3, you know 
which state the machine is in in cycle 1 (answer: state 18), cycle 2, ...until 
the program completes execution.

Your job in part b is to provide the control signals needed to carry out the
work of each of the 8 states.  You are also asked to identify the state and
the cycle in which it occurs.  We start with the first entry.  In this case,
it is the first cycle of the machine, and of course that is state 18, the
first clock cycle of the fetch phase of the first instruction.

You know that state 18 does two things: MAR <-- PC and PC <-- PC +1.
You are asked to fill in the control signals to make that happen.  Why is
GateALU = 0 in state 18.

The 2nd entry shows the state as 3.  You are asked in which clock cycle 
is state 3.  If you follow the state machine for the first instruction, you
see that you are in state 3 in cycle 10.  You look at what goes on in state 3
and assign control signals accordingly.  

In the next clock cycle after cycle 10, you can see from the state machine
that you go to state 23.  By going back and forth between the code and the
state machine and the table, you should be able to fill in all the blanks.

Hope that helps.  Good luck with Lab 5 and with the final exam.

Yale Patt