Search code examples
assemblyarm

How to use push{lr} pop{pc} in ARM Assembly


I've been trying this for days and looking all over the net but haven't gotten a solution so I'll try to ask here: I have this simplified code as an example - it should blink a LED on a raspberry without an OS (Standalone). As of now the LED turns on and never turns off again. The delay loop isn't the problem, since it works when used in place of "bl delayloop", the problem lies in the push pop. Those need to be used in order for me to translate it into a more complex project, bx lr isn't an option. Any help is extremely appreciated!!


_run_morse:

_short_blink:
    
    str r1,[r0,#GPSET0]

    mov r10,#0

    bl delayloop
    
    str r1,[r0,#GPCLR0]
    
    mov r10,#0

    bl delayloop

b _run_morse

delayloop:

    push {lr}

    delayloop2:

    add r10,r10,#4

    cmp r10,r2

    bne delayloop2

    pop {pc}

Solution

  • It appears you not have set the stack pointer (sp/r13) to pointer to suitable memory and the program does not run under an operating system that initialises it for you.

    You should set sp to point to just above the area of memory you wish to use as a stack.