Computer Sciences Dept.

CS/ECE 252 Introduction to Computer Engineering

Spring 2013 Section 1 & 2
Instructors Mark D. Hill and Guri Sohi
TAs Preeti Agarwal, Mona Jalal, Rebecca Lam, Pradip Vallathol

URLs: http://www.cs.wisc.edu/~markhill/cs252/Spring2013/ and http://www.cs.wisc.edu/~sohi/cs252/Spring2013/

Homework 8 [Due at Lecture on Fri, May 3]

Primary contacts for this homework: Rebecca Lam [rjlam@cs.wisc.edu] and Pradip Vallathol [pradip16@cs.wisc.edu]

You should do this homework in groups of two. Please hand in ONE copy of the homework in to the homework8 dropbox at Learn@UW. See the submission guidelines below.

Important Notes:

This homework must be submitted electronically to the Learn@UW dropbox. No hard copies will be accepted. Turn in problems 1-5 as a single PDF document and problems 6 and 7 as .txt files (see the submission guidelines below). List the full names and UWIDs of all members in your group in the PDF document and also in the comment section of your submission.

Submission guidelines:

Please adhere to the following submission guidelines strictly. You will be penalized if your submission violates any of these.

  • Submit only one set of files per group to the folder homework8.
  • List the full names and UWIDs of all members in your group in the comment section when submitting your files.
  • Submit the following files to the dropbox. (The files MUST be named exactly like this):
    • hw8_p1-5.pdf - Answers for questions 1-5 in PDF format
    • hw8_p6.txt - The assembly code for problem 6
    • hw8_p7.txt - The assembly code for problem 7

Submission deadline:

You may submit your files as many times as you want until the end of lecture of your registered section (i.e., 10:45 AM for Section 1 and 3:15 PM for Section 2) on Friday, May 3. After that time we will consider your latest submissions for grading.

Submit problems 1-5 as a single pdf document named "hw8_p1-5.pdf". List the full names and UWIDs of each group member in this file and in the comment section of your dropbox submission.

Problem 1 (2 points)

After reading the article RFID Inside, answer the following questions:

  1. List two benefits of RFID tags.
  2. List two potential problems/issues with RFID tags.

Problem 2 (2 Points)

Assemble and run the following program in PennSim. Describe what this program does (a high level overview) in 1-2 sentences.

        .ORIG x3000 
        LEA R0, MSG
        TRAP x22
        LEA R1, FCHAR
        ADD R3, R1, 0
        AND R2, R2, 0
        ADD R2, R2, -8

NEXT    TRAP x20
        TRAP x21

        STR R0, R3, 0
        ADD R3, R3, 1
        ADD R2, R2, 1
        BRnp NEXT

        LD  R0, ENTER
        TRAP x21

OUTPUT  ADD R2, R2, -4
        LEA R0, PRINT
        TRAP x22

LOOP    LDR R0, R1, 0
        TRAP x21
        ADD R1, R1, 2
        ADD R2, R2, 1
        BRnp LOOP

        LD  R0, ENTER
        TRAP x21

DONE    HALT

MSG    .STRINGZ  "Enter a string (exactly 8 characters): "
PRINT  .STRINGZ  "Output: "
ENTER  .FILL   10
FCHAR  .BLKW   10
       .END

Problem 3 (4 Points)

Suppose we load the LC-3 with a new service routine called GETS which is the equivalent to calling TRAP 0x50. If we suppose that the subroutine code for GETS starts at memory address 0x0450,

  1. What is the address of the trap vector table entry that is accessed when GETS is called?
  2. What is the value of the trap vector table entry that is accessed when GETS is called?
  3. What must be the last assembly instruction in the trap subroutine code?
  4. How many accesses to memory are made during the EXECUTE phase of a TRAP instruction, assuming the TRAP instruction is already in the IR?

Problem 4 (4 Points)

Answer the questions below for the following program using 1-2 sentences.The intended operation of the program is to loop 3 times, adding R0 and R1 to the value stored at RES. R0 and R1 start with the values at X and Y, respectively, and are incremented by 1 for each execution of the loop.

        .ORIG x3000
        LD  R0, X
        LD  R1, Y
        LD  R2, CNT
