



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Equality, Assembly Language, Number, Input Parameters, Output Value, Save Except, Location
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




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!
line: ~ece190/bin/exam
Do not create new files.
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).
you leave in your student directory.
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.
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:
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
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.
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.
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:
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.
Reference information
LC-3 assembly language problems:
C language problem: