memloc access

This is a discussion on memloc access within the C Programming forums, part of the General Programming Boards category; Hi, how do I access a memory locations in C? For example how do I read what is in memory ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    memloc access

    Hi,

    how do I access a memory locations in C? For example how do I read what is in memory at address 0x3FF?

    Thanks
    wolf

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    What embedded microcontroller are you using? Typically it would be done something like this.
    Code:
    unsigned char value = *(unsigned char *)0x3FF;
    But frequently registers of interest have #defines to make the syntax nicer looking.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Far pointer is used to access memory locations outside the program.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    'far' is obsolete with the introduction of 32bit compilers. Oh, wait. That means at least 50% of the people here still use it.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    2
    Quote Originally Posted by Dave_Sinkula
    What embedded microcontroller are you using? Typically it would be done something like this.
    Code:
    unsigned char value = *(unsigned char *)0x3FF;
    But frequently registers of interest have #defines to make the syntax nicer looking.
    Z8 Zilog, I did try with
    Code:
    #define MYVERSION  (*(unsigned char volatile far*)0x3FF)
    but I get the wrong value. I also tried what you suggeted but gives me a compiler error. I suppose that it is compiler dependent hence I will have to contact them to know how to do it.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I also tried what you suggeted but gives me a compiler error.
    You probably need to break what Dave gave you into two lines, one for the declaration, and one for the assignment:
    Code:
    unsigned char value;  /* Place this with your other variable declarations */
    
    value = *(unsigned char *)0x3FF;

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by wolfsafety
    Z8 Zilog, I did try with
    Code:
    #define MYVERSION  (*(unsigned char volatile far*)0x3FF)
    but I get the wrong value. I also tried what you suggeted but gives me a compiler error. I suppose that it is compiler dependent hence I will have to contact them to know how to do it.
    I did a quick look at the Zilog site, but you didn't mention which micro so I picked one at random. I also looked at the ZDS manual, and it mentions that there are extensions for near, far, and rom pointers. Since I'm not familiar with your device, or even the Z8 for that matter, I'm hard-pressed to know in which address space 0x3FF might reside.

    But yes, your best bet would be getting support from the compiler vendor.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,262
    Try it like the following:
    Code:
    #define pREG (volatile unsigned long*)0x0x3FF
    Now dereference pREG like you would any other pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. access to devices
    By pastitprogram in forum C++ Programming
    Replies: 1
    Last Post: 06-07-2008, 12:16 AM
  2. Order of access labels in class definition
    By Mario F. in forum C++ Programming
    Replies: 10
    Last Post: 06-16-2006, 08:13 AM
  3. ww hosting and SSH access
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 04-07-2005, 09:49 AM
  4. Direct disk access in DOS
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-26-2002, 02:52 PM

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