473,941 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to read hardware memory from pointer?

Hi,

Am trying to read one byte at location 0xFFF0 000E in an embedded system.

I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.
Apr 28 '06 #1
22 2241
Brad wrote:
Hi,

Am trying to read one byte at location 0xFFF0 000E in an embedded system.

I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.

Show us what you have tried, what do you mean by "cast a pointer to int"?
--
Ian Collins.
Apr 28 '06 #2
"Brad" <ro*********@ve rizon.net> writes:
Hi,

Am trying to read one byte at location 0xFFF0 000E in an embedded system.

I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.


unsigned char data = *((unsigned char*)0xFFF0000 E);

--

John Devereux
Apr 28 '06 #3
John Devereux wrote:
"Brad" <ro*********@ve rizon.net> writes:
Hi,

Am trying to read one byte at location 0xFFF0 000E in an embedded system.

I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.


unsigned char data = *((unsigned char*)0xFFF0000 E);


I don't see any compilation error in this code. Is it in global scope
by any chance?
Post the complete (minimal compilable) code.

Consider adding volatile to the typecast. This may not solve your
current problem though.

Apr 28 '06 #4
suresh opined:
John Devereux wrote:
"Brad" <ro*********@ve rizon.net> writes:
> Hi,
>
> Am trying to read one byte at location 0xFFF0 000E in an embedded
> system.
>
> I cast a pointer to int, then try to stuff the above address in,
> then reference whats at the location? wont compile, tried many
> different
> variations of this; any ideas appreciated.
>
unsigned char data = *((unsigned char*)0xFFF0000 E);


I don't see any compilation error in this code. Is it in global scope
by any chance? Post the complete (minimal compilable) code.


You seem to have misinterpreted the attributions. The OP (Brad) did not
post any code. John then posted the line above (which looks OK to me,
too). We're still to hear from the OP whether it solves his problem.
Consider adding volatile to the typecast.


Another good idea for the OP.

--
Falling in love makes smoking pot all day look like the ultimate in
restraint.
-- Dave Sim, author of "Cerebus".

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

Apr 28 '06 #5
suresh wrote:
John Devereux wrote:
"Brad" <ro*********@ve rizon.net> writes:
Hi,

Am trying to read one byte at location 0xFFF0 000E in an embedded system.

I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.


unsigned char data = *((unsigned char*)0xFFF0000 E);


I don't see any compilation error in this code. Is it in global scope
by any chance?
Post the complete (minimal compilable) code.

Consider adding volatile to the typecast. This may not solve your
current problem though.


Oops... sorry. Don't consider my last statement unless the content of
that memory is volatile.

Apr 28 '06 #6

"Brad" <ro*********@ve rizon.net> wrote in message
news:z_h4g.4277 $Sh.1325@trnddc 06...
Hi,

Am trying to read one byte at location 0xFFF0 000E in an embedded system.

I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.


This is compiler and environment specific.
(All examples are untested...)

Example 1) OW 16-bit DOS

unsigned char far *address;
unsigned char byte;
address=MK_FP(0 xFFF0,0x000E);
byte=*address;

Example 2) OW 32-bit DOS

unsigned char *address;
unsigned char byte;
address = (unsigned char *)(((unsigned long)0xFFF0)<<4 )+((unsigned
long)0x000E);
byte=*address;

Example 3) DJGPP 32-bit DOS (segmented memory model)

unsigned char byte;
byte=_farpeekb( _dos_ds,(((unsi gned long)0xFFF0)<<4 )+((unsigned
long)0x000E));
HTH,

Rod Pemberton
Apr 28 '06 #7

"Vladimir Oka" <no****@btopenw orld.com> wrote in message
news:wp******** ************@bt .com...
suresh opined:
John Devereux wrote:
"Brad" <ro*********@ve rizon.net> writes:

> Hi,
>
> Am trying to read one byte at location 0xFFF0 000E in an embedded
> system.
>
> I cast a pointer to int, then try to stuff the above address in,
> then reference whats at the location? wont compile, tried many
> different
> variations of this; any ideas appreciated.
>

