| 1 |
|
| 2 |
DOCUMENTATION FOR DASM, a high level macro cross assembler for: |
| 3 |
|
| 4 |
-6502 (and 6507) |
| 5 |
-68705 |
| 6 |
-6803 |
| 7 |
-HD6303 (extension of 6803) |
| 8 |
-68HC11 |
| 9 |
|
| 10 |
|
| 11 |
ABSTRACT |
| 12 |
|
| 13 |
This file contains the main documentation for DASM. It explains how |
| 14 |
to use Dasm and what the supported assembler directives are. |
| 15 |
|
| 16 |
DASM's homepage is https://dasm-assembler.github.io/ since release |
| 17 |
2.20.12. |
| 18 |
|
| 19 |
|
| 20 |
LEGALESE |
| 21 |
|
| 22 |
the DASM macro assembler (aka small systems cross assembler) |
| 23 |
|
| 24 |
Copyright (c) 1988-2002 by Matthew Dillon. |
| 25 |
Copyright (c) 1995 by Olaf "Rhialto" Seibert. |
| 26 |
Copyright (c) 2003-2008 by Andrew Davie. |
| 27 |
Copyright (c) 2008 by Peter H. Froehlich. |
| 28 |
Copyright (c) 2019-2020 by the DASM team. |
| 29 |
|
| 30 |
This program is free software; you can redistribute it and/or modify |
| 31 |
it under the terms of the GNU General Public License as published by |
| 32 |
the Free Software Foundation; either version 2 of the License, or |
| 33 |
(at your option) any later version. |
| 34 |
|
| 35 |
This program is distributed in the hope that it will be useful, |
| 36 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 38 |
GNU General Public License for more details. |
| 39 |
|
| 40 |
You should have received a copy of the GNU General Public License along |
| 41 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 42 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 43 |
|
| 44 |
|
| 45 |
PREFACE FROM MATT: |
| 46 |
|
| 47 |
Over the last year my work has included writing software to drive small |
| 48 |
single-chip microcomputers for various things (remote telemetry units, |
| 49 |
for instance). I have had need to program quite a few different |
| 50 |
processors over that time. |
| 51 |
|
| 52 |
At the beginning, I used an awful macro assembler running on an IBM-PC. |
| 53 |
I *really* wanted to do it on my Amiga. Thus the writing of this |
| 54 |
program. |
| 55 |
|
| 56 |
Feel free to suggest other similar processors for me to add to the list! |
| 57 |
The processor type is specified with a pseudo-op (see below). This |
| 58 |
assembler produces only binary output in one of three formats described |
| 59 |
below. In general, one has a master assembly file which INCLUDEs all |
| 60 |
the modules. |
| 61 |
|
| 62 |
Also provided is FTOHEX which converts an output file in one of the |
| 63 |
three formats to an intel-hex format suitable for many intelligent |
| 64 |
prom programmers (I have a GTEK). |
| 65 |
|
| 66 |
YES it's packed with features! |
| 67 |
|
| 68 |
FEATURES: |
| 69 |
|
| 70 |
-fast assembly |
| 71 |
-supports several common 8 bit processor models (NOT 8086, thank god!) |
| 72 |
-takes as many passes as needed |
| 73 |
-automatic checksum generation, special symbol '...' |
| 74 |
-several binary output formats available. Format 2 allows reverse |
| 75 |
indexed origins. |
| 76 |
-multiple segments, BSS segments (no generation), relocatable origin. |
| 77 |
-expressions, as in C but [] is used instead of () for parenthesis. |
| 78 |
(all expressions are computed with 32 bit integers) |
| 79 |
-no real limitation on label size, label values are 32 bits. |
| 80 |
-complex pseudo ops, repeat loops, macros, etc.... |
| 81 |
|
| 82 |
|
| 83 |
PREFACE FROM ANDREW (APRIL/2003) |
| 84 |
|
| 85 |
The documentation is lagging a bit behind the modifications. |
| 86 |
Essentially the information contained herein is correct, but |
| 87 |
there have been minor changes to the formatting of output data. |
| 88 |
|
| 89 |
Please see the accompanying text files in the distribution's |
| 90 |
root directory for a list of recent changes to DASM. |
| 91 |
|
| 92 |
|
| 93 |
PREFACE FROM PETER (APRIL/2008) |
| 94 |
|
| 95 |
Everything Andrew says above is still true, there have been a |
| 96 |
few sporadic updates to the documentation but no major ones, |
| 97 |
not even Olaf Seibert's changes from 1995 have been integrated, |
| 98 |
to say nothing of Thomas Mathys' F8 backend from 2004. We are |
| 99 |
urgently looking for volunteers to help with the documentation! |
| 100 |
|
| 101 |
|
| 102 |
COMMAND LINE: |
| 103 |
|
| 104 |
dasm sourcefile [options] |
| 105 |
|
| 106 |
options: -f# output format 1-3 (default 1, see below) |
| 107 |
-oname output file name (else a.out) |
| 108 |
-lname list file name (else none generated) |
| 109 |
-Lname list file name, containing all passes |
| 110 |
-sname symbol dump file name (else none generated) |
| 111 |
-v# verboseness 0-4 (default 0, see below) |
| 112 |
-d debug mode (for developers) |
| 113 |
-Dsymbol define symbol, set to 0 |
| 114 |
-Dsymbol=expression define symbol, set to expression |
| 115 |
-Msymbol=expression define symbol using EQM (same as -D) |
| 116 |
-Idir search directory for include and incbin |
| 117 |
-p# maximum number of passes |
| 118 |
-P# maximum number of passes, with fewer checks |
| 119 |
-T# symbol table sorting (default 0 = alphabetical, |
| 120 |
1 = address/value) |
| 121 |
-E# error format (default 0 = MS, 1 = Dillon, 2 = GNU) |
| 122 |
-S strict syntax checking |
| 123 |
|
| 124 |
Example: dasm master.asm -f2 -oout -llist -v3 -DVER=4 |
| 125 |
|
| 126 |
Note: A slash (/) or dash (-) must prefix options. |
| 127 |
|
| 128 |
|
| 129 |
Return Value: |
| 130 |
|
| 131 |
The assembler will return 0 on successful compilation, 1 otherwise. |
| 132 |
|
| 133 |
|
| 134 |
FORMAT OPTIONS: |
| 135 |
|
| 136 |
1 (DEFAULT) |
| 137 |
|
| 138 |
The output file contains a two byte origin in LSB,MSB order, then |
| 139 |
data until the end of the file. |
| 140 |
|
| 141 |
Restrictions: Any instructions which generate output (within an |
| 142 |
initialized segment) must do so with an ascending PC. Initialized |
| 143 |
segments must occur in ascending order. |
| 144 |
|
| 145 |
2 RAS (Random Access Segment) |
| 146 |
|
| 147 |
The output file contains one or more hunks. Each hunk consists |
| 148 |
of a 2 byte origin (LSB,MSB), 2 byte length (LSB,MSB), and that |
| 149 |
number of data bytes. The hunks occur in the same order as |
| 150 |
initialized segments in the assembly. There are no restrictions |
| 151 |
to segment ordering (i.e. reverse indexed ORG statements are |
| 152 |
allowed). The next hunk begins after the previous hunk's data, |
| 153 |
until the end of the file. |
| 154 |
|
| 155 |
3 RAW (Raw) |
| 156 |
|
| 157 |
The output file contains data only (format #1 without the 2 byte |
| 158 |
header). Restrictions are the same as for format #1. |
| 159 |
|
| 160 |
Format 3 RAW (Raw format) |
| 161 |
Same as format 1, but NO header origin is generated. You get |
| 162 |
nothing but data. |
| 163 |
|
| 164 |
VERBOSE OPTIONS: |
| 165 |
|
| 166 |
0 (default) |
| 167 |
|
| 168 |
Only warnings and errors are generated |
| 169 |
|
| 170 |
1 |
| 171 |
-Segment list information generated after each pass |
| 172 |
-Include file names are displayed |
| 173 |
-statistics on why the assembler is going to make another pass |
| 174 |
R1,R2 reason code: R3 |
| 175 |
where R1 is the number of times the assembler encountered |
| 176 |
something requiring another pass to resolve. R2 is the |
| 177 |
number of references to unknown symbols which occured in the |
| 178 |
pass (but only R1 determines the need for another pass). R3 |
| 179 |
is a BITMASK of the reasons why another pass is required. |
| 180 |
See the end of this document for bit designations. |
| 181 |
|
| 182 |
2 |
| 183 |
mismatches between program labels and equates are displayed |
| 184 |
on every pass (usually none occur in the first pass unless you |
| 185 |
have re-declared a symbol name). |
| 186 |
|
| 187 |
displayed information for symbols: |
| 188 |
???? = unknown value |
| 189 |
str = symbol is a string |
| 190 |
eqm = symbol is an eqm macro |
| 191 |
(r) = symbol has been referenced |
| 192 |
(s) = symbol created with SET or EQM pseudo-op |
| 193 |
|
| 194 |
3 |
| 195 |
Unresolved and unreferenced symbols are displayed every pass |
| 196 |
(unsorted, sorry) |
| 197 |
|
| 198 |
4 |
| 199 |
An entire symbol list is displayed every pass to STDOUT. |
| 200 |
(unsorted, sorry) |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
PROCESSOR MODEL: |
| 205 |
|
| 206 |
The processor model is chosen with the PROCESSOR pseudo-op and should |
| 207 |
be the first thing you do in your assembly file. Different processor |
| 208 |
models use different integer formats (see below). The word order does |
| 209 |
not effect the headers in the output files (-f1 and -f2), which are |
| 210 |
always LSB,MSB. The word ordering effects all address, word, and |
| 211 |
long generation. |
| 212 |
|
| 213 |
Only one PROCESSOR pseudo-op may be declared in the entire assembly, |
| 214 |
and should be the first thing encountered. |
| 215 |
|
| 216 |
-6502 LSB,MSB |
| 217 |
-68HC11 MSB,LSB |
| 218 |
-68705 MSB,LSB |
| 219 |
-6803 MSB,LSB |
| 220 |
-HD6303 MSB,LSB |
| 221 |
-F8 ? |
| 222 |
|
| 223 |
SEGMENTS: |
| 224 |
The SEG pseudo-op creates/sets the current segment. Each segment has |
| 225 |
it's own origin and is optionally an 'uninitialized' segment. |
| 226 |
Unitialized segments produce no output and have no restrictions. This |
| 227 |
is useful for determining the size of a certain assembly sequence |
| 228 |
without generating code, and for assigning RAM to labels. |
| 229 |
|
| 230 |
'Initialized' segments produce output. The following should be |
| 231 |
considered when generating roms: |
| 232 |
|
| 233 |
(1) The default fill character when using ORG (and format 1 or 3) to |
| 234 |
skip forward is 00. This is a GLOBAL default and effects all |
| 235 |
segments. See ORG. |
| 236 |
|
| 237 |
(2) The default fill character for DS is 00 and is independant of |
| 238 |
the default fill character for ORG (see DS). |
| 239 |
|
| 240 |
GENERAL: |
| 241 |
Most everything is recursive. You cannot have a macro DEFINITION |
| 242 |
within a macro definition, but can nest macro calls, repeat loops, |
| 243 |
and include files. |
| 244 |
|
| 245 |
The other major feature in this assembler is the SUBROUTINE pseudo-op, |
| 246 |
which logically separates local labels (starting with a dot). This |
| 247 |
allows you to reuse label names (for example, .1 .fail) rather than |
| 248 |
think up crazy combinations of the current subroutine to keep it all |
| 249 |
unique. |
| 250 |
|
| 251 |
Almost nothing need be resolved in pass 1. The assembler will make |
| 252 |
multiple passes in an attempt to resolve the assembly (including just |
| 253 |
one pass if everything is resolved immediately). |
| 254 |
|
| 255 |
|
| 256 |
PSEUDOPS: |
| 257 |
|
| 258 |
INCLUDE "name" |
| 259 |
|
| 260 |
Include another assembly file. |
| 261 |
|
| 262 |
[label] INCBIN "name" |
| 263 |
|
| 264 |
Include another file literally in the output. |
| 265 |
|
| 266 |
INCDIR "directory name" |
| 267 |
|
| 268 |
Add the given directory name to the list of places where |
| 269 |
INCLUDE and INCBIN search their files. First, the names are |
| 270 |
tried relative to the current directory, if that fails and |
| 271 |
the name is not an absolute pathname, the list is tried. |
| 272 |
You can optionally end the name with a /. AmigaDOS filename |
| 273 |
conventions imply that two slashes at the |
| 274 |
end of an INCDIR (dir//) indicates the parent directory, and |
| 275 |
so does an INCLUDE /filename. |
| 276 |
|
| 277 |
The command-line option -Idir is equivalent to an INCDIR |
| 278 |
directive placed before the source file. |
| 279 |
|
| 280 |
Currently the list is not cleared between passes, but each |
| 281 |
exact directory name is added to the list only once. |
| 282 |
This may change in subsequent releases. |
| 283 |
|
| 284 |
[label] SEG[.U] name |
| 285 |
|
| 286 |
This sets the current segment, creating it if neccessary. If |
| 287 |
a .U extension is specified on segment creation, the segment |
| 288 |
is an UNINITIALIZED segment. The .U is not needed when going |
| 289 |
back to an already created uninitialized segment, though it |
| 290 |
makes the code more readable. |
| 291 |
|
| 292 |
[label] DC[.BWL] exp,exp,exp ... |
| 293 |
|
| 294 |
Declare data in the current segment. No output is generated if |
| 295 |
within a .U segment. Note that the byte ordering for the |
| 296 |
selected processor is used for each entry. |
| 297 |
|
| 298 |
The default size extension is a byte. |
| 299 |
|
| 300 |
BYTE, WORD and LONG are synonyms for DC.B, DC.W and DC.L. |
| 301 |
|
| 302 |
[label] DS[.BWL] exp[,filler] |
| 303 |
|
| 304 |
declare space (default filler is 0). Data is not generated if |
| 305 |
within an uninitialized segment. Note that the number of bytes |
| 306 |
generated is exp * entrysize (1,2, or 4) |
| 307 |
|
| 308 |
The default size extension is a byte. |
| 309 |
|
| 310 |
Note that the default filler is always 0 (has nothing to do |
| 311 |
with the ORG default filler). |
| 312 |
|
| 313 |
[label] DV[.BWL] eqmlabel exp,exp,exp.... |
| 314 |
|
| 315 |
This is equivalent to DC, but each exp in the list is passed |
| 316 |
through the symbolic expression specified by the EQM label. |
| 317 |
The expression is held in a special symbol dotdot '..' on each |
| 318 |
call to the EQM label. |
| 319 |
|
| 320 |
See EQM below |
| 321 |
|
| 322 |
[label] HEX hh hh hh.. |
| 323 |
|
| 324 |
This sets down raw HEX data. Spaces are optional between bytes. |
| 325 |
NO EXPRESSIONS are allowed. Note that you do NOT place a $ |
| 326 |
in front of the digits. This is a short form for creating |
| 327 |
tables compactly. Data is always layed down on a byte-by-byte |
| 328 |
basis. |
| 329 |
|
| 330 |
Example: HEX 1A45 45 13254F 3E12 |
| 331 |
|
| 332 |
ERR |
| 333 |
|
| 334 |
Abort assembly. |
| 335 |
|
| 336 |
[label] ORG exp[,DefaultFillVal] |
| 337 |
|
| 338 |
This pseudop sets the current origin. You can also set the |
| 339 |
global default fill character (a byte value) with this |
| 340 |
pseudoop. NOTE that no filler is generated until the first |
| 341 |
data-generating opcode/psueoop is encountered after this one. |
| 342 |
Sequences like: |
| 343 |
|
| 344 |
org 0,255 |
| 345 |
org 100,0 |
| 346 |
org 200 |
| 347 |
dc 23 |
| 348 |
|
| 349 |
will result in 200 zero's and a 23. This allows you to specify |
| 350 |
some ORG, then change your mind and specify some other (lower |
| 351 |
address) ORG without causing an error (assuming nothing is |
| 352 |
generated inbetween). |
| 353 |
|
| 354 |
Normally, DS and ALIGN are used to generate specific filler |
| 355 |
values. |
| 356 |
|
| 357 |
[label] RORG exp |
| 358 |
|
| 359 |
This activates the relocatable origin. All generated |
| 360 |
addresses, including '.', although physically placed at the |
| 361 |
true origin, will use values from the relocatable origin. |
| 362 |
While in effect both the physical origin and relocatable origin |
| 363 |
are updated. |
| 364 |
|
| 365 |
The relocatable origin can skip around (no limitations). The |
| 366 |
relocatable origin is a function of the segment. That is, you |
| 367 |
can still SEG to another segment that does not have a |
| 368 |
relocatable origin activated, do other (independant) stuff |
| 369 |
there, and then switch back to the current segment and continue |
| 370 |
where you left off. |
| 371 |
|
| 372 |
PROCESSOR model |
| 373 |
|
| 374 |
do not quote. model is one of: 6502,6803,HD6303,68705,68HC11,F8 |
| 375 |
Can only be executed once, and should be the first thing |
| 376 |
encountered by the assembler. |
| 377 |
|
| 378 |
ECHO exp,exp,exp |
| 379 |
|
| 380 |
The expressions (which may also be strings), are echoed on the |
| 381 |
screen and into the list file. |
| 382 |
|
| 383 |
[label] REND |
| 384 |
|
| 385 |
Deactivate the relocatable origin for the current segment. |
| 386 |
Generation uses the real origin for reference. |
| 387 |
|
| 388 |
[label] ALIGN N[,fill] |
| 389 |
|
| 390 |
Align the current PC to an N byte boundry. The default |
| 391 |
fill character is always 0, and has nothing to do with |
| 392 |
the default fill character specifiable in an ORG. |
| 393 |
|
| 394 |
[label] SUBROUTINE name |
| 395 |
|
| 396 |
This isn't really a subroutine, but a boundry between sets of |
| 397 |
temporary labels (which begin with a dot). Temporary label |
| 398 |
names are unique within segments of code bounded by SUBROUTINE: |
| 399 |
|
| 400 |
CHARLIE subroutine |
| 401 |
ldx #10 |
| 402 |
.1 dex |
| 403 |
bne .1 |
| 404 |
BEN subroutine |
| 405 |
ldx #20 |
| 406 |
.qq dex |
| 407 |
bne .qq |
| 408 |
|
| 409 |
Automatic temporary label boundries occur for each macro level. |
| 410 |
Usually temporary labels are used in macros and within actual |
| 411 |
subroutines (so you don't have to think up a thousand different |
| 412 |
names) |
| 413 |
|
| 414 |
|
| 415 |
symbol EQU exp |
| 416 |
|
| 417 |
symbol = exp |
| 418 |
|
| 419 |
The expression is evaluated and the result assigned to the |
| 420 |
symbol. |
| 421 |
|
| 422 |
If this option is enabled, you can use the common idiom of |
| 423 |
|
| 424 |
. EQU . + 3 (or . = .+3) |
| 425 |
|
| 426 |
in other words, you can assign to "." (or "*" if OlafStar |
| 427 |
is also enabled) instead of an ORG or RORG directive. |
| 428 |
More formally, a directive of the form ". EQU expr" is |
| 429 |
interpreted as if it were written " (R)ORG expr". |
| 430 |
The RORG is used if a relocatable origin is already in effect, |
| 431 |
otherwise ORG is used. Note that the first example is NOT |
| 432 |
equivalent with "DS.B 3" when the rorg is in effect. |
| 433 |
|
| 434 |
symbol EQM exp |
| 435 |
|
| 436 |
The STRING representing the expression is assigned to the |
| 437 |
symbol. Occurances of the label in later expressions causes |
| 438 |
the string to be evaluated for each occurance. Also used in |
| 439 |
conjuction with the DV psuedo-op. |
| 440 |
|
| 441 |
symbol SET exp |
| 442 |
|
| 443 |
Same as EQU, but the symbol may be reassigned later. |
| 444 |
|
| 445 |
symbol SETSTR exp |
| 446 |
|
| 447 |
The expression is converted to a string, and assigned to the |
| 448 |
symbol. Typical use case is within a macro, to allow the |
| 449 |
macro to echo or otherwise use the name of an argument. |
| 450 |
|
| 451 |
MAC name |
| 452 |
|
| 453 |
Declare a macro. lines between MAC and ENDM are the macro. |
| 454 |
You cannot recursively declare a macro. You CAN recursively |
| 455 |
use a macro (reference a macro in a macro). No label is |
| 456 |
allowed to the left of MAC or ENDM. |
| 457 |
|
| 458 |
Arguments passed to macros are referenced with: {#}. The first |
| 459 |
argument passed to a macro would thus be {1}. You should |
| 460 |
always use LOCAL labels (.name) inside macros which you use |
| 461 |
more than once. {0} represents an EXACT substitution of the |
| 462 |
ENTIRE argument line. |
| 463 |
|
| 464 |
ENDM |
| 465 |
|
| 466 |
end of macro def. NO LABEL ALLOWED ON THE LEFT! |
| 467 |
|
| 468 |
MEXIT |
| 469 |
|
| 470 |
Used in conjuction with conditionals. Exits the current macro |
| 471 |
level. |
| 472 |
|
| 473 |
[label] IFCONST exp |
| 474 |
|
| 475 |
Is TRUE if the expression result is defined, FALSE otherwise |
| 476 |
and NO error is generated if the expression is undefined. |
| 477 |
|
| 478 |
[label] IFNCONST exp |
| 479 |
|
| 480 |
Is TRUE if the expression result is undefined, FALSE otherwise |
| 481 |
and NO error is generated if the expression is undefined. |
| 482 |
|
| 483 |
[label] IF exp |
| 484 |
|
| 485 |
Is TRUE if the expression result is defined AND non-zero. |
| 486 |
Is FALSE if the expression result is defined AND zero. |
| 487 |
Neither IF or ELSE will be executed if the expression result |
| 488 |
is undefined. If the expression is undefined, another assembly |
| 489 |
pass is automatically taken. |
| 490 |
|
| 491 |
If this happens, phase errors in the next pass only will not |
| 492 |
be reported unless the verboseness is 1 or more. |
| 493 |
|
| 494 |
[label] ELSE |
| 495 |
|
| 496 |
ELSE the current IF. |
| 497 |
|
| 498 |
[label] ENDIF |
| 499 |
[label] EIF |
| 500 |
|
| 501 |
Terminate an IF. ENDIF and EIF are equivalent. |
| 502 |
|
| 503 |
[label] REPEAT exp |
| 504 |
[label] REPEND |
| 505 |
|
| 506 |
Repeat code between REPEAT/REPEND 'exp' times. |
| 507 |
|
| 508 |
#if DAD |
| 509 |
if exp == 0, |
| 510 |
the code repeats forever. exp is evaluated once. |
| 511 |
|
| 512 |
If exp == 0, the repeat loop is ignored. |
| 513 |
If exp < 0, a warning "REPEAT parameter < 0 (ignored)" is generated and the repeat loop is ignored. |
| 514 |
#endif |
| 515 |
|
| 516 |
Y SET 0 |
| 517 |
REPEAT 10 |
| 518 |
X SET 0 |
| 519 |
REPEAT 10 |
| 520 |
DC X,Y |
| 521 |
X SET X + 1 |
| 522 |
REPEND |
| 523 |
Y SET Y + 1 |
| 524 |
REPEND |
| 525 |
|
| 526 |
generates an output table: 0,0 1,0 2,0 ... 9,0 0,1 1,1 2,1 |
| 527 |
... 9,1, etc... |
| 528 |
|
| 529 |
Labels within a REPEAT/REPEND should be temporary labels with a |
| 530 |
SUBROUTINE pseudo-op to keep them unique. |
| 531 |
|
| 532 |
The Label to the left of REPEND is assigned AFTER the loop |
| 533 |
FINISHES. |
| 534 |
|
| 535 |
|
| 536 |
[label] XXX[.force] operand |
| 537 |
|
| 538 |
XXX is some mnemonic, not necessarily three characters long. |
| 539 |
The .FORCE optional extension is used to force specific |
| 540 |
addressing modes (see below). |
| 541 |
|
| 542 |
[label] LIST ON or OFF |
| 543 |
|
| 544 |
Globally turns listing on or off, starting with the current |
| 545 |
line. |
| 546 |
|
| 547 |
When you give LOCALON or LOCALOFF the effect is local to the |
| 548 |
current macro or included file. For a line to be listed both |
| 549 |
the global and local list switches must be on. |
| 550 |
|
| 551 |
All pseudo-ops (and incidentally also the mnemonics) can be |
| 552 |
prefixed with a . for compatibility with other assemblers. |
| 553 |
So .IF is the same as IF. This works only because lone .FORCE |
| 554 |
extensions are meaningless. |
| 555 |
|
| 556 |
GENERAL: |
| 557 |
|
| 558 |
The label will be set to the current ORG/RORG either before or after |
| 559 |
a pseudo-op is executed. Most of the time, the label to the left of a |
| 560 |
pseudo-op is the current ORG/RORG. The following pseudo-op's labels are |
| 561 |
created AFTER execution of the pseudo-op: |
| 562 |
|
| 563 |
SEG, ORG, RORG, REND, ALIGN |
| 564 |
|
| 565 |
EXTENSIONS: |
| 566 |
|
| 567 |
FORCE extensions are used to force an addressing mode. In some cases, |
| 568 |
you can optimize the assembly to take fewer passes by telling it the |
| 569 |
addressing mode. Force extensions are also used with DS,DC, and DV |
| 570 |
to determine the element size. NOT ALL EXTENSIONS APPLY TO ALL |
| 571 |
PROCESSORS! |
| 572 |
|
| 573 |
example: lda.z charlie |
| 574 |
|
| 575 |
i -implied |
| 576 |
ind -indirect word |
| 577 |
0 -implied |
| 578 |
0x -implied indexing (0,x) |
| 579 |
0y -implied indexing (0,y) |
| 580 |
b -byte address |
| 581 |
bx -byte address indexed x |
| 582 |
by -byte address indexed y |
| 583 |
w -word address |
| 584 |
wx -word address indexed x |
| 585 |
wy -word address indexed y |
| 586 |
l -longword (4 bytes) (DS/DC/DV) |
| 587 |
r -relative |
| 588 |
u -uninitialized (SEG) |
| 589 |
|
| 590 |
First character equivalent substitutions: |
| 591 |
|
| 592 |
b z d (byte, zeropage, direct) |
| 593 |
w e a (word, extended, absolute) |
| 594 |
|
| 595 |
|
| 596 |
ASSEMBLER PASSES: |
| 597 |
The assembler may have to make several passes through the source |
| 598 |
code to resolve all generation. The number of passes is not |
| 599 |
limited to two. Since this may result in an unexpected, verbose |
| 600 |
option 2, 3, and 4 have been provided to allow determination of the |
| 601 |
cause. The assembler will give up if it thinks it can't do the |
| 602 |
assembly in *any* number of passes. |
| 603 |
|
| 604 |
Error reporting could be better.... |
| 605 |
|
| 606 |
The check if another pass might resolve the source is pretty good, but |
| 607 |
not perfect. You can specify the maximum number of passes to do |
| 608 |
(default -p10), and with the -P option you can override the normal check. |
| 609 |
This allows the following contrived example to resolve in 12 passes: |
| 610 |
|
| 611 |
org 1 |
| 612 |
repeat [[x < 11] ? [x-11]] + 11 |
| 613 |
dc.b x |
| 614 |
repend |
| 615 |
x: |
| 616 |
|
| 617 |
EXPRESSIONS: |
| 618 |
[] may be used to group expressions. The precedense of operators |
| 619 |
is the same as for the C language in almost all respects. Use |
| 620 |
brackets [] when you are unsure. The reason () cannot be used to |
| 621 |
group expressions is due to a conflict with the 6502 and other |
| 622 |
assembly languages. |
| 623 |
|
| 624 |
It is possible to use () instead of [] in expressions following |
| 625 |
pseudo-ops, but not following mnemonics. So this works: |
| 626 |
if target & (pet3001 | pet4001), but this doesn't: |
| 627 |
lda #target & (pet3001 | pet4001). |
| 628 |
|
| 629 |
Some operators, such as ||, can return a resolved value even if |
| 630 |
one of the expressions is not resolved. Operators are as follows: |
| 631 |
|
| 632 |
NOTE WELL! Some operations will result in non-byte values when a |
| 633 |
byte value was wanted. For example: ~1 is NOT $FF, but |
| 634 |
$FFFFFFFF. Preceding it with a < (take LSB of) will solve the |
| 635 |
problem. ALL ARITHMETIC IS CARRIED OUT IN 32 BITS. The final |
| 636 |
Result will be automatically truncated to the maximum handleable |
| 637 |
by the particular machine language (usually a word) when applied |
| 638 |
to standard mnemonics. |
| 639 |
|
| 640 |
prec UNARY |
| 641 |
|
| 642 |
20 ~exp one's complement. |
| 643 |
20 -exp negation |
| 644 |
20 !exp not expression (returns 0 if exp non-zero, 1 if exp zero) |
| 645 |
20 <exp take LSB byte of a 16 bit expression |
| 646 |
20 >exp take MSB byte of an expression |
| 647 |
|
| 648 |
BINARY |
| 649 |
|
| 650 |
19 * multiplication |
| 651 |
19 / division |
| 652 |
19 % mod |
| 653 |
18 + addition |
| 654 |
18 - subtraction |
| 655 |
17 >>,<< shift right, shift left |
| 656 |
16 >,>= greater, greater equal |
| 657 |
16 <,<= smaller, smaller equal |
| 658 |
15 == equal to. Try to use this instead of = |
| 659 |
15 = exactly the same as == (exists compatibility) |
| 660 |
15 != not equal to |
| 661 |
14 & logical and |
| 662 |
13 ^ logical xor |
| 663 |
12 | logical or |
| 664 |
11 && left expression is true AND right expression is true |
| 665 |
10 || left expression is true OR right expression is true |
| 666 |
9 ? if left expression is true, result is right expression, |
| 667 |
else result is 0. [10 ? 20] returns 20 |
| 668 |
8 [] group expressions |
| 669 |
7 , separate expressions in list (also used in |
| 670 |
addressing mode resolution, BE CAREFUL! |
| 671 |
|
| 672 |
Note: The effect of the C conditional operator a ? b : c can be |
| 673 |
had with [a ? b - c] + c. |
| 674 |
|
| 675 |
Constants: |
| 676 |
|
| 677 |
nnn decimal |
| 678 |
0nnn octal |
| 679 |
%nnn binary |
| 680 |
$nnn hex |
| 681 |
'c character |
| 682 |
"cc.." string (NOT zero terminated if in DC/DS/DV) |
| 683 |
[exp]d the constant expressions is evaluated and it's decimal |
| 684 |
result turned into an ascii string. |
| 685 |
|
| 686 |
Symbols: |
| 687 |
|
| 688 |
... -holds CHECKSUM so far (of actual-generated stuff) |
| 689 |
.. -holds evaluated value in DV pseudo op |
| 690 |
.name -represents a temporary symbol name. Temporary symbols |
| 691 |
may be reused inside MACROS and between SUBROUTINES, but |
| 692 |
may not be referenced across macros or across SUBROUTINEs. |
| 693 |
. -current program counter (as of the beginning of the |
| 694 |
instruction). |
| 695 |
name -beginning with an alpha character and containing letters, |
| 696 |
numbers, or '_'. Represents some global symbol name. |
| 697 |
* -synonym for ., when not confused as an operator. |
| 698 |
nnn$ -temporary label, much like .name, except that defining |
| 699 |
a non-temporary label has the effect that SUBROUTINE |
| 700 |
has on .name. They are unique within macros, like |
| 701 |
.name. Note that 0$ and 00$ are distinct, as are 8$ |
| 702 |
and 010$. |
| 703 |
(mainly for compatibility with other assemblers.) |
| 704 |
|
| 705 |
Dynamic Symbol/Labels |
| 706 |
|
| 707 |
When used in a symbol name, the "," operator indicates one or more |
| 708 |
arguments that follow should be evaluated, and the resulting values |
| 709 |
should concatenated to the label, to create a "dynamic" symbol name. |
| 710 |
|
| 711 |
symbol,ARG1[,ARG2,...] |
| 712 |
|
| 713 |
String literals can be specified with quotes around the string |
| 714 |
text. Expression operators can also be used, but due to label |
| 715 |
parsing constraints, they should not contain spacing. |
| 716 |
|
| 717 |
The concat-eval "," operator also works on the expression side |
| 718 |
of EQU/SET pseudo-ops, so dynamic labels can be used with opcodes. |
| 719 |
|
| 720 |
WHY codes: |
| 721 |
Each bit in the WHY word (verbose option 1) is a reason (why |
| 722 |
the assembler needs to do another pass), as follows: |
| 723 |
|
| 724 |
bit 0 expression in mnemonic not resolved |
| 725 |
1 - |
| 726 |
2 expression in a DC not resolved |
| 727 |
3 expression in a DV not resolved (probably in DV's EQM symbol) |
| 728 |
4 expression in a DV not resolved (could be in DV's EQM symbol) |
| 729 |
5 expression in a DS not resolved |
| 730 |
6 expression in an ALIGN not resolved |
| 731 |
7 ALIGN: Relocatable origin not known (if in RORG at the time) |
| 732 |
8 ALIGN: Normal origin not known (if in ORG at the time) |
| 733 |
9 EQU: expression not resolved |
| 734 |
10 EQU: value mismatch from previous pass (phase error) |
| 735 |
11 IF: expression not resolved |
| 736 |
12 REPEAT: expression not resolved |
| 737 |
|
| 738 |
13 a program label has been defined after it has been |
| 739 |
referenced (forward reference) and thus we need another |
| 740 |
pass |
| 741 |
14 a program label's value is different from that of the |
| 742 |
previous pass (phase error) |
| 743 |
|
| 744 |
Certain errors will cause the assembly to abort immediately, others |
| 745 |
will wait until the current pass is other. The remaining allow another |
| 746 |
pass to occur in the hopes the error will fix itself. |
| 747 |
|
| 748 |
|
| 749 |
HISTORIC VERSIONS: (pre github) |
| 750 |
|
| 751 |
V2.12 |
| 752 |
-Fixed macro naming bug (macros wouldn't work if the name after |
| 753 |
the 'mac' was in upper case). |
| 754 |
|
| 755 |
V2.11 |
| 756 |
-Fixed <exp >exp bug, <exp now means LSB, >exp MSB (it used to |
| 757 |
be reversed). |
| 758 |
-Fixed many bugs in macros and other things |
| 759 |
-Added automatic checksumming ... no more doing checksums manually! |
| 760 |
-Added several new processors, including 6502. |
| 761 |
-Source is now 16/32 bit int compatible, and will compile on an |
| 762 |
IBM-PC (the ultimate portability test) |
| 763 |
|
| 764 |
V2.01 |
| 765 |
|
| 766 |
-can now have REPEAT/REPEND's within macros |
| 767 |
-fill field for DS.W is a word (used to be a byte fill) |
| 768 |
-fill field for DS.L is a long (used to be a byte fill) |
| 769 |
|