Code Generator

Most compilers use some kind of intermediate code which is a program representation somewhere betwen the high-level source code and executable code for target processor. This means that the compiler does not generate the target code directly but it generates some intermediate pseudo instructions which are converted into target code after the program is compiled.

Turbo Pascal uses few procedures to generate any x86 instruction needed. In general two intermediate code records are used: one for actual inctruction opcodes and imemdiate data and one for references.

Whenever Turbo Pascal needs to reference anything that doesn't have fixed location, i.e. its address is not known yet like variables, typed constants or procedures, the compiler generates intermediate code reference record which contains all information to later resolve the reference.