| 1 |
\begin{savequote} |
| 2 |
\sffamily |
| 3 |
%I'm completely operational and all my circuits are functioning normally-- |
| 4 |
%\qauthor{Hal (2001, A Space Odyssey)} |
| 5 |
%\index{AUV} |
| 6 |
%\index{AUV!\emph{Starbug}} |
| 7 |
"Do you program in Assembly?" she asked.\newline |
| 8 |
"NOP", he said.\\[0.5cm] |
| 9 |
|
| 10 |
%\qauthor{Sayer} |
| 11 |
|
| 12 |
|
| 13 |
\includegraphics[width=0.75\textwidth]{dasm-logo.png} |
| 14 |
|
| 15 |
|
| 16 |
\end{savequote} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
\chapter{Introduction} |
| 21 |
|
| 22 |
%\begin{epigraphs} |
| 23 |
%\qitem{ |
| 24 |
%\emph{``Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows %where you live.'' |
| 25 |
%\end{epigraphs} |
| 26 |
|
| 27 |
|
| 28 |
\section{About} |
| 29 |
|
| 30 |
This is the Technical Documentation and User Guide for the \dasm macro-assembler. It explains how |
| 31 |
to use \dasm and the supported assembler directives. |
| 32 |
|
| 33 |
\section{Home} |
| 34 |
|
| 35 |
Since release 2.20.12, \dasm has lived at |
| 36 |
|
| 37 |
~~~~\url{https://dasm-assembler.github.io/} |
| 38 |
|
| 39 |
On that page you can download prebuilt binaries for MacOS, Linux, and Windows operating systems. You can also download the full source code and build the program binary yourself. |
| 40 |
|
| 41 |
\label{changelog:20200913bugs} |
| 42 |
\index{Bugs!Reporting} |
| 43 |
For bugs and feature requests, please visit |
| 44 |
|
| 45 |
~~~~\url{https://github.com/dasm-assembler/dasm/issues} |
| 46 |
|
| 47 |
|
| 48 |
\section{Features} |
| 49 |
|
| 50 |
\dasm is packed with features... |
| 51 |
|
| 52 |
\begin{itemize} |
| 53 |
\item fast assembly |
| 54 |
\item supports several common 8 bit processor models |
| 55 |
\item takes as many passes as needed |
| 56 |
\item automatic checksum generation, special symbol '...' |
| 57 |
\item several binary output formats available. |
| 58 |
\item allows reverse indexed origins. |
| 59 |
\item multiple segments, BSS segments (no generation), relocatable origin. |
| 60 |
\item expressions, as in C |
| 61 |
\item expressions are computed using 32 bit integers |
| 62 |
\item no real limitation on label size |
| 63 |
\item complex pseudo-ops, repeat loops, macros |
| 64 |
\end{itemize} |
| 65 |
|
| 66 |
|
| 67 |
\section{Conventions in this Document} |
| 68 |
|
| 69 |
This document uses standardised terminology to describe usage and function. |
| 70 |
|
| 71 |
\textit{Should the name be ``\mono{dasm}'', ``\mono{DASM}'' or ``\mono{Dasm}''?} |
| 72 |
|
| 73 |
Yes. In this document we shall refer to it as \dasm. |
| 74 |
|
| 75 |
Usage of directives and command-line options are shown in a box like this... |
| 76 |
|
| 77 |
\begin{usage} |
| 78 |
dasm source.asm -f3 -v5 -otest.bin |
| 79 |
\end{usage} |
| 80 |
|
| 81 |
Items/examples that appear in source code are shown like this... |
| 82 |
|
| 83 |
\begin{code} |
| 84 |
MAC END_BANK |
| 85 |
IF _CURRENT_BANK_TYPE = _TYPE_RAM |
| 86 |
CHECK_RAM_BANK_SIZE |
| 87 |
ELSE |
| 88 |
CHECK_BANK_SIZE |
| 89 |
ENDIF |
| 90 |
ENDM |
| 91 |
\end{code} |
| 92 |
|
| 93 |
\label{change:lsbmsb} |
| 94 |
In 8-bit microprocessors, 16-bit values are represented by pairs of bytes, either in low/high or high/low ordering. The ordering, called the ``endianness'', differs between processors. In this document, \mono{LSB} refers to the least-significant byte, and \mono{MSB} refers to the most-significant byte, independent of the endianness of the processor. See the unary operators \mono{<} and \mono{>} which are used to retrieve the \mono{LSB} or \mono{MSB} from a symbol/value. |
| 95 |
|
| 96 |
See \nameref{operators:unary}. |
| 97 |
|
| 98 |
\subsection{SI Units} |
| 99 |
\label{changelog:20200909SI} |
| 100 |
Computer memory sizes are referred to in this document using SI units. |
| 101 |
|
| 102 |
In particular, \mono{kilo} (\mono{K}) is \mono{1000}, and \mono{kibi} (\mono{Ki}) is \mono{1024}. A \mono{bit} is \mono{b}, a \mono{byte} is \mono{B}. Thus, \mono{4096 bytes} is \mono{4 kibibytes}, or \mono{4 KiB}. |
| 103 |
|
| 104 |
Historically, disk drive manufacturers were responsible for this change in meaning of the "kilobyte", as they divided capacity by 1000 instead of 1024 when listing drive size. This not only made their drives seem bigger, it created an ambiguity when discussing computer and disk memory size. The adoption of the new SI units for computer memory size removed the ambiguity. |
| 105 |
|
| 106 |
\subsection{Format Description} |
| 107 |
\label{changelog:20200829formatdescription} |
| 108 |
|
| 109 |
The following format templates are used to describe items on the command line. |
| 110 |
|
| 111 |
\begin{table}[H] |
| 112 |
\begin{tabularx}{\linewidth}{lll} |
| 113 |
\toprule |
| 114 |
\textbf{Format}&\textbf{Result}\\ |
| 115 |
\hline |
| 116 |
\\ |
| 117 |
\mono{item}& one item\\ |
| 118 |
\mono{item ...}& one or more items, space-separated\\ |
| 119 |
\mono{item,...}& one or more items, comma-separated\\ |
| 120 |
\mono{\{item|...\}}& only one of the items, bar-separated\\ |
| 121 |
\mono{[item]} &optional item\\ |
| 122 |
\mono{[ ]...}&optional whitespace(s)\\ |
| 123 |
\\ |
| 124 |
\bottomrule |
| 125 |
\end{tabularx} |
| 126 |
\end{table} |
| 127 |
|
| 128 |
\subsubsection{Examples} |
| 129 |
\begin{code} |
| 130 |
A[ {B|C}] "A" or "A B" or "A C" |
| 131 |
DC[{.B|.W|.L}] "DC" or "DC.B" or "DC.W" or "DC.L" |
| 132 |
DC[.{B|W|L}] the same |
| 133 |
\end{code} |
| 134 |
|
| 135 |
\section{Assembler Passes} |
| 136 |
\index{Assembler Passes} |
| 137 |
|
| 138 |
\dasm is most likely to make multiple passes through the source code to resolve all symbols. It is not necessary for anything to be resolved in the first pass. The maximum number of passes (default 3) is controllable. |
| 139 |
|
| 140 |
\dasm will return an error if it can't resolve all referenced symbols within the maximum number of passes. |
| 141 |
|
| 142 |
See \nameref{flag:passes} and \nameref{flag:passes2}. |
| 143 |
|
| 144 |
\subsubsection{Example} |
| 145 |
|
| 146 |
The the following contrived example will resolve in 12 passes: |
| 147 |
|
| 148 |
\begin{code} |
| 149 |
ORG 1 |
| 150 |
REPEAT [[addr < 11] ? [addr-11]] + 11 |
| 151 |
DC.b addr |
| 152 |
REPEND |
| 153 |
addr: |
| 154 |
\end{code} |
| 155 |
|
| 156 |
\begin{outputx} |
| 157 |
> dasm test.asm -P11 |
| 158 |
test.asm (8): error: Label mismatch... |
| 159 |
--> addr 000b |
| 160 |
test.asm (8): error: Too many passes (12). |
| 161 |
\end{outputx} |
| 162 |
|
| 163 |
In the above example, the example does not assemble because the number of passes (set to 11) is insufficient to resolve the value of \mono{addr}. |
| 164 |
|
| 165 |
\begin{outputx} |
| 166 |
> dasm test.asm -P12 |
| 167 |
Complete. (0) |
| 168 |
\end{outputx} |
| 169 |
|
| 170 |
In the above example, 12 passes is sufficient to assemble the code. |
| 171 |
|
| 172 |
There is generally no harm in setting the number of passes to a sufficiently high value. |
| 173 |
|
| 174 |
|
| 175 |
Most everything is recursive. You cannot have a macro definition |
| 176 |
within a macro definition, but you can nest macro calls, repeat loops, |
| 177 |
and include files. |
| 178 |
|
| 179 |
The other major feature in this assembler is the \nameref{pseudoop:subroutine} directive , which logically separates \nameref{locallabels} (starting with a dot). This |
| 180 |
allows you to reuse label names (for example, \mono{.1, .fail}) rather than |
| 181 |
think up crazy combinations of the current subroutine to keep it all |
| 182 |
unique. |
| 183 |
|
| 184 |
See \nameref{flag:passes}, \nameref{flag:passes2}, and \nameref{pseudoop:subroutine}. |
| 185 |
|
| 186 |
|