Hi Experts,I have just started with ARM assembly, I have written a program in assembly for toggling GPIO. The issue that I am facing is that the code works when I use several "nop" in place of "bl delay". The code goes below:
.equ IODIR0, 0xE0028008 .equ IOCLR0, 0xE002800C .equ IOSET0, 0xE0028004 delay: mov r0, #10 dowaitloop: subs r0,#1 bne dowaitloop bx lr MOV r3, #0xFFFFFFFF LDR r4, =IODIR0 LDR r1, =IOCLR0 LDR r2, =IOSET0 str r3, [r4] loop: str r3, [r1] bl delay str r3, [r2] bl delay b loop
Commands that I execute to compile:arm-none-eabi-as -gcoff -o blinky.o blinky.sarm-none-eabi-ld -e0x00000000 -Ttext=0x00000000 -o blinky.elf blinky.o
arm-none-eabi-objcopy -Oihex blinky.elf blinky.hex
Hi, could I ask the start point of your program? If it was 'delay:', the program would not work correctly because the branch target of 'bx lr' would be unknown. How about putting the delay function below the 'b loop'? Best regards, Yasuhiko Koumoto.
Hello Yasuhiko,
Thanks a lot for your reply, moving the 'delay:' subroutine below 'bl loop' did the trick; the entry of my program is from 0x00.
Now I am providing entry symbol '_start' but the code doesn't seem to work.
Can we not write any function above entry symbol in assembly like this below:
.global _start .equ IODIR0, 0xE0028008 .equ IOCLR0, 0xE002800C .equ IOSET0, 0xE0028004 delay: mov r0, #10 dowaitloop: subs r0,#1 bne dowaitloop bx lr _start: MOV r3, #0xFFFFFFFF LDR r4, =IODIR0 LDR r1, =IOCLR0 LDR r2, =IOSET0 str r3, [r4] loop: str r3, [r2] bl delay str r3, [r1] bl delay b loop
The above code doesn't work; but when I move 'delay:' below 'b loop' it works.If we cannot write any function above(before) entry symbol '_start:' then why is it so?I am executing below commands to create hex file:
arm-none-eabi-as -o blinky.o blinky.s arm-none-eabi-ld -Ttext=0x0 -o blinky.elf blinky.o arm-none-eabi-objcopy -Oihex blinky.elf blinky.hex
Hi,
the _start symbol would be useless because there is no means to initiate from the _start.
If you use assembler, you had better put the vector table from the address 0x0.
The program will begin with the address 0x0.
For exsample:
.global _start .equ IODIR0, 0xE0028008 .equ IOCLR0, 0xE002800C .equ IOSET0, 0xE0028004 .text b _start b undef_handler b SVC_handler b PAbt_handelr b DAbt_handler b RFU_handler b IRQ_handler b FIQ_handler undef_handler: SVC_handler: PAbt_handelr: DAbt_handler: RFU_handler: IRQ_handler: FIQ_handler: b undef_handler /* do nothing */ delay: mov r0, #10 dowaitloop: subs r0,#1 bne dowaitloop bx lr _start: MOV r3, #0xFFFFFFFF LDR r4, =IODIR0 LDR r1, =IOCLR0 LDR r2, =IOSET0 str r3, [r4] loop: str r3, [r2] bl delay str r3, [r1] bl delay b loop
Best regards,
Yasuhiko Koumoto.