历史上的今天
今天是:2024年10月11日(星期五)
2018年10月11日 | OK6410裸机学习之汇编调用C函数传参数
2018-10-11 来源:eefocus
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裸板方法汇总
史海拾趣
|
TPS2000系列数字存储示波器 详细资料申请 http://digital.ni.com/worldwide/china.nsf/sb/Download?OpenDocument&node=162000_zhs 样片申请服务(成都国腾微电子)http://www.gticcsssss.com/cn/khfw-ypsq.htm   ...… 查看全部问答> |
|
我要用readline做个命令行,但是在移植readline的时候,make以后编译不通,出现下面的情况 make[1]: Leaving directory `/work/readline/readline-5.2/shlib\' 不知道是啥原因! 帮忙给点意见!^_^ 过程如下: # tar zxf readline-5.2.tar.gz ...… 查看全部问答> |
|
针对丝印器件 反查;本人曾经查找了一些资料,希望用得上 更偏僻的或者新出的产品就得花MONEY买专业材料了 价格不菲 这是其中一款反查界面;… 查看全部问答> |




