This commit is contained in:
NikolajDanger
2022-05-25 09:01:19 +02:00
parent fa5488e983
commit a377292c7d
6 changed files with 42 additions and 13 deletions

View File

@ -16,7 +16,7 @@
\setlength{\parskip}{5pt}
\setlength{\parindent}{0pt}
\title{W2 - IPS}
\title{W3 - IPS}
\author{Nikolaj Gade (qhp695)}
\date{May 2022}
@ -135,15 +135,43 @@ slt w, x, y
\section{}
\subsubsection{}
\begin{lstlisting}
bool* y = (bool*)malloc(n*4);
int* y = malloc(n);
int i = 0;
while (i < n) {
ne = myop(ne, x[i*4]);
y[i*4] = ne;
ne = myop(ne, x[i]);
y[i] = ne;
i++;
}
\end{lstlisting}
\subsubsection{}
\begin{lstlisting}
lw len, 0(x) // Loads the length of x from the first word in the list
// dynalloc from group project
move regy, HP // Sets y to the start of the non-allocated memory
addi tmp, len, 3 // Adds 3 and rounds down, to line up with the 4-byte boundary
sra tmp, tmp, 2
sll tmp, tmp, 2
addi tmp, tmp, 4 // Adds space for the length of the array
add HP, HP, tmp // Moves HP
sw len, 0(regy) // Saves the length of the array in the first word
addi i, R0, 0 // int i = 0
loop_beg:
bge i, len, loop_end // while (i < n) {..
add xi, x, i // x[i]
add yi, regy, i // y[i]
MIPS.CALL(myop, (ne, xi), ne) // ne = myop(ne, x[i]);
sw ne, 0(yi) // y[i] = ne;
addi i, i, 1 // i++;
j loop_beg
loop_end:
\end{lstlisting}
\newpage
\appendix
\section{Intermediate code generation}