I used to code on a non-intel 8-bit processor years ago, and am now having a go at a little assembly from Delphi. I've been reading some of Intel's documentation (the IA-32 Intel Architechture Software Developers Manual) and am slowly getting the idea of all this stuff about segment registers. Now here's the question...

Is it utterly true that I can just ignore segments when I'm coding Win32 applications? Everywhere on the net seems to indicate that Windows uses a flat memory model and that I can just use simple 32 bit addressing. The reason I'm asking is that the CS, DS, SS, ES, FS, GS registers don't all seem to hold the same value in my application and I expected that they would on a true flat memory model.

I've been trying out the idea of creating code on the fly by placing it into an array of bytes and calling the VirtualProtect API call to get the relevant access rights from Windows, and it seems to work fine. But my guess is that my ordinary Delphi array must exist in the the data segment, and that code would normally reside in the code segment. So is it really safe me executing code that resides in the data segment?

If anyone could enlighten me I'd be dead grateful!

Thanks.
Posted on 2004-02-17 11:27:24 by philthy256