Finished initial cheatsheet

This commit is contained in:
Louis Burke 2025-02-17 02:00:37 -05:00
parent 9ebaa2982c
commit 1c69cbf70e

View file

@ -6,8 +6,12 @@
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{setspace}
\usepackage{listofitems}
\usetikzlibrary{shapes.multipart,positioning}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usetikzlibrary{shapes.multipart,positioning,arrows.meta}
\tikzstyle{stack}=[rectangle split, rectangle split parts=#1,draw,anchor=center]
@ -16,101 +20,482 @@
\newcommand{\opsummaryshort}{#1}
\newcommand{\opsummarylong}{#2}
}{%
\draw[->, double distance=1pt] (before) -- node[above] {\texttt{\opsummaryshort}} node[below] {\texttt{\opsummarylong}} (after);
\draw[->] (before) -- node[above] {\texttt{\opsummaryshort}} node[text width=1cm,align=center,below] {\texttt{\tiny\begin{spacing}{0.6}\opsummarylong\end{spacing}}} (after);
\end{tikzpicture}
}
\newcommand{\stackdiagram}[2]{%
\readlist\leftelems{#1}
\readlist\rightelems{#2}
\node[stack=\leftelemslen] (before) {%
\ifnum\leftelemslen>0\nodepart{one}$\leftelems[1]$\fi
\ifnum\leftelemslen>1\nodepart{two}$\leftelems[2]$\fi
\ifnum\leftelemslen>2\nodepart{three}$\leftelems[3]$\fi
\ifnum\leftelemslen>3\nodepart{four}$\leftelems[4]$\fi
\ifnum\leftelemslen>4\nodepart{five}$\leftelems[5]$\fi
\ifnum\leftelemslen>5\nodepart{six}$\leftelems[6]$\fi
};
\node[stack=\rightelemslen,right=of before] (after) {%
\ifnum\rightelemslen>0\nodepart{one}$\rightelems[1]$\fi
\ifnum\rightelemslen>1\nodepart{two}$\rightelems[2]$\fi
\ifnum\rightelemslen>2\nodepart{three}$\rightelems[3]$\fi
\ifnum\rightelemslen>3\nodepart{four}$\rightelems[4]$\fi
\ifnum\rightelemslen>4\nodepart{five}$\rightelems[5]$\fi
\ifnum\rightelemslen>5\nodepart{six}$\rightelems[6]$\fi
};
}
\newif\ifnoopdef
\newif\ifopisfun
\newif\ifopisimm
\newcommand{\optextdescr}{}
\newcommand{\optext}[1]{\renewcommand{\optextdescr}{#1}\noopdeffalse}
\newcommand{\opsumof}[1]{%
\begin{tikzpicture}
\noopdeftrue
\opisfunfalse
\opisimmfalse
% TODO: document and add more metasyntactic variables/functions
% So far uncategorized instructions
\if0#1
\optext{branch to immediate if x is not zero}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if9#1
\optext{compare and swap x and y at p, push success}
\stackdiagram{y,x,p,\ldots}{z,\ldots}
\fi
\if E#1
\optext{round a to integer and store in x}
\stackdiagram{a,\ldots}{x,\ldots}
\fi
\if L#1
\optext{roll stack by immediate places}
\stackdiagram{z,\cdots,y,x,\ldots}{x,z,\cdots,y,\ldots}
\opisimmtrue
\fi
\if U#1
\optext{compare x to y unsigned and set z such that x o y is z o 0}
\stackdiagram{y,x,\ldots}{z,\ldots}
\fi
\if V#1
\optext{bitwise OR x and y}
\stackdiagram{y,x,\ldots}{x\vee{}y,\ldots}
\fi
\if W#1
\optext{truncate x to 32 bits, then sign extend}
\stackdiagram{x,\ldots}{x,\ldots}
\fi
\if d#1
\optext{set x bytes of memory to immediate value at p}
\stackdiagram{x,p,\ldots}{\ldots}
\fi
\if e#1
\optext{rotate stack}
\stackdiagram{z,y,x,\ldots}{x,z,y,\ldots}
\fi
\if f#1
\optext{invoke f, saving return address on stack}
\opisfuntrue
\stackdiagram{f,\ldots}{g,\ldots}
\fi
\if h#1
\optext{stack over}
\stackdiagram{y,x,\ldots}{x,y,x,\ldots}
\fi
\if j#1
\optext{negate a}
\stackdiagram{a,\ldots}{-a,\ldots}
\fi
\if k#1
\optext{stack pop}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if l#1
\optext{bit clear y from x to z}
\stackdiagram{y,x,\ldots}{(x\wedge\neg{}y}
\fi
\if m#1
\optext{floating point difference}
\stackdiagram{b,a,\ldots}{a-b}
\fi
\if p#1
\optext{floating point multiply}
\stackdiagram{b,a,\ldots}{a\times{}b,\ldots}
\fi
\if q#1
\optext{floating point divide}
\stackdiagram{b,a,\ldots}{b\over{}a,\ldots}
\fi
\if s#1
\optext{floating point add}
\stackdiagram{b,a,\ldots}{b+a,\ldots}
\fi
\if t#1
\optext{stack swap}
\stackdiagram{y,x,\ldots}{x,y,\ldots}
\fi
\if u#1
\optext{logical shift x by immediate bits right}
\opisimmtrue
\stackdiagram{x,\ldots}{x,\ldots}
\fi
\if v#1
\optext{floating point absolute value}
\stackdiagram{a,\ldots}{|a|,\ldots}
\fi
\if w#1
\optext{stack duplicate}
\stackdiagram{x,\ldots}{x,x,\ldots}
\fi
\ifx#1\_
\optext{negate x}
\stackdiagram{x,\ldots}{-x,\ldots}
\fi
\if .#1
\optext{convert x to a float}
\stackdiagram{x,\ldots}{a,\ldots}
\fi
\if +#1
\optext{integer add}
\stackdiagram{y,x,\ldots}{x+y,\ldots}
\fi
\if -#1
\optext{integer subtract}
\stackdiagram{y,x,\ldots}{x-y,\ldots}
\fi
\if *#1
\optext{integer multiply}
\stackdiagram{y,x,\ldots}{x\times{}y,\ldots}
\fi
\if /#1
\optext{integer divide}
\stackdiagram{y,x,\ldots}{x\div{}y,\ldots}
\fi
\ifx#1\%
\optext{integer modulo}
\stackdiagram{y,x,\ldots}{x\ \textrm{mod}\ y,\ldots}
\fi
\ifx#1\textbackslash
\optext{integer remainder}
\stackdiagram{y,x,\ldots}{x\%y,\ldots}
\fi
\if |#1
\optext{integer absolute value}
\stackdiagram{x,\ldots}{|x|,\ldots}
\fi
\ifx#1\$
\optext{load constant value}
\opisimmtrue
\stackdiagram{\ldots}{\star{},\ldots}
\fi
\if @#1
\optext{call immediate name}
\opisimmtrue
\opisfuntrue
\stackdiagram{\ldots}{f,\ldots}
\fi
\ifx#1\&
\optext{set z to the bitwise and of x and y}
\stackdiagram{x,y,\ldots}{x\wedge{}y}
\fi
\ifx#1\textasciicircum
\optext{set z to the bitwise xor of x and y}
\stackdiagram{x,y,\ldots}{x\oplus{}y}
\fi
\if !#1
\optext{set y to the bitwise not of x}
\stackdiagram{x,\ldots}{y,\ldots}
\fi
\if [#1
\optext{rotate x right by immediate bits}
\opisimmtrue
\stackdiagram{x,\ldots}{x,\ldots}
\fi
\if ]#1
\optext{arithmetic right shift x by immediate bits}
\opisimmtrue
\stackdiagram{x,\ldots}{x,\ldots}
\fi
\if ?#1
\optext{compare x to y and set z such that x o y is z o 0}
\stackdiagram{x,y,\ldots}{z,\ldots}
\fi
\ifx#1\textasciitilde
\optext{compare a to b within an immediate error}
\opisimmtrue
\stackdiagram{a,b,\ldots}{c,\ldots}
\fi
\if :#1
\optext{label code location}
\stackdiagram{\ldots}{\ldots}
\fi
\if (#1
\optext{set x to depth of stack}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if )#1
\optext{pack x elements of stack into array p}
\stackdiagram{x,p,\ldots}{p,\ldots}
\fi
\if '#1
\optext{embed data}
\stackdiagram{ }{ }
\fi
\if "#1
\optext{change section}
\stackdiagram{ }{ }
\fi
\if `#1
\optext{call builtin with given name/value}
\opisimmtrue
\stackdiagram{?,\ldots}{?,\ldots}
\fi
\ifx#1\textvisiblespace
\optext{do nothing}
\stackdiagram{\ldots}{\ldots}
\fi
\ifx#1\#
\optext{comment}
\stackdiagram{ }{ }
\fi
\ifx#1\P
\optext{mark a beat for relative branching}
\stackdiagram{\ldots}{\ldots}
\fi
% Load instructions
\if1#1
\optext{load byte x from p}
\stackdiagram{p,\ldots}{x,\ldots}
\fi
\if2#1
\optext{load short x from p}
\stackdiagram{p,\ldots}{x,\ldots}
\fi
\if3#1
\optext{load int x from p}
\stackdiagram{p,\ldots}{x,\ldots}
\fi
\if4#1
\optext{load word x from p}
\stackdiagram{p,\ldots}{x,\ldots}
\fi
\if G#1
\optext{load int at p plus immediate offset in x}
\stackdiagram{p,\ldots}{x,\ldots}
\opisimmtrue
\fi
\if H#1
\optext{load short at p plus immediate offset in x}
\stackdiagram{p,\ldots}{x,\ldots}
\opisimmtrue
\fi
\if o#1
\optext{load byte at p plus immediate offset in x}
\stackdiagram{p,\ldots}{x,\ldots}
\opisimmtrue
\fi
% Store instructions
\if5#1
\optext{store byte x to p}
\stackdiagram{x,p,\ldots}{\ldots}
\fi
\if6#1
\optext{store short x to p}
\stackdiagram{x,p,\ldots}{\ldots}
\fi
\if7#1
\optext{store int x to p}
\stackdiagram{x,p,\ldots}{\ldots}
\fi
\if8#1
\optext{store word x to p}
\stackdiagram{x,p,\ldots}{\ldots}
\fi
% Register instructions
\if A#1
\optext{store x in rA}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if B#1
\optext{store x in rB}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if C#1
\optext{store x in rC}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if I#1
\optext{store x in rI}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if X#1
\optext{store x in rX}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if Y#1
\optext{store x in rY}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if Z#1
\optext{store x in rZ}
\stackdiagram{x,\ldots}{\ldots}
\fi
\if a#1
\optext{load x from rA}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if b#1
\optext{load x from rB}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if c#1
\optext{load x from rC}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if i#1
\optext{load x from rI}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if n#1
\optext{load x from rN}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if x#1
\optext{load x from rX}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if y#1
\optext{load x from rY}
\stackdiagram{\ldots}{x,\ldots}
\fi
\if z#1
\optext{load x from rZ}
\stackdiagram{\ldots}{x,\ldots}
\fi
% Branch instructions
\if <#1
\optext{branch to immediate if x is less than zero}
\opisimmtrue
\opisfuntrue
\stackdiagram{x,\ldots}{\ldots}
\fi
\ifx#1\{
\optext{branch to immediate if x is less than or equal to zero}
\opisimmtrue
\opisfuntrue
\stackdiagram{x,\ldots}{\ldots}
\fi
\if =#1
\optext{branch to immediate if x is zero}
\opisimmtrue
\opisfuntrue
\stackdiagram{x,\ldots}{\ldots}
\fi
\ifx#1\}
\optext{branch to immediate if x is greater or equal to zero}
\opisimmtrue
\opisfuntrue
\stackdiagram{x,\ldots}{\ldots}
\fi
\if >#1
\optext{branch to immediate if x is greater than zero}
\opisimmtrue
\opisfuntrue
\stackdiagram{x,\ldots}{\ldots}
\fi
\if ,#1
\optext{jump to immediate without pushing return address}
\opisimmtrue
\opisfuntrue
\stackdiagram{\ldots}{\ldots}
\fi
\if ;#1
\optext{return from subroutine}
\opisfuntrue
\stackdiagram{f,\ldots}{\ldots}
\fi
\ifnoopdef
\tikzset{every node/.style={fill=gray}}
\renewcommand{\optextdescr}{?}
\stackdiagram{?}{?}
\fi
\ifopisfun
\ifopisimm
\tikzset{->/.style={arrows={Arc Barb[reversed,length=3pt]-Latex[length=5pt]}, double distance=1pt}}
\else
\tikzset{->/.style={arrows={-Latex[length=5pt]}, double distance=1pt}}
\fi
\else
\ifopisimm
\tikzset{->/.style={arrows={Arc Barb[reversed,length=3pt]-Latex[length=5pt]}}}
\else
\tikzset{->/.style={arrows={-Latex[length=5pt]}}}
\fi
\fi
\draw[->]
(before) --
node[above] {\texttt{#1}}
node[text width=1cm,align=center,below]
{\texttt{\tiny\begin{spacing}{0.6}\optextdescr\end{spacing}}}
(after);
\end{tikzpicture}
}
\begin{document}
\begin{tabulary}{\textwidth}{@{}cccccccccccccccc@{}} \toprule
\begin{opsummary}{0}{BNEZ}
\node[stack=2] (before) {%
\nodepart{one}$x$
\nodepart{two}\ldots
};
\node[stack=1,right=of before] (after) {%
\nodepart{one}\ldots
};
\end{opsummary}
&
\begin{table}[h]
\renewcommand{\arraystretch}{0}
\centering
%\caption{All Code Section Instructions In ASCII Order}
\begin{tabularx}{\textwidth}{@{}XXXXXXXXXXXXXXXX@{}} %\toprule
\opsumof{0} & \opsumof{1} & \opsumof{2} & \opsumof{3} &
\opsumof{4} & \opsumof{5} & \opsumof{6} & \opsumof{7} \\
\begin{opsummary}{1}{LDAB}
\node[stack=2] (before) {%
\nodepart{one}$p$
\nodepart{two}
};
\node[stack=2,right=of before] (after) {%
\nodepart{one}$x$
\nodepart{two}
};
\end{opsummary}
&
\opsumof{8} & \opsumof{9} & \opsumof{A} & \opsumof{B} &
\opsumof{C} & \opsumof{D} & \opsumof{E} & \opsumof{F} \\
\begin{opsummary}{2}{LDAS}
\node[stack=2] (before) {%
\nodepart{one}$p$
\nodepart{two}
};
\node[stack=2,right=of before] (after) {%
\nodepart{one}$x$
\nodepart{two}
};
\end{opsummary}
&
\opsumof{G} & \opsumof{H} & \opsumof{I} & \opsumof{J} &
\opsumof{K} & \opsumof{L} & \opsumof{M} & \opsumof{N} \\
\begin{opsummary}{3}{LDAI}
\node[stack=2] (before) {%
\nodepart{one}$p$
\nodepart{two}
};
\node[stack=2,right=of before] (after) {%
\nodepart{one}$x$
\nodepart{two}
};
\end{opsummary}
&
\opsumof{O} & \opsumof{P} & \opsumof{Q} & \opsumof{R} &
\opsumof{S} & \opsumof{T} & \opsumof{U} & \opsumof{V} \\
\begin{opsummary}{4}{LDAW}
\node[stack=2] (before) {%
\nodepart{one}$p$
\nodepart{two}
};
\node[stack=2,right=of before] (after) {%
\nodepart{one}$x$
\nodepart{two}
};
\end{opsummary}
&
\opsumof{W} & \opsumof{X} & \opsumof{Y} & \opsumof{Z} &
\opsumof{a} & \opsumof{b} & \opsumof{c} & \opsumof{d} \\
5 &
6 &
7 &
8 &
9 &
A &
B &
C &
D &
E &
F \\
\opsumof{e} & \opsumof{f} & \opsumof{g} & \opsumof{h} &
\opsumof{i} & \opsumof{j} & \opsumof{k} & \opsumof{l} \\
G &
H &
I &
J &
K &
L &
M &
N &
O &
P &
Q &
R &
S &
T &
U &
V \\
\opsumof{m} & \opsumof{n} & \opsumof{o} & \opsumof{p} &
\opsumof{q} & \opsumof{r} & \opsumof{s} & \opsumof{t} \\
\end{tabulary}
\opsumof{u} & \opsumof{v} & \opsumof{w} & \opsumof{x} &
\opsumof{y} & \opsumof{z} & \opsumof{\_} & \opsumof{.} \\
\opsumof{+} & \opsumof{-} & \opsumof{*} & \opsumof{/} &
\opsumof{\%} & \opsumof{\textbackslash} & \opsumof{|} & \opsumof{\$} \\
\opsumof{@} & \opsumof{<} & \opsumof{\{} & \opsumof{=} &
\opsumof{\}} & \opsumof{>} & \opsumof{,} & \opsumof{;} \\
\opsumof{\&} & \opsumof{\textasciicircum} & \opsumof{!} & \opsumof{[} &
\opsumof{]} & \opsumof{?} & \opsumof{\textasciitilde} & \opsumof{:} \\
\opsumof{(} & \opsumof{)} & \opsumof{'} & \opsumof{"} &
\opsumof{`} & \opsumof{\textvisiblespace} & \opsumof{\#} & \opsumof{\P} \\
\end{tabularx}
\end{table}
\end{document}