10.07.2015 Views

PDF version - ARM Information Center

PDF version - ARM Information Center

PDF version - ARM Information Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C, C++ 및 어셈블리 언어 조합C에서 어셈블리 언어 호출예제 4-4와 예제 4-5에서는 어셈블리 언어 서브루틴을 호출하여 한 문자열을 다른 문자열의 맨 위에 복사하는 C 프로그램을 보여 줍니다.예제 4-4 C에서 어셈블리 언어 호출#include extern void strcopy (char *d, const char *s) ;int main (){ const char *srcstr = "First string - source ";char dststr[] = "Second string - destination ";/* dststr is an array since we’ re going to change it */printf ("Before copying:\n") ;printf (" %s\n %s\n",srcstr,dststr) ;strcopy (dststr,srcstr) ;printf ("After copying:\n") ;printf (" %s\n %s\n",srcstr,dststr) ;return (0) ;}예제 4-5 어셈블리 언어 문자열 복사 서브루틴PRESERVE8AREA SCopy, CODE, READONLYEXPORT strcopystrcopy; R0 points to destination string.; R1 points to source string.LDRB R2, [R1],#1 ; Load byte and update address.STRB R2, [R0],#1 ; Store byte and update address.CMP R2, #0 ; Check for null terminator.BNE strcopy ; Keep going if not.BX lr ; Return.END예제 4-4는 예제 디렉토리의 ...\asm에 strtest.c 및 scopy.s라는 이름으로 포함되어 있습니다.명령 행에서 예제를 빌드하려면 다음 단계를 수행하십시오.1. armasm --debug scopy.s를 입력하여 어셈블리 언어 소스를 빌드합니다.2. armcc -c --debug strtest.c를 입력하여 C 소스를 빌드합니다.4-10 Copyright © 2002-2008 <strong>ARM</strong> Limited. All rights reserved. <strong>ARM</strong> DUI 0203IKNon-ConfidentialUnrestricted Access

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!