incrementing addresses 
Author Message
 incrementing addresses

Hello - I'm trying simple read/write operations to memory and need some help
with getting started.  I've tried this: for(x = 0x1d200000; x < 0x1d201ffc;
x++)  printf("Contents of address: %x are %x .\n",x,*x); and          &x      =
0x1d200000;  &pointer2 = 0x1d201ffc; ... while(x != pointer2)  {  x++;
printf("Contents of address: %x are %x .\n",x,*x);  } what am I doing
wrong, and what are some tips I can use?  thanks. Dan

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 26 Nov 2002 03:00:00 GMT  
 incrementing addresses
Aargh! Stop using those silly CR line delimiters and use LF line
delimiters instead! This post appears as follows on tin:

Hello -^M^MI'm trying simple read/write operations to memory...

While I'm sure you wished it to appear like so:

Hello -

I'm trying simple read/write operations to memory...


: Hello -

I'm trying simple read/write operations to memory and need some help
: with getting started.  I've tried this:

 for(x = 0x1d200000; x < 0x1d201ffc;
: x++)
  printf("Contents of address: %x are %x .\n",x,*x);

I hope you've declared x as a pointer (like unsigned char *) and not as
an int or long. Anyway a better solution is to compare an offset from
the pointer instead of the pointer:
unsigned char *x;
unsigned long i;
x=(unsigned char *)0x1d200000;
for (i=0; i<0x1ffc; i++)
  printf("Contents of address: %x are %x .\n", 0x1d200000+i, *(x+i));

and

  &x        =
: 0x1d200000;
  &pointer2 = 0x1d201ffc;
...

This is simply wrong. Never try to set the address of a variable
yourself. For one thing, it's a compiler error (addresses aren't
lvalues), for another, it doesn't make sense. To set a pointer to
an absolute address try this:
unsigned char *x;
x=(unsigned char *)0x1d200000;

while(x != pointer2)
  {
  x++;

: printf("Contents of address: %x are %x .\n",x,*x);
  }

what am I doing
: wrong, and what are some tips I can use?  thanks.

Dan

What you are doing wrong is that you are happily mixing up addresses,
pointers, and scalar values. If you follow my advice on this post,
this code should work on most common platforms (like Windows, Unix,
Amiga...) but on systems with memory protection (like Unix) you will
get a segmentation fault if you try to read the contents of memory
that doesn't belong to you. Also note that not all systems allow
assigning absolute addresses to pointers in the first place.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ |
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/

"Stronger, no. More seductive, cunning, crunchier the Dark Side is."
   - Mika P. Nieminen



Tue, 26 Nov 2002 03:00:00 GMT  
 incrementing addresses

Quote:

>Hello -I'm trying simple read/write operations to memory and need some help
>with getting started.

Generally, you are not allowed to access the whole memory.
Most operating systems will prevent you from reading/writing
to an address which does not belong to your address space.

Some systems (e.g. DOS) don't limit the access. E.g. in
Borland C++ 3.1 (for DOS) you can access any address
in such a way:

char far *p;
p = (char far*)0xb8000000l;   /*  video memory, b800:0000  */
*p= 65;                       /*  write something          */

PF



Tue, 26 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pointers & incrementing array address

2. pre-increment v.s. post-increment

3. pre increment and post increment

4. How to get MAC address from IP Address

5. convert mac address to ip address

6. How can i get MAC Address by IP address in SCO UNIX C

7. PMode Address -> Segment:Offset Address

8. address of structure == address of first member? (long)

9. Incomplete import address table causes jump to invalid address

10. Determinig a machine's Physical Address (MAC Address)

11. Obtaining a PCI address vs a virtual address?

12. IP address and Mac Address help!!!

 

 
Powered by phpBB® Forum Software