We help IT Professionals succeed at work.

Accessing Memory

rhobbs22
rhobbs22 asked
on
276 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?

Comment
Watch Question

As you're using Borland 3.1, take a look at the MK_FP macro. It should do what you wish to attain.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Actually, the huge pointer should be pointing to 0xF003070, not 0xF0003070, because the segment and offset parts overlap.
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
Wyn

Commented:
->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




Commented:
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.
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
Yes, pjknibbs is right: the physical address is F3070h.

Andrew
Wyn

Commented:
->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
Wyn

Commented:
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.

Commented:
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.
Wyn

Commented:
Sorry,in my last sentence I mean :

Should be descriptor table and selectors are stored in registers.
Wyn

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



Wyn

Commented:
It's funny that I spare two words(should be) but lead differenct meaning,sorry for my poor english

Commented:
>>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

Author

Commented:
Thanks, that seems to have worked out!  I am able to read and verify the string stored at that memory address location!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.