This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

push {lr}, pop {pc} 不能返回子程序调用的地方,是什么问题?

以下是我用汇编编写的一段代码,使用的是MDK5.15,下载到LPC824M201(Cortex-M0+内核),调用子程序的时候不能正常返回。请问问题在哪里?

源代码如下:

    area     reset,     code,     readonly
             preserve8
SYSCON_BASE     equ     0x40048000
SYSCON_SYSAHBCLKCTRL     equ (SYSCON_BASE + 0X80

MSP_TOP     equ     0x10001808
          export    __Vectors
          export    __Vectors_End
__Vectors    dcd     MSP_TOP
             dcd     Reset_Handler
             space   200
__Vectors_End
__Vectors_Size     equ     __Vectors_End - __Vectors

                  entry
Reset_Handler     proc
     export     Reset_Handler
     movs       r0, #1
     movs       r1, #2
     movs       r2, #3
     movs       r3, #4

     bl         system_init

loop     nop
         nop
         b      loop
         endp

system_init proc
     push     {lr}
     ldr     r0, =SYSCON_SYSAHBCLKCTRL
     ldr     r1, =(1 << 7)
     ldr     r2, =(1<< 18)
     orrs    r1, r1, r2
     str     r1, [r0]
     pop     {pc}
  • I can not say what exactly is wrong, but experimenting might help solve the problem.

    First try this:

    system_init proc
         ldr     r0, =SYSCON_SYSAHBCLKCTRL
         ldr     r1, =(1 << 7)
         ldr     r2, =(1<< 18)
         orrs    r1, r1, r2
         str     r1, [r0]
         bx      lr
         endp
    

    If the above works, then your stack pointer's value is probably wrong.

    However, if the above does not work, try this:

    system_init proc
         push     {lr}
        movs    r0,#17
         pop     {pc}
         endp
    

    If this works, then there is a problem (HardFault) with the peripheral address being accessed.

    If none of the above are executed, then the problem is elsewhere. Unfortunately I am not familiar with the tools you are using, so there might be some assembler-directives that are necessary.

    (on the GNU assembler, it's necessary to have .thumb_func preceding all the function entry labels, plus .type Reset_Handler,%function before the reset handler, but I do not know if there are any equivalent directives  on the assembler from ARM).