Interrupt Entry and Exit Code
Interrupt procedures also need some initialization and finalization. Turbo Pascal generates interrupt entry code that saves registers, creates stack frame and sets DS
register to data segment.
Function GenerateInterruptEntryCode: Word;
begin
GenerateInstruction_TwoBytes (PUSH_AX, PUSH_BX);
GenerateInstruction_TwoBytes (PUSH_CX, PUSH_DX);
GenerateInstruction_TwoBytes (PUSH_SI, PUSH_DI);
GenerateInstruction_TwoBytes (PUSH_DS, PUSH_ES);
CreateStackFrame;
GenerateInstruction_Byte (MOV_AX_Immediate);
GenerateReference (SymbolTable [stMain].Segment, 0, 0, [rfDataSegment, rfSegment]);
GenerateInstruction_Word (MOV_DS_AX);
GenerateInterruptEntryCode := EndSubroutine
end;
Interrupt exit code reverses the proces: it destroys stack frame, restores registers and returns from the interrupt.
Function GenerateInterruptExitCode: Word;
begin
DestroyStackFrame;
GenerateInstruction_TwoBytes (POP_ES, POP_DS);
GenerateInstruction_TwoBytes (POP_DI, POP_SI);
GenerateInstruction_TwoBytes (POP_DX, POP_CX);
GenerateInstruction_TwoBytes (POP_BX, POP_AX);
GenerateInstruction_Byte (IRET);
GenerateInterruptExitCode := EndSubroutine;
end;