Solved

Access Memory

Posted on 2000-03-13
3
246 Views
Last Modified: 2010-04-02
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
Comment
Question by:rhobbs85
  • 2
3 Comments
 
LVL 3

Expert Comment

by:ufolk123
Comment Utility
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
 
LVL 3

Accepted Solution

by:
ufolk123 earned 500 total points
Comment Utility
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
 

Author Comment

by:rhobbs85
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now