Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access Memory

Posted on 2000-03-13
3
271 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional 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