Removed invalid Option nibble codes and refactored most of the instructions' section code to use the new command.

This commit is contained in:
2025-02-24 02:01:41 -06:00
parent 02b3c9185d
commit 3680d24d68
+53 -186
View File
@@ -1,16 +1,7 @@
\ExplSyntaxOn
% Opcode, Opcode Name, Description, Flags Affected, Options
% Maybe have an optional argument to relabel the operands Source and Destination
\NewDocumentCommand{\createoptable}{ m m m m m }{
%\newcommand{\row}[3] {#1~#3 & #2 & Temp & \cs_if_eq:NNTF {#3} {E} { Allowed} { None } \\ \hline}
%\clist_new:N \l_options
%\clist_set:Nn \l_options {#3}
%\begin{tabularx}{\textwidth}{ | c | }
% \clist_map_inline:Nn \l_options { ##1 \\ }
%\end{tabularx}
%\seq_set_split:Nnn \l_tmpa_seq {,} {#3}
\clist_clear_new:N \l_options
\clist_set:Nn \l_options {#3}
@@ -23,28 +14,26 @@
\clist_map_inline:Nn \l_options {
%\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2 & Temp & \cs_if_eq:NNTF {##1} {E} { Allowed} { None } \\ \hline }
\str_case:nnF{##1} {
{1} {
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /r1 & r & r1 \\ \hline }
{0}{
\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 }
}{2}{
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /r2 & r & r2 \\ \hline }
}{3}{
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /r3 & r & r2 \\ \hline }
}{4}{
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /r4 & r & r2 \\ \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 & #2 /r, /r5 & r & r2 \\ \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 }
}{9}{
\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 }
}{D}{
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /rD & r & r2 \\ \hline }
}{E}{
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /rE & r & r2 \\ \hline }
}{F}{
\tl_put_right:Nn \l_tmpa_seq { #1 & #2 /r, /rF & r & r2 \\ \hline }
\tl_put_right:Nn \l_tmpa_seq { #1~##1 & #2 ~imm,~[imm] & imm & [imm] \\ \hline }
}
}{ FALSE }
}{ \tl_put_right:Nn \l_tmpa_seq {#1~##1 & INVALID & -- & -- \\ \hline} }
%\tl_put_right:Ne \l_tmpa_seq { \my_parse #1 #2 #3 }
}
\tl_put_right:Nn \l_tmpa_seq { \end{tabularx} }
@@ -52,16 +41,6 @@
\tl_put_right:Nn \l_tmpa_seq { \paragraph{Flags Affected} #4 }
\tl_use:N \l_tmpa_seq
%\begin{tabularx}{\textwidth}{ | c | X | c | c | } \hline
%Opcode & Instruction & Operand One & Operand Two \\ \hline
%\clist_map_inline:Nn \l_options { #1~##1 \parseoption{#2}{##1} \\ \hline } %{ \row{#1}{##1}{#2} }
%\l_parse_row:nn{#1}{#2}
%\end{tabularx}
%\paragraph{Description} #5
%\paragraph{Flags Affected} #4
}
\ExplSyntaxOff
@@ -154,138 +133,45 @@ In general instructions are variable length depending on the number of arguments
\section{Instructions}
The /r represents a byte that specifies a register. /immX is for the immediate data type, where \textit{X} defines the width, which are 8, 16, or 32 bits. An address is defined as /addrX with the \textit{X} denoting the size of the data that will be written which can be 8, 16 or 32 bits, with the address itself always being 32-bits wide.
\subsection{Add}
\createoptable{01}{add}{1, 2, 3}{ OF and ZF. }
\createoptable{01}{add}{0, 8}{ OF and ZF. }
{
Adds two unsigned values together, the source (operand one) and the destination (operand two), storing the result in destination. The overflow flag (OF) is set if the result is less than the source and the zero flag (ZF) is set when the result of addition is zero.
}
\subsection{Sub}
\createoptable{02}{sub}{F, E, D}{ UF and ZF. }
\createoptable{02}{sub}{0, 8}{ UF and ZF. }
{
Subtracts 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.
}
\subsection{Mul}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
03 \rRArgH\byteWidthH & mul byte /r, /r & /r & /r \\
03 \rRArgH\shortWidthH & mul short /r, /r & /r & /r \\
03 \rRArgH\intWidthH & mul (int) /r, /r & /r & /r \\
03 \immRArgH\byteWidthH & mul byte /imm8, /r & /imm8 & /r \\
03 \immRArgH\shortWidthH & mul short /imm16, /r & /imm16 & /r \\
03 \immRArgH\intWidthH & mul (int) /imm32, /r & /imm32 & /r \\
\hline
\end{tabularx}
\paragraph{Description} Multiplies two unsigned values together, the source (operand one) and the destination (operand two), storing the result in destination. The overflow flag (OF) is set if the result is less than the source and the zero flag (ZF) is set when the result of addition is zero.
\paragraph{Flags Affected} OF and ZF.
\createoptable{03}{mul}{0, 8}{ OF and ZF. }
{
Multiplies two unsigned values together, the source (operand one) and the destination (operand two), storing the result in destination. The overflow flag (OF) is set if the result is less than the source and the zero flag (ZF) is set when the result of addition is zero.
}
\subsection{Div}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
04 \rRArgH\byteWidthH & div byte /r, /r & /r & /r \\
04 \rRArgH\shortWidthH & div short /r, /r & /r & /r \\
04 \rRArgH\intWidthH & div (int) /r, /r & /r & /r \\
04 \immRArgH\byteWidthH & div byte /imm8, /r & /imm8 & /r \\
04 \immRArgH\shortWidthH & div short /imm16, /r & /imm16 & /r \\
04 \immRArgH\intWidthH & div (int) /imm32, /r & /imm32 & /r \\
\hline
\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.
\createoptable{04}{div}{0, 8}{ UF and ZF. }
{
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.
}
\subsection{Mov}\label{sec:mov}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
05 \rRArgH\byteWidthH & mov byte /r, /r & /r & /r \\
05 \rRArgH\shortWidthH & mov short /r, /r & /r & /r \\
05 \rRArgH\intWidthH & mov (int) /r, /r & /r & /r \\
05 \rRaArgH\byteWidthH & mov byte /r, [/r] & /r & [/r] \\
05 \rRaArgH\shortWidthH & mov short /r, [/r] & /r & [/r] \\
05 \rRaArgH\intWidthH & mov (int) /r, [/r] & /r & [/r] \\
05 \rAArgH\byteWidthH & mov byte /r, [imm32] & /r & [imm32] \\
05 \rAArgH\shortWidthH & mov short /r, [imm32] & /r & [imm32] \\
05 \rAArgH\intWidthH & mov (int) /r, [imm32] & /r & [imm32] \\
05 \raRArgH\byteWidthH & mov byte [/r], /r & [/r] & /r \\
05 \raRArgH\shortWidthH & mov short [/r], /r & [/r] & /r \\
05 \raRArgH\intWidthH & mov (int) [/r], /r & [/r] & /r \\
05 \raRaArgH\byteWidthH & mov byte [/r], [/r] & [/r] & [/r] \\
05 \raRaArgH\shortWidthH & mov short [/r], [/r] & [/r] & [/r] \\
05 \raRaArgH\intWidthH & mov (int) [/r], [/r] & [/r] & [/r] \\
05 \raAArgH\byteWidthH & mov byte [/r], [imm32] & [/r] & [imm32] \\
05 \raAArgH\shortWidthH & mov short [/r], [imm32] & [/r] & [imm32] \\
05 \raAArgH\intWidthH & mov (int) [/r], [imm32] & [/r] & [imm32] \\
05 \immRArgH\byteWidthH & mov byte imm8, /r & imm8 & /r \\
05 \immRArgH\shortWidthH & mov short imm16, /r & imm16 & /r \\
05 \immRArgH\intWidthH & mov (int) imm32, /r & imm32 & /r \\
05 \immRaArgH\byteWidthH & mov byte imm8, [/r] & imm8 & [/r] \\
05 \immRaArgH\shortWidthH & mov short imm16, [/r] & imm16 & [/r] \\
05 \immRaArgH\intWidthH & mov (int) imm32, [/r] & imm32 & [/r] \\
05 \immAArgH\byteWidthH & mov byte imm8, [imm32] & imm8 & [imm32] \\
05 \immAArgH\shortWidthH & mov short imm16, [imm32] & imm16 & [imm32] \\
05 \immAArgH\intWidthH & mov (int) imm32, [imm32] & imm32 & [imm32] \\
05 \aRArgH\byteWidthH & mov byte [imm32], /r & [imm32] & /r \\
05 \aRArgH\shortWidthH & mov short [imm32], /r & [imm32] & /r \\
05 \aRArgH\intWidthH & mov (int) [imm32], /r & [imm32] & /r \\
05 \aRaArgH\byteWidthH & mov byte [imm32], [/r] & [imm32] & [/r] \\
05 \aRaArgH\shortWidthH & mov short [imm32], [/r] & [imm32] & [/r] \\
05 \aRaArgH\intWidthH & mov (int) [imm32], [/r] & [imm32] & [/r] \\
05 \aAArgH\byteWidthH & mov byte [imm32], [imm32] & [imm32] & [imm32] \\
05 \aAArgH\shortWidthH & mov short [imm32], [imm32] & [imm32] & [imm32] \\
05 \aAArgH\intWidthH & mov (int) [imm32], [imm32] & [imm32] & [imm32] \\
\hline
\end{tabularx}
\paragraph{Description} Copies the source (operand one) value to the destination (operand two).
\paragraph{Flags Affected} None.
\createoptable{05}{mov}{0, 1, 2, 5, 8, 9, A, D}{ None. }
{
Copies the source (operand one) value to the destination (operand two).
}
\subsection{AND}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
06 \rRArgH\byteWidthH & and byte /r, /r & /r & /r \\
06 \rRArgH\shortWidthH & and short /r, /r & /r & /r \\
06 \rRArgH\intWidthH & and (int) /r, /r & /r & /r \\
06 \immRArgH\byteWidthH & and byte /imm8, /r & /imm8 & /r \\
06 \immRArgH\shortWidthH & and short /imm16, /r & /imm16 & /r \\
06 \immRArgH\intWidthH & and (int) /imm32, /r & /imm32 & /r \\
\hline
\end{tabularx}
\paragraph{Description} Bitwise AND's the source (operand one) with the destination (operand two) storing the result in the destination. If the result of the operation is zero then the Zero Flag (ZF) is set.
\paragraph{Flags Affected} ZF.
\createoptable{06}{and}{0, 8}{ ZF. }
{
Bitwise AND's the source (operand one) with the destination (operand two) storing the result in the destination. If the result of the operation is zero then the Zero Flag (ZF) is set.
}
\subsection{OR}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
07 \rRArgH\byteWidthH & or byte /r, /r & /r & /r \\
07 \rRArgH\shortWidthH & or short /r, /r & /r & /r \\
07 \rRArgH\intWidthH & or (int) /r, /r & /r & /r \\
07 \immRArgH\byteWidthH & or byte /imm8, /r & /imm8 & /r \\
07 \immRArgH\shortWidthH & or short /imm16, /r & /imm16 & /r \\
07 \immRArgH\intWidthH & or (int) /imm32, /r & /imm32 & /r \\
\hline
\end{tabularx}
\paragraph{Description} Bitwise OR's the source (operand one) with the destination (operand two) storing the result in the destination. If the result of the operation is zero then the Zero Flag (ZF) is set.
\paragraph{Flags Affected} ZF.
\createoptable{07}{or}{0, 8}{ ZF. }
{
Bitwise OR's the source (operand one) with the destination (operand two) storing the result in the destination. If the result of the operation is zero then the Zero Flag (ZF) is set.
}
\subsection{XOR}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
08 \rRArgH\byteWidthH & xor byte /r, /r & /r & /r \\
08 \rRArgH\shortWidthH & xor short /r, /r & /r & /r \\
08 \rRArgH\intWidthH & xor (int) /r, /r & /r & /r \\
08 \immRArgH\byteWidthH & xor byte /imm8, /r & /imm8 & /r \\
08 \immRArgH\shortWidthH & xor short /imm16, /r & /imm16 & /r \\
08 \immRArgH\intWidthH & xor (int) /imm32, /r & /imm32 & /r \\
\hline
\end{tabularx}
\paragraph{Description} Bitwise exclusive OR's (XOR) the source (operand one) with the destination (operand two) storing the result in the destination. If the result of the operation is zero then the Zero Flag (ZF) is set.
\paragraph{Flags Affected} ZF.
\createoptable{08}{xor}{0, 8}{ ZF. }
{
Bitwise exclusive OR's (XOR) the source (operand one) with the destination (operand two) storing the result in the destination. If the result of the operation is zero then the Zero Flag (ZF) is set.
}
\subsection{NOT}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
@@ -297,29 +183,15 @@ The /r represents a byte that specifies a register. /immX is for the immediate d
\paragraph{Description} Bit-wise NOT's the source (operand one) in place.
\paragraph{Flags Affected} None.
\subsection{SHL}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
0A \immRArgH\byteWidthH & shl byte imm8, /r & imm8 & /r \\
0A \immRArgH\shortWidthH & shl short imm16, /r & imm16 & /r \\
0A \immRArgH\intWidthH & shl (int) imm32, /r & imm32 & /r \\
\hline
\end{tabularx}
\paragraph{Description} Shifts the destination (operand two) left \textit{operand one} times in place. If the source is smaller than before the operation the overflow flag (OF) is set. If the result of the operation is zero than the zero flag (ZF) is set.
\paragraph{Flags Affected} OF and ZF.
\createoptable{0A}{shl}{8}{ OF and ZF. }
{
Shifts the destination (operand two) left \textit{operand one} times in place. If the source is smaller than before the operation the overflow flag (OF) is set. If the result of the operation is zero than the zero flag (ZF) is set.
}
\subsection{SHR}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
0B \immRArgH\byteWidthH & shr byte imm8, /r & imm8 & /r \\
0B \immRArgH\shortWidthH & shr short imm16, /r & imm16 & /r \\
0B \immRArgH\intWidthH & shr (int) imm32, /r & imm32 & /r \\
\hline
\end{tabularx}
\paragraph{Description} Shifts the destination (operand two) right \textit{operand one} times in place. If the source is larger than before the operation the underflow flag (UF) is set. If the result of the operation is zero than the zero flag (ZF) is set.
\paragraph{Flags Affected} UF and ZF.
\createoptable{0B}{shr}{8}{ UF and ZF. }
{
Shifts the destination (operand two) right \textit{operand one} times in place. If the source is larger than before the operation the underflow flag (UF) is set. If the result of the operation is zero than the zero flag (ZF) is set.
}
\subsection{NOP}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
@@ -331,15 +203,10 @@ The /r represents a byte that specifies a register. /immX is for the immediate d
\paragraph{Description} Performs no operation except for incrementing the program counter by one.
\paragraph{Flags Affected} None.
\subsection{CMP}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline
Opcode & Instruction & Operand One & Operand Two \\
\hline
0D \rRArgH\intWidthH & cmp /r, /r & /r & /r \\
\hline
\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.
\createoptable{0D}{cmp}{0, 8}{ OF, UF and ZF. }
{
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.
}
\subsection{JMP}\label{sec:jmp}
\begin{tabularx}{\textwidth}{ | c | X | c | c | }
\hline