0

how can i access a direct (absolute, not the offset) memory
address?

here is what i tried:
wrote a program that ask's for an address from the user,
creates a FAR pointer to that adress and shows it. then the
user can increment/decrement the value in that address by
pressing p(inc+) and m(dec-).

NOW, i compiled that program and opened it twice (in 2
different windows) and gave twice the same address to it.
now look what happen - if i change the value in
one "window" of the program, it DOES NOT change in the
other! even if they point to the same address in the memory!

here is the code snippet:

//------------------------------------------------------

#include <stdio.h>        //INCLUDE EVERY KNOWN HEADER FILE
#include <conio.h>        //FOR ANY CASE...
#include <iostream.h>
#include <dos.h>
#include <process.h>


main()
{
 int far *ptr;         //FAR POINTER!!!
 long address;         
 char key=0;     //A KEY FROM THE KEYBOARD
 int temp=0;

 clrscr();

 cout<<"Enter Address:";
 cin>>hex>>address;           //GETS THE ADDRESS
 clrscr();

 (long)ptr=address; temp=*ptr; //PUTS THE ADDRESS IN THE PTR

 cout<<"["<<hex<<(unsigned long)ptr<<"]="<<*ptr<<"  =  "<<
(char)(*ptr);    

//SHOWS: [address]=value=ASCII symbol.


 while (key!=27)   //WHILE YOU DONT PRESS ESC.
 {
  while(!kbhit())  //WHILE KEY IS NOT PRESSED
  {
   if (temp!=*ptr) { temp=*ptr; clrscr();  cout<<"["<<hex<<
   (unsigned long)ptr<<"]="<<*ptr<<"  =  "<<(char)(*ptr); };

   //IF THE VALUE HAS CHANGED, CLEAR THE SCREEN AND SHOW 
   //AGAIN

   if (key=='p') {key=0; (*ptr)++; }   //INCREMENT VALUE
   if (key=='m') {key=0; (*ptr)--;       } //DEC. VALUE
  };
  key=getch(); //IF A KEY IS PRESSED, READ IT FROM THE 
               //KEYBOARD
 };
 return 0;  //IF ESC WAS THE KEY, EXIT THE PROGRAM
}
//---------------------------------------------------------

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Salem
0

Rule 1 - don't spam the crap out of the net with your cross posting
http://www.catb.org/~esr/faqs/smart-questions.html#forum

Already answered here - http://cboard.cprogramming.com/showthread.php?t=106619
If a forum doesn't deliver, then you're free to move on. Broadcast spam like this just pisses people off.

Rule 2 - read ALL (not as in your case, NONE) the posts on HOW TO POST CODE.
This tells you to use code tags - http://www.daniweb.com/forums/forum2.html
So does this - http://www.daniweb.com/forums/forum8.html
Wait for it, wait for it - http://www.daniweb.com/forums/announcement8-3.html
You're not going to believe this - http://www.daniweb.com/forums/thread78223.html
And not forgetting the watermark at the back of the edit window.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.