CS/ECE 252 Introduction to Computer Engineering Spring 2009 All Sections |
Homework
5 // Due at lecture Mar 30, Mon
Primary contact for this homework:
Mengmeng Chen [mchen at cs
dot wisc dot edu]
You may choose to do this homework in a group of TWO or THREE
students or all by yourself. If you do it in a group, each of the group member
should hand in ONE copy of the homework that lists the common section number
and names and UW ID numbers of all the other students. Please staple multiple pages together.
Program
1.
a.
An addressing mode is a mechanism for specifying
where the operand is located.
b.
Memory, register, or part of the instruction
c.
PC-relative mode(memory), register mode(register),
indirect mode(memory), immediate mode(instruction), Base+offset
mode(memory)
d. Register mode
Program
2.
If both R0[15] and R1[15] are 0. (Otherwise
an overflow will happen.)
Program
3.
For LDR, two memory accesses; STI, three memory accesses; TRAP, two memory accesses.
Note that, this
includes one memory access that is needed to load the instruction into IR.
Problem
4.
Suppose the following LC-3 program is loaded into memory starting at location x30FF:
X30FF 1110 0010 0000 0001 R[1] <- x3100 + 1
X3100 0110 0100 0100 0010 R[2] <- MEM[X3101+2] = x1482
X3101 1111 0000 0010 0101 HALT
X3102 0001 0100 0100 0001
X3103 0001 0100 1000 0010
If the program is executed, what is the value in R2 at the end of execution?
Therefore, R2 will be x1482 at the end of the execution.
Problem
5.
Write an LC-3 program that compares two numbers in R2 and R3 and puts the larger number in R1. If the numbers are equal, then R1 is set equal to 0. For this question, you need to hand in your answer electronically. The handin directories have been created for everyone. You should put your code into a ASCII file with the name <yourstudentid>.asm. To hand in your file, follow the next two steps:
1. add the following line to your .cshrc.local file:
set path = ($path /s/handin/bin)
2. Then run the following command:
handin -c cs252-1 -a homework5 -d DIRECTORY
DIRECTORY is the path to the directory where your file for this assignment is located. handin will go through the specified directory and hand in all the necessary files. To check that your files have been copied successfully, look inside the directory ~cs252-1/handin/{yourID}/{ASSIGNMENT_NAME}, and make sure that your file has been copied.
Problem
6.
An LDR instruction, located at x3200, uses R4 as its base register. The value currently in R4 is x4011.
(a)
What is the largest address that this
instruction can load from? x4011+0x001F = 0x4030
(b)
Suppose we redefine the LDR offset to be
zero-extended unsigned number, rather than sign-extended 2’s complement number.
Then what would be the largest address that this instruction could load from? 0x4050 (when offset6 = 111111)
(c)
With the new definition, what would be the
smallest address that this instruction could load from? 0x4011(when offset = 000000)
Problem 7.
The instructions are:
R[1] <- not(R[1])
R[2] <- R[0]+R[1]
R[2] <- NOT(R[2])
Branch
to 0x3100 if result is zero.
Since the control
branch to x3100, we know NOT(R[2]) is zero and
therefore R[2] is 0x1111. And not(R[1])+R[0] is 0x1111
only if R0=R1
Problem
8.
Problem 5.26 on page 149 of ItCS. Do not answer the question (c) and (d). Instead, answer the following two questions:
(a)
16
bit. Since 64K = 2^16.
(b)
The
largest immediate value is 1. We need to use one more bit for Opcode, one more for DR and one more for SR1. So imm5
became imm2.
(c)
Given
the constraints, which instructions can’t be implemented correctly?
ADD(register mode),
AND(register mode)
(For
LDI and other indirect mode instruction, it is actually doable if you always
load two bytes together into the registers. )
(d)
How far
forward and backward can the branch instruction go with this new format?
-128 ~ +127(now is PCoffset8)
Problem
9.
The purpose of this problem is to get you setup with the LC-3 simulator, which will be important for subsequent homework. You can get the LC-3 simulator in one of the following ways:
1. Unsupported PC Use: You can download and extract the LC-3 Simulator on your own personal computer. However, we cannot support any problems encountered and you are on your own. Nevertheless, many students in previous semesters preferred this option. You can find it at http://highered.mcgraw-hill.com/sites/0072467509/student_view0/lc-3_simulator.html
After opening the LC-3 simulator, please report the following: