Thread: Assign a value to address of memory;

  1. #1
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184

    Assign a value to address of memory;

    I Need save a value to a variable in a specified memory address.

    My variable address 0xE0084000.
    My variable value is 100

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Is the value to occupy one byte in memory? Two bytes (16 bits)?
    Code:
    unsigned char *addr = (unsigned char *)0xE0084000lu; /* for 1 byte */
    /* or */
    unsigned short *addr = (unsigned short *)0xE0084000lu; /* for 2 bytes */
    
    *addr = 100;

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    That'd be possible only on a system that doesn't implement virtual memory ie there's no translation between logical and physical memory addresses because they are one and the same.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    I'm using ARM 7, this address point to my SRAM.

    Thanks a lot,

    whats lu ?
    I need to set dynamic char long int...

    I create a Map of Memory to set/get values
    Last edited by sergioms; 03-22-2011 at 02:24 PM.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    "lu" (small "L", small "U") is a suffix that makes the compiler should interpret the constant as an unsigned long integer. Because from the hex value I assume the address is 32 bits. If you left off the "lu", the compiler might start off assuming the constant is an int, and on systems where the native int size is 16 bits, the compiler would complain about overflow when trying to interpret 0xE0084000.

    I don't know what you mean: "I need to set dynamic char long int..."
    Yes you can set the address dynamically:
    Code:
    unsigned char *addr;
    addr = (unsigned char *)0xE0084000lu; /* for 1 byte */
    /* or */
    addr = /* get value from someplace */
    *addr = 100;
    Last edited by nonoob; 03-22-2011 at 02:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with insert/delete binary search tree
    By Nazgulled in forum C Programming
    Replies: 39
    Last Post: 03-25-2009, 04:24 PM
  2. Pointers
    By chadmandoo in forum C++ Programming
    Replies: 6
    Last Post: 11-23-2008, 12:40 PM
  3. Memory address?
    By Munkey01 in forum C++ Programming
    Replies: 4
    Last Post: 02-01-2003, 09:04 PM
  4. HelpMePlease
    By Prncess100 in forum C++ Programming
    Replies: 6
    Last Post: 12-11-2002, 02:02 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM