



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Spring 2011
Practice Exam
Notes: Programming part of the exam will consist of three problems. Each problem will be graded separately. We will provide skeleton codes for each problem.
Problem 1 (10 points): Warm-up.
After reading the MP3 handout Kirti discovered that the 16 x 16 "Life" board was not big enough to hold the extremely fun PULSAR pattern. Sam was so disappointed in our failure that he has asked you to write the new gold code for the CALC_ADDR routine.
Implement a subroutine that multiplies an input by 17 using only 5 non-looping/branching instructions, then adds x5000 and R1.
Inputs: R0, R1 (will always be between 0 and 16, no need to do a modulus or any other looping operation to ensure the input is in range) Outputs: R2 = 17 * R1 + R0 + x Description: Callee saves all registers (does not count against 5 instruction limit). Uses 5 non-looping instructions to perform a mult. by 17. The table starts at x Use the following skeleton code is provided to get you started:
; “main” function .ORIG x AND R0, R0, # ADD R1, R0, #4 ; R1 <- 4 as an example ADD R0, R0, #5 ; R0 <- 5 as an example JSR CALC_ADDR HALT ; CALC_ADDR ; your code starts here
RET ; end of CALC_ADDR function ; any data fields to be allocated here ; .END
Problem 2 (5 points): Debugging.
This program is given a 200x200 matrix of cells, one cell per memory location starting at x in row-major layout, and prints out a message indicating if there is a cell containing xFFFF. The program, however, has several bugs. Find and fix them!
.orig x
; r0: address of matrix cell ; r1: size ; r2: size * size ; r3: addition counter in multiply ; r4: data in matrix cell
ld r0, base_address ld r1, size
; r2 <- r1 * r add r3, r1, # multiply brz exit_multiply add r2, r2, r add r3, r3, #- br multiply exit_multiply
; find cell containing 0xffff in matrix iterate add r2, r2, #- brn exit_iterate ldr r4, r0, # add r0, r0, # add r4, r4, # brnp iterate ld r0, success puts halt exit_iterate
ld r0, failure puts halt
size .fill # base_address .fill x
success .stringz "Found it!\n" failure .stringz "Didn't find it.\n"
.orig x MAIN ; Set all of the table to x LD R1, LOOP LD R2, PRIME AND R3, R3, # ADD R3, R3, # INIT_START ; CC Check ADD R1, R1, # BRn INIT_END
; Load table with x STR R3, R2, # ADD R2, R2, #
; Decrement and loop ADD R1, R1, #- BRnzp INIT_START INIT_END
; Call ITER LD R7, ITER JSRR R
; Print string LEA R0, STRING PUTS
; Loop through and print the prime numbers table LD R1, LOOP LD R2, PRIME LD R3, ASCII LOOP_START ; Condition code check ADD R1, R1, # BRn LOOP_END
; Load data from table LDR R0, R2, # ADD R2, R2, #
; Convert to ASCII ADD R0, R0, R ; Print out OUT
; Print space LD R0, SPACE OUT
; Every 16 entries, print newline AND R4, R1, # BRnp NO_PRINT ; Print new line AND R0, R0, # ADD R0, R0, # OUT NO_PRINT
; Loop update ADD R1, R1, #- BRnzp LOOP_START LOOP_END
HALT ASCII .fill x SPACE .fill x LOOP .fill x00FF ITER .fill x SIEVE .fill x PRIME .fill x STRING .stringz "\nPRIME NUMBERS TABLE\n"
.end
; Register Table ; R0 - ; R1 - ; R2 - ; R3 - ; R4 - ; R5 - ; R6 - ; R7 - .orig x ITER RET
LOOP .fill x00FF SIEVE .fill x
.end