arm汇编学习(一)

之前断断续续看ARM,啥也没学到的感觉。开始系统学习arm,坚持下来,从arm开发环境,到arm模拟器实际运行。GNU AS汇编编译语法

摘自skyeye arm_hello的代码
start.S:

#define MODE_SVC 0x13
#define I_BIT   0x80
.text
        .align 4
        .global begin
        .type begin, function
begin:
        /*disable I-bit*/
        mov     r0, #I_BIT|MODE_SVC 

        msr     cpsr_c, r0    //设置状态寄存器,I位为1,禁止IRQ中断

        ldr         sp, =irq_stack           @ set sp_irq = irq_stack

        bl        hello   //跳转到hello,子程序调用
        b        begin   //又跳转到begin                        
.data
        .align  4
irq_stack:
        .space        4096

 

hello.c:

#define BOGO_MIPS 1000000
void hello(void)
{        
        int i;
        char * hellostr="helloworld";
        long* paddr=(long*)0xfffd001c;  //因为AT91的UART0的基址为0xfffd0000,USART发送寄存器US_THR的偏移量是0x1c。所以向0xfffd001c地址写入字符就是向串口发送字符。Skyeye就会把字符打印到屏幕上
        int timeout ;
        while(1){
                timeout = 0;
                while(++timeout != BOGO_MIPS);
                for(i=0;i<10;i++)
                {
                        * paddr=hellostr[i];
                }
        }
        return;        
}

 

hello.lds:

OUTPUT_ARCH(arm)
ENTRY(begin)    //符号begin设置为入口地址
SECTIONS
{
        . = 0x1000000;   //当前地址为0x1000000
        .text : 
        {
                *(.text) 
                *(.rodata)
        }


        . = ALIGN(8192);

        .data : {*(.data)}

        .bss : {*(.bss)}


        /* Stabs debugging sections.    */
        .stab 0 : { *(.stab) }
        .stabstr 0 : { *(.stabstr) }
        .stab.excl 0 : { *(.stab.excl) }
        .stab.exclstr 0 : { *(.stab.exclstr) }
        .stab.index 0 : { *(.stab.index) }
        .stab.indexstr 0 : { *(.stab.indexstr) }
        .comment 0 : { *(.comment) }
        .debug_abbrev 0 : { *(.debug_abbrev) }
        .debug_info 0 : { *(.debug_info) }
        .debug_line 0 : { *(.debug_line) }
        .debug_pubnames 0 : { *(.debug_pubnames) }
        .debug_aranges 0 : { *(.debug_aranges) }

}

 

Makefile:

    CC=arm-elf-gcc

    LD=arm-elf-ld

    CFLAGS= -c -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -pipe -g -mapcs-32 -march=armv4 -mtune=arm7tdmi 
    LDFLAGS= -N -p -X -Thello.lds
    LIB=    
    all: hello 
    hello: start.o hello.o
        $(LD) $(LDFLAGS)  start.o hello.o -o hello
        arm-elf-objdump -xS hello > hello.s
        arm-elf-readelf -a hello > hello.r
        arm-elf-nm hello > hello.n 
    start.o:start.S
        $(CC) $(CFLAGS) start.S         
    hello.o:hello.c
        $(CC) $(CFLAGS) hello.c
    clean:
        rm -rf *.o *.elf *.gdb hello *.r *.n *.s

 

refer link:
skyeye安装文章
http://blog.csdn.net/keyboardota/article/details/6864155
http://jaist.dl.sourceforge.net/project/skyeye/skyeye-documentation/skyeye-1.3.2_rc1/skyeyev3_usermanual-v6.pdf

ARM汇编开发环境,不用IDE环境,使用arm-elf-tools交叉编译环境
http://opensrc.sec.samsung.com/download.html 下载arm-elf-tools-20040427.sh
http://www.360doc.com/content/10/1206/22/1378815_75660576.shtml
http://wenku.baidu.com/view/d14e7a791711cc7931b7165d.html

ARM汇编编写
http://blog.csdn.net/dndxhej/article/details/7487264
http://blog.csdn.net/tigerjb/article/details/6201716
http://blog.chinaunix.net/uid-22315114-id-99977.html   ldr mov区别
http://wenku.baidu.com/view/19ba4b6f7e21af45b207a800.html skyeye实例解析

posted @ 2013-04-17 18:01  yarpee  阅读(828)  评论(0编辑  收藏  举报