473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

view memory

I'm trying to write a program that will take ROM and show the values. Is
that address 0-255? Would this involve malloc or memcpy? How can you alter
memory values if you do know how to find them?

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #1
5 3411
On Wed, 5 Nov 2003 20:02:36 -0500, "Bill Cunningham" <nospam@net>
wrote in comp.lang.c:
I'm trying to write a program that will take ROM and show the values. Is
that address 0-255? Would this involve malloc or memcpy? How can you alter
memory values if you do know how to find them?

Bill


C has no concept of ROM. Some computers might have some things in
ROM, or more likely today in flash, but C provides no particular
method to access it, and it certainly has nothing to do with either
malloc or memcpy.

If you want to know if the particular compiler that you use has some
non-standard extension to provide a method of accessing such ROM as
there might be in a particular hardware platform that compiler makes
programs for, ask in a support group for that particular
compiler/platform combination.

This is not a language issue.

And as to how you can alter memory values in ROM (Read Only Memory)
from a C program, the answer is ... you can't. If you could it
wouldn't be ROM.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #2
"Bill Cunningham" <nospam@net> wrote:
I'm trying to write a program that will take ROM and show the values.
That is possible on many systems - however note that it's undefined
behaviour to read from an address that is not a valid C object.
Generally either it will work, or your program will crash.
Is that address 0-255?
That's implementation-specific - it might be on your computer.
Would this involve malloc or memcpy?
You can't get ROM from malloc, as the memory returned by
malloc must be writeable. Using memcpy is possible but
unnecessary.
How can you alter memory values if you do know how to
find them?


If they are in ROM, you can't alter them.

Here's a program that will print out the values from a specified
memory range, with each byte in hexadecimal then any printable
characters at the end of the line.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define WIDTH 19

int main(int argc, char **argv)
{
if(argc != 3) /* If called with wrong number of arguments */
{
printf("I require two arguments: length to print, and base address in hex\n");
}
else
{
size_t i, n = strtoul(argv[1], 0, 0); /* Parse length */
unsigned char *p = (unsigned char *)strtoul(argv[2], 0, 16); /* Parse base address */
char buf[WIDTH + 1]; /* Allocate buffer for printable characters */

for(i = 0; i < n; i++) /* For the specified length */
{
if(i > 0 && i % WIDTH == 0) /* If at end of line */
{
buf[WIDTH] = 0; /* Terminate the string */
printf("%s\n", buf); /* And print it with a newline */
}
printf("%02X ", p[i]); /* Print the next value from memory */
buf[i % WIDTH] = isprint(p[i]) ? p[i] : ' '; /* If printable store in buffer else store space
*/
}
putchar('\n'); /* Terminate last line */
}
return 0; /* Program ended successfully */
}

Note that this program will only work if your program is allowed
to access the specified memory range.

Sample run:

C:\docs\prog\c>gcc -std=c99 -pedantic -Wall -W -O2 rom.c -o rom

C:\docs\prog\c>rom 99 22ff00
7C 02 00 00 72 6F 6D 00 39 39 00 32 32 66 66 30 30 00 FD | rom 99 22ff00
7F FF FF FF FF 00 00 00 00 01 00 00 00 0D 00 0E 00 20 3C <
23 00 E0 FF 22 00 90 00 01 61 E0 FF 22 00 00 00 00 00 FF # " a "
FF FF FF 78 FF 22 00 90 FF 22 00 ED 52 00 61 E0 FE 0C 61 x " " R a a
FE FF FF FF D8 03 00 00 04 FE 0C 61 00 00 00 00 00 00 00 a
00 02 00 00

As you can see on the right, I picked the memory area that my
implementation uses to store the command line strings.

--
Simon.
Nov 13 '05 #3
Bill Cunningham wrote:
I'm trying to write a program that will take ROM and show the values. Is
that address 0-255? Depends on your platform. On my platform ROM is 0x0000
to 0x7fff. But on another similar platform, it is RAM.

Would this involve malloc or memcpy? Not malloc, since malloc _allocates_ read and writeable memory from
some operating system specified area. There is no method in C to
tell malloc() where to allocate from.

You could use memcpy, but that would be duplicating the effort.
Why not just read the values directly?
const unsigned char * p_byte = 0x1000;
printf("Value at 0x1000 is: 0x%02X\n", *p_byte);
{This is provided that the operating system and your platform allow
access to this address and there is something to read at the above
address.}

How can you alter memory values if you do know how to find them?

Bill


You can either find the documentation that describes the memory
mapping of your platform or use random addresses.

But then, maybe you should not be modifying those values.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 13 '05 #4
As you can see on the right, I picked the memory area that my
implementation uses to store the command line strings.
How do you find out what RAM memory you have? Write a C program I guess. I
have 96M CPU.



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #5
On Thu, 6 Nov 2003 22:10:40 -0500
"Bill Cunningham" <nospam@net> wrote:
As you can see on the right, I picked the memory area that my
implementation uses to store the command line strings.

How do you find out what RAM memory you have? Write a C program I
guess. I have 96M CPU.


You read your documentation and/or ask on a group dedicated to your
platform. Standard C has no mechanism for finding out how much RAM you
have.
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.
Nov 13 '05 #6

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

Similar topics

4
by: sci | last post by:
Could someone help me by answering the questions below? What's a cursor? What's difference between Query and View? Is a RecordSet just part of a table? Can it be part of a query of view? If...
0
by: Mohsen Memarian | last post by:
When I use a Tree-View ( with few nodes ) in my web page, and then , when I browse it in the client, it takes 1MB memory, and this memeory never releases until I close the Internet-Explorer . If...
0
by: AMDIRT | last post by:
I have a few questions about IssueVision (from WindowsForms) concerning its scalability and performance. Rather, if I were to implement techniques described here into another application, how...
8
by: Jef Driesen | last post by:
I'm implementing some image processing algorithms in C++. I created a class called 'image' (see declaration below), that will take care of the memory allocations and some basic (mathematical)...
2
by: Chris | last post by:
I think I already know that the answer is that this can't be done, but I'll ask anyways. Suppose you want to use an RDBMS to store messages for a threaded message forum like usenet and then...
19
by: Lyle Fairfield | last post by:
I have developed ADPs now for three years, in Ac2K and AcXP. I have sold two ADP applications for > $30,000 USD, one to a large company in Atlanta, and one to a local (Ontario, Canada) school...
40
by: Fao, Sean | last post by:
A guy at http://www.embedded.com gave his opinion on the C language and I was shocked to see the number of supporters for the author.  I also find it hard to believe that 99% of all code has memory...
1
by: Sureshbari | last post by:
Dear All, I have four table in database , each table contain the 5 lacs record, i have created a view on that four table using union clause. and now i am call that view form my code like ...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.