汇编函数调用c程序
程序实例:按键控制led灯
/************************* types.h **************************/
#typedef unsigned char u8;
#typedef unsigned int size_t;
/************************* led_key.c **************************/
//转载请注明原文地址:http://blog.csdn.net/oyhb_1992/article/details/77822877
static int (*printf)(const char *format,...) = (int (*)(const char *format,...))0xc3e11ad0
#define GPM4CON (*(volatile u32 *)0X110002E0)
#define GPM4DAT (*(volatile u32 *)0X110002E4)
#define GPX3CON (*(volatile u32 *)0X11000c60)
#define GPX3DAT (*(volatile u32 *)0X11000c64)
#include "types.h"
void led_init()
{
printf("%s , %s
", __FUNCTION__, __LINE__);
GPM4CON = (GPM4CON & ~0xffff) | 0x1111 ;
}
void led_on(u8 stat)
{
printf("%s , %s
", __FUNCTION__, __LINE__);
GPM4DAT = (GPM4DAT & ~0xf) | (stat & 0xf) ;
}
void delay(size_t delay_count)
{
printf("%s , %s
", __FUNCTION__, __LINE__);
size_t i = 0;
for(i=0;i>2) & 0xf ;
}
/************************* led_key.S **************************/
程序实例:按键控制led灯
.global _start
_start:
mov lr , pc //两条指令可以合为一条bl led_init
b led_init
mov lr , pc
b key_init
loop:
mov lr , pc
b key_stat //获取按键状态
mov lr , pc
b led_on //根据按键状态点亮led灯
b loop
/************************* makefile **************************/
TGT := boot.o
OBJS := start.o
OBJC := led_key.o
CROSS_COMPILER := arm-linux-
CC := $(CROSS_COMPILER)gcc
OBJCOPY := $(CROSS_COMPILER)objcopy
CFLAGS := -ffreestanding
LDFLAGS : -static -nostartfiles -Ttext=0x40000000
all:
$(CC) $(CFLAGS) -c $(OBJC:.o=.S) $(OBJC:.o=.c)#替换后缀,编译生成a.out
$(CC) $(LDFLAGS) $(OBJS) $(OBJC) #链接,_start在哪个文件里哪个文件链接就放前面
$(OBJCOPY) -O binary a.out $(TGT:.o=.bin)
clean:
$(RM) a.out $(OBJC) $(TGT:.o=.bin)