start.S汇编源码:
.globl _start
_start:
// 硬件相关的设置
// Peri port setup
ldr r0, =0x70000000
orr r0, r0, #0x13
mcr p15,0,r0,c15,c2,4 @ 256M(0x70000000-0x7fffffff)
// 关看门狗
// 往WTCON(0x7E004000)写0
ldr r0, =0x7E004000
mov r1, #0
str r1, [r0]
// 设置栈
ldr sp, =6*1024
// int xxxxx(int start, int end, int a, int b, int c, int d)
mov r0, #0 // start
mov r1, #8 // end
mov r2, #0 // a
mov r3, #0 // b
// c, d 存在栈里 ,C函数的参数超过4个以后超过的部分存在栈里
// 栈是向下增长的,数据入栈时SP指针先减再存入数据
// 把sp栈顶的位置先减8,对于32位的单片机一个寄存器32位4个字节,减8可以存两个寄存器的值
ldr sp, =6*1024-8;
mov r4, #0
str r4, [sp] // c
mov r4, #1
str r4, [sp, #4] // d ,把参数d的值r4存在sp+4的位置
// 到此sp-8预留的空间已经存入了c、d两个参数
bl xxxxx
halt:
b halt
=====================================================================
led.c源码:
void delay(int a, int b, int c, int d, int e, int f, int g, int h)
{
volatile int i = a+b+c+d+e+f+g+h;
while (i--);
}
int xxxxx(int start, int end, int a, int b, int c, int d)
{
int i = start + a + b + c + d;
volatile unsigned long *gpmcon = (volatile unsigned long *)0x7F008820;
volatile unsigned long *gpmdat = (volatile unsigned long *)0x7F008824;
// gpm0,1,2,3设为输出引脚
*gpmcon = 0x1111;
while (1)
{
*gpmdat = i;
i++;
if (i == end)
i = start;
delay(0, 1, 2, 3, 4, 5, 6, 0x10000);
}
return 0;
}
=====================================================================
Makefile:
led.bin: start.o led.o
arm-linux-ld -Ttext 0 -o led.elf start.o led.o
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led.dis
start.o : start.S
arm-linux-gcc -o start.o start.S -c -O2
led.o : led.c
arm-linux-gcc -o led.o led.c -c -O2
clean:
rm *.o led.elf led.bin led.dis
上一篇:OK6410裸机学习之C语言调用汇编函数
下一篇:烧写OK6410裸板方法汇总
推荐阅读最新更新时间:2024-03-16 16:15