ARM-第四次

作者: 帅碧 | 来源:发表于2017-01-09 20:00 被阅读11次

配置环境

Paste_Image.png

将hello.c下载进开发板

  • 不能运行,因为hello.c里面的头文件不适用与u-boot

在u-boot下输入/输出(输出)

1.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的地址:如下

Paste_Image.png

4.解决hello.c不能运行的问题

5.在sq1612下创建04的文件夹,进入04,然后mkdir 1_hello ,进入1_hello,vim hello.c

Paste_Image.png

6.vi Makefile

Paste_Image.png Paste_Image.png

7.make好了之后,先检查网络是否连通

Paste_Image.png Paste_Image.png

在u-boot下输入

1.找到getc的原型(0x33f965f0)(函数原型:gedit /include/common.h)

Paste_Image.png Paste_Image.png

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)

4.make一下
5.在下载开始一定要重启一下开发板
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的形式实现两书相加

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;
}

3.下载到开发板

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"//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

相关文章

  • ARM-第四次

    配置环境 将hello.c下载进开发板 不能运行,因为hello.c里面的头文件不适用与u-boot 在u-boo...

  • ARM-指针认证

    一、介绍 2016年10月,ARMV8.3-A指令集中加入了指针认证(Pointer Authentication...

  • ARM-第五次

    ARM微处理器的工作状态 处理器状态 1.ARM状态:32位,这种状态下执行的是字方式的ARM指令2.Thumb状...

  • ARM-第六次

    ARM体系结构的数据存储格式 小端:低位放在低地址大端:低位放在高地址 指令长度及数据类型 1.CPU与内存之间的...

  • ARM-第七次

    ### ARM驱动 程序的分种 1.直接运行在硬件上:裸机程序2.只能运行在对应的操作系统上:应用程序 操作系统 ...

  • ARM-第三次

    命令回顾 串口命令 ls -l /dev/ttyUSB0sudo chmod 777 /dev/ttyUSB0mi...

  • ARM-第二次

    回顾烧写过程 如果开发板里已经烧过了的话,就不需要再次进行烧写,只需要如下 插入有转接头的线,在终端中输入:ls ...

  • ARM-第八次

    1.主设备号:表示某类设备2.次设备号:表示某个设备 文件描述符fd 通过文件描述符的下标得到文件指针,通过文件指...

  • 共享单车

    第四次作业 by迷迷萌萌 第四次作业 v2.0

  • 第四次

    第四次

网友评论

    本文标题:ARM-第四次

    本文链接:https://www.haomeiwen.com/subject/vmfhbttx.html