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

  • SEARCH
  • Home
  • 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 3395564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:18:17+00:00 2026-05-18T04:18:17+00:00

First off, sorry for the title, it was hard to come up with a

  • 0

First off, sorry for the title, it was hard to come up with a description. I am attempting to create a structure that will access a peripheral that has quite of few internal registers that are controlled by 3 address lines. So I have the following structure definition:

typedef struct {
  union {
    unsigned char  *reg0aPtr;
    unsigned char  *reg0bPtr;
  } RegsAddrOffset0;

  union {
    unsigned char  *reg1aPtr;
    unsigned char  *reg1bPtr;
  } RegsAddrOffset1;

  ...

  union {
    unsigned char  *reg7aPtr;
    unsigned char  *reg7bPtr;
  } RegsAddrOffset7;
} DeviceRegMap;

Then if I declare a variable as so

DeviceRegMap  *uartRegMap = (DeviceRegMap *)(0xD0000000);

Now, if I try to to use the uartRegMap variable to access the memory mapped registers I thought I would see that *(uartRegMap->RegsAddrOffset0.reg0aPtr) would read the data from address 0xD0000000, which is does. If I use *(uartRegMap->RegsAddrOffset1.reg1bPtr) I thought I would access 0xD0000001, but it is actually accesses address 0xD0000004. Since the processor is 32-bit the natural alignment is 4-bytes. I am thinking since the size of a pointer is an int which in this case is 32-bits this is the reason why I am accessing on 4-byte address ranges (e.g., 0xD0000000, 0xD0000004, 0xD0000008, etc).

If I declared an instance of the DeviceRegMap datatype I would expect the following initialization:

DeviceRegMap uartRegMap = {
  (unsigned char  *)0xD0000000,
  (unsigned char  *)0xD0000001,
  ...
  (unsigned char  *)0xD0000007,
};

Then if I wanted to access address 0xD0000007 then I would use *(uartRegMap.RegsAddrOffset7.reg7bPtr)

The question is why is the pointer to the DeviceRegMap data type access memory on 4-byte alignments (e.g., 0xD0000000, 0xD0000004, etc) instead of byte alignments (e.g., 0xD0000000, 0xD0000001, etc). With regards to the toolset I am using Wind River diab compiler. Thanks.

Mark

EDIT: Based upon abelenky’s comment

  • 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-05-18T04:18:18+00:00Added an answer on May 18, 2026 at 4:18 am

    If you want to access the byte-sized parts of a memory-mapped register, do the following:

    struct DeviceRegMap {
      volatile unsigned char byte0;
      volatile unsigned char byte1;
      volatile unsigned char byte2;
      volatile unsigned char byte3;
    };
    
    static struct DeviceRegMap *device = (struct DeviceRegMap *)(0xD0000000);
    

    Now device->byte0 points to 0xD0000000, and device->byte3 points to 0xD00000003. Is that what you want?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, sorry if the title is confusing! I'm working on a part of
First off, sorry for the lame title, but I couldn't think of a better
First off, I'm sorry if the title doesn't explain this very well. I'm looking
First off, I'm using Access 2000 and DAO. I have code that executes a
First off, I am using Windows XP. I have multiple hard drives and it
First off, I'm working on an app that's written such that some of your
First off, let me start off that I am not a .net developer. The
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
I have DateTime structure for an old data format that I don't have access
Sorry, I know that this topic has been covered a bit. I've read the

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.