[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Access Memory

Posted on 2000-03-13
3
Medium Priority
?
283 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
[X]
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
  • 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 1500 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

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.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 opening and reading files in the C programming language.

656 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