This program is implemented with KEIL5.
KEIL4 will set the address of the C program to 0x00000000, that is, the first to run the C program, the parameters are not set. I didn't dig into the mistake, because I was keil5.
You first need to specify the parameters in the assembly code for the C program. If the function requires 4 and 4 of the following parameters, then the parameters we need to assign values in the R0~R3 4 registers can be.
If there are more than 4 parameters, then both parameters are placed in the stack.
Set the address of the SP, which is the stack pointer, and the C function takes the 4th parameter in the stack.
When calling the C function, the C file does not need to declare anything, it is normal C. And the assembly to be in front of the import function name
C Language code:
int SUM (int result,int A,int b,int c,int d,int e,int F { return result = a+b+c+d+e+f; }
Assembly Code:
Area example,code,readonly IMPORT SUM PRESERVE8 ENTRY ARM M OV r0,#0; result MOV r1,#1; a MOV r2,#2; b MOV r3,#3; c LDR SP,=0x40001000MOV r4,#4;d MOV r5,#5; e MOV r6,#6; F stmfd SP!, {R4,R5,R6}; BL SUM; call C END
Assembly Call C Program