Click to See Complete Forum and Search --> : Memory access


Sorc
November 22nd, 2001, 05:25 AM
Its a simple problem but I am having problems with accessing the (physical) memory. The problem i'm facing is as follows: I want to access the memory at a memory location (say 0x8000).The code i'm using for this purpose is as follows:

unsigned int j;
char xdata *w_ptr;

j = 0x8000;
w_ptr = (char *)j; // I want the pointer to point to memory location 0x8000.

*w_ptr = data; // then transfer some bytes of data in the memory location




I want to whether in the above code, does the pointer w_ptr really point to the desired location (in this case: 0x8000) ?

Some1 please help me out, Thankyou in advance.

Green_Beret
November 22nd, 2001, 05:41 AM
Yes the pointer does indeed point to the memory location 0x00008000, but it is illegal to assign a pointer an address in this manner.
If you try to write to that memory location it may result in a memory access violation.

Regards,
The Beret.

NMTop40
November 22nd, 2001, 05:49 AM
Indeed - I remember years ago when we used to do this on purpose though in old MS-DOS applications.

We would write to the screen memory location because it was a lot faster than using regular printf and cursor-location functions.

In addition, it even used 2-byte characters - one of the bytes was used for attributes - foreground and background colour (3 bits each) with one bit for brightness (foreground only) and one for "flashing".

I'm talking about back in 1988-1990 computers were much slower back then and the time-saving was essential!

James Curran
November 22nd, 2001, 05:51 AM
That works, but you seem to be going to a lot of extra effort:char* w_ptr = (char*) 0x00008000;
char data = 0x55;
*w_ptr = data;





Truth,
James
http://www.NJTheater.com
http://www.NovelTheory.com
I don't do it for the points (OK, maybe I do), but rating a post is a good way for me to know if I helped.