配置環(huán)境
Paste_Image.png
將hello.c下載進開發(fā)板
- 不能運行,因為hello.c里面的頭文件不適用與u-boot
在u-boot下輸入/輸出(輸出)
1.cd ~/1612/1/sq1612/bootloader/u-boot
2.vi include/common.h(看common里面的函數(shù)原型)
3.找到cd ~/1612/1/sq1612/bootloader/u-boot/下的u-boot.map里的pingtf的地址:如下
Paste_Image.png
4.解決hello.c不能運行的問題
5.在sq1612下創(chuàng)建04的文件夾,進入04,然后mkdir 1_hello ,進入1_hello,vim hello.c
Paste_Image.png
6.vi Makefile
Paste_Image.png
Paste_Image.png
7.make好了之后,先檢查網(wǎng)絡(luò)是否連通
Paste_Image.png
Paste_Image.png
在u-boot下輸入
1.找到getc的原型(0x33f965f0)(函數(shù)原型:gedit /include/common.h)
Paste_Image.png
Paste_Image.png
2.新建2_hello 在里面創(chuàng)建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)
4.make一下
5.在下載開始一定要重啟一下開發(fā)板
6.ping 192.168.0.1
7.tftp 0x30000000 hello.bin
8.go 0x30000000
Paste_Image.png
9.common.h在u-boot下輸入:gedit include/common.h
匯編指令
1.以C的形式實現(xiàn)兩書相加
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.以匯編語言的形式實現(xiàn)兩數(shù)相加
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"http://將a的值放到r0中
"mov r1,%2\n"http://將b的值放到r1中
"add r2,r0,r1\n"http://將r0和r1的值進加放入r2中
"mov %0,r2\n"http://將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;
}
3.下載到開發(fā)板
Paste_Image.png
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"http://a存r1
"ldr r0,=0x30008000\n"http://創(chuàng)建一個指針
"str r1,[r0]\n"http://a存入指針
"ldr r2,[r0]\n"http://把指針內(nèi)容給r2
"mov %0,r2\n"http://把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"http://創(chuàng)建指針
"stmia r0!,{r1-r4}\n"http://指定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.條件代碼(兩個數(shù)進行比較)(大的那個數(shù)進行+1)
Paste_Image.png