IT Community - Software Programming, Web Development and Technical Support

How can I access memory in C?

This is a discussion on How can I access memory in C? within the C and C++ Programming forums, part of the Software Development category; How can I access memory (a memory-mapped device, or graphics memory) located at a certain address? How can I ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-17-2007, 03:34 AM
Sabari Sabari is offline
D-Web Genius
 
Join Date: Jul 2007
Posts: 1,008
Sabari is on a distinguished road
Default How can I access memory in C?

How can I access memory (a memory-mapped device, or graphics memory) located at a certain address?
How can I do PEEK and POKE in C?
__________________
Thanks & Regards
Sabari...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-17-2007, 03:43 AM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Default Re: How can I access memory in C?

hi,

Set a pointer, of the appropriate type, to the right number (using an explicit cast to assure the compiler that you really do intend this nonportable conversion):

unsigned int *magicloc = (unsigned int *)0x12345678;

Then, *magicloc refers to the location you want. [footnote] If the location is a memory-mapped I/O register, you will probably also want to use the volatile qualifier: ``volatile unsigned int *magicloc''. (If you want to refer to a byte at a certain address rather than a word, use unsigned char *.)

Under MS-DOS, you may find a macro like MK_FP() handy for working with segments and offsets. As suggested by Gary Blaine, you can also declare tricky array pointers which allow you to access screen memory using array notation. For example, on an MS-DOS machine in an 80x25 text mode, given the declaration

unsigned short (far * videomem)[80] =
(unsigned short (far *)[80])0xb8000000;

you can access the character and attribute byte at row i, column j with videomem[i][j].

Many operating systems execute user-mode programs in a protected mode where direct access to I/O devices (or to any address outside the running process) is simply not possible. In such cases you will have to ask the operating system to carry out I/O operations for you.

PEEK and POKE
POKE and PEEK are memory write and read statments

USING in C
----------WAY 1------------
SCREEN 13
DEF SEG = &HA000
'then to plot a pixel with coordinates of x and y and color c
POKE (y * 320 + x), c
'to read a pixel you
c = PEEK(y * 320 + x)
'then c will be the color of that pixel

Thanks,
Prasath.K

Last edited by prasath : 07-17-2007 at 03:51 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Efficient memory allocation vigneshgets Operating Systems 1 08-18-2007 12:18 AM
Memory alignment prasath C and C++ Programming 1 07-30-2007 06:46 AM
Access e-mail using Outlook Web Access gattuso Server Management 0 07-19-2007 07:20 AM
How to get the available and used memory in mobile using J2ME ? oxygen J2ME 1 07-19-2007 12:51 AM
Memory Sticks?? WiccanSpirit The Lounge 10 03-15-2007 08:59 PM


All times are GMT -7. The time now is 06:50 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0