unsigned char data = *((unsigned char*)0xFFF0000 E);


I don't see any compilation error in this code. Is it in global scope
by any chance? Post the complete (minimal compilable) code.


You seem to have misinterpreted the attributions. The OP (Brad) did not
post any code. John then posted the line above (which looks OK to me,
too). We're still to hear from the OP whether it solves his problem.
Consider adding volatile to the typecast.


Another good idea for the OP.

--
Falling in love makes smoking pot all day look like the ultimate in
restraint.
-- Dave Sim, author of "Cerebus".

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>


Wow, you guys are fast. I was trying code on a different computer, didnt
have examples here, but was trying to force the literal memory address into
the pointer, then reference it, here the example simply references the
address, this is so awesome! Since Ive spent time having to not consider
any access to physical memory, this stumped me. I will go try this code out
soon. It will be reading an area of flash. The code module itself
references everything from an offset, this would be simply offset 0xE but
its always put into flash.

Its odd doing it this way but will work out perfectly. will try and post
results. Thanks for everyones input!

Brad
Apr 28 '06 #8
In article <87************ @cordelia.dever eux.me.uk>,
John Devereux <jd******@THISd evereux.me.uk> wrote:
"Brad" <ro*********@ve rizon.net> writes:
Am trying to read one byte at location 0xFFF0 000E in an embedded system.

unsigned char data = *((unsigned char*)0xFFF0000 E);


I went looking at the ANSI C89 reference thinking that was wrong, but
I was mistaken, and learned somethings along the way. It was not, though,
about the obvious question of whether a number can be converted to a pointer.

What I was looking at was whether the 0xFFF0000E constant had the
right type: I was thinking "Ah, but if int is only 16 bits, won't
that constant get truncated, seeing as it does not have a suffix?".
The C89 standard indicates, though, that an integer constant has
the smallest type out of a given list that will fit the numeric value.

And what I also found in the C89 standard was that the type list considered
is different for decimal constants than for octal or hex constants.
I had thought that all forms of constants were equivilent, but they
aren't.

On 16 bit int 2's complement systems, the decimal constant 65535
would be represented as type long int, but the hex constant 0xFFFF
would be represented as type unsigned int. That would imply that,
for example, on such a system, sizeof(65535) > sizeof(0xFFFF).

There's gotta be a good Obfuscated C trick in there somewhere ;-)
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Apr 28 '06 #9

"Walter Roberson" <ro******@ibd.n rc-cnrc.gc.ca> wrote in message
news:e2******** **@canopus.cc.u manitoba.ca...
In article <87************ @cordelia.dever eux.me.uk>,
John Devereux <jd******@THISd evereux.me.uk> wrote:
"Brad" <ro*********@ve rizon.net> writes:

Am trying to read one byte at location 0xFFF0 000E in an embedded
system.

unsigned char data = *((unsigned char*)0xFFF0000 E);


I went looking at the ANSI C89 reference thinking that was wrong, but
I was mistaken, and learned somethings along the way. It was not, though,
about the obvious question of whether a number can be converted to a
pointer.

What I was looking at was whether the 0xFFF0000E constant had the
right type: I was thinking "Ah, but if int is only 16 bits, won't
that constant get truncated, seeing as it does not have a suffix?".
The C89 standard indicates, though, that an integer constant has
the smallest type out of a given list that will fit the numeric value.

And what I also found in the C89 standard was that the type list
considered
is different for decimal constants than for octal or hex constants.
I had thought that all forms of constants were equivilent, but they
aren't.

On 16 bit int 2's complement systems, the decimal constant 65535
would be represented as type long int, but the hex constant 0xFFFF
would be represented as type unsigned int. That would imply that,
for example, on such a system, sizeof(65535) > sizeof(0xFFFF).

There's gotta be a good Obfuscated C trick in there somewhere ;-)
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)


