Solved

Accessing Memory

Posted on 2000-03-14
16
257 Views
Last Modified: 2010-04-15
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:rhobbs22
  • 6
  • 4
  • 2
  • +4
16 Comments
 
LVL 2

Expert Comment

by:bbousquet
ID: 2618367
As you're using Borland 3.1, take a look at the MK_FP macro. It should do what you wish to attain.
0
 
LVL 2

Accepted Solution

by:
AndrewRodionov earned 100 total points
ID: 2618525
Hi!

Yes, using MK_FP is good decision. Moreover you can use huge pointer:

#include <stdio.h>
#include <dos.h>

int main()
{
  printf( "The address is %Fp\n", MK_FP( 0xF000, 0x3070 ) );
  printf( "The address is %Fp\n", (void huge *)0xF0003070 );
  return 0;
}

Hope this helps.
Andrew
0
 
LVL 4

Expert Comment

by:feenix
ID: 2618714
Actually, the huge pointer should be pointing to 0xF003070, not 0xF0003070, because the segment and offset parts overlap.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2618749
Hi, feenix!

You can try my and your comment -- build my sample program under Borland C 3.x and check. The huge address 0xF0003070 is the LOGICAL address but the address 0xF003070 (that you talk about) is the PHYSICAL address.

That's the difference.

Andrew
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2618780
->The huge address 0xF0003070 is the LOGICAL address but the address 0xF003070 (that you talk about) is the PHYSICAL address.
======================
Andrew , sorry for breakin ,I'm confused about this above.What mode are these code in ? real or protect?
What is logical address?

I think F000:3070 should be 0xF03070 in real mode ,how you got the F0003070 ANDF003070?
Thank you very much.

Regards
W.Yinan




0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2618820
Wyn: Actually, since the segment address of an Intel x86 running in real mode contributes only 4 extra bits to the address, the *logical* address F000:3070 points at the *physical* address F3070 (995440 decimal--real mode can only access 1Mb, plus 64K due to a bug in the chip firmware). When you're running in protected mode all bets are off, because the physical address will depend on the CPU's selector table--that logical address could be pointing anywhere in memory.
0
 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2618824
Hi, Wyn!

As mentioned above we are talking about Borland C 3.x compiler. We are talking about MK_FP macro too. It means that we all assume DOS and the real mode x86 processor (even the include file for MK_FP is called "dos.h")...

The logical address is the address a programmer works with. And the physical address is the address a hardware (i.e. the processor) works with. That's what I mean.

Andrew
0
 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2618839
Yes, pjknibbs is right: the physical address is F3070h.

Andrew
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2618951
->real mode can only access 1Mb, plus 64K due to a bug in the chip firmware
=========================
But I think it's DOS's fault,it limits the segment register and common register to 16bits in real mode?
Correct me if I'm wrong.

->the *logical* address F000:3070 points at the *physical* address F3070
============================
Yes,I mean that.I make a stupid addition mistake.It should be F0000+3070 =F30F0.

My confusion is not above.
I'm just perplexed by Andrew 's comment ,Andrew,you got F0003070 AND F003070 and you refer them by logic and phisical address.These figure and calling convention make no sense to me:)

Anyhow,I understand you now.

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2618961
Thanks,Andrew :-)

-> because the physical address will depend on the CPU's selector table--that logical address could be pointing anywhere in memory.
======================
Descriptor table and selectors are stored in registers.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2618966
The descriptor table isn't stored in registers--it's too big for that (8K). Its location in memory is stored in a register, certainly.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2618968
Sorry,in my last sentence I mean :

Should be descriptor table and selectors are stored in registers.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2618978
->The descriptor table isn't stored in registers--it's too big for that (8K).
============================
sure:-)



0
 
LVL 5

Expert Comment

by:Wyn
ID: 2618984
It's funny that I spare two words(should be) but lead differenct meaning,sorry for my poor english
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2621404
>>F000:3070
F000 is the SEG
3070 OFFSET

the offest & the seg are stored in a 16bit regs

so it should be F000h*16dec+3070h this the correct address

as i know from ASsembler
then use a pointer to it
0
 

Author Comment

by:rhobbs22
ID: 2621983
Thanks, that seems to have worked out!  I am able to read and verify the string stored at that memory address location!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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.

805 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