1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Assembler for Microchip PIC16Cxx microcontrollers</title>
<link rel="made" href="mailto:trossi@iki.fi">
</head>
<body>
<h1>Assembler for Microchip PIC16Cxx microcontrollers</h1>
<h2>Version 1.14</h2>
<p>
Copyright 1995-2005 by Timo Rossi. All rights reserved.
See the file "<a href="LICENSE">LICENSE</a>" for information
about redistribution conditions.
</p>
<p>
Timo Rossi<br>
email: <a href="mailto:trossi@iki.fi">trossi@iki.fi</a><br>
www: <a href="http://www.iki.fi/trossi/pic/">http://www.iki.fi/trossi/pic/</a>
</p>
<p>
<strong>NOTE:</strong>
This document file
has not been properly updated. There is support for many new PICs
(including 16-bit ones), and some new directives.
</p>
<p>
The code is (mostly) ISO-C90, and should compile with most
platforms (It does assume that negative integers are
stored in two's complement representation) And it
uses the <code>strcasecmp()</code> or <code>stricmp()</code> function).
The code also uses the so-called "struct hack".
Also, the snprintf() function (standard in ISO-C99) is used.
</p>
<h2>Command line usage:</h2>
<code>picasm</code> [<code>-o</code><var><objname></var>]
[<code>-l</code><var><listfile></var>]
[<code>-ihx8m</code>] [<code>-ihx16</code>]
[-<code>pic</code><var><device></var>] <var><filename></var>
<h3>Options:</h3>
<table><tr>
<td valign="top"><code>-o</code><var><filename></var></td>
<td valign="top">Define output file name.
Default is <var><source_without_ext></var><code>.hex</code>.</td>
</tr><tr>
<td valign="top"><code>-l</code>[<var><listfile></var>]</td>
<td valign="top">Enable listing. Default listing
file name is <var><source_without_ext></var><code>.lst</code>.</td>
</tr><tr>
<td valign="top"><code>-s</code></td>
<td valign="top">Includes symbol table in listing.
Does nothing if listing is not enabled.</td>
</tr><tr>
<td valign="top"><code>-w</code>[<var><warnlevel></var>]</td>
<td valign="top">Give more warnings. If <warnlevel> is omitted,
one is assumed. Level two warns also
about tris/option instructions on 14-bit PICs.</td>
</tr><tr>
<td valign="top"><code>-i</code><var><include_dir></var></td>
<td valign="top">Add a directory to the include file search path.
Several <code>-i</code> -options can be used
to add multiple directories.</td>
</tr><tr>
<td valign="top"><code>-d</code><var><symbol></var> [ <code>=</code>
<var><value></var> ]</td>
<td valign="top">Define an assembler symbol. The value of the symbol must be
a decimal or hex number (hex uses <code>0x</code>-prefix). If a value is not given,
the symbol value becomes <code>1</code>. Multiple <code>-d</code>-
options can be used to define multiple symbols.</td>
</tr><tr>
<td valign="top"><code>-ihx8m</code></td>
<td valign="top">IHX8M output format (default).</td>
</tr><tr>
<td valign="top"><code>-ihx16</code></td>
<td valign="top">IHX16 output format.</td>
</tr><tr>
<td valign="top"><code>-pic</code><var><device></var></td>
<td valign="top">Select PIC device. The PIC types are defined
in special include files (see the <code>device_definitions</code> directory).
</tr></table>
<h2>Code syntax</h2>
<p>The basic syntax that this assembler uses is similar to the
syntax of the Microchip assembler. However, many directives
and expressions are different.</p>
<p>Assembler mnemonics and directives must not be located in the very
beginning of a line (tabs or spaces should be used, unless the line
begins with a label). Labels must either end with a colon, or start
at the beginning of a line.</p>
<p>This is a single-pass assembler, forward gotos/calls are patched
at the end of the assembly (only single labels are accepted in
that case, otherwise expressions can be used too)</p>
<p>In current versions forward references can also be used
with <code>movlw</code>, <code>addlw</code> and <code>retlw</code>
(only the low 8 bits of an address are used.)</p>
<h2>Expressions</h2>
<p>Expressions can have the following elements:
(from highest precedence to the lowest).</p>
<table border="0"><tr>
<td valign="top"></td><td valign="top">integer constants</td>
</tr><tr>
<td valign="top"></td><td valign="top">symbols</td>
</tr><tr>
<td valign="top"><code>(</code><var><expression></var><code>)</code></td>
</tr><tr>
<td valign="top"><code>.</code> (or <code>$</code>)</td><td valign="top">current location</td>
</tr><tr>
<td valign="top"><code>defined(</code><var><symbol></var><code>)</code></td>
<td valign="top">TRUE (-1) if symbol is defined else FALSE (0).</td>
</tr><tr>
<td valign="top"><code>streq(</code><var>"str1"</var><code>,</code> <var>"str2"</var><code>)</code></td>
<td valign="top">TRUE if strings are identical.</td>
</tr><tr>
<td valign="top"><code>streqcase(</code><var>"str1"</var><code>,</code> <var>"str2"</var><code>)</code></td>
<td valign="top">The same as streq() but ignores case (Only for ASCII characters, not ISO-Latin, Unicode etc.).</td>
</tr><tr>
<td valign="top"><code>isstr(</code><var><arg></var><code>)</code></td>
<td valign="top">TRUE is argument is a quoted string.</td>
</tr><tr>
<td valign="top"><code>chrval(</code><var>"str"</var><code>,</code> <var><pos></var><code>)</code></td>
<td valign="top">Returns ASCII character code from the string.
Position range is from 0 to <var>string length</var>-1.
If position is out of range, returns -1.</td>
</tr><tr>
<td valign="top"><code>hibyte(</code><var>label</var><code>)</code></td>
<td valign="top">
Return the high byte of the label address.
Useful for accessing program memory using the eeadr/eeadrh registers.
Forward reference is allowed when <code>hibyte()</code> is not used as
a part of a more complex expression.</td>
</tr><tr>
<td><code>[</code> <var>expr1</var> <var>expr2</var>...
<var>expr_n</var> <code>]</code></td>
<td>The same as <code>(1 << </code><var>expr1</var><code>)</code>
<code>|</code> <code>(1 << </code><var>expr2</var><code>)</code> ...
(builds a number by setting individual bits)</td>
</tr><tr>
<td><code>-</code></td><td>unary minus</td>
</tr><tr>
<td><code>~</code></td><td>bitwise not</td>
</tr><tr>
<td><code>*</code></td><td>multiply</td>
</tr><tr>
<td><code>/</code></td><td>divide</td>
</tr><tr>
<td><code>%</code></td><td>modulo/remainder</td>
</tr><tr>
<td><code>&</code></td><td>bitwise and</td>
</tr><tr>
<td><code>+</code></td><td>add</td>
</tr><tr>
<td><code>-</code></td><td>subtract</td>
</tr><tr>
<td><code>|</code></td><td>bitwise or</td>
</tr><tr>
<td><code>^</code></td><td>bitwise exclusive or</td>
</tr><tr>
<td><code><<</code></td><td>shift left</td>
</tr><tr>
<td><code>>></code></td><td>shift right</td>
</tr><tr>
<td><code>==</code></td><td>equal</td>
</tr><tr>
<td><code>!=</code>, <code><></code></td><td>not equal</td>
</tr><tr>
<td><code><</code></td><td>less than</td>
</tr><tr>
<td><code><=</code>, <code>=<</code></td><td>less or equal than</td>
</tr><tr>
<td><code>></code></td><td>greater than</td>
</tr><tr>
<td><code>>=</code>, <code>=></code></td><td>greater or equal than</td>
</tr></table>
<p>
The compare operators return TRUE (-1) or FALSE (0)
(they are useful with conditional assembly).</p>
<p>
Expressions are evaluated as 32-bit integers (or whatever size 'long' is).
</p>
<table border="0"><tr><td>
hex numbers</td><td><code>0x</code><var><digits></var>,
<code>h'</code><var><digits></var><code>'</code>,
<code>$</code><var><digits></var>
or <var><digits></var><code>h</code> (must begin with 0..9)
</td></tr><tr><td>
octal numbers</td><td><var><digits></var><code>o</code>,
<code>o'</code><var><digits></var><code>'</code>
</td></tr><tr><td>
binary numbers</td><td><code>0b</code><var><digits></var>,
<code>b'</code><var><digits></var><code>'</code>
or <var><digits></var><code>b</code>
</td></tr><tr><td>
decimal numbers</td><td>without prefix or
<code>d'</code><var><digits></var><code>'</code>.
</td></tr></table>
<h2>Directives</h2>
(square brackets denote optional parameters)
<table border="0"><tr>
<td valign="top"><var><label></var> <code>equ</code> <var><expr></var></td>
<td valign="top">Define a constant</td>
</tr><tr>
<td valign="top"><var><label></var> <code>set</code> <var><expr></var></td>
<td valign="top">Define a variable
(similar to equ but can be redefined with another set-directive)</td>
</tr><tr>
<td valign="top">
<code> org</code> <var><address></var><br>
<code> org</code> <var><address></var><code>,</code> <var><mode></var><br>
<code> org</code> <var><mode></var></td>
<td valign="top">Specify origin for program code, register file or data EEPROM.
<var><mode></var> is "<code>code</code>" for program code,
"<code>reg</code>" for register file and "<code>edata</code>" for data EEPROM.
If mode is not given, it is
determined automatically from first instruction that generates
output to the hex file. After that the mode cannot be changed
without another ORG statement. When ORG is used with only
the mode parameter, the address continues from the last value
for that mode.</td>
</tr><tr>
<td valign="top"><code> include</code> <code>"</code><var>
<filename></var><code>"</code></td>
<td valign="top">Include another source file. Includes can be nested.
<code>#include</code> is an alternate name for this</td>
</tr><tr>
<td valign="top"><code> end</code></td>
<td valign="top"> End assembly. anything after this is ignored.</td>
</tr><tr>
<td valign="top"><var><label></var> <code>ds</code> <var><expr></var></td>
<td valign="top">Reserve <expr> number of file register (RAM)
locations. ORG must be set for this to work.</td>
</tr><tr>
<td valign="top"><var><label></var> <code>edata</code> <var><expr></var> [<code>,</code> <var><expr>...</var> ]</td>
<td valign="top">Define data EEPROM contents (only with PICs with data EEPROM)</td>
</tr><tr>
<td valign="top"><code> dt</code>
<var><value1></var> [ <code>,</code> <var><value2>...</var> ]</td>
<td valign="top">Generate an array <code>retlw</code> instructions with the
specified return values (typically used for table lookup in PIC assembler code.
You can also use a list of multiple return values with the actual <code>retlw</code>
-mnemonic to generate to a list of <code>retlw</code> instructions.)
</tr><tr>
<td valign="top"><code> if</code> <var><expr></var><br>
<var><code1></var><br>
<code> </code>[ <code>else</code><br>
<var><code2></var> ]<br>
<code> endif</code>
<td valign="top">Conditional assembly. If <var><expr></var> is non-zero,
<var><code1></var> after the if-directive is assembled,
and the optional <var><code2></var> is skipped.
If <var><expr></var> is zero, <var><code1></var>
is skipped and optional <var><code2></var> is assembled.</td>
</tr><tr>
<td valign="top"><var><macroname></var> <code>macro</code><br>
<var><macro definition></var><br>
<code> endm</code></td>
<td valign="top"><p>Define a macro.</p><p>
Macro parameters are <code>\1</code>...<code>\9</code>,
<code>\#</code> is the number of parameters.
<code>\@</code> (or <code>\0</code>) is an number that is different
for each macro
expansion (it can be used to generate unique labels inside macros).
Macros can be recursive.</p></td>
</tr><tr>
<td valign="top"><code> exitm</code></td>
<td valign="top">Exit macro (can only be used inside a macro
definition. Useful with conditional assembly)</td>
</tr><tr>
<td valign="top"><code> local</code><br>
<code> endlocal</code></td>
<td valign="top"><p>Begin and end a local label/symbol block.</p><p>
Local symbols must be prefixed with "<code>=</code>"
and their name scope is only
the current local symbol block.
Local symbol blocks can be nested
but only the symbols in the currently
active block can be used (the symbols
in the inner and outer blocks are not visible)</p></td>
</tr><tr>
<td valign="top">
<code> config</code> <var><config_param></var> [<code>,</code> <var><config_param></var>...]</td>
<td valign="top">Define PIC configuration fuse data.
<var><config_param></var> can be:
<table border="0"><tr>
<td valign="top"><code>CP=</code><var><on_off></var></td>
<td valign="top">Code protection (default off, partial protection not supported)</td>
</tr><tr>
<td valign="top"><code>PWRTE=</code><var><on_off></var></td>
<td valign="top">Powerup timer (default varies with PIC models, not valid with 12-bit PICs).
Also <code>PWRT=</code><var><on_off></var>.</td>
</tr><tr>
<td valign="top"><code>WDTE=</code><var><on_off></var></td>
<td valign="top"> Watchdog (default on). Also <code>WDT=</code><var><on_off></var>.</td>
</tr><tr>
<td valign="top"><code>BODEN=</code><var><on_off></var></td>
<td valign="top">Brown-out detect. only valid with some PIC models.
Also <code>BOD=</code><var><on_off></var>.</td>
</tr><tr>
<td valign="top"><code>OSC=</code><var><osctype></var></td>
<td valign="top">Oscillator type (typically <code>HS</code>, <code>XT</code>,
<code>LP</code>, <code>RC</code>, some PIC models have different options)
</td></tr></table>
The <var><on_off></var> parameter can be:
<table border="0"><tr>
<td valign="top"><code>on</code>, <code>yes</code>, <code>enabled</code></td><td valign="top">on</td>
</tr><tr>
<td valign="top"><code>off</code>, <code>no</code>, <code>disabled</code></td><td valign="top">off</td>
</tr></table>
The fuses are located in address 0xfff with
12-bit PICs and 0x2007 with 14-bit PICs.
</tr><tr>
<td valign="top"><code> picid</code> <var><id1></var><code>,</code>
<var><id2></var><code>,</code>
<var><id3></var><code>,</code>
<var><id4></var></td>
<td valign="top"><p>Define PIC ID values.</p><p>
The ID is located in the hex file at the address
following program memory end with 12-bit PICs,
and at 0x2000 with 14-bit PICs.</p></td>
</tr><tr>
<td valign="top"><code> device</code> <var><device></var></td>
<td valign="top">Select PIC device type. The PIC types are defined
in special include files. (see the <code>device_definitions</code> directory).
</td>
</tr><tr>
<td valign="top"><code> opt</code> <var><option></var></td>
<td valign="top">Set assembly options. Currently only implemented:
<table border="0"><tr>
<td><code>list</code> or <code>l</code></td><td>turn listing on</td>
</tr><tr>
<td><code>nolist</code> or <code>nol</code></td><td>turn listing off</td>
</tr></table>
</tr><tr>
<td valign="top"><code> error</code> <var><error_message></var></td>
<td valign="top">Causes an assembly error.</td>
</tr>
</table>
</body>
</html>
|