整個代碼: 間斷地響5次 BEEPER
知識點:
1: 在C檔案中聲名函數為外部extern
2: 在C檔案裡面的參數聲名, 會直接保在R0~R3(參數小于5個),其它參數儲存在SP指向的棧
3: 在彙編檔案裡面要聲名函數數是可以外部使export
*******************************************
C檔案:
#include"2440addr.h"
extern void delay(int i); //declared extern function
void init(void)
{
rGPBCON = 0x1;
rGPBDAT = 0x0;
rGPBUP = 0x7ff;
}
void change_led_status(void)
{
if(rGPBDAT&0x1)
{
rGPBDAT = 0x0;
}
else
{
rGPBDAT = 0x1;
}
}
int function(int a,int b,int c, int d, int e)
{
int count = 10; // loop 10 times and beeper rings five times
init();
while(count--)
{
change_led_status();
delay(0xfffff);
}
return a+b+c+d+e;
}
*******************************************
彙編檔案:
stack_size equ 0x400
area stack, data, noinit, readwrite, align = 3
stack_men SPACE stack_size
preserve8
export delay ; declared this code section is extern
area asm_to_c , code, readonly
ENTRY
code32
start ldr r0,=stack_men
mov sp, r0
sub sl, sp, #stack_size
bl call_c_function
b stop
call_c_function
import function
str lr, [sp,#-0x4]!
mov r0, #0x1
mov r1, #0x2
mov r2, #0x3
mov r3, #0x4
mov r4, #0x5
str r4, [sp,#-0x4]!
bl function
nop
ldr pc, [sp,#0x4]
delay
sub r0, r0 , #0x1 ; the args saved in r0
cmp r0, #0x0
bne delay
mov pc, lr
stop
b stop
END
轉載于:https://blog.51cto.com/642364/1103660