test1.S
.text
.global test1
@global可以让其他程序调用
test1:
mov r9,lr
mov r6,#10
loop:
ldr r0,=fmt1
bl printf
bl delay
sub r6,r6,#1
cmp r6,#0
beq return_start
@这里如果不等就往下执行b loop,否则执行beq后的
b loop
delay:
mov r5,#0x1000000
temp:
sub r5,r5,#1
cmp r5,#0
bne temp
bx lr
@这里像是退出子程序,返回上一层那样,然后继续回到loop,往下运行sub r6,r6,#1
return_start:
mov lr,r9
bx lr
@这里退出程序,返回上一层是到bootcmd界面
fmt1:
.asciz "yesterday is another day\n\r"
.end
makefile
all:start.bin clean
start.bin:start.o test1.o uart.o libc.a
arm-linux-ld -Ttext=0x40000000 start.o test1.o uart.o libc.a -o start.elf
arm-linux-objcopy -O binary -S start.elf start.bin
arm-linux-objdump -d start.elf > debug
start.o:start.S
arm-linux-gcc -c -nostdlib -nostdinc start.S -o start.o
test1.o:test1.S
arm-linux-gcc -c -nostdlib -nostdinc test1.S -o test1.o
clean:
rm -rf start.o start.elf test1.o
注意其中还需要其他的文件