hw5-soln - ECE 209 Homework 5 Fall 2007 1(24 points Show...

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

View Full Document Right Arrow Icon
Fall 2007 Homework 5 1. (24 points) Show the LC-3 code generated by a non-optimizing compiler for the following function definition. #define CARDS 52 int findCard(int deck[], int card) { int *ptr = deck; int index = 0; while(index != CARDS) { if (*ptr == card) break; findCard ADD R6, R6, #-1 ; ret val ADD R6, R6, #-1 ; ret addr STR R7, R6, #0 ADD R6, R6, #-1 ; dyn link STR R5, R6, #0 ADD R5, R6, #-1 ; set R5 ADD R6, R6, #-2 ; local vars LDR R0, R5, #4 ; deck STR R0, R5, #0 ; initialize ptr AND R0, R0, #0 STR R0, R5, #-1 ; initialize index WLOOP LDR R0, R5, #-1 ; index LD R1, CARDS NOT R1, R1 AND R0, R0, R1 ; (zero iff equal) BRz DONE LDR R0, R5, #0 ; ptr LDR R0, R0, #0 ; *ptr LDR R1, R5, #5 ; card NOT R1, R1 AND R0, R0, R1 ; (zero iff equal) BRz DONE LDR R0, R5, #0 ; ptr++ ADD R0, R0, #1 STR R0, R5, #0 LDR R0, R5, #-1 ; index++ ADD R0, R0, #1 STR R0, R5, #-1 JMP WLOOP DONE LDR R0, R5, #-1 ; return index STR R0, R5, #3 ADD R6, R6, #2 ; pop locals LDR R5, R6, #0 ; pop dyn link ADD R6, R6, #1
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

hw5-soln - ECE 209 Homework 5 Fall 2007 1(24 points Show...

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

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