配置环境
Paste_Image.png将hello.c下载进开发板
- 不能运行,因为hello.c里面的头文件不适用与u-boot
在u-boot下输入/输出(输出)
Paste_Image.png1.cd ~/1612/1/sq1612/bootloader/u-boot
2.vi include/common.h(看common里面的函数原型)
3.找到cd ~/1612/1/sq1612/bootloader/u-boot/下的u-boot.map里的pingtf的地址:如下
4.解决hello.c不能运行的问题
Paste_Image.png5.在sq1612下创建04的文件夹,进入04,然后mkdir 1_hello ,进入1_hello,vim hello.c
Paste_Image.png Paste_Image.png6.vi Makefile
Paste_Image.png Paste_Image.png7.make好了之后,先检查网络是否连通
在u-boot下输入
Paste_Image.png Paste_Image.png1.找到getc的原型(0x33f965f0)(函数原型:gedit /include/common.h)
2.新建2_hello 在里面创建hello.c
int (*my_scanf)(void);
void (*my_printf)(const char * fmt,...);
int _start()
{
int ch;
my_scanf=(void *)0x33f965f0;
my_printf=(void *)0x33f963a8;
while(1)
{
ch=my_scanf();
if(ch=='q')
{
break;
}
my_printf("%c\n",ch);
}
my_printf("lalalalla\n");
return 0;
}
3.新建Makefile
CC=arm-linux-
TARGET=hello
all:
$(CC)gcc -c $(TARGET).c -o $(TARGET).o
$(CC)ld -Ttext 0x30000000 $(TARGET).o -o $(TARGET)
$(CC)objcopy -O binary $(TARGET) $(TARGET).bin
cp $(TARGET).bin /tftpboot/
clean:
rm /tftpboot/$(TARGET).bin *.o *.bin $(TARGET)
Paste_Image.png4.make一下
5.在下载开始一定要重启一下开发板
6.ping 192.168.0.1
7.tftp 0x30000000 hello.bin
8.go 0x30000000
9.common.h在u-boot下输入:gedit include/common.h
汇编指令
1.以C的形式实现两书相加
void (*my_printf)(const char* fmt,...);
int (*my_getc)(void);
int _start(void)
{
int a,b,c;
my_printf = (void *)0x33f963a8;
my_getc = (void *)0x33f965f0;
a=my_getc();
my_printf("%c\n",a);
a-='0';
b=my_getc();
b-='0';
my_printf("%d\n",b);
my_printf("%d+%d=%d",a,b,c);
return 0;
}
2.以汇编语言的形式实现两数相加
void (*my_printf)(const char* fmt,...);
int (*my_getc)(void);
int _start(void)
{
int a,b,c;
my_printf = (void *)0x33f963a8;
my_getc = (void *)0x33f965f0;
a=my_getc();
my_printf("%c\n",a);
a-='0';
b=my_getc();
b-='0';
my_printf("%d\n",b);
__asm__ __volatile__
(
"mov r0,%1\n"//将a的值放到r0中
"mov r1,%2\n"//将b的值放到r1中
"add r2,r0,r1\n"//将r0和r1的值进加放入r2中
"mov %0,r2\n"//将r2的值赋给c
:"=r"(c)//r0
:"r"(a),"r"(b)//a:r1,b:r2
:"r0","r1","r2"
)
my_printf("%d+%d=%d",a,b,c);
return 0;
}
Paste_Image.png3.下载到开发板
4.ldrstr
void (*my_printf)(const char* fmt,...);
int (*my_getc)(void);
int _start(void)
{
int a,b;
my_printf = (void *)0x33f963a8;
my_getc = (void *)0x33f965f0;
a=my_getc();
my_printf("%c\n",a);
__asm__ __volatile__(
"mov r1,%1\n"//a存r1
"ldr r0,=0x30008000\n"//创建一个指针
"str r1,[r0]\n"//a存入指针
"ldr r2,[r0]\n"//把指针内容给r2
"mov %0,r2\n"//把r2放入b
:"=r"(b)
:"r"(a)
:"r0","r1","r2"
);
my_printf("%c",b);
return 0;
}
Paste_Image.png
5.stmia与ldmstm
void (*my_printf)(const char* fmt,...);
int _start(void)
{
int a,b,c,d;
my_printf = (void *)0x33f963a8;
__asm__ __volatile__(
"mov r1,#0x01\n"
"mov r2,#0x02\n"
"mov r3,#0x03\n"
"mov r4,#0x04\n"
"ldr r0,=0x30008000\n"//创建指针
"stmia r0!,{r1-r4}\n"//指定r0的变化方式
"ldr r0,=0x30008000\n"
"ldmia r0!,{r1-r4}\n"
"mov %0,r1\n"
"mov %1,r2\n"
"mov %2,r3\n"
"mov %3,r4\n"
:"=r"(a),"=r"(b),"=r"(c),"=r"(d)
:
:"r0","r1","r2","r3","r4"
);
my_printf("a=%d,b=%d,c=%d,d=%d",a,b,c,d);
return 0;
}
Paste_Image.png
6.ld
int _start(void)
{
void (*my_printf)(const char* fmt,...);
my_printf = (void *)0x33f963a8;
my_printf("In %s: before bl.\n",__func__);
__asm__ __volatile__(
"bl mytest\n"
);
my_printf("In %s: after bl.\n",__func__);
return 0;
}
void mytest()
{
void (*my_printf)(const char* fmt,...);
my_printf = (void *)0x33f963a8;
my_printf("In %s:in bl.\n",__func__);
}
Paste_Image.png
7.条件代码(两个数进行比较)(大的那个数进行+1)
Paste_Image.png
网友评论