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 153939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:53:25+00:00 2026-05-11T09:53:25+00:00

For embedded applications, it is often necessary to access fixed memory locations for peripheral

  • 0

For embedded applications, it is often necessary to access fixed memory locations for peripheral registers. The standard way I have found to do this is something like the following:

// access register 'foo_reg', which is located at address 0x100 #define foo_reg *(int *)0x100  foo_reg = 1;      // write to foo_reg int x = foo_reg;  // read from foo_reg 

I understand how that works, but what I don’t understand is how the space for foo_reg is allocated (i.e. what keeps the linker from putting another variable at 0x100?). Can the space be reserved at the C level, or does there have to be a linker option that specifies that nothing should be located at 0x100. I’m using the GNU tools (gcc, ld, etc.), so am mostly interested in the specifics of that toolset at the moment.

Some additional information about my architecture to clarify the question:

My processor interfaces to an FPGA via a set of registers mapped into the regular data space (where variables live) of the processor. So I need to point to those registers and block off the associated address space. In the past, I have used a compiler that had an extension for locating variables from C code. I would group the registers into a struct, then place the struct at the appropriate location:

typedef struct {     BYTE reg1;    BYTE reg2;    ... } Registers;  Registers regs _at_ 0x100;  regs.reg1 = 0; 

Actually creating a ‘Registers’ struct reserves the space in the compiler/linker’s eyes.

Now, using the GNU tools, I obviously don’t have the at extension. Using the pointer method:

#define reg1 *(BYTE*)0x100; #define reg2 *(BYTE*)0x101; reg1 = 0  // or #define regs *(Registers*)0x100 regs->reg1 = 0; 

This is a simple application with no OS and no advanced memory management. Essentially:

void main() {     while(1){         do_stuff();     } } 
  • 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. 2026-05-11T09:53:26+00:00Added an answer on May 11, 2026 at 9:53 am

    Your linker and compiler don’t know about that (without you telling it anything, of course). It’s up to the designer of the ABI of your platform to specify they don’t allocate objects at those addresses.

    So, there is sometimes (the platform i worked on had that) a range in the virtual address space that is mapped directly to physical addresses and another range that can be used by user space processes to grow the stack or to allocate heap memory.

    You can use the defsym option with GNU ld to allocate some symbol at a fixed address:

    --defsym symbol=expression 

    Or if the expression is more complicated than simple arithmetic, use a custom linker script. That is the place where you can define regions of memory and tell the linker what regions should be given to what sections/objects. See here for an explanation. Though that is usually exactly the job of the writer of the tool-chain you use. They take the spec of the ABI and then write linker scripts and assembler/compiler back-ends that fulfill the requirements of your platform.

    Incidentally, GCC has an attribute section that you can use to place your struct into a specific section. You could then tell the linker to place that section into the region where your registers live.

    Registers regs __attribute__((section('REGS'))); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unless you are doing development on an embedded system, I… May 16, 2026 at 6:11 pm
  • Editorial Team
    Editorial Team added an answer I've set up a Rakefile for Sinatra using a kind… May 16, 2026 at 6:11 pm
  • Editorial Team
    Editorial Team added an answer I haven't used tpl before, but from a quick look… May 16, 2026 at 6:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Possible Duplicate: Smart pointers/safe memory management for C? I have an embedded application where
In many embedded applications there is a tradeoff between making the code very efficient
In the many Python applications I've created, I often create simple modules containing nothing
What unusual, unexpected consequences have occurred in terms of performance, memory, etc when switching
I have an MVC Application the views was embedded in the compiled dll, how
I have a situation where I need to write some unit tests for some
I'm looking at porting an Interbase 6 / Delphi 7 application to embedded Firebird
I have a C library with numerous math routines for dealing with vectors, matrices,
Is there any ready-to-use solution to log the memory consumption from the start of
I've been assigned to upgrade an embedded application written in C. The application is

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.