Microsoft "C" How to Peek and Poke?

Doug Gwyn gwyn at brl-smoke.ARPA
Sat Jul 9 14:45:01 AEST 1988


In article <1148 at cod.NOSC.MIL> ammons at cod.NOSC.MIL (Tempest P. Ammons) writes:
>   How can a Microsoft "C" programmer read and write the contents of
>   a particular memory location in an IBM-PC compatble (ie. Zenith Z-248)?
>   That is, how can you peek and poke in Microsoft C?

If you really must stoop to such a disgusting habit, the following
approach should work on any reasonable C implementation on any system
that does not use memory mapping.  (For 80x86 implementations, you may
need to resort to kludgery such as using a "far" keyword; I don't
program those critters so I'm not 100% familiar with all the crocks
that typical 80x86 implementations seem to force on you.)

	#define	PEEK_8( byte_loc )	(*(char *)(byte_loc))
	#define	PEEK_16( word_loc )	(*(short *)(word_loc))
	#define	POKE_8( loc, byte )	((void)(*(char *)(loc) = byte))
	#define	POKE_16( loc, word )	((void)(*(short *)(loc) = word))

Usage:
	if ( PEEK_8( 0xFF00 ) != 0x80 )
		POKE_16( 0xF080, 0x1000 );



More information about the Comp.lang.c mailing list