汇编代码如下:
_start:
ldr r0, =0x11111111
ldr r1, =0xE0200240
str r0, [r1]
ldr r0, =0x0
ldr r1, =0xE0200244
str r0, [r1]
flag:
b flag
Makefile代码如下:
led.bin: start.o
arm-linux-ld -Ttext 0x0 -o led.elf $^
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led_elf.dis
gcc mkv210_image.c -o mkx210
./mkx210 led.bin 210.bin
%.o : %.S
arm-linux-gcc -o $@ $< -c
%.o : %.c
arm-linux-gcc -o $@ $< -c
clean:
rm *.o *.elf *.bin *.dis mkx210 -f
进行make,但是报错,如下:
as -o start.o start.s
start.s: Assembler messages:
start.s:2: Error: no such instruction: `ldr r0,=0x11111111'
start.s:3: Error: no such instruction: `ldr r1,=0xE0200240'
start.s:4: Error: invalid char '[' beginning operand 2 `[r1]'
start.s:6: Error: no such instruction: `ldr r0,=0x0'
start.s:7: Error: no such instruction: `ldr r1,=0xE0200244'
start.s:8: Error: invalid char '[' beginning operand 2 `[r1]'
start.s:10: Error: no such instruction: `b flag'
make: *** [start.o] Error 1
是什么原因呢?
Makefile中的依赖也没有写错,汇编也没有错,为什么编译不了而报错呢?原因很傻瓜,就是因为start.s写错了,后缀名要大写,写成:start.S,就可以编译成功了。
arm-linux-gcc -o start.o start.S -c
arm-linux-ld -Ttext 0x0 -o led.elf start.o
arm-linux-ld: warning: cannot find entry symbol _start; defaulting to 00000000
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led_elf.dis
gcc mkv210_image.c -o mkx210
./mkx210 led.bin 210.bin