Updated chapter 1 to be more fleshed out.

This commit is contained in:
2025-02-02 00:15:44 -06:00
parent 05adb3d0c9
commit f85a74bd83
3 changed files with 18 additions and 48 deletions
+11 -44
View File
@@ -1,47 +1,14 @@
\chapter{Overview}
This is an attempt to distill what I know about how computers work into some kind of emulator / simulator. I'm curious to see if what I know at the moment is enough to allow me to emulate a general purpose computer. A computer that will be big-endian, using 8-bit bytes for its char type. The memory is a 32 bit linear address space allowing for a maximum of 2\textsuperscript{32} bytes to be addressable.
\chapter{Introduction}
This is an attempt to distill what I know about how computers work into some kind of emulator / simulator. I'm curious to see if what I know at the moment is enough to allow me to emulate a general purpose computer. It turns out that it take quite a different skillset compared to writing web applications or desktop applications. But I realize that, while I understand the concepts that underpin what I do day to day, I don't have an intuitive understanding of the hardware. This has become painfully evident pretty much immediately after I started this project. An ISA should be simple, add, subtract, copy, etc., but the you have to consider the state the processor will be in after each instruction.
\section{Registers}
Eight 32-bit general purpose registers are available for holding operands and memory addresses along with a Flags Register. The Flags Register is a 32-bit register allowing for 32 flags. Currently there are only arithmetic flags which are Overflow (OF), Underflow (UF), and a Zero Flag (ZF). The overflow flag is set if there is a carry. A base pointer register contains a 32 bit address that points to the start of the current stack frame, which is the first opcode of the stack frame. Therefore the first argument would be addressed as such:
\begin{verbatim}
mov r1, bp - sizeof(void *)
\end{verbatim}
Finally we have the Program Counter which contains a 32 bit address that points to the next instruction to execute.
Thirty-two general purpose registers are available for program code to use however it wishes. The base name for the general purpose registers is \quotes{r} follows by an unpadded number, such as \quotes{r28}. These numbers do not follow a zero-based index scheme, \quotes{r29} is the twenty-ninth register. Using the base name implies full width, a \quotes{word}, when reading or writing from or to the register respectively. In addition to the general purpose registers there is also a base pointer (bp), stack pointer (sp) and an instruction pointer (ip). The base pointer and the stack pointer may be set directly using the \hyperref[sec:mov]{mov} instruction, which allows the programmer to set up a stack frame. The instruction pointer can only be set with a branching operation like \hyperref[sec:jmp]{jmp} or a call to a subroutine with the \hyperref[sec:call]{call} instruction.
\def\minY{-5} \def\maxY{5}
\def\minX{-5} \def\maxX{5}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[node distance=0cm]
\node [draw, fit={(\minX, 1.0) (0, 1.5)}, label=center:Program Counter] (pc) {};
\node [draw, fit={(\minX, 0) (0, 0.5)}, label=center:Flags] (flags) {};
\node [draw, fit={(\minX, -1) (0, -1.5)}, label=center:r1] (r1) {};
\node [draw, fit={(\maxX / 2, 0) (\maxX, \minY)}, label=center:Memory] (memory) {};
\begin{description}
\item In summary, the available registers are as follows:
\item[General Purpose] Thirty-two general purpose registers that are the width of a \textit{word} and numbered \quotes{r1} through \quotes{r32}
\item[Base Pointer (bp)] Points to the call location when a function call is made
\item[Stack Pointer (sp)] points to the end of the last argument after a function call is executed, which may be the return address of the stack
\item[Instruction Pointer (ip)] Points to the next instruction to execute and advanced by the width of an instruction. Set by jump or call instructions to the location specified by the instruction.
\end{description}
\draw (pc);
\node[above =of pc] {Status Registers};
\node[above left =of pc] {31};
\node[above right =of pc] {0};
\draw (flags);
\draw (r1);
\node[above =of r1] {General Purpose Registers};
\node[above left =of r1] {31};
\node[above right =of r1] {0};
\foreach \pos in {2,...,8} {
\node [draw, fit={(\minX, -\pos) (0, -\pos - 0.5)}, label=center:r\pos] (r\pos) {};
\draw (r\pos);
}
\draw (memory);
\node [above =of memory] {Linear Memory (2\textsuperscript{32} Bytes)};
\node [above right =of memory, yshift=-1em] {0};
\node [below right =of memory, yshift=1em] {2\textsuperscript{32 - 1}};
%\draw (memory.north east) -- (memory.south west);
%\node at (memory.south east) {test};
\end{tikzpicture}
\caption{Register Bit Layout}
\end{figure}
\section{Memory Layout}
\section{Memory}
+3 -3
View File
@@ -144,7 +144,7 @@ The /r represents a byte that specifies a register. /immX is for the immediate d
\end{tabularx}
\paragraph{Description} Divides two unsigned values, the source (operand one) and the destination (operand two), storing the result in destination. The underflow flag (UF) is set if the result is greater than the source and the zero flag (ZF) is set when the result of subtraction is zero.
\paragraph{Flags Affected} UF and ZF.
\subsection{Mov}
\subsection{Mov}\label{sec:mov}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
@@ -291,7 +291,7 @@ The /r represents a byte that specifies a register. /immX is for the immediate d
\end{tabularx}
\paragraph{Description} Compares \textit{operand one} to \textit{operand two} by subtracting \textit{operand one} from \textit{operand two}, updating the status register with the results. If \textit{operand one} is larger than the result, and the result is not zero, the overflow flag (OF) is set. If \textit{operand one} is smaller than the result, and the result is not zero, the underflow flag (UF) is set. And if the result of the subtraction is zero the zero flag (ZF) is set.
\paragraph{Flags Affected} OF, UF and ZF.
\subsection{JMP}
\subsection{JMP}\label{sec:jmp}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
@@ -422,7 +422,7 @@ The /r represents a byte that specifies a register. /immX is for the immediate d
\end{tabularx}
\paragraph{Description} Pops all general purpose registers from the stack, restoring them, in the reverse order of \textit{r8} to \textit{r1}.
\paragraph{Flags Affected} None.
\subsection{CALL}
\subsection{CALL}\label{sec:call}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
+3
View File
@@ -4,6 +4,7 @@
\usepackage{multirow}
\usepackage{xintbinhex}
\usepackage[linkcolor=Aquamarine, linktoc=all, colorlinks=true]{hyperref}
\usepackage{environ}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}
@@ -11,6 +12,8 @@
%\usepackage{showframe} % Good for debugging, uncomment to see the bounding boxes for the various sections of a page.
\newcommand{\quotes}[1]{``#1''}
\begin{document}
\title{Unnamed Machine}
\author{An attempt to understand the makings of a computer arch}