Cleaned up the code a bit and updated Figure 2.1 to show the physical layout of an instruction. Added some text in Section 2.1.
This commit is contained in:
+30
-61
@@ -12,25 +12,25 @@
|
||||
|
||||
\str_case:nnF{##1} {
|
||||
{0}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~/r,~/r & r & r \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~/r,~/r & r & r \\ \hline }
|
||||
}{1}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~/r,~[/r] & r & [r] \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~/r,~[/r] & r & [r] \\ \hline }
|
||||
}{2}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~[/r],~/r2 & [r] & r \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~[/r],~/r2 & [r] & r \\ \hline }
|
||||
}{5}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~/r,~[imm] & r & [imm] \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~/r,~[imm] & r & [imm] \\ \hline }
|
||||
}{8}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~imm,~/r & imm & r \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~imm,~/r & imm & r \\ \hline }
|
||||
}{9}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2 ~imm,~[r] & imm & [r] \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2 ~imm,~[r] & imm & [r] \\ \hline }
|
||||
}{A}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~[imm],~/r & imm & r \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~[imm],~/r & imm & r \\ \hline }
|
||||
}{C}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~imm,~imm & imm & imm \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~imm,~imm & imm & imm \\ \hline }
|
||||
}{D}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2~imm,~[imm] & imm & [imm] \\ \hline }
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1~##1\_ & #2~imm,~[imm] & imm & [imm] \\ \hline }
|
||||
}
|
||||
}{ \tl_put_right:Nn \l_tmpa_seq {#1~##1 & INVALID & -- & -- \\ \hline} }
|
||||
}{ \tl_put_right:Nn \l_tmpa_seq {#1~##1\_ & INVALID & -- & -- \\ \hline} }
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
}{reg}{
|
||||
\tl_put_right:Nn \l_tmpa_seq { #1 & #2~/r & r & None \\ \hline }
|
||||
}
|
||||
}{ \tl_put_right:Nn \l_tmpa_seq {#1~##1 & INVALID & -- & -- \\ \hline} }
|
||||
}{ \tl_put_right:Nn \l_tmpa_seq {#1 & INVALID & -- & -- \\ \hline} }
|
||||
|
||||
\__end_op_table:nn {#5} {#4}
|
||||
|
||||
@@ -83,67 +83,36 @@
|
||||
\ExplSyntaxOff
|
||||
|
||||
\chapter{Instruction Set Architecture}
|
||||
In general instructions are variable length depending on the number of arguments and their width. The first byte of an instruction is the \textit{opcode} which tells the machine what operation is to be performed. If one or more arguments are required, then the next byte is the \textit{options} byte which describes the type and width of the argument(s). The exact meaning of all the bits in the \textit{options} byte are shown in Figure \ref{fig:opencoding}. The order of the arguments follows the AT\&T syntax, meaning the left hand argument is the \textit{source} and the right hand argument is the \textit{destination}.
|
||||
In general instructions are variable length depending on the number of arguments and their width. The first byte of an instruction is the \textit{opcode} which tells the machine what operation is to be performed. If one or more arguments are required, then the next byte is the \textit{options} byte which describes the type and width of the argument(s). The exact meaning of all the bits in the \textit{options} byte are shown in Figure \ref{fig:encodingphysicallayout}.
|
||||
|
||||
\section{Instruction Layout}
|
||||
The logical ordering of the arguments follows the AT\&T syntax, meaning the left hand argument is the \textit{source} and the right hand argument is the \textit{destination}. Of course, the way the instructions are laid out in memory is reversed since we're a \textit{little endian} machine. 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 \textit{Options} byte and, depending on the instruction, all but the \textit{Opcode} byte may be present.
|
||||
%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);
|
||||
\draw (-8, 4) node[above] {7} rectangle (-6, 3) node[above = 1] {0};
|
||||
\node at (-7, 2.5) {Opcode};
|
||||
\draw (-5, 4) node[above] {7} rectangle (-3, 3) node[above = 1] {0};
|
||||
\draw[dashed] (-4.5, 3) -- (-4.5, 4) node[above] {6};
|
||||
\draw[dashed] (-4, 3) -- (-4, 4) node[above] {4};
|
||||
\draw[dashed] (-3.5, 3) -- (-3.5, 4) node[above] {2};
|
||||
\node at (-4, 2.5) {Mode};
|
||||
\node (A) at (-4, 2.0) {(If required)};
|
||||
\node [draw, fit={( -7.5, 0.0) ( -13.5, 1.0)}, inner sep=0, label=center:Destination] (argtwo) {};
|
||||
\node [draw, fit={( -2.5, 0.0) ( - 7.5, 1.0)}, inner sep=0, label=center:Source] (argone) {};
|
||||
\node [draw, fit={( 0.0, 0.0) ( - 2.5, 1.0)}, inner sep=0, label=center:Options] (options) {};
|
||||
\node [draw, fit={( 0.0, 0.0) ( 2.5, 1.0)}, inner sep=0, label=center:Opcode] (opcode) {};
|
||||
|
||||
%Operand One
|
||||
\draw (-2, 4) node[above] {31} rectangle (2, 3) node[above = 1] {0};
|
||||
\draw[dashed] (1, 3) -- (1, 4) node[above] {7};
|
||||
\draw[dashed] (0, 3) -- (0, 4) node[above] {15};
|
||||
\node at (0, 2.5) {Source (Variable)};
|
||||
\node at (0, 2.0) {(If required)};
|
||||
%Operand Two
|
||||
\draw (3, 4) node[above] {31} rectangle (7, 3) node[above = 1] {0};
|
||||
\draw[dashed] (6, 3) -- (6, 4) node[above] {7};
|
||||
\draw[dashed] (5, 3) -- (5, 4) node[above] {15};
|
||||
\node at (5, 2.5) {Destination (Variable)};
|
||||
\node at (5, 2.0) {(If required)};
|
||||
%Mode / argument break down.
|
||||
%Fanout
|
||||
\draw (A.west) -- (-8, 0);
|
||||
\draw (A.east) -- (3, 0);
|
||||
%Operand One Type
|
||||
\draw (-8, 0) node[above] {7} rectangle (-6, -1) node[above = 1] {6};
|
||||
\node at (-7, -1.5) {Source Type};
|
||||
%Operand Two Type
|
||||
\draw (-5, 0) node[above] {5} rectangle (-3, -1) node[above = 1] {4};
|
||||
\node at (-4, -1.5) {Destination Type};
|
||||
%Reserved
|
||||
\draw (-2, 0) node[above] {3} rectangle (0, -1) node[above = 1] {2};
|
||||
\node at (-1, -1.5) {Reserved};
|
||||
%Width Descriptor
|
||||
\draw (1, 0) node[above] {1} rectangle (3, -1) node[above = 1] {0};
|
||||
\node at (2, -1.5) {Source Width};
|
||||
\node at (argtwo.north)[above] {(if required)};
|
||||
\node at (argtwo.north west)[above] (highestbit) {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] (lowestbit) {0};
|
||||
% 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};
|
||||
\end{tikzpicture}
|
||||
\caption{Encoding}
|
||||
\label{fig:opencoding} % https://www.overleaf.com/learn/latex/Referencing_Figures
|
||||
\caption{Physical Layout}
|
||||
\label{fig:encodingphysicallayout} % https://www.overleaf.com/learn/latex/Referencing_Figures
|
||||
\end{figure}
|
||||
%Argument options
|
||||
% Register first
|
||||
\newcommand{\rRArgH}{0}\newcommand{\rRaArgH}{1}\newcommand{\rAArgH}{3}
|
||||
% Register contains address first
|
||||
\newcommand{\raRArgH}{4}\newcommand{\raRaArgH}{5}\newcommand{\raAArgH}{7}
|
||||
% Immediate first
|
||||
\newcommand{\immRArgH}{8}\newcommand{\immRaArgH}{9}\newcommand{\immAArgH}{B}
|
||||
% Address first
|
||||
\newcommand{\aRArgH}{C}\newcommand{\aRaArgH}{D}\newcommand{\aAArgH}{F}
|
||||
%Width hex codes
|
||||
\newcommand{\byteWidthH}{1}\newcommand{\shortWidthH}{2}\newcommand{\intWidthH}{3}
|
||||
|
||||
\begin{figure}
|
||||
\begin{tabularx}{\textwidth}{ | c | c | X | }
|
||||
|
||||
Reference in New Issue
Block a user