ARM 어셈블리 for 루프, strcmp, printf 인쇄 문자열 호출 예

1585 단어 ARM 어셈블리
utils.S(for 주기, strcmp 구현)
 AREA FIRE, CODE, READONLY
 EXPORT for
 EXPORT strcmp_asm

for
 PUSH {LR}
FOR_LOOP
 BLX R0
 SUBS R1, R1, #0x1
 BNE FOR_LOOP
 POP {LR}
 BX LR

strcmp_asm
 LDRB R2, [R0], #1
 LDRB R3, [R1], #1
 CMP R2, #0
 CMPNE R3, #0
 BEQ return
 CMP R2, R3
 BEQ strcmp_asm
return
 SUB R0, R2, R3
 MOV PC, LR

 END

clac.S(아래에 PRESERVE8이라고 쓴 이유는 무엇입니까?https://blog.csdn.net/heyustudent/article/details/39206155)
 PRESERVE8
 AREA CLAC, CODE, READONLY
 EXPORT asm_add
 IMPORT for
 IMPORT strcmp_asm
 IMPORT _printf


ANONYMOUS_FIRE DCB "    -_-!!", 0
ANONYMOUS_FIRE2 DCB "    -_-!!", 0

asm_test PROC
 NOP
 BX LR
 ENDP

asm_printf
 STMFD SP!, {LR}
 BL _printf
 LDMFD SP!, {PC}

asm_add PROC
 STMFD SP!, {LR}

 LDR R0, =asm_test
 MOV R1, #0x3
 ;BL for

 LDR R0, =ANONYMOUS_FIRE
 ;BL asm_printf
 BL _printf                   ; ARM    printf
 LDR R1, =ANONYMOUS_FIRE2
 BL strcmp_asm

 ;BX LR
 LDMFD SP!, {R1}
 MOV PC, R1
 ENDP

 END

main.c
#include
#include
#include

extern int asm_add(int, int);

int main(int argc, char* argv[]){
	int a = 13;
	int b = 2;
	int result = asm_add(a, b);
	printf("hello, arm7 ! result=%d", result);
	return 0;
}

출력: 무명의 불 - -!!hello, arm7 ! result=26
 
참조:
https://blog.csdn.net/denlee/article/details/2445810?utm_source=blogxgwz9
https://blog.csdn.net/heyustudent/article/details/39206155
https://wenku.baidu.com/view/a0306e974028915f804dc265.html

좋은 웹페이지 즐겨찾기