home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18705 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.8 KB

  1. Path: sparky!uunet!spool.mu.edu!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!sobeco!philmtl!ray
  2. From: ray@philmtl.philips.ca (Ray Dunn)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Peek/Poke in C
  5. Message-ID: <1992Dec20.011645.17632@philmtl.philips.ca>
  6. Date: 20 Dec 92 01:16:45 GMT
  7. References: <BV5XVB5w165w@blackwlf.gwinnett.com> <behrenss.724679975@hphalle6>
  8. Organization: Not Philips.
  9. Lines: 32
  10.  
  11. In refd article, behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens) writes:
  12. >>ericwebb@blackwlf.gwinnett.com (eric webb) writes:
  13. >>>Hi again.. does anyone know how to do equivalent of BASIC's PEEK & POKE
  14. >>>statements in C?
  15. >
  16. >Very implentation-specific. Some architectures allow something along
  17. >the lines of
  18. >
  19. >char *address;
  20. >
  21. >address = 0x678090;
  22. >*address = 80; /* poke $678090,80 */
  23. >printf ("And peek gives us: %d\n",*address);
  24.  
  25. _All_ architectures allow the above constructions.  What is architecture
  26. specific is the range of numeric addresses which are meaningful, and
  27. whether the addresses are absolute or relative to some base or segment
  28. start address.  This is actually no different from PEEK and POKE in the
  29. general case.
  30.  
  31. There are even architectures in which you can address _registers_ in this
  32. way, and of course if running on hardware that has memory mapped I/O, the
  33. I/O ports can be accessed using the same technique too.
  34.  
  35. On the PC you can create an absolute memory address so long as you define
  36. the pointer to be of type far.  If you don't, then in small or medium model
  37. the address is taken to be relative to the start of the data segment.  Far
  38. pointers can be created into other segments by using (in MSC) the FP_SEG
  39. and FP_OFF macros.
  40. -- 
  41. Ray Dunn at home        |  Beaconsfield, Quebec  |  Phone: (514) 630 3749
  42. ray@philmtl.philips.ca  |  ray@cam.org           |  uunet!sobeco!philmtl!ray
  43.