Linux学习笔记(5)——汇编点灯程序

  1. 汇编源文件

/**
 * led.s
 */

.global _start  /* 全局标号 */

/*
 * _start函数
 */
_start:
    ldr r0, =0x020c4068     /* CCGR0 */
    ldr r1, = 0xFFFFFFFF
    str r1, [r0]

    ldr r0, =0x020c406c     /* CCGR1 */
    str r1, [r0]

    ldr r0, =0x020c4070     /* CCGR2 */
    str r1, [r0]

    ldr r0, =0x020c4074     /* CCGR3 */
    str r1, [r0]

    ldr r0, =0x020c4078     /* CCGR4 */
    str r1, [r0]

    ldr r0, =0x020c407c     /* CCGR5 */
    str r1, [r0]

    ldr r0, =0x020c4080     /* CCGR6 */
    str r1, [r0]

    /* 设置GPIO1_IO03复用为GPIO1_IO03 */
    ldr r0, =0x020E0068
    ldr r1, =0x05
    str r1,[r0]

    /* 配置GPIO1_IO03的IO属性 */
    ldr r0, =0x020E02F4
    ldr r1, =0x10B0
    str r1,[r0]

    /* 设置GPIO1_IO03为输出 */
    ldr r0, =0x0209c004
    ldr r1, =0x08
    str r1,[r0]

1:
    bl led_on
    bl delay
    bl led_off
    bl delay
    b 1b

led_on:
    /* 打开LED */
    ldr r0, =0x0209c000
    ldr r1, =0x00
    str r1,[r0]
    mov pc, lr

led_off:
    /* 关闭LED0 */
    ldr r0, =0x0209c000
    ldr r1, =0x08
    str r1, [r0]
    mov pc, lr

delay:
    ldr r0, =0x0F9E0C
2:
    sub r0, r0, #1
    ;mov r2, #0
    cmp r0, #0
    bne 2b
    mov pc, lr

  1. Makefile文件
led.bin:led.s
	arm-linux-gnueabihf-gcc -g -c led.s -o led.o
	arm-linux-gnueabihf-ld -Ttext 0x87800000 led.o -o led.elf
	arm-linux-gnueabihf-objcopy -O binary -S -g led.elf led.bin
	arm-linux-gnueabihf-objdump -D led.elf > led.dis
.PHONY clean:
	rm -rf *.o *.bin *.elf *.dis

你可能感兴趣的:(Linux)