return 0
return 0

Reputation: 4366

What's the value of program counter when use them in a statement? (Assembly)

Currently I have a small (ARM Cortex M4) assembly program, the excerpt for which I have a question is below:

PC    Instruction
0x9c  MOV    R0, #0
0x9e  LDR.N  R1, [PC, #0x20]
0xa0  STR.N  R0, [R1]

In the second line PC = 0x9e. But, when access the PC as one of the operands, what value does it have? 0x9e or 0xa0?

Upvotes: 0

Views: 1519

Answers (1)

wallyk
wallyk

Reputation: 57774

The PC values displayed are almost surely not absolute. They are normally relative to the beginning of the module.

Different versions of the ARM have different PC read behavior. Early versions have a value equivalent to 0x9e. Later versions have considerable "lookahead" so they have values of 0xa0 or greater. That is, by the time the PC is sampled, it has already sequenced further for fetching the next instruction(s).       Stricken because @Notlikethat found a 1985 reference saying they are all +8 advanced.

So the second instruction source operand PC, #0x20 adds 32 to the value of the PC, but the PC has the absolute address of (roughly) where the instruction is, which could be relocated by zillions of bytes above 0x9e.

Upvotes: 1

Related Questions