Updated the way the encoding for the 'mode' byte works.

This commit is contained in:
2024-09-01 14:51:25 -05:00
parent cc4a220aed
commit abbe9828e9
+76 -56
View File
@@ -1,5 +1,5 @@
\chapter{Instruction Set Architecture}
Instructions are variable width with their total length being determined by the mode setting byte that immediately follows the opcode byte. A break down of what a nibble means in the mode setting byte can be found in Figure \ref{fig:ModeSettingEncodingFigure}. Figure \ref{fig:opencoding} shows the layout of an instruction with the mode setting byte split down the middle to indicate the top nibble defines what \textit{Operand One} is meant to be interpreted as, followed by the lower nibble for \textit{Operand Two}. Depending on what mode is set for each operand there may be no bytes to follow the instruction (like in the case of nop) or there may be 8 bytes to follow (like in the case of mov [address], [address], assuming absolute addresses).
Instructions are variable width with most instructions' width being determined by the \textit{mode} byte that follows immediately after the opcode byte. The \textit{mode} byte is split into four parts, with the upper nibble describing what the types of source and destination operands the instruction is to deal with. Following those four bits is two reserved bits and finally the final two bits in the least significant half of the lower nibble, the \textit{source width}. Depending on the \textit{source type} bits, the next number of bytes to be read for the source operand can be 8-, 16- or 32-bits and the same applies to the \textit{destination type} bits. A more visual layout of this may be found in Figure \ref{fig:opencoding}.
\newcommand{\OpcodeTable}[5] {
\noindent
@@ -14,44 +14,60 @@ Instructions are variable width with their total length being determined by the
\paragraph{Description} #5
\end{minipage}
}
\def\gap{0.25pt}
\def\minX{0}\def\maxX{\textwidth}
\def\minY{-0.25}\def\maxY{0.25}
\def\lnWidth{\textwidth / 4}
\section{Instruction Layout}
% 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}
%Opcode Byte
\draw (\minX, 0) -- (\lnWidth, 0) node[midway, below=1em] {Opcode};
\draw (\minX, \minY) node[below] {7} -- (\minX, \maxY);
\draw (\lnWidth, \minY) -- (\lnWidth, \maxY) node[above] {7};
%Mode setting byte
\draw (\lnWidth, 0) -- (\lnWidth * 2, 0) node[midway, above=1em] (ModeSettingByteLabel) {Mode};
\draw node[above of=ModeSettingByteLabel] {(if required)};
\draw (\lnWidth, \minY) node[below] {0} -- (\lnWidth, \maxY);
\draw (\lnWidth * 2, \minY) node[below] {0} -- (\lnWidth * 2, \maxY);
\draw (\lnWidth + \lnWidth / 2, \minY) node[below] (ModeByteMiddleLabel) {4 3} -- (\lnWidth + \lnWidth / 2, \maxY);
%\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] {5};
\draw[dashed] (-4, 3) -- (-4, 4) node[above] {4};
\draw[dashed] (-3.5, 3) -- (-3.5, 4) node[above] {1};
\node at (-4, 2.5) {Mode};
\node (A) at (-4, 2.0) {(If required)};
%Operand One
\draw (\lnWidth * 2, 0) -- (\lnWidth * 3, 0) node[midway, below=1em] (OperOneLabel) {Operand One};
\draw (\lnWidth * 2, \minY) -- (\lnWidth * 2, \maxY) node[above] {31/15/7};
\draw (\lnWidth * 3, \minY) node[below] {0} -- (\lnWidth * 3, \maxY);
\draw node[below of=OperOneLabel] {(if required)};
\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 (\lnWidth * 3, 0) -- (\lnWidth * 4, 0) node[midway, below=1em] (OperTwoLabel) {Operand Two};
\draw (\lnWidth * 3, \minY) -- (\lnWidth * 3, \maxY) node[above] {31/15/7} node[above=1.5em] {Operand Widths Based on Mode};
\draw (\textwidth, \minY) node[below] {0} -- (\textwidth, \maxY);
\draw node[below of=OperTwoLabel] {(if required)};
\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};
\end{tikzpicture}
\caption{Encoding}
\label{fig:opencoding} % https://www.overleaf.com/learn/latex/Referencing_Figures
\paragraph{Note} Figure \ref{fig:ModeSettingEncodingFigure} shows the options for the \textit{Mode} byte.
%\paragraph{Note} Figure \ref{fig:ModeSettingEncodingFigure} shows the options for the \textit{Mode} byte.
\end{figure}
\def\registerType{00}\def\registerValueType{01}
\def\immediateType{10}\def\addressType{11}
\def\noWidth{00}\def\eightBitWidth{01}\def\sixteenBitWidth{10}\def\thirtyBitWidth{11}
\def\registerBit{0}\def\registerBitA{8}
\def\eightBit{1}\def\eightBitA{9}
\def\sixteenBit{2}\def\sixteenBitA{A}
@@ -59,18 +75,24 @@ Instructions are variable width with their total length being determined by the
\def\none{F}
\begin{figure}
\begin{tabularx}{\textwidth}{ | X | X | X | }
\begin{tabularx}{\textwidth}{ | c | c | X | }
\hline
Operand & Immediate Value & Value As Address \\
Type & Pattern & Description \\
\hline
Register & \xintCHexToBin{\registerBit} & \xintCHexToBin{\registerBitA} \\
8-Bit & \xintCHexToBin{\eightBit} & \xintCHexToBin{\eightBitA} \\
16-Bit & \xintCHexToBin{\sixteenBit} & \xintCHexToBin{\sixteenBitA} \\
32-Bit & \xintCHexToBin{\thirtyBit} & \xintCHexToBin{\thirtyBitA} \\
None & \xintCHexToBin{\none} & \xintCHexToBin{\none} \\
Register & \registerType & Operand is a register \\
\&Register & \registerValueType & Operand is a 32-bit address stored in a register \\
Immediate & \immediateType & Operand is an 8-, 16- or 32-bit value \\
Address & \addressType & Operand is a 32-bit address \\
\hline
\multicolumn{3}{ | X | }{Source Operand Width Patterns} \\
\hline
Invalid & \noWidth & Source must have a width \\
8-bit & \eightBitWidth & 8-bit wide source \\
16-bit & \sixteenBitWidth & 16-bit wide source \\
32-bit & \thirtyBitWidth & 32-bit wide source \\
\hline
\end{tabularx}
\caption{Operand Modes Bit Pattern}
\caption{Operand Type and Width Bit Patterns}
\label{fig:ModeSettingEncodingFigure} % https://www.overleaf.com/learn/latex/Referencing_Figures
\end{figure}
\clearpage
@@ -134,33 +156,31 @@ The /r represents a byte that specifies a register. /immX is for the immediate d
Opcode & Instruction & Operand One & Operand Two \\
\hline
05 \registerBit\registerBit & mov /r, /r & /r & /r \\
05 \registerBit\eightBitA & mov /r, /addr8 & /r & /addr8 \\
05 \registerBit\sixteenBitA & mov /r, /addr16 & /r & /addr16 \\
05 \registerBit\thirtyBitA & mov /r, /addr32 & /r & /addr32 \\
05 \registerBit\eightBitA & mov byte /r, /addr & /r & /addr \\
05 \registerBit\sixteenBitA & mov short /r, /addr & /r & /addr \\
05 \registerBit\thirtyBitA & mov (int) /r, /addr & /r & /addr \\
05 \registerBitA\registerBit & mov [/r], /r & [/r] & /r \\
05 \registerBitA\eightBitA & mov [/r], /addr8 & [/r] & /addr8 \\
05 \registerBitA\sixteenBitA & mov [/r], /addr16 & [/r] & /addr16 \\
05 \registerBitA\thirtyBitA & mov [/r], /addr32 & [/r] & /addr32 \\
05 \registerBitA\registerBitA & mov (int) [/r], [/r] & [/r] & [/r] \\
05 \registerBitA\eightBitA & mov byte [/r], /addr & [/r] & /addr \\
05 \registerBitA\sixteenBitA & mov short [/r], /addr & [/r] & /addr \\
05 \registerBitA\thirtyBitA & mov (int) [/r], /addr & [/r] & /addr \\
05 \eightBitA\registerBit & mov /addr8, /r & /addr8 & /r \\
05 \sixteenBitA\registerBit & mov /addr16, /r & /addr16 & /r \\
05 \thirtyBitA\registerBit & mov /addr32, /r & /addr32 & /r \\
05 \eightBitA\registerBit & mov byte /addr, /r & /addr & /r \\
05 \sixteenBitA\registerBit & mov short /addr, /r & /addr & /r \\
05 \thirtyBitA\registerBit & mov (int) /addr, /r & /addr & /r \\
05 \eightBit\registerBit & mov /imm8, /r & /imm8 & /r \\
05 \eightBit\registerBitA & mov /imm8, [/r] & /imm8 & [/r] \\
05 \eightBit\eightBitA & mov /imm8, /addr8 & /imm8 & /addr8 \\
05 \eightBit\sixteenBitA & mov /imm8, /addr16 & /imm8 & /addr16 \\
05 \eightBit\thirtyBitA & mov /imm8, /addr32 & /imm8 & /addr32 \\
05 \eightBit\registerBit & mov byte /imm8, /r & /imm8 & /r \\
05 \eightBit\registerBitA & mov byte /imm8, [/r] & /imm8 & [/r] \\
05 \eightBit\eightBitA & mov byte /imm8, /addr & /imm8 & /addr \\
05 \sixteenBit\registerBit & mov /imm16, /r & /imm16 & /r \\
05 \sixteenBit\registerBitA & mov /imm16, [/r] & /imm16 & [/r] \\
05 \sixteenBit\sixteenBitA & mov /imm16, /addr16 & /imm16 & /addr16 \\
05 \sixteenBit\thirtyBitA & mov /imm16, /addr32 & /imm16 & /addr32 \\
05 \sixteenBit\registerBit & mov short /imm16, /r & /imm16 & /r \\
05 \sixteenBit\registerBitA & mov short /imm16, [/r] & /imm16 & [/r] \\
05 \sixteenBit\sixteenBitA & mov short /imm16, /addr & /imm16 & /addr \\
05 \thirtyBit\registerBit & mov /imm32, /r & /imm32 & /r \\
05 \thirtyBit\registerBitA & mov /imm32, [/r] & /imm32 & [/r] \\
05 \thirtyBit\thirtyBitA & mov /imm32, /addr32 & /imm32 & /addr32 \\
05 \thirtyBit\registerBit & mov (int) /imm32, /r & /imm32 & /r \\
05 \thirtyBit\registerBitA & mov (int) /imm32, [/r] & /imm32 & [/r] \\
05 \thirtyBit\thirtyBitA & mov (int) /imm32, /addr & /imm32 & /addr \\
\hline
\end{tabularx}
\paragraph{Description} Copies the source (operand one) value to the destination (operand two).