Changeset 508 for Deliverables/D4.1

Ignore:
Timestamp:
Feb 14, 2011, 3:24:55 PM (10 years ago)
Message:

Changes

File:
1 edited

Legend:

Unmodified
 r507 \label{subsect.labels.pseudoinstructions} The MCS-51's instruction set has numerous instructions for jumping to memory locations, calling procedures and moving data between memory spaces. For instance, the instructions \texttt{AJMP}, \texttt{JMP} and \texttt{LJMP} all perform jumps. However, these instructions differ in how large the maximum size of the offset in memory of the jump performed can be. Selecting a jump instruction therefore requires the compiler to compute the size of the offset and select the most suitable instruction. In parallel with the implementation of the emulator was the implementation of a prototype compiler. It was recognised that it would simplify the design of the compiler if the emulator introduced a notion of \emph{pseudoinstruction}. That is, instead of requiring that the compiler select the most appropriate jump instruction, for instance, we introduce a single pseudoinstruction \texttt{Jump}. Similarly, we introduce pseudoinstructions for generic calls, 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. 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. 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. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Putting dependent types to work} \label{subsect.putting.dependent.types.to.work} A peculiarity of the MCS-51 is the non-orthogonality of its instruction set. For instance, the \texttt{MOV} instruction, can be invoked using one of sixteen combinations of addressing modes. Such non-orthogonality in the instruction set was handled with the use of polymorphic variants in the O'Caml emulator. For instance, we introduced types corresponding to each addressing mode: \begin{quote} \begin{lstlisting} type direct = [ DIRECT of byte ] type indirect = [ INDIRECT of bit ] ... \end{lstlisting} \end{quote} Which were then used in our inductive datatype for assembly instructions, as follows: \begin{quote} \begin{lstlisting} type 'addr preinstruction = [ ADD of acc * [ reg | direct | indirect | data ] ... | MOV of (acc * [ reg | direct | indirect | data ], [ reg | indirect ] * [ acc | direct | data ], direct * [ acc | reg | direct | indirect | data ], dptr * data16, carry * bit, bit * carry ) union6 ... \end{lstlisting} \end{quote} Here, \texttt{union6} is a disjoint union type, defined as follows: \begin{quote} \begin{lstlisting} type ('a,'b,'c,'d,'e,'f) union6 = [ U1 of 'a | ... | U6 of 'f ] \end{lstlisting} \end{quote} For our purposes, the types \texttt{union2} and \texttt{union3} were also necessary. This polymorphic variant machinery worked well: it allowed us to pattern match We provide an inductive data type representing all possible addressing modes of 8051 assembly.