• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Access Memory

In C, how do you access a specific region in memory?  For example I want to be able to read the contents of memory address F000:3070.  I am using Borland 3.0.  My C code looks like this:

#include<stdio.h>
int main(void)
{
      char *p =(char *) 0xF000;
          while (p != (char *(0x3070))
            printf("%c", *p++);
      return 0;
}

There is a specific string located at the address F000:3070 that I need to check for.  However when I use the code above, it prints funny ASCII characters. I can use debug, however I would prefer accessing it from code, and reading it into a buffer.


Thanks in advance,
Ryan

I am a novice to C programming.  Can anyone help?
0
rhobbs85
Asked:
rhobbs85
  • 2
1 Solution
 
ufolk123Commented:
Hi rhobbs85,

You logic is little wrong.Actually F000:3070 is not an address range .It is a segment:offset address pair.So You need to get the final address by combinnig thesr two address using the follwing logic:
final address:
(segment << 4) + offset;
Or shift left the segment address to four positions and add the offset in to it.
There is a macro to do this conversion.I forget the exact name but it is something like MK_FAR or MAKE_POINTER on all C/Dos environemts.
I think this is the main problem you are facing .Just change your logic to

#include<stdio.h>
int main(void)
{
char *p =MK_FAR(0xF000,0x3070);
int len=0;
while (len != STRING_LENGTH)  //STRING_LENGTH is length of your string
      {
      printf("%c", *(p+len));
      len++;
      }
return 0;
}


Just check the excat name for MK_FAR on your machine.It should work.

Feel free to ask any further doubts.



0
 
ufolk123Commented:
Hi rhobbs85,

You logic is little wrong.Actually F000:3070 is not an address range .It is a segment:offset address pair.So You need to get the final address by combinnig thesr two address using the follwing logic:
final address:
(segment << 4) + offset;
Or shift left the segment address to four positions and add the offset in to it.
There is a macro to do this conversion.I forget the exact name but it is something like MK_FAR or MAKE_POINTER on all C/Dos environemts.
I think this is the main problem you are facing .Just change your logic to

#include<stdio.h>
int main(void)
{
char *p =MK_FAR(0xF000,0x3070);
int len=0;
while (len != STRING_LENGTH)  //STRING_LENGTH is length of your string
      {
      printf("%c", *(p+len));
      len++;
      }
return 0;
}


Just check the excat name for MK_FAR on your machine.It should work.

Feel free to ask any further doubts.



0
 
rhobbs85Author Commented:
Thanks, for the information.  Actually after reviewing the code, and reading a few items.  I managed to see the problem and fix it.  I used a far pointer, and was able to get the string and then compare it.  


Thanks for your help
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now