C程序调用汇编程序

电工技术 2年前 (2024) aysz01
0

    文件strtest.c
    1 #include <stdio.h>
    2 extern void strcopy(char *d, const char *s);
    3 int main()
    4 { const char *srcstr = "First string - source";
    5 char dststr[] = "Second string - destination";
    6 /* dststr is an array since we're going to change it */
    7
    8 printf("Before copying:n");
    9 printf(" '%s'n '%s'n",srcstr,dststr);
    10 strcopy(dststr,srcstr);
    11 printf("After copying:n");
    12 printf(" '%s'n '%s'n",srcstr,dststr);
    13 return 0;
    14 }
    文件scopy.s
    1 AREA SCopy, CODE, READONLY
    2 EXPORT strcopy
    3 strcopy
    4 ; r0 points to destination string
    5 ; r1 points to source string
    6 LDRB r2, [r1],#1 ; load byte and update address
    7 STRB r2, [r0],#1 ; store byte and update address;
    8 CMP r2, #0 ; check for zero terminator
    9 BNE strcopy ; keep going if not
    10 MOV pc,lr ; Return
    11 END

版权声明:aysz01 发表于 2024-07-26 1:43:55。
转载请注明:C程序调用汇编程序 | 鳌游电工

暂无评论

暂无评论...