0% found this document useful (0 votes)
47 views

ECE 190 - Mon Exam 2 - SP 2012 - v2

The document is an exam for the course ECE 190. It contains instructions for taking the exam, which involves logging into a Linux machine, loading exam files, and writing code in assembly language and C to solve 5 problems. The problems involve writing subroutines to check equality, compute Manhattan distance, count days since January 1st of a given year, compute the sum of memory locations, and compute the area of a triangle. Hints are available for some problems, which reduce the maximum points if viewed.

Uploaded by

Lee Gill
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

ECE 190 - Mon Exam 2 - SP 2012 - v2

The document is an exam for the course ECE 190. It contains instructions for taking the exam, which involves logging into a Linux machine, loading exam files, and writing code in assembly language and C to solve 5 problems. The problems involve writing subroutines to check equality, compute Manhattan distance, count days since January 1st of a given year, compute the sum of memory locations, and compute the area of a triangle. Hints are available for some problems, which reduce the maximum points if viewed.

Uploaded by

Lee Gill
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ECE 190 - Exam 2

Monday, March 26, 2012


Name:

NetID:

Discussion Section (Friday Lab Section): (circle one)


AD1 AD2 AD3 AD4 AD5 AD6 AD7 AD8 AD9 ADA

 Be sure that your exam booklet has 7 pages.


 This is a closed book exam.
 You are allowed two 8.5x11-inch sheets of handwritten notes.
 Absolutely no interaction between students is allowed.
 Do your best!

***START HERE***
1. Log into an EWS Linux machine.
2. Open a terminal window.
3. Run the script to load the exam files into your student directory by typing in the command
line: ~ece190/bin/exam2
4. Appendix A and Appendix D from the textbook are provided for you on the desktop.
5. Write your code in the files indicated by the problem statements. Do not rename the files.
Do not create new files.
6. Hint files are available for some problems. The hints are intended to help you if you get
stuck and don’t know how to start a problem. If you choose to view the hint file for a
problem, the maximum amount of points you can earn on that problem will be reduced. The
point reduction is 7 points on the 20-point problems and 10 points on the 30-point problem
(i.e., a perfect answer would earn 13 out of 20 points or 20 out of 30 points).
7. We are NOT using a subversion repository for the exam. We will grade the saved files that
you leave in your student directory.
Name: _____________________________________________________________ 2

Problem 1: Equality Check (20 points)

Write a subroutine in LC-3 assembly language that checks whether the number in R0 is equal to the
number in R1. If so, R2 should be set to 1. If not, R2 should be set to 0.

The input parameters are stored in R0 and R1.


The output value should be stored in R2.
All registers are callee-save except for R2 (and R7).
The subroutine must start at location x4000.

Your code must go in the given equals.asm file that can be found in your problem1 directory.
Do not create a new file.

Your code will be graded by an autograder. You may receive zero points if your code does not
assemble or behave as specified.
Name: _____________________________________________________________ 3

Problem 2: Manhattan Distance (20 points)

Write a subroutine in LC-3 assembly language that computes the Manhattan distance between two
points (a1,b1) and (a2,b2). The formula for computing Manhattan distance is:

|a1 - a2| + |b1 - b2|

Where |·| indicates absolute value.

The input parameters for the subroutine are as follows:


 R0 contains a1
 R1 contains b1
 R2 contains a2
 R3 contains b2
The output value (the Manhattan distance) should be stored in R5.
All registers are callee-save except for R5 (and R7).
The subroutine must start at location x4000.

Your code must go in the given manhattan.asm file that can be found in your problem2
directory. Do not create a new file.

HINT OPTION:
 The point reduction is 7 points if you view the hint for this problem.
To view the hint, type ./hint from your problem2 directory.

Your code will be graded by an autograder. You may receive zero points if your code does not
assemble or behave as specified.
Name: _____________________________________________________________ 4
Problem 3: Count the Days (20 points)

Write a C function int daynum(int month, int day, int year) which accepts as
input a date and computes the number of days passed since January 1 of that date’s year. (On
January 1, we say that the number of days passed is 1. On January 2, it is 2 days, etc.) The month
input follows this convention: 1 = January, 2 = February, … , 12 = December. You may not use any
libraries to do this computation.

The function must:


