ループ、strcmp、call printf printstringの例のARMアセンブリ実装



Arm Assembly Implementation



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 'Nameless Fire-_-!!', 0 ANONYMOUS_FIRE2 DCB 'Nameless Fire-_-!!', 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 call printf in ARM 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 }

出力:不明な火災-_- !!こんにちは、arm7!結果= 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