Solved

Access Memory

Posted on 2000-03-13
3
265 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
ID: 2626449
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
ID: 2626450
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
ID: 2626508
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

809 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