1. Return the number of days between the date and January 1 of the year.
2. Return -1 if the date entered is not valid. Assume the year input is always a valid
positive number.

NOTE 1: The months that have 30 days are April, June, November, and September.
The months that have 31 days are January, March, May, July, August, October, December.
February has 29 days in a leap year but only 28 days in a non-leap year.

NOTE 2: The entered year can be a leap year. February 29 is a date that only occurs on leap years.
Provided below is suggested psuedocode to determine whether a year is a leap year:

if year modulo 4 is 0
then
if year modulo 100 is 0
then
if year modulo 400 is 0
then
is_leap_year
else
not_leap_year
else
is_leap_year
else
not_leap_year

Your code must go in the daynum.c file that can be found in your problem3 directory. Do not
create a new file.

To compile your code, type ./compile in your problem3 directory (this script uses the clang
compiler with the C99 standard). You must compile your code in this way.

To run your code, type ./daynum

HINT OPTION:
 The point reduction is 7 points if you view the hint for this problem.
To view the hint, type ./hint from your problem3 directory.

Your code will be graded by an autograder. You may receive zero points if your code does not
compile or behave as specified.
Name: _____________________________________________________________ 5
Problem 4: Compute the Sum (20 points)

Write a subroutine in LC-3 assembly language that computes the sum all of the contents of
memory locations x3100, x3101, x3102, … , x310C and stores the result of this sum in memory
location x310D.

For this subroutine, none of the registers are used for input parameters or output values. Input and
output are given via the memory locations as described above.
All registers are callee-save (except for R7).
The subroutine must start at location x4000.

Three files are given for this problem. They can be found in your problem4 directory.

1. main.asm: This file actually runs the program with the subroutine. DO NOT EDIT THIS
FILE.
2. numbers.asm: This file contains the test numbers for memory locations : x3100, x3101,
x3102, … , x310C. You may edit these numbers if you wish to have different test cases.
3. sum.asm: This file contains the subroutine you will write.

Your code must go in the given sum.asm file that can be found in your problem4 directory. Do
not create a new file or put your solution in either of the other given files.

To run your code, assemble all three files and load the object files into the simulator in the
following order:

1. numbers.obj
2. sum.obj
3. main.obj

HINT OPTION:
 The point reduction is 7 points if you view the hint for this problem.
To view the hint, type ./hint from your problem4 directory.

Your code will be graded by an autograder. You may receive zero points if your code does not
assemble or behave as specified.
Name: _____________________________________________________________ 6

Problem 5: Area of a Triangle (30 points)

Write a subroutine in LC-3 assembly language that computes the area of a triangle given the base
width in R0 and the height in R1. The result must be stored in R3.

The area of a triangle is given by the formula 0.5*base*height. You must calculate the area to be
the largest integer not greater than the actual area. That is, if the area is 33.5, your answer must
be 33. You may assume that the values in R0 and R1 will be positive integers. (Hint: Use what you
know about the multiplication and division subroutines you developed for MP3).

The input parameters are stored in R0 and R1.


The output value should be stored in R3.
All registers are callee-save except for R3 (and R7).
The subroutine must start at location x4000.

Your code must go in the given area.asm file that can be found in your problem5 directory.
Do not create a new file.

HINT OPTION:
 The point reduction is 10 points if you view the hint for this problem.
To view the hint, type ./hint from your problem5 directory.

Your code will be graded by an autograder. You may receive zero points if your code does not
assemble or behave as specified.
Name: _____________________________________________________________ 7

Reference information

LC-3 assembly language problems:

1. To begin work on problem X, use the cd command to get to the problemX directory.
2. To edit the file, type gedit givenfilename.asm &
(Replace “givenfilename” with the name of the file where you will add your code.)
3. Save your work.
4. To assemble your code and produce the object file, type
lc3as givenfilename.asm
5. To run the LC-3 graphical simulator, type lc3sim-tk givenfilename.obj
OR
To run the LC-3 command-line simulator, type lc3sim givenfilename.obj

C language problem:

1. To begin work on problem 3, use the cd command to get to the problem3 directory.
2. To edit the file, type gedit daynum.c &
3. Save your work.
4. To compile your code, type ./compile (this script uses the clang compiler with the C99
standard). You must compile your code in this way.
5. To run your code, type ./daynum

You might also like