Getting PC value in an ARM assembly

I have a Windows Mobile 6 ARMV4I project where I would like to get the program counter value.

The function is declared as follows:

extern "C" unsigned __int32 GetPC();

My build code is as follows:

GetPC FUNCTION
    EXPORT GetPC
    ldr r0, [r15]   ; load the PC value in to r0
    mov pc, lr      ; return the value of r0
ENDFUNC

But when I call the function GetPC(), I get the same number every time. So, I assume that my assembly does not do what I think it does. Can someone point out what I can do wrong?

Thanks PaulH

+3
source share
2 answers

, ldr r0, [r15] ( ). R14, , , . .

+7

, , , GetPC.

, :

move r0, lr // put return address in r0
move pc, lr // return
+4

Source: https://habr.com/ru/post/1743041/


All Articles