Homework 8 // Due at lecture Fri, Dec 9
Primary contact for this homework: Rebecca Lam [rjlam@cs.wisc.edu]
You must do this homework in groups of two. Please write the full name and the student id of each member on every pages and staple multiple pages together. Only turn in ONE copy of homework per group.
Important Notes:
Problem 5 requires you to submit your code to the Learn@UW dropbox.
Submission guidelines:
- For your your code submit only one archive file (*.zip or *.tar.gz) per group to the folder homework8.
- Name the file with the following convention: lastname1lastname2.zip or lastname1lastname2.tar.gz
- Your archive file should contain the following (The files MUST be named exactly like this):
- hw8_p5.asm - Assembly code for problem 5
- README.txt - Readme file that contains the names and student IDs for all members of your group
- You can submit your code for problem 5 as many times as you want until 11:00 AM on Friday Dec. 9. After that time we will consider your latest submissions for grading.
Problem 1 (2 points)
After reading the article RFID Inside, answer the following questions with 1 sentence each:
- What are the benefits of RFID tags?
They hold information on identity, physiological characteristics, health, nationality, security clearances for purposes of healthcare, services, etc.
- What are potential problems / issues with RFID tags?
There are concerns regarding privacy, confidentiality, ethics of universal tagging, and body integrity.
Problem 2 (8 points)
Suppose we want to write a program in LC-3 that will be able to take a 16-bit value stored in memory and find the ASCII characters for its hex representation. For instance, we have a value stored at num = 0x12AB. The result should be stored in the memory pointed to by res such as follows: valueAt[res] = 'B' = 0x0042, valueAt[res+1] = 'A' = 0x0041, valueAt[res+2] = '2' = 0x0032, valueAt[res+3] = '1' = 0x0031.
The following program does this task by converting each 4-bit chunk of the 16-bit value into ASCII and storing it into the result array. It has one subroutine rshift, which right shifts the value in R1 by 4 bits and stores it into low4. Fill in the missing parts of the code indicated by ____.
;
; Translate a 16-bit number into hex, ASCII style
;
.ORIG x3000
ld R3, four ; R3 is the counter
ld R1, num
lea R4, res ; R4 = pointer to result
loop and R0, R1, x0F ; Mask the lowest 4 bits
add R2, R0, #-10 ; Check if > 9
brzp alpha
ld R5, numeric ; gets it to the 0-9 range
brnzp next
alpha ld R5, alphabt ; gets it to the A-F range
next add R0, R0, R5
str R0, R4, #0
add R4, R4, #1 ; increment pointer
add R3, R3, #-1 ; decrement counter
brnz end ; stop the loop
jsr rshift ; Right shift R1
ld R1, low4
brnzp loop
end halt
rshift ld R0, twelve ; left shifts R1 by 12 and stores result in low4
and R2, R2, #0
rloop add R2, R2, R2 ; Shift left R2
add R1, R1, #0
brzp skip
add R2, R2, #1
skip add R1, R1, R1 ;Shift left
add R0, R0, #-1
brp rloop
st R2, low4
ret
four .FILL #4
twelve .FILL #12
numeric .FILL #48 ; offset used to get to numeric ASCII range
alphabt .FILL #55 ; offset used to get to alphabetic ASCII range
low4 .BLKW 1
num .BLKW 1
res .BLKW 4 ; where mem[Res] = lowest char to highest
Problem 3 (4 points)
The following program outputs ABCFGH out to the monitor. Fill in the missing parts of code.
.ORIG x3000
LEA R1, TESTOUT
BACK_1 LDR R0, R1, #0
BRz NEXT_1
TRAP x21
ADD R1, R1, #1
BRnzp BACK_1
NEXT_1 LEA R1, TESTOUT
BACK_2 LDR R0, R1, #0
BRz NEXT_2
JSR SUB_1
ADD R1, R1, #1
BRnzp BACK_2
NEXT_2 HALT
SUB_1 ADD R0, R0, #5
K LDI R2, DSR
BRzp K
STI R0, DDR
RET
DSR .FILL xFE04
DDR .FILL xFE06
TESTOUT .STRINGZ "ABC"
.END
Problem 4 (6 points)
What does the following program do, in 4 or less sentences?
.ORIG x3000
LEA R1, HELLO
AGAIN LDR R2, R1, #0
BRz NEXT
ADD R1, R1, #1
BR AGAIN
NEXT LEA R0, PROMPT
TRAP x22
LD R3, NEGENTER
AGAIN2 TRAP x20
TRAP x21
ADD R2, R0, R3
BRz CONT
STR R0, R1, #0
ADD R1, R1, #1
BR AGAIN2
CONT AND R2, R2, #0
STR R2, R1, #0
LEA R0, HELLO
TRAP x22
TRAP x25
NEGENTER .FILL xFFF6 ; -x0A
PROMPT .STRINGZ "Please enter your name: "
HELLO .STRINGZ "HELLO, "
.BLKW #25
.END
Asks user for their name with prompt "Please enter your name:" and echoes whatever the user types. When the enter key is pressed it prints "Hello, ____" where ____ contains the name entered.
Problem 5 (10 points)
Now let's modify the program we wrote in homework 7 problem 5, the countdown timer. You may use your own code from before, or use the provided solution assembly file (Problem 5 Solution). Change the program in the following ways:
- (8 points) Change the timer to handle inputs of two digit hex values (e.g. 1B->1A->19). When representing values less than 0x10, it will display it as 0#. For instance, 9 will be represented as 09.
- (2 points) In addition to the above, modify your code so that the color of the timer output changes to green when the number is less than or equal to 05. For example, if we start our counter with 29, it should be RED when displaying 29 to 06 and GREEN when displaying 05 to 00.
Implement this task with minimal changes to the existing subroutines (it can be done without modifying any subroutines except DISPLAY).
Solution file: (hw8_p5.asm)
Color encoding: Each location holds a 16-bit value which determines the color of that pixel. The high-order bit is ignored, and the remaining 15 bits specify the color, using a 5-bit values for each of red [14:10], green [9:5], and blue [4:0]. The codes of the colors you would need for your program (BLACK and RED) is given to you in the code provided, however if you are curious to know the value for some other common colors, here are a few of them:
Pixel Code |
Color |
x7FFF |
White |
x0000 |
Black |
x7C00 |
Red |
x03E0 |
Green |
x001F |
Blue |
x3466 |
Puce |
|