<title=Protected Mode General Considerations>
<keywords=protected mode general considerations programming information pm PM>


  This compiler generates a 32-bit code that will be executed in Protected
Mode. These are some things you should know :

    1. The program is loaded in high memory (above 1Mb).
  That's why a variable used in your program can not be accesed in Real Mode.
  That's why you should use for your Real-Mode operations (DOS support,
 DOS interrupts, BIOS interrupts, file access, etc.) buffers allocated in low
memory region (obtained using lalloc function, for example), buffers that can
be accessed in Real-Mode.

    2. The Code Segment,the Data Segment and the Stack Segment (CS,DS and SS)
  point to the same location : the begining of the memory block where the
  program was loaded. And all the addresses (of variables, of functions,
  pointers) are relative to DS. ES segment points to the absolute begining
  of the system 's memory, and using ES can be accessed variables and other
  objects which have absolute adresses (the screen, the BIOS parameter area,
  or variables from your program, which have absoulute addresses - see
  language.txt).

    3. Because the code is a 32 bit code, using 32 bit registers is faster
  then using 16 bit registers. And don't forget, the Stack is 32-bit too,
  so you should use pushad/popad/pushfd/popfd/iretd instead of
  pusha/popa/pushf/popf/iret, or else you may have problems.

    4. If you use IRQ-handler or interrupt-handler functions, the DS, CS or
  SS segments may be modified. A copy of these segments is in CS segment.
  So, first initialise DS with the asm instruction : mov ds,cs:DSselector,
  and the initialise ES with : mov es,ESselector. If you do not initialise
  DS and ES with program's default registers, you may get into troubles
  (you may not have access to program's variables, and write who-know-where).

