152 lines
2.3 KiB
TeX
152 lines
2.3 KiB
TeX
\documentclass[a4paper]{article}
|
|
\usepackage{listings}
|
|
\usepackage{fontspec}
|
|
\usepackage[margin=1in]{geometry}
|
|
\usepackage{amsmath}
|
|
\usepackage{multicol}
|
|
|
|
\renewcommand{\thesection}{Task \arabic{section}}
|
|
\renewcommand{\thesubsection}{\arabic{subsection})}
|
|
\renewcommand{\thesubsubsection}{\alph{subsubsection})}
|
|
|
|
\setmonofont[Scale=0.9]{Antikor Mono Medium}
|
|
|
|
\input{fasto.sty}
|
|
|
|
\setlength{\parskip}{5pt}
|
|
\setlength{\parindent}{0pt}
|
|
|
|
\title{W2 - IPS}
|
|
\author{Nikolaj Gade (qhp695)}
|
|
\date{May 2022}
|
|
|
|
\newcommand{\partthing}[3]{%
|
|
{\center \rule{\textwidth}{2px}\\\vspace{5px}}
|
|
|
|
{\large \underline{#1}}
|
|
|
|
\texttt{#2}
|
|
|
|
\underline{#3}
|
|
|
|
\vspace{10px}
|
|
}
|
|
|
|
\begin{document}
|
|
\maketitle
|
|
\section{}
|
|
\subsection{Intermediate code}
|
|
See appendix A for the full generation.
|
|
|
|
\begin{lstlisting}
|
|
LABEL label1
|
|
t4 := v1
|
|
t5 := 1
|
|
IF t4 == t5 THEN label3 ELSE label4
|
|
LABEL label4
|
|
t0 := 1
|
|
place2 := v0
|
|
place3 := v1
|
|
t1 := place2 / place3
|
|
IF t0 < t1 THEN label2 ELSE label3
|
|
LABEL label2
|
|
t0 := v1
|
|
t3 := v0
|
|
IF t2 < t3 THEN label6 ELSE label7
|
|
LABEL label5
|
|
place4 := v0
|
|
place5 := v1
|
|
place0 := place4 - place5
|
|
v0 := place0
|
|
GOTO label7
|
|
LABEL label6
|
|
place6 := v1
|
|
place7 := v0
|
|
place1 := place6 - place7
|
|
v1 := place1
|
|
GOTO label5
|
|
LABEL label7
|
|
GOTO label1
|
|
LABEL label3
|
|
\end{lstlisting}
|
|
|
|
\newpage
|
|
\subsection{MIPS code}
|
|
|
|
\begin{lstlisting}
|
|
label1:
|
|
mov t4, v1
|
|
addi t5, R0, 1
|
|
beq t4, t5, label3
|
|
label4:
|
|
addi t0, R0, 1
|
|
mov place2, v0
|
|
mov place3, v1
|
|
div place2, place3
|
|
mflo t1
|
|
addi t1, t1, 1
|
|
slt rd, t0, t1
|
|
beq rd, R0, label3
|
|
label2:
|
|
mov t0, v1
|
|
mov t3, v0
|
|
slt rd, t2, t3
|
|
bne rd, R0, label6
|
|
j label7
|
|
label5:
|
|
mov place4, v0
|
|
mov place5, v1
|
|
sub place0, place4, place5
|
|
mov v0, place0
|
|
j label7
|
|
label6:
|
|
mov place6, v1
|
|
mov place7, v0
|
|
sub place1, place6, place7
|
|
mov v1, place1
|
|
j label5
|
|
label7:
|
|
j label1
|
|
label3:
|
|
\end{lstlisting}
|
|
|
|
\section{}
|
|
|
|
\subsection{\texttt{z := x >= y}}
|
|
|
|
\begin{lstlisting}
|
|
sub v, y, x
|
|
slti z, v, 1
|
|
\end{lstlisting}
|
|
|
|
\subsection{\texttt{w := !z}}
|
|
|
|
\begin{lstlisting}
|
|
slt w, R0, z
|
|
\end{lstlisting}
|
|
|
|
\subsection{\texttt{z := x >= y, w := !z}}
|
|
|
|
\begin{lstlisting}
|
|
slt w, x, y
|
|
\end{lstlisting}
|
|
|
|
\newpage
|
|
\section{}
|
|
\subsubsection{}
|
|
\begin{lstlisting}
|
|
bool* y = (bool*)malloc(n*4);
|
|
int i = 0;
|
|
while (i < n) {
|
|
ne = myop(ne, x[i*4]);
|
|
y[i*4] = ne;
|
|
i++;
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\newpage
|
|
\appendix
|
|
\section{Intermediate code generation}
|
|
\input{appendix_a.tex}
|
|
|
|
\end{document} |