LOOP    JSR SUB1
        JSR SUB2
        ADD R2, R2, #-1
        BRp LOOP
        HALT

CNT     .FILL   3
X       .FILL   1
Y       .FILL   2
RES     .FILL   0

SUB1    ST  R2, TMP_R2
        LD  R2, RES
	ADD R2, R2, R0
        ADD R2, R2, R1
        ST  R2, RES
        LD  R2, TMP_R2
        RET

SUB2    ST  R0, TMP_R0
        ST  R1, TMP_R1
        ADD R0, R0, #1
        ADD R1, R1, #1
        ADD R7, R7, #-1
        RET

TMP_R0  .BLKW   1
TMP_R1  .BLKW   1
TMP_R2  .BLKW   1
TMP_R7  .BLKW   1
  1. For SUB1 and SUB2, identify whether it is a callee-save or caller-save subroutine and explain why.
  2. There a problem with the above program. Identify the error and how to fix it.

Problem 5 (4 points)

The below program displays the 16-bit binary representation of a number stored at NUM by printing out the character representation of each bit from the most significant bit to the least significant bit. Fill in the blanks below.

        .ORIG x3000
        AND R3, R3, 0
        ADD R3, R3, 15
        LD R1, NUM
LOOP    LD R0, ZERO
        ADD R1, R1, 0
        BRzp DISP
        (a)______________   
        DISP    LDI R2, DSR
        (b)______________
        STI R0, DDR
        (c)______________   ; Left shift
        ADD R3, R3, -1
        BRzp LOOP       ; Stop if negative
        HALT

NUM     .BLKW 1
ZERO    .FILL (d)_____      ; '0' character
DSR     .FILL (e)_____
DDR     .FILL xFE06

    .END

Problem 6 (6 Points)

Write an LC-3 assembly program using the template file (hw8_p6.txt) that prompts the user for a number from 0 to 9 by displaying the message "Enter a number from 0 to 9: ". If the number is even, the program prints "Even" and if the number is odd, the program prints "Odd" and terminates. Otherwise, it displays the message "Invalid input" and again prompts the user with "Enter a number from 0 to 9: ".

To test your code use the script, found here. "README.txt" in the zip package contains instructions on how to run the tests and verify your program.

Grading:

2 points per test case.

  • Prints "Odd" when number is odd and terminates.
  • Prints "Even" when number is even and terminates.
  • Displays message "Invalid Input" when something other than a number is entered and prompts the user again for input.

Problem 7 (8 points)

For this problem you will be modifying the program from homework 7 problem 6, the connect-four game. You may either use your own code from before or the provided solution (hw7_p6_sol.txt). In either case, make sure you rename your solution file to hw8_p7.txt

Change the program in the following ways:

  1. (5 points) Modify the CHECKEND subroutine so that it will check for a diagonal win
  2. (3 points) Modify the CHECKEND subroutine so that it will check for a win in each row (horizontal direction)

To test your code use the script, found here. "README.txt" in the zip package contains instructions on how to run the tests and verify your program. There are some changes that you need to make before you are able to run the tests. So make sure you go through the README.txt file.

Grading:

  • Diagonal win check:
    • 1 pt *ooo : Correctly identifies win when the current piece was placed on the low end of the winning sequence
    • 1 pt o**o : Correctly identifies win when the current piece was placed on one of the non-end spots of the winning sequence
    • 1 pt ooo* : Correctly identifies win when the current piece was placed on the high end of the winning sequence
    • 2 pts : Correctly identifies wins in both diagonal directions \ and / (slanting left and slanting right)
  • Row win check:
    • 1 pt *ooo : Correctly identifies win when the current piece was placed on the left end of the winning sequence
    • 1 pt ooo* : Correctly identifies win when the current piece was placed on the right end of the winning sequence
    • 1 pt o**o : Correctly identifies win when the current piece was placed in one of the non-end spots of the winning sequence

 
Computer Sciences | UW Home