• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Accessing Memory

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
rhobbs22
Asked:
rhobbs22
  • 6
  • 4
  • 2
  • +4
1 Solution
 
bbousquetCommented:
As you're using Borland 3.1, take a look at the MK_FP macro. It should do what you wish to attain.
0
 
Andrei RodionovCommented:
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
 
feenixCommented:
Actually, the huge pointer should be pointing to 0xF003070, not 0xF0003070, because the segment and offset parts overlap.
0
On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

 
Andrei RodionovCommented:
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
 
WynCommented:
->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
 
pjknibbsCommented:
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
 
Andrei RodionovCommented:
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
 
Andrei RodionovCommented:
Yes, pjknibbs is right: the physical address is F3070h.

Andrew
0
 
WynCommented:
->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
 
WynCommented:
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
 
pjknibbsCommented:
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
 
WynCommented:
Sorry,in my last sentence I mean :

Should be descriptor table and selectors are stored in registers.
0
 
WynCommented:
->The descriptor table isn't stored in registers--it's too big for that (8K).
============================
sure:-)



0
 
WynCommented:
It's funny that I spare two words(should be) but lead differenct meaning,sorry for my poor english
0
 
ntdragonCommented:
>>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
 
rhobbs22Author Commented:
Thanks, that seems to have worked out!  I am able to read and verify the string stored at that memory address location!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 6
  • 4
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now