diff options
| -rwxr-xr-x[-rw-r--r--] | report/report.tex | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/report/report.tex b/report/report.tex index 44265b8..0837393 100644..100755 --- a/report/report.tex +++ b/report/report.tex @@ -270,6 +270,92 @@ the sub-array, and access the element at the given \textit{index}. To swap two \textit{sub-arrays}, it simply swap their \textit{pointers} in the pointer-array. +\newpage + +\subsection{Integer to ASCII} +\begin{wrapfigure}[11]{r}{0.4\textwidth} + \begin{tabular}{|c|c|c|c|c|} + \hline + \multicolumn{5}{|c|}{ASCII table :: Numeric Glyphs} \\ + \hline + 0 & 1 & 2 & 3 & 4 \\ + \hline + $48_{10}$ & $49_{10}$ &$ 50_{10}$ & $51_{10}$ &$ 52_{10}$ \\ + $30_{16}$ & $31_{16}$ & $32_{16}$ & $33_{16}$ & $34_{16}$ \\ + \hline 5 & 6 & 7 & 8 & 9 \\ + \hline + $53_{10}$ &$ 54_{10}$ & $55_{10}$ &$ 56_{10}$ & $57_{10}$ \\ + $35_{16}$ & $36_{16}$ & $37_{16}$ & $38_{16}$ & $39_{16}$ \\ + \hline + \end{tabular} + \caption{Table over numeric ASCII codes}\label{fig:ascii-table} +\end{wrapfigure} + +When converting each coordinate back into \textit{ASCII}, +we use the \textbf{Euclidean algorithm} to extract each digit, +but the result is still in binary. +\smallskip + +\noindent +To convert the binary digit to its \textit{ASCII} character, +we simply add the \textit{ASCII} code for \texttt{0}, +which is \texttt{48} in decimal and \texttt{30} in hexadecimal. +This works because each digit is in order in the \textit{ASCII Table}. +\smallskip + +\noindent +But the algorithm have the downside of getting each digit +in \textit{reverse} order, means we need to start right side of the \textit{buffer} when +adding new digits, as to not \textit{overwrite} previous digits. +\smallskip + +\noindent +So each digit needs to be shifted down to \textit{leftmost} position in memory. +\bigskip + +\noindent +To do this we used \texttt{REP MOVSB} which is a string operation in the +\textit{x86 instructionset architecture} that performs a +\textit{repeated byte copy operation}. + +\noindent +\begin{wrapfigure}[8]{l}{0.55\textwidth} + \begin{tabular}{|c|c|} + \hline + \multicolumn{2}{|c|}{\texttt{REP MOVSB} :: Operands Overview} \\ + \hline + Register/Input & Purpose \\ + \hline + \texttt{RSI} & Source memory addresse \\ + \texttt{RDI} & Destination memory addresse \\ + \texttt{RCX} & Repeat Count \\ + \texttt{DF} & Direction \\ + \hline + \end{tabular} + \caption{Table over \texttt{MOVSB} operands}\label{fig:movsb-operands} +\end{wrapfigure} + +\noindent +It copies data from the memory location pointed to by +the \textit{source} index register (\texttt{RSI}) to the location pointed to by +the \textit{destination} index register (\texttt{RDI}), +repeating this operation for a number of \textit{iterations} specified by +the count register (\texttt{RCX}). +\vspace{1cm} + +\noindent +\texttt{RSI} and \texttt{RDI} are automatically either \textit{incremented} or +\textit{decremented}, based on direction flag (\texttt{DF}); +when the direction flag is \textit{clear}, both pointers \textit{increment}, +and when it's \textit{set} both pointers \textit{decrement}. +\smallskip + +\noindent +This \textit{instruction} is particularly useful for bulk memory operations +such as copying strings +as it encodes a potentially lengthy loop into a \textit{single} instruction, +thereby improving both code density + \section{Evaluation} To evaluate whether out program works, we created three \textit{shell scripts}, |