# Changeset 522 for Deliverables/D4.1/ITP-Paper/itp-2011.tex

Ignore:
Timestamp:
Feb 15, 2011, 4:42:15 PM (9 years ago)
Message:

completed changes to discussion on labels and pseudoinstructions

File:
1 edited

### Legend:

Unmodified
 r521 \label{subsect.labels.pseudoinstructions} % Compare to SDCC assembly % Need labels for separate compilation, should we implement it at a later date % Discuss Move instruction more, and labels for the GLOBALS As part of the CerCo project, a prototype compiler was being developed in parallel with the emulator. Easing the design of the compiler was a key objective in implementing the emulator. For this reason, we introduced notion of \emph{pseudoinstruction} and \emph{label}. The MCS-51's instruction set has numerous instructions for unconditional and conditional jumps to memory locations, calling procedures and moving data between memory spaces. Aside from implementing the core MCS-51 instruction set, we also implemented \emph{pseudoinstructions} and \emph{labels}. Introducing pseudoinstructions had the effect of simplifying a C compiler---another component of the CerCo project---that was being implemented in parallel with our implementation. To understand why this is so, consider the fact that the MCS-51's instruction set has numerous instructions for unconditional and conditional jumps to memory locations. For instance, the instructions \texttt{AJMP}, \texttt{JMP} and \texttt{LJMP} all perform unconditional jumps. However, these instructions differ in how large the maximum size of the offset of the jump to be performed can be. Further, all jump instructions require a concrete memory address, to jump to, to be specified. Further, all jump instructions require a concrete memory address---to jump to---to be specified. Requiring the compiler to compute these offsets, and select appropriate jump instructions, was seen as needleslly burdensome. Instead, we introduced generic \texttt{Jump}, \texttt{Call} and \texttt{Move} instructions. These are expanded into MCS-51 assembly instructions with an assembly phase, prior to program execution. Further, we introduced a notion of label (represented by strings), and introduced pseudoinstructions that allow conditional jumps to jump to labels. These are also removed during the assembly phase, and replaced by concrete memory addresses and offsets. Introducing labels also had a simplifying effect on the design of the compiler. Instead of jumping to a concrete address, the compiler could just' jump to a label. In this vein, we introduced pseudoinstructions for both unconditional and conditional jumps to a label. Further, we also introduced labels for storing global data in a preamble before the program. A pseudoinstruction \texttt{Mov} moves (16-bit) data stored at a label into the (16-bit) register \texttt{DPTR}. We believe this facility, of storing global data in a preamble referenced by a label, will also make any future extension considering separate compilation much simpler. Our pseudoinstructions and labels induce an assembly language similar to that of SDCC. All pseudoinstructions and labels are assembled away', prior to program execution, using a preprocessing stage. Jumps are computed in two stages. The first stage builds a map associating memory addresses to labels, with the second stage removing pseudojumps with concrete jumps to the correct address. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% One peculiarity is the packing of the 24 combined SFRs into fixed length vectors. This was due to a bug in Matita when we were constructing the emulator, since fixed, where the time needed to typecheck a record grew exponentially with the number of fields. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \label{subsect.computation.cost.traces} % Cost labels The CerCo approach to inducing a cost model necessitates the introduction of \emph{cost labels}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%