Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ihnet!tjr From: tjr@ihnet.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Functions to access memory Message-ID: <585@ihnet.ATT.COM> Date: Thu, 12-Nov-87 10:20:24 EST Article-I.D.: ihnet.585 Posted: Thu Nov 12 10:20:24 1987 Date-Received: Sat, 14-Nov-87 12:31:05 EST Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 30 > Use these sparingly! > > #define PEEK(loc) (*(char *)(loc)) > #define POKE(loc,value) *(char *)(loc) = (value) > > To access a wide datum than a byte, change "char" to "short" or "long". BEWARE! These work fine on a VAX, or other non-segmented machine; on an 8086-based machine (like an IBM PC or compatible), there is a lot more going on. A C programmer MUST be aware of the underlying hardware architecture, and of the different memory models provided by the C compiler to utilize that hardware. In the most common memory model (SMALL), the above macros will not let you reference outside of your DGROUP "segment" (DGROUP is a segment to the HW, but a "group" to the linker - thanks a bunch Microsoft (:-(); there is almost no point to such macros in SMALL memory model - PEEK() and POKE() are usually used to reference the OS or the memory-mapped display - things which are outside of DGROUP. Writing PEEK() and POKE() macros is compiler dependent - you are better off using the library routines usually supplied by the compiler manufacturer. ANOTHER GOTCHA: different compilers convert (long) to (char far *) in different ways: Turbo C: 0xB8000000L => B800:0000 Lattice C: 0x000B8000L => B800:0000 (other compilere probably use one of these - I don't know). Tom Roberts ihnp4!ihnet!tjr