Hey Thanks for that Walter, this is so interesting, and while trying the
solution, the compiler croaks for NO apparent reason at least to me,
1 unsigned char valIsaDot = 0;
2 unsigned char valBootVer = 0;
3
4 unsigned char *pBootVer = (unsigned char *)0xFFF0000E;
5 valBootVer = *pBootVer;
6
7
8 unsigned char *pBootDot = (unsigned char *)0xFFF0000F;
9 valIsaDot = *pBootDot;

The compiler says error at line 8 near 'unsigned' If line 8 and 9 are
removed, it compiles fine. There is nothing wrong with the spelling, it
simply wont allow this. On line 7 I add some extra task like int foo =0;
doesnt matter. If I take out the '=' on line 8 and have only the
definition? same error, line 8 near unsigned.


1// unsigned char valIsaDot = 0;
2// unsigned char valBootVer = 0;
3
4 unsigned char *pBootVer = (unsigned char *)0xFFF0000E;
5 unsigned char valBootVer = *pBootVer;
6
7
8 unsigned char *pBootDot = (unsigned char *)0xFFF0000F;
9 unsigned char valIsaDot = *pBootDot;

Do this? it compiles fine and works exactly right. (thanks again btw)
If there are no syntax errors, why does it refuse to accept the line 8
command before?
Apr 29 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2994
by: Julius Mong | last post by:
Hi all, I'm doing this: // Test char code wchar_t lookup = {0x8364, 0x5543, 0x3432, 0xabcd, 0xef01}; for (int x=0; x<5; x++) { wchar_t * string = (wchar_t*) malloc(sizeof(wchar_t)); string = (wchar_t*)lookup; string = '\0'; CComBSTR bstrTest = SysAllocString(string); }
4
2673
by: Jeff Rodriguez | last post by:
Main just loops over this while it's not null. The segfault occurs at this line: *line = (char)ch; Also, please don't just fix the code. I would like to know why exactly this isn't working so I can avoid problems with it in the future. If there are any references I should check out let me know. Full highlighted code at:
19
2715
by: Holger Hasselbach | last post by:
- The value of the object allocated by the malloc function is used (7.20.3.3). - The value of any bytes in a new object allocated by the realloc function beyond the size of the old object are used (7.20.3.4). Something like this (include and checkings omitted): p = malloc(sizeof(*p) * 5); p = 1; p = 1; p = 1;
10
3109
by: just4me | last post by:
Exactly how do I read a specific location in the bios eprom. (such as debug.exe location ffff:0000)
9
1984
by: ferbar | last post by:
Hi all, I'm trying to read from the txt file 'ip.packets.2.txt' using the read function. It seems everything ok, but I get a -1 when executing >>bytesr = read(fdo1, bufread, 2); The 'open' function returns the file dsc 3. So this seems ok.. Any idea what might be wrong?
42
3203
by: Martin Jørgensen | last post by:
Hi, I'm trying to move a matlab program into c language. For those who knows matlab, this is the line I want to program in c: hx(1:nx,1:ny) = 0; % nx=10, ny=10 It works on a 2-dimensional array (size is 10*10), setting all the values inside the 10*10 matrix to zero. My C-function looks like this:
4
4058
by: Bit byte | last post by:
I have a structure defined like this: struct foo { unsigned int magic ; void *mydata ; };
2
21986
by: Ilkka | last post by:
I have created an C++ application with Windows Forms, ADO and SQL server 2005. Now I need to change something and started debugging the code. Then suddenly I receive an error. "An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." The progran ends on a windows form designer...
2
4908
by: duylam76 | last post by:
I'm programming a server and corresponding client application that sends data to each other over a socket. I want to encode an integer to send over the socket. Right now everything is fine because everyone using our app has an integer encoded as 32 bits. I'm not sure what might happen should someone use a machine/OS that uses 64 bit integers, however. For instance, say that I know for certain that our server uses 32 bit integers. I can...
0
9964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11529
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11111
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9858
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3505
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.