Homework 3

EECS 284
Posted: January 28, 2000
Due: February 3, 2000
 

Learning objectives

 Homework guidelines

 
1
10 points
Suppose we have a memory consisting of 4,096 locations, each location containing 12 bits. 
 a) How many bits are required for an address? 
 b) If we divide this memory into 32 pages, how many bits are required ro represent the page number? 
 c) How many bits specify the location of a word within a page? 
 d) What is the address of the first word on the fourth page?  (Remember that page numbering starts with 0). 
 e) What is the address of the last word on the same page?
 

2
15 points


 a) How many times does the LC-2 use the MAR during processing of the LD instruction? 
 b) How many times during processing of the LDR instruction? 
 c) How many times  during processing of the LEA instruction?

3
10 points


Calculate the maximum number of TRAP service routines that the LC-2 ISA allows.  Show your work, clearly identifying the values on which your calculation depends.
 

4
20 points


Consider the following fragment of an LC-2 Assembly Language program.  
LD R1, Location1    ; x3006
NOT R2, R1          ; x3007
ADD R2, R2, #1      ; x3008
STI R2, Location2   ; x3009
BRz InstrX          ; x300A
BRn InstrY          ; x300B
BRp InstrZ          ; x300C
Suppose that just before this code is executed that Location1 contains  the value xFFF0, Location2 contains x4000, address x3000 contains x56E0, and address x4000 contains x0001.
 a) Which of the instructions set condition codes?  (Identify them by the line numbers at right).
 b) What will be the contents of Location1, Location2, x3000 and x4000 when the code fragment completes execution.
 c) What instruction will be executed next?
 

5
30 points


 a) Write one LC-2 Assembly Language instruction that will set the condition codes based on the contents of register R1 without changing the contents of any of the general-purpose registers.
 b) Suppose we are adding two 16-bit two's complement integers using the instruction ADD R3, R2, R1, and we wish to detect whether overflow occurs.  Write a sequence of Assembly Language instructions that will branch to a location labelled OVERFLOW if the addition operation results in overflow and to a location labelled DONE if the addition operation does not cause an overflow condition. 
 

6
15 points


The LC-2 instruction LDR DR, BaseR, Offset can be broken down into the following constituent operations (called "micro-instructions"):
MAR <- BaseR + Offset
MDR <- mem[MAR]
DR <- MDR
Suppose that the designers of the LC-2 wanted to include an instruction with the Assembly Language format MOVE DR, SR that would copy the contents of the memory location with the address contained in SR and store it into the memory location whose address is in DR.
 a) Using existing LC-2 instructions (from your LC-2 manual or Appendix A of the textbook), write code to carry out a MOVE R0, R1 instruction.  If necessary, use R2 for temporary storage.
 b) List the constituent micro-instructions required to carry out the MOVE instruction.