fall2003-exam2a-soln

fall2003-exam2a-soln - ECE 206-001 NC State University Exam...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 206-001 Name:___________________________________________ NC State University Exam 2 (A) – Nov. 4, 2003 3 1. (21 points) You’re going to write an LC-3 subroutine that shifts the value in R0 to the right. The value in R1 indicates the number of bits to shift. (We’ll assume that R1 holds a value between 1 and 15.) For each box below, write LC-3 assembly language to perform the task indicated in the lefthand column. Some of the boxes are already filled in. Start subroutine at location x3500 .ORIG x3500 Save registers R1, R2, R3, and R4. ST R1, SaveR1 ST R2, SaveR2 ST R3, SaveR3 ST R4, SaveR4 Set R2 = 1. Set R3 = 1. Set R4 = R0. Set R0 = 0. AND R2, R2, #0 ADD R2, R2, #1 ADD R3, R2, #0 ADD R4, R0, #0 AND R0, R0, #0 Shift R2 one bit to the left. L1 ADD R2, R2, R2 Decrement R1. If the result is > 0, go back to the previous box. ADD R1, R1, #-1 BRp L1 AND R4 with R2. If the result is non-zero, add R3 to R0. L2 AND R1, R2, R4 BRz L3 ADD R0, R0, R3 Shift R3 one bit to the left. Shift R2 one bit to the left. If R2 is non-zero, go back to the previous box. ADD R3, R3, R3 ADD R2, R2, R2 BRnp L2 Restore R1, R2, R3, and R4. LD R1, SaveR1 LD R2, SaveR2 LD R3, SaveR3 LD R4, SaveR4 Return to caller. RET ; or JMP R7 Allocate space to save registers SaveR1 .BLKW 1 SaveR2 .BLKW 1 SaveR3 .BLKW 1 SaveR4 .BLKW 1 End of program. .END
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ECE 206-001 Name:___________________________________________ NC State University Exam 2 (A) – Nov. 4, 2003 4 2. (20 points) Using the symbol table to the right, write the corresponding LC-3 machine language word (16 bits, in binary) for each assembly language statement below. Assume in each case that the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

fall2003-exam2a-soln - ECE 206-001 NC State University Exam...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online