From 5068c6c293ca37eeb612e5d647409024b80c6a2e Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Thu, 20 Feb 2025 13:50:59 -0600 Subject: [PATCH] Added a new environment for creating the opcode tables. hoping this will simplify the setup and make things easier to maintain. --- chapter 2.tex | 35 +++++++++++++++++++++++++++-------- document.tex | 2 +- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/chapter 2.tex b/chapter 2.tex index f97e9a6..455c24a 100644 --- a/chapter 2.tex +++ b/chapter 2.tex @@ -1,3 +1,22 @@ +% When the argument list ends with "b" that makes the body of the environment an argument. +% To quote section 3.6 Body of an environment: +% The approach taken in xparse is different from the earlier packages environ or newenviron: the body of +% the environment is provided to the code part as a usual argument #1, #2 etc., rather than +% stored in a macro such as \BODY. +% Source: https://mirrors.rit.edu/CTAN/macros/latex/contrib/l3packages/xparse.pdf (Released 2024-08-16) +\NewDocumentEnvironment{opcodetable}{ m m b } { + \begin{tabularx}{\textwidth}{ | c | X | c | c | } + \hline + Opcode & Instruction & Operand One & Operand Two \\ + \hline + #3 + \hline + \end{tabularx} + \paragraph{Description} #1 + \paragraph{Flags Affected} #2 +}{ +} + \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}. @@ -86,20 +105,20 @@ 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} - \begin{tabularx}{\textwidth}{ | c | X | c | c | } - \hline - Opcode & Instruction & Operand One & Operand Two \\ - \hline + \begin{opcodetable} + { + 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. + } + { + OF and ZF. + } 01 \rRArgH\byteWidthH & add byte /r, /r & /r & /r \\ 01 \rRArgH\shortWidthH & add short /r, /r & /r & /r \\ 01 \rRArgH\intWidthH & add (int) /r, /r & /r & /r \\ 01 \immRArgH\byteWidthH & add byte /imm8, /r & /imm8 & /r \\ 01 \immRArgH\shortWidthH & add short /imm16, /r & /imm16 & /r \\ 01 \immRArgH\intWidthH & add (int) /imm32, /r & /imm32 & /r \\ - \hline - \end{tabularx} - \paragraph{Description} 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. - \paragraph{Flags Affected} OF and ZF. + \end{opcodetable} \subsection{Sub} \begin{tabularx}{\textwidth}{ | c | X | c | c | } \hline diff --git a/document.tex b/document.tex index b28012c..5ca8a28 100644 --- a/document.tex +++ b/document.tex @@ -13,7 +13,7 @@ %\usepackage{showframe} % Good for debugging, uncomment to see the bounding boxes for the various sections of a page. -\newcommand{\quotes}[1]{``#1''} +\NewDocumentCommand{\quotes}{m}{``#1''} \begin{document} \title{Unnamed Machine}