Homework 8 // Due at lecture Fri, Dec 7
Primary contact for this homework: Pradip Vallathol [pradip16 at cs dot wisc dot 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.
Important notes:
-
Submitted code should be commented; answers without comments will be penalized.
-
Use the "homework8" DropBox in Learn@UW to hand in the code for problems 5. The file should be named hw8_p5.asm. Since your code is tested automatically, it is important to stick to this naming convention, otherwise you will lose credit, even if your code is working correctly.
-
Submit one archive file (*.zip or *.tar.gz) per group to the folder homework8. Add a README.txt file in the archive which contains the names and student IDs of all members of your group.
-
The archive file should be named exactly like: <lastname1><lastname2>[.zip|.tar.gz]
-
You can submit your code for problem 5 as many times as you want, until 11:00 AM on Wednesday, Dec 7, 2012. 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)
Consider the following LC-3 assembly language program which reads a 2 digit number from the keyboard and puts it in register R2. Note that the input is read from the keyboard as ASCII characters. After the execution of the program R2 should have the value of the 2 digit number. For example, if the user enter the characters '2' and '3', R2 will have the value 23 or 0x0017.
Fill in the missing parts of the program marked by ________.
;
; Program to read a two 2 digit decimal number from the keyboard into R2
;
.ORIG x3000
(a)GETC/TRAP x20 ; get first character from keyboard
(b)OUT/TRAP x21 ; print character on screen
LD R6, M30 ; read 0x-30 into R6
(c)ADD R0, R0, R6 ; convert the read character to hex
ADD R1, R0, R0 ; R1 = 2xR0
ADD R2, R1, #0 ; copy R1 into R2
ADD R2, R2, R2 ; R2 = 4xR0
ADD R2, R2, R2 ; R2 = 8xR0
(d)ADD R2, R2, R1 ; R2 = 10xR0
(e)GETC/TRAP x20 ; get second character
(f)OUT/TRAP x21 ; print character on screen
(g)ADD R0, R0, R6 ; convert the read character to hex
(h)ADD R2, R2, R0 ; R2 = decimal number
HALT
M30 .FILL xFFD0 ; -x30
.END
Problem 3 (6 points)
The following LC-3 assembly program takes an input character from the keyboard and prints the input character and the next 9 characters (in ASCII order) to the display. But you will not use TRAP instructions for this this problem. The input character is read by polling the Keyboard Status register and reading from the Keyboard data register. A character is written to the display by polling the Display Status Register and writing the output character to the Display data register. Fill in the missing parts of the program indicated by ______.
;
; Program to print 10 characters starting from an input character.
;
.ORIG x3000
LD R1, NEG ; Load negative of count to R1
POLL1 (a)LDI R2, KSR ; Read Keyboard status register into R2
(b)BRzp POLL1 ; If "ready bit" not set, branch to POLL1
(c)LDI R0, KDR ; Read input character from Keyboard data register to R0
POLL2 (d)LDI R2, DSR ; Read Display status register into R2
(e)BRzp POLL2 ; If "ready bit" not set, branch to POLL2
(f)STI R0, DDR ; Write output character from R0 to Display data register
ADD R0, R0, #1 ; Increment the charater
ADD R1, R1, #1 ; Increment count
BRn POLL2
HALT
NEG .FILL xFFF6 ; -x000A
KSR .FILL xFE00 ; Keyboard status register location
KDR .FILL xFE02 ; Keyboard data register location
DSR .FILL xFE04 ; Display status register location
DDR .FILL xFE06 ; Display data register location
.END
Problem 4 (4 points)
Assemble and run the following program in PennSim. Describe what this program does in 4 sentences or less.
.ORIG x3000
LEA R0, MSG
TRAP x22
LEA R1, FCHAR
ADD R3, R1, 0
LD R2, ENT
NEXT TRAP x20
TRAP x21
ADD R4, R0, R2
BRz OUTPUT
STR R0, R3, 0
ADD R3, R3, 1
BRnzp NEXT
OUTPUT ADD R3, R3, -1
NOT R1, R1
ADD R1, R1, 2
LEA R0, PRINT
TRAP x22
LOOP ADD R4, R1, R3
BRz DONE
LDR R0, R3, 0
TRAP x21
ADD R3, R3, -1
BRnzp LOOP
DONE HALT
MSG .STRINGZ "Please enter a string (max length 8): "
PRINT .STRINGZ "Output: "
ENT .FILL -10
FCHAR .BLKW 10
.END
The program reverses the user input string.
Problem 5 (10 points)
The following LC-3 assembly language program is used to detect if a string is a palindrome or not. The size of the string is fixed at exactly 10 characters and they are stored in memory locations starting from 0x3100. One character is stored in one memory location (the lower order 8 bits represent the ASCII character and higher order 8 bits are 0). For example, if character 'a' is stored at memory location x3101, then the value stored at x3101 will be 0x0061. In this problem, you have to write the subroutine "CHECK" which does the following:
- Checks if the characters at locations specified in registers R1 and R2 are the same.
- If the characters at the locations are the same,
- Set the value of register R6 to 0.
- Print the following message on the console:
"Same character: <character>". (without quotes)
- If the characters at the locations are different,
- Set the value of register R6 to 1.
- Print the following message on the console:
"Different characters: <character at location specified by R1> <character at location specified by R2>".
- Each of the messages should be printed on a new line.
For example:
If the characters at locations specified by register R1 is 'a' and by register R2 is 'a', then register R6 will be set to 0 and the following message will be printed:
Same character: a
If the characters at locations specified by register R1 is 'a' and by register R2 is 'b', then register R6 will be set to 1 and the following message will be printed:
Different characters: a b
To test your code use the scripts, found here. "README.txt" in the zip package contains instructions on how to run the tests and verify your program.
Important: Submit the complete program (NOT the CHECK subroutine alone) in the file named "hw8_p5.asm" to the Dropbox. (Follow the submission guidelines mentioned at the beginning of the homework)
Notes:
- Palindrome is a string that reads the same backward as forward. For example: madam, abbccbba, malayalam, etc.
- You will need to use TRAP instructions to print messages in your subroutine. Recall that every subroutine call or the execution of a TRAP instruction will write the return address into R7. So you will have to save the value of R7, before executing a TRAP instruction, and load the value back into R7 before return.
;
; Program to check if a string is palindrome or not
;
.ORIG x3000
LD R1, START ; load start address into R1
LD R2, LAST ; load end address into R2
LOOP JSR CHECK ; call to CHECK subroutine
ADD R6, R6, #0
BRz YES
NO LEA R0, NOTPAL ; Print NOTPAL and exit
PUTS
BRnzp DONE
YES NOT R5, R1
ADD R5, R2, R5
BRz PRINT ; If completed, print ISPAL
ADD R1, R1, #1 ; We're not done, move 'pointers'
ADD R2, R2, #-1
BRnzp LOOP
PRINT LEA R0, ISPAL
PUTS
DONE HALT
CHECK ST R7, STRET
LDR R3, R1, 0 ; Check if Mem[A] equals Mem[B]
LDR R4, R2, 0
NOT R5, R3
ADD R5, R5, #1
ADD R6, R5, R4
BRz PRINTY
LEA R0, DIFF
PUTS
ADD R0, R3, #0
OUT
LEA R0, SPACE
PUTS
ADD R0, R4, #0
OUT
LEA R0, NLINE
PUTS
BR RETB
PRINTY LEA R0, SAME
PUTS
ADD R0, R3, #0
OUT
LEA R0, NLINE
PUTS
RETB LD R7, STRET
RET
START .FILL x3100
LAST .FILL x3109
STRET .FILL x0000
ISPAL .STRINGZ "The string is a palindrome."
NOTPAL .STRINGZ "The string is not a palindrome."
;
; Add any strings or characters you need
;
.END
|