开发者

Getting the PC value in ARM assembly

I开发者_如何转开发 have a Windows Mobile 6 ARMV4I project where I would like to get the value of the program counter.

The function is declared like this:

extern "C" unsigned __int32 GetPC();

My assembly code looks like this:

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 GetPC() function, I get the same number every time. So, I'm assuming my assembly isn't doing what I think it's doing. Can anybody point out what I may be doing wrong?

Thanks, PaulH


PC is same every time, because ldr r0, [r15] has fixed address (PC is always same there). use R14 because it holds return address, that might be what you need. or use inline functions.


If this is a true function, you should always get the same value in this code since you're just returning the current PC which is inside GetPC.

You probably want:

move r0, lr // put return address in r0
move pc, lr // return
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