CS/ECE 252 Introduction to
Computer Engineering Spring
2009 All Sections |
Homework 7// Due at lecture Apr 17,
Fri
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.
Problem 1.
Consider the following two instructions in a LC-3 assembly language program:
ASCII LD R0, ASCII
L ST
R0, L
The symbol table entry for ASCII is x4F08.
(a) What will be contained in R0 immediately after the first instruction is executed.
(b) What will be stored at memory location x4F09 after the second instruction is executed.
Problem 2.
Refer to Problem 7.15 on ItCS. Answer the following questions:
(a) What does the program do? (Explain it in less than 25 words.)
(b) Write out the symbol table of the program.
Problem 3.
You are given a string “introductiontocomputersystem” and you are going to write an assembly language program to find a letter that occurs at least three times in the string. Make sure you put your result in R0 and halt your program in the end.
Hint: Use .BLKW to allocate memory to keep track of each letters’
occurrences. Your program should work with arbitrary strings that contain only
lowercase letters.
(a) Draw a flowchart of your program.
(b) Submit a screenshot of your commented code and what is stored in R0 after you run your program on LC-3.
Problem 4.
The following program adds the values stored in the memory
location A, B, and C, and stores the result into memory. There are two errors
in the code. For each, describe the error and indicate whether it will be
detected at assembly time or at run time.
Line No.
1 |
|
.ORIG x3000 |
2 |
ONE |
LD R0, A |
3 |
|
ADD R1, R1, R0 |
4 |
TWO |
LD R0, B |
5 |
|
ADD R1, R1, R0 |
6 |
THREE |
LD R0, C |
7 |
|
ADD R1, R1, R0 |
8 |
|
ST R1M SUM |
9 |
|
TRAP x25 |
10 |
A |
.FILL x0001 |
11 |
B |
.FILL x0002 |
12 |
C |
.FILL x0003 |
13 |
D |
.FILL x0004 |
14 |
|
.END |
Problem 5.
You are given two pieces of program. They have been written by different programmers to store x0015 into memory location x4000.
a.
|
.ORIG x5000 |
|
AND R0, R0, #0 |
|
ADD R0, R0, #15 |
|
ADD R0, R0, #6 |
|
STI R0, PTR |
|
<rest of the program…..> |
|
HALT |
PTR |
.FILL x4000 |
|
.END |
b.
|
.ORIG x4000 |
|
.FILL x0015 |
|
.END |
|
|
(1) Why there are two ‘ADD’ instructions in module (a)?
(2) Explain the fundamental differences in their approaches?
(3) Give one example where module (a) ‘s approach is preferred.