整个代码: 间断地响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