PC relative addressing mode

This is a discussion on PC relative addressing mode within the Tech Board forums, part of the Community Boards category; Take for example Code: LDR R1, =Sample Does R1 point to the the program counter plus the location of Sample ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    116

    PC relative addressing mode

    Take for example
    Code:
    LDR R1, =Sample
    Does R1 point to the the program counter plus the location of Sample OR the value of Sample?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    Are we supposed to guess which processor/assembler you're using, or are we to guess you're using ARM like last time?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    116
    ARM. I thought it would be the same in all assembly languages?

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by c_weed View Post
    ARM. I thought it would be the same in all assembly languages?
    Of course not.

    Every processor type has it's own instruction set and nope they're not all the same.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    In this case I think it also depends on the particular assembler. LDR Rd, =... is a pseudo instruction in at least the ARM and GNU assembler. The behaviour depends on what "Sample" is.

    If "Sample" is an expression, e.g. a constant, then the value of Sample will be loaded. Sample might not even have an address if it is small enough.

    Code:
     .equ SmallSample,5
     .equ BigSample,0xdeadbeef
    
    
     LDR r1, =SmallSample
    #  ---> this will assemble to "MOV r1, 5". 
     LDR r1,=BigSample
    #  ---> the assembler will generate a literal pool containing 0xdeadbeef and load from it using LDR r1, [pc,#offset]
    If Sample is a symbol, e.g. a label, the assembler will load the address of Sample.

    Code:
    Sample .word 0xf00df00d
    
     LDR r0, =Sample
    #--> In this case the assembler will probably generate a literal pool containing the address of "Sample".
    Likewise if "Sample" is a function name, it'll load the address of the symbol
    Last edited by smokeyangel; 10-21-2011 at 05:08 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory addressing question
    By stevenswj in forum C Programming
    Replies: 17
    Last Post: 10-13-2010, 11:41 AM
  2. 2d array addressing
    By R.Stiltskin in forum C++ Programming
    Replies: 6
    Last Post: 08-19-2008, 01:36 AM
  3. memory addressing
    By sarathius in forum C Programming
    Replies: 7
    Last Post: 03-31-2008, 08:23 AM
  4. ipv6 addressing
    By venkatam in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2008, 06:52 AM
  5. Indirect Addressing uses how many bits?
    By franziss in forum C Programming
    Replies: 8
    Last Post: 12-16-2004, 03:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21