Is it mistake to force PC to specific address?

I want to make mechanism to force my processor (LPC2378) to do one program if some flag is set and to do another if that flag isn't set.
But that two programs may have functions with same name and I want to insure that right one will be executed.

Parents
  • Hi Bojana,

    I'm still not entirely sure I understand what you are trying to do here. You could link the programs to different addresses (say prog1 at 0x8000, prog2 at 0x9000). Then have a third assembly level program that tests a flag (at say 0x1000), and then based on that, jump to appropriate address. Note the thumb code address should be "odd" in the below as least significant bit highlights to the core that you are going to Thumb state (even though Cortex-M3 only supports Thumb state...).

         AREA test, CODE

         ENTRY

    flag     EQU 0x1000

    prog1    EQU 0x8000 +1

    prog2    EQU 0x9000 +1


    testflag

         LDR r0, =flag

         LDR r1, [r0]


         CMP r1, #0

         LDREQ pc, =prog1

         LDRNE pc, =prog2


         END


Reply
  • Hi Bojana,

    I'm still not entirely sure I understand what you are trying to do here. You could link the programs to different addresses (say prog1 at 0x8000, prog2 at 0x9000). Then have a third assembly level program that tests a flag (at say 0x1000), and then based on that, jump to appropriate address. Note the thumb code address should be "odd" in the below as least significant bit highlights to the core that you are going to Thumb state (even though Cortex-M3 only supports Thumb state...).

         AREA test, CODE

         ENTRY

    flag     EQU 0x1000

    prog1    EQU 0x8000 +1

    prog2    EQU 0x9000 +1


    testflag

         LDR r0, =flag

         LDR r1, [r0]


         CMP r1, #0

         LDREQ pc, =prog1

         LDRNE pc, =prog2


         END


Children
More questions in this forum