Connecting Tech Pros Worldwide Forums | Help | Site Map

how to declare and read/write to a memory register in C

Newbie
 
Join Date: Jun 2007
Posts: 1
#1: Jun 22 '07
Hello
I am new to group, and new to development.
I have question. I am doing project on embedded, need to read/write to the registers of the microprocessor.

Two questions:
1. How to declare?
Maybe use pointer.
#define TX_Register 0x30008000
long * tx_reg = TX_Register
Is this correct?
Is it possible to use maybe double pointer?
long ** tx_reg = ???
Please help with syntax in declaration.

2. How to access/ read/write/reference the register using the pointer (or double pointer)?

Thank you.

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,370
#2: Jun 22 '07

re: how to declare and read/write to a memory register in C


I'm not sure you can write to specific registers using C or C++.

You can declare a register variable:
Expand|Select|Wrap|Line Numbers
  1. register int value;
  2.  
as a suggestion to the compiler that value should be in a register rather than a variable in memory but I don't think you can specify the precise register.

If you are using Visual Studio, you can drop into assembly by invoking the inline assembler:
Expand|Select|Wrap|Line Numbers
  1. __asm
  2. {
  3.      //assembly code here
  4. }
  5.  
Otherwise, I am at a loss.
Reply