test2_sum08_sol - ECE 3724 Summer 2008 Solutions Test#2...

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

View Full Document Right Arrow Icon
ECE 3724 Summer 2008 Solutions Test #2 –Reese You may NOT use a calculator. You may use only the provided reference materials. If a binary result is required, give the value in HEX. For any signed right shifts, assume that the sign bit is preserved. Part I: (82 points) a. (4 points) Write a PIC24 assembly language code fragment to implement the following. int32 i32_k; asr k+2 ;MSW first rrc k ;then LSW k = k >> 1; b. (6 points) Write a PIC24 assembly code fragment to implement the following. . int32 i32_k; do { ...operation 1. .. ...operation 2. .. }while (i32_k != 0); ;one solution loop_top: ...operation 1. .. ...operation 2. .. clr W0 ;W0=0 cp0 i32_k cpb i32k_k+2 ;cp with ;borrow to W0 bra NZ, loop_top ;another solution loop_top: ...operation 1. .. ...operation 2. .. mov i32_k, W0 iorf i32_k+2,WREG bra NZ, loop_top
Background image of page 1

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

View Full DocumentRight Arrow Icon
c. (8 points) Write a PIC24 assembly code fragment to implement the following. ;one solution loop_top: mov i16_q,W0 cp i16_p bra LE, loop_exit ;signed branch ...operation 1. .. ...operation 2. .. bra loop_top loop_top: int16 i16_p, i16_q; while (i16_p > i16_q) { ...operation 1. .. ...operation 2. .. } d. (8 points) Implement the strcmp() function given below. Use the working register usage rules for subroutine parameter and locals that we have used in class. A char* is the same as a uint8* in this usage. uint8 strcmp(char* psz_1, char* psz_2) { while ( (*psz_1 != 0) && (*psz_1 == *psz_2) ) { psz_1++; psz_2++ } return(*psz_1 - *psz_2); } ;one solution ; W0 has psz_1, W1 has psz_2, W2 is temp reg strcmp: mov.b [W0],W2 ;W2 = *psz_1 cp0.b W2 bra Z, loop_exit ;exit if *psz_1 ==0 cp.b W2,[W1] bra NZ, loop_exit ;exit if *psz_1!= *psz_2 inc W0,W0 ;psz_1++ inc W1,W1 ;psz_2++ bra strcmp loop_exit: mov.b [W0],W2 ;W2= *psz_1 sub.b W2,[W1],W0 ;W0 = *psz_1 - *psz_2 ;;W0 has return value return
Background image of page 2
e. (8 points) Implement the main() code below in PIC24 assembly. Use the subroutine parameter passing rules we have followed in class. uint8 strcmp(uint8* psz_1, uint8* psz_1)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/15/2009.

Page1 / 9

test2_sum08_sol - ECE 3724 Summer 2008 Solutions Test#2...

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

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