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

function pointer assignment

Note: This was originally posted on 22nd December 2008 at http://forums.arm.com

Hi,

I've a scenario here.

say, i have 2 functions. func1 and func2.

func1is at adddress 0x28 and func2 at some other location.
now, i have to pass func1 through func2 (where func1 is a callback function)

func2(func1);
while executing the above,  i observed in the assembly instruction that,

ldr r3,0xdb1f0 is called where

At 0xdb1f0:  dcd 0x29 is found.
so that r0 =0x29  (address of func1+1)

Now my question is:
1. why the func1 address 0x29 (func1+1) is loaded instead of 0x28 (func1). what is the logic behind this behaviour.

Please some one answer my question. Though it is not obstructing my work, just curious to know the reason for this behaviour.

Thanks
Parents
  • Note: This was originally posted on 22nd December 2008 at http://forums.arm.com

    Of course, the mode switch won't happen automatically with a standard B instruction, so you have to use BX.

    BX 0x100 // Branches to address 0x100 and switches to ARM mode.
    BX 0x201 // Branches to address 0x200 and switches to Thumb mode.
    B  0x301 // No mode switch occurs, so the result is undefined as you can't branch to a misaligned address.


    Just a quick note...  The rest of the reply is correct, but there is no "BX label" instruction, so this isn't quite right.  You are thinking of the BL and BLX instructions.  e.g.  "BL xxx" branches to xxx without changing state, "BLX xxx" branches to xxx and changes to the opposite state.

    Aside, for a function pointer I assume the address is in a register, so using this register with a BX or BLX instruction would detect the state by looking at the low bit.
Reply
  • Note: This was originally posted on 22nd December 2008 at http://forums.arm.com

    Of course, the mode switch won't happen automatically with a standard B instruction, so you have to use BX.

    BX 0x100 // Branches to address 0x100 and switches to ARM mode.
    BX 0x201 // Branches to address 0x200 and switches to Thumb mode.
    B  0x301 // No mode switch occurs, so the result is undefined as you can't branch to a misaligned address.


    Just a quick note...  The rest of the reply is correct, but there is no "BX label" instruction, so this isn't quite right.  You are thinking of the BL and BLX instructions.  e.g.  "BL xxx" branches to xxx without changing state, "BLX xxx" branches to xxx and changes to the opposite state.

    Aside, for a function pointer I assume the address is in a register, so using this register with a BX or BLX instruction would detect the state by looking at the low bit.
Children
No data