Updated the figure showing the layout of an instruction.

This commit is contained in:
2025-03-10 00:49:51 -05:00
parent 4f155090f3
commit 454ce519a5
2 changed files with 33 additions and 37 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ There are three data types that are understood by this machine: byte, short and
\item[Word] Exactly four bytes wide, or 32-bits.
\end{description}
\section{Registers}
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{r8}. 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.
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{r8}. These numbers do not follow a zero-based index scheme, \quotes{r29} is the twenty-ninth register.
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. One final register that can only be indirectly set is the \quotes{flags} register. This register, like the others, is one word wide meaning it can store thirty-two flags. Currently only three flags are present, the Zero, Underflow and Overflow flags. These flags are only affected by arithmetic operations and generally read by branching instructions like \hyperref[sec:jmp]{jmp}.
+32 -36
View File
@@ -1,20 +1,20 @@
\ExplSyntaxOn
\int_new:N \l_options_count
\int_new:N \l_options_loop_count
\int_new:N \l__options_count
\int_new:N \l__options_loop_count
% Opcode, Opcode Name, Description, Flags Affected, Options
% Maybe have an optional argument to relabel the operands Source and Destination
\NewDocumentCommand{\createoptabletwoparam}{ m m m m m }{
\int_set:Nn \l_options_loop_count {1}
\clist_clear_new:N \l_options
\int_set:Nn \l__options_loop_count {1}
\clist_clear_new:N \l__options
\clist_set:Nn \l_options {#3}
\clist_set:Nn \l__options {#3}
\int_set:Nn \l_options_count { \clist_count:N \l_options }
\int_set:Nn \l__options_count { \clist_count:N \l__options }
\__start_op_table:
\clist_map_inline:Nn \l_options {
\clist_map_inline:Nn \l__options {
\str_case:nnF{##1} {
{0}{
@@ -38,12 +38,12 @@
}
}{ \tl_put_right:Nn \l_tmpa_seq {#1~##1\_ & INVALID & -- & -- \\ } }
\int_compare:nT { \l_options_loop_count < \l_options_count }
\int_compare:nT { \l__options_loop_count < \l__options_count }
{
\tl_put_right:Nn \l_tmpa_seq { \midrule }
}
\int_incr:N \l_options_loop_count
\int_incr:N \l__options_loop_count
}
\__end_op_table:nn {#5} {#4}
@@ -103,35 +103,23 @@ The logical ordering of the arguments follows the AT\&T syntax, meaning the left
\begin{verbatim}
mov 40, r1
\end{verbatim}
This is in contrast with how the data is laid out physically in memory, following the conventions described in section \ref{sec:conventions}~\nameref{sec:conventions}. Figure \ref{fig:encodingphysicallayout} shows how an instruction would be laid out. The operands can be of varying sizes based on the low nibble of the Options byte or, depending on the instruction, may only consist of an Opcode byte. The Source and Destination may have any one of the following three widths, in any combination:
This is in contrast with how the data is laid out physically in memory, following the conventions described in section \ref{sec:conventions}~\nameref{sec:conventions}. Figure \ref{fig:encodingphysicallayout} shows how an instruction would be laid out. The operands can be of varying sizes based on the low nibble of the Options byte or, depending on the instruction, may only consist of an Opcode byte. The Source, Destination and Destination Offset may have any one of the following three widths, in any combination:
\begin{verbatim}
byte, short, or word
\end{verbatim}
For the exact definition of these data types please refer to section \ref{sec:conventions} as mentioned above.
If the \textit{Destination Offset} bits are set in the Options byte, then immediately following the Destination will be an immediate value that is added to the Destination.
%Because this machine is little endian, the opcode byte is physically located on the right hand-side of a word.
% Placement info here: https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Figures
% Paths: https://tikz.dev/tikz-paths
\begin{figure}[ht]
\begin{tikzpicture}
%\draw[help lines] (-8,-5) grid (8,5);
\node [draw, fit={(- 8.00, 0.00) (-12.00, 0.75)}, inner sep=0, label=center:Destination] (argtwo) {};
\node [draw, fit={(- 4.00, 0.00) (- 8.00, 0.75)}, inner sep=0, label=center:Source] (argone) {};
\node [draw, fit={(- 2.00, 0.00) (- 4.00, 0.75)}, inner sep=0, label=center:Options] (options) {};
\node [draw, fit={( 0.00, 0.00) (- 2.00, 0.75)}, inner sep=0, label=center:Opcode] (opcode) {};
\node [draw, fit={( 0.00, 1.50) (- 4.00, 2.25)}, inner sep=0, label=center:Offset] (offset) {};
\node at (argtwo.north)[above] {(if required)};
\node at (argtwo.north west)[above] {31};
\node at (argone.north)[above] {(if required)};
\node at (argone.north west)[above] {24 23};
\node at (options.north west)[above] {16 15};
\node at (opcode.north west)[above] {8 7};
\node at (options.south)[below] {(if required)};
\node at (opcode.north east)[above] {0};
\node at (offset.north east)[above] {32};
\node at (offset.north west)[above] {39};
\node at (offset.north)[above] {(if required)};
% Row 0
\node [draw, fit={( 0.0, 0.00) ( 2.5, 0.75)}, inner sep=0, label=center:Opcode] (opcode) {};
\node [draw, fit={( 0.0, 0.00) ( -2.5, 0.75)}, inner sep=0, label=center:Options] (options) {};
\node [draw, fit={(-2.5, 0.00) ( -5.0, 0.75)}, inner sep=0, label=center:Source] (source) {};
\node [draw, fit={(-5.0, 0.00) ( -7.5, 0.75)}, inner sep=0, label=center:Destination] (destination) {};
\node [draw, fit={(-7.5, 0.00) (-10.0, 0.75)}, inner sep=0, label=center:Offset] (destination) {};
% Use the calc library to calculate the center of two points.
% Reference: https://tex.stackexchange.com/a/71479
%\node at ($(highestbit.north)!0.5!(lowestbit.north)$)[above] {Physical Layout};
@@ -144,20 +132,20 @@ For the exact definition of these data types please refer to section \ref{sec:co
The Options byte makes use of all 8 bits to encode something about the instruction that precedes it. Reading the byte from left to right, we have the following properties:
\begin{itemize}
\item Operand Type
\item Operand as Pointer
\item Operand is Pointer
\item Destination Offset
\item Source Width.
\end{itemize}
Starting with the high nibble we have two \quotes{columns}, \textit{Operand Type} and \textit{Operand as Pointer}, both spanning 2 bits for a total of 4 bits. The first two bits describe the type of operand we're expecting, zero (0) for \textit{register} and one (1) for an \textit{immediate} value. Bit 7 is for the source operand and bit 6 for the destination operand. Following this same layout (source then destination) we have two bits that say whether or not the operand should be treated as a pointer, zero (0) for no and one (1) for yes. For register type arguments this means to read the contents of whatever register is specified and treat that value as a full width pointer. If the argument is an immediate value, then we simply read one word and treat that word as a pointer.
Starting with the high nibble we have two \quotes{columns}, \textit{Operand Type} and \textit{Operand is Pointer}, both spanning 2 bits for a total of 4 bits. The first two bits describe the type of operand we're expecting, zero (0) for \textit{register} and one (1) for an \textit{immediate value}. Bit 7 is for the source operand and bit 6 for the destination operand. Following this same layout (source then destination) we have two bits that say whether or not the operand should be treated as a pointer, zero (0) for no and one (1) for yes. For register type arguments this means to read the contents of whatever register is specified and treat that value as a full width pointer. If the argument is an immediate value, then we simply read one word and treat that word as a pointer.
The lower nibble consists of two \quotes{columns}, the same width as the previous two, that describe what kind of offset, if any, to apply to the destination operand and how many bytes are to be read from the source operand. Starting with bit 3 and ending on bit 2 we have the number of bytes to read for an offset. Bits 1 and 0 say how many bytes should be read from the source, which could be a register, an immediate value, or a pointer.
The lower nibble consists of two \quotes{columns}, the same width as the previous two, that describe what kind of offset, if any, to apply to the destination operand and how many bytes are to be read from the source operand. Starting with bit 3 and ending on bit 2 we have the number of bytes to read for an offset. Bits 1 and 0 say how many bytes should be read from the source, which could be a register, an immediate value or a pointer.
\begin{figure}[ht]
\begin{tabular}{cccccccc}
\begin{tabular}{ c c c c c c c c }
\toprule
%\multicolumn{8}{c}{Bit Position} \\
\multicolumn{2}{c}{Type} & \multicolumn{2}{c}{Pointer} & \multicolumn{2}{c}{ } & \multicolumn{2}{c}{ } \\
7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\
\multicolumn{2}{c}{Type} & \multicolumn{2}{c}{Is Pointer} & \multicolumn{2}{c}{ } & \multicolumn{2}{c}{ } \\
7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\
\midrule
Source & Destination & Source & Destination & \multicolumn{2}{c}{Offset} & \multicolumn{2}{c}{Source Width} \\
\bottomrule
@@ -166,10 +154,18 @@ The lower nibble consists of two \quotes{columns}, the same width as the previou
\label{fig:optionsbitlayout}
\end{figure}
The offset and source width bits both have effectively the same meaning, which is as follows:
\begin{verbatim}
00 - None or N/A (For instructions that take no arguments)
01 - Byte
10 - Short
11 - Word
\end{verbatim}
\section{Instructions}
Following is a complete listing of all supported instructions where the first two hexadecimal digits (starting from the left most digit in the Opcode column) represents the actual opcode byte that would be expected in object code. If the instruction expects an options byte then the next hexadecimal digit denotes the operand mode for the instruction. An underscore (\_) denotes that the low nibble of the options byte is to be set based on the instruction.
The Instruction column shows the assembly syntax that represents the opcode, with the letter \textit{r} representing any register such as \textit{r32} and \textit{imm} for any numeric literal. This numeric literal could be a memory address or a number to start a counter, the semantics don't matter in this instance. The last two columns simply provide at a glance the operands, in the order they appear in the assembly sample, Source and Destination respectively.
The Instruction column shows the assembly syntax that represents the opcode, with the letter \textit{r} representing any register such as \textit{r32} and \textit{imm} for any numeric literal. This numeric literal could be a memory address or a number to start a counter, the semantics don't matter in this instance. The last two columns simply provide at a glance, the operands, in the order they appear in the assembly sample, Source and Destination respectively.
\subsection{Add}
\createoptabletwoparam{01}{add}{0, 8}{ OF and ZF. }
{