CEG3136DGD2Solution.pdf - CEG 3136 Computer Architecture II...

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

CEG 3136 Computer Architecture II Tutorial 2 Basic Programming - Solution Tutorial 2 Translating C Code to Assembler Fall 2017 1) Complete the translation of the C function to Assembler. /*------------------------------ Function: addByteArray Parameters: arrPt pointer to array num number of elements to sum Description: Adds the contents of an integer array. Assumption: array contains at least one element. ------------------------------*/ int addByteArray(byte *arrPt, byte num) { int sum; sum=0; do { sum=sum+*arrPt++; num--; }while(num != 0); return(sum); } ;-------------Assembler Code------------- ; Subroutine addByteArray ; Parameters arrPt register X ; num register Y ; Results: sum register D ; Description: Adds contents of an integer ; array. addByteArray: PSHX PSHY ; preserve Registers LDD #0 ; sum=0; ; do { loop ADDB 1,X+ ; sum=sum+ ADCA #0 ; *arrPt++; DEY num--; BNE loop ; } while(num != 0); PULY ; restore registers PULX RTS ; return(sum);
Image of page 1

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