Page 307 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 307

284                                 Chapter 9 Implementation of C Procedures


            char *strncpy(char *str_d,char *str_s,int count){char *sd = str d;
        0000088A 3B               PSHD
        0000088B 3B                PSHD
        0000088C EC88             LDD     8,SP
        QQOGQ88E 6C82              STD    2,SP
            51   whi le (count—) {
        00000890 201A              BRA    *+28    ;abs = 08AC
            6:       if(*str_s) *str__d++ = *str_s++;
        00000892 EE86              LDX    6,SP
        00000894 E600              LDAB 0,X
        00000896 270E              BEQ    *+16    ;abs = 08A6
        00000898 EE88              LDX    8,SP
        0000089A ED86              LDY    6,SP
        0000089C E670              LDAB 1,Y+
        0000089E 6B30              STAB 1,X+
        000008AO 6E88              STX    8,SP
        000008A2 6D86              STY    6,SP
        000008A4 2006              BRA    *+8    ;abs = 08AC
            7:       else *str_d++ = '\0';
        000008A6 EE88              LDX    8,SP
        000008A8 6930              CLR 1,X+
        000008AA 6E88              STX    8,SP
            5: while(count—) {
        000008AC EE80             'LDX 0,SP
        000008AE 191F              LEAY -1,X
        000008BO 6D80              STY 0,SP
        000008B2 0475DD            TBNE X,*-32       ;abs = 0892
            9: return (sd);
        000008B5 EC82              LDD    2,SP
           10: }
        000008B7 1B84              LEAS 4,SP
        000008B9 3D                RTS
           13: void main() { strncpy(sl, s2, 5);
        000008BD CC080B            LDD    #2059     ; this is si
        000008CO 3B                PSHD
        000008C1 CE0800            LDX    #2048     ; this is s2
        000008C4 34                PSHX
        000008C5 C605              LDAB #5          ; this is the rightmost argument
        000008C7 87                CLRA
        000008C8 07CO              BSR    *-62    ;abs = 088A
        000008CA 1B84              LEAS 4,SP
           15: }
        000008D2 3D               RTS

                             Figure 9.19. The Strncpy Procedure
   302   303   304   305   306   307   308   309   310   311   312