Department of Electrical and Computer Engineering

The University of Texas at Austin

EE 306, Fall 2006
Problem Set 4
Due: Monday October 30th, before class
Instructor: Yale N. Patt
TAs: Aseem Bathla, Cameron Davison, Lisa de la Fuente, Phillip Duran, Jose Joao,
        Jasveen Kaur, Rustam Miftakhutdinov, Veynu Narasiman, Nady Obeid, Poorna Samanta.


You are encouraged to work on the problem set in groups and turn in one problem set for the entire group. Remember to put all your names on the solution sheet. Also remember to put the name of the TA in whose discussion section you would like the problem set turned back to you.


  1. If a computer has a 16-bit MAR and a 32-bit MDR:

    1. How many memory locations are available in the memory of this computer?
    2. How many bits are stored at each of those locations?
    3. What is the total size of the memory (in Bytes)?
  2. (Prob 5.5)

    1. What is an addressing mode?
    2. Name three places an instruction's operands might be located.
    3. List the five addressing modes of the LC-3, and for each one state where the operand is located (from part b).
    4. What addressing mode is used by the ADD instruction shown in Section 5.1.2?
  3. (Prob 5.9)

    We would like to have an instruction that does nothing. Many ISAs actually have an opcode devoted to doing nothing. It is usually called NOP, for NO OPERATION. The instruction is fetched, decoded and executed. The execution phase is to do nothing! Which of the following three instructions could be used for NOP and have the program still work correctly?

    1. 0001 001 001 1 00000
    2. 0000 111 000000001
    3. 0000 000 000000000

    What does the ADD instruction do that the others do not do?

  4. Which of the two algorithms for multiplying two numbers is preferable and why?

    4 * 48 = 4 + 4 + 4 + 4 + ... + 4 or 48 + 48 +48 +48?

  5. The LC-3 does not have an instruction to perform an OR. Write a LC-3 machine language program segment that takes the values in R1 and R2 and stores the OR of the two operands (R1 OR R2) in R3.

  6. (Adapted 5.13)

    1. How might one use a single LC-3 instruction to move the value in R2 into R3?
    2. Using only one LC-3 instruction and without changing the contents of any register, how might one set the condition codes based on the value that resides in R1?
    3. Write an LC-3 instruction that clears the contents of R2.
  7. (5.17)

    How many times does the LC-3 make a read or write request to memory during the processing of the LD instruction? Answer the same question for the LDR, LDI, and LEA instructions. Processing includes all phases of the instruction cycle.

  8. (5.24)

    An LDR instruction, located at x3200, uses R4 as its base register. The value currently in R4 is x4011. What is the largest address that this instruction can load from? Suppose we redefine the LDR offset to be zero-extended, rather that sign-extended. Then what would be the largest address that this instruction could load from? With the new definition, what would be the smallest address that this instruction could load from?

  9. (5.30)

    The following table shows a part of the LC-3s memory:

    0011 0001 0000 00001001 001 001 111111
    0011 0001 0000 00010001 010 000 000 001
    0011 0001 0000 00101001 010 010 111111
    0011 0001 0000 00110000 010 111111100

    State what is known about R1 and R0 if the conditional branch redirects control to location x3100.

  10. The following LC-3 Machine Language program is supposed to multiply the contents of R1 with R2 and store the result in R3. The program assumes that both R1 and R2 contain positive integers. However, there is an error in the program.

    x3000:0101 0110 1110 0000
     0001 0110 1100 0010
     0001 0010 0111 1111
     0000 0111 1111 1101
     1111 0000 0010 0101
    1. What is the error?
    2. Modify the present program to make it work correctly
  11. (Adapted 7.16)

    Assume a sequence of nonnegative integers is stored in consecutive memory locations, one integer per memory location, starting at location x4000. Each integer has a value between 0 and 30,000 (decimal). The sequence terminates with the value -1 (i.e., xFFFF).

    a. Create the symbol table entries generated by the assembler when translating the following routine into machine code:

    	.ORIG 	x3000
    	AND 	R4, R4, #0
    	AND 	R3, R3, #0
    	LD 	R0, NUMBERS
    LOOP	LDR 	R1, R0, #0
    	NOT 	R2, R1
    	BRz 	DONE
    	AND 	R2, R1, #1
    	BRz 	L1
    	ADD 	R4, R4, #1
    	BRnzp 	NEXT
    L1	ADD 	R3, R3, #1
    NEXT	ADD 	R0, R0, #1
    	BRnzp 	LOOP
    DONE	TRAP 	x25
    NUMBERS	.FILL 	x4000

    b. What does the above program do?

  12. Draw a flow chart for the following problem. It should be as specific as possible, similar to Figure 6.3 (e) page 161.

    You are given 16 numbers stored in memory from location x3100 to x310F. Your program should take each number and left shift (not rotate) it until the most significant bit becomes 1, and then store this result back in the same location. This action is very useful in floating point processing, it can be used to normalize a result.

    If the original contents of memory location x3100 was 0000 1010 0000 0011, then your program should store 1010 0000 0011 0000 in x3100.
    If the original contents of memory location x3101 was 1111 0000 1111 0000, then your program should store 1111 0000 1111 0000 in x3101

    Hint: You do not know the number of times you have to left shift each number. Think about how to decide that.

    Note: You can assume that the numbers stored in memory locations x3100 to x310F will not be zero.

    You are required to make the flowchart only!