Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  2.     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <meta name="generator" content="AsciiDoc 8.5.3" />
  7. <link rel="stylesheet" href="./xhtml11.css" type="text/css" />
  8. <link rel="stylesheet" href="./xhtml11-quirks.css" type="text/css" />
  9. <link rel="stylesheet" href="./layout1.css" type="text/css" />
  10. <script type="text/javascript">
  11. /*<![CDATA[*/
  12. window.onload = function(){asciidoc.footnotes();}
  13. /*]]>*/
  14. </script>
  15. <script type="text/javascript" src="./asciidoc-xhtml11.js"></script>
  16. <title>README</title>
  17. </head>
  18. <body>
  19. <div id="layout-banner">
  20.   <div id="layout-title">AVRA</div>
  21.   <div id="layout-description">Assember for the Atmel AVR microcontroller family</div>
  22. </div>
  23. <table>
  24. <tr valign="top">
  25. <td id="layout-menu">
  26.   <div>&#187;<a href="index.html">Home</a></div>
  27.   <div>&#187;<a href="README.html">Readme</a></div>
  28.   <div>&#187;<a href="downloads.html">Downloads</a></div>
  29.   <div>&#187;<a href="ChangeLog.html">ChangeLog</a></div>
  30.   <div>&#187;<a href="http://sourceforge.net/projects/avra">Sourceforge</a></div>
  31.   <div id="page-source">&#187;<a href="README.txt">Page&nbsp;Source</a></div>
  32. </td>
  33. <td>
  34. <div id="layout-content">
  35. <div id="header">
  36. <h1>README</h1>
  37. </div>
  38. <div id="content">
  39. <h2 id="_general_and_licensing_information">General and licensing information</h2>
  40. <div class="sectionbody">
  41. <div class="paragraph"><p>AVRA v1.3.0 - Assember for the Atmel AVR microcontroller family</p></div>
  42. <h3 id="_licensing_information">Licensing information</h3><div style="clear:left"></div>
  43. <div class="paragraph"><p>This program is free software; you can redistribute it and/or modify
  44. it under the terms of the GNU General Public License as published by
  45. the Free Software Foundation; either version 2 of the License, or
  46. (at your option) any later version. Please read below for for information.</p></div>
  47. <h3 id="_disclaimer">Disclaimer</h3><div style="clear:left"></div>
  48. <div class="paragraph"><p>This program is distributed in the hope that it will be useful, but
  49. WITHOUT ANY WARRANTY; without even the implied warranty of
  50. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  51. GNU General Public License for more details.</p></div>
  52. <h3 id="_gnu_general_public_license">GNU General Public License</h3><div style="clear:left"></div>
  53. <div class="paragraph"><p>You should have received a copy of the GNU General Public License
  54. along with this program; see the file "COPYING".  If not, visit
  55. <a href="http://www.gnu.org">http://www.gnu.org</a> or write to the Free Software Foundation, Inc.,
  56. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. You can
  57. also contact the authors of AVRA to receive a copy of the COPYING file.</p></div>
  58. <h3 id="_trademarks_and_copyright">Trademarks and copyright</h3><div style="clear:left"></div>
  59. <div class="paragraph"><p>Atmel, AVR, AVR Studio, Intel, Windows are registered enterprises, brands
  60. and registered trademarks. The mentioned companies have no relation to
  61. AVRA and are therefore not responslible for any problems that occur when
  62. using AVRA. Many thanks for your products, support and efforts.</p></div>
  63. </div>
  64. <h2 id="_introducion">Introducion</h2>
  65. <div class="sectionbody">
  66. <div class="paragraph"><p>AVRA is an assembler for Atmel AVR microcontrollers, and it is almost
  67. compatible with Atmel&#8217;s own assembler AVRASM32. The programming
  68. principles and conceptions are based on the ANSI programming language "C".</p></div>
  69. <div class="paragraph"><p>The initial version of AVRA was written by John Anders Haugum. He released
  70. all versions until v0.7. All later versions were released by Tobias Weber.</p></div>
  71. <h3 id="_differences_between_avra_and_avrasm32">Differences between AVRA and AVRASM32</h3><div style="clear:left"></div>
  72. <div class="paragraph"><p>There are some differences between the original Atmel assembler AVRASM32 and AVRA. Basically AVRA is designed to replace AVRASM32 without special changes in your current Atmel AVR Studio enviroment.
  73. Command line options have been adapted as far as it was possible until now. Jumping to fault containing line directly by double-clicking on the error message in the output window does work as with AVRASM32.</p></div>
  74. <h3 id="_the_differences_in_detail">The differences in detail</h3><div style="clear:left"></div>
  75. <div class="ulist"><ul>
  76. <li>
  77. <p>
  78. Support for some extra preprocessor directives.
  79. </p>
  80. <div class="literalblock">
  81. <div class="content">
  82. <pre><tt>.define, .undef, .ifdef, .ifndef, .if, .else, .endif, .elif, .elseif, .warning</tt></pre>
  83. </div></div>
  84. </li>
  85. <li>
  86. <p>
  87. Not all command line options are supported.
  88.       Specifying an eeprom file (-e) is not supported. All eeprom data is
  89.       put out into a file called program.eep.hex and always Intel hex
  90.       format. Other hex file formats than Intel are currently not supported.
  91. </p>
  92. </li>
  93. <li>
  94. <p>
  95. Forward references not supported for .ifdef and .ifndef directives.
  96.       This makes sure, that directives like .ifdef and .undef are working
  97.       properly. If you are familiar with the C programming language, you
  98.       should get easily into AVRA. See chapter "Programming techniques" for
  99.       more information about how to write proper code.
  100. </p>
  101. </li>
  102. <li>
  103. <p>
  104. Enhanced macro support
  105.       AVRA has some new features for writing flexible macros. This should
  106.       increase the ability to reuse code e.g. build your own library.
  107. </p>
  108. </li>
  109. <li>
  110. <p>
  111. Debugging support
  112.       AVRA creates a coff file everytime the assembly was sucessful. This
  113.       file allows AVR Studio or any coff compatible debugger to simulate
  114.       or emulate the program.
  115. </p>
  116. </li>
  117. <li>
  118. <p>
  119. Meta tags for assembly time
  120.       This helps you tracking versions of your software and can also be
  121.       used to generate customer specific serial numbers.
  122. </p>
  123. </li>
  124. </ul></div>
  125. <h3 id="_compatibility">Compatibility</h3><div style="clear:left"></div>
  126. <div class="paragraph"><p>Since AVRA is written in ANSI C, it should be possible to compile it on
  127. most system platforms. If you have problems compiling AVRA, please leave
  128. a message on the sourceforge message board or send a mail to the
  129. authors of AVRA.</p></div>
  130. </div>
  131. <h2 id="_installation">Installation</h2>
  132. <div class="sectionbody">
  133. <div class="paragraph"><p>To install avra you should copy the avra-executable to an apropriate
  134. location. To compile you should rename the appropriate makefile, and
  135. perform a make (use smake for Amiga SAS/C, and nmake for Mickeysoft
  136. visual c++).</p></div>
  137. <h3 id="_linux">Linux</h3><div style="clear:left"></div>
  138. <div class="paragraph"><p>To compile avra you need gcc and the automake utilities. These will create
  139. a ./configure script that evaluates your system enviroment. To get the
  140. AVRA executable, you have to issue the following commands:</p></div>
  141. <div class="paragraph"><p>aclocal
  142. autoconf
  143. automake -a
  144. ./configure
  145. make &amp;&amp; make install</p></div>
  146. <h3 id="_amigaos">AmigaOS</h3><div style="clear:left"></div>
  147. <div class="paragraph"><p>avra can be copied any apropriate directory. If you are using the source
  148. distribution a <em>make install</em> will do the same.</p></div>
  149. <h3 id="_microsoft_windows">Microsoft Windows</h3><div style="clear:left"></div>
  150. <div class="paragraph"><p>If you received the Windows binary package, look into the \bin
  151. directory where you can find avra.exe. This should be copied to any
  152. apropriate location. You can also overwrite AVRASM32.EXE in your
  153. Atmel AVR Studio. If you want to compile it yourself you could download then
  154. OpenWatcom C/C++ Toolchain for windows and create a new project and add the C
  155. and H files to it and compile.</p></div>
  156. <h3 id="_apple_os_x">Apple OS X</h3><div style="clear:left"></div>
  157. <div class="paragraph"><p>If you recieved the Apple OS X binary package, look into the bin directory this
  158. file is compiled universal and should run on intel 32 and 64 bit and powerpc. If
  159. you want to compile it yourself go to the src directory and invoke <tt>make -f
  160. makefiles/Makefiles.osx</tt> and then the executable should be created.</p></div>
  161. </div>
  162. <h2 id="_synopsis">Synopsis</h2>
  163. <div class="sectionbody">
  164. <h3 id="_command_line_usage">Command line usage</h3><div style="clear:left"></div>
  165. <div class="literalblock">
  166. <div class="content">
  167. <pre><tt>usage: AVRA [-f][O|M|I|G] output file type
  168.          [-o &lt;filename&gt;] output file name
  169.          [-l &lt;filename&gt;] generate list file
  170.          [-m &lt;mapfile&gt;] generate map file
  171.          [--define &lt;symbol&gt;[=&lt;value&gt;]]  [--includedir &lt;dir&gt;] [--listmac]
  172.          [--max_errors &lt;number&gt;] [--devices] [--version]
  173.          [-h] [--help] general help
  174.          [-W NoRegDef] supress register redefinition warnings
  175.          &lt;file to assemble&gt;</tt></pre>
  176. </div></div>
  177. <h3 id="_parameter_list">Parameter list</h3><div style="clear:left"></div>
  178. <div class="literalblock">
  179. <div class="content">
  180. <pre><tt>--listfile    -l : Create list file
  181. --mapfile     -m : Create map file
  182. --define      -D : Define symbol.
  183. --includedir  -I : Additional include dirs.
  184. --listmac        : List macro expansion in listfile.
  185. --max_errors     : Maximum number of errors before exit
  186.                    (default: 10)
  187. --devices        : List out supported devices.
  188. --version        : Version information.
  189. --help, -h       : This help text.</tt></pre>
  190. </div></div>
  191. <h3 id="_warning_supression">Warning supression</h3><div style="clear:left"></div>
  192. <div class="paragraph"><p>Since avra 1.1 there is a possibility to supress certain warnings.
  193. Currently only register reassignment warnings can be supressed.</p></div>
  194. <div class="paragraph"><p>Example: avra -W NoRegDef</p></div>
  195. </div>
  196. <h2 id="_programming_techniques">Programming techniques</h2>
  197. <div class="sectionbody">
  198. <h3 id="_using_directives">Using directives</h3><div style="clear:left"></div>
  199. <div class="paragraph"><p>AVRA offers a number of directives that are not part of Atmel&#8217;s
  200. assembler. These directives should help you creating versatile code that
  201. can be designed more modular.</p></div>
  202. <h4 id="_directive_define">Directive .define</h4>
  203. <div class="paragraph"><p>To define a constant, use ".define". This does the same thing as ".equ",
  204. it is just a little more C style. Keep in mind that AVRA is not case
  205. sensitive. Do not mix ".def" and ".define", because ".def" is used to
  206. assign registers only. This is due to backward compatibility to Atmel&#8217;s
  207. AVRASM32. Here is an example on how .define can be used.</p></div>
  208. <div class="literalblock">
  209. <div class="content">
  210. <pre><tt>.define network 1</tt></pre>
  211. </div></div>
  212. <div class="paragraph"><p>Now "network" is set to the value 1. You may want to assemble a specific
  213. part of your code depeding on a define or switch setting. You can test
  214. your defined word on existence (.ifdef and .ifndef) as well as on the
  215. value it represents. The following code shows a way to prevent error
  216. messages due to testing undefined constants. Conditional directives must
  217. always end with an .endif directive.</p></div>
  218. <div class="literalblock">
  219. <div class="content">
  220. <pre><tt>.ifndef network
  221. .define network 0
  222. .endif</tt></pre>
  223. </div></div>
  224. <h4 id="_directive_if_and_else">Directive .if and .else</h4>
  225. <div class="paragraph"><p>The three lines in the last example set the default value of "network".
  226. In the next example, you see how we can use default values. If a constant
  227. has not defined previously, it is set to zero. Now you can test wether
  228. e.g. network support is included into the assemby process.</p></div>
  229. <div class="literalblock">
  230. <div class="content">
  231. <pre><tt>.if network = 1
  232. .include "include\tcpip.asm"
  233. .else
  234. .include "include\dummynet.asm"
  235. .endif</tt></pre>
  236. </div></div>
  237. <div class="paragraph"><p>In the second part of the above listing you see the use of .else, which
  238. defines the part of the condition that is being executed if the equation
  239. of the preceding .if statement is not equal. You can also use the else
  240. statement to test another equasion. For that purpose use .elif, which
  241. means "else if". Always close this conditional part with ".endif"</p></div>
  242. <h4 id="_directive_error">Directive .error</h4>
  243. <div class="paragraph"><p>This directive can be used to throw errors if a part in the code has reached
  244. that should not be reached. The following example shows how we can stop
  245. the assembly process if a particular value has not been previously set.</p></div>
  246. <div class="literalblock">
  247. <div class="content">
  248. <pre><tt>.ifndef network
  249. .error "network is not configured!" ;the assembler stops here</tt></pre>
  250. </div></div>
  251. <h4 id="_directive_nolist_and_list">Directive .nolist and .list</h4>
  252. <div class="paragraph"><p>The ouput to the list file can be paused by this two directives. After
  253. avra discovers a .nolist while assembling, it stops output to the list file.
  254. After a .list directive is detected, it continues the normal list file output.</p></div>
  255. <h4 id="_directive_includepath">Directive .includepath</h4>
  256. <div class="paragraph"><p>By default, any file that is included from within the source file must
  257. either be a single filename or a complete absolute path. With the directive
  258. .includepath you can set an additional include path . Furthermore you can
  259. set as many include paths as you want. Be sure not no use same filename
  260. in separate includes, because then it is no longer clear which one avra
  261. should take.</p></div>
  262. </div>
  263. <h2 id="_using_include_files">Using include files</h2>
  264. <div class="sectionbody">
  265. <div class="paragraph"><p>To avoid multiple inclusions of include files, you may use some pre-
  266. processor directives. See example file stack.asm that is being included
  267. into the main programm file as well as in other include files.</p></div>
  268. <div class="literalblock">
  269. <div class="content">
  270. <pre><tt>.ifndef _STACK_ASM_
  271. .define _STACK_ASM_</tt></pre>
  272. </div></div>
  273. <div class="literalblock">
  274. <div class="content">
  275. <pre><tt>.include "include/config.inc"</tt></pre>
  276. </div></div>
  277. <div class="literalblock">
  278. <div class="content">
  279. <pre><tt>; *** stack macro ***</tt></pre>
  280. </div></div>
  281. <div class="literalblock">
  282. <div class="content">
  283. <pre><tt>.dseg
  284. m_stack:    .byte __stack_size__
  285. .cseg</tt></pre>
  286. </div></div>
  287. <div class="literalblock">
  288. <div class="content">
  289. <pre><tt>.macro      stack_setup
  290.     load    [v:w,m_stack + __stack_size__]
  291.     outp    [SPREG,v:w]
  292. .endm</tt></pre>
  293. </div></div>
  294. <div class="literalblock">
  295. <div class="content">
  296. <pre><tt>.endif ; avoid multiple inclusion of stack.asm</tt></pre>
  297. </div></div>
  298. <h3 id="_using_build_date_meta_tags">Using build date meta tags</h3><div style="clear:left"></div>
  299. <div class="paragraph"><p>If you like to implement compiler build time and date into your
  300. program, you can make use of some sepcial tags that avra supports.</p></div>
  301. <div class="literalblock">
  302. <div class="content">
  303. <pre><tt>%MINUTE%  is being replaced by the current minute (00-59)
  304. %HOUR%    is being replaced by the current hour (00-23)
  305. %DAY%     is being replaced by the current day of month (01-31)
  306. %MONTH%   is being replaced by the current month (01-12)
  307. %YEAR%    is being replaced by the current year (2004-9999)</tt></pre>
  308. </div></div>
  309. <div class="literalblock">
  310. <div class="content">
  311. <pre><tt>buildtime: .db "Release date %DAY%.%MONTH%.%YEAR% %HOUR%:%MINUTE%"</tt></pre>
  312. </div></div>
  313. <div class="paragraph"><p>This line will then assembled by avra into:</p></div>
  314. <div class="literalblock">
  315. <div class="content">
  316. <pre><tt>buildtime: .db "Release date 10.05.2004 19:54"</tt></pre>
  317. </div></div>
  318. <div class="paragraph"><p>You may also create a self defined serial number with meta tags:</p></div>
  319. <div class="literalblock">
  320. <div class="content">
  321. <pre><tt>.define serialnumber %DAY% + %MONTH%*31 + (%YEAR% - 2000) *31*12</tt></pre>
  322. </div></div>
  323. <div class="paragraph"><p>The %TAG% is translated before any other parsing happens. The real
  324. output can be found in the list file.</p></div>
  325. </div>
  326. <h2 id="_macro_features">Macro features</h2>
  327. <div class="sectionbody">
  328. <div class="paragraph"><p>Sometimes you have to work with 16 bit or greater variables stored
  329. in 8 bit registers. The enhanced macro support allows you to write short
  330. and flexible macros that simplify access to big variables. The extended
  331. mode is active, as soon as you use parenthesis like this "[ ]" to wrap
  332. macro parameters.</p></div>
  333. <h3 id="_auto_type_conversion_for_macros">Auto type conversion for macros</h3><div style="clear:left"></div>
  334. <div class="paragraph"><p>Values representing more than 8 Bits are usualy kept in a set of byte
  335. wide registers. To simplify 16 Bit or greater operations, I added a new
  336. language definitions. Words can be written as r16:r17, whereas register
  337. r16 contains the higher part and register r17 the lower part of this
  338. 16 Bit value.</p></div>
  339. <h4 id="_macro_data_types">Macro data types</h4>
  340. <div class="paragraph"><p>There are 3 data types that can be used. They will be added as character
  341. separated by one underline character.</p></div>
  342. <div class="literalblock">
  343. <div class="content">
  344. <pre><tt>immediate values  _i
  345. registers         _8,_16,_24,_32,_40,_48,_56,_64
  346. void parameter    _v</tt></pre>
  347. </div></div>
  348. <div class="paragraph"><p>16 Bit Source and Destionation registers <em>dst</em> and <em>src</em></p></div>
  349. <div class="literalblock">
  350. <div class="content">
  351. <pre><tt>src = YH:YL
  352. dst = ZH:ZL</tt></pre>
  353. </div></div>
  354. <div class="paragraph"><p>Within the parenthesis, the two words src and dst are interpreted as YH:YL
  355. and ZH:ZL. Normal code outside of the macro parameter parenthesis can
  356. still make use of these special key words "src" and "dst".</p></div>
  357. <h4 id="_examples_for_automatic_type_conversion">Examples for automatic type conversion</h4>
  358. <div class="paragraph"><p>To simplify the parameters in the demonstration below, we need to
  359. redefine some registers.</p></div>
  360. <div class="literalblock">
  361. <div class="content">
  362. <pre><tt>.def    a = r16   ; general purpose registers
  363. .def    b = r17
  364. .def    c = r18
  365. .def    d = r19</tt></pre>
  366. </div></div>
  367. <div class="literalblock">
  368. <div class="content">
  369. <pre><tt>.def    w = r20   ; working register
  370. .def    v = r21   ; working register</tt></pre>
  371. </div></div>
  372. <div class="paragraph"><p>If we substract 16 Bit values stored in a, higher byte and b, lower byte
  373. with that in c:d, we usually have to use the following command sequence:</p></div>
  374. <div class="literalblock">
  375. <div class="content">
  376. <pre><tt>sub     b,d
  377. sbc     a,c</tt></pre>
  378. </div></div>
  379. <div class="paragraph"><p>Now we can do the following steps to simplify 16 or more Bit manipulations</p></div>
  380. <div class="literalblock">
  381. <div class="content">
  382. <pre><tt>.macro  subs
  383. .message "no parameters specified"
  384. .endm</tt></pre>
  385. </div></div>
  386. <div class="literalblock">
  387. <div class="content">
  388. <pre><tt>.macro  subs_16_16
  389. sub     @1,@3
  390. sbc     @0,@2
  391. .endm</tt></pre>
  392. </div></div>
  393. <div class="literalblock">
  394. <div class="content">
  395. <pre><tt>.macro  subs_16_8
  396. sub     @1,@2
  397. sbci    @0,0
  398. .endm</tt></pre>
  399. </div></div>
  400. <div class="literalblock">
  401. <div class="content">
  402. <pre><tt>;now we can write a 16 Bit subraction as:</tt></pre>
  403. </div></div>
  404. <div class="literalblock">
  405. <div class="content">
  406. <pre><tt>subs    [a:b,c:d]</tt></pre>
  407. </div></div>
  408. <div class="literalblock">
  409. <div class="content">
  410. <pre><tt>;or for calculating 16 minus 8 Bit</tt></pre>
  411. </div></div>
  412. <div class="literalblock">
  413. <div class="content">
  414. <pre><tt>subs    [a:b,c]</tt></pre>
  415. </div></div>
  416. <h3 id="_overloading_macros">Overloading macros</h3><div style="clear:left"></div>
  417. <div class="paragraph"><p>Like in you are used to C functions, you can write macros for different
  418. parameter lists. If you would like to have a versatile macro, you can
  419. specify a unique macro for each parameter situation. See the next sample.</p></div>
  420. <div class="literalblock">
  421. <div class="content">
  422. <pre><tt>.macro  load</tt></pre>
  423. </div></div>
  424. <div class="literalblock">
  425. <div class="content">
  426. <pre><tt>; this message is shown if you use the macro within your code
  427. ; specifying no parameters. If your macro allows the case where
  428. ; no parameters are given, exchange .message with your code.</tt></pre>
  429. </div></div>
  430. <div class="literalblock">
  431. <div class="content">
  432. <pre><tt>.message "no parameters specified"
  433. .endm</tt></pre>
  434. </div></div>
  435. <div class="literalblock">
  436. <div class="content">
  437. <pre><tt>; Here we define the macro "load" for the case it is being used
  438. ; with two registers as first parameter and a immediate (constant)
  439. ; value as second parameter.</tt></pre>
  440. </div></div>
  441. <div class="literalblock">
  442. <div class="content">
  443. <pre><tt>.macro  load_16_i
  444. ldi     @0,high(@2)
  445. ldi     @1,low(@2)
  446. .endm</tt></pre>
  447. </div></div>
  448. <div class="literalblock">
  449. <div class="content">
  450. <pre><tt>; the same case, but now with a 32 bit register value as first
  451. ; parameter</tt></pre>
  452. </div></div>
  453. <div class="literalblock">
  454. <div class="content">
  455. <pre><tt>.macro  load_32_i
  456. ldi     @0,BYTE4(@4)
  457. ldi     @1,BYTE3(@4)
  458. ldi     @2,high(@4)
  459. ldi     @3,low(@4)
  460. .endm</tt></pre>
  461. </div></div>
  462. <div class="literalblock">
  463. <div class="content">
  464. <pre><tt>; Now let's see how these macros are being used in the code</tt></pre>
  465. </div></div>
  466. <div class="literalblock">
  467. <div class="content">
  468. <pre><tt>load    [a:b,15]     ;uses macro load_16_i to load immediate</tt></pre>
  469. </div></div>
  470. <div class="literalblock">
  471. <div class="content">
  472. <pre><tt>load    [a:b:c:d,15] ;uses macro load_32_i to load immediate</tt></pre>
  473. </div></div>
  474. <h3 id="_more_examples">More examples</h3><div style="clear:left"></div>
  475. <div class="literalblock">
  476. <div class="content">
  477. <pre><tt>.dseg
  478. counter  .byte 2
  479. .cseg</tt></pre>
  480. </div></div>
  481. <div class="literalblock">
  482. <div class="content">
  483. <pre><tt>.macro   poke
  484. .message "no parameters"
  485. .endm</tt></pre>
  486. </div></div>
  487. <div class="literalblock">
  488. <div class="content">
  489. <pre><tt>.macro   poke_i_16_i
  490. ldi      @1,high(@3)
  491. sts      @0+0,@1
  492. ldi      @2,low(@3)
  493. sts      @0+1,@2
  494. .endm</tt></pre>
  495. </div></div>
  496. <div class="literalblock">
  497. <div class="content">
  498. <pre><tt>.macro   poke_i_i
  499. ldi      w,@1
  500. sts      @0+0,w
  501. .endm</tt></pre>
  502. </div></div>
  503. <div class="literalblock">
  504. <div class="content">
  505. <pre><tt>.macro   poke_i_v_i
  506. ldi      w,high(@3)
  507. sts      @0+0,w
  508. ldi      w,low(@3)
  509. sts      @0+1,w
  510. .endm</tt></pre>
  511. </div></div>
  512. <div class="literalblock">
  513. <div class="content">
  514. <pre><tt>.macro   poke_i_v_v_v_i
  515. ldi      w,high(@3)
  516. sts      @0+0,w
  517. ldi      w,low(@3)
  518. sts      @0+1,w
  519. ldi      w,BYTE3(@3)
  520. sts      @0+2,w
  521. ldi      w,BYTE4(@3)
  522. sts      @0+3,w
  523. .endm</tt></pre>
  524. </div></div>
  525. <div class="literalblock">
  526. <div class="content">
  527. <pre><tt>; this writes '9999' into the memory at 'counter'
  528. ; uses only the working register for transfering the values.</tt></pre>
  529. </div></div>
  530. <div class="literalblock">
  531. <div class="content">
  532. <pre><tt>poke     [counter,w:w,9999]</tt></pre>
  533. </div></div>
  534. <div class="literalblock">
  535. <div class="content">
  536. <pre><tt>; works same as above, but the transferred value '9999' is also
  537. ; kept in the pair of register a:b</tt></pre>
  538. </div></div>
  539. <div class="literalblock">
  540. <div class="content">
  541. <pre><tt>poke     [counter,a:b,9999]</tt></pre>
  542. </div></div>
  543. <div class="literalblock">
  544. <div class="content">
  545. <pre><tt>; in my design 'w' is always working reg. which implies that
  546. ; it cannot be used for normal variables. The following example
  547. ; uses poke_i_i because the parameter contains two immediate values.</tt></pre>
  548. </div></div>
  549. <div class="literalblock">
  550. <div class="content">
  551. <pre><tt>poke     [counter,9999] ;uses poke_i_i</tt></pre>
  552. </div></div>
  553. <div class="literalblock">
  554. <div class="content">
  555. <pre><tt>; to be able to choose between a 8,16 or 32 Bit operation, you just
  556. ; add a void parameter.</tt></pre>
  557. </div></div>
  558. <div class="literalblock">
  559. <div class="content">
  560. <pre><tt>poke     [counter,,9999] ;uses poke_i_v_i</tt></pre>
  561. </div></div>
  562. <div class="literalblock">
  563. <div class="content">
  564. <pre><tt>; and the same for 32 Bit pokes</tt></pre>
  565. </div></div>
  566. <div class="literalblock">
  567. <div class="content">
  568. <pre><tt>poke     [counter,,,,9999] ;uses poke_i_v_v_v_i</tt></pre>
  569. </div></div>
  570. <h3 id="_loops_within_macros">Loops within macros</h3><div style="clear:left"></div>
  571. <div class="paragraph"><p>One problem you may have experienced, is that labels defined within macros
  572. are defined twice if you call the macro for example two times. Now you can
  573. use labels for macro loops. Loops within macros must end with <em>_%</em>. the
  574. "%" symbol is replaced by a running number.</p></div>
  575. <h4 id="_loop_example">Loop example</h4>
  576. <div class="literalblock">
  577. <div class="content">
  578. <pre><tt>; Definition of the macro</tt></pre>
  579. </div></div>
  580. <div class="literalblock">
  581. <div class="content">
  582. <pre><tt>.macro   write_8_8
  583. write_%:
  584.     st      Z+,@0
  585.     dec     @1
  586.     brne    write_%
  587. .endm</tt></pre>
  588. </div></div>
  589. <div class="literalblock">
  590. <div class="content">
  591. <pre><tt>; Use in user code</tt></pre>
  592. </div></div>
  593. <div class="literalblock">
  594. <div class="content">
  595. <pre><tt>write   [a,b]
  596. write   [c,d]</tt></pre>
  597. </div></div>
  598. <div class="literalblock">
  599. <div class="content">
  600. <pre><tt>; After assembling this code, the result looks like this</tt></pre>
  601. </div></div>
  602. <div class="literalblock">
  603. <div class="content">
  604. <pre><tt>write_1:
  605.     st          Z+,a
  606.     dec         b
  607.     brne        write_1
  608. write_2:
  609.     st          Z+,c
  610.     dec         d
  611.     brne        write_2</tt></pre>
  612. </div></div>
  613. </div>
  614. <h2 id="_warnings_and_errors">Warnings and Errors</h2>
  615. <div class="sectionbody">
  616. <div class="paragraph"><p>Some errors and warnings may confuse you a little bit so we will try to
  617. clear some frequently asked questions about such cases.</p></div>
  618. <h3 id="_constant_out_of_range">Constant out of range</h3><div style="clear:left"></div>
  619. <div class="paragraph"><p>This warning occurs if a value exceeds the byte or word value of a assignment.
  620. Read the comment posted by Jim Galbraith:</p></div>
  621. <div class="paragraph"><p>The expression (~0x80) is a Bitwise Not operation.  This
  622. operator returns the input expression with all its bits
  623. inverted.  If 0x80 represents -128, then 0x7f, or +127
  624. should be ok.  If this is considered as a 32-bit expression
  625. (AVRA internal representation), then it appears to be more
  626. like oxffffffff-0x80 or 0xffffffff<sup>0x80.  The result would then
  627. be 0xffffff7f.  The assembler would then have to be told or it
  628. would have to decide, based on context, how much
  629. significance to assign to the higher bits.  I have also
  630. encountered such conditions with various assemblers,
  631. including AVRA.  To make sure the assembler does what I
  632. really want, I use a construct like 0xff-0x80 or 0xff</sup>0x80.
  633. This way the bit significance cannot extend beyond bit-7 and
  634. there cannot be any misunderstanding.</p></div>
  635. <h3 id="_can_8217_t_use_db_directive_in_data_segment">Can&#8217;t use .DB directive in data segment</h3><div style="clear:left"></div>
  636. <div class="paragraph"><div class="title">DB and .DW is only used to assign constant data in eeprom or code space.</div><p>The reason why using it within data segment is forbidden is, that you
  637. cannot set ram content at assembly time. The values must be programmed into
  638. ROM area and at boot read from ROM into RAM. This is up to the user code.
  639. You can only allocate memory for your variables using labels and the .byte
  640. directive.</p></div>
  641. <div class="literalblock">
  642. <div class="content">
  643. <pre><tt>.dseg
  644. my_string: .byte 15</tt></pre>
  645. </div></div>
  646. <h3 id="_byte_directive">BYTE directive</h3><div style="clear:left"></div>
  647. <div class="paragraph"><div class="title">BYTE directive can only be used in data segment (.DSEG)</div><p>This directive cannot be used in code or eeprom region because this only
  648. allocates memory without assgning distinct values to it. Please use .db
  649. or .dw instead.</p></div>
  650. <h3 id="_internal_assembler_error">Internal assembler error</h3><div style="clear:left"></div>
  651. <div class="paragraph"><p>If you get an "Internal assembler error" please contact the project maintainer
  652. by sending him a code example and a description of your working enviroment.</p></div>
  653. </div>
  654. <h2 id="_avra_internals">AVRA internals</h2>
  655. <div class="sectionbody">
  656. <div class="paragraph"><p>This section provides thoughts of the avra internal design. I have to admit
  657. that the code of avra is anything else than clean and optimized. To increase
  658. the code readability I will try to give you some standards that should improve
  659. quality. The following standards are similar to what GNU proposes.</p></div>
  660. <h3 id="_coding_standards">Coding standards</h3><div style="clear:left"></div>
  661. <div class="paragraph"><p>Tab space is always 2 spaces. The Tab character (ascii 9) is not used.
  662. if,while,for are always opened on the same line but closed on the next line.
  663. The closing bracket is in the same column as the first letter of the loop
  664. directive.</p></div>
  665. <div class="literalblock">
  666. <div class="content">
  667. <pre><tt>Example:</tt></pre>
  668. </div></div>
  669. <div class="listingblock">
  670. <div class="content">
  671. <pre><tt>    while(i &gt; 0) {
  672.     do_something();
  673.    }</tt></pre>
  674. </div></div>
  675. </div>
  676. <h2 id="_credits">Credits</h2>
  677. <div class="sectionbody">
  678. <div class="paragraph"><p>We would like to thank the following people for giving contributions,
  679. patches and bug reports, as well as suggestions and new ideas.</p></div>
  680. <div class="listingblock">
  681. <div class="content">
  682. <pre><tt>      Jon Anders Haugum (project founder)
  683.      Burkhard Arenfeld (release 1.2.0)
  684.      Tobias Weber (old maintainer)
  685.      Jerry Jacobs (release 1.3.0)
  686.      Bernt Hembre
  687.      Nils Strøm
  688.      Roberto Biancardi
  689.      Qwerty Jones
  690.      Ben Hitchcock (Maker of the mac port)
  691.      Daniel Drotos
  692.      Laurence Boyd II
  693.      Varuzhan Danielyan
  694.      Laurence Turner
  695.      Eugene R. O'Bryan
  696.       Dmitry Dicky
  697.       Bob Harris (Maker of coff support)
  698.       Tobias Weber (enhanced macro support)
  699.       Lesha Bogdanow
  700.       Jim Galbraith
  701.       Mark Brinicombe
  702.       Igor Nikolayenko
  703.       Peter Hettkamp
  704.       Herb Poppe
  705.       David Burke
  706.       Alexey Pavluchenko
  707.       Alan Probandt
  708.       Mariusz Matuszek
  709.       Arne Rossius
  710.       Marti Tichacek
  711.       Patrick Parity
  712.       Johannes Overmann
  713.       Roland Riegel
  714.       Peter Katzmann
  715.       Donald D. Davis</tt></pre>
  716. </div></div>
  717. <div class="paragraph"><p>And all the anonymous people who submitted patches!</p></div>
  718. <div class="paragraph"><p>Thank you for your work and support.</p></div>
  719. </div>
  720. <h2 id="_references">References</h2>
  721. <div class="sectionbody">
  722. <div class="literalblock">
  723. <div class="content">
  724. <pre><tt>http://www.suprafluid.com/avra
  725. http://www.avrfreaks.de
  726. http://www.atmel.com</tt></pre>
  727. </div></div>
  728. </div>
  729. </div>
  730. <div id="footnotes"><hr /></div>
  731. <div id="footer">
  732. <div id="footer-text">
  733. Version 1.3.0<br />
  734. Last updated 2010-06-28 16:04:26 CEST
  735. </div>
  736. <div id="footer-badges">
  737. <a href="http://validator.w3.org/check?uri=referer">
  738.   <img style="border:0;width:88px;height:31px"
  739.     src="http://www.w3.org/Icons/valid-xhtml11-blue"
  740.     alt="Valid XHTML 1.1" height="31" width="88" />
  741. </a>
  742. <a href="http://jigsaw.w3.org/css-validator/">
  743.   <img style="border:0;width:88px;height:31px"
  744.     src="http://jigsaw.w3.org/css-validator/images/vcss-blue"
  745.     alt="Valid CSS!" />
  746. </a>
  747. <a href="http://www.mozilla.org/products/firefox/">
  748.   <img style="border:none; width:110px; height:32px;"
  749.        src="http://www.spreadfirefox.com/community/images/affiliates/Buttons/110x32/safer.gif"
  750.        alt="Get Firefox!" />
  751. </a>
  752. </div>
  753. </div>
  754. </div>
  755. </td>
  756. </tr>
  757. </table>
  758. </body>
  759. </html>
  760.