Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8145655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:44:16+00:00 2026-06-06T13:44:16+00:00

In modern processors it is possible to load a register from memory and then

  • 0

In modern processors it is possible to load a register from memory and then post-modify the indexing pointer by a desired value. For example, in our embedded processor, this will be done by:

ldr r0, [r1], +12

which means – load the value pointed to by r1 into r0 and then increment r1 by 12:

r0 = [r1]
r1 = r1 + 12

In the C language, using pointer arithmetics, one can assign a value using a pointer and then advance the pointer by 1:

char i, *p, a[3]={10, 20, 30};

p = &(a[0]);
i = *p++;
// now i==10 and p==&(a[1]).

I am looking for a way to dereference a pointer while post-modifying it by an offset other than 1. Is this possible in C, so it maps nicely to the similar asm instruction?

Note that:

i = *p+=2;

increases the value in a[0] w/o modifying the pointer, and:

i = *(p+=2);

pre-modifies the pointer, so in this case i==30.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:44:18+00:00Added an answer on June 6, 2026 at 1:44 pm
    1. Yes this is possible.

    2. You shouldn’t be doing weird pointer math to make it happen.

    3. Not only is it about optimization settings, your GCC back-end needs to tell GCC that it has such a feature (i.e. when GCC itself is being compiled). Based on this knowledge, GCC automatically combines the relevant sequence into a single instruction.

    i.e. if your back-end is written right, even something like:

     a = *ptr;
     ptr += SOME_CONST;
    

    should become a single post-modify instruction.

    How to correctly set this up when writing a back-end? (ask your friendly neighbourhood GCC back-end developer to do it for you):

    If your GCC back-end is called foo:

    1. In the GCC source tree, the back-end description and hooks will be located at gcc/config/foo/.
    2. Among the files there (which get compiled along with GCC), there is usually a header foo.h which contains a lot of #defines describing machine features.
    3. GCC expects that a back-end which supports post-increment define the macro HAVE_POST_INCREMENT to evaluate to true, and if it supports post-modify, then define the macro HAVE_POST_MODIFY_DISP to true. (post-increment => ptr++, post-modify => ptr += CONST). Maybe there are a few other things to be handled as well.

    Assuming that your processor’s back-end has got this right, lets move to what happens when you compile your code containing said post-modify sequence:

    There is a specific GCC optimization pass that goes through instruction pairs that fall into this category and combines them. The source for that pass is here, and has a rather clear description of what GCC will do and how to get it to do it.

    But this, in the end, is not in your control as a GCC user. It is in the control of the developer who wrote your GCC back-end. All you should be doing, like the most upvoted comment says, is:

     a = *ptr;
     ptr += SOME_CONST;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somewhere I have read that modern Intel processors have low-level hardware for implementing exceptions
It seems like most modern(as in, past 20 years) processors have used little endian,
I am reading modern C++ design. Following is the text snippet taken from typeinfo
We are joining the modern world and transitioning from SVN to Mercurial for source
This is exert from a book about data alignment of primitive types in memory.
In Linux or other modern OS, each process's memory is protected, so that a
I'm using the Modern Carousel tool from here and I've added 6 images and
Modern processors use all sorts of tricks to bridge the gap between the large
Modern browsers are supposed to support the CSS page-break properties to some degree. However
use Modern::Perl; use DateTime; use autodie; my $dt; open my $fh, '<', 'data.txt'; #

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.