Date: Wed, 26 Oct 94 22:04:14 EDT From: peprbv AT cfa0 DOT harvard DOT edu (Bob Babcock) To: grendel AT mail DOT csh DOT rit DOT edu Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Re: Program works only when not optimized. Why? Reply-To: babcock AT cfa DOT harvard DOT edu > The following short program tries to read the palette from the video card > and print each rgb triplet. On either of the systems I've tried it on it > dumps in the readpal routine if I optimize it. Your readpal routine uses _go32_dpmi_simulate_int() without initializing ss and sp. Unless they both happen to be zero, they are used as-is. So, some random area of memory is being used as stack space. Turning on optimization probably just moves the corrupted area to someplace harmful. The safest thing to do is to zero the entire regs structure before assigning the registers which you really care about. The docs don't mention it, but some recent messages indicated that the value of the flags register could also cause trouble if, say, the single-step bit happened to be set.