* doc/sdccman.lyx: updated "configure options" for autoconf 2.6
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \pdfoptionpdfminorversion=3
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
11   pdfpagemode=UseOutlines,
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.6.4
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargeted for other microprocessors, support for Microchip PIC,
146  Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargetable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.295
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE 754
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 1.175494351E-38, 
506 \family roman 
507 \series medium 
508 \shape up 
509 \size normal 
510 \emph off 
511 \bar no 
512 \noun off 
513 \color none
514 3.402823466E+38
515 \end_inset 
516 </cell>
517 </row>
518 <row topline="true" bottomline="true">
519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
520 \begin_inset Text
521
522 \layout Standard
523
524 pointer
525 \end_inset 
526 </cell>
527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_inset Text
529
530 \layout Standard
531
532 1, 2, 3 or 4 bytes
533 \end_inset 
534 </cell>
535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
536 \begin_inset Text
537
538 \layout Standard
539
540 generic
541 \end_inset 
542 </cell>
543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_inset Text
545
546 \layout Standard
547
548 \end_inset 
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
551 \begin_inset Text
552
553 \layout Standard
554
555 \end_inset 
556 </cell>
557 </row>
558 </lyxtabular>
559
560 \end_inset 
561
562
563 \newline 
564 The compiler also allows 
565 \emph on 
566 inline assembler code
567 \emph default 
568  to be embedded anywhere in a function.
569  In addition, routines developed in assembly can also be called.
570 \newline 
571
572 \newline 
573 SDCC also provides an option (-
574 \begin_inset ERT
575 status Collapsed
576
577 \layout Standard
578
579 \backslash 
580 /
581 \end_inset 
582
583 -cyclomatic) to report the relative complexity of a function.
584  These functions can then be further optimized, or hand coded in assembly
585  if needed.
586  
587 \newline 
588
589 \newline 
590 SDCC also comes with a companion source level debugger SDCDB, the debugger
591  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
592 \newline 
593
594 \newline 
595 The latest version can be downloaded from 
596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
597
598 \end_inset 
599
600 .
601
602 \series bold 
603  
604 \series default 
605 \emph on 
606 Please note: the compiler will probably always be some steps ahead of this
607  documentation
608 \series bold 
609 \emph default 
610
611 \begin_inset LatexCommand \index{Status of documentation}
612
613 \end_inset 
614
615
616 \begin_inset Foot
617 collapsed false
618
619 \layout Standard
620
621 Obviously this has pros and cons
622 \end_inset 
623
624 .
625 \layout Section
626
627 Open Source
628 \layout Standard
629
630 All packages used in this compiler system are 
631 \emph on 
632 open source
633 \emph default 
634  and 
635 \emph on 
636 freeware
637 \emph default 
638 ; source code for all the sub-packages (pre-processor, assemblers, linkers
639  etc) is distributed with the package.
640  This documentation is maintained using a freeware word processor (LyX).
641 \newline 
642 This program is free software; you can redistribute it and/or modify it
643  under the terms of the GNU General Public License
644 \begin_inset LatexCommand \index{GNU General Public License, GPL}
645
646 \end_inset 
647
648  as published by the Free Software Foundation; either version 2, or (at
649  your option) any later version.
650  This program is distributed in the hope that it will be useful, but WITHOUT
651  ANY WARRANTY; without even the implied warranty
652 \begin_inset LatexCommand \index{warranty}
653
654 \end_inset 
655
656  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
657  See the GNU General Public License for more details.
658  You should have received a copy of the GNU General Public License along
659  with this program; if not, write to the Free Software Foundation, 59 Temple
660  Place - Suite 330, Boston, MA 02111-1307, USA.
661  In other words, you are welcome to use, share and improve this program.
662  You are forbidden to forbid anyone else to use, share and improve what
663  you give them.
664  Help stamp out software-hoarding! 
665 \layout Section
666
667 Typographic conventions
668 \begin_inset LatexCommand \index{Typographic conventions}
669
670 \end_inset 
671
672
673 \layout Standard
674
675 Throughout this manual, we will use the following convention.
676  Commands you have to type in are printed in 
677 \family sans 
678 \series bold 
679 "sans serif"
680 \series default 
681 .
682
683 \family default 
684  Code samples are printed in 
685 \family typewriter 
686 typewriter font.
687
688 \family default 
689  Interesting items and new terms are printed in 
690 \emph on 
691 italic.
692 \layout Section
693
694 Compatibility
695 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
696
697 \end_inset 
698
699  with previous versions
700 \begin_inset LatexCommand \index{Compatibility with previous versions}
701
702 \end_inset 
703
704
705 \layout Standard
706
707 This version has numerous bug fixes compared with the previous version.
708  But we also introduced some incompatibilities with older versions.
709  Not just for the fun of it, but to make the compiler more stable, efficient
710  and ANSI compliant
711 \begin_inset LatexCommand \index{ANSI-compliance}
712
713 \end_inset 
714
715  (see section 
716 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
717
718 \end_inset 
719
720  for ANSI-Compliance).
721  
722 \newline 
723
724 \layout Itemize
725
726 short is now equivalent to int (16 bits), it used to be equivalent to char
727  (8 bits) which is not ANSI compliant.
728 \layout Itemize
729
730 the default directory for gcc-builds where include, library and documentation
731  files are stored is now in /usr/local/share.
732 \layout Itemize
733
734 char type parameters to vararg
735 \begin_inset LatexCommand \index{vararg, va\_arg}
736
737 \end_inset 
738
739  functions are casted to int unless explicitly casted
740 \begin_inset Marginal
741 collapsed true
742
743 \layout Standard
744
745
746 \series bold 
747 \SpecialChar ~
748 !
749 \end_inset 
750
751 , e.g.: 
752 \newline 
753
754 \family typewriter 
755 \SpecialChar ~
756 \SpecialChar ~
757 char a=3;
758 \newline 
759 \SpecialChar ~
760 \SpecialChar ~
761 printf ("%d %c
762 \backslash 
763 n", a, (char)a);
764 \family default 
765
766 \newline 
767  will push a as an int and as a char resp.
768 \layout Itemize
769
770 option -
771 \begin_inset ERT
772 status Collapsed
773
774 \layout Standard
775
776 \backslash 
777 /
778 \end_inset 
779
780 -regextend has been removed.
781 \layout Itemize
782
783 option -
784 \begin_inset ERT
785 status Collapsed
786
787 \layout Standard
788
789 \backslash 
790 /
791 \end_inset 
792
793 -noregparms has been removed.
794 \layout Itemize
795
796 option -
797 \begin_inset ERT
798 status Collapsed
799
800 \layout Standard
801
802 \backslash 
803 /
804 \end_inset 
805
806 -stack-after-data has been removed.
807 \layout Itemize
808
809 bit
810 \begin_inset LatexCommand \index{bit}
811
812 \end_inset 
813
814  and sbit
815 \begin_inset LatexCommand \index{sbit}
816
817 \end_inset 
818
819
820 \begin_inset LatexCommand \index{\_\_sbit}
821
822 \end_inset 
823
824  types now consistently behave like the C99 _Bool type with respect to type
825  conversion
826 \begin_inset LatexCommand \index{type conversion}
827
828 \end_inset 
829
830
831 \begin_inset LatexCommand \index{type promotion}
832
833 \end_inset 
834
835 .
836  The most common incompatibility resulting from this change is related to
837  bit toggling
838 \begin_inset LatexCommand \index{Bit toggling}
839
840 \end_inset 
841
842  idioms, e.g.:
843 \newline 
844
845 \family typewriter 
846 \SpecialChar ~
847 \SpecialChar ~
848 bit b;
849 \newline 
850 \SpecialChar ~
851 \SpecialChar ~
852 b = ~
853 \begin_inset LatexCommand \index{\~\/ Operator}
854
855 \end_inset 
856
857 b; /* equivalent to b=1 instead of toggling b */
858 \begin_inset Marginal
859 collapsed true
860
861 \layout Standard
862
863
864 \series bold 
865 \SpecialChar ~
866 !
867 \end_inset 
868
869
870 \newline 
871 \SpecialChar ~
872 \SpecialChar ~
873 b = !b; /* toggles b */
874 \newline 
875
876 \family default 
877 In previous versions, both forms would have toggled the bit.
878 \layout Standard
879
880
881 \emph on 
882 <pending: more incompatibilities?>
883 \layout Section
884
885 System Requirements
886 \layout Standard
887
888 What do you need before you start installation of SDCC? A computer, and
889  a desire to compute.
890  The preferred method of installation is to compile SDCC from source using
891  GNU gcc and make.
892  For Windows some pre-compiled binary distributions are available for your
893  convenience.
894  You should have some experience with command line tools and compiler use.
895 \layout Section
896
897 Other Resources
898 \layout Standard
899
900 The SDCC home page at 
901 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
902
903 \end_inset 
904
905  is a great place to find distribution sets.
906  You can also find links to the user mailing lists that offer help or discuss
907  SDCC with other SDCC users.
908  Web links to other SDCC related sites can also be found here.
909  This document can be found in the DOC directory of the source package as
910  a text or HTML file.
911  A pdf version of this document is available at 
912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
913
914 \end_inset 
915
916 .
917  Some of the other tools (simulator and assembler) included with SDCC contain
918  their own documentation and can be found in the source distribution.
919  If you want the latest unreleased software, the complete source package
920  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
921 /trunk/sdcc.
922 \layout Section
923
924 Wishes for the future
925 \layout Standard
926
927 There are (and always will be) some things that could be done.
928  Here are some I can think of:
929 \newline 
930
931 \layout Standard
932
933
934 \family typewriter 
935 char KernelFunction3(char p) at 0x340;
936 \newline 
937
938 \layout Standard
939
940
941 \family typewriter 
942 better code banking
943 \begin_inset LatexCommand \index{code banking (limited support)}
944
945 \end_inset 
946
947  support for mcs51
948 \newline 
949
950 \newline 
951
952 \family default 
953 If you can think of some more, please see the section 
954 \begin_inset LatexCommand \ref{sub:Requesting-Features}
955
956 \end_inset 
957
958  about filing feature requests
959 \begin_inset LatexCommand \index{Requesting features}
960
961 \end_inset 
962
963
964 \begin_inset LatexCommand \index{Feature request}
965
966 \end_inset 
967
968 .
969 \newline 
970
971 \layout Chapter
972
973 Installing SDCC
974 \begin_inset LatexCommand \index{Installation}
975
976 \end_inset 
977
978
979 \layout Standard
980
981 For most users it is sufficient to skip to either section 
982 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
983
984 \end_inset 
985
986  (Unix) or section 
987 \begin_inset LatexCommand \ref{sub:Windows-Install}
988
989 \end_inset 
990
991  (Windows).
992  More detailed instructions follow below.
993 \layout Section
994
995 Configure Options
996 \begin_inset LatexCommand \index{Options SDCC configuration}
997
998 \end_inset 
999
1000
1001 \layout Standard
1002
1003 The install paths, search paths and other options are defined when running
1004  'configure'.
1005  The defaults can be overridden by:
1006 \layout List
1007 \labelwidthstring 00.00.0000
1008
1009 -
1010 \begin_inset ERT
1011 status Collapsed
1012
1013 \layout Standard
1014
1015 \backslash 
1016 /
1017 \end_inset 
1018
1019 -prefix see table below
1020 \layout List
1021 \labelwidthstring 00.00.0000
1022
1023 -
1024 \begin_inset ERT
1025 status Collapsed
1026
1027 \layout Standard
1028
1029 \backslash 
1030 /
1031 \end_inset 
1032
1033 -exec_prefix see table below
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036
1037 -
1038 \begin_inset ERT
1039 status Collapsed
1040
1041 \layout Standard
1042
1043 \backslash 
1044 /
1045 \end_inset 
1046
1047 -bindir see table below
1048 \layout List
1049 \labelwidthstring 00.00.0000
1050
1051 -
1052 \begin_inset ERT
1053 status Collapsed
1054
1055 \layout Standard
1056
1057 \backslash 
1058 /
1059 \end_inset 
1060
1061 -datadir see table below
1062 \layout List
1063 \labelwidthstring 00.00.0000
1064
1065 -
1066 \begin_inset ERT
1067 status Collapsed
1068
1069 \layout Standard
1070
1071 \backslash 
1072 /
1073 \end_inset 
1074
1075 -datarootdir see table below
1076 \newline 
1077
1078 \layout List
1079 \labelwidthstring 00.00.0000
1080
1081 \SpecialChar ~
1082 \SpecialChar ~
1083 docdir environment variable, see table below
1084 \layout List
1085 \labelwidthstring 00.00.0000
1086
1087 \SpecialChar ~
1088 \SpecialChar ~
1089 include_dir_suffix environment variable, see table below
1090 \layout List
1091 \labelwidthstring 00.00.0000
1092
1093 \SpecialChar ~
1094 \SpecialChar ~
1095 lib_dir_suffix environment variable, see table below
1096 \layout List
1097 \labelwidthstring 00.00.0000
1098
1099 \SpecialChar ~
1100 \SpecialChar ~
1101 sdccconf_h_dir_separator environment variable, either / or 
1102 \backslash 
1103
1104 \backslash 
1105  makes sense here.
1106  This character will only be used in sdccconf.h; don't forget it's a C-header,
1107  therefore a double-backslash is needed there.
1108 \newline 
1109
1110 \layout List
1111 \labelwidthstring 00.00.0000
1112
1113 -
1114 \begin_inset ERT
1115 status Collapsed
1116
1117 \layout Standard
1118
1119 \backslash 
1120 /
1121 \end_inset 
1122
1123 -disable-mcs51-port Excludes the Intel mcs51 port
1124 \layout List
1125 \labelwidthstring 00.00.0000
1126
1127 -
1128 \begin_inset ERT
1129 status Collapsed
1130
1131 \layout Standard
1132
1133 \backslash 
1134 /
1135 \end_inset 
1136
1137 -disable-gbz80-port Excludes the Gameboy gbz80 port
1138 \layout List
1139 \labelwidthstring 00.00.0000
1140
1141 -
1142 \begin_inset ERT
1143 status Collapsed
1144
1145 \layout Standard
1146
1147 \backslash 
1148 /
1149 \end_inset 
1150
1151 -disable-z80-port Excludes the z80 port
1152 \layout List
1153 \labelwidthstring 00.00.0000
1154
1155 -
1156 \begin_inset ERT
1157 status Collapsed
1158
1159 \layout Standard
1160
1161 \backslash 
1162 /
1163 \end_inset 
1164
1165 -disable-avr-port Excludes the AVR port
1166 \layout List
1167 \labelwidthstring 00.00.0000
1168
1169 -
1170 \begin_inset ERT
1171 status Collapsed
1172
1173 \layout Standard
1174
1175 \backslash 
1176 /
1177 \end_inset 
1178
1179 -disable-ds390-port Excludes the DS390 port
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182
1183 -
1184 \begin_inset ERT
1185 status Collapsed
1186
1187 \layout Standard
1188
1189 \backslash 
1190 /
1191 \end_inset 
1192
1193 -disable-hc08-port Excludes the HC08 port
1194 \layout List
1195 \labelwidthstring 00.00.0000
1196
1197 -
1198 \begin_inset ERT
1199 status Collapsed
1200
1201 \layout Standard
1202
1203 \backslash 
1204 /
1205 \end_inset 
1206
1207 -disable-pic-port Excludes the PIC port
1208 \layout List
1209 \labelwidthstring 00.00.0000
1210
1211 -
1212 \begin_inset ERT
1213 status Collapsed
1214
1215 \layout Standard
1216
1217 \backslash 
1218 /
1219 \end_inset 
1220
1221 -disable-xa51-port Excludes the XA51 port
1222 \layout List
1223 \labelwidthstring 00.00.0000
1224
1225 -
1226 \begin_inset ERT
1227 status Collapsed
1228
1229 \layout Standard
1230
1231 \backslash 
1232 /
1233 \end_inset 
1234
1235 -disable-ucsim Disables configuring and building of ucsim
1236 \layout List
1237 \labelwidthstring 00.00.0000
1238
1239 -
1240 \begin_inset ERT
1241 status Collapsed
1242
1243 \layout Standard
1244
1245 \backslash 
1246 /
1247 \end_inset 
1248
1249 -disable-device-lib Disables automatically building device libraries
1250 \layout List
1251 \labelwidthstring 00.00.0000
1252
1253 -
1254 \begin_inset ERT
1255 status Collapsed
1256
1257 \layout Standard
1258
1259 \backslash 
1260 /
1261 \end_inset 
1262
1263 -disable-packihx Disables building packihx
1264 \newline 
1265
1266 \layout List
1267 \labelwidthstring 00.00.0000
1268
1269 -
1270 \begin_inset ERT
1271 status Collapsed
1272
1273 \layout Standard
1274
1275 \backslash 
1276 /
1277 \end_inset 
1278
1279 -enable-doc Build pdf, html and txt files from the lyx sources
1280 \layout List
1281 \labelwidthstring 00.00.0000
1282
1283 -
1284 \begin_inset ERT
1285 status Collapsed
1286
1287 \layout Standard
1288
1289 \backslash 
1290 /
1291 \end_inset 
1292
1293 -enable-libgc Use the Bohem memory allocator.
1294  Lower runtime footprint.
1295 \layout Standard
1296
1297 Furthermore the environment variables CC, CFLAGS, ...
1298  the tools and their arguments can be influenced.
1299  Please see `configure -
1300 \begin_inset ERT
1301 status Collapsed
1302
1303 \layout Standard
1304
1305 \backslash 
1306 /
1307 \end_inset 
1308
1309 -help` and the man/info pages of `configure` for details.
1310 \newline 
1311
1312 \newline 
1313 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1314  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1315 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1316  At the moment it's not possible to change the default settings (it was
1317  simply never required).
1318 \newline 
1319
1320 \newline 
1321 These configure options are compiled into the binaries, and can only be
1322  changed by rerunning 'configure' and recompiling SDCC.
1323  The configure options are written in 
1324 \emph on 
1325 italics
1326 \emph default 
1327  to distinguish them from run time environment variables (see section search
1328  paths).
1329 \newline 
1330
1331 \newline 
1332 The settings for 
1333 \begin_inset Quotes sld
1334 \end_inset 
1335
1336 Win32 builds
1337 \begin_inset Quotes srd
1338 \end_inset 
1339
1340  are used by the SDCC team to build the official Win32 binaries.
1341  The SDCC team uses Mingw32 to build the official Windows binaries, because
1342  it's
1343 \layout Enumerate
1344
1345 open source, 
1346 \layout Enumerate
1347
1348 a gcc compiler and last but not least
1349 \layout Enumerate
1350
1351 the binaries can be built by cross compiling on Sourceforge's compile farm.
1352 \layout Standard
1353
1354 See the examples, how to pass the Win32 settings to 'configure'.
1355  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1356  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1357  for Win32.
1358 \newline 
1359
1360 \newline 
1361 These defaults are:
1362 \newline 
1363
1364 \layout Standard
1365 \align center 
1366
1367 \begin_inset  Tabular
1368 <lyxtabular version="3" rows="9" columns="3">
1369 <features>
1370 <column alignment="block" valignment="top" leftline="true" width="0in">
1371 <column alignment="block" valignment="top" leftline="true" width="0in">
1372 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1373 <row topline="true" bottomline="true">
1374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1375 \begin_inset Text
1376
1377 \layout Standard
1378
1379 Variable
1380 \end_inset 
1381 </cell>
1382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1383 \begin_inset Text
1384
1385 \layout Standard
1386
1387 default
1388 \end_inset 
1389 </cell>
1390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1391 \begin_inset Text
1392
1393 \layout Standard
1394
1395 Win32 builds
1396 \end_inset 
1397 </cell>
1398 </row>
1399 <row topline="true">
1400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1401 \begin_inset Text
1402
1403 \layout Standard
1404
1405
1406 \emph on 
1407 PREFIX
1408 \end_inset 
1409 </cell>
1410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1411 \begin_inset Text
1412
1413 \layout Standard
1414
1415 /usr/local
1416 \end_inset 
1417 </cell>
1418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1419 \begin_inset Text
1420
1421 \layout Standard
1422
1423
1424 \backslash 
1425 sdcc
1426 \end_inset 
1427 </cell>
1428 </row>
1429 <row topline="true">
1430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1431 \begin_inset Text
1432
1433 \layout Standard
1434
1435
1436 \emph on 
1437 EXEC_PREFIX
1438 \end_inset 
1439 </cell>
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1441 \begin_inset Text
1442
1443 \layout Standard
1444
1445
1446 \emph on 
1447 $PREFIX
1448 \end_inset 
1449 </cell>
1450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1451 \begin_inset Text
1452
1453 \layout Standard
1454
1455
1456 \emph on 
1457 $PREFIX
1458 \end_inset 
1459 </cell>
1460 </row>
1461 <row topline="true">
1462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1463 \begin_inset Text
1464
1465 \layout Standard
1466
1467
1468 \emph on 
1469 BINDIR
1470 \end_inset 
1471 </cell>
1472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1473 \begin_inset Text
1474
1475 \layout Standard
1476
1477
1478 \emph on 
1479 $EXEC_PREFIX
1480 \emph default 
1481 /bin
1482 \end_inset 
1483 </cell>
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1485 \begin_inset Text
1486
1487 \layout Standard
1488
1489
1490 \emph on 
1491 $EXEC_PREFIX
1492 \emph default 
1493
1494 \backslash 
1495 bin
1496 \end_inset 
1497 </cell>
1498 </row>
1499 <row topline="true">
1500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1501 \begin_inset Text
1502
1503 \layout Standard
1504
1505
1506 \emph on 
1507 DATADIR
1508 \end_inset 
1509 </cell>
1510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1511 \begin_inset Text
1512
1513 \layout Standard
1514
1515
1516 \emph on 
1517 $DATAROOTDIR
1518 \end_inset 
1519 </cell>
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1521 \begin_inset Text
1522
1523 \layout Standard
1524
1525
1526 \emph on 
1527 $DATAROOTDIR
1528 \end_inset 
1529 </cell>
1530 </row>
1531 <row topline="true">
1532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1533 \begin_inset Text
1534
1535 \layout Standard
1536
1537
1538 \emph on 
1539 DATAROOTDIR
1540 \end_inset 
1541 </cell>
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1543 \begin_inset Text
1544
1545 \layout Standard
1546
1547
1548 \emph on 
1549 $PREFIX
1550 \emph default 
1551 /share
1552 \end_inset 
1553 </cell>
1554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1555 \begin_inset Text
1556
1557 \layout Standard
1558
1559
1560 \emph on 
1561 $PREFIX
1562 \end_inset 
1563 </cell>
1564 </row>
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1567 \begin_inset Text
1568
1569 \layout Standard
1570
1571
1572 \emph on 
1573 DOCDIR
1574 \end_inset 
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581
1582 \emph on 
1583 $DATAROOTDIR
1584 \emph default 
1585 /sdcc/doc
1586 \end_inset 
1587 </cell>
1588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1589 \begin_inset Text
1590
1591 \layout Standard
1592
1593
1594 \emph on 
1595 $DATAROOTDIR
1596 \emph default 
1597
1598 \backslash 
1599 doc
1600 \end_inset 
1601 </cell>
1602 </row>
1603 <row topline="true">
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1605 \begin_inset Text
1606
1607 \layout Standard
1608
1609
1610 \emph on 
1611 INCLUDE_DIR_SUFFIX
1612 \end_inset 
1613 </cell>
1614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1615 \begin_inset Text
1616
1617 \layout Standard
1618
1619 sdcc/include
1620 \end_inset 
1621 </cell>
1622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1623 \begin_inset Text
1624
1625 \layout Standard
1626
1627 include
1628 \end_inset 
1629 </cell>
1630 </row>
1631 <row topline="true" bottomline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_inset Text
1634
1635 \layout Standard
1636
1637
1638 \emph on 
1639 LIB_DIR_SUFFIX
1640 \end_inset 
1641 </cell>
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1643 \begin_inset Text
1644
1645 \layout Standard
1646
1647 sdcc/lib
1648 \end_inset 
1649 </cell>
1650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1651 \begin_inset Text
1652
1653 \layout Standard
1654
1655 lib
1656 \end_inset 
1657 </cell>
1658 </row>
1659 </lyxtabular>
1660
1661 \end_inset 
1662
1663
1664 \newline 
1665
1666 \layout Standard
1667 \noindent 
1668 'configure' also computes relative paths.
1669  This is needed for full relocatability of a binary package and to complete
1670  search paths (see section search paths below):
1671 \newline 
1672  
1673 \layout Standard
1674 \align center 
1675
1676 \begin_inset  Tabular
1677 <lyxtabular version="3" rows="4" columns="3">
1678 <features>
1679 <column alignment="block" valignment="top" leftline="true" width="0in">
1680 <column alignment="block" valignment="top" leftline="true" width="0in">
1681 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1682 <row topline="true" bottomline="true">
1683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1684 \begin_inset Text
1685
1686 \layout Standard
1687
1688 Variable (computed)
1689 \end_inset 
1690 </cell>
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 \begin_inset Text
1693
1694 \layout Standard
1695
1696 default
1697 \end_inset 
1698 </cell>
1699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1700 \begin_inset Text
1701
1702 \layout Standard
1703
1704 Win32 builds
1705 \end_inset 
1706 </cell>
1707 </row>
1708 <row topline="true" bottomline="true">
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713
1714
1715 \emph on 
1716 BIN2DATA_DIR
1717 \end_inset 
1718 </cell>
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_inset Text
1721
1722 \layout Standard
1723
1724 ../share
1725 \end_inset 
1726 </cell>
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1728 \begin_inset Text
1729
1730 \layout Standard
1731
1732 ..
1733 \end_inset 
1734 </cell>
1735 </row>
1736 <row bottomline="true">
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1738 \begin_inset Text
1739
1740 \layout Standard
1741
1742
1743 \emph on 
1744 PREFIX2BIN_DIR
1745 \end_inset 
1746 </cell>
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_inset Text
1749
1750 \layout Standard
1751
1752 bin
1753 \end_inset 
1754 </cell>
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1756 \begin_inset Text
1757
1758 \layout Standard
1759
1760 bin
1761 \end_inset 
1762 </cell>
1763 </row>
1764 <row bottomline="true">
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 \begin_inset Text
1767
1768 \layout Standard
1769
1770
1771 \emph on 
1772 PREFIX2DATA_DIR
1773 \end_inset 
1774 </cell>
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_inset Text
1777
1778 \layout Standard
1779
1780 share/sdcc
1781 \end_inset 
1782 </cell>
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1784 \begin_inset Text
1785
1786 \layout Standard
1787
1788 \end_inset 
1789 </cell>
1790 </row>
1791 </lyxtabular>
1792
1793 \end_inset 
1794
1795
1796 \newline 
1797
1798 \layout Standard
1799 \noindent 
1800 Examples:
1801 \layout LyX-Code
1802
1803 ./configure
1804 \newline 
1805 ./configure -
1806 \begin_inset ERT
1807 status Collapsed
1808
1809 \layout Standard
1810
1811 \backslash 
1812 /
1813 \end_inset 
1814
1815 -prefix=
1816 \begin_inset Quotes srd
1817 \end_inset 
1818
1819 /usr/bin
1820 \begin_inset Quotes srd
1821 \end_inset 
1822
1823  -
1824 \begin_inset ERT
1825 status Collapsed
1826
1827 \layout Standard
1828
1829 \backslash 
1830 /
1831 \end_inset 
1832
1833 -datarootdir=
1834 \begin_inset Quotes srd
1835 \end_inset 
1836
1837 /usr/share
1838 \begin_inset Quotes srd
1839 \end_inset 
1840
1841
1842 \newline 
1843 ./configure -
1844 \begin_inset ERT
1845 status Collapsed
1846
1847 \layout Standard
1848
1849 \backslash 
1850 /
1851 \end_inset 
1852
1853 -disable-avr-port -
1854 \begin_inset ERT
1855 status Collapsed
1856
1857 \layout Standard
1858
1859 \backslash 
1860 /
1861 \end_inset 
1862
1863 -disable-xa51-port
1864 \layout Standard
1865
1866 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1867 32'):
1868 \layout LyX-Code
1869
1870 ./configure 
1871 \backslash 
1872
1873 \newline 
1874 CC=
1875 \begin_inset Quotes srd
1876 \end_inset 
1877
1878 i586-mingw32msvc-gcc
1879 \begin_inset Quotes srd
1880 \end_inset 
1881
1882  CXX=
1883 \begin_inset Quotes srd
1884 \end_inset 
1885
1886 i586-mingw32msvc-g++
1887 \begin_inset Quotes srd
1888 \end_inset 
1889
1890  
1891 \backslash 
1892  
1893 \newline 
1894 RANLIB=
1895 \begin_inset Quotes srd
1896 \end_inset 
1897
1898 i586-mingw32msvc-ranlib
1899 \begin_inset Quotes srd
1900 \end_inset 
1901
1902  
1903 \backslash 
1904
1905 \newline 
1906 STRIP=
1907 \begin_inset Quotes srd
1908 \end_inset 
1909
1910 i586-mingw32msvc-strip
1911 \begin_inset Quotes srd
1912 \end_inset 
1913
1914  
1915 \backslash 
1916
1917 \newline 
1918 -
1919 \begin_inset ERT
1920 status Collapsed
1921
1922 \layout Standard
1923
1924 \backslash 
1925 /
1926 \end_inset 
1927
1928 -prefix=
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932 /sdcc
1933 \begin_inset Quotes srd
1934 \end_inset 
1935
1936  
1937 \backslash 
1938
1939 \newline 
1940 -
1941 \begin_inset ERT
1942 status Collapsed
1943
1944 \layout Standard
1945
1946 \backslash 
1947 /
1948 \end_inset 
1949
1950 -datarootdir=
1951 \begin_inset Quotes srd
1952 \end_inset 
1953
1954 /sdcc
1955 \begin_inset Quotes srd
1956 \end_inset 
1957
1958  
1959 \backslash 
1960
1961 \newline 
1962 docdir=
1963 \begin_inset Quotes srd
1964 \end_inset 
1965
1966
1967 \backslash 
1968 ${datarootdir}/doc
1969 \begin_inset Quotes srd
1970 \end_inset 
1971
1972  
1973 \backslash 
1974
1975 \newline 
1976 include_dir_suffix=
1977 \begin_inset Quotes srd
1978 \end_inset 
1979
1980 include
1981 \begin_inset Quotes srd
1982 \end_inset 
1983
1984  
1985 \backslash 
1986
1987 \newline 
1988 lib_dir_suffix=
1989 \begin_inset Quotes srd
1990 \end_inset 
1991
1992 lib
1993 \begin_inset Quotes srd
1994 \end_inset 
1995
1996  
1997 \backslash 
1998
1999 \newline 
2000 sdccconf_h_dir_separator=
2001 \begin_inset Quotes srd
2002 \end_inset 
2003
2004
2005 \backslash 
2006
2007 \backslash 
2008
2009 \backslash 
2010
2011 \backslash 
2012
2013 \begin_inset Quotes srd
2014 \end_inset 
2015
2016  
2017 \backslash 
2018
2019 \newline 
2020 -
2021 \begin_inset ERT
2022 status Collapsed
2023
2024 \layout Standard
2025
2026 \backslash 
2027 /
2028 \end_inset 
2029
2030 -disable-device-lib
2031 \backslash 
2032
2033 \newline 
2034 -
2035 \begin_inset ERT
2036 status Collapsed
2037
2038 \layout Standard
2039
2040 \backslash 
2041 /
2042 \end_inset 
2043
2044 -host=i586-mingw32msvc
2045 \backslash 
2046
2047 \newline 
2048 -
2049 \begin_inset ERT
2050 status Collapsed
2051
2052 \layout Standard
2053
2054 \backslash 
2055 /
2056 \end_inset 
2057
2058 -build=unknown-unknown-linux-gnu
2059 \layout Standard
2060
2061 To 
2062 \begin_inset Quotes sld
2063 \end_inset 
2064
2065 cross
2066 \begin_inset Quotes srd
2067 \end_inset 
2068
2069 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2070 ):
2071 \layout LyX-Code
2072
2073 ./configure -C 
2074 \backslash 
2075
2076 \newline 
2077 -
2078 \begin_inset ERT
2079 status Collapsed
2080
2081 \layout Standard
2082
2083 \backslash 
2084 /
2085 \end_inset 
2086
2087 -prefix=
2088 \begin_inset Quotes srd
2089 \end_inset 
2090
2091 /sdcc
2092 \begin_inset Quotes srd
2093 \end_inset 
2094
2095  
2096 \backslash 
2097
2098 \newline 
2099 -
2100 \begin_inset ERT
2101 status Collapsed
2102
2103 \layout Standard
2104
2105 \backslash 
2106 /
2107 \end_inset 
2108
2109 -datarootdir=
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113 /sdcc
2114 \begin_inset Quotes srd
2115 \end_inset 
2116
2117  
2118 \backslash 
2119
2120 \newline 
2121 docdir=
2122 \begin_inset Quotes srd
2123 \end_inset 
2124
2125
2126 \backslash 
2127 ${datarootdir}/doc
2128 \begin_inset Quotes srd
2129 \end_inset 
2130
2131  
2132 \backslash 
2133  
2134 \newline 
2135 include_dir_suffix=
2136 \begin_inset Quotes srd
2137 \end_inset 
2138
2139 include
2140 \begin_inset Quotes srd
2141 \end_inset 
2142
2143  
2144 \backslash 
2145
2146 \newline 
2147 lib_dir_suffix=
2148 \begin_inset Quotes srd
2149 \end_inset 
2150
2151 lib
2152 \begin_inset Quotes srd
2153 \end_inset 
2154
2155  
2156 \backslash 
2157
2158 \newline 
2159 sdccconf_h_dir_separator=
2160 \begin_inset Quotes srd
2161 \end_inset 
2162
2163
2164 \backslash 
2165
2166 \backslash 
2167
2168 \backslash 
2169
2170 \backslash 
2171
2172 \begin_inset Quotes srd
2173 \end_inset 
2174
2175  
2176 \backslash 
2177
2178 \newline 
2179 CC=
2180 \begin_inset Quotes srd
2181 \end_inset 
2182
2183 gcc -mno-cygwin
2184 \begin_inset Quotes srd
2185 \end_inset 
2186
2187  
2188 \backslash 
2189
2190 \newline 
2191 CXX=
2192 \begin_inset Quotes srd
2193 \end_inset 
2194
2195 g++ -mno-cygwin
2196 \begin_inset Quotes srd
2197 \end_inset 
2198
2199  
2200 \layout Standard
2201
2202 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2203  The option '-
2204 \begin_inset ERT
2205 status Collapsed
2206
2207 \layout Standard
2208
2209 \backslash 
2210 /
2211 \end_inset 
2212
2213 -C' turns on caching, which gives a little bit extra speed.
2214  However if options are changed, it can be necessary to delete the config.cache
2215  file.
2216 \layout Section
2217
2218 Install paths
2219 \begin_inset LatexCommand \label{sub:Install-paths}
2220
2221 \end_inset 
2222
2223
2224 \begin_inset LatexCommand \index{Install paths}
2225
2226 \end_inset 
2227
2228
2229 \layout Standard
2230 \added_space_top medskip \align center 
2231
2232 \begin_inset  Tabular
2233 <lyxtabular version="3" rows="5" columns="4">
2234 <features>
2235 <column alignment="left" valignment="top" leftline="true" width="0">
2236 <column alignment="left" valignment="top" leftline="true" width="0">
2237 <column alignment="left" valignment="top" leftline="true" width="0">
2238 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2239 <row topline="true" bottomline="true">
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2241 \begin_inset Text
2242
2243 \layout Standard
2244
2245
2246 \series bold 
2247 Description
2248 \end_inset 
2249 </cell>
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2251 \begin_inset Text
2252
2253 \layout Standard
2254
2255
2256 \series bold 
2257 Path
2258 \end_inset 
2259 </cell>
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2261 \begin_inset Text
2262
2263 \layout Standard
2264
2265
2266 \series bold 
2267 Default
2268 \end_inset 
2269 </cell>
2270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2271 \begin_inset Text
2272
2273 \layout Standard
2274
2275
2276 \series bold 
2277 Win32 builds
2278 \end_inset 
2279 </cell>
2280 </row>
2281 <row topline="true">
2282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2283 \begin_inset Text
2284
2285 \layout Standard
2286
2287 Binary files*
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295
2296 \emph on 
2297 $EXEC_PREFIX
2298 \end_inset 
2299 </cell>
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2301 \begin_inset Text
2302
2303 \layout Standard
2304
2305 /usr/local/bin
2306 \end_inset 
2307 </cell>
2308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2309 \begin_inset Text
2310
2311 \layout Standard
2312
2313
2314 \backslash 
2315 sdcc
2316 \backslash 
2317 bin
2318 \end_inset 
2319 </cell>
2320 </row>
2321 <row topline="true">
2322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2323 \begin_inset Text
2324
2325 \layout Standard
2326
2327 Include files
2328 \end_inset 
2329 </cell>
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2331 \begin_inset Text
2332
2333 \layout Standard
2334
2335
2336 \emph on 
2337 $DATADIR/ $INCLUDE_DIR_SUFFIX
2338 \end_inset 
2339 </cell>
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 /usr/local/share/sdcc/include
2346 \end_inset 
2347 </cell>
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2349 \begin_inset Text
2350
2351 \layout Standard
2352
2353
2354 \backslash 
2355 sdcc
2356 \backslash 
2357 include
2358 \end_inset 
2359 </cell>
2360 </row>
2361 <row topline="true">
2362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2363 \begin_inset Text
2364
2365 \layout Standard
2366
2367 Library file**
2368 \end_inset 
2369 </cell>
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375
2376 \emph on 
2377 $DATADIR/$LIB_DIR_SUFFIX
2378 \end_inset 
2379 </cell>
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2381 \begin_inset Text
2382
2383 \layout Standard
2384
2385 /usr/local/share/sdcc/lib
2386 \end_inset 
2387 </cell>
2388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2389 \begin_inset Text
2390
2391 \layout Standard
2392
2393
2394 \backslash 
2395 sdcc
2396 \backslash 
2397 lib
2398 \end_inset 
2399 </cell>
2400 </row>
2401 <row topline="true" bottomline="true">
2402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2403 \begin_inset Text
2404
2405 \layout Standard
2406
2407 Documentation
2408 \end_inset 
2409 </cell>
2410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2411 \begin_inset Text
2412
2413 \layout Standard
2414
2415
2416 \emph on 
2417 $DOCDIR
2418 \end_inset 
2419 </cell>
2420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2421 \begin_inset Text
2422
2423 \layout Standard
2424
2425 /usr/local/share/sdcc/doc
2426 \end_inset 
2427 </cell>
2428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2429 \begin_inset Text
2430
2431 \layout Standard
2432
2433
2434 \backslash 
2435 sdcc
2436 \backslash 
2437 doc
2438 \end_inset 
2439 </cell>
2440 </row>
2441 </lyxtabular>
2442
2443 \end_inset 
2444
2445
2446 \layout Verse
2447
2448
2449 \size footnotesize 
2450 *compiler, preprocessor, assembler, and linker
2451 \newline 
2452 **the 
2453 \shape italic 
2454 model
2455 \shape default 
2456  is auto-appended by the compiler, e.g.
2457  small, large, z80, ds390 etc
2458 \layout Standard
2459 \noindent 
2460 The install paths can still be changed during `make install` with e.g.:
2461 \layout LyX-Code
2462
2463 make install prefix=$(HOME)/local/sdcc
2464 \layout Standard
2465
2466 Of course this doesn't change the search paths compiled into the binaries.
2467 \newline 
2468
2469 \newline 
2470 Moreover the install path can be changed by defining DESTDIR
2471 \begin_inset LatexCommand \index{DESTDIR}
2472
2473 \end_inset 
2474
2475 :
2476 \layout LyX-Code
2477
2478 make install DESTDIR=$(HOME)/sdcc.rpm/
2479 \layout Standard
2480
2481 Please note that DESTDIR must have a trailing slash!
2482 \layout Section
2483
2484 Search Paths
2485 \begin_inset LatexCommand \label{sub:Search-Paths}
2486
2487 \end_inset 
2488
2489
2490 \begin_inset LatexCommand \index{Search path}
2491
2492 \end_inset 
2493
2494
2495 \layout Standard
2496
2497 Some search paths or parts of them are determined by configure variables
2498  (in 
2499 \emph on 
2500 italics
2501 \emph default 
2502 , see section above).
2503  Further search paths are determined by environment variables during runtime.
2504  
2505 \newline 
2506 The paths searched when running the compiler are as follows (the first catch
2507  wins):
2508 \newline 
2509
2510 \newline 
2511 1.
2512  Binary files (preprocessor, assembler and linker)
2513 \newline 
2514
2515 \layout Standard
2516 \align center 
2517
2518 \begin_inset  Tabular
2519 <lyxtabular version="3" rows="4" columns="3">
2520 <features>
2521 <column alignment="block" valignment="top" leftline="true" width="0in">
2522 <column alignment="block" valignment="top" leftline="true" width="0in">
2523 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2524 <row topline="true" bottomline="true">
2525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2526 \begin_inset Text
2527
2528 \layout Standard
2529
2530 Search path
2531 \end_inset 
2532 </cell>
2533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2534 \begin_inset Text
2535
2536 \layout Standard
2537
2538 default
2539 \end_inset 
2540 </cell>
2541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2542 \begin_inset Text
2543
2544 \layout Standard
2545
2546 Win32 builds
2547 \end_inset 
2548 </cell>
2549 </row>
2550 <row topline="true">
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2552 \begin_inset Text
2553
2554 \layout Standard
2555
2556 $SDCC_HOME/
2557 \emph on 
2558 $PPREFIX2BIN_DIR
2559 \end_inset 
2560 </cell>
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2562 \begin_inset Text
2563
2564 \layout Standard
2565
2566 $SDCC_HOME/bin
2567 \end_inset 
2568 </cell>
2569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2570 \begin_inset Text
2571
2572 \layout Standard
2573
2574 $SDCC_HOME
2575 \backslash 
2576 bin
2577 \end_inset 
2578 </cell>
2579 </row>
2580 <row topline="true">
2581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2582 \begin_inset Text
2583
2584 \layout Standard
2585
2586 Path of argv[0] (if available)
2587 \end_inset 
2588 </cell>
2589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2590 \begin_inset Text
2591
2592 \layout Standard
2593
2594 Path of argv[0]
2595 \end_inset 
2596 </cell>
2597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2598 \begin_inset Text
2599
2600 \layout Standard
2601
2602 Path of argv[0]
2603 \end_inset 
2604 </cell>
2605 </row>
2606 <row topline="true" bottomline="true">
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2608 \begin_inset Text
2609
2610 \layout Standard
2611
2612 $PATH
2613 \end_inset 
2614 </cell>
2615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2616 \begin_inset Text
2617
2618 \layout Standard
2619
2620 $PATH
2621 \end_inset 
2622 </cell>
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \layout Standard
2627
2628 $PATH
2629 \end_inset 
2630 </cell>
2631 </row>
2632 </lyxtabular>
2633
2634 \end_inset 
2635
2636  
2637 \newline 
2638
2639 \layout Standard
2640 \noindent 
2641 2.
2642  Include files
2643 \newline 
2644
2645 \layout Standard
2646 \align center 
2647
2648 \begin_inset  Tabular
2649 <lyxtabular version="3" rows="6" columns="3">
2650 <features>
2651 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2652 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2653 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2654 <row topline="true" bottomline="true">
2655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2656 \begin_inset Text
2657
2658 \layout Standard
2659
2660 Search path
2661 \end_inset 
2662 </cell>
2663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_inset Text
2665
2666 \layout Standard
2667
2668 default
2669 \end_inset 
2670 </cell>
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2672 \begin_inset Text
2673
2674 \layout Standard
2675
2676 Win32 builds
2677 \end_inset 
2678 </cell>
2679 </row>
2680 <row topline="true">
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \layout Standard
2685
2686 -
2687 \begin_inset ERT
2688 status Collapsed
2689
2690 \layout Standard
2691
2692 \backslash 
2693 /
2694 \end_inset 
2695
2696 -I dir
2697 \end_inset 
2698 </cell>
2699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2700 \begin_inset Text
2701
2702 \layout Standard
2703
2704 -
2705 \begin_inset ERT
2706 status Collapsed
2707
2708 \layout Standard
2709
2710 \backslash 
2711 /
2712 \end_inset 
2713
2714 -I dir
2715 \end_inset 
2716 </cell>
2717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2718 \begin_inset Text
2719
2720 \layout Standard
2721
2722 -
2723 \begin_inset ERT
2724 status Collapsed
2725
2726 \layout Standard
2727
2728 \backslash 
2729 /
2730 \end_inset 
2731
2732 -I dir
2733 \end_inset 
2734 </cell>
2735 </row>
2736 <row topline="true">
2737 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_inset Text
2739
2740 \layout Standard
2741
2742 $SDCC_INCLUDE
2743 \end_inset 
2744 </cell>
2745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2746 \begin_inset Text
2747
2748 \layout Standard
2749
2750 $SDCC_INCLUDE
2751 \end_inset 
2752 </cell>
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2754 \begin_inset Text
2755
2756 \layout Standard
2757
2758 $SDCC_INCLUDE
2759 \end_inset 
2760 </cell>
2761 </row>
2762 <row topline="true">
2763 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2764 \begin_inset Text
2765
2766 \layout Standard
2767
2768 $SDCC_HOME/
2769 \newline 
2770
2771 \emph on 
2772 $PREFIX2DATA_DIR/
2773 \newline 
2774 $INCLUDE_DIR_SUFFIX
2775 \end_inset 
2776 </cell>
2777 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2778 \begin_inset Text
2779
2780 \layout Standard
2781
2782 $SDCC_ HOME/
2783 \newline 
2784 share/sdcc/
2785 \newline 
2786 include
2787 \end_inset 
2788 </cell>
2789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2790 \begin_inset Text
2791
2792 \layout Standard
2793
2794 $SDCC_HOME
2795 \backslash 
2796 include
2797 \end_inset 
2798 </cell>
2799 </row>
2800 <row topline="true">
2801 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \layout Standard
2805
2806 path(argv[0])/
2807 \newline 
2808
2809 \emph on 
2810 $BIN2DATADIR/
2811 \emph default 
2812
2813 \newline 
2814
2815 \emph on 
2816 $INCLUDE_DIR_SUFFIX
2817 \end_inset 
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824 path(argv[0])/
2825 \newline 
2826 ../sdcc/include
2827 \newline 
2828 \SpecialChar ~
2829 \SpecialChar ~
2830 \SpecialChar ~
2831 \SpecialChar ~
2832 \SpecialChar ~
2833 \SpecialChar ~
2834 \SpecialChar ~
2835 \SpecialChar ~
2836 \SpecialChar ~
2837 \SpecialChar ~
2838 \SpecialChar ~
2839 \SpecialChar ~
2840 \SpecialChar ~
2841 \SpecialChar ~
2842 \SpecialChar ~
2843 \SpecialChar ~
2844 \SpecialChar ~
2845 \SpecialChar ~
2846 \SpecialChar ~
2847 \SpecialChar ~
2848 \SpecialChar ~
2849 \SpecialChar ~
2850 \SpecialChar ~
2851 \SpecialChar ~
2852 \SpecialChar ~
2853 \SpecialChar ~
2854 \SpecialChar ~
2855 \SpecialChar ~
2856 \SpecialChar ~
2857 \SpecialChar ~
2858 \SpecialChar ~
2859 \SpecialChar ~
2860 \SpecialChar ~
2861 \SpecialChar ~
2862 \SpecialChar ~
2863 \SpecialChar ~
2864 \SpecialChar ~
2865 \SpecialChar ~
2866
2867 \end_inset 
2868 </cell>
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \layout Standard
2873
2874 path(argv[0])
2875 \backslash 
2876 ..
2877 \backslash 
2878 include
2879 \end_inset 
2880 </cell>
2881 </row>
2882 <row topline="true" bottomline="true">
2883 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2884 \begin_inset Text
2885
2886 \layout Standard
2887
2888
2889 \emph on 
2890 $DATADIR/
2891 \emph default 
2892
2893 \newline 
2894
2895 \emph on 
2896 $INCLUDE_DIR_SUFFIX
2897 \end_inset 
2898 </cell>
2899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2900 \begin_inset Text
2901
2902 \layout Standard
2903
2904 /usr/local/share/sdcc/
2905 \newline 
2906 include
2907 \end_inset 
2908 </cell>
2909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2910 \begin_inset Text
2911
2912 \layout Standard
2913
2914 (not on Win32)
2915 \end_inset 
2916 </cell>
2917 </row>
2918 </lyxtabular>
2919
2920 \end_inset 
2921
2922  
2923 \newline 
2924
2925 \layout Standard
2926 \noindent 
2927 The option -
2928 \begin_inset ERT
2929 status Collapsed
2930
2931 \layout Standard
2932
2933 \backslash 
2934 /
2935 \end_inset 
2936
2937 -nostdinc disables the last two search paths.
2938 \newline 
2939
2940 \newline 
2941 3.
2942  Library files 
2943 \newline 
2944
2945 \layout Standard
2946
2947 With the exception of 
2948 \begin_inset Quotes sld
2949 \end_inset 
2950
2951 -
2952 \begin_inset ERT
2953 status Collapsed
2954
2955 \layout Standard
2956
2957 \backslash 
2958 /
2959 \end_inset 
2960
2961 -L dir
2962 \begin_inset Quotes srd
2963 \end_inset 
2964
2965  the 
2966 \shape italic 
2967 model
2968 \shape default 
2969  is auto-appended by the compiler (e.g.
2970  small, large, z80, ds390 etc.).
2971  
2972 \newline 
2973
2974 \layout Standard
2975 \align center 
2976
2977 \begin_inset  Tabular
2978 <lyxtabular version="3" rows="6" columns="3">
2979 <features>
2980 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2981 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2982 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2983 <row topline="true" bottomline="true">
2984 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2985 \begin_inset Text
2986
2987 \layout Standard
2988
2989 Search path
2990 \end_inset 
2991 </cell>
2992 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2993 \begin_inset Text
2994
2995 \layout Standard
2996
2997 default
2998 \end_inset 
2999 </cell>
3000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3001 \begin_inset Text
3002
3003 \layout Standard
3004
3005 Win32 builds
3006 \end_inset 
3007 </cell>
3008 </row>
3009 <row topline="true">
3010 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_inset Text
3012
3013 \layout Standard
3014
3015 -
3016 \begin_inset ERT
3017 status Collapsed
3018
3019 \layout Standard
3020
3021 \backslash 
3022 /
3023 \end_inset 
3024
3025 -L dir
3026 \end_inset 
3027 </cell>
3028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 -
3034 \begin_inset ERT
3035 status Collapsed
3036
3037 \layout Standard
3038
3039 \backslash 
3040 /
3041 \end_inset 
3042
3043 -L dir
3044 \end_inset 
3045 </cell>
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3047 \begin_inset Text
3048
3049 \layout Standard
3050
3051 -
3052 \begin_inset ERT
3053 status Collapsed
3054
3055 \layout Standard
3056
3057 \backslash 
3058 /
3059 \end_inset 
3060
3061 -L dir
3062 \end_inset 
3063 </cell>
3064 </row>
3065 <row topline="true">
3066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3067 \begin_inset Text
3068
3069 \layout Standard
3070
3071 $SDCC_LIB/
3072 \newline 
3073
3074 \emph on 
3075 <model>
3076 \end_inset 
3077 </cell>
3078 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3079 \begin_inset Text
3080
3081 \layout Standard
3082
3083 $SDCC_LIB/
3084 \newline 
3085
3086 \emph on 
3087 <model>
3088 \end_inset 
3089 </cell>
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3091 \begin_inset Text
3092
3093 \layout Standard
3094
3095 $SDCC_LIB
3096 \backslash 
3097
3098 \newline 
3099
3100 \emph on 
3101 <model>
3102 \end_inset 
3103 </cell>
3104 </row>
3105 <row topline="true">
3106 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3107 \begin_inset Text
3108
3109 \layout Standard
3110
3111 $SDCC_HOME/
3112 \newline 
3113
3114 \emph on 
3115 $PREFIX2DATA_DIR/
3116 \newline 
3117 $LIB_DIR_SUFFIX/<model>
3118 \end_inset 
3119 </cell>
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3121 \begin_inset Text
3122
3123 \layout Standard
3124
3125 $SDCC_HOME/
3126 \newline 
3127 share/sdcc/
3128 \newline 
3129 lib/
3130 \emph on 
3131 <model>
3132 \end_inset 
3133 </cell>
3134 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3135 \begin_inset Text
3136
3137 \layout Standard
3138
3139 $SDCC_HOME
3140 \backslash 
3141 lib
3142 \backslash 
3143
3144 \emph on 
3145
3146 \newline 
3147 <model>
3148 \end_inset 
3149 </cell>
3150 </row>
3151 <row topline="true">
3152 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3153 \begin_inset Text
3154
3155 \layout Standard
3156
3157 path(argv[0])/
3158 \newline 
3159
3160 \emph on 
3161 $BIN2DATADIR/
3162 \emph default 
3163
3164 \newline 
3165
3166 \emph on 
3167 $LIB_DIR_SUFFIX/<model>
3168 \end_inset 
3169 </cell>
3170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_inset Text
3172
3173 \layout Standard
3174
3175 path(argv[0])/
3176 \newline 
3177 ../sdcc/lib/
3178 \emph on 
3179 <model>
3180 \newline 
3181 \SpecialChar ~
3182 \SpecialChar ~
3183 \SpecialChar ~
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 \SpecialChar ~
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 \SpecialChar ~
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211 \SpecialChar ~
3212 \SpecialChar ~
3213 \SpecialChar ~
3214 \SpecialChar ~
3215 \SpecialChar ~
3216 \SpecialChar ~
3217 \SpecialChar ~
3218 \SpecialChar ~
3219 \SpecialChar ~
3220
3221 \end_inset 
3222 </cell>
3223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3224 \begin_inset Text
3225
3226 \layout Standard
3227
3228 path(argv[0])
3229 \backslash 
3230
3231 \newline 
3232 ..
3233 \backslash 
3234 lib
3235 \backslash 
3236
3237 \emph on 
3238 <model>
3239 \newline 
3240 \SpecialChar ~
3241 \SpecialChar ~
3242 \SpecialChar ~
3243 \SpecialChar ~
3244 \SpecialChar ~
3245 \SpecialChar ~
3246 \SpecialChar ~
3247 \SpecialChar ~
3248 \SpecialChar ~
3249 \SpecialChar ~
3250 \SpecialChar ~
3251 \SpecialChar ~
3252 \SpecialChar ~
3253 \SpecialChar ~
3254 \SpecialChar ~
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 \SpecialChar ~
3258 \SpecialChar ~
3259 \SpecialChar ~
3260 \SpecialChar ~
3261 \SpecialChar ~
3262 \SpecialChar ~
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 \SpecialChar ~
3266 \SpecialChar ~
3267 \SpecialChar ~
3268 \SpecialChar ~
3269 \SpecialChar ~
3270 \SpecialChar ~
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 \SpecialChar ~
3274 \SpecialChar ~
3275
3276 \end_inset 
3277 </cell>
3278 </row>
3279 <row topline="true" bottomline="true">
3280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_inset Text
3282
3283 \layout Standard
3284
3285
3286 \emph on 
3287 $DATADIR/
3288 \newline 
3289 $LIB_DIR_SUFFIX/<model>
3290 \end_inset 
3291 </cell>
3292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3293 \begin_inset Text
3294
3295 \layout Standard
3296
3297 /usr/local/share/sdcc/
3298 \newline 
3299 lib/
3300 \emph on 
3301 <model>
3302 \end_inset 
3303 </cell>
3304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3305 \begin_inset Text
3306
3307 \layout Standard
3308
3309 (not on Win32)
3310 \end_inset 
3311 </cell>
3312 </row>
3313 </lyxtabular>
3314
3315 \end_inset 
3316
3317
3318 \newline 
3319
3320 \layout Comment
3321
3322 Don't delete any of the stray spaces in the table above without checking
3323  the HTML output (last line)!
3324 \layout Standard
3325
3326 \SpecialChar ~
3327
3328 \newline 
3329 The option -
3330 \begin_inset ERT
3331 status Collapsed
3332
3333 \layout Standard
3334
3335 \backslash 
3336 /
3337 \end_inset 
3338
3339 -nostdlib disables the last two search paths.
3340 \layout Section
3341
3342 Building SDCC
3343 \begin_inset LatexCommand \index{Building SDCC}
3344
3345 \end_inset 
3346
3347
3348 \layout Subsection
3349
3350 Building SDCC on Linux
3351 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3352
3353 \end_inset 
3354
3355
3356 \layout Enumerate
3357
3358
3359 \series medium 
3360 Download the source package
3361 \series default 
3362  either from the SDCC Subversion repository or from the nightly snapshots
3363 \series medium 
3364 , it will be named something like sdcc
3365 \series default 
3366 .src
3367 \series medium 
3368 .t
3369 \series default 
3370 ar.
3371 \series medium 
3372 gz
3373 \series default 
3374  
3375 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3376
3377 \end_inset 
3378
3379 .
3380 \layout Enumerate
3381
3382
3383 \series medium 
3384 Bring up a command line terminal, such as xterm.
3385 \layout Enumerate
3386
3387
3388 \series medium 
3389 Unpack the file using a command like: 
3390 \family sans 
3391 \series bold 
3392 "tar -xvzf sdcc.src.tar.gz
3393 \family default 
3394 \series default 
3395 "
3396 \series medium 
3397 , this will create a sub-directory called sdcc with all of the sources.
3398 \layout Enumerate
3399
3400 Change directory into the main SDCC directory, for example type: 
3401 \family sans 
3402 \series bold 
3403 "cd sdcc
3404 \series default 
3405 ".
3406 \layout Enumerate
3407
3408
3409 \series medium 
3410 Type 
3411 \family sans 
3412 \series bold 
3413 "./configure
3414 \family default 
3415 \series default 
3416 ".
3417  This configures the package for compilation on your system.
3418 \layout Enumerate
3419
3420
3421 \series medium 
3422 Type 
3423 \family sans 
3424 \series bold 
3425 "make
3426 \family default 
3427 \series default 
3428 "
3429 \series medium 
3430 .
3431
3432 \series default 
3433  All of the source packages will compile, this can take a while.
3434 \layout Enumerate
3435
3436
3437 \series medium 
3438 Type 
3439 \family sans 
3440 \series bold 
3441 "make install"
3442 \family default 
3443 \series default 
3444  as root
3445 \series medium 
3446 .
3447
3448 \series default 
3449  This copies the binary executables, the include files, the libraries and
3450  the documentation to the install directories.
3451  Proceed with section 
3452 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3453
3454 \end_inset 
3455
3456 .
3457 \layout Subsection
3458
3459 Building SDCC on OSX 2.x
3460 \layout Standard
3461
3462 Follow the instruction for Linux.
3463 \newline 
3464
3465 \newline 
3466 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3467 )) fails to compile SDCC.
3468  Fortunately there's also gcc 2.9.x installed, which works fine.
3469  This compiler can be selected by running 'configure' with:
3470 \layout LyX-Code
3471
3472 ./configure CC=gcc2 CXX=g++2
3473 \layout Subsection
3474
3475 Cross compiling SDCC on Linux for Windows
3476 \layout Standard
3477
3478 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3479  See section 'Configure Options'.
3480 \layout Subsection
3481
3482 Building SDCC using Cygwin and Mingw32
3483 \layout Standard
3484
3485 For building and installing a Cygwin executable follow the instructions
3486  for Linux.
3487 \newline 
3488
3489 \newline 
3490 On Cygwin a 
3491 \begin_inset Quotes sld
3492 \end_inset 
3493
3494 native
3495 \begin_inset Quotes srd
3496 \end_inset 
3497
3498  Win32-binary can be built, which will not need the Cygwin-DLL.
3499  For the necessary 'configure' options see section 'configure options' or
3500  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3501 \newline 
3502
3503 \newline 
3504 In order to install Cygwin on Windows download setup.exe from 
3505 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3506
3507 \end_inset 
3508
3509 .
3510  Run it, set the 
3511 \begin_inset Quotes sld
3512 \end_inset 
3513
3514 default text file type
3515 \begin_inset Quotes srd
3516 \end_inset 
3517
3518  to 
3519 \begin_inset Quotes sld
3520 \end_inset 
3521
3522 unix
3523 \begin_inset Quotes srd
3524 \end_inset 
3525
3526  and download/install at least the following packages.
3527  Some packages are selected by default, others will be automatically selected
3528  because of dependencies with the manually selected packages.
3529  Never deselect these packages!
3530 \layout Itemize
3531
3532 flex
3533 \layout Itemize
3534
3535 bison
3536 \layout Itemize
3537
3538 gcc ; version 3.x is fine, no need to use the old 2.9x
3539 \layout Itemize
3540
3541 binutils ; selected with gcc
3542 \layout Itemize
3543
3544 make
3545 \layout Itemize
3546
3547 rxvt ; a nice console, which makes life much easier under windoze (see below)
3548 \layout Itemize
3549
3550 man ; not really needed for building SDCC, but you'll miss it sooner or
3551  later
3552 \layout Itemize
3553
3554 less ; not really needed for building SDCC, but you'll miss it sooner or
3555  later
3556 \layout Itemize
3557
3558 svn ; only if you use Subversion access
3559 \layout Standard
3560
3561 If you want to develop something you'll need:
3562 \layout Itemize
3563
3564 python ; for the regression tests
3565 \layout Itemize
3566
3567 gdb ; the gnu debugger, together with the nice GUI 
3568 \begin_inset Quotes sld
3569 \end_inset 
3570
3571 insight
3572 \begin_inset Quotes srd
3573 \end_inset 
3574
3575
3576 \layout Itemize
3577
3578 openssh ; to access the CF or commit changes
3579 \layout Itemize
3580
3581 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3582  use autoconf-stable!
3583 \layout Standard
3584
3585 rxvt is a nice console with history.
3586  Replace in your cygwin.bat the line
3587 \layout LyX-Code
3588
3589 bash -
3590 \begin_inset ERT
3591 status Collapsed
3592
3593 \layout Standard
3594
3595 \backslash 
3596 /
3597 \end_inset 
3598
3599 -login -i 
3600 \layout Standard
3601
3602 with (one line):
3603 \layout LyX-Code
3604
3605 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3606 \layout LyX-Code
3607
3608      -bg black -fg white -geometry 100x65 -e bash -
3609 \begin_inset ERT
3610 status Collapsed
3611
3612 \layout Standard
3613
3614 \backslash 
3615 /
3616 \end_inset 
3617
3618 -login
3619 \layout Standard
3620
3621 Text selected with the mouse is automatically copied to the clipboard, pasting
3622  works with shift-insert.
3623 \newline 
3624
3625 \newline 
3626 The other good tip is to make sure you have no //c/-style paths anywhere,
3627  use /cygdrive/c/ instead.
3628  Using // invokes a network lookup which is very slow.
3629  If you think 
3630 \begin_inset Quotes sld
3631 \end_inset 
3632
3633 cygdrive
3634 \begin_inset Quotes srd
3635 \end_inset 
3636
3637  is too long, you can change it with e.g.
3638 \layout LyX-Code
3639
3640 mount -s -u -c /mnt
3641 \layout Standard
3642
3643 SDCC sources use the unix line ending LF.
3644  Life is much easier, if you store the source tree on a drive which is mounted
3645  in binary mode.
3646  And use an editor which can handle LF-only line endings.
3647  Make sure not to commit files with windows line endings.
3648  The tabulator spacing
3649 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3650
3651 \end_inset 
3652
3653  used in the project is 8.
3654  Although a tabulator spacing of 8 is a sensible choice for programmers
3655  (it's a power of 2 and allows to display 8/16 bit signed variables without
3656  loosing columns) the plan is to move towards using only spaces in the source.
3657 \layout Subsection
3658
3659 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3660 \layout Standard
3661
3662
3663 \series medium 
3664 Download the source package
3665 \series default 
3666  either from the SDCC Subversion repository or from the 
3667 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3668
3669 \end_inset 
3670
3671
3672 \series medium 
3673 , it will be named something like sdcc
3674 \series default 
3675 .src
3676 \series medium 
3677 .tgz.
3678
3679 \series default 
3680  SDCC is distributed with all the projects, workspaces, and files you need
3681  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3682  The workspace name is 'sdcc.dsw'.
3683  Please note that as it is now, all the executables are created in a folder
3684  called sdcc
3685 \backslash 
3686 bin_vc.
3687  Once built you need to copy the executables from sdcc
3688 \backslash 
3689 bin_vc to sdcc
3690 \backslash 
3691 bin before running SDCC.
3692  
3693 \newline 
3694
3695 \newline 
3696 WARNING: Visual studio is very picky with line terminations; it expects
3697  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3698  When using the Subversion repository it's easiest to configure the svn
3699  client to convert automatically for you.
3700  If however you are getting a message such as "This makefile was not generated
3701  by Developer Studio etc.
3702  etc.
3703 \begin_inset Quotes srd
3704 \end_inset 
3705
3706  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3707  need to convert the Unix style line endings to DOS style line endings.
3708  To do so you can use the 
3709 \begin_inset Quotes sld
3710 \end_inset 
3711
3712 unix2dos
3713 \begin_inset Quotes srd
3714 \end_inset 
3715
3716  utility freely available on the internet.
3717  Doug Hawkins reported in the sdcc-user list that this works:
3718 \newline 
3719
3720 \newline 
3721 C:
3722 \backslash 
3723 Programming
3724 \backslash 
3725 SDCC> unix2dos sdcc.dsw
3726 \newline 
3727 C:
3728 \backslash 
3729 Programming
3730 \backslash 
3731 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3732 \newline 
3733
3734 \newline 
3735 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3736  flex.exe, and gawk.exe.
3737  One good place to get them is 
3738 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3739
3740 \end_inset 
3741
3742
3743 \newline 
3744
3745 \newline 
3746 Download the file UnxUtils
3747 \begin_inset LatexCommand \index{UnxUtils}
3748
3749 \end_inset 
3750
3751 .zip.
3752  Now you have to install the utilities and setup MSVC so it can locate the
3753  required programs.
3754  Here there are two alternatives (choose one!):
3755 \layout Enumerate
3756
3757 The easy way:
3758 \newline 
3759
3760 \newline 
3761 a) Extract UnxUtils.zip to your C:
3762 \backslash 
3763  hard disk PRESERVING the original paths, otherwise bison won't work.
3764  (If you are using WinZip make certain that 'Use folder names' is selected)
3765 \newline 
3766
3767 \newline 
3768 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3769  in 'Show directories for:' select 'Executable files', and in the directories
3770  window add a new path: 'C:
3771 \backslash 
3772 user
3773 \backslash 
3774 local
3775 \backslash 
3776 wbin', click ok.
3777 \newline 
3778
3779 \newline 
3780 (As a side effect, you get a bunch of Unix utilities that could be useful,
3781  such as diff and patch.)
3782 \layout Enumerate
3783
3784 A more compact way:
3785 \newline 
3786
3787 \newline 
3788 This one avoids extracting a bunch of files you may not use, but requires
3789  some extra work:
3790 \newline 
3791
3792 \newline 
3793 a) Create a directory were to put the tools needed, or use a directory already
3794  present.
3795  Say for example 'C:
3796 \backslash 
3797 util'.
3798 \newline 
3799
3800 \newline 
3801 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3802  to such directory WITHOUT preserving the original paths.
3803  (If you are using WinZip make certain that 'Use folder names' is not selected)
3804 \newline 
3805
3806 \newline 
3807 c) Rename bison.exe to '_bison.exe'.
3808 \newline 
3809
3810 \newline 
3811 d) Create a batch file 'bison.bat' in 'C:
3812 \backslash 
3813 util
3814 \backslash 
3815 ' and add these lines: 
3816 \newline 
3817 \SpecialChar ~
3818 \SpecialChar ~
3819 set BISON_SIMPLE=C:
3820 \backslash 
3821 util
3822 \backslash 
3823 bison.simple 
3824 \newline 
3825 \SpecialChar ~
3826 \SpecialChar ~
3827 set BISON_HAIRY=C:
3828 \backslash 
3829 util
3830 \backslash 
3831 bison.hairy
3832 \newline 
3833 \SpecialChar ~
3834 \SpecialChar ~
3835 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3836 \newline 
3837
3838 \newline 
3839 Steps 'c' and 'd' are needed because bison requires by default that the
3840  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3841  '/usr/local/share/' I think.
3842  So it is necessary to tell bison where those files are located if they
3843  are not in such directory.
3844  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3845 \newline 
3846
3847 \newline 
3848 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3849  in 'Show directories for:' select 'Executable files', and in the directories
3850  window add a new path: 'c:
3851 \backslash 
3852 util', click ok.
3853  Note that you can use any other path instead of 'c:
3854 \backslash 
3855 util', even the path where the Visual C++ tools are, probably: 'C:
3856 \backslash 
3857 Program Files
3858 \backslash 
3859 Microsoft Visual Studio
3860 \backslash 
3861 Common
3862 \backslash 
3863 Tools'.
3864  So you don't have to execute step 'e' :)
3865 \layout Standard
3866
3867 That is it.
3868  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3869  the executables from sdcc
3870 \backslash 
3871 bin_vc to sdcc
3872 \backslash 
3873 bin, and you can compile using SDCC.
3874 \layout Subsection
3875
3876 Building SDCC Using Borland
3877 \layout Enumerate
3878
3879 From the sdcc directory, run the command "make -f Makefile.bcc".
3880  This should regenerate all the .exe files in the bin directory except for
3881  SDCDB and ucSim.
3882 \layout Enumerate
3883
3884 If you modify any source files and need to rebuild, be aware that the dependenci
3885 es may not be correctly calculated.
3886  The safest option is to delete all .obj files and run the build again.
3887  From a Cygwin BASH prompt, this can easily be done with the command (be
3888  sure you are in the sdcc directory):
3889 \newline 
3890
3891 \newline 
3892
3893 \family sans 
3894 \series bold 
3895 find .
3896  
3897 \backslash 
3898 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3899 \backslash 
3900 ) -print -exec rm {} 
3901 \backslash 
3902 ;
3903 \family default 
3904 \series default 
3905
3906 \newline 
3907
3908 \newline 
3909 or on Windows NT/2000/XP from the command prompt with the command:
3910 \newline 
3911
3912 \family sans 
3913 \series bold 
3914
3915 \newline 
3916 del /s *.obj *.lib *.rul
3917 \family default 
3918 \series default 
3919  from the sdcc directory.
3920 \layout Subsection
3921
3922 Windows Install Using a ZIP Package
3923 \layout Enumerate
3924
3925 Download the binary zip package from 
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3927
3928 \end_inset 
3929
3930  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3931  This should unpack to a group of sub-directories.
3932  An example directory structure after unpacking the mingw32 package is:
3933  c:
3934 \backslash 
3935 sdcc
3936 \backslash 
3937 bin for the executables, c:
3938 \backslash 
3939 sdcc
3940 \backslash 
3941 include and c:
3942 \backslash 
3943 sdcc
3944 \backslash 
3945 lib for the include and libraries.
3946 \layout Enumerate
3947
3948 Adjust your environment variable PATH to include the location of the bin
3949  directory or start sdcc using the full path.
3950 \layout Subsection
3951
3952 Windows Install Using the Setup Program
3953 \begin_inset LatexCommand \label{sub:Windows-Install}
3954
3955 \end_inset 
3956
3957
3958 \layout Standard
3959
3960 Download the setup program 
3961 \emph on 
3962 sdcc-x.y.z-setup.exe
3963 \emph default 
3964  for an official release from 
3965 \newline 
3966
3967 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3968
3969 \end_inset 
3970
3971  or a setup program for one of the snapshots 
3972 \emph on 
3973 sdcc-yyyymmdd-xxxx-setup.exe
3974 \emph default 
3975  from 
3976 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3977
3978 \end_inset 
3979
3980  and execute it.
3981  A windows typical installer will guide you through the installation process.
3982 \layout Subsection
3983
3984 VPATH
3985 \begin_inset LatexCommand \index{VPATH}
3986
3987 \end_inset 
3988
3989  feature
3990 \layout Standard
3991
3992 SDCC supports the VPATH feature provided by configure and make.
3993  It allows to separate the source and build trees.
3994  Here's an example:
3995 \layout Standard
3996
3997
3998 \family typewriter 
3999 cd ~\SpecialChar ~
4000 \SpecialChar ~
4001 \SpecialChar ~
4002 \SpecialChar ~
4003 \SpecialChar ~
4004 \SpecialChar ~
4005 \SpecialChar ~
4006 \SpecialChar ~
4007 \SpecialChar ~
4008 \SpecialChar ~
4009 \SpecialChar ~
4010 \SpecialChar ~
4011 \SpecialChar ~
4012 \SpecialChar ~
4013 \SpecialChar ~
4014 \SpecialChar ~
4015 \SpecialChar ~
4016 \SpecialChar ~
4017 \SpecialChar ~
4018 \SpecialChar ~
4019 \SpecialChar ~
4020 # cd $HOME
4021 \layout Standard
4022
4023
4024 \family typewriter 
4025 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4026 # extract source to directory sdcc
4027 \layout Standard
4028
4029
4030 \family typewriter 
4031 mkdir sdcc.build\SpecialChar ~
4032 \SpecialChar ~
4033 \SpecialChar ~
4034 \SpecialChar ~
4035 \SpecialChar ~
4036 \SpecialChar ~
4037 \SpecialChar ~
4038 \SpecialChar ~
4039 \SpecialChar ~
4040 # put output in sdcc.build
4041 \layout Standard
4042
4043
4044 \family typewriter 
4045 cd sdcc.build
4046 \layout Standard
4047
4048
4049 \family typewriter 
4050 ../sdcc/configure\SpecialChar ~
4051 \SpecialChar ~
4052 \SpecialChar ~
4053 \SpecialChar ~
4054 \SpecialChar ~
4055 \SpecialChar ~
4056 \SpecialChar ~
4057 \SpecialChar ~
4058 # configure is doing all the magic!
4059 \layout Standard
4060
4061
4062 \family typewriter 
4063 make
4064 \layout Standard
4065 \noindent 
4066 That's it! 
4067 \series bold 
4068 configure
4069 \series default 
4070  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4071  It automagically computes the variables srcdir, top_srcdir and top_buildir
4072  for each directory.
4073  After running 
4074 \series bold 
4075 make
4076 \series default 
4077  the generated files will be in ~/sdcc.build, while the source files stay
4078  in ~/sdcc.
4079 \newline 
4080 This is not only usefull for building different binaries, e.g.
4081  when cross compiling.
4082  It also gives you a much better overview in the source tree when all the
4083  generated files are not scattered between the source files.
4084  And the best thing is: if you want to change a file you can leave the original
4085  file untouched in the source directory.
4086  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4087  Makefile.dep` and `make`.
4088  
4089 \series bold 
4090 make
4091 \series default 
4092  will do the rest for you!
4093 \layout Section
4094
4095 Building the Documentation
4096 \layout Standard
4097
4098 Add -
4099 \begin_inset ERT
4100 status Collapsed
4101
4102 \layout Standard
4103
4104 \backslash 
4105 /
4106 \end_inset 
4107
4108 -enable-doc to the configure arguments to build the documentation together
4109  with all the other stuff.
4110  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4111  dvips and makeindex) to get the job done.
4112  Another possibility is to change to the doc directory and to type 
4113 \family sans 
4114 \series bold 
4115
4116 \begin_inset Quotes srd
4117 \end_inset 
4118
4119 make
4120 \begin_inset Quotes srd
4121 \end_inset 
4122
4123
4124 \family default 
4125 \series default 
4126  there.
4127  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4128 x).
4129  Using LyX 
4130 \begin_inset LatexCommand \url{http://www.lyx.org}
4131
4132 \end_inset 
4133
4134  as editor is straightforward.
4135  Prebuilt documentation in html and pdf format is available from 
4136 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4137
4138 \end_inset 
4139
4140 .
4141 \layout Section
4142
4143 Reading the Documentation
4144 \begin_inset LatexCommand \index{Documentation}
4145
4146 \end_inset 
4147
4148
4149 \layout Standard
4150
4151 Currently reading the document in pdf format is recommended, as for unknown
4152  reason the hyperlinks are working there whereas in the html version they
4153  are not
4154 \begin_inset Foot
4155 collapsed false
4156
4157 \layout Standard
4158
4159 If you should know why please drop us a note
4160 \end_inset 
4161
4162 .
4163  
4164 \newline 
4165 You'll find the pdf version
4166 \begin_inset LatexCommand \index{PDF version of this document}
4167
4168 \end_inset 
4169
4170  at 
4171 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4172
4173 \end_inset 
4174
4175 .
4176  
4177 \newline 
4178 A html version
4179 \begin_inset LatexCommand \index{HTML version of this document}
4180
4181 \end_inset 
4182
4183  should be online at 
4184 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4185
4186 \end_inset 
4187
4188 .
4189 \newline 
4190 This documentation is in some aspects different from a commercial documentation:
4191  
4192 \layout Itemize
4193
4194 It tries to document SDCC for several processor architectures in one document
4195  (commercially these probably would be separate documents/products).
4196  This document
4197 \begin_inset LatexCommand \index{Status of documentation}
4198
4199 \end_inset 
4200
4201  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4202 on about f.e.
4203  Z80, PIC14, PIC16 and HC08.
4204 \layout Itemize
4205
4206 There are many references pointing away from this documentation.
4207  Don't let this distract you.
4208  If there f.e.
4209  was a reference like 
4210 \begin_inset LatexCommand \url{http://www.opencores.org}
4211
4212 \end_inset 
4213
4214  together with a statement 
4215 \begin_inset Quotes sld
4216 \end_inset 
4217
4218 some processors which are targetted by SDCC can be implemented in a 
4219 \emph on 
4220 f
4221 \emph default 
4222 ield 
4223 \emph on 
4224 p
4225 \emph default 
4226 rogrammable 
4227 \emph on 
4228 g
4229 \emph default 
4230 ate 
4231 \emph on 
4232 a
4233 \emph default 
4234 rray
4235 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4236
4237 \end_inset 
4238
4239
4240 \begin_inset Quotes srd
4241 \end_inset 
4242
4243  or 
4244 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4245
4246 \end_inset 
4247
4248
4249 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4250
4251 \end_inset 
4252
4253  
4254 \begin_inset Quotes sld
4255 \end_inset 
4256
4257 have you ever heard of an open source compiler that compiles a subset of
4258  C for an FPGA?
4259 \begin_inset Quotes srd
4260 \end_inset 
4261
4262  we expect you to have a quick look there and come back.
4263  If you read this you are on the right track.
4264 \layout Itemize
4265
4266 Some sections attribute more space to problems, restrictions and warnings
4267  than to the solution.
4268 \layout Itemize
4269
4270 The installation section and the section about the debugger is intimidating.
4271 \layout Itemize
4272
4273 There are still lots of typos and there are more different writing styles
4274  than pictures.
4275 \layout Section
4276
4277 Testing the SDCC Compiler
4278 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4279
4280 \end_inset 
4281
4282
4283 \layout Standard
4284
4285 The first thing you should do after installing your SDCC compiler is to
4286  see if it runs.
4287  Type 
4288 \family sans 
4289 \series bold 
4290 "sdcc -
4291 \begin_inset ERT
4292 status Collapsed
4293
4294 \layout Standard
4295
4296 \backslash 
4297 /
4298 \end_inset 
4299
4300 -version"
4301 \begin_inset LatexCommand \index{version}
4302
4303 \end_inset 
4304
4305
4306 \family default 
4307 \series default 
4308  at the prompt, and the program should run and output its version like:
4309  
4310 \newline 
4311
4312 \family typewriter 
4313 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4314  (UNIX)
4315 \layout Standard
4316
4317 If it doesn't run, or gives a message about not finding sdcc program, then
4318  you need to check over your installation.
4319  Make sure that the sdcc bin directory is in your executable search path
4320  defined by the PATH environment setting (
4321 \series medium 
4322 see 
4323 \series default 
4324 section 
4325 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4326
4327 \end_inset 
4328
4329 \SpecialChar ~
4330
4331 \series medium 
4332 Install trouble-shooting for suggestions
4333 \series default 
4334 ).
4335  Make sure that the sdcc program is in the bin folder, if not perhaps something
4336  did not install correctly.
4337 \newline 
4338
4339 \newline 
4340
4341 \series medium 
4342 SDCC 
4343 \series default 
4344 is commonly installed as described in section 
4345 \begin_inset Quotes sld
4346 \end_inset 
4347
4348 Install and search paths
4349 \begin_inset Quotes srd
4350 \end_inset 
4351
4352 .
4353 \newline 
4354
4355 \newline 
4356
4357 \series medium 
4358 Make sure the compiler works on a very simple example.
4359  Type in the following test.c program using your favorite 
4360 \series default 
4361 ASCII 
4362 \series medium 
4363 editor:
4364 \layout Verse
4365
4366
4367 \family typewriter 
4368 char test;
4369 \newline 
4370
4371 \newline 
4372 void main(void) {
4373 \newline 
4374 \SpecialChar ~
4375 \SpecialChar ~
4376 \SpecialChar ~
4377 \SpecialChar ~
4378 test=0;
4379 \newline 
4380 }
4381 \layout Standard
4382
4383
4384 \series medium 
4385 Compile this using the following command: 
4386 \family sans 
4387 \series bold 
4388 "sdcc -c test.c".
4389
4390 \family default 
4391 \series default 
4392  
4393 \series medium 
4394 If all goes well, the compiler will generate a test.asm and test.rel file.
4395  Congratulations, you've just compiled your first program with SDCC.
4396  We used the -c option to tell SDCC not to link the generated code, just
4397  to keep things simple for this step.
4398 \series default 
4399
4400 \newline 
4401
4402 \newline 
4403
4404 \series medium 
4405 The next step is to try it with the linker.
4406  Type in 
4407 \family sans 
4408 \series bold 
4409 "sdcc test.c
4410 \family default 
4411 \series default 
4412 "
4413 \series medium 
4414 .
4415  If all goes well the compiler will link with the libraries and produce
4416  a test.ihx output file.
4417  If this step fails
4418 \series default 
4419  
4420 \series medium 
4421 (no test.ihx, and the linker generates warnings), then the problem is most
4422  likely that 
4423 \series default 
4424 SDCC
4425 \series medium 
4426  cannot find the 
4427 \series default 
4428 /
4429 \series medium 
4430 usr/local/share/sdcc/lib directory
4431 \series default 
4432  
4433 \series medium 
4434 (see 
4435 \series default 
4436 section 
4437 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4438
4439 \end_inset 
4440
4441 \SpecialChar ~
4442
4443 \series medium 
4444 Install trouble-shooting for suggestions).
4445 \series default 
4446
4447 \newline 
4448
4449 \newline 
4450
4451 \series medium 
4452 The final test is to ensure 
4453 \series default 
4454 SDCC
4455 \series medium 
4456  can use the 
4457 \series default 
4458 standard
4459 \series medium 
4460  header files and libraries.
4461  Edit test.c and change it to the following:
4462 \layout Verse
4463
4464
4465 \family typewriter 
4466 #include <string.h>
4467 \newline 
4468
4469 \newline 
4470 char str1[10];
4471 \newline 
4472
4473 \newline 
4474 void main(void) {
4475 \newline 
4476 \SpecialChar ~
4477 \SpecialChar ~
4478 strcpy(str1, "testing");
4479 \newline 
4480 }
4481 \layout Standard
4482
4483
4484 \series medium 
4485 Compile this by typing 
4486 \family sans 
4487 \series bold 
4488 "sdcc test.c"
4489 \family default 
4490 \series medium 
4491 .
4492  This should generate a test.ihx output file, and it should give no warnings
4493  such as not finding the string.h file.
4494  If it cannot find the string.h file, then the problem is that 
4495 \series default 
4496 SDCC
4497 \series medium 
4498  cannot find the /usr/local/share/sdcc/include directory
4499 \series default 
4500  
4501 \series medium 
4502 (see the 
4503 \series default 
4504 section 
4505 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4506
4507 \end_inset 
4508
4509 \SpecialChar ~
4510
4511 \series medium 
4512 Install trouble-shooting section for suggestions).
4513
4514 \series default 
4515  Use option 
4516 \series bold 
4517 -
4518 \begin_inset ERT
4519 status Collapsed
4520
4521 \layout Standard
4522
4523 \backslash 
4524 /
4525 \end_inset 
4526
4527 -print-search-dirs
4528 \series default 
4529
4530 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4531
4532 \end_inset 
4533
4534  to find exactly where SDCC is looking for the include and lib files.
4535 \layout Section
4536
4537 Install Trouble-shooting
4538 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4539
4540 \end_inset 
4541
4542
4543 \begin_inset LatexCommand \index{Install trouble-shooting}
4544
4545 \end_inset 
4546
4547
4548 \layout Subsection
4549
4550 If SDCC does not build correctly
4551 \layout Standard
4552
4553 A thing to try is starting from scratch by unpacking the .tgz source package
4554  again in an empty directory.
4555  Configure it like:
4556 \newline 
4557
4558 \newline 
4559
4560 \family sans 
4561 \series bold 
4562 ./configure 2>&1 | tee configure.log
4563 \family default 
4564 \series default 
4565
4566 \newline 
4567
4568 \newline 
4569 and build it like:
4570 \newline 
4571
4572 \newline 
4573
4574 \family sans 
4575 \series bold 
4576 make 2>&1 | tee make.log
4577 \family default 
4578 \series default 
4579
4580 \newline 
4581
4582 \newline 
4583 If anything goes wrong, you can review the log files to locate the problem.
4584  Or a relevant part of this can be attached to an email that could be helpful
4585  when requesting help from the mailing list.
4586 \layout Subsection
4587
4588 What the 
4589 \begin_inset Quotes sld
4590 \end_inset 
4591
4592 ./configure
4593 \begin_inset Quotes srd
4594 \end_inset 
4595
4596  does
4597 \layout Standard
4598
4599 The 
4600 \begin_inset Quotes sld
4601 \end_inset 
4602
4603 ./configure
4604 \begin_inset Quotes srd
4605 \end_inset 
4606
4607  command is a script that analyzes your system and performs some configuration
4608  to ensure the source package compiles on your system.
4609  It will take a few minutes to run, and will compile a few tests to determine
4610  what compiler features are installed.
4611 \layout Subsection
4612
4613 What the 
4614 \begin_inset Quotes sld
4615 \end_inset 
4616
4617 make
4618 \begin_inset Quotes srd
4619 \end_inset 
4620
4621  does
4622 \layout Standard
4623
4624 This runs the GNU make tool, which automatically compiles all the source
4625  packages into the final installed binary executables.
4626 \layout Subsection
4627
4628 What the 
4629 \begin_inset Quotes sld
4630 \end_inset 
4631
4632 make install
4633 \begin_inset Quotes erd
4634 \end_inset 
4635
4636  command does.
4637 \layout Standard
4638
4639 This will install the compiler, other executables libraries and include
4640  files into the appropriate directories.
4641  See sections 
4642 \begin_inset LatexCommand \ref{sub:Install-paths}
4643
4644 \end_inset 
4645
4646 ,\SpecialChar ~
4647
4648 \begin_inset LatexCommand \ref{sub:Search-Paths}
4649
4650 \end_inset 
4651
4652 \SpecialChar ~
4653 about install and search paths.
4654 \newline 
4655 On most systems you will need super-user privileges to do this.
4656 \layout Section
4657
4658 Components of SDCC
4659 \layout Standard
4660
4661 SDCC is not just a compiler, but a collection of tools by various developers.
4662  These include linkers, assemblers, simulators and other components.
4663  Here is a summary of some of the components.
4664  Note that the included simulator and assembler have separate documentation
4665  which you can find in the source package in their respective directories.
4666  As SDCC grows to include support for other processors, other packages from
4667  various developers are included and may have their own sets of documentation.
4668 \newline 
4669
4670 \newline 
4671 You might want to look at the files which are installed in <installdir>.
4672  At the time of this writing, we find the following programs for gcc-builds:
4673 \newline 
4674  
4675 \newline 
4676 In <installdir>/bin:
4677 \layout Itemize
4678
4679 sdcc - The compiler.
4680 \layout Itemize
4681
4682 sdcpp - The C preprocessor.
4683 \layout Itemize
4684
4685 asx8051 - The assembler for 8051 type processors.
4686 \layout Itemize
4687
4688 as-z80
4689 \series bold 
4690
4691 \series default 
4692 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4693 \layout Itemize
4694
4695 aslink -The linker for 8051 type processors.
4696 \layout Itemize
4697
4698 link-z80
4699 \series bold 
4700
4701 \series default 
4702 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4703 \layout Itemize
4704
4705 s51 - The ucSim 8051 simulator.
4706 \layout Itemize
4707
4708 sdcdb - The source debugger.
4709 \layout Itemize
4710
4711 packihx - A tool to pack (compress) Intel hex files.
4712 \layout Standard
4713
4714 In <installdir>/share/sdcc/include
4715 \layout Itemize
4716
4717 the include files
4718 \layout Standard
4719
4720 In <installdir>/share/sdcc/lib
4721 \layout Itemize
4722
4723 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4724  relocatables.
4725 \layout Standard
4726
4727 In <installdir>/share/sdcc/doc
4728 \layout Itemize
4729
4730 the documentation
4731 \layout Standard
4732
4733 As development for other processors proceeds, this list will expand to include
4734  executables to support processors like AVR, PIC, etc.
4735 \layout Subsection
4736
4737 sdcc - The Compiler
4738 \layout Standard
4739
4740 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4741  the assembler and linkage editor.
4742 \layout Subsection
4743
4744 sdcpp - The C-Preprocessor
4745 \layout Standard
4746
4747 The preprocessor
4748 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4749
4750 \end_inset 
4751
4752  is a modified version of the GNU cpp
4753 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4754
4755 \end_inset 
4756
4757  preprocessor 
4758 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4759
4760 \end_inset 
4761
4762 .
4763  The C preprocessor is used to pull in #include sources, process #ifdef
4764  statements, #defines and so on.
4765 \layout Subsection
4766
4767 as
4768 \emph on 
4769 xxxx
4770 \emph default 
4771 , aslink, link-
4772 \emph on 
4773 xxx
4774 \emph default 
4775  - The Assemblers and Linkage Editors
4776 \layout Standard
4777
4778 This is retargettable assembler & linkage editor, it was developed by Alan
4779  Baldwin.
4780  John Hartman created the version for 8051, and I (Sandeep) have made some
4781  enhancements and bug fixes for it to work properly with SDCC.
4782 \layout Subsection
4783
4784 s51 - The Simulator
4785 \layout Standard
4786
4787 S51
4788 \begin_inset LatexCommand \index{s51}
4789
4790 \end_inset 
4791
4792  is a freeware, opensource simulator developed by Daniel Drotos.
4793  The simulator is built as part of the build process.
4794  For more information visit Daniel's web site at: 
4795 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4796
4797 \end_inset 
4798
4799 .
4800  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4801  XA51 family.
4802 \layout Subsection
4803
4804 sdcdb - Source Level Debugger
4805 \layout Standard
4806
4807 SDCDB
4808 \begin_inset LatexCommand \index{SDCDB (debugger)}
4809
4810 \end_inset 
4811
4812  is the companion source level debugger.
4813  More about SDCDB in section 
4814 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4815
4816 \end_inset 
4817
4818 .
4819  The current version of the debugger uses Daniel's Simulator S51
4820 \begin_inset LatexCommand \index{s51}
4821
4822 \end_inset 
4823
4824 , but can be easily changed to use other simulators.
4825 \layout Chapter
4826
4827 Using SDCC
4828 \layout Section
4829
4830 Compiling
4831 \layout Subsection
4832
4833 Single Source File Projects
4834 \layout Standard
4835
4836 For single source file 8051 projects the process is very simple.
4837  Compile your programs with the following command 
4838 \family sans 
4839 \series bold 
4840 "sdcc sourcefile.c".
4841
4842 \family default 
4843 \series default 
4844  This will compile, assemble and link your source file.
4845  Output files are as follows:
4846 \layout Itemize
4847
4848 sourcefile.asm
4849 \begin_inset LatexCommand \index{<file>.asm}
4850
4851 \end_inset 
4852
4853  - Assembler source
4854 \begin_inset LatexCommand \index{Assembler source}
4855
4856 \end_inset 
4857
4858  file created by the compiler
4859 \layout Itemize
4860
4861 sourcefile.lst
4862 \begin_inset LatexCommand \index{<file>.lst}
4863
4864 \end_inset 
4865
4866  - Assembler listing
4867 \begin_inset LatexCommand \index{Assembler listing}
4868
4869 \end_inset 
4870
4871  file created by the Assembler
4872 \layout Itemize
4873
4874 sourcefile.rst
4875 \begin_inset LatexCommand \index{<file>.rst}
4876
4877 \end_inset 
4878
4879  - Assembler listing
4880 \begin_inset LatexCommand \index{Assembler listing}
4881
4882 \end_inset 
4883
4884  file updated with linkedit information, created by linkage editor
4885 \layout Itemize
4886
4887 sourcefile.sym
4888 \begin_inset LatexCommand \index{<file>.sym}
4889
4890 \end_inset 
4891
4892  - symbol listing
4893 \begin_inset LatexCommand \index{Symbol listing}
4894
4895 \end_inset 
4896
4897  for the sourcefile, created by the assembler
4898 \layout Itemize
4899
4900 sourcefile.rel
4901 \begin_inset LatexCommand \index{<file>.rel}
4902
4903 \end_inset 
4904
4905  or sourcefile.o
4906 \begin_inset LatexCommand \index{<file>.o}
4907
4908 \end_inset 
4909
4910  - Object file
4911 \begin_inset LatexCommand \index{Object file}
4912
4913 \end_inset 
4914
4915  created by the assembler, input to Linkage editor
4916 \layout Itemize
4917
4918 sourcefile.map
4919 \begin_inset LatexCommand \index{<file>.map}
4920
4921 \end_inset 
4922
4923  - The memory map
4924 \begin_inset LatexCommand \index{Memory map}
4925
4926 \end_inset 
4927
4928  for the load module, created by the Linker
4929 \layout Itemize
4930
4931 sourcefile.mem
4932 \begin_inset LatexCommand \index{<file>.mem}
4933
4934 \end_inset 
4935
4936  - A file with a summary of the memory usage
4937 \layout Itemize
4938
4939 sourcefile.ihx
4940 \begin_inset LatexCommand \index{<file>.ihx}
4941
4942 \end_inset 
4943
4944  - The load module in Intel hex format
4945 \begin_inset LatexCommand \index{Intel hex format}
4946
4947 \end_inset 
4948
4949  (you can select the Motorola S19 format
4950 \begin_inset LatexCommand \index{Motorola S19 format}
4951
4952 \end_inset 
4953
4954  with -
4955 \begin_inset ERT
4956 status Collapsed
4957
4958 \layout Standard
4959
4960 \backslash 
4961 /
4962 \end_inset 
4963
4964 -out-fmt-s19
4965 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4966
4967 \end_inset 
4968
4969 .
4970  If you need another format you might want to use 
4971 \family sans 
4972 \shape italic 
4973 objdump
4974 \family default 
4975 \shape default 
4976
4977 \begin_inset LatexCommand \index{objdump (tool)}
4978
4979 \end_inset 
4980
4981  or
4982 \family sans 
4983 \shape italic 
4984  srecord
4985 \family default 
4986 \shape default 
4987
4988 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4989
4990 \end_inset 
4991
4992 ).
4993  Both formats are documented in the documentation of srecord
4994 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4995
4996 \end_inset 
4997
4998
4999 \layout Itemize
5000
5001 sourcefile.adb
5002 \begin_inset LatexCommand \index{<file>.adb}
5003
5004 \end_inset 
5005
5006  - An intermediate file containing debug information needed to create the
5007  .cdb file (with -
5008 \begin_inset ERT
5009 status Collapsed
5010
5011 \layout Standard
5012
5013 \backslash 
5014 /
5015 \end_inset 
5016
5017 -debug
5018 \begin_inset LatexCommand \index{-\/-debug}
5019
5020 \end_inset 
5021
5022
5023 \layout Itemize
5024
5025 sourcefile.cdb
5026 \begin_inset LatexCommand \index{<file>.cdb}
5027
5028 \end_inset 
5029
5030  - An optional file (with -
5031 \begin_inset ERT
5032 status Collapsed
5033
5034 \layout Standard
5035
5036 \backslash 
5037 /
5038 \end_inset 
5039
5040 -debug) containing debug information.
5041  The format is documented in cdbfileformat.pdf
5042 \layout Itemize
5043
5044 sourcefile.
5045  - (no extension)
5046 \begin_inset LatexCommand \index{<file> (no extension)}
5047
5048 \end_inset 
5049
5050  An optional AOMF or AOMF51
5051 \begin_inset LatexCommand \index{AOMF, AOMF51}
5052
5053 \end_inset 
5054
5055  
5056 \begin_inset LatexCommand \label{OMF file}
5057
5058 \end_inset 
5059
5060 file containing debug information (generated with option -
5061 \begin_inset ERT
5062 status Collapsed
5063
5064 \layout Standard
5065
5066 \backslash 
5067 /
5068 \end_inset 
5069
5070 -debug).
5071  The (Intel)
5072 \emph on 
5073  a
5074 \emph default 
5075 bsolute 
5076 \emph on 
5077 o
5078 \emph default 
5079 bject 
5080 \emph on 
5081 m
5082 \emph default 
5083 odule 
5084 \emph on 
5085 f
5086 \emph default 
5087 ormat is commonly used by third party tools (debuggers
5088 \begin_inset LatexCommand \index{Debugger}
5089
5090 \end_inset 
5091
5092 , simulators, emulators)
5093 \layout Itemize
5094
5095 sourcefile.dump*
5096 \begin_inset LatexCommand \index{<file>.dump*}
5097
5098 \end_inset 
5099
5100  - Dump file to debug the compiler it self (generated with option -
5101 \begin_inset ERT
5102 status Collapsed
5103
5104 \layout Standard
5105
5106 \backslash 
5107 /
5108 \end_inset 
5109
5110 -dumpall) (see section 
5111 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5112
5113 \end_inset 
5114
5115 \SpecialChar ~
5116  and section 
5117 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5118
5119 \end_inset 
5120
5121 \SpecialChar ~
5122
5123 \begin_inset Quotes sld
5124 \end_inset 
5125
5126 Anatomy of the compiler
5127 \begin_inset Quotes srd
5128 \end_inset 
5129
5130 ).
5131 \layout Subsection
5132
5133 Postprocessing the Intel Hex
5134 \begin_inset LatexCommand \index{Intel hex format}
5135
5136 \end_inset 
5137
5138  file
5139 \layout Standard
5140
5141 In most cases this won't be needed but the Intel Hex file
5142 \begin_inset LatexCommand \index{<file>.ihx}
5143
5144 \end_inset 
5145
5146  which is generated by SDCC might include lines of varying length and the
5147  addresses within the file are not guaranteed to be strictly ascending.
5148  If your toolchain or a bootloader does not like this you can use the tool
5149  
5150 \family typewriter 
5151 packihx
5152 \family default 
5153
5154 \begin_inset LatexCommand \index{packihx (tool)}
5155
5156 \end_inset 
5157
5158  which is part of the SDCC distribution: 
5159 \newline 
5160
5161 \newline 
5162
5163 \family sans 
5164 \series bold 
5165  packihx sourcefile.ihx >sourcefile.hex
5166 \family default 
5167 \series default 
5168
5169 \newline 
5170
5171 \newline 
5172 The separately available
5173 \emph on 
5174  srecord
5175 \emph default 
5176
5177 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5178
5179 \end_inset 
5180
5181  package additionally allows to set undefined locations to a predefined
5182  value, to insert checksums
5183 \begin_inset LatexCommand \index{checksum}
5184
5185 \end_inset 
5186
5187  of various flavours (crc, add, xor) and to perform other manipulations
5188  (convert, split, crop, offset, ...).
5189  
5190 \newline 
5191
5192 \newline 
5193
5194 \family sans 
5195 \series bold 
5196 srec_cat\SpecialChar ~
5197 \SpecialChar ~
5198 sourcefile.ihx -intel\SpecialChar ~
5199 \SpecialChar ~
5200 -o sourcefile.hex -intel
5201 \newline 
5202
5203 \newline 
5204
5205 \family default 
5206 \series default 
5207 An example for a more complex command line
5208 \begin_inset Foot
5209 collapsed false
5210
5211 \layout Standard
5212
5213 the command backfills
5214 \begin_inset LatexCommand \index{backfill unused memory}
5215
5216 \end_inset 
5217
5218  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5219  block is zero.
5220  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5221  will be interpreted as an 
5222 \family typewriter 
5223 lcall
5224 \family default 
5225  to address 
5226 \family typewriter 
5227 0x1212
5228 \family default 
5229  (where an emergency routine could sit).
5230 \end_inset 
5231
5232  could look like:
5233 \newline 
5234
5235 \newline 
5236
5237 \family sans 
5238 \series bold 
5239 \size footnotesize 
5240 srec_cat\SpecialChar ~
5241 sourcefile.ihx -intel\SpecialChar ~
5242 \SpecialChar ~
5243 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5244 -little-endian-checksum-nega
5245 tive 0xfffe 0x02 0x02\SpecialChar ~
5246 \SpecialChar ~
5247 -o sourcefile.hex -intel
5248 \size default 
5249
5250 \newline 
5251
5252 \newline 
5253
5254 \family default 
5255 \series default 
5256 The srecord package is available at 
5257 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5258
5259 \end_inset 
5260
5261  .
5262 \layout Subsection
5263
5264 Projects with Multiple Source Files
5265 \layout Standard
5266
5267 SDCC can compile only ONE file at a time.
5268  Let us for example assume that you have a project containing the following
5269  files:
5270 \newline 
5271
5272 \newline 
5273 foo1.c (contains some functions)
5274 \newline 
5275 foo2.c (contains some more functions)
5276 \newline 
5277 foomain.c (contains more functions and the function main)
5278 \newline 
5279
5280 \size footnotesize 
5281
5282 \newline 
5283
5284 \size default 
5285 The first two files will need to be compiled separately with the commands:
5286 \size footnotesize 
5287  
5288 \size default 
5289
5290 \newline 
5291
5292 \newline 
5293
5294 \family sans 
5295 \series bold 
5296 sdcc\SpecialChar ~
5297 -c\SpecialChar ~
5298 foo1.c
5299 \family default 
5300 \series default 
5301 \size footnotesize 
5302
5303 \newline 
5304
5305 \family sans 
5306 \series bold 
5307 \size default 
5308 sdcc\SpecialChar ~
5309 -c\SpecialChar ~
5310 foo2.c
5311 \family default 
5312 \series default 
5313
5314 \newline 
5315
5316 \newline 
5317 Then compile the source file containing the 
5318 \emph on 
5319 main()
5320 \emph default 
5321  function and link
5322 \begin_inset LatexCommand \index{Linker}
5323
5324 \end_inset 
5325
5326  the files together with the following command: 
5327 \newline 
5328
5329 \newline 
5330
5331 \family sans 
5332 \series bold 
5333 sdcc\SpecialChar ~
5334 foomain.c\SpecialChar ~
5335 foo1.rel\SpecialChar ~
5336 foo2.rel
5337 \family default 
5338 \series default 
5339
5340 \begin_inset LatexCommand \index{<file>.rel}
5341
5342 \end_inset 
5343
5344
5345 \newline 
5346
5347 \newline 
5348 Alternatively, 
5349 \emph on 
5350 foomain.c 
5351 \emph default 
5352 can be separately compiled as well: 
5353 \family sans 
5354 \series bold 
5355
5356 \newline 
5357
5358 \newline 
5359 sdcc\SpecialChar ~
5360 -c\SpecialChar ~
5361 foomain.c
5362 \newline 
5363 sdcc foomain.rel foo1.rel foo2.rel
5364 \newline 
5365
5366 \newline 
5367
5368 \family default 
5369 \series default 
5370 The file containing the 
5371 \emph on 
5372 main()
5373 \emph default 
5374  function
5375 \emph on 
5376  
5377 \emph default 
5378 \noun on 
5379 must
5380 \noun default 
5381  be the 
5382 \noun on 
5383 first
5384 \noun default 
5385  file specified in the command line, since the linkage editor processes
5386  file in the order they are presented to it.
5387  The linker is invoked from SDCC using a script file with extension .lnk
5388 \begin_inset LatexCommand \index{<file>.lnk}
5389
5390 \end_inset 
5391
5392 .
5393  You can view this file to troubleshoot linking problems such as those arising
5394  from missing libraries.
5395 \layout Subsection
5396
5397 Projects with Additional Libraries
5398 \begin_inset LatexCommand \index{Libraries}
5399
5400 \end_inset 
5401
5402
5403 \layout Standard
5404
5405 Some reusable routines may be compiled into a library, see the documentation
5406  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5407  for how to create a 
5408 \emph on 
5409 .lib
5410 \begin_inset LatexCommand \index{<file>.lib}
5411
5412 \end_inset 
5413
5414
5415 \emph default 
5416  library file.
5417  Libraries created in this manner can be included in the command line.
5418  Make sure you include the -L <library-path> option to tell the linker where
5419  to look for these files if they are not in the current directory.
5420  Here is an example, assuming you have the source file 
5421 \emph on 
5422 foomain.c
5423 \emph default 
5424  and a library
5425 \emph on 
5426  foolib.lib
5427 \emph default 
5428  in the directory 
5429 \emph on 
5430 mylib
5431 \emph default 
5432  (if that is not the same as your current project):
5433 \newline 
5434
5435 \newline 
5436
5437 \family sans 
5438 \series bold 
5439 sdcc foomain.c foolib.lib -L mylib
5440 \newline 
5441
5442 \newline 
5443
5444 \family default 
5445 \series default 
5446 Note here that
5447 \emph on 
5448  mylib
5449 \emph default 
5450  must be an absolute path name.
5451 \newline 
5452
5453 \newline 
5454 The most efficient way to use libraries is to keep separate modules in separate
5455  source files.
5456  The lib file now should name all the modules.rel
5457 \begin_inset LatexCommand \index{<file>.rel}
5458
5459 \end_inset 
5460
5461  files.
5462  For an example see the standard library file 
5463 \emph on 
5464 libsdcc.lib
5465 \emph default 
5466  in the directory <installdir>/share/lib/small.
5467 \layout Subsection
5468
5469 Using sdcclib to Create and Manage Libraries
5470 \begin_inset LatexCommand \index{sdcclib}
5471
5472 \end_inset 
5473
5474
5475 \layout Standard
5476
5477 Alternatively, instead of having a .rel file for each entry on the library
5478  file as described in the preceding section, sdcclib can be used to embed
5479  all the modules belonging to such library in the library file itself.
5480  This results in a larger library file, but it greatly reduces the number
5481  of disk files accessed by the linker.
5482   Additionally, the packed library file contains an index of all include
5483  modules and symbols that significantly speeds up the linking process.
5484  To display a list of options supported by sdcclib type:
5485 \newline 
5486
5487 \layout Standard
5488
5489
5490 \family sans 
5491 \series bold 
5492 sdcclib -?
5493 \begin_inset LatexCommand \index{sdcclib}
5494
5495 \end_inset 
5496
5497
5498 \newline 
5499
5500 \newline 
5501
5502 \family default 
5503 \series default 
5504 To create a new library file, start by compiling all the required modules.
5505  For example:
5506 \newline 
5507
5508 \layout Standard
5509
5510
5511 \family sans 
5512 \series bold 
5513 sdcc -c _divsint.c
5514 \layout Standard
5515
5516
5517 \family sans 
5518 \series bold 
5519 sdcc -c _divuint.c
5520 \layout Standard
5521
5522
5523 \family sans 
5524 \series bold 
5525 sdcc -c _modsint.c
5526 \layout Standard
5527
5528
5529 \family sans 
5530 \series bold 
5531 sdcc -c _moduint.c
5532 \layout Standard
5533
5534
5535 \family sans 
5536 \series bold 
5537 sdcc -c _mulint.c
5538 \newline 
5539
5540 \layout Standard
5541
5542 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5543  and _mulint.rel.
5544  The next step is to add the .rel files to the library file:
5545 \newline 
5546
5547 \layout Standard
5548
5549
5550 \family sans 
5551 \series bold 
5552 sdcclib libint.lib _divsint.rel
5553 \family default 
5554
5555 \begin_inset LatexCommand \index{sdcclib}
5556
5557 \end_inset 
5558
5559
5560 \layout Standard
5561
5562
5563 \family sans 
5564 \series bold 
5565 sdcclib libint.lib _divuint.rel
5566 \layout Standard
5567
5568
5569 \family sans 
5570 \series bold 
5571 sdcclib libint.lib _modsint.rel
5572 \layout Standard
5573
5574
5575 \family sans 
5576 \series bold 
5577 sdcclib libint.lib _moduint.rel
5578 \layout Standard
5579
5580
5581 \family sans 
5582 \series bold 
5583 sdcclib libint.lib _mulint.rel
5584 \series default 
5585
5586 \newline 
5587
5588 \layout Standard
5589
5590 If the file already exists in the library, it will be replaced.
5591  To see what modules and symbols are included in the library, options -s
5592  and -m are available.
5593  For example:
5594 \newline 
5595
5596 \newline 
5597
5598 \family sans 
5599 \series bold 
5600 sdcclib -s libint.lib
5601 \family default 
5602
5603 \begin_inset LatexCommand \index{sdcclib}
5604
5605 \end_inset 
5606
5607
5608 \newline 
5609
5610 \family typewriter 
5611 \series default 
5612 _divsint.rel:
5613 \layout Standard
5614
5615
5616 \family typewriter 
5617 __divsint_a_1_1
5618 \layout Standard
5619
5620
5621 \family typewriter 
5622 __divsint_PARM_2
5623 \layout Standard
5624
5625
5626 \family typewriter 
5627 __divsint
5628 \newline 
5629 _divuint.rel:
5630 \layout Standard
5631
5632
5633 \family typewriter 
5634 __divuint_a_1_1
5635 \layout Standard
5636
5637
5638 \family typewriter 
5639 __divuint_PARM_2
5640 \layout Standard
5641
5642
5643 \family typewriter 
5644 __divuint_reste_1_1
5645 \layout Standard
5646
5647
5648 \family typewriter 
5649 __divuint_count_1_1
5650 \layout Standard
5651
5652
5653 \family typewriter 
5654 __divuint
5655 \newline 
5656 _modsint.rel:
5657 \layout Standard
5658
5659
5660 \family typewriter 
5661 __modsint_a_1_1
5662 \layout Standard
5663
5664
5665 \family typewriter 
5666 __modsint_PARM_2
5667 \layout Standard
5668
5669
5670 \family typewriter 
5671 __modsint
5672 \newline 
5673 _moduint.rel:
5674 \layout Standard
5675
5676
5677 \family typewriter 
5678 __moduint_a_1_1
5679 \layout Standard
5680
5681
5682 \family typewriter 
5683 __moduint_PARM_2
5684 \layout Standard
5685
5686
5687 \family typewriter 
5688 __moduint_count_1_1
5689 \layout Standard
5690
5691
5692 \family typewriter 
5693 __moduint
5694 \newline 
5695 _mulint.rel:
5696 \layout Standard
5697
5698
5699 \family typewriter 
5700 __mulint_PARM_2
5701 \layout Standard
5702
5703
5704 \family typewriter 
5705 __mulint
5706 \family default 
5707 \series bold 
5708
5709 \newline 
5710
5711 \layout Standard
5712 \added_space_bottom bigskip 
5713 If the source files are compiled using -
5714 \begin_inset ERT
5715 status Collapsed
5716
5717 \layout Standard
5718
5719 \backslash 
5720 /
5721 \end_inset 
5722
5723 -debug
5724 \begin_inset LatexCommand \index{-\/-debug}
5725
5726 \end_inset 
5727
5728 , the corresponding debug information file .adb will be include in the library
5729  file as well.
5730  The library files created with sdcclib are plain text files, so they can
5731  be viewed with a text editor.
5732  It is not recomended to modify a library file created with sdcclib using
5733  a text editor, as there are file indexes numbers located accross the file
5734  used by the linker to quickly locate the required module to link.
5735  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5736  it can be safely deleted, since all the information required for linking
5737  is embedded in the library file itself.
5738  Library files created using sdcclib are used as described in the preceding
5739  sections.
5740 \layout Section
5741
5742 Command Line Options
5743 \begin_inset LatexCommand \index{Command Line Options}
5744
5745 \end_inset 
5746
5747
5748 \layout Subsection
5749
5750 Processor Selection Options
5751 \begin_inset LatexCommand \index{Options processor selection}
5752
5753 \end_inset 
5754
5755
5756 \begin_inset LatexCommand \index{Processor selection options}
5757
5758 \end_inset 
5759
5760
5761 \layout List
5762 \labelwidthstring 00.00.0000
5763
5764
5765 \series bold 
5766 -mmcs51
5767 \begin_inset LatexCommand \index{-mmcs51}
5768
5769 \end_inset 
5770
5771
5772 \series default 
5773  Generate code for the Intel MCS51
5774 \begin_inset LatexCommand \index{MCS51}
5775
5776 \end_inset 
5777
5778  family of processors.
5779  This is the default processor target.
5780 \layout List
5781 \labelwidthstring 00.00.0000
5782
5783
5784 \series bold 
5785 -mds390
5786 \begin_inset LatexCommand \index{-mds390}
5787
5788 \end_inset 
5789
5790
5791 \series default 
5792  Generate code for the Dallas DS80C390
5793 \begin_inset LatexCommand \index{DS80C390}
5794
5795 \end_inset 
5796
5797  processor.
5798 \layout List
5799 \labelwidthstring 00.00.0000
5800
5801
5802 \series bold 
5803 -mds400
5804 \begin_inset LatexCommand \index{-mds400}
5805
5806 \end_inset 
5807
5808
5809 \series default 
5810  Generate code for the Dallas DS80C400
5811 \begin_inset LatexCommand \index{DS80C400}
5812
5813 \end_inset 
5814
5815  processor.
5816 \layout List
5817 \labelwidthstring 00.00.0000
5818
5819
5820 \series bold 
5821 -mhc08
5822 \begin_inset LatexCommand \index{-mhc08}
5823
5824 \end_inset 
5825
5826
5827 \series default 
5828  Generate code for the Freescale/Motorola HC08
5829 \begin_inset LatexCommand \index{HC08}
5830
5831 \end_inset 
5832
5833  family of processors.
5834 \layout List
5835 \labelwidthstring 00.00.0000
5836
5837
5838 \series bold 
5839 -mz80
5840 \begin_inset LatexCommand \index{-mz80}
5841
5842 \end_inset 
5843
5844
5845 \series default 
5846  Generate code for the Zilog Z80
5847 \begin_inset LatexCommand \index{Z80}
5848
5849 \end_inset 
5850
5851  family of processors.
5852 \layout List
5853 \labelwidthstring 00.00.0000
5854
5855
5856 \series bold 
5857 -mgbz80
5858 \begin_inset LatexCommand \index{-mgbz80}
5859
5860 \end_inset 
5861
5862
5863 \series default 
5864  Generate code for the GameBoy Z80
5865 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5866
5867 \end_inset 
5868
5869  processor (Not actively maintained).
5870 \layout List
5871 \labelwidthstring 00.00.0000
5872
5873
5874 \series bold 
5875 -mavr
5876 \begin_inset LatexCommand \index{-mavr}
5877
5878 \end_inset 
5879
5880
5881 \series default 
5882  Generate code for the Atmel AVR
5883 \begin_inset LatexCommand \index{AVR}
5884
5885 \end_inset 
5886
5887  processor (Not maintained, not complete).
5888  AVR users should probably have a look at winavr 
5889 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5890
5891 \end_inset 
5892
5893  or 
5894 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5895
5896 \end_inset 
5897
5898 .
5899 \layout Comment
5900
5901 I think it is fair to direct users there for now.
5902  Open source is also about avoiding unnecessary work .
5903  But I didn't find the 'official' link.
5904 \layout List
5905 \labelwidthstring 00.00.0000
5906
5907
5908 \series bold 
5909 -mpic14
5910 \begin_inset LatexCommand \index{-mpic14}
5911
5912 \end_inset 
5913
5914
5915 \series default 
5916  Generate code for the Microchip PIC 14
5917 \begin_inset LatexCommand \index{PIC14}
5918
5919 \end_inset 
5920
5921 -bit processors (p16f84 and variants.
5922  In development, not complete).
5923 \layout Comment
5924
5925 p16f627 p16f628 p16f84 p16f873 p16f877?
5926 \layout List
5927 \labelwidthstring 00.00.0000
5928
5929
5930 \series bold 
5931 -mpic16
5932 \begin_inset LatexCommand \index{-mpic16}
5933
5934 \end_inset 
5935
5936
5937 \series default 
5938  Generate code for the Microchip PIC 16
5939 \begin_inset LatexCommand \index{PIC16}
5940
5941 \end_inset 
5942
5943 -bit processors (p18f452 and variants.
5944  In development, not complete).
5945 \layout List
5946 \labelwidthstring 00.00.0000
5947
5948
5949 \series bold 
5950 -mtlcs900h
5951 \series default 
5952  Generate code for the Toshiba TLCS-900H
5953 \begin_inset LatexCommand \index{TLCS-900H}
5954
5955 \end_inset 
5956
5957  processor (Not maintained, not complete).
5958 \layout List
5959 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5960
5961
5962 \series bold 
5963 -mxa51
5964 \begin_inset LatexCommand \index{-mxa51}
5965
5966 \end_inset 
5967
5968
5969 \series default 
5970  Generate code for the Phillips XA51
5971 \begin_inset LatexCommand \index{XA51}
5972
5973 \end_inset 
5974
5975  processor (Not maintained, not complete).
5976 \layout Subsection
5977
5978 Preprocessor Options
5979 \begin_inset LatexCommand \index{Options preprocessor}
5980
5981 \end_inset 
5982
5983
5984 \begin_inset LatexCommand \index{Preprocessor options}
5985
5986 \end_inset 
5987
5988
5989 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5990
5991 \end_inset 
5992
5993
5994 \layout List
5995 \labelwidthstring 00.00.0000
5996
5997
5998 \series bold 
5999 -I<path>
6000 \begin_inset LatexCommand \index{-I<path>}
6001
6002 \end_inset 
6003
6004
6005 \series default 
6006  The additional location where the pre processor will look for <..h> or 
6007 \begin_inset Quotes eld
6008 \end_inset 
6009
6010 ..h
6011 \begin_inset Quotes erd
6012 \end_inset 
6013
6014  files.
6015 \layout List
6016 \labelwidthstring 00.00.0000
6017
6018
6019 \series bold 
6020 -D<macro[=value]>
6021 \begin_inset LatexCommand \index{-D<macro[=value]>}
6022
6023 \end_inset 
6024
6025
6026 \series default 
6027  Command line definition of macros.
6028  Passed to the preprocessor.
6029 \layout List
6030 \labelwidthstring 00.00.0000
6031
6032
6033 \series bold 
6034 -M
6035 \begin_inset LatexCommand \index{-M}
6036
6037 \end_inset 
6038
6039
6040 \series default 
6041  Tell the preprocessor to output a rule suitable for make describing the
6042  dependencies of each object file.
6043  For each source file, the preprocessor outputs one make-rule whose target
6044  is the object file name for that source file and whose dependencies are
6045  all the files `#include'd in it.
6046  This rule may be a single line or may be continued with `
6047 \backslash 
6048 '-newline if it is long.
6049  The list of rules is printed on standard output instead of the preprocessed
6050  C program.
6051  `-M' implies `-E
6052 \begin_inset LatexCommand \index{-E}
6053
6054 \end_inset 
6055
6056 '.
6057 \layout List
6058 \labelwidthstring 00.00.0000
6059
6060
6061 \series bold 
6062 -C
6063 \begin_inset LatexCommand \index{-C}
6064
6065 \end_inset 
6066
6067
6068 \series default 
6069  Tell the preprocessor not to discard comments.
6070  Used with the `-E' option.
6071 \layout List
6072 \labelwidthstring 00.00.0000
6073
6074
6075 \series bold 
6076 -MM
6077 \begin_inset LatexCommand \index{-MM}
6078
6079 \end_inset 
6080
6081
6082 \size large 
6083 \bar under 
6084  
6085 \series default 
6086 \size default 
6087 \bar default 
6088 Like `-M' but the output mentions only the user header files included with
6089  `#include 
6090 \begin_inset Quotes eld
6091 \end_inset 
6092
6093 file"'.
6094  System header files included with `#include <file>' are omitted.
6095 \layout List
6096 \labelwidthstring 00.00.0000
6097
6098
6099 \series bold 
6100 -Aquestion(answer)
6101 \begin_inset LatexCommand \index{-Aquestion(answer)}
6102
6103 \end_inset 
6104
6105
6106 \series default 
6107  Assert the answer answer for question, in case it is tested with a preprocessor
6108  conditional such as `#if #question(answer)'.
6109  `-A-' disables the standard assertions that normally describe the target
6110  machine.
6111 \layout List
6112 \labelwidthstring 00.00.0000
6113
6114
6115 \series bold 
6116 -Umacro
6117 \begin_inset LatexCommand \index{-Umacro}
6118
6119 \end_inset 
6120
6121
6122 \series default 
6123  Undefine macro macro.
6124  `-U' options are evaluated after all `-D' options, but before any `-include'
6125  and `-imacros' options.
6126 \layout List
6127 \labelwidthstring 00.00.0000
6128
6129
6130 \series bold 
6131 -dM
6132 \begin_inset LatexCommand \index{-dM}
6133
6134 \end_inset 
6135
6136
6137 \series default 
6138  Tell the preprocessor to output only a list of the macro definitions that
6139  are in effect at the end of preprocessing.
6140  Used with the `-E' option.
6141 \layout List
6142 \labelwidthstring 00.00.0000
6143
6144
6145 \series bold 
6146 -dD
6147 \begin_inset LatexCommand \index{-dD}
6148
6149 \end_inset 
6150
6151
6152 \series default 
6153  Tell the preprocessor to pass all macro definitions into the output, in
6154  their proper sequence in the rest of the output.
6155 \layout List
6156 \labelwidthstring 00.00.0000
6157
6158
6159 \series bold 
6160 -dN
6161 \begin_inset LatexCommand \index{-dN}
6162
6163 \end_inset 
6164
6165
6166 \size large 
6167 \bar under 
6168  
6169 \series default 
6170 \size default 
6171 \bar default 
6172 Like `-dD' except that the macro arguments and contents are omitted.
6173  Only `#define name' is included in the output.
6174 \layout List
6175 \labelwidthstring 00.00.0000
6176
6177
6178 \series bold 
6179 -pedantic-parse-number
6180 \begin_inset LatexCommand \index{-pedantic-parse-number}
6181
6182 \end_inset 
6183
6184
6185 \size large 
6186 \bar under 
6187  
6188 \series default 
6189 \size default 
6190 \bar default 
6191 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6192  and the macro LO_B(3) gets expanded.
6193  See also #pragma pedantic_parse_number in section
6194 \begin_inset LatexCommand \ref{sec:Pragmas}
6195
6196 \end_inset 
6197
6198  
6199 \emph on 
6200 Note: this functionality is not in conformance with standard!
6201 \layout List
6202 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6203
6204
6205 \series bold 
6206 -Wp\SpecialChar ~
6207 preprocessorOption[,preprocessorOption]
6208 \series default 
6209
6210 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6211
6212 \end_inset 
6213
6214 ...
6215  Pass the preprocessorOption to the preprocessor 
6216 \family typewriter 
6217 sdcpp
6218 \family default 
6219
6220 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6221
6222 \end_inset 
6223
6224 .
6225  SDCC uses an adapted version of the preprocessor 
6226 \emph on 
6227 cpp
6228 \emph default 
6229  of the GNU Compiler Collection
6230 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6231
6232 \end_inset 
6233
6234  (
6235 \emph on 
6236 gcc
6237 \emph default 
6238  
6239 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6240
6241 \end_inset 
6242
6243 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6244 4.1.1\SpecialChar ~
6245 CPP\SpecialChar ~
6246 Manual
6247  at 
6248 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6249
6250 \end_inset 
6251
6252 .
6253 \layout Subsection
6254
6255 Linker Options
6256 \begin_inset LatexCommand \index{Options linker}
6257
6258 \end_inset 
6259
6260
6261 \begin_inset LatexCommand \index{Linker options}
6262
6263 \end_inset 
6264
6265
6266 \layout List
6267 \labelwidthstring 00.00.0000
6268
6269
6270 \series bold 
6271 -L\SpecialChar ~
6272 -
6273 \series default 
6274
6275 \begin_inset ERT
6276 status Collapsed
6277
6278 \layout Standard
6279
6280 \backslash 
6281 /
6282 \end_inset 
6283
6284
6285 \series bold 
6286 -lib-path
6287 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6288
6289 \end_inset 
6290
6291
6292 \begin_inset LatexCommand \index{-L -\/-lib-path}
6293
6294 \end_inset 
6295
6296
6297 \series default 
6298 \SpecialChar ~
6299 <absolute path to additional libraries> This option is passed to the linkage
6300  editor's additional libraries
6301 \begin_inset LatexCommand \index{Libraries}
6302
6303 \end_inset 
6304
6305  search path.
6306  The path name must be absolute.
6307  Additional library files may be specified in the command line.
6308  See section Compiling programs for more details.
6309 \layout List
6310 \labelwidthstring 00.00.0000
6311
6312
6313 \series bold 
6314 -
6315 \begin_inset ERT
6316 status Collapsed
6317
6318 \layout Standard
6319
6320 \backslash 
6321 /
6322 \end_inset 
6323
6324 -xram-loc
6325 \series default 
6326
6327 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6328
6329 \end_inset 
6330
6331 \SpecialChar ~
6332 <Value> The start location of the external ram
6333 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6334
6335 \end_inset 
6336
6337 , default value is 0.
6338  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6339 \begin_inset ERT
6340 status Collapsed
6341
6342 \layout Standard
6343
6344 \backslash 
6345 /
6346 \end_inset 
6347
6348 -xram-loc 0x8000 or -
6349 \begin_inset ERT
6350 status Collapsed
6351
6352 \layout Standard
6353
6354 \backslash 
6355 /
6356 \end_inset 
6357
6358 -xram-loc 32768.
6359 \layout List
6360 \labelwidthstring 00.00.0000
6361
6362
6363 \series bold 
6364 -
6365 \begin_inset ERT
6366 status Collapsed
6367
6368 \layout Standard
6369
6370 \backslash 
6371 /
6372 \end_inset 
6373
6374 -code-loc
6375 \series default 
6376
6377 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6378
6379 \end_inset 
6380
6381 \SpecialChar ~
6382 <Value> The start location of the code
6383 \begin_inset LatexCommand \index{code}
6384
6385 \end_inset 
6386
6387  segment, default value 0.
6388  Note when this option is used the interrupt vector table
6389 \begin_inset LatexCommand \index{interrupt vector table}
6390
6391 \end_inset 
6392
6393  is also relocated to the given address.
6394  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6395 \begin_inset ERT
6396 status Collapsed
6397
6398 \layout Standard
6399
6400 \backslash 
6401 /
6402 \end_inset 
6403
6404 -code-loc 0x8000 or -
6405 \begin_inset ERT
6406 status Collapsed
6407
6408 \layout Standard
6409
6410 \backslash 
6411 /
6412 \end_inset 
6413
6414 -code-loc 32768.
6415 \layout List
6416 \labelwidthstring 00.00.0000
6417
6418
6419 \series bold 
6420 -
6421 \begin_inset ERT
6422 status Collapsed
6423
6424 \layout Standard
6425
6426 \backslash 
6427 /
6428 \end_inset 
6429
6430 -stack-loc
6431 \series default 
6432
6433 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6434
6435 \end_inset 
6436
6437 \SpecialChar ~
6438 <Value> By default the stack
6439 \begin_inset LatexCommand \index{stack}
6440
6441 \end_inset 
6442
6443  is placed after the data segment.
6444  Using this option the stack can be placed anywhere in the internal memory
6445  space of the 8051.
6446  The value entered can be in Hexadecimal or Decimal format, e.g.
6447  -
6448 \begin_inset ERT
6449 status Collapsed
6450
6451 \layout Standard
6452
6453 \backslash 
6454 /
6455 \end_inset 
6456
6457 -stack-loc 0x20 or -
6458 \begin_inset ERT
6459 status Collapsed
6460
6461 \layout Standard
6462
6463 \backslash 
6464 /
6465 \end_inset 
6466
6467 -stack-loc 32.
6468  Since the sp register is incremented before a push or call, the initial
6469  sp will be set to one byte prior the provided value.
6470  The provided value should not overlap any other memory areas such as used
6471  register banks or the data segment and with enough space for the current
6472  application.
6473  The 
6474 \series bold 
6475 -
6476 \begin_inset ERT
6477 status Collapsed
6478
6479 \layout Standard
6480
6481 \backslash 
6482 /
6483 \end_inset 
6484
6485 -pack-iram
6486 \series default 
6487 \SpecialChar ~
6488
6489 \begin_inset LatexCommand \index{-\/-pack-iram}
6490
6491 \end_inset 
6492
6493  option (which is now a default setting) will override this setting, so
6494  you should also specify the 
6495 \series bold 
6496 -
6497 \begin_inset ERT
6498 status Collapsed
6499
6500 \layout Standard
6501
6502 \backslash 
6503 /
6504 \end_inset 
6505
6506 -no-pack-iram
6507 \series default 
6508 \SpecialChar ~
6509
6510 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6511
6512 \end_inset 
6513
6514  option if you need to manually place the stack.
6515 \layout List
6516 \labelwidthstring 00.00.0000
6517
6518
6519 \series bold 
6520 -
6521 \begin_inset ERT
6522 status Collapsed
6523
6524 \layout Standard
6525
6526 \backslash 
6527 /
6528 \end_inset 
6529
6530 -xstack-loc
6531 \series default 
6532
6533 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6534
6535 \end_inset 
6536
6537 \SpecialChar ~
6538 <Value> By default the external stack
6539 \begin_inset LatexCommand \index{xstack}
6540
6541 \end_inset 
6542
6543  is placed after the pdata
6544 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6545
6546 \end_inset 
6547
6548  segment.
6549  Using this option the xstack can be placed anywhere in the external memory
6550  space of the 8051.
6551  The value entered can be in Hexadecimal or Decimal format, e.g.
6552  -
6553 \begin_inset ERT
6554 status Collapsed
6555
6556 \layout Standard
6557
6558 \backslash 
6559 /
6560 \end_inset 
6561
6562 -xstack-loc 0x8000 or -
6563 \begin_inset ERT
6564 status Collapsed
6565
6566 \layout Standard
6567
6568 \backslash 
6569 /
6570 \end_inset 
6571
6572 -stack-loc 32768.
6573  The provided value should not overlap any other memory areas such as the
6574  pdata or xdata segment and with enough space for the current application.
6575 \layout List
6576 \labelwidthstring 00.00.0000
6577
6578
6579 \series bold 
6580 -
6581 \begin_inset ERT
6582 status Collapsed
6583
6584 \layout Standard
6585
6586 \backslash 
6587 /
6588 \end_inset 
6589
6590 -data-loc
6591 \series default 
6592
6593 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6594
6595 \end_inset 
6596
6597 \SpecialChar ~
6598 <Value> The start location of the internal ram data
6599 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6600
6601 \end_inset 
6602
6603  segment.
6604  The value entered can be in Hexadecimal or Decimal format, eg.
6605  -
6606 \begin_inset ERT
6607 status Collapsed
6608
6609 \layout Standard
6610
6611 \backslash 
6612 /
6613 \end_inset 
6614
6615 -data-loc 0x20 or -
6616 \begin_inset ERT
6617 status Collapsed
6618
6619 \layout Standard
6620
6621 \backslash 
6622 /
6623 \end_inset 
6624
6625 -data-loc 32.
6626  (By default, the start location of the internal ram data segment  is set
6627  as low as possible in memory, taking into account the used register banks
6628  and the bit segment at address 0x20.
6629  For example if register banks 0 and 1 are used without bit variables, the
6630  data segment will be set, if -
6631 \begin_inset ERT
6632 status Collapsed
6633
6634 \layout Standard
6635
6636 \backslash 
6637 /
6638 \end_inset 
6639
6640 -data-loc is not used, to location 0x10.)
6641 \layout List
6642 \labelwidthstring 00.00.0000
6643
6644
6645 \series bold 
6646 -
6647 \begin_inset ERT
6648 status Collapsed
6649
6650 \layout Standard
6651
6652 \backslash 
6653 /
6654 \end_inset 
6655
6656 -idata-loc
6657 \series default 
6658
6659 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6660
6661 \end_inset 
6662
6663 \SpecialChar ~
6664 <Value> The start location of the indirectly addressable internal ram
6665 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6666
6667 \end_inset 
6668
6669  of the 8051, default value is 0x80.
6670  The value entered can be in Hexadecimal or Decimal format, eg.
6671  -
6672 \begin_inset ERT
6673 status Collapsed
6674
6675 \layout Standard
6676
6677 \backslash 
6678 /
6679 \end_inset 
6680
6681 -idata-loc 0x88 or -
6682 \begin_inset ERT
6683 status Collapsed
6684
6685 \layout Standard
6686
6687 \backslash 
6688 /
6689 \end_inset 
6690
6691 -idata-loc 136.
6692 \layout List
6693 \labelwidthstring 00.00.0000
6694
6695
6696 \series bold 
6697 -
6698 \begin_inset ERT
6699 status Collapsed
6700
6701 \layout Standard
6702
6703 \backslash 
6704 /
6705 \end_inset 
6706
6707 -bit-loc
6708 \series default 
6709 \SpecialChar ~
6710 <Value> The start location of the bit
6711 \begin_inset LatexCommand \index{bit}
6712
6713 \end_inset 
6714
6715  addressable internal ram of the 8051.
6716  This is 
6717 \emph on 
6718 not
6719 \emph default 
6720  implemented yet.
6721  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6722 -bBSEG=<Value>.
6723 \layout List
6724 \labelwidthstring 00.00.0000
6725
6726
6727 \series bold 
6728 -
6729 \begin_inset ERT
6730 status Collapsed
6731
6732 \layout Standard
6733
6734 \backslash 
6735 /
6736 \end_inset 
6737
6738 -out-fmt-ihx
6739 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6740
6741 \end_inset 
6742
6743
6744 \bar under 
6745  
6746 \series default 
6747 \bar default 
6748 The linker output (final object code) is in Intel Hex format.
6749 \begin_inset LatexCommand \index{Intel hex format}
6750
6751 \end_inset 
6752
6753  This is the default option.
6754  The format itself is documented in the documentation of srecord
6755 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6756
6757 \end_inset 
6758
6759 .
6760 \layout List
6761 \labelwidthstring 00.00.0000
6762
6763
6764 \series bold 
6765 -
6766 \begin_inset ERT
6767 status Collapsed
6768
6769 \layout Standard
6770
6771 \backslash 
6772 /
6773 \end_inset 
6774
6775 -out-fmt-s19
6776 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6777
6778 \end_inset 
6779
6780
6781 \bar under 
6782  
6783 \series default 
6784 \bar default 
6785 The linker output (final object code) is in Motorola S19 format
6786 \begin_inset LatexCommand \index{Motorola S19 format}
6787
6788 \end_inset 
6789
6790 .
6791  The format itself is documented in the documentation of srecord.
6792 \layout List
6793 \labelwidthstring 00.00.0000
6794
6795
6796 \series bold 
6797 -
6798 \begin_inset ERT
6799 status Collapsed
6800
6801 \layout Standard
6802
6803 \backslash 
6804 /
6805 \end_inset 
6806
6807 -out-fmt-elf
6808 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6809
6810 \end_inset 
6811
6812
6813 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6814
6815 \end_inset 
6816
6817
6818 \bar under 
6819  
6820 \series default 
6821 \bar default 
6822 The linker output (final object code) is in ELF format
6823 \begin_inset LatexCommand \index{ELF format}
6824
6825 \end_inset 
6826
6827 .
6828  (Currently only supported for the HC08
6829 \begin_inset LatexCommand \index{HC08}
6830
6831 \end_inset 
6832
6833  processors)
6834 \layout List
6835 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6836
6837
6838 \series bold 
6839 -Wl\SpecialChar ~
6840 linkOption[,linkOption]
6841 \series default 
6842
6843 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6844
6845 \end_inset 
6846
6847 ...
6848  Pass the linkOption to the linker.
6849  If a bootloader is used an option like 
6850 \begin_inset Quotes sld
6851 \end_inset 
6852
6853 -Wl\SpecialChar ~
6854 -bCSEG=0x1000
6855 \begin_inset Quotes srd
6856 \end_inset 
6857
6858  would be typical to set the start of the code segment.
6859  See also #pragma constseg and #pragma codeseg in section 
6860 \begin_inset LatexCommand \ref{sec:Pragmas}
6861
6862 \end_inset 
6863
6864  .
6865  File sdcc/as/doc/asxhtm.html has more on linker options.
6866 \layout Subsection
6867
6868 MCS51 Options
6869 \begin_inset LatexCommand \index{Options MCS51}
6870
6871 \end_inset 
6872
6873
6874 \begin_inset LatexCommand \index{MCS51 options}
6875
6876 \end_inset 
6877
6878
6879 \layout List
6880 \labelwidthstring 00.00.0000
6881
6882
6883 \series bold 
6884 -
6885 \begin_inset ERT
6886 status Collapsed
6887
6888 \layout Standard
6889
6890 \backslash 
6891 /
6892 \end_inset 
6893
6894 -model-small
6895 \begin_inset LatexCommand \index{-\/-model-small}
6896
6897 \end_inset 
6898
6899
6900 \series default 
6901 \size large 
6902 \emph on 
6903  
6904 \size default 
6905 \emph default 
6906 Generate code for Small Model programs, see section Memory Models for more
6907  details.
6908  This is the default model.
6909 \layout List
6910 \labelwidthstring 00.00.0000
6911
6912
6913 \series bold 
6914 -
6915 \begin_inset ERT
6916 status Collapsed
6917
6918 \layout Standard
6919
6920 \backslash 
6921 /
6922 \end_inset 
6923
6924 -model-medium
6925 \begin_inset LatexCommand \index{-\/-model-medium}
6926
6927 \end_inset 
6928
6929
6930 \series default 
6931  Generate code for Medium model programs, see section Memory Models for
6932  more details.
6933  If this option is used all source files in the project have to be compiled
6934  with this option.
6935  It must also be used when invoking the linker.
6936 \layout List
6937 \labelwidthstring 00.00.0000
6938
6939
6940 \series bold 
6941 -
6942 \begin_inset ERT
6943 status Collapsed
6944
6945 \layout Standard
6946
6947 \backslash 
6948 /
6949 \end_inset 
6950
6951 -model-large
6952 \begin_inset LatexCommand \index{-\/-model-large}
6953
6954 \end_inset 
6955
6956
6957 \series default 
6958  Generate code for Large model programs, see section Memory Models for more
6959  details.
6960  If this option is used all source files in the project have to be compiled
6961  with this option.
6962  It must also be used when invoking the linker.
6963 \layout List
6964 \labelwidthstring 00.00.0000
6965
6966
6967 \series bold 
6968 -
6969 \begin_inset ERT
6970 status Collapsed
6971
6972 \layout Standard
6973
6974 \backslash 
6975 /
6976 \end_inset 
6977
6978 -xstack
6979 \begin_inset LatexCommand \index{-\/-xstack}
6980
6981 \end_inset 
6982
6983
6984 \series default 
6985  Uses a pseudo stack in the pdata
6986 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6987
6988 \end_inset 
6989
6990  area (usually the first 256 bytes in the external ram) for allocating variables
6991  and passing parameters.
6992  See section 
6993 \begin_inset LatexCommand \ref{sub:External-Stack}
6994
6995 \end_inset 
6996
6997 \SpecialChar ~
6998  External Stack for more details.
6999 \layout List
7000 \labelwidthstring 00.00.0000
7001
7002
7003 \series bold 
7004 -
7005 \begin_inset ERT
7006 status Collapsed
7007
7008 \layout Standard
7009
7010 \backslash 
7011 /
7012 \end_inset 
7013
7014 -iram-size
7015 \series default 
7016 \SpecialChar ~
7017 <Value>
7018 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7019
7020 \end_inset 
7021
7022  Causes the linker to check if the internal ram usage is within limits of
7023  the given value.
7024 \layout List
7025 \labelwidthstring 00.00.0000
7026
7027
7028 \series bold 
7029 -
7030 \begin_inset ERT
7031 status Collapsed
7032
7033 \layout Standard
7034
7035 \backslash 
7036 /
7037 \end_inset 
7038
7039 -xram-size
7040 \series default 
7041 \SpecialChar ~
7042 <Value>
7043 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7044
7045 \end_inset 
7046
7047  Causes the linker to check if the external ram usage is within limits of
7048  the given value.
7049 \layout List
7050 \labelwidthstring 00.00.0000
7051
7052
7053 \series bold 
7054 -
7055 \begin_inset ERT
7056 status Collapsed
7057
7058 \layout Standard
7059
7060 \backslash 
7061 /
7062 \end_inset 
7063
7064 -code-size
7065 \series default 
7066 \SpecialChar ~
7067 <Value>
7068 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7069
7070 \end_inset 
7071
7072  Causes the linker to check if the code memory usage is within limits of
7073  the given value.
7074 \layout List
7075 \labelwidthstring 00.00.0000
7076
7077
7078 \series bold 
7079 -
7080 \begin_inset ERT
7081 status Collapsed
7082
7083 \layout Standard
7084
7085 \backslash 
7086 /
7087 \end_inset 
7088
7089 -stack-size
7090 \series default 
7091 \SpecialChar ~
7092 <Value>
7093 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7094
7095 \end_inset 
7096
7097  Causes the linker to check if there is at minimum <Value> bytes for stack.
7098 \layout List
7099 \labelwidthstring 00.00.0000
7100
7101
7102 \series bold 
7103 -
7104 \begin_inset ERT
7105 status Collapsed
7106
7107 \layout Standard
7108
7109 \backslash 
7110 /
7111 \end_inset 
7112
7113 -pack-iram
7114 \series default 
7115 \SpecialChar ~
7116
7117 \begin_inset LatexCommand \index{-\/-pack-iram}
7118
7119 \end_inset 
7120
7121  Causes the linker to use unused register banks for data variables and pack
7122  data, idata and stack together.
7123  This is the default now.
7124 \layout List
7125 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7126
7127
7128 \series bold 
7129 -
7130 \begin_inset ERT
7131 status Collapsed
7132
7133 \layout Standard
7134
7135 \backslash 
7136 /
7137 \end_inset 
7138
7139 -no-pack-iram
7140 \series default 
7141 \SpecialChar ~
7142
7143 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7144
7145 \end_inset 
7146
7147  Causes the linker to use old style for allocating memory areas.
7148 \layout Subsection
7149
7150 DS390 / DS400 Options
7151 \begin_inset LatexCommand \index{Options DS390}
7152
7153 \end_inset 
7154
7155
7156 \begin_inset LatexCommand \index{DS390}
7157
7158 \end_inset 
7159
7160
7161 \layout List
7162 \labelwidthstring 00.00.0000
7163
7164
7165 \series bold 
7166 -
7167 \begin_inset ERT
7168 status Collapsed
7169
7170 \layout Standard
7171
7172 \backslash 
7173 /
7174 \end_inset 
7175
7176 -model-flat24
7177 \series default 
7178
7179 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7180
7181 \end_inset 
7182
7183
7184 \size large 
7185 \emph on 
7186  
7187 \size default 
7188 \emph default 
7189 Generate 24-bit flat mode code.
7190  This is the one and only that the ds390 code generator supports right now
7191  and is default when using 
7192 \emph on 
7193 -mds390
7194 \emph default 
7195 .
7196  See section Memory Models for more details.
7197 \layout List
7198 \labelwidthstring 00.00.0000
7199
7200
7201 \series bold 
7202 -
7203 \begin_inset ERT
7204 status Collapsed
7205
7206 \layout Standard
7207
7208 \backslash 
7209 /
7210 \end_inset 
7211
7212 -protect-sp-update
7213 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7214
7215 \end_inset 
7216
7217
7218 \series default 
7219  disable interrupts during ESP:SP updates.
7220 \layout List
7221 \labelwidthstring 00.00.0000
7222
7223
7224 \series bold 
7225 -
7226 \begin_inset ERT
7227 status Collapsed
7228
7229 \layout Standard
7230
7231 \backslash 
7232 /
7233 \end_inset 
7234
7235 -stack-10bit
7236 \series default 
7237
7238 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7239
7240 \end_inset 
7241
7242  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7243  This is the one and only that the ds390 code generator supports right now
7244  and is default when using 
7245 \emph on 
7246 -mds390
7247 \emph default 
7248 .
7249  In this mode, the stack is located in the lower 1K of the internal RAM,
7250  which is mapped to 0x400000.
7251  Note that the support is incomplete, since it still uses a single byte
7252  as the stack pointer.
7253  This means that only the lower 256 bytes of the potential 1K stack space
7254  will actually be used.
7255  However, this does allow you to reclaim the precious 256 bytes of low RAM
7256  for use for the DATA and IDATA segments.
7257  The compiler will not generate any code to put the processor into 10 bit
7258  stack mode.
7259  It is important to ensure that the processor is in this mode before calling
7260  any re-entrant functions compiled with this option.
7261  In principle, this should work with the 
7262 \emph on 
7263 -
7264 \begin_inset ERT
7265 status Collapsed
7266
7267 \layout Standard
7268
7269 \backslash 
7270 /
7271 \end_inset 
7272
7273 -stack-auto
7274 \begin_inset LatexCommand \index{-\/-stack-auto}
7275
7276 \end_inset 
7277
7278
7279 \emph default 
7280  option, but that has not been tested.
7281  It is incompatible with the 
7282 \emph on 
7283 -
7284 \begin_inset ERT
7285 status Collapsed
7286
7287 \layout Standard
7288
7289 \backslash 
7290 /
7291 \end_inset 
7292
7293 -xstack
7294 \begin_inset LatexCommand \index{-\/-xstack}
7295
7296 \end_inset 
7297
7298
7299 \emph default 
7300  option.
7301  It also only makes sense if the processor is in 24 bit contiguous addressing
7302  mode (see the 
7303 \emph on 
7304 -
7305 \begin_inset ERT
7306 status Collapsed
7307
7308 \layout Standard
7309
7310 \backslash 
7311 /
7312 \end_inset 
7313
7314 -model-flat24 option
7315 \emph default 
7316 ).
7317 \layout List
7318 \labelwidthstring 00.00.0000
7319
7320
7321 \series bold 
7322 -
7323 \begin_inset ERT
7324 status Collapsed
7325
7326 \layout Standard
7327
7328 \backslash 
7329 /
7330 \end_inset 
7331
7332 -stack-probe
7333 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7334
7335 \end_inset 
7336
7337
7338 \series default 
7339  insert call to function __stack_probe at each function prologue.
7340 \layout List
7341 \labelwidthstring 00.00.0000
7342
7343
7344 \series bold 
7345 -
7346 \begin_inset ERT
7347 status Collapsed
7348
7349 \layout Standard
7350
7351 \backslash 
7352 /
7353 \end_inset 
7354
7355 -tini-libid
7356 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7357
7358 \end_inset 
7359
7360
7361 \series default 
7362  <nnnn> LibraryID used in -mTININative.
7363  
7364 \layout List
7365 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7366
7367
7368 \series bold 
7369 -
7370 \begin_inset ERT
7371 status Collapsed
7372
7373 \layout Standard
7374
7375 \backslash 
7376 /
7377 \end_inset 
7378
7379 -use-accelerator
7380 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7381
7382 \end_inset 
7383
7384
7385 \series default 
7386  generate code for DS390 Arithmetic Accelerator.
7387  
7388 \layout Subsection
7389
7390 Z80 Options
7391 \begin_inset LatexCommand \index{Options Z80}
7392
7393 \end_inset 
7394
7395
7396 \begin_inset LatexCommand \index{Z80}
7397
7398 \end_inset 
7399
7400
7401 \layout List
7402 \labelwidthstring 00.00.0000
7403
7404
7405 \series bold 
7406 -
7407 \begin_inset ERT
7408 status Collapsed
7409
7410 \layout Standard
7411
7412 \backslash 
7413 /
7414 \end_inset 
7415
7416 -callee-saves-bc
7417 \series default 
7418
7419 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7420
7421 \end_inset 
7422
7423
7424 \size large 
7425 \emph on 
7426  
7427 \size default 
7428 \emph default 
7429 Force a called function to always save BC.
7430 \layout List
7431 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7432
7433
7434 \series bold 
7435 -
7436 \begin_inset ERT
7437 status Collapsed
7438
7439 \layout Standard
7440
7441 \backslash 
7442 /
7443 \end_inset 
7444
7445 -no-std-crt0
7446 \series default 
7447
7448 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7449
7450 \end_inset 
7451
7452  When linking, skip the standard crt0.o object file.
7453  You must provide your own crt0.o for your system when linking.
7454  
7455 \layout Subsection
7456
7457 Optimization Options
7458 \begin_inset LatexCommand \index{Options optimization}
7459
7460 \end_inset 
7461
7462
7463 \begin_inset LatexCommand \index{Optimization options}
7464
7465 \end_inset 
7466
7467
7468 \layout List
7469 \labelwidthstring 00.00.0000
7470
7471
7472 \series bold 
7473 -
7474 \begin_inset ERT
7475 status Collapsed
7476
7477 \layout Standard
7478
7479 \backslash 
7480 /
7481 \end_inset 
7482
7483 -nogcse
7484 \begin_inset LatexCommand \index{-\/-nogcse}
7485
7486 \end_inset 
7487
7488
7489 \series default 
7490  Will not do global subexpression elimination, this option may be used when
7491  the compiler creates undesirably large stack/data spaces to store compiler
7492  temporaries (
7493 \emph on 
7494 s
7495 \emph default 
7496 pill 
7497 \emph on 
7498 loc
7499 \emph default 
7500 ations, sloc
7501 \begin_inset LatexCommand \index{sloc (spill location)}
7502
7503 \end_inset 
7504
7505 ).
7506  A warning message will be generated when this happens and the compiler
7507  will indicate the number of extra bytes it allocated.
7508  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7509 nogcse
7510 \begin_inset LatexCommand \index{\#pragma nogcse}
7511
7512 \end_inset 
7513
7514  can be used to turn off global subexpression elimination
7515 \begin_inset LatexCommand \index{Subexpression elimination}
7516
7517 \end_inset 
7518
7519  for a given function only.
7520 \layout List
7521 \labelwidthstring 00.00.0000
7522
7523
7524 \series bold 
7525 -
7526 \begin_inset ERT
7527 status Collapsed
7528
7529 \layout Standard
7530
7531 \backslash 
7532 /
7533 \end_inset 
7534
7535 -noinvariant
7536 \begin_inset LatexCommand \index{-\/-noinvariant}
7537
7538 \end_inset 
7539
7540
7541 \series default 
7542  Will not do loop invariant optimizations, this may be turned off for reasons
7543  explained for the previous option.
7544  For more details of loop optimizations performed see Loop Invariants in
7545  section 
7546 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7547
7548 \end_inset 
7549
7550 .
7551  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7552 noinvariant
7553 \begin_inset LatexCommand \index{\#pragma noinvariant}
7554
7555 \end_inset 
7556
7557  can be used to turn off invariant optimizations for a given function only.
7558 \layout List
7559 \labelwidthstring 00.00.0000
7560
7561
7562 \series bold 
7563 -
7564 \begin_inset ERT
7565 status Collapsed
7566
7567 \layout Standard
7568
7569 \backslash 
7570 /
7571 \end_inset 
7572
7573 -noinduction
7574 \begin_inset LatexCommand \index{-\/-noinduction}
7575
7576 \end_inset 
7577
7578
7579 \series default 
7580  Will not do loop induction optimizations, see section strength reduction
7581  for more details.
7582  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7583 noinduction
7584 \begin_inset LatexCommand \index{\#pragma noinduction}
7585
7586 \end_inset 
7587
7588  can be used to turn off induction optimizations for a given function only.
7589 \layout List
7590 \labelwidthstring 00.00.0000
7591
7592
7593 \series bold 
7594 -
7595 \begin_inset ERT
7596 status Collapsed
7597
7598 \layout Standard
7599
7600 \backslash 
7601 /
7602 \end_inset 
7603
7604 -nojtbound
7605 \begin_inset LatexCommand \index{-\/-nojtbound}
7606
7607 \end_inset 
7608
7609
7610 \size large 
7611 \bar under 
7612  
7613 \series default 
7614 \size default 
7615 \bar default 
7616  Will not generate boundary condition check when switch statements
7617 \begin_inset LatexCommand \index{switch statement}
7618
7619 \end_inset 
7620
7621  are implemented using jump-tables.
7622  See section 
7623 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7624
7625 \end_inset 
7626
7627 \SpecialChar ~
7628 Switch Statements for more details.
7629  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7630 nojtbound
7631 \begin_inset LatexCommand \index{\#pragma nojtbound}
7632
7633 \end_inset 
7634
7635  can be used to turn off boundary checking for jump tables for a given function
7636  only.
7637 \layout List
7638 \labelwidthstring 00.00.0000
7639
7640
7641 \series bold 
7642 -
7643 \begin_inset ERT
7644 status Collapsed
7645
7646 \layout Standard
7647
7648 \backslash 
7649 /
7650 \end_inset 
7651
7652 -noloopreverse
7653 \begin_inset LatexCommand \index{-\/-noloopreverse}
7654
7655 \end_inset 
7656
7657
7658 \series default 
7659 \size large 
7660  
7661 \size default 
7662 Will not do loop reversal 
7663 \begin_inset LatexCommand \index{Loop reversing}
7664
7665 \end_inset 
7666
7667 optimization.
7668 \layout List
7669 \labelwidthstring 00.00.0000
7670
7671 -
7672 \begin_inset ERT
7673 status Collapsed
7674
7675 \layout Standard
7676
7677 \backslash 
7678 /
7679 \end_inset 
7680
7681 -
7682 \series bold 
7683 nolabelopt
7684 \series default 
7685  
7686 \begin_inset LatexCommand \index{-\/-nolabelopt }
7687
7688 \end_inset 
7689
7690 Will not optimize labels (makes the dumpfiles more readable).
7691 \layout List
7692 \labelwidthstring 00.00.0000
7693
7694
7695 \series bold 
7696 -
7697 \begin_inset ERT
7698 status Collapsed
7699
7700 \layout Standard
7701
7702 \backslash 
7703 /
7704 \end_inset 
7705
7706 -no-xinit-opt
7707 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7708
7709 \end_inset 
7710
7711
7712 \series default 
7713  Will not memcpy initialized data from code space into xdata space.
7714  This saves a few bytes in code space if you don't have initialized data
7715 \begin_inset LatexCommand \index{Variable initialization}
7716
7717 \end_inset 
7718
7719 .
7720 \layout List
7721 \labelwidthstring 00.00.0000
7722
7723
7724 \series bold 
7725 -
7726 \begin_inset ERT
7727 status Collapsed
7728
7729 \layout Standard
7730
7731 \backslash 
7732 /
7733 \end_inset 
7734
7735 -nooverlay
7736 \begin_inset LatexCommand \index{-\/-nooverlay}
7737
7738 \end_inset 
7739
7740
7741 \series default 
7742   The compiler will not overlay parameters and local variables of any function,
7743  see section Parameters and local variables for more details.
7744 \layout List
7745 \labelwidthstring 00.00.0000
7746
7747
7748 \series bold 
7749 -
7750 \begin_inset ERT
7751 status Collapsed
7752
7753 \layout Standard
7754
7755 \backslash 
7756 /
7757 \end_inset 
7758
7759 -no-peep
7760 \begin_inset LatexCommand \index{-\/-no-peep}
7761
7762 \end_inset 
7763
7764
7765 \series default 
7766  Disable peep-hole optimization with built-in rules.
7767 \layout List
7768 \labelwidthstring 00.00.0000
7769
7770
7771 \series bold 
7772 -
7773 \begin_inset ERT
7774 status Collapsed
7775
7776 \layout Standard
7777
7778 \backslash 
7779 /
7780 \end_inset 
7781
7782 -peep-file
7783 \series default 
7784
7785 \begin_inset LatexCommand \index{-\/-peep-file}
7786
7787 \end_inset 
7788
7789 \SpecialChar ~
7790 <filename> This option can be used to use additional rules to be used by
7791  the peep hole optimizer.
7792  See section 
7793 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7794
7795 \end_inset 
7796
7797 \SpecialChar ~
7798 Peep Hole optimizations for details on how to write these rules.
7799 \layout List
7800 \labelwidthstring 00.00.0000
7801
7802
7803 \series bold 
7804 -
7805 \begin_inset ERT
7806 status Collapsed
7807
7808 \layout Standard
7809
7810 \backslash 
7811 /
7812 \end_inset 
7813
7814 -peep-asm
7815 \begin_inset LatexCommand \index{-\/-peep-asm}
7816
7817 \end_inset 
7818
7819
7820 \series default 
7821  Pass the inline assembler code through the peep hole optimizer.
7822  This can cause unexpected changes to inline assembler code, please go through
7823  the peephole optimizer
7824 \begin_inset LatexCommand \index{Peephole optimizer}
7825
7826 \end_inset 
7827
7828  rules defined in the source file tree '<target>/peeph.def' before using
7829  this option.
7830 \layout List
7831 \labelwidthstring 00.00.0000
7832
7833
7834 \series bold 
7835 -
7836 \begin_inset ERT
7837 status Collapsed
7838
7839 \layout Standard
7840
7841 \backslash 
7842 /
7843 \end_inset 
7844
7845 -opt-code-speed
7846 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7847
7848 \end_inset 
7849
7850
7851 \series default 
7852  The compiler will optimize code generation towards fast code, possibly
7853  at the expense of code size.
7854 \layout List
7855 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7856
7857
7858 \series bold 
7859 -
7860 \begin_inset ERT
7861 status Collapsed
7862
7863 \layout Standard
7864
7865 \backslash 
7866 /
7867 \end_inset 
7868
7869 -opt-code-size
7870 \begin_inset LatexCommand \index{-\/-opt-code-size}
7871
7872 \end_inset 
7873
7874
7875 \series default 
7876  The compiler will optimize code generation towards compact code, possibly
7877  at the expense of code speed.
7878 \layout Subsection
7879
7880 Other Options
7881 \begin_inset LatexCommand \index{Options other}
7882
7883 \end_inset 
7884
7885
7886 \layout List
7887 \labelwidthstring 00.00.0000
7888
7889
7890 \series bold 
7891 -c\SpecialChar ~
7892 -
7893 \begin_inset ERT
7894 status Collapsed
7895
7896 \layout Standard
7897
7898 \backslash 
7899 /
7900 \end_inset 
7901
7902 -compile-only
7903 \begin_inset LatexCommand \index{-\/-compile-only}
7904
7905 \end_inset 
7906
7907
7908 \begin_inset LatexCommand \index{-c -\/-compile-only}
7909
7910 \end_inset 
7911
7912
7913 \series default 
7914  will compile and assemble the source, but will not call the linkage editor.
7915 \layout List
7916 \labelwidthstring 00.00.0000
7917
7918
7919 \series bold 
7920 -
7921 \series default 
7922
7923 \begin_inset ERT
7924 status Collapsed
7925
7926 \layout Standard
7927
7928 \backslash 
7929 /
7930 \end_inset 
7931
7932
7933 \series bold 
7934 -c1mode
7935 \begin_inset LatexCommand \index{-\/-c1mode}
7936
7937 \end_inset 
7938
7939
7940 \series default 
7941  reads the preprocessed source from standard input and compiles it.
7942  The file name for the assembler output must be specified using the -o option.
7943 \layout List
7944 \labelwidthstring 00.00.0000
7945
7946
7947 \series bold 
7948 -E
7949 \begin_inset LatexCommand \index{-E}
7950
7951 \end_inset 
7952
7953
7954 \series default 
7955  Run only the C preprocessor.
7956  Preprocess all the C source files specified and output the results to standard
7957  output.
7958 \layout List
7959 \labelwidthstring 00.00.0000
7960
7961
7962 \series bold 
7963 -o\SpecialChar ~
7964 <path/file>
7965 \begin_inset LatexCommand \index{-o <path/file>}
7966
7967 \end_inset 
7968
7969  
7970 \series default 
7971 The output path resp.
7972  file where everything will be placed.
7973  If the parameter is a path, it must have a trailing slash (or backslash
7974  for the Windows binaries) to be recognized as a path.
7975  
7976 \layout List
7977 \labelwidthstring 00.00.0000
7978
7979
7980 \series bold 
7981 -
7982 \begin_inset ERT
7983 status Collapsed
7984
7985 \layout Standard
7986
7987 \backslash 
7988 /
7989 \end_inset 
7990
7991 -stack-auto
7992 \begin_inset LatexCommand \index{-\/-stack-auto}
7993
7994 \end_inset 
7995
7996
7997 \series default 
7998 \size large 
7999 \emph on 
8000  
8001 \size default 
8002 \emph default 
8003 All functions in the source file will be compiled as 
8004 \emph on 
8005 reentrant
8006 \emph default 
8007
8008 \begin_inset LatexCommand \index{reentrant}
8009
8010 \end_inset 
8011
8012 , i.e.
8013  the parameters and local variables will be allocated on the stack
8014 \begin_inset LatexCommand \index{stack}
8015
8016 \end_inset 
8017
8018 .
8019  See section 
8020 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8021
8022 \end_inset 
8023
8024  Parameters and Local Variables for more details.
8025  If this option is used all source files in the project should be compiled
8026  with this option.
8027  It automatically implies --int-long-reent and --float-reent.
8028  
8029 \layout List
8030 \labelwidthstring 00.00.0000
8031
8032
8033 \series bold 
8034 -
8035 \begin_inset ERT
8036 status Collapsed
8037
8038 \layout Standard
8039
8040 \backslash 
8041 /
8042 \end_inset 
8043
8044 -callee-saves
8045 \begin_inset LatexCommand \index{-\/-callee-saves}
8046
8047 \end_inset 
8048
8049  function1[,function2][,function3]....
8050
8051 \series default 
8052  The compiler by default uses a caller saves convention for register saving
8053  across function calls, however this can cause unnecessary register pushing
8054  & popping when calling small functions from larger functions.
8055  This option can be used to switch the register saving convention for the
8056  function names specified.
8057  The compiler will not save registers when calling these functions, no extra
8058  code will be generated at the entry & exit (function prologue
8059 \series bold 
8060
8061 \begin_inset LatexCommand \index{function prologue}
8062
8063 \end_inset 
8064
8065
8066 \series default 
8067  & epilogue
8068 \series bold 
8069
8070 \begin_inset LatexCommand \index{function epilogue}
8071
8072 \end_inset 
8073
8074
8075 \series default 
8076 ) for these functions to save & restore the registers used by these functions,
8077  this can SUBSTANTIALLY reduce code & improve run time performance of the
8078  generated code.
8079  In the future the compiler (with inter procedural analysis) will be able
8080  to determine the appropriate scheme to use for each function call.
8081  DO NOT use this option for built-in functions such as _mulint..., if this
8082  option is used for a library function the appropriate library function
8083  needs to be recompiled with the same option.
8084  If the project consists of multiple source files then all the source file
8085  should be compiled with the same -
8086 \begin_inset ERT
8087 status Collapsed
8088
8089 \layout Standard
8090
8091 \backslash 
8092 /
8093 \end_inset 
8094
8095 -callee-saves option string.
8096  Also see #pragma\SpecialChar ~
8097 callee_saves
8098 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8099
8100 \end_inset 
8101
8102 .
8103 \layout List
8104 \labelwidthstring 00.00.0000
8105
8106
8107 \series bold 
8108 -
8109 \begin_inset ERT
8110 status Collapsed
8111
8112 \layout Standard
8113
8114 \backslash 
8115 /
8116 \end_inset 
8117
8118 -debug
8119 \begin_inset LatexCommand \index{-\/-debug}
8120
8121 \end_inset 
8122
8123
8124 \bar under 
8125  
8126 \series default 
8127 \bar default 
8128 When this option is used the compiler will generate debug information.
8129  The debug information collected in a file with .cdb extension can be used
8130  with the SDCDB.
8131  For more information see documentation for SDCDB.
8132  Another file with no extension contains debug information in AOMF or AOMF51
8133 \begin_inset LatexCommand \index{AOMF, AOMF51}
8134
8135 \end_inset 
8136
8137  format which is commonly used by third party tools.
8138 \layout List
8139 \labelwidthstring 00.00.0000
8140
8141
8142 \series bold 
8143 -S
8144 \begin_inset LatexCommand \index{-S}
8145
8146 \end_inset 
8147
8148
8149 \size large 
8150 \bar under 
8151  
8152 \series default 
8153 \size default 
8154 \bar default 
8155 Stop after the stage of compilation proper; do not assemble.
8156  The output is an assembler code file for the input file specified.
8157 \layout List
8158 \labelwidthstring 00.00.0000
8159
8160
8161 \series bold 
8162 -
8163 \begin_inset ERT
8164 status Collapsed
8165
8166 \layout Standard
8167
8168 \backslash 
8169 /
8170 \end_inset 
8171
8172 -int-long-reent
8173 \begin_inset LatexCommand \index{-\/-int-long-reent}
8174
8175 \end_inset 
8176
8177
8178 \series default 
8179  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8180  Note by default these libraries are compiled as non-reentrant.
8181  See section Installation for more details.
8182 \layout List
8183 \labelwidthstring 00.00.0000
8184
8185
8186 \series bold 
8187 -
8188 \begin_inset ERT
8189 status Collapsed
8190
8191 \layout Standard
8192
8193 \backslash 
8194 /
8195 \end_inset 
8196
8197 -cyclomatic
8198 \begin_inset LatexCommand \index{-\/-cyclomatic}
8199
8200 \end_inset 
8201
8202
8203 \bar under 
8204  
8205 \series default 
8206 \bar default 
8207 This option will cause the compiler to generate an information message for
8208  each function in the source file.
8209  The message contains some 
8210 \emph on 
8211 important
8212 \emph default 
8213  information about the function.
8214  The number of edges and nodes the compiler detected in the control flow
8215  graph of the function, and most importantly the 
8216 \emph on 
8217 cyclomatic complexity
8218 \begin_inset LatexCommand \index{Cyclomatic complexity}
8219
8220 \end_inset 
8221
8222
8223 \emph default 
8224  see section on Cyclomatic Complexity for more details.
8225 \layout List
8226 \labelwidthstring 00.00.0000
8227
8228
8229 \series bold 
8230 -
8231 \begin_inset ERT
8232 status Collapsed
8233
8234 \layout Standard
8235
8236 \backslash 
8237 /
8238 \end_inset 
8239
8240 -float-reent
8241 \begin_inset LatexCommand \index{-\/-float-reent}
8242
8243 \end_inset 
8244
8245
8246 \series default 
8247  Floating point library is compiled as reentrant
8248 \begin_inset LatexCommand \index{reentrant}
8249
8250 \end_inset 
8251
8252 .
8253  See section Installation for more details.
8254 \layout List
8255 \labelwidthstring 00.00.0000
8256
8257
8258 \series bold 
8259 -
8260 \begin_inset ERT
8261 status Collapsed
8262
8263 \layout Standard
8264
8265 \backslash 
8266 /
8267 \end_inset 
8268
8269 -main-return
8270 \begin_inset LatexCommand \index{-\/-main-return}
8271
8272 \end_inset 
8273
8274
8275 \series default 
8276  This option can be used if the code generated is called by a monitor program
8277  or if the main routine includes an endless loop.
8278  This option results in slightly smaller code and saves two bytes of stack
8279  space.
8280  The return from the 'main'
8281 \begin_inset LatexCommand \index{main return}
8282
8283 \end_inset 
8284
8285  function will return to the function calling main.
8286  The default setting is to lock up i.e.
8287  generate a '
8288 \family typewriter 
8289 sjmp .
8290 \family default 
8291 '.
8292 \layout List
8293 \labelwidthstring 00.00.0000
8294
8295
8296 \series bold 
8297 -
8298 \begin_inset ERT
8299 status Collapsed
8300
8301 \layout Standard
8302
8303 \backslash 
8304 /
8305 \end_inset 
8306
8307 -nostdinc
8308 \begin_inset LatexCommand \index{-\/-nostdinc}
8309
8310 \end_inset 
8311
8312
8313 \series default 
8314  This will prevent the compiler from passing on the default include path
8315  to the preprocessor.
8316 \layout List
8317 \labelwidthstring 00.00.0000
8318
8319
8320 \series bold 
8321 -
8322 \begin_inset ERT
8323 status Collapsed
8324
8325 \layout Standard
8326
8327 \backslash 
8328 /
8329 \end_inset 
8330
8331 -nostdlib
8332 \begin_inset LatexCommand \index{-\/-nostdlib}
8333
8334 \end_inset 
8335
8336
8337 \series default 
8338  This will prevent the compiler from passing on the default library
8339 \begin_inset LatexCommand \index{Libraries}
8340
8341 \end_inset 
8342
8343  path to the linker.
8344 \layout List
8345 \labelwidthstring 00.00.0000
8346
8347
8348 \series bold 
8349 -
8350 \begin_inset ERT
8351 status Collapsed
8352
8353 \layout Standard
8354
8355 \backslash 
8356 /
8357 \end_inset 
8358
8359 -verbose
8360 \begin_inset LatexCommand \index{-\/-verbose}
8361
8362 \end_inset 
8363
8364
8365 \series default 
8366  Shows the various actions the compiler is performing.
8367 \layout List
8368 \labelwidthstring 00.00.0000
8369
8370
8371 \series bold 
8372 -V
8373 \begin_inset LatexCommand \index{-V}
8374
8375 \end_inset 
8376
8377
8378 \series default 
8379  Shows the actual commands the compiler is executing.
8380 \layout List
8381 \labelwidthstring 00.00.0000
8382
8383
8384 \series bold 
8385 -
8386 \begin_inset ERT
8387 status Collapsed
8388
8389 \layout Standard
8390
8391 \backslash 
8392 /
8393 \end_inset 
8394
8395 -no-c-code-in-asm
8396 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8397
8398 \end_inset 
8399
8400
8401 \series default 
8402  Hides your ugly and inefficient c-code from the asm file, so you can always
8403  blame the compiler :)
8404 \layout List
8405 \labelwidthstring 00.00.0000
8406
8407
8408 \series bold 
8409 -
8410 \begin_inset ERT
8411 status Collapsed
8412
8413 \layout Standard
8414
8415 \backslash 
8416 /
8417 \end_inset 
8418
8419 -no-peep-comments
8420 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8421
8422 \end_inset 
8423
8424
8425 \series default 
8426  Will not include peep-hole comments in the generated files.
8427 \layout List
8428 \labelwidthstring 00.00.0000
8429
8430
8431 \series bold 
8432 -
8433 \begin_inset ERT
8434 status Collapsed
8435
8436 \layout Standard
8437
8438 \backslash 
8439 /
8440 \end_inset 
8441
8442 -i-code-in-asm
8443 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8444
8445 \end_inset 
8446
8447
8448 \series default 
8449  Include i-codes in the asm file.
8450  Sounds like noise but is most helpful for debugging the compiler itself.
8451 \layout List
8452 \labelwidthstring 00.00.0000
8453
8454
8455 \series bold 
8456 -
8457 \begin_inset ERT
8458 status Collapsed
8459
8460 \layout Standard
8461
8462 \backslash 
8463 /
8464 \end_inset 
8465
8466 -less-pedantic
8467 \begin_inset LatexCommand \index{-\/-less-pedantic}
8468
8469 \end_inset 
8470
8471
8472 \series default 
8473  Disable some of the more pedantic warnings
8474 \begin_inset LatexCommand \index{Warnings}
8475
8476 \end_inset 
8477
8478  (jwk burps: please be more specific here, please!).
8479 \layout List
8480 \labelwidthstring 00.00.0000
8481
8482
8483 \series bold 
8484 -
8485 \begin_inset ERT
8486 status Collapsed
8487
8488 \layout Standard
8489
8490 \backslash 
8491 /
8492 \end_inset 
8493
8494 -disable-warning\SpecialChar ~
8495 <nnnn>
8496 \begin_inset LatexCommand \index{-\/-disable-warning}
8497
8498 \end_inset 
8499
8500
8501 \series default 
8502  Disable specific warning with number <nnnn>.
8503 \layout List
8504 \labelwidthstring 00.00.0000
8505
8506
8507 \series bold 
8508 -
8509 \begin_inset ERT
8510 status Collapsed
8511
8512 \layout Standard
8513
8514 \backslash 
8515 /
8516 \end_inset 
8517
8518 -print-search-dirs
8519 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8520
8521 \end_inset 
8522
8523
8524 \series default 
8525  Display the directories in the compiler's search path
8526 \layout List
8527 \labelwidthstring 00.00.0000
8528
8529
8530 \series bold 
8531 -
8532 \begin_inset ERT
8533 status Collapsed
8534
8535 \layout Standard
8536
8537 \backslash 
8538 /
8539 \end_inset 
8540
8541 -vc
8542 \begin_inset LatexCommand \index{-\/-vc}
8543
8544 \end_inset 
8545
8546
8547 \series default 
8548  Display errors and warnings using MSVC style, so you can use SDCC with
8549  the visual studio IDE
8550 \begin_inset LatexCommand \index{IDE}
8551
8552 \end_inset 
8553
8554 .
8555  With SDCC both offering a GCC-like (the default) and a MSVC-like
8556 \begin_inset LatexCommand \index{MSVC output style}
8557
8558 \end_inset 
8559
8560  output style, integration into most programming editors should be straightforwa
8561 rd.
8562 \layout List
8563 \labelwidthstring 00.00.0000
8564
8565
8566 \series bold 
8567 -
8568 \begin_inset ERT
8569 status Collapsed
8570
8571 \layout Standard
8572
8573 \backslash 
8574 /
8575 \end_inset 
8576
8577 -use-stdout
8578 \begin_inset LatexCommand \index{-\/-use-stdout}
8579
8580 \end_inset 
8581
8582
8583 \series default 
8584  Send errors and warnings to stdout instead of stderr.
8585 \layout List
8586 \labelwidthstring 00.00.0000
8587
8588
8589 \series bold 
8590 -Wa\SpecialChar ~
8591 asmOption[,asmOption]
8592 \series default 
8593
8594 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8595
8596 \end_inset 
8597
8598 ...
8599  Pass the asmOption to the assembler
8600 \begin_inset LatexCommand \index{Options assembler}
8601
8602 \end_inset 
8603
8604
8605 \begin_inset LatexCommand \index{Assembler options}
8606
8607 \end_inset 
8608
8609 .
8610  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8611 \layout List
8612 \labelwidthstring 00.00.0000
8613
8614
8615 \series bold 
8616 -
8617 \begin_inset ERT
8618 status Collapsed
8619
8620 \layout Standard
8621
8622 \backslash 
8623 /
8624 \end_inset 
8625
8626 -std-sdcc89
8627 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8628
8629 \end_inset 
8630
8631
8632 \series default 
8633  Generally follow the C89 standard, but allow SDCC features that conflict
8634  with the standard (default).
8635 \layout List
8636 \labelwidthstring 00.00.0000
8637
8638
8639 \series bold 
8640 -
8641 \begin_inset ERT
8642 status Collapsed
8643
8644 \layout Standard
8645
8646 \backslash 
8647 /
8648 \end_inset 
8649
8650 -std-c89
8651 \begin_inset LatexCommand \index{-\/-std-c89}
8652
8653 \end_inset 
8654
8655
8656 \series default 
8657  Follow the C89 standard and disable SDCC features that conflict with the
8658  standard.
8659 \layout List
8660 \labelwidthstring 00.00.0000
8661
8662
8663 \series bold 
8664 -
8665 \begin_inset ERT
8666 status Collapsed
8667
8668 \layout Standard
8669
8670 \backslash 
8671 /
8672 \end_inset 
8673
8674 -std-sdcc99
8675 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8676
8677 \end_inset 
8678
8679
8680 \series default 
8681  Generally follow the C99 standard, but allow SDCC features that conflict
8682  with the standard (incomplete support).
8683 \layout List
8684 \labelwidthstring 00.00.0000
8685
8686
8687 \series bold 
8688 -
8689 \begin_inset ERT
8690 status Collapsed
8691
8692 \layout Standard
8693
8694 \backslash 
8695 /
8696 \end_inset 
8697
8698 -std-c99
8699 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8700
8701 \end_inset 
8702
8703
8704 \series default 
8705  Follow the C99 standard and disable SDCC features that conflict with the
8706  standard (incomplete support).
8707 \layout List
8708 \labelwidthstring 00.00.0000
8709
8710
8711 \series bold 
8712 -
8713 \begin_inset ERT
8714 status Collapsed
8715
8716 \layout Standard
8717
8718 \backslash 
8719 /
8720 \end_inset 
8721
8722 -codeseg
8723 \series default 
8724
8725 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8726
8727 \end_inset 
8728
8729 \SpecialChar ~
8730 <Name> The name to be used for the code
8731 \begin_inset LatexCommand \index{code}
8732
8733 \end_inset 
8734
8735  segment, default CSEG.
8736  This is useful if you need to tell the compiler to put the code in a special
8737  segment so you can later on tell the linker to put this segment in a special
8738  place in memory.
8739  Can be used for instance when using bank switching to put the code in a
8740  bank.
8741 \layout List
8742 \labelwidthstring 00.00.0000
8743
8744
8745 \series bold 
8746 -
8747 \begin_inset ERT
8748 status Collapsed
8749
8750 \layout Standard
8751
8752 \backslash 
8753 /
8754 \end_inset 
8755
8756 -constseg
8757 \series default 
8758
8759 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8760
8761 \end_inset 
8762
8763 \SpecialChar ~
8764 <Name> The name to be used for the const
8765 \begin_inset LatexCommand \index{code}
8766
8767 \end_inset 
8768
8769  segment, default CONST.
8770  This is useful if you need to tell the compiler to put the const data in
8771  a special segment so you can later on tell the linker to put this segment
8772  in a special place in memory.
8773  Can be used for instance when using bank switching to put the const data
8774  in a bank.
8775 \layout List
8776 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8777
8778
8779 \series bold 
8780 more-pedantic
8781 \series default 
8782  Actually this is 
8783 \series bold 
8784 \emph on 
8785 not
8786 \series default 
8787 \emph default 
8788  a SDCC compiler option but if you want 
8789 \emph on 
8790 more
8791 \emph default 
8792  warnings you can use a separate tool dedicated to syntax checking like
8793  splint
8794 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8795
8796 \end_inset 
8797
8798
8799 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8800
8801 \end_inset 
8802
8803  
8804 \begin_inset LatexCommand \url{http://www.splint.org}
8805
8806 \end_inset 
8807
8808 .
8809  To make your source files parseable by splint you will have to include
8810  
8811 \family sans 
8812 lint.h
8813 \family default 
8814
8815 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8816
8817 \end_inset 
8818
8819  in your source file and add brackets around extended keywords (like 
8820 \family sans 
8821
8822 \begin_inset Quotes sld
8823 \end_inset 
8824
8825 __at\SpecialChar ~
8826
8827 \series bold 
8828 (
8829 \series default 
8830 0xab
8831 \series bold 
8832 )
8833 \series default 
8834
8835 \begin_inset Quotes srd
8836 \end_inset 
8837
8838
8839 \family default 
8840  and 
8841 \family sans 
8842
8843 \begin_inset Quotes sld
8844 \end_inset 
8845
8846 __interrupt\SpecialChar ~
8847 (2)
8848 \begin_inset Quotes srd
8849 \end_inset 
8850
8851
8852 \family default 
8853 ).
8854  
8855 \newline 
8856 Splint has an excellent on line manual at 
8857 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8858
8859 \end_inset 
8860
8861  and it's capabilities go beyond pure syntax checking.
8862  You'll need to tell splint the location of SDCC's include files so a typical
8863  command line could look like this: 
8864 \newline 
8865
8866 \family sans 
8867 splint\SpecialChar ~
8868 -I\SpecialChar ~
8869 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8870 \SpecialChar ~
8871 myprogram.c
8872 \layout Subsection
8873
8874 Intermediate Dump Options
8875 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8876
8877 \end_inset 
8878
8879
8880 \begin_inset LatexCommand \index{Options intermediate dump}
8881
8882 \end_inset 
8883
8884
8885 \begin_inset LatexCommand \index{Intermediate dump options}
8886
8887 \end_inset 
8888
8889
8890 \layout Standard
8891
8892 The following options are provided for the purpose of retargetting and debugging
8893  the compiler.
8894  They provide a means to dump the intermediate code (iCode
8895 \begin_inset LatexCommand \index{iCode}
8896
8897 \end_inset 
8898
8899 ) generated by the compiler in human readable form at various stages of
8900  the compilation process.
8901  More on iCodes see chapter 
8902 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8903
8904 \end_inset 
8905
8906  
8907 \begin_inset Quotes srd
8908 \end_inset 
8909
8910 The anatomy of the compiler
8911 \begin_inset Quotes srd
8912 \end_inset 
8913
8914 .
8915 \layout List
8916 \labelwidthstring 00.00.0000
8917
8918
8919 \series bold 
8920 -
8921 \begin_inset ERT
8922 status Collapsed
8923
8924 \layout Standard
8925
8926 \backslash 
8927 /
8928 \end_inset 
8929
8930 -dumpraw
8931 \begin_inset LatexCommand \index{-\/-dumpraw}
8932
8933 \end_inset 
8934
8935
8936 \series default 
8937  This option will cause the compiler to dump the intermediate code into
8938  a file of named 
8939 \emph on 
8940 <source filename>.dumpraw
8941 \emph default 
8942  just after the intermediate code has been generated for a function, i.e.
8943  before any optimizations are done.
8944  The basic blocks
8945 \begin_inset LatexCommand \index{Basic blocks}
8946
8947 \end_inset 
8948
8949  at this stage ordered in the depth first number, so they may not be in
8950  sequence of execution.
8951 \layout List
8952 \labelwidthstring 00.00.0000
8953
8954
8955 \series bold 
8956 -
8957 \begin_inset ERT
8958 status Collapsed
8959
8960 \layout Standard
8961
8962 \backslash 
8963 /
8964 \end_inset 
8965
8966 -dumpgcse
8967 \begin_inset LatexCommand \index{-\/-dumpgcse}
8968
8969 \end_inset 
8970
8971
8972 \series default 
8973  Will create a dump of iCode's, after global subexpression elimination
8974 \begin_inset LatexCommand \index{Global subexpression elimination}
8975
8976 \end_inset 
8977
8978 , into a file named 
8979 \emph on 
8980 <source filename>.dumpgcse.
8981 \layout List
8982 \labelwidthstring 00.00.0000
8983
8984
8985 \series bold 
8986 -
8987 \begin_inset ERT
8988 status Collapsed
8989
8990 \layout Standard
8991
8992 \backslash 
8993 /
8994 \end_inset 
8995
8996 -dumpdeadcode
8997 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8998
8999 \end_inset 
9000
9001
9002 \series default 
9003  Will create a dump of iCode's, after deadcode elimination
9004 \begin_inset LatexCommand \index{Dead-code elimination}
9005
9006 \end_inset 
9007
9008 , into a file named 
9009 \emph on 
9010 <source filename>.dumpdeadcode.
9011 \layout List
9012 \labelwidthstring 00.00.0000
9013
9014
9015 \series bold 
9016 -
9017 \begin_inset ERT
9018 status Collapsed
9019
9020 \layout Standard
9021
9022 \backslash 
9023 /
9024 \end_inset 
9025
9026 -dumploop
9027 \begin_inset LatexCommand \index{-\/-dumploop}
9028
9029 \end_inset 
9030
9031
9032 \series default 
9033 \size large 
9034  
9035 \size default 
9036 Will create a dump of iCode's, after loop optimizations
9037 \begin_inset LatexCommand \index{Loop optimization}
9038
9039 \end_inset 
9040
9041 , into a file named 
9042 \emph on 
9043 <source filename>.dumploop.
9044 \layout List
9045 \labelwidthstring 00.00.0000
9046
9047
9048 \series bold 
9049 -
9050 \begin_inset ERT
9051 status Collapsed
9052
9053 \layout Standard
9054
9055 \backslash 
9056 /
9057 \end_inset 
9058
9059 -dumprange
9060 \begin_inset LatexCommand \index{-\/-dumprange}
9061
9062 \end_inset 
9063
9064
9065 \series default 
9066 \size large 
9067  
9068 \size default 
9069 Will create a dump of iCode's, after live range analysis
9070 \begin_inset LatexCommand \index{Live range analysis}
9071
9072 \end_inset 
9073
9074 , into a file named 
9075 \emph on 
9076 <source filename>.dumprange.
9077 \layout List
9078 \labelwidthstring 00.00.0000
9079
9080
9081 \series bold 
9082 -
9083 \begin_inset ERT
9084 status Collapsed
9085
9086 \layout Standard
9087
9088 \backslash 
9089 /
9090 \end_inset 
9091
9092 -dumlrange
9093 \begin_inset LatexCommand \index{-\/-dumlrange}
9094
9095 \end_inset 
9096
9097
9098 \series default 
9099  Will dump the life ranges
9100 \begin_inset LatexCommand \index{Live range analysis}
9101
9102 \end_inset 
9103
9104  for all symbols.
9105 \layout List
9106 \labelwidthstring 00.00.0000
9107
9108
9109 \series bold 
9110 -
9111 \begin_inset ERT
9112 status Collapsed
9113
9114 \layout Standard
9115
9116 \backslash 
9117 /
9118 \end_inset 
9119
9120 -dumpregassign
9121 \begin_inset LatexCommand \index{-\/-dumpregassign}
9122
9123 \end_inset 
9124
9125
9126 \bar under 
9127  
9128 \series default 
9129 \bar default 
9130 Will create a dump of iCode's, after register assignment
9131 \begin_inset LatexCommand \index{Register assignment}
9132
9133 \end_inset 
9134
9135 , into a file named 
9136 \emph on 
9137 <source filename>.dumprassgn.
9138 \layout List
9139 \labelwidthstring 00.00.0000
9140
9141
9142 \series bold 
9143 -
9144 \begin_inset ERT
9145 status Collapsed
9146
9147 \layout Standard
9148
9149 \backslash 
9150 /
9151 \end_inset 
9152
9153 -dumplrange
9154 \begin_inset LatexCommand \index{-\/-dumplrange}
9155
9156 \end_inset 
9157
9158
9159 \series default 
9160  Will create a dump of the live ranges of iTemp's
9161 \layout List
9162 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9163
9164
9165 \series bold 
9166 -
9167 \begin_inset ERT
9168 status Collapsed
9169
9170 \layout Standard
9171
9172 \backslash 
9173 /
9174 \end_inset 
9175
9176 -dumpall
9177 \begin_inset LatexCommand \index{-\/-dumpall}
9178
9179 \end_inset 
9180
9181
9182 \size large 
9183 \bar under 
9184  
9185 \series default 
9186 \size default 
9187 \bar default 
9188 Will cause all the above mentioned dumps to be created.
9189 \layout Subsection
9190
9191 Redirecting output on Windows Shells
9192 \layout Standard
9193 \added_space_bottom bigskip 
9194 By default SDCC writes it's error messages to 
9195 \begin_inset Quotes sld
9196 \end_inset 
9197
9198 standard error
9199 \begin_inset Quotes srd
9200 \end_inset 
9201
9202 .
9203  To force all messages to 
9204 \begin_inset Quotes sld
9205 \end_inset 
9206
9207 standard output
9208 \begin_inset Quotes srd
9209 \end_inset 
9210
9211  use 
9212 \series bold 
9213 -
9214 \series default 
9215 \emph on 
9216
9217 \begin_inset ERT
9218 status Collapsed
9219
9220 \layout Standard
9221
9222 \backslash 
9223 /
9224 \end_inset 
9225
9226
9227 \series bold 
9228 \emph default 
9229 -
9230 \series default 
9231 use-stdout
9232 \begin_inset LatexCommand \index{-\/-use-stdout}
9233
9234 \end_inset 
9235
9236 .
9237  Additionally, if you happen to have visual studio installed in your windows
9238  machine, you can use it to compile your sources using a custom build and
9239  the SDCC -
9240 \emph on 
9241
9242 \begin_inset ERT
9243 status Collapsed
9244
9245 \layout Standard
9246
9247 \backslash 
9248 /
9249 \end_inset 
9250
9251
9252 \emph default 
9253 -vc
9254 \begin_inset LatexCommand \index{-\/-vc}
9255
9256 \end_inset 
9257
9258  option.
9259  Something like this should work:
9260 \newline 
9261
9262 \newline 
9263
9264 \series bold 
9265 c:
9266 \backslash 
9267 sdcc
9268 \backslash 
9269 bin
9270 \backslash 
9271 sdcc.exe -
9272 \series default 
9273 \emph on 
9274
9275 \begin_inset ERT
9276 status Collapsed
9277
9278 \layout Standard
9279
9280 \backslash 
9281 /
9282 \end_inset 
9283
9284
9285 \series bold 
9286 \emph default 
9287 -vc -
9288 \series default 
9289 \emph on 
9290
9291 \begin_inset ERT
9292 status Collapsed
9293
9294 \layout Standard
9295
9296 \backslash 
9297 /
9298 \end_inset 
9299
9300
9301 \series bold 
9302 \emph default 
9303 -model-large -c $(InputPath)
9304 \layout Section
9305
9306 Environment variables
9307 \begin_inset LatexCommand \index{Environment variables}
9308
9309 \end_inset 
9310
9311
9312 \layout Standard
9313
9314 SDCC recognizes the following environment variables:
9315 \layout List
9316 \labelwidthstring 00.00.0000
9317
9318
9319 \series bold 
9320 SDCC_LEAVE_SIGNALS
9321 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9322
9323 \end_inset 
9324
9325
9326 \series default 
9327  SDCC installs a signal handler
9328 \begin_inset LatexCommand \index{signal handler}
9329
9330 \end_inset 
9331
9332  to be able to delete temporary files after an user break (^C) or an exception.
9333  If this environment variable is set, SDCC won't install the signal handler
9334  in order to be able to debug SDCC.
9335 \layout List
9336 \labelwidthstring 00.00.0000
9337
9338
9339 \series bold 
9340 TMP,\SpecialChar ~
9341 TEMP,\SpecialChar ~
9342 TMPDIR
9343 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9344
9345 \end_inset 
9346
9347
9348 \series default 
9349  Path, where temporary files will be created.
9350  The order of the variables is the search order.
9351  In a standard *nix environment these variables are not set, and there's
9352  no need to set them.
9353  On Windows it's recommended to set one of them.
9354 \layout List
9355 \labelwidthstring 00.00.0000
9356
9357
9358 \series bold 
9359 SDCC_HOME
9360 \begin_inset LatexCommand \index{SDCC\_HOME}
9361
9362 \end_inset 
9363
9364
9365 \series default 
9366  Path, see section 
9367 \begin_inset LatexCommand \ref{sub:Install-paths}
9368
9369 \end_inset 
9370
9371 \SpecialChar ~
9372
9373 \begin_inset Quotes sld
9374 \end_inset 
9375
9376  Install Paths
9377 \begin_inset Quotes srd
9378 \end_inset 
9379
9380 .
9381 \layout List
9382 \labelwidthstring 00.00.0000
9383
9384
9385 \series bold 
9386 SDCC_INCLUDE
9387 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9388
9389 \end_inset 
9390
9391
9392 \series default 
9393  Path, see section 
9394 \begin_inset LatexCommand \ref{sub:Search-Paths}
9395
9396 \end_inset 
9397
9398 \SpecialChar ~
9399
9400 \begin_inset Quotes sld
9401 \end_inset 
9402
9403 Search Paths
9404 \begin_inset Quotes srd
9405 \end_inset 
9406
9407 .
9408 \layout List
9409 \labelwidthstring 00.00.0000
9410
9411
9412 \series bold 
9413 SDCC_LIB
9414 \begin_inset LatexCommand \index{SDCC\_LIB}
9415
9416 \end_inset 
9417
9418
9419 \series default 
9420  Path, see section 
9421 \begin_inset LatexCommand \ref{sub:Search-Paths}
9422
9423 \end_inset 
9424
9425 \SpecialChar ~
9426
9427 \begin_inset Quotes sld
9428 \end_inset 
9429
9430 Search Paths
9431 \begin_inset Quotes srd
9432 \end_inset 
9433
9434 ..
9435 \layout Standard
9436 \added_space_bottom bigskip 
9437 There are some more environment variables recognized by SDCC, but these
9438  are solely used for debugging purposes.
9439  They can change or disappear very quickly, and will never be documented.
9440 \layout Section
9441
9442 Storage Class Language Extensions
9443 \layout Subsection
9444
9445 MCS51/DS390 Storage Class
9446 \begin_inset LatexCommand \index{Storage class}
9447
9448 \end_inset 
9449
9450  Language Extensions
9451 \layout Standard
9452
9453 In addition to the ANSI storage classes SDCC allows the following MCS51
9454  specific storage classes:
9455 \layout Subsubsection
9456
9457 data
9458 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9459
9460 \end_inset 
9461
9462
9463 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9464
9465 \end_inset 
9466
9467  / near
9468 \begin_inset LatexCommand \index{near (storage class)}
9469
9470 \end_inset 
9471
9472
9473 \begin_inset LatexCommand \index{\_\_near (storage class)}
9474
9475 \end_inset 
9476
9477
9478 \layout Standard
9479
9480 This is the 
9481 \series bold 
9482 default
9483 \series default 
9484  storage class for the Small Memory model (
9485 \emph on 
9486 data
9487 \emph default 
9488  and 
9489 \emph on 
9490 near
9491 \emph default 
9492  or the more ANSI-C compliant forms 
9493 \emph on 
9494 __data
9495 \emph default 
9496  and 
9497 \emph on 
9498 __near
9499 \emph default 
9500  can be used synonymously).
9501  Variables declared with this storage class will be allocated in the directly
9502  addressable portion of the internal RAM of a 8051, e.g.:
9503 \layout Verse
9504
9505
9506 \family typewriter 
9507 __data unsigned char test_data;
9508 \layout Standard
9509
9510 Writing 0x01 to this variable generates the assembly code:
9511 \layout Verse
9512
9513
9514 \family typewriter 
9515 75*00 01\SpecialChar ~
9516 \SpecialChar ~
9517 \SpecialChar ~
9518 mov\SpecialChar ~
9519 \SpecialChar ~
9520 _test_data,#0x01
9521 \layout Subsubsection
9522
9523 xdata
9524 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9525
9526 \end_inset 
9527
9528
9529 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9530
9531 \end_inset 
9532
9533  / far
9534 \begin_inset LatexCommand \index{far (storage class)}
9535
9536 \end_inset 
9537
9538
9539 \begin_inset LatexCommand \index{\_\_far (storage class)}
9540
9541 \end_inset 
9542
9543
9544 \layout Standard
9545
9546 Variables declared with this storage class will be placed in the external
9547  RAM.
9548  This is the 
9549 \series bold 
9550 default
9551 \series default 
9552  storage class for the Large Memory model, e.g.:
9553 \layout Verse
9554
9555
9556 \family typewriter 
9557 __xdata unsigned char test_xdata;
9558 \layout Standard
9559
9560 Writing 0x01 to this variable generates the assembly code:
9561 \layout Verse
9562
9563
9564 \family typewriter 
9565 90s00r00\SpecialChar ~
9566 \SpecialChar ~
9567 \SpecialChar ~
9568 mov\SpecialChar ~
9569 \SpecialChar ~
9570 dptr,#_test_xdata 
9571 \newline 
9572 74\SpecialChar ~
9573 01\SpecialChar ~
9574 \SpecialChar ~
9575 \SpecialChar ~
9576 \SpecialChar ~
9577 \SpecialChar ~
9578 \SpecialChar ~
9579 mov\SpecialChar ~
9580 \SpecialChar ~
9581 a,#0x01 
9582 \newline 
9583 F0\SpecialChar ~
9584 \SpecialChar ~
9585 \SpecialChar ~
9586 \SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 \SpecialChar ~
9592 movx\SpecialChar ~
9593 @dptr,a 
9594 \layout Subsubsection
9595
9596 idata
9597 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9598
9599 \end_inset 
9600
9601
9602 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9603
9604 \end_inset 
9605
9606
9607 \layout Standard
9608
9609 Variables declared with this storage class will be allocated into the indirectly
9610  addressable portion of the internal ram of a 8051, e.g.:
9611 \layout Verse
9612
9613
9614 \family typewriter 
9615 __idata unsigned char test_idata;
9616 \layout Standard
9617
9618 Writing 0x01 to this variable generates the assembly code:
9619 \layout Verse
9620
9621
9622 \family typewriter 
9623 78r00\SpecialChar ~
9624 \SpecialChar ~
9625 \SpecialChar ~
9626 \SpecialChar ~
9627 \SpecialChar ~
9628 \SpecialChar ~
9629 \SpecialChar ~
9630 mov\SpecialChar ~
9631 \SpecialChar ~
9632 r0,#_test_idata
9633 \newline 
9634 76\SpecialChar ~
9635 01\SpecialChar ~
9636 \SpecialChar ~
9637 \SpecialChar ~
9638 \SpecialChar ~
9639 \SpecialChar ~
9640 \SpecialChar ~
9641 \SpecialChar ~
9642 mov\SpecialChar ~
9643 \SpecialChar ~
9644 @r0,#0x01
9645 \layout Standard
9646
9647 Please note, the first 128 byte of idata physically access the same RAM
9648  as the data memory.
9649  The original 8051 had 128 byte idata memory, nowadays most devices have
9650  256 byte idata memory.
9651  The stack
9652 \begin_inset LatexCommand \index{stack}
9653
9654 \end_inset 
9655
9656  is located in idata memory.
9657 \layout Subsubsection
9658
9659 pdata
9660 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9661
9662 \end_inset 
9663
9664
9665 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9666
9667 \end_inset 
9668
9669
9670 \layout Standard
9671
9672 Paged xdata access is just as straightforward as using the other addressing
9673  modes of a 8051.
9674  It is typically located at the start of xdata and has a maximum size of
9675  256 bytes.
9676  The following example writes 0x01 to the pdata variable.
9677  Please note, pdata access physically accesses xdata memory.
9678  The high byte of the address is determined by port P2 
9679 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9680
9681 \end_inset 
9682
9683 (or in case of some 8051 variants by a separate Special Function Register,
9684  see section 
9685 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9686
9687 \end_inset 
9688
9689 ).
9690  This is the 
9691 \series bold 
9692 default
9693 \series default 
9694  storage class for the Medium Memory model, e.g.:
9695 \layout Verse
9696
9697
9698 \family typewriter 
9699 __pdata unsigned char test_pdata;
9700 \layout Standard
9701
9702 Writing 0x01 to this variable generates the assembly code:
9703 \layout Verse
9704
9705
9706 \family typewriter 
9707 78r00\SpecialChar ~
9708 \SpecialChar ~
9709 \SpecialChar ~
9710 \SpecialChar ~
9711 \SpecialChar ~
9712 \SpecialChar ~
9713 mov r0,#_test_pdata
9714 \newline 
9715 74 01\SpecialChar ~
9716 \SpecialChar ~
9717 \SpecialChar ~
9718 \SpecialChar ~
9719 \SpecialChar ~
9720 \SpecialChar ~
9721 mov a,#0x01 
9722 \newline 
9723 F2\SpecialChar ~
9724 \SpecialChar ~
9725 \SpecialChar ~
9726 \SpecialChar ~
9727 \SpecialChar ~
9728 \SpecialChar ~
9729 \SpecialChar ~
9730 \SpecialChar ~
9731 \SpecialChar ~
9732 movx @r0,a
9733 \layout Standard
9734
9735 If the -
9736 \begin_inset ERT
9737 status Collapsed
9738
9739 \layout Standard
9740
9741 \backslash 
9742 /
9743 \end_inset 
9744
9745 -xstack
9746 \begin_inset LatexCommand \index{-\/-xstack}
9747
9748 \end_inset 
9749
9750  option is used the pdata memory area is followed by the xstack memory area
9751  and the sum of their sizes is limited to 256 bytes.
9752 \layout Subsubsection
9753
9754 code
9755 \begin_inset LatexCommand \index{code}
9756
9757 \end_inset 
9758
9759
9760 \begin_inset LatexCommand \index{\_\_code}
9761
9762 \end_inset 
9763
9764
9765 \layout Standard
9766
9767 'Variables' declared with this storage class will be placed in the code
9768  memory:
9769 \layout Verse
9770
9771
9772 \family typewriter 
9773 __code unsigned char test_code;
9774 \layout Standard
9775
9776 Read access to this variable generates the assembly code:
9777 \layout Verse
9778
9779
9780 \family typewriter 
9781 90s00r6F\SpecialChar ~
9782 \SpecialChar ~
9783 \SpecialChar ~
9784 mov dptr,#_test_code
9785 \newline 
9786 E4\SpecialChar ~
9787 \SpecialChar ~
9788 \SpecialChar ~
9789 \SpecialChar ~
9790 \SpecialChar ~
9791 \SpecialChar ~
9792 \SpecialChar ~
9793 \SpecialChar ~
9794 \SpecialChar ~
9795 clr a
9796 \newline 
9797 93\SpecialChar ~
9798 \SpecialChar ~
9799 \SpecialChar ~
9800 \SpecialChar ~
9801 \SpecialChar ~
9802 \SpecialChar ~
9803 \SpecialChar ~
9804 \SpecialChar ~
9805 \SpecialChar ~
9806 movc a,@a+dptr 
9807 \layout Standard
9808
9809
9810 \family typewriter 
9811 char
9812 \family default 
9813  indexed arrays of characters in code memory can be accessed efficiently:
9814 \layout Verse
9815
9816
9817 \family typewriter 
9818 __code char test_array[] = {'c','h','e','a','p'}; 
9819 \layout Standard
9820
9821 Read access to this array using an 8-bit unsigned index generates the assembly
9822  code:
9823 \layout Verse
9824
9825
9826 \family typewriter 
9827 E5*00\SpecialChar ~
9828 \SpecialChar ~
9829 \SpecialChar ~
9830 \SpecialChar ~
9831 \SpecialChar ~
9832 \SpecialChar ~
9833 mov a,_index 
9834 \layout Verse
9835
9836
9837 \family typewriter 
9838 90s00r41\SpecialChar ~
9839 \SpecialChar ~
9840 \SpecialChar ~
9841 mov dptr,#_test_array
9842 \layout Verse
9843
9844
9845 \family typewriter 
9846 93\SpecialChar ~
9847 \SpecialChar ~
9848 \SpecialChar ~
9849 \SpecialChar ~
9850 \SpecialChar ~
9851 \SpecialChar ~
9852 \SpecialChar ~
9853 \SpecialChar ~
9854 \SpecialChar ~
9855 movc a,@a+dptr 
9856 \layout Subsubsection
9857
9858 bit
9859 \begin_inset LatexCommand \index{bit}
9860
9861 \end_inset 
9862
9863
9864 \begin_inset LatexCommand \index{\_\_bit}
9865
9866 \end_inset 
9867
9868
9869 \layout Standard
9870
9871 This is a data-type and a storage class specifier.
9872  When a variable is declared as a bit, it is allocated into the bit addressable
9873  memory of 8051, e.g.:
9874 \layout Verse
9875
9876
9877 \family typewriter 
9878 __bit test_bit;
9879 \layout Standard
9880
9881 Writing 1 to this variable generates the assembly code:
9882 \layout Verse
9883
9884
9885 \family typewriter 
9886 D2*00\SpecialChar ~
9887 \SpecialChar ~
9888 \SpecialChar ~
9889 \SpecialChar ~
9890 \SpecialChar ~
9891 \SpecialChar ~
9892 \SpecialChar ~
9893 setb\SpecialChar ~
9894 _test_bit
9895 \layout Standard
9896
9897 The bit addressable memory consists of 128 bits which are located from 0x20
9898  to 0x2f in data memory.
9899  
9900 \newline 
9901 Apart from this 8051 specific storage class most architectures support ANSI-C
9902  bitfields
9903 \begin_inset LatexCommand \index{bitfields}
9904
9905 \end_inset 
9906
9907
9908 \begin_inset Foot
9909 collapsed false
9910
9911 \layout Standard
9912
9913 Not really meant as examples, but nevertheless showing what bitfields are
9914  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9915 \end_inset 
9916
9917 .
9918  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9919  signed modifier are implemented as unsigned.
9920 \layout Subsubsection
9921
9922 sfr
9923 \begin_inset LatexCommand \index{sfr}
9924
9925 \end_inset 
9926
9927
9928 \begin_inset LatexCommand \index{\_\_sfr}
9929
9930 \end_inset 
9931
9932  / sfr16
9933 \begin_inset LatexCommand \index{sfr16}
9934
9935 \end_inset 
9936
9937
9938 \begin_inset LatexCommand \index{\_\_sfr16}
9939
9940 \end_inset 
9941
9942  / sfr32
9943 \begin_inset LatexCommand \index{sfr32}
9944
9945 \end_inset 
9946
9947
9948 \begin_inset LatexCommand \index{\_\_sfr32}
9949
9950 \end_inset 
9951
9952  / sbit
9953 \begin_inset LatexCommand \index{\_\_sbit}
9954
9955 \end_inset 
9956
9957
9958 \begin_inset LatexCommand \index{sbit}
9959
9960 \end_inset 
9961
9962
9963 \layout Standard
9964
9965 Like the bit keyword, 
9966 \emph on 
9967 sfr / sfr16 / sfr32 / sbit 
9968 \emph default 
9969 signify both a data-type and storage class, they are used to describe the
9970  
9971 \emph on 
9972 s
9973 \emph default 
9974 pecial 
9975 \emph on 
9976 f
9977 \emph default 
9978 unction 
9979 \emph on 
9980 r
9981 \emph default 
9982 egisters and 
9983 \emph on 
9984 s
9985 \emph default 
9986 pecial 
9987 \emph on 
9988 bit
9989 \emph default 
9990  variables of a 8051, eg:
9991 \layout Verse
9992
9993
9994 \family typewriter 
9995 __sfr __at
9996 \begin_inset LatexCommand \index{at}
9997
9998 \end_inset 
9999
10000
10001 \begin_inset LatexCommand \index{\_\_at}
10002
10003 \end_inset 
10004
10005  (0x80) P0;\SpecialChar ~
10006  /* special function register P0 at location 0x80 */
10007 \newline 
10008
10009 \newline 
10010 /* 16 bit special function register combination for timer 0
10011 \newline 
10012 \SpecialChar ~
10013 \SpecialChar ~
10014  with the high byte at location 0x8C and the low byte at location 0x8A */
10015 \newline 
10016 __sfr16 __at (0x8C8A) TMR0;
10017 \newline 
10018
10019 \newline 
10020 __sbit __at
10021 \begin_inset LatexCommand \index{at}
10022
10023 \end_inset 
10024
10025
10026 \begin_inset LatexCommand \index{\_\_at}
10027
10028 \end_inset 
10029
10030  (0xd7) CY;\SpecialChar ~
10031  /* CY (Carry Flag
10032 \begin_inset LatexCommand \index{Flags}
10033
10034 \end_inset 
10035
10036
10037 \begin_inset LatexCommand \index{Carry flag}
10038
10039 \end_inset 
10040
10041 ) */
10042 \layout Standard
10043
10044 Special function registers which are located on an address dividable by
10045  8 are bit-addressable, an
10046 \emph on 
10047  sbit
10048 \emph default 
10049  addresses a specific bit within these sfr.
10050 \newline 
10051 16 Bit and 32 bit special function register combinations which require a
10052  certain access order are better not declared using 
10053 \emph on 
10054 sfr16
10055 \emph default 
10056  or 
10057 \emph on 
10058 sfr32.
10059
10060 \emph default 
10061  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10062  this is not guaranteed.
10063 \newline 
10064
10065 \layout Standard
10066
10067 Please note, if you use a header file which was written for another compiler
10068  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10069  likely be 
10070 \emph on 
10071 not 
10072 \emph default 
10073 compatible.
10074  Specifically the syntax 
10075 \family typewriter 
10076 \SpecialChar ~
10077 sfr P0 = 0x80;\SpecialChar ~
10078
10079 \family default 
10080  is compiled 
10081 \emph on 
10082 without warning
10083 \emph default 
10084  by SDCC to an assignment of 0x80 to a variable called P0 
10085 \family typewriter 
10086
10087 \begin_inset Marginal
10088 collapsed true
10089
10090 \layout Standard
10091
10092
10093 \series bold 
10094 \SpecialChar ~
10095 !
10096 \end_inset 
10097
10098 .
10099  
10100 \family default 
10101 Nevertheless it is possible to write header files
10102 \begin_inset LatexCommand \index{Header files}
10103
10104 \end_inset 
10105
10106
10107 \begin_inset LatexCommand \index{Include files}
10108
10109 \end_inset 
10110
10111  which can be shared among different compilers (see section 
10112 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10113
10114 \end_inset 
10115
10116 ).
10117  
10118 \layout Subsubsection
10119
10120 Pointers
10121 \begin_inset LatexCommand \index{Pointer}
10122
10123 \end_inset 
10124
10125  to MCS51/DS390 specific memory spaces
10126 \layout Standard
10127
10128 SDCC allows (via language extensions) pointers to explicitly point to any
10129  of the memory spaces
10130 \begin_inset LatexCommand \index{Memory model}
10131
10132 \end_inset 
10133
10134  of the 8051.
10135  In addition to the explicit pointers, the compiler uses (by default) generic
10136  pointers which can be used to point to any of the memory spaces.
10137 \newline 
10138
10139 \newline 
10140 Pointer declaration examples:
10141 \layout Verse
10142
10143
10144 \family typewriter 
10145 /* pointer physically in internal ram pointing to object in external ram
10146  */ 
10147 \newline 
10148 __xdata unsigned char * __data p;
10149 \newline 
10150
10151 \newline 
10152 /* pointer physically in external ram pointing to object in internal ram
10153  */ 
10154 \newline 
10155 __data unsigned char * __xdata p;
10156 \newline 
10157
10158 \newline 
10159 /* pointer physically in code rom pointing to data in xdata space */ 
10160 \newline 
10161 __xdata unsigned char * __code p;
10162 \newline 
10163
10164 \newline 
10165 /* pointer physically in code space pointing to data in code space */ 
10166 \newline 
10167 __code unsigned char * __code p;
10168 \newline 
10169
10170 \newline 
10171 /* generic pointer physically located in xdata space */
10172 \newline 
10173 unsigned char * __xdata p;
10174 \newline 
10175
10176 \newline 
10177 /* generic pointer physically located in default memory space */
10178 \newline 
10179 unsigned char * p;
10180 \newline 
10181
10182 \newline 
10183 /* the following is a function pointer
10184 \begin_inset LatexCommand \index{function pointer}
10185
10186 \end_inset 
10187
10188  physically located in data space */
10189 \newline 
10190 char (* __data fp)(void);
10191 \layout Standard
10192
10193 Well you get the idea.
10194  
10195 \newline 
10196
10197 \newline 
10198 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10199 \emph on 
10200 generic
10201 \emph default 
10202  pointers.
10203  
10204 \size small 
10205
10206 \newline 
10207
10208 \newline 
10209
10210 \size default 
10211 The highest order byte of the 
10212 \emph on 
10213 generic
10214 \emph default 
10215  pointers contains the data space information.
10216  Assembler support routines are called whenever data is stored or retrieved
10217  using 
10218 \emph on 
10219 generic
10220 \emph default 
10221  pointers.
10222  These are useful for developing reusable library
10223 \begin_inset LatexCommand \index{Libraries}
10224
10225 \end_inset 
10226
10227  routines.
10228  Explicitly specifying the pointer
10229 \begin_inset LatexCommand \index{pointer}
10230
10231 \end_inset 
10232
10233  type will generate the most efficient code.
10234 \layout Subsubsection
10235
10236 Notes on MCS51 memory
10237 \begin_inset LatexCommand \index{MCS51 memory}
10238
10239 \end_inset 
10240
10241  layout
10242 \layout Standard
10243
10244 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10245  RAM memory which is structured as follows:
10246 \newline 
10247
10248 \newline 
10249 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10250  
10251 \newline 
10252 - Bytes 20-2F - 16 bytes to hold 128 bit
10253 \begin_inset LatexCommand \index{bit}
10254
10255 \end_inset 
10256
10257  variables and, 
10258 \newline 
10259 - Bytes 30-7F - 80 bytes for general purpose use.
10260 \newline 
10261
10262 \layout Standard
10263
10264 Additionally some members of the MCS51 family may have up to 128 bytes of
10265  additional, indirectly addressable, internal RAM memory (
10266 \emph on 
10267 idata
10268 \emph default 
10269
10270 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10271
10272 \end_inset 
10273
10274
10275 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10276
10277 \end_inset 
10278
10279 ).
10280  Furthermore, some chips may have some built in external memory (
10281 \emph on 
10282 xdata
10283 \emph default 
10284
10285 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10286
10287 \end_inset 
10288
10289
10290 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10291
10292 \end_inset 
10293
10294 ) which should not be confused with the internal, directly addressable RAM
10295  memory (
10296 \emph on 
10297 data
10298 \emph default 
10299
10300 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10301
10302 \end_inset 
10303
10304
10305 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10306
10307 \end_inset 
10308
10309 ).
10310  Sometimes this built in 
10311 \emph on 
10312 xdata
10313 \emph default 
10314  memory has to be activated before using it (you can probably find this
10315  information on the datasheet of the microcontroller your are using, see
10316  also section 
10317 \begin_inset LatexCommand \ref{sub:Startup-Code}
10318
10319 \end_inset 
10320
10321 \SpecialChar ~
10322 Startup-Code).
10323 \layout Standard
10324
10325 Normally SDCC will only use the first bank
10326 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10327
10328 \end_inset 
10329
10330  of registers (register bank 0), but it is possible to specify that other
10331  banks of registers (keyword 
10332 \emph on 
10333 using
10334 \emph default 
10335  
10336 \emph on 
10337
10338 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10339
10340 \end_inset 
10341
10342
10343 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10344
10345 \end_inset 
10346
10347
10348 \emph default 
10349 ) should be used in interrupt
10350 \begin_inset LatexCommand \index{interrupt}
10351
10352 \end_inset 
10353
10354
10355 \begin_inset LatexCommand \index{\_\_interrupt}
10356
10357 \end_inset 
10358
10359  routines.
10360  By default, the compiler will place the stack after the last byte of allocated
10361  memory for variables.
10362  For example, if the first 2 banks of registers are used, and only four
10363  bytes are used for 
10364 \emph on 
10365 data
10366 \emph default 
10367  variables, it will position the base of the internal stack at address 20
10368  (0x14).
10369  This implies that as the stack
10370 \begin_inset LatexCommand \index{stack}
10371
10372 \end_inset 
10373
10374  grows, it will use up the remaining register banks, and the 16 bytes used
10375  by the 128 bit variables, and 80 bytes for general purpose use.
10376  If any bit variables are used, the data variables will be placed in unused
10377  register banks and after the byte holding the last bit variable.
10378  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10379  (two bytes used), 
10380 \emph on 
10381 data
10382 \emph default 
10383  variables will be placed starting from address 0x10 to 0x20 and continue
10384  at address 0x22.
10385  You can also use -
10386 \begin_inset ERT
10387 status Collapsed
10388
10389 \layout Standard
10390
10391 \backslash 
10392 /
10393 \end_inset 
10394
10395 -data-loc
10396 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10397
10398 \end_inset 
10399
10400  to specify the start address of the 
10401 \emph on 
10402 data
10403 \emph default 
10404  and -
10405 \begin_inset ERT
10406 status Collapsed
10407
10408 \layout Standard
10409
10410 \backslash 
10411 /
10412 \end_inset 
10413
10414 -iram-size
10415 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10416
10417 \end_inset 
10418
10419  to specify the size of the total internal RAM (
10420 \emph on 
10421 data
10422 \emph default 
10423 +
10424 \emph on 
10425 idata
10426 \emph default 
10427 ).
10428  
10429 \newline 
10430
10431 \layout Standard
10432
10433 By default the 8051 linker will place the stack after the last byte of (i)data
10434  variables.
10435  Option -
10436 \begin_inset ERT
10437 status Collapsed
10438
10439 \layout Standard
10440
10441 \backslash 
10442 /
10443 \end_inset 
10444
10445 -stack-loc
10446 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10447
10448 \end_inset 
10449
10450  allows you to specify the start of the stack, i.e.
10451  you could start it after any data in the general purpose area.
10452  If your microcontroller has additional indirectly addressable internal
10453  RAM (
10454 \emph on 
10455 idata
10456 \emph default 
10457 ) you can place the stack on it.
10458  You may also need to use -
10459 \begin_inset ERT
10460 status Collapsed
10461
10462 \layout Standard
10463
10464 \backslash 
10465 /
10466 \end_inset 
10467
10468 -xdata-loc
10469 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10470
10471 \end_inset 
10472
10473  to set the start address of the external RAM (
10474 \emph on 
10475 xdata
10476 \emph default 
10477 ) and -
10478 \begin_inset ERT
10479 status Collapsed
10480
10481 \layout Standard
10482
10483 \backslash 
10484 /
10485 \end_inset 
10486
10487 -xram-size
10488 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10489
10490 \end_inset 
10491
10492  to specify its size.
10493  Same goes for the code memory, using -
10494 \begin_inset ERT
10495 status Collapsed
10496
10497 \layout Standard
10498
10499 \backslash 
10500 /
10501 \end_inset 
10502
10503 -code-loc
10504 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10505
10506 \end_inset 
10507
10508  and -
10509 \begin_inset ERT
10510 status Collapsed
10511
10512 \layout Standard
10513
10514 \backslash 
10515 /
10516 \end_inset 
10517
10518 -code-size
10519 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10520
10521 \end_inset 
10522
10523 .
10524  If in doubt, don't specify any options and see if the resulting memory
10525  layout is appropriate, then you can adjust it.
10526 \layout Standard
10527 \added_space_bottom bigskip 
10528 The linker generates two files with memory allocation information.
10529  The first, with extension .map
10530 \begin_inset LatexCommand \index{<file>.map}
10531
10532 \end_inset 
10533
10534  shows all the variables and segments.
10535  The second with extension .mem
10536 \begin_inset LatexCommand \index{<file>.mem}
10537
10538 \end_inset 
10539
10540  shows the final memory layout.
10541  The linker will complain either if memory segments overlap, there is not
10542  enough memory, or there is not enough space for stack.
10543  If you get any linking warnings and/or errors related to stack or segments
10544  allocation, take a look at either the .map or .mem files to find out what
10545  the problem is.
10546  The .mem file may even suggest a solution to the problem.
10547 \layout Subsection
10548
10549 Z80/Z180 Storage Class
10550 \begin_inset LatexCommand \index{Z80!Storage class}
10551
10552 \end_inset 
10553
10554  Language Extensions
10555 \layout Subsubsection
10556
10557 sfr
10558 \begin_inset LatexCommand \index{sfr}
10559
10560 \end_inset 
10561
10562
10563 \begin_inset LatexCommand \index{\_\_sfr}
10564
10565 \end_inset 
10566
10567  (in/out to 8-bit addresses)
10568 \layout Standard
10569
10570 The Z80
10571 \begin_inset LatexCommand \index{Z80}
10572
10573 \end_inset 
10574
10575  family has separate address spaces for memory and 
10576 \emph on 
10577 i
10578 \emph default 
10579 nput/
10580 \emph on 
10581 o
10582 \emph default 
10583 utput memory.
10584  I/O memory
10585 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10586
10587 \end_inset 
10588
10589
10590 \begin_inset LatexCommand \index{Z80!I/O memory}
10591
10592 \end_inset 
10593
10594
10595 \begin_inset LatexCommand \index{Z180!I/O memory}
10596
10597 \end_inset 
10598
10599  is accessed with special instructions, e.g.:
10600 \layout Verse
10601
10602
10603 \family typewriter 
10604 sfr at 0x78 IoPort;\SpecialChar ~
10605 \SpecialChar ~
10606 /* define a var in I/O space at 78h called IoPort */
10607  
10608 \layout Standard
10609
10610 Writing 0x01 to this variable generates the assembly code:
10611 \layout Verse
10612
10613
10614 \family typewriter 
10615 3E 01\SpecialChar ~
10616 \SpecialChar ~
10617 \SpecialChar ~
10618 \SpecialChar ~
10619 \SpecialChar ~
10620 \SpecialChar ~
10621 ld a,#0x01
10622 \newline 
10623 D3 78\SpecialChar ~
10624 \SpecialChar ~
10625 \SpecialChar ~
10626 \SpecialChar ~
10627 \SpecialChar ~
10628 \SpecialChar ~
10629 out (_IoPort),a 
10630 \layout Subsubsection
10631
10632 banked sfr
10633 \begin_inset LatexCommand \index{sfr}
10634
10635 \end_inset 
10636
10637
10638 \begin_inset LatexCommand \index{\_\_sfr}
10639
10640 \end_inset 
10641
10642  (in/out to 16-bit addresses)
10643 \layout Standard
10644
10645 The keyword 
10646 \emph on 
10647 banked
10648 \emph default 
10649  is used to support 16 bit addresses in I/O memory e.g.:
10650 \layout Verse
10651
10652
10653 \family typewriter 
10654 sfr banked at
10655 \begin_inset LatexCommand \index{at}
10656
10657 \end_inset 
10658
10659
10660 \begin_inset LatexCommand \index{\_\_at}
10661
10662 \end_inset 
10663
10664  0x123 IoPort; 
10665 \layout Standard
10666
10667 Writing 0x01 to this variable generates the assembly code:
10668 \layout Verse
10669
10670
10671 \family typewriter 
10672 01 23 01\SpecialChar ~
10673 \SpecialChar ~
10674 \SpecialChar ~
10675 ld bc,#_IoPort
10676 \newline 
10677 3E 01\SpecialChar ~
10678 \SpecialChar ~
10679 \SpecialChar ~
10680 \SpecialChar ~
10681 \SpecialChar ~
10682 \SpecialChar ~
10683 ld a,#0x01 
10684 \newline 
10685 ED 79\SpecialChar ~
10686 \SpecialChar ~
10687 \SpecialChar ~
10688 \SpecialChar ~
10689 \SpecialChar ~
10690 \SpecialChar ~
10691 out (c),a 
10692 \layout Subsubsection
10693
10694 sfr
10695 \begin_inset LatexCommand \index{sfr}
10696
10697 \end_inset 
10698
10699
10700 \begin_inset LatexCommand \index{\_\_sfr}
10701
10702 \end_inset 
10703
10704  (in0/out0 to 8 bit addresses on Z180
10705 \begin_inset LatexCommand \index{Z180}
10706
10707 \end_inset 
10708
10709 /HD64180
10710 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10711
10712 \end_inset 
10713
10714 )
10715 \layout Standard
10716 \added_space_bottom bigskip 
10717 The compiler option -
10718 \begin_inset ERT
10719 status Collapsed
10720
10721 \layout Standard
10722
10723 \backslash 
10724 /
10725 \end_inset 
10726
10727 -portmode
10728 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10729
10730 \end_inset 
10731
10732 =180 (80) and a compiler #pragma\SpecialChar ~
10733 portmode
10734 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10735
10736 \end_inset 
10737
10738  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10739 ns 
10740 \family typewriter 
10741 in0/out0
10742 \family default 
10743  instead of 
10744 \family typewriter 
10745 in/out
10746 \family default 
10747 .
10748  If you include the file z180.h this will be set automatically.
10749 \layout Subsection
10750
10751 HC08 Storage Class
10752 \begin_inset LatexCommand \index{HC08!Storage class}
10753
10754 \end_inset 
10755
10756  Language Extensions
10757 \layout Subsubsection
10758
10759 data
10760 \begin_inset LatexCommand \index{data (hc08 storage class)}
10761
10762 \end_inset 
10763
10764
10765 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10766
10767 \end_inset 
10768
10769  
10770 \layout Standard
10771
10772 The data storage class declares a variable that resides in the first 256
10773  bytes of memory (the direct page).
10774  The HC08
10775 \begin_inset LatexCommand \index{HC08}
10776
10777 \end_inset 
10778
10779  is most efficient at accessing variables (especially pointers) stored here.
10780 \layout Subsubsection
10781
10782 xdata
10783 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10784
10785 \end_inset 
10786
10787
10788 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10789
10790 \end_inset 
10791
10792  
10793 \layout Standard
10794 \added_space_bottom bigskip 
10795 The xdata storage class declares a variable that can reside anywhere in
10796  memory.
10797  This is the default if no storage class is specified.
10798  
10799 \layout Section
10800
10801 Absolute Addressing
10802 \begin_inset LatexCommand \index{Absolute addressing}
10803
10804 \end_inset 
10805
10806
10807 \layout Standard
10808
10809 Data items can be assigned an absolute address with the 
10810 \emph on 
10811 at
10812 \begin_inset LatexCommand \index{at}
10813
10814 \end_inset 
10815
10816
10817 \begin_inset LatexCommand \index{\_\_at}
10818
10819 \end_inset 
10820
10821  <address>
10822 \emph default 
10823  keyword, in addition to a storage class, e.g.:
10824 \layout Verse
10825
10826
10827 \family typewriter 
10828 xdata
10829 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10830
10831 \end_inset 
10832
10833
10834 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10835
10836 \end_inset 
10837
10838  at
10839 \begin_inset LatexCommand \index{at}
10840
10841 \end_inset 
10842
10843
10844 \begin_inset LatexCommand \index{\_\_at}
10845
10846 \end_inset 
10847
10848  0x7ffe unsigned int chksum;
10849 \layout Standard
10850
10851 or, better conforming to ISO/IEC 9899 C:
10852 \layout Verse
10853
10854
10855 \family typewriter 
10856 __xdata __at (0x7ffe) unsigned int chksum;
10857 \layout Standard
10858
10859 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10860  of the external ram.
10861  The compiler does 
10862 \emph on 
10863 not
10864 \emph default 
10865  reserve any space for variables declared in this way
10866 \begin_inset Marginal
10867 collapsed true
10868
10869 \layout Standard
10870
10871
10872 \series bold 
10873 \SpecialChar ~
10874 !
10875 \end_inset 
10876
10877  (they are implemented with an equate in the assembler).
10878  Thus it is left to the programmer to make sure there are no overlaps with
10879  other variables that are declared without the absolute address.
10880  The assembler listing file (.lst
10881 \begin_inset LatexCommand \index{<file>.lst}
10882
10883 \end_inset 
10884
10885 ) and the linker output files (.rst
10886 \begin_inset LatexCommand \index{<file>.rst}
10887
10888 \end_inset 
10889
10890 ) and (.map
10891 \begin_inset LatexCommand \index{<file>.map}
10892
10893 \end_inset 
10894
10895 ) are good places to look for such overlaps.
10896  Variables with an absolute address are 
10897 \emph on 
10898 not
10899 \begin_inset Marginal
10900 collapsed true
10901
10902 \layout Standard
10903
10904
10905 \series bold 
10906 \SpecialChar ~
10907 !
10908 \end_inset 
10909
10910
10911 \emph default 
10912  initialized
10913 \begin_inset LatexCommand \index{Variable initialization}
10914
10915 \end_inset 
10916
10917 .
10918 \layout Standard
10919
10920 In case of memory mapped I/O devices the keyword 
10921 \emph on 
10922 volatile
10923 \emph default 
10924  has to be used to tell the compiler that accesses might not be removed:
10925 \layout Verse
10926
10927
10928 \family typewriter 
10929 volatile
10930 \begin_inset LatexCommand \index{volatile}
10931
10932 \end_inset 
10933
10934  __xdata
10935 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10936
10937 \end_inset 
10938
10939  __at
10940 \begin_inset LatexCommand \index{at}
10941
10942 \end_inset 
10943
10944  (0x8000) unsigned char PORTA_8255;
10945 \layout Standard
10946
10947 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10948 r) array
10949 \family typewriter 
10950 \size footnotesize 
10951
10952 \begin_inset LatexCommand \index{Aligned array}
10953
10954 \end_inset 
10955
10956
10957 \family default 
10958 \size default 
10959  starts at a block (256 byte) boundary
10960 \begin_inset LatexCommand \index{block boundary}
10961
10962 \end_inset 
10963
10964  (section 
10965 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10966
10967 \end_inset 
10968
10969  has an example).
10970 \newline 
10971 Absolute addresses can be specified for variables in all storage classes,
10972  e.g.:
10973 \layout Verse
10974
10975
10976 \family typewriter 
10977 __bit
10978 \begin_inset LatexCommand \index{bit}
10979
10980 \end_inset 
10981
10982  __at
10983 \begin_inset LatexCommand \index{at}
10984
10985 \end_inset 
10986
10987  (0x02) bvar;
10988 \layout Standard
10989
10990 The above example will allocate the variable at offset 0x02 in the bit-addressab
10991 le space.
10992  There is no real advantage to assigning absolute addresses to variables
10993  in this manner, unless you want strict control over all the variables allocated.
10994  One possible use would be to write hardware portable code.
10995  For example, if you have a routine that uses one or more of the microcontroller
10996  I/O pins, and such pins are different for two different hardwares, you
10997  can declare the I/O pins in your routine using:
10998 \layout Verse
10999
11000
11001 \family typewriter 
11002 extern volatile
11003 \begin_inset LatexCommand \index{volatile}
11004
11005 \end_inset 
11006
11007  __bit MOSI;\SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 /* master out, slave in */
11012 \newline 
11013 extern volatile __bit MISO;\SpecialChar ~
11014 \SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 /* master in, slave out */
11018 \newline 
11019 extern volatile __bit MCLK;\SpecialChar ~
11020 \SpecialChar ~
11021 \SpecialChar ~
11022 \SpecialChar ~
11023 /* master clock */
11024 \newline 
11025
11026 \newline 
11027 /* Input and Output of a byte on a 3-wire serial bus.
11028 \newline 
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 \SpecialChar ~
11032 If needed adapt polarity of clock, polarity of data and bit order
11033 \newline 
11034 \SpecialChar ~
11035 */
11036 \newline 
11037 unsigned char spi_io(unsigned char out_byte) 
11038 \newline 
11039
11040 \newline 
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 unsigned char i=8;
11046 \newline 
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 do { 
11052 \newline 
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 MOSI = out_byte & 0x80; 
11062 \newline 
11063 \SpecialChar ~
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 out_byte <<= 1;
11072 \newline 
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 \SpecialChar ~
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 MCLK = 1; 
11082 \newline 
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 /* _asm nop _endasm; */\SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 \SpecialChar ~
11095 \SpecialChar ~
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 /* for slow peripherals */
11100 \newline 
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 if(MISO) 
11110 \newline 
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 out_byte += 1; 
11124 \newline 
11125 \SpecialChar ~
11126 \SpecialChar ~
11127 \SpecialChar ~
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 MCLK = 0; 
11134 \newline 
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 } while(--i);
11140 \newline 
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 return out_byte; 
11146 \newline 
11147 }
11148 \layout Standard
11149
11150 Then, someplace in the code for the first hardware you would use
11151 \layout Verse
11152
11153
11154 \family typewriter 
11155 __bit __at
11156 \begin_inset LatexCommand \index{at}
11157
11158 \end_inset 
11159
11160
11161 \begin_inset LatexCommand \index{\_\_at}
11162
11163 \end_inset 
11164
11165  (0x80) MOSI;\SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 /* I/O port 0, bit 0 */
11170 \newline 
11171 __bit __at (0x81) MISO;\SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 /* I/O port 0, bit 1 */
11176 \newline 
11177 __bit __at (0x82) MCLK;\SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 \SpecialChar ~
11181 /* I/O port 0, bit 2 */
11182 \layout Standard
11183
11184 Similarly, for the second hardware you would use
11185 \layout Verse
11186
11187
11188 \family typewriter 
11189 __bit __at (0x83) MOSI;\SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 /* I/O port 0, bit 3 */
11194 \newline 
11195 __bit __at (0x91) MISO;\SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 /* I/O port 1, bit 1 */
11200 \newline 
11201 __bit
11202 \begin_inset LatexCommand \index{bit}
11203
11204 \end_inset 
11205
11206  __at (0x92) MCLK;\SpecialChar ~
11207 \SpecialChar ~
11208 \SpecialChar ~
11209 \SpecialChar ~
11210 /* I/O port 1, bit 2 */
11211 \layout Standard
11212 \added_space_bottom bigskip 
11213 and you can use the same hardware dependent routine without changes, as
11214  for example in a library.
11215  This is somehow similar to sbit, but only one absolute address has to be
11216  specified in the whole project.
11217 \layout Section
11218
11219 Parameters
11220 \begin_inset LatexCommand \index{Parameters}
11221
11222 \end_inset 
11223
11224
11225 \begin_inset LatexCommand \index{function parameter}
11226
11227 \end_inset 
11228
11229  & Local Variables
11230 \begin_inset LatexCommand \index{local variables}
11231
11232 \end_inset 
11233
11234
11235 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11236
11237 \end_inset 
11238
11239
11240 \layout Standard
11241
11242 Automatic (local) variables and parameters to functions can either be placed
11243  on the stack or in data-space.
11244  The default action of the compiler is to place these variables in the internal
11245  RAM (for small model) or external RAM (for large model).
11246  This in fact makes them similar to 
11247 \emph on 
11248 static
11249 \begin_inset LatexCommand \index{static}
11250
11251 \end_inset 
11252
11253
11254 \emph default 
11255  so by default functions are non-reentrant
11256 \begin_inset LatexCommand \index{reentrant}
11257
11258 \end_inset 
11259
11260 .
11261  
11262 \newline 
11263
11264 \newline 
11265 They can be placed on the stack
11266 \begin_inset LatexCommand \index{stack}
11267
11268 \end_inset 
11269
11270  by using the
11271 \emph on 
11272  -
11273 \begin_inset ERT
11274 status Collapsed
11275
11276 \layout Standard
11277
11278 \backslash 
11279 /
11280 \end_inset 
11281
11282 -stack-auto
11283 \begin_inset LatexCommand \index{-\/-stack-auto}
11284
11285 \end_inset 
11286
11287
11288 \emph default 
11289  option, by using 
11290 \emph on 
11291 #pragma\SpecialChar ~
11292 stackauto
11293 \emph default 
11294
11295 \begin_inset LatexCommand \index{\#pragma stackauto}
11296
11297 \end_inset 
11298
11299  or by using the 
11300 \emph on 
11301 reentrant
11302 \begin_inset LatexCommand \index{reentrant}
11303
11304 \end_inset 
11305
11306
11307 \emph default 
11308  keyword in the function declaration, e.g.:
11309 \layout Verse
11310
11311
11312 \family typewriter 
11313 unsigned char foo(char i) __reentrant 
11314 \newline 
11315
11316 \newline 
11317 \SpecialChar ~
11318 \SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 ...
11322  
11323 \newline 
11324 }
11325 \layout Standard
11326
11327 Since stack space on 8051 is limited, the 
11328 \emph on 
11329 reentrant 
11330 \emph default 
11331 keyword or the
11332 \emph on 
11333  -
11334 \begin_inset ERT
11335 status Collapsed
11336
11337 \layout Standard
11338
11339 \backslash 
11340 /
11341 \end_inset 
11342
11343 -stack-auto
11344 \emph default 
11345  option should be used sparingly.
11346  Note that the reentrant keyword just means that the parameters & local
11347  variables will be allocated to the stack, it 
11348 \emph on 
11349 does not
11350 \emph default 
11351  mean that the function is register bank
11352 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11353
11354 \end_inset 
11355
11356  independent.
11357 \newline 
11358
11359 \newline 
11360 Local variables
11361 \begin_inset LatexCommand \index{local variables}
11362
11363 \end_inset 
11364
11365  can be assigned storage classes and absolute
11366 \begin_inset LatexCommand \index{Absolute addressing}
11367
11368 \end_inset 
11369
11370  addresses, e.g.: 
11371 \layout Verse
11372
11373
11374 \family typewriter 
11375 unsigned char foo() 
11376 \newline 
11377 {
11378 \newline 
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 __xdata unsigned char i;
11384 \newline 
11385 \SpecialChar ~
11386 \SpecialChar ~
11387 \SpecialChar ~
11388 \SpecialChar ~
11389 __bit bvar;
11390 \newline 
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 \SpecialChar ~
11394 \SpecialChar ~
11395 __data __at
11396 \begin_inset LatexCommand \index{at}
11397
11398 \end_inset 
11399
11400  (0x31) unsigned char j;
11401 \newline 
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 ...
11407  
11408 \newline 
11409 }
11410 \layout Standard
11411
11412 In the above example the variable 
11413 \emph on 
11414 i
11415 \emph default 
11416  will be allocated in the external ram, 
11417 \emph on 
11418 bvar
11419 \emph default 
11420  in bit addressable space and
11421 \emph on 
11422  j
11423 \emph default 
11424  in internal ram.
11425  When compiled with 
11426 \emph on 
11427 -
11428 \begin_inset ERT
11429 status Collapsed
11430
11431 \layout Standard
11432
11433 \backslash 
11434 /
11435 \end_inset 
11436
11437 -stack-auto
11438 \emph default 
11439  or when a function is declared as 
11440 \emph on 
11441 reentrant
11442 \emph default 
11443  this should only be done for static variables.
11444 \layout Standard
11445
11446 Parameters
11447 \begin_inset LatexCommand \index{function parameter}
11448
11449 \end_inset 
11450
11451  however are not allowed any storage class
11452 \begin_inset LatexCommand \index{Storage class}
11453
11454 \end_inset 
11455
11456 , (storage classes for parameters will be ignored), their allocation is
11457  governed by the memory model in use, and the reentrancy options.
11458 \layout Standard
11459
11460 It is however allowed to use bit parameters in reentrant functions and also
11461  non-static local bit variables are supported.
11462  Efficient use is limited to 8 semi-bitregisters in bit space.
11463  They are pushed and popped to stack
11464 \begin_inset LatexCommand \index{stack}
11465
11466 \end_inset 
11467
11468  as a single byte just like the normal registers.
11469 \layout Section
11470
11471 Overlaying
11472 \begin_inset LatexCommand \label{sub:Overlaying}
11473
11474 \end_inset 
11475
11476
11477 \begin_inset LatexCommand \index{Overlaying}
11478
11479 \end_inset 
11480
11481
11482 \layout Standard
11483
11484 For non-reentrant
11485 \begin_inset LatexCommand \index{reentrant}
11486
11487 \end_inset 
11488
11489  functions SDCC will try to reduce internal ram space usage by overlaying
11490  parameters and local variables of a function (if possible).
11491  Parameters and local variables
11492 \begin_inset LatexCommand \index{local variables}
11493
11494 \end_inset 
11495
11496  of a function will be allocated to an overlayable segment if the function
11497  has 
11498 \emph on 
11499 no other function calls and the function is non-reentrant and the memory
11500  model
11501 \begin_inset LatexCommand \index{Memory model}
11502
11503 \end_inset 
11504
11505  is small.
11506
11507 \emph default 
11508  If an explicit storage class
11509 \begin_inset LatexCommand \index{Storage class}
11510
11511 \end_inset 
11512
11513  is specified for a local variable, it will NOT be overlayed.
11514 \layout Standard
11515
11516 Note that the compiler (not the linkage editor) makes the decision for overlayin
11517 g the data items.
11518  Functions that are called from an interrupt service routine
11519 \begin_inset Marginal
11520 collapsed true
11521
11522 \layout Standard
11523
11524
11525 \series bold 
11526 !
11527 \end_inset 
11528
11529  should be preceded by a #pragma\SpecialChar ~
11530 nooverlay
11531 \begin_inset LatexCommand \index{\#pragma nooverlay}
11532
11533 \end_inset 
11534
11535  if they are not reentrant.
11536 \layout Standard
11537
11538 Also note that the compiler does not do any processing of inline assembler
11539  code, so the compiler might incorrectly assign local variables and parameters
11540  of a function into the overlay segment if the inline assembler code calls
11541  other c-functions that might use the overlay.
11542  In that case the #pragma\SpecialChar ~
11543 nooverlay should be used.
11544 \layout Standard
11545
11546 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11547 tion
11548 \begin_inset LatexCommand \index{Multiplication}
11549
11550 \end_inset 
11551
11552  or division
11553 \begin_inset LatexCommand \index{Division}
11554
11555 \end_inset 
11556
11557  will NOT be overlayed since these are implemented using external functions,
11558  e.g.:
11559 \layout Verse
11560
11561
11562 \family typewriter 
11563 #pragma save 
11564 \newline 
11565 #pragma nooverlay
11566 \begin_inset LatexCommand \index{\#pragma nooverlay}
11567
11568 \end_inset 
11569
11570  
11571 \newline 
11572 void set_error(unsigned char errcd) 
11573 \newline 
11574 {
11575 \newline 
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 P3 = errcd;
11581 \newline 
11582
11583 \newline 
11584 #pragma restore 
11585 \newline 
11586
11587 \newline 
11588 void some_isr () __interrupt
11589 \begin_inset LatexCommand \index{interrupt}
11590
11591 \end_inset 
11592
11593  (2)
11594 \newline 
11595 {
11596 \newline 
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 ...
11602 \newline 
11603 \SpecialChar ~
11604 \SpecialChar ~
11605 \SpecialChar ~
11606 \SpecialChar ~
11607 set_error(10);
11608 \newline 
11609 \SpecialChar ~
11610 \SpecialChar ~
11611 \SpecialChar ~
11612 \SpecialChar ~
11613 ...
11614  
11615 \newline 
11616 }
11617 \layout Standard
11618 \added_space_bottom bigskip 
11619 In the above example the parameter 
11620 \emph on 
11621 errcd
11622 \emph default 
11623  for the function 
11624 \emph on 
11625 set_error
11626 \emph default 
11627  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11628 nooverlay was
11629  not present, this could cause unpredictable runtime behavior when called
11630  from an interrupt service routine.
11631  The #pragma\SpecialChar ~
11632 nooverlay ensures that the parameters and local variables for
11633  the function are NOT overlayed.
11634 \layout Section
11635
11636 Interrupt Service Routines
11637 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11638
11639 \end_inset 
11640
11641
11642 \layout Subsection
11643
11644 General Information
11645 \layout Standard
11646
11647 SDCC allows 
11648 \emph on 
11649 i
11650 \emph default 
11651 nterrupt 
11652 \emph on 
11653 s
11654 \emph default 
11655 ervice 
11656 \emph on 
11657 r
11658 \emph default 
11659 outines to be coded in C, with some extended keywords.
11660 \layout Verse
11661
11662
11663 \family typewriter 
11664 void timer_isr (void) __interrupt (1) __using (1) 
11665 \newline 
11666
11667 \newline 
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 \SpecialChar ~
11672 ...
11673  
11674 \newline 
11675 }
11676 \layout Standard
11677
11678 The optional number following the 
11679 \emph on 
11680 interrupt
11681 \begin_inset LatexCommand \index{interrupt}
11682
11683 \end_inset 
11684
11685
11686 \begin_inset LatexCommand \index{\_\_interrupt}
11687
11688 \end_inset 
11689
11690
11691 \emph default 
11692  keyword is the interrupt number this routine will service.
11693  When present, the compiler will insert a call to this routine in the interrupt
11694  vector table
11695 \begin_inset LatexCommand \index{interrupt vector table}
11696
11697 \end_inset 
11698
11699  for the interrupt number specified.
11700  If you have multiple source files in your project, interrupt service routines
11701  can be present in any of them, but a prototype of the isr MUST be present
11702  or included in the file that contains the function 
11703 \emph on 
11704 main
11705 \emph default 
11706 .
11707  The optional (8051 specific) keyword 
11708 \emph on 
11709 using
11710 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11711
11712 \end_inset 
11713
11714
11715 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11716
11717 \end_inset 
11718
11719
11720 \emph default 
11721  can be used to tell the compiler to use the specified register bank when
11722  generating code for this function.
11723  
11724 \newline 
11725 Interrupt service routines open the door for some very interesting bugs:
11726 \layout Subsubsection
11727
11728
11729 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11730
11731 \end_inset 
11732
11733 Common interrupt pitfall: variable not declared 
11734 \emph on 
11735 volatile
11736 \layout Standard
11737
11738 If an interrupt service routine changes variables which are accessed by
11739  other functions these variables have to be declared 
11740 \emph on 
11741 volatile
11742 \emph default 
11743
11744 \begin_inset LatexCommand \index{volatile}
11745
11746 \end_inset 
11747
11748 .
11749  See 
11750 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11751
11752 \end_inset 
11753
11754  .
11755 \layout Subsubsection
11756
11757
11758 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11759
11760 \end_inset 
11761
11762 Common interrupt pitfall: 
11763 \emph on 
11764 non-atomic access
11765 \layout Standard
11766
11767 If the access to these variables is not 
11768 \emph on 
11769 atomic
11770 \begin_inset LatexCommand \index{atomic}
11771
11772 \end_inset 
11773
11774
11775 \emph default 
11776  (i.e.
11777  the processor needs more than one instruction for the access and could
11778  be interrupted while accessing the variable) the interrupt must be disabled
11779  during the access to avoid inconsistent data.
11780  
11781 \newline 
11782 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11783  should be protected by disabling interrupts.
11784  You're not automatically on the safe side if you use 8 bit variables though.
11785  We need an example here: f.e.
11786  on the 8051 the harmless looking 
11787 \begin_inset Quotes srd
11788 \end_inset 
11789
11790
11791 \family typewriter 
11792 flags\SpecialChar ~
11793 |=\SpecialChar ~
11794 0x80;
11795 \family default 
11796
11797 \begin_inset Quotes sld
11798 \end_inset 
11799
11800  is not atomic if 
11801 \family typewriter 
11802 flags
11803 \family default 
11804  resides in xdata.
11805  Setting 
11806 \begin_inset Quotes srd
11807 \end_inset 
11808
11809
11810 \family typewriter 
11811 flags\SpecialChar ~
11812 |=\SpecialChar ~
11813 0x40;
11814 \family default 
11815
11816 \begin_inset Quotes sld
11817 \end_inset 
11818
11819  from within an interrupt routine might get lost if the interrupt occurs
11820  at the wrong time.
11821  
11822 \begin_inset Quotes sld
11823 \end_inset 
11824
11825
11826 \family typewriter 
11827 counter\SpecialChar ~
11828 +=\SpecialChar ~
11829 8;
11830 \family default 
11831
11832 \begin_inset Quotes srd
11833 \end_inset 
11834
11835  is not atomic on the 8051 even if 
11836 \family typewriter 
11837 counter
11838 \family default 
11839  is located in data memory.
11840 \newline 
11841 Bugs like these are hard to reproduce and can cause a lot of trouble.
11842  
11843 \layout Subsubsection
11844
11845
11846 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11847
11848 \end_inset 
11849
11850 Common interrupt pitfall: 
11851 \emph on 
11852 stack overflow
11853 \layout Standard
11854
11855 The return address and the registers used in the interrupt service routine
11856  are saved on the stack
11857 \begin_inset LatexCommand \index{stack}
11858
11859 \end_inset 
11860
11861  so there must be sufficient stack space.
11862  If there isn't variables or registers (or even the return address itself)
11863  will be corrupted.
11864  This 
11865 \emph on 
11866 stack overflow
11867 \emph default 
11868
11869 \begin_inset LatexCommand \index{stack overflow}
11870
11871 \end_inset 
11872
11873  is most likely to happen if the interrupt occurs during the 
11874 \begin_inset Quotes sld
11875 \end_inset 
11876
11877 deepest
11878 \begin_inset Quotes srd
11879 \end_inset 
11880
11881  subroutine when the stack is already in use for f.e.
11882  many return addresses.
11883 \layout Subsubsection
11884
11885
11886 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11887
11888 \end_inset 
11889
11890 Common interrupt pitfall: 
11891 \emph on 
11892 use of non-reentrant functions
11893 \layout Standard
11894
11895 A special note here, int (16 bit) and long (32 bit) integer division
11896 \begin_inset LatexCommand \index{Division}
11897
11898 \end_inset 
11899
11900 , multiplication
11901 \begin_inset LatexCommand \index{Multiplication}
11902
11903 \end_inset 
11904
11905  & modulus
11906 \begin_inset LatexCommand \index{Modulus}
11907
11908 \end_inset 
11909
11910  and floating-point
11911 \begin_inset LatexCommand \index{Floating point support}
11912
11913 \end_inset 
11914
11915  operations are implemented using external support routines.
11916  If an interrupt service routine needs to do any of these operations then
11917  the support routines (as mentioned in a following section) will have to
11918  be recompiled using the
11919 \emph on 
11920  -
11921 \begin_inset ERT
11922 status Collapsed
11923
11924 \layout Standard
11925
11926 \backslash 
11927 /
11928 \end_inset 
11929
11930 -stack-auto
11931 \begin_inset LatexCommand \index{-\/-stack-auto}
11932
11933 \end_inset 
11934
11935
11936 \emph default 
11937  option and the source file will need to be compiled using the 
11938 \emph on 
11939 -
11940 \begin_inset ERT
11941 status Collapsed
11942
11943 \layout Standard
11944
11945 \backslash 
11946 /
11947 \end_inset 
11948
11949 -int-long-reent
11950 \emph default 
11951
11952 \begin_inset LatexCommand \index{-\/-int-long-reent}
11953
11954 \end_inset 
11955
11956  compiler option.
11957  
11958 \newline 
11959 Note, the type promotion
11960 \begin_inset LatexCommand \index{type promotion}
11961
11962 \end_inset 
11963
11964  required by ANSI C can cause 16 bit routines to be used
11965 \begin_inset Marginal
11966 collapsed true
11967
11968 \layout Standard
11969
11970
11971 \series bold 
11972 \SpecialChar ~
11973 !
11974 \end_inset 
11975
11976  without the programmer being aware of it.
11977  See f.e.
11978  the cast 
11979 \family typewriter 
11980 (unsigned char)(tail-1)
11981 \family default 
11982  within the if clause in section 
11983 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11984
11985 \end_inset 
11986
11987 .
11988 \layout Standard
11989 \added_space_bottom bigskip 
11990 Calling other functions from an interrupt service routine is not recommended,
11991  avoid it if possible.
11992  Note that when some function is called from an interrupt service routine
11993  it should be preceded by a #pragma\SpecialChar ~
11994 nooverlay
11995 \begin_inset LatexCommand \index{\#pragma nooverlay}
11996
11997 \end_inset 
11998
11999  if it is not reentrant.
12000  Furthermore nonreentrant functions should not be called from the main program
12001  while the interrupt service routine might be active.
12002  They also must not be called from low priority interrupt service routines
12003  while a high priority interrupt service routine might be active.
12004  You could use semaphores or make the function
12005 \emph on 
12006  critical
12007 \emph default 
12008  if all parameters are passed in registers.
12009 \newline 
12010  Also see section 
12011 \begin_inset LatexCommand \ref{sub:Overlaying}
12012
12013 \end_inset 
12014
12015 \SpecialChar ~
12016 about Overlaying and section 
12017 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12018
12019 \end_inset 
12020
12021 \SpecialChar ~
12022 about Functions using private register banks.
12023 \layout Subsection
12024
12025 MCS51/DS390 Interrupt Service Routines
12026 \layout Standard
12027
12028 Interrupt
12029 \begin_inset LatexCommand \index{interrupt}
12030
12031 \end_inset 
12032
12033  numbers and the corresponding address & descriptions for the Standard 8051/8052
12034  are listed below.
12035  SDCC will automatically adjust the 
12036 \begin_inset LatexCommand \index{interrupt vector table}
12037
12038 \end_inset 
12039
12040  to the maximum interrupt number specified.
12041 \newline 
12042
12043 \layout Standard
12044 \align center 
12045
12046 \begin_inset  Tabular
12047 <lyxtabular version="3" rows="9" columns="3">
12048 <features>
12049 <column alignment="center" valignment="top" leftline="true" width="0in">
12050 <column alignment="left" valignment="top" leftline="true" width="0in">
12051 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12052 <row topline="true" bottomline="true">
12053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12054 \begin_inset Text
12055
12056 \layout Standard
12057
12058 Interrupt #
12059 \end_inset 
12060 </cell>
12061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12062 \begin_inset Text
12063
12064 \layout Standard
12065
12066 Description
12067 \end_inset 
12068 </cell>
12069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12070 \begin_inset Text
12071
12072 \layout Standard
12073
12074 Vector Address
12075 \end_inset 
12076 </cell>
12077 </row>
12078 <row topline="true">
12079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12080 \begin_inset Text
12081
12082 \layout Standard
12083
12084 0
12085 \end_inset 
12086 </cell>
12087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12088 \begin_inset Text
12089
12090 \layout Standard
12091
12092 External 0
12093 \end_inset 
12094 </cell>
12095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12096 \begin_inset Text
12097
12098 \layout Standard
12099
12100 0x0003
12101 \end_inset 
12102 </cell>
12103 </row>
12104 <row topline="true">
12105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12106 \begin_inset Text
12107
12108 \layout Standard
12109
12110 1
12111 \end_inset 
12112 </cell>
12113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12114 \begin_inset Text
12115
12116 \layout Standard
12117
12118 Timer 0
12119 \end_inset 
12120 </cell>
12121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12122 \begin_inset Text
12123
12124 \layout Standard
12125
12126 0x000b
12127 \end_inset 
12128 </cell>
12129 </row>
12130 <row topline="true">
12131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12132 \begin_inset Text
12133
12134 \layout Standard
12135
12136 2
12137 \end_inset 
12138 </cell>
12139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12140 \begin_inset Text
12141
12142 \layout Standard
12143
12144 External 1
12145 \end_inset 
12146 </cell>
12147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12148 \begin_inset Text
12149
12150 \layout Standard
12151
12152 0x0013
12153 \end_inset 
12154 </cell>
12155 </row>
12156 <row topline="true">
12157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12158 \begin_inset Text
12159
12160 \layout Standard
12161
12162 3
12163 \end_inset 
12164 </cell>
12165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12166 \begin_inset Text
12167
12168 \layout Standard
12169
12170 Timer 1
12171 \end_inset 
12172 </cell>
12173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12174 \begin_inset Text
12175
12176 \layout Standard
12177
12178 0x001b
12179 \end_inset 
12180 </cell>
12181 </row>
12182 <row topline="true">
12183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12184 \begin_inset Text
12185
12186 \layout Standard
12187
12188 4
12189 \end_inset 
12190 </cell>
12191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12192 \begin_inset Text
12193
12194 \layout Standard
12195
12196 Serial
12197 \end_inset 
12198 </cell>
12199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12200 \begin_inset Text
12201
12202 \layout Standard
12203
12204 0x0023
12205 \end_inset 
12206 </cell>
12207 </row>
12208 <row topline="true">
12209 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12210 \begin_inset Text
12211
12212 \layout Standard
12213
12214 5
12215 \end_inset 
12216 </cell>
12217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12218 \begin_inset Text
12219
12220 \layout Standard
12221
12222 Timer 2 (8052)
12223 \end_inset 
12224 </cell>
12225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12226 \begin_inset Text
12227
12228 \layout Standard
12229
12230 0x002b
12231 \end_inset 
12232 </cell>
12233 </row>
12234 <row topline="true">
12235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12236 \begin_inset Text
12237
12238 \layout Standard
12239
12240 ...
12241 \end_inset 
12242 </cell>
12243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12244 \begin_inset Text
12245
12246 \layout Standard
12247
12248 \end_inset 
12249 </cell>
12250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12251 \begin_inset Text
12252
12253 \layout Standard
12254
12255 ...
12256 \end_inset 
12257 </cell>
12258 </row>
12259 <row topline="true" bottomline="true">
12260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12261 \begin_inset Text
12262
12263 \layout Standard
12264
12265 n
12266 \end_inset 
12267 </cell>
12268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12269 \begin_inset Text
12270
12271 \layout Standard
12272
12273 \end_inset 
12274 </cell>
12275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12276 \begin_inset Text
12277
12278 \layout Standard
12279
12280 0x0003 + 8*n
12281 \end_inset 
12282 </cell>
12283 </row>
12284 </lyxtabular>
12285
12286 \end_inset 
12287
12288
12289 \newline 
12290
12291 \layout Standard
12292
12293 If the interrupt service routine is defined without 
12294 \emph on 
12295 using
12296 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12297
12298 \end_inset 
12299
12300
12301 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12302
12303 \end_inset 
12304
12305
12306 \emph default 
12307  a register bank or with register bank 0 (
12308 \emph on 
12309 using
12310 \emph default 
12311  0), the compiler will save the registers used by itself on the stack upon
12312  entry and restore them at exit, however if such an interrupt service routine
12313  calls another function then the entire register bank will be saved on the
12314  stack.
12315  This scheme may be advantageous for small interrupt service routines which
12316  have low register usage.
12317 \layout Standard
12318 \added_space_bottom bigskip 
12319 If the interrupt service routine is defined to be using a specific register
12320  bank then only 
12321 \emph on 
12322 a, b, dptr
12323 \emph default 
12324  & psw are saved and restored, if such an interrupt service routine calls
12325  another function (using another register bank) then the entire register
12326  bank of the called function will be saved on the stack
12327 \begin_inset LatexCommand \index{stack}
12328
12329 \end_inset 
12330
12331 .
12332  This scheme is recommended for larger interrupt service routines.
12333 \layout Subsection
12334
12335 HC08
12336 \begin_inset LatexCommand \index{HC08}
12337
12338 \end_inset 
12339
12340  Interrupt Service Routines
12341 \layout Standard
12342 \added_space_bottom bigskip 
12343 Since the number of interrupts
12344 \begin_inset LatexCommand \index{HC08!interrupt}
12345
12346 \end_inset 
12347
12348  available is chip specific and the interrupt vector table always ends at
12349  the last byte of memory, the interrupt numbers corresponds to the interrupt
12350  vectors in reverse order of address.
12351  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12352  2 will use the interrupt vector at 0xfffa, and so on.
12353  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12354  this way; instead see section 
12355 \begin_inset LatexCommand \ref{sub:Startup-Code}
12356
12357 \end_inset 
12358
12359  for details on customizing startup.
12360 \layout Subsection
12361
12362 Z80 Interrupt Service Routines
12363 \layout Standard
12364
12365 The Z80
12366 \begin_inset LatexCommand \index{Z80}
12367
12368 \end_inset 
12369
12370  uses several different methods for determining the correct interrupt
12371 \begin_inset LatexCommand \index{Z80!interrupt}
12372
12373 \end_inset 
12374
12375  vector depending on the hardware implementation.
12376  Therefore, SDCC ignores the optional interrupt number and does not attempt
12377  to generate an interrupt vector table.
12378 \layout Standard
12379
12380 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12381  instruction to return from the interrupt.
12382  To write an interrupt handler for the non-maskable interrupt, which needs
12383  a RETN instruction instead, add the 
12384 \emph on 
12385 critical
12386 \emph default 
12387  keyword:
12388 \layout Verse
12389
12390
12391 \family typewriter 
12392 void nmi_isr (void) critical interrupt
12393 \newline 
12394
12395 \newline 
12396 \SpecialChar ~
12397 \SpecialChar ~
12398 \SpecialChar ~
12399 \SpecialChar ~
12400 ...
12401  
12402 \newline 
12403 }
12404 \layout Standard
12405 \added_space_bottom bigskip 
12406 However if you need to create a non-interruptable interrupt service routine
12407  you would also require the 
12408 \emph on 
12409 critical
12410 \emph default 
12411  keyword.
12412  To distinguish between this and an nmi_isr you must provide an interrupt
12413  number.
12414 \layout Section
12415
12416 Enabling and Disabling Interrupts
12417 \layout Subsection
12418
12419 Critical Functions and Critical Statements
12420 \layout Standard
12421
12422 A special keyword may be associated with a block or a function declaring
12423  it as 
12424 \emph on 
12425 critical
12426 \emph default 
12427 .
12428  SDCC will generate code to disable all interrupts
12429 \begin_inset LatexCommand \index{interrupt}
12430
12431 \end_inset 
12432
12433  upon entry to a critical function and restore the interrupt enable to the
12434  previous state before returning.
12435  Nesting critical functions will need one additional byte on the stack
12436 \begin_inset LatexCommand \index{stack}
12437
12438 \end_inset 
12439
12440  for each call.
12441 \layout Verse
12442
12443
12444 \family typewriter 
12445 int foo () __critical
12446 \begin_inset LatexCommand \index{critical}
12447
12448 \end_inset 
12449
12450
12451 \begin_inset LatexCommand \index{\_\_critical}
12452
12453 \end_inset 
12454
12455  
12456 \newline 
12457
12458 \newline 
12459 \SpecialChar ~
12460 \SpecialChar ~
12461 \SpecialChar ~
12462 \SpecialChar ~
12463 ...
12464  
12465 \newline 
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 ...
12471  
12472 \newline 
12473 }
12474 \layout Standard
12475
12476 The critical attribute maybe used with other attributes like 
12477 \emph on 
12478 reentrant.
12479 \emph default 
12480
12481 \newline 
12482 The keyword 
12483 \emph on 
12484 critical
12485 \emph default 
12486  may also be used to disable interrupts more locally:
12487 \layout Verse
12488
12489
12490 \family typewriter 
12491 __critical{ i++; }
12492 \layout Standard
12493
12494 More than one statement could have been included in the block.
12495 \layout Subsection
12496
12497 Enabling and Disabling Interrupts directly
12498 \layout Standard
12499
12500 Interrupts
12501 \begin_inset LatexCommand \index{interrupt}
12502
12503 \end_inset 
12504
12505  can also be disabled and enabled directly (8051):
12506 \layout Verse
12507
12508
12509 \family typewriter 
12510 EA = 0;\SpecialChar ~
12511 \SpecialChar ~
12512 \SpecialChar ~
12513 \SpecialChar ~
12514 \SpecialChar ~
12515 \SpecialChar ~
12516 \SpecialChar ~
12517 \SpecialChar ~
12518 \SpecialChar ~
12519 \SpecialChar ~
12520 \SpecialChar ~
12521 \SpecialChar ~
12522 or:\SpecialChar ~
12523 \SpecialChar ~
12524 \SpecialChar ~
12525 \SpecialChar ~
12526 \SpecialChar ~
12527 \SpecialChar ~
12528 \SpecialChar ~
12529 \SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 \SpecialChar ~
12533 EA_SAVE = EA;
12534 \layout Verse
12535
12536
12537 \family typewriter 
12538 ...\SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 \SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 \SpecialChar ~
12560 \SpecialChar ~
12561 \SpecialChar ~
12562 \SpecialChar ~
12563 \SpecialChar ~
12564 \SpecialChar ~
12565 \SpecialChar ~
12566 \SpecialChar ~
12567 \SpecialChar ~
12568 EA = 0;
12569 \layout Verse
12570
12571
12572 \family typewriter 
12573 EA = 1;\SpecialChar ~
12574 \SpecialChar ~
12575 \SpecialChar ~
12576 \SpecialChar ~
12577 \SpecialChar ~
12578 \SpecialChar ~
12579 \SpecialChar ~
12580 \SpecialChar ~
12581 \SpecialChar ~
12582 \SpecialChar ~
12583 \SpecialChar ~
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 \SpecialChar ~
12587 \SpecialChar ~
12588 \SpecialChar ~
12589 \SpecialChar ~
12590 \SpecialChar ~
12591 \SpecialChar ~
12592 \SpecialChar ~
12593 \SpecialChar ~
12594 \SpecialChar ~
12595 \SpecialChar ~
12596 \SpecialChar ~
12597 \SpecialChar ~
12598 \SpecialChar ~
12599 ...
12600 \layout Verse
12601
12602
12603 \family typewriter 
12604 \SpecialChar ~
12605 \SpecialChar ~
12606 \SpecialChar ~
12607 \SpecialChar ~
12608 \SpecialChar ~
12609 \SpecialChar ~
12610 \SpecialChar ~
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 \SpecialChar ~
12614 \SpecialChar ~
12615 \SpecialChar ~
12616 \SpecialChar ~
12617 \SpecialChar ~
12618 \SpecialChar ~
12619 \SpecialChar ~
12620 \SpecialChar ~
12621 \SpecialChar ~
12622 \SpecialChar ~
12623 \SpecialChar ~
12624 \SpecialChar ~
12625 \SpecialChar ~
12626 \SpecialChar ~
12627 \SpecialChar ~
12628 \SpecialChar ~
12629 \SpecialChar ~
12630 \SpecialChar ~
12631 \SpecialChar ~
12632 \SpecialChar ~
12633 \SpecialChar ~
12634 \SpecialChar ~
12635 \SpecialChar ~
12636 \SpecialChar ~
12637 EA = EA_SAVE;
12638 \layout Standard
12639
12640 On other architectures which have seperate opcodes for enabling and disabling
12641  interrupts you might want to make use of defines with inline assembly
12642 \begin_inset LatexCommand \index{Assembler routines}
12643
12644 \end_inset 
12645
12646  (HC08
12647 \begin_inset LatexCommand \index{HC08!interrupt}
12648
12649 \end_inset 
12650
12651 ):
12652 \layout Verse
12653
12654
12655 \family typewriter 
12656 #define CLI _asm
12657 \begin_inset LatexCommand \index{\_asm}
12658
12659 \end_inset 
12660
12661 \SpecialChar ~
12662 \SpecialChar ~
12663 cli\SpecialChar ~
12664 \SpecialChar ~
12665 _endasm
12666 \begin_inset LatexCommand \index{\_endasm}
12667
12668 \end_inset 
12669
12670
12671 \layout Verse
12672
12673
12674 \family typewriter 
12675 #define SEI _asm\SpecialChar ~
12676 \SpecialChar ~
12677 sei\SpecialChar ~
12678 \SpecialChar ~
12679 _endasm; 
12680 \layout Verse
12681
12682
12683 \family typewriter 
12684 ...
12685 \layout Standard
12686
12687 Note: it is sometimes sufficient to disable only a specific interrupt source
12688  like f.e.
12689  a timer or serial interrupt by manipulating an 
12690 \emph on 
12691 interrupt mask
12692 \begin_inset LatexCommand \index{interrupt mask}
12693
12694 \end_inset 
12695
12696
12697 \emph default 
12698  register.
12699  
12700 \layout Standard
12701
12702 Usually the time during which interrupts are disabled should be kept as
12703  short as possible.
12704  This minimizes both 
12705 \emph on 
12706 interrupt latency
12707 \emph default 
12708
12709 \begin_inset LatexCommand \index{interrupt latency}
12710
12711 \end_inset 
12712
12713  (the time between the occurrence of the interrupt and the execution of
12714  the first code in the interrupt routine) and 
12715 \emph on 
12716 interrupt jitter
12717 \emph default 
12718
12719 \begin_inset LatexCommand \index{interrupt jitter}
12720
12721 \end_inset 
12722
12723  (the difference between the shortest and the longest interrupt latency).
12724  These really are something different, f.e.
12725  a serial interrupt has to be served before its buffer overruns so it cares
12726  for the maximum interrupt latency, whereas it does not care about jitter.
12727  On a loudspeaker driven via a digital to analog converter which is fed
12728  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12729  a much smaller jitter will be very audible.
12730 \layout Standard
12731
12732 You can reenable interrupts within an interrupt routine and on some architecture
12733 s you can make use of two (or more) levels of 
12734 \emph on 
12735 interrupt priorities
12736 \emph default 
12737
12738 \begin_inset LatexCommand \index{interrupt priority}
12739
12740 \end_inset 
12741
12742 .
12743  On some architectures which don't support interrupt priorities these can
12744  be implemented by manipulating the interrupt mask and reenabling interrupts
12745  within the interrupt routine.
12746  Check there is sufficient space on the stack
12747 \begin_inset LatexCommand \index{stack}
12748
12749 \end_inset 
12750
12751  and don't add complexity unless you have to.
12752  
12753 \layout Subsection
12754
12755 Semaphore
12756 \begin_inset LatexCommand \index{semaphore}
12757
12758 \end_inset 
12759
12760  locking (mcs51/ds390)
12761 \layout Standard
12762
12763 Some architectures (mcs51/ds390) have an atomic
12764 \begin_inset LatexCommand \index{atomic}
12765
12766 \end_inset 
12767
12768  bit test and
12769 \emph on 
12770  
12771 \emph default 
12772 clear
12773 \emph on 
12774  
12775 \emph default 
12776 instruction.
12777  These type of instructions are typically used in preemptive multitasking
12778  systems, where a routine f.e.
12779  claims the use of a data structure ('acquires a lock
12780 \begin_inset LatexCommand \index{lock}
12781
12782 \end_inset 
12783
12784  on it'), makes some modifications and then releases the lock when the data
12785  structure is consistent again.
12786  The instruction may also be used if interrupt and non-interrupt code have
12787  to compete for a resource.
12788  With the atomic bit test and clear instruction interrupts
12789 \begin_inset LatexCommand \index{interrupt}
12790
12791 \end_inset 
12792
12793  don't have to be disabled for the locking operation.
12794  
12795 \layout Standard
12796
12797 SDCC generates this instruction if the source follows this pattern:
12798 \layout Verse
12799
12800
12801 \family typewriter 
12802 volatile
12803 \begin_inset LatexCommand \index{volatile}
12804
12805 \end_inset 
12806
12807  bit resource_is_free; 
12808 \newline 
12809
12810 \newline 
12811 if (resource_is_free) 
12812 \newline 
12813 \SpecialChar ~
12814 \SpecialChar ~
12815
12816 \newline 
12817 \SpecialChar ~
12818 \SpecialChar ~
12819 \SpecialChar ~
12820 \SpecialChar ~
12821 resource_is_free=0; 
12822 \newline 
12823 \SpecialChar ~
12824 \SpecialChar ~
12825 \SpecialChar ~
12826 \SpecialChar ~
12827 ...
12828  
12829 \newline 
12830 \SpecialChar ~
12831 \SpecialChar ~
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 resource_is_free=1;
12835 \newline 
12836 \SpecialChar ~
12837 \SpecialChar ~
12838
12839 \layout Standard
12840
12841 Note, mcs51 and ds390 support only an atomic
12842 \begin_inset LatexCommand \index{atomic}
12843
12844 \end_inset 
12845
12846  bit test and 
12847 \emph on 
12848 clear
12849 \emph default 
12850  instruction (as opposed to atomic bit test and 
12851 \emph on 
12852 set).
12853 \layout Section
12854
12855 Functions using private register banks
12856 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12857
12858 \end_inset 
12859
12860  (mcs51/ds390)
12861 \layout Standard
12862
12863 Some architectures have support for quickly changing register sets.
12864  SDCC supports this feature with the 
12865 \emph on 
12866 using
12867 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12868
12869 \end_inset 
12870
12871
12872 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12873
12874 \end_inset 
12875
12876
12877 \emph default 
12878  attribute (which tells the compiler to use a register bank
12879 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12880
12881 \end_inset 
12882
12883  other than the default bank zero).
12884  It should only be applied to 
12885 \emph on 
12886 interrupt
12887 \begin_inset LatexCommand \index{interrupt}
12888
12889 \end_inset 
12890
12891
12892 \emph default 
12893  functions (see footnote below).
12894  This will in most circumstances make the generated ISR code more efficient
12895  since it will not have to save registers on the stack.
12896 \layout Standard
12897
12898 The 
12899 \emph on 
12900 using
12901 \emph default 
12902  attribute will have no effect on the generated code for a 
12903 \emph on 
12904 non-interrupt
12905 \emph default 
12906  function (but may occasionally be useful anyway
12907 \begin_inset Foot
12908 collapsed false
12909
12910 \layout Standard
12911
12912 possible exception: if a function is called ONLY from 'interrupt' functions
12913  using a particular bank, it can be declared with the same 'using' attribute
12914  as the calling 'interrupt' functions.
12915  For instance, if you have several ISRs using bank one, and all of them
12916  call memcpy(), it might make sense to create a specialized version of memcpy()
12917  'using 1', since this would prevent the ISR from having to save bank zero
12918  to the stack on entry and switch to bank zero before calling the function
12919 \end_inset 
12920
12921 ).
12922 \newline 
12923
12924 \emph on 
12925 (pending: Note, nowadays the 
12926 \emph default 
12927 using
12928 \emph on 
12929  attribute has an effect on
12930 \emph default 
12931  
12932 \emph on 
12933 the generated code for a 
12934 \emph default 
12935 non-interrupt
12936 \emph on 
12937  function
12938 \emph default 
12939 .
12940 \emph on 
12941 )
12942 \layout Standard
12943
12944 An 
12945 \emph on 
12946 interrupt
12947 \emph default 
12948  function using a non-zero bank will assume that it can trash that register
12949  bank, and will not save it.
12950  Since high-priority interrupts
12951 \begin_inset LatexCommand \index{interrupts}
12952
12953 \end_inset 
12954
12955
12956 \begin_inset LatexCommand \index{interrupt priority}
12957
12958 \end_inset 
12959
12960  can interrupt low-priority ones on the 8051 and friends, this means that
12961  if a high-priority ISR 
12962 \emph on 
12963 using
12964 \emph default 
12965  a particular bank occurs while processing a low-priority ISR 
12966 \emph on 
12967 using
12968 \emph default 
12969  the same bank, terrible and bad things can happen.
12970  To prevent this, no single register bank should be 
12971 \emph on 
12972 used
12973 \emph default 
12974  by both a high priority and a low priority ISR.
12975  This is probably most easily done by having all high priority ISRs use
12976  one bank and all low priority ISRs use another.
12977  If you have an ISR which can change priority at runtime, you're on your
12978  own: I suggest using the default bank zero and taking the small performance
12979  hit.
12980 \layout Standard
12981 \added_space_bottom bigskip 
12982 It is most efficient if your ISR calls no other functions.
12983  If your ISR must call other functions, it is most efficient if those functions
12984  use the same bank as the ISR (see note 1 below); the next best is if the
12985  called functions use bank zero.
12986  It is very inefficient to call a function using a different, non-zero bank
12987  from an ISR.
12988  
12989 \layout Section
12990
12991 Startup Code
12992 \begin_inset LatexCommand \label{sub:Startup-Code}
12993
12994 \end_inset 
12995
12996
12997 \begin_inset LatexCommand \index{Startup code}
12998
12999 \end_inset 
13000
13001
13002 \layout Subsection
13003
13004 MCS51/DS390 Startup Code
13005 \layout Standard
13006
13007 The compiler inserts a call to the C routine 
13008 \emph on 
13009 _sdcc_external_startup()
13010 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13011
13012 \end_inset 
13013
13014
13015 \series bold 
13016 \emph default 
13017  
13018 \series default 
13019 at the start of the CODE area.
13020  This routine is in the runtime library
13021 \begin_inset LatexCommand \index{Runtime library}
13022
13023 \end_inset 
13024
13025 .
13026  By default this routine returns 0, if this routine returns a non-zero value,
13027  the static & global variable initialization will be skipped and the function
13028  main will be invoked.
13029  Otherwise static & global variables will be initialized before the function
13030  main is invoked.
13031  You could add a 
13032 \emph on 
13033 _sdcc_external_startup()
13034 \emph default 
13035  routine to your program to override the default if you need to setup hardware
13036  or perform some other critical operation prior to static & global variable
13037  initialization
13038 \begin_inset LatexCommand \index{Variable initialization}
13039
13040 \end_inset 
13041
13042 .
13043  On some mcs51 variants xdata
13044 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13045
13046 \end_inset 
13047
13048  memory has to be explicitly enabled before it can be accessed or if the
13049  watchdog
13050 \begin_inset LatexCommand \index{watchdog}
13051
13052 \end_inset 
13053
13054  needs to be disabled, this is the place to do it.
13055  The startup code clears all internal data memory, 256 bytes by default,
13056  but from 0 to n-1 if 
13057 \emph on 
13058 -
13059 \begin_inset ERT
13060 status Collapsed
13061
13062 \layout Standard
13063
13064 \backslash 
13065 /
13066 \end_inset 
13067
13068 -iram-size
13069 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13070
13071 \end_inset 
13072
13073 n
13074 \emph default 
13075  is used.
13076  (recommended for Chipcon CC1010).
13077 \layout Standard
13078 \added_space_bottom bigskip 
13079 See also the compiler options 
13080 \emph on 
13081 -
13082 \begin_inset ERT
13083 status Collapsed
13084
13085 \layout Standard
13086
13087 \backslash 
13088 /
13089 \end_inset 
13090
13091 -no-xinit
13092 \emph default 
13093 -
13094 \emph on 
13095 opt
13096 \emph default 
13097
13098 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13099
13100 \end_inset 
13101
13102
13103 \emph on 
13104 -
13105 \begin_inset ERT
13106 status Collapsed
13107
13108 \layout Standard
13109
13110 \backslash 
13111 /
13112 \end_inset 
13113
13114 -main-return
13115 \emph default 
13116
13117 \begin_inset LatexCommand \index{-\/-main-return}
13118
13119 \end_inset 
13120
13121  and section 
13122 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13123
13124 \end_inset 
13125
13126  about MCS51-variants.
13127 \layout Subsection
13128
13129 HC08 Startup Code
13130 \layout Standard
13131 \added_space_bottom bigskip 
13132 The HC08
13133 \begin_inset LatexCommand \index{HC08}
13134
13135 \end_inset 
13136
13137  startup code follows the same scheme as the MCS51 startup code.
13138 \layout Subsection
13139
13140 Z80 Startup Code
13141 \layout Standard
13142 \added_space_bottom bigskip 
13143 On the Z80
13144 \begin_inset LatexCommand \index{Z80}
13145
13146 \end_inset 
13147
13148  the startup code is inserted by linking with crt0.o which is generated from
13149  sdcc/device/lib/z80/crt0.s.
13150  If you need a different startup code you can use the compiler option 
13151 \emph on 
13152 -
13153 \series bold 
13154 \emph default 
13155
13156 \begin_inset ERT
13157 status Collapsed
13158
13159 \layout Standard
13160
13161 \backslash 
13162 /
13163 \end_inset 
13164
13165
13166 \series default 
13167 \emph on 
13168 -no-std-crt0
13169 \emph default 
13170
13171 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13172
13173 \end_inset 
13174
13175  and provide your own crt0.o.
13176  
13177 \layout Section
13178
13179 Inline Assembler Code
13180 \begin_inset LatexCommand \index{Assembler routines}
13181
13182 \end_inset 
13183
13184
13185 \layout Subsection
13186
13187 A Step by Step Introduction
13188 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13189
13190 \end_inset 
13191
13192
13193 \layout Standard
13194
13195 Starting from a small snippet of c-code this example shows for the MCS51
13196  how to use inline assembly, access variables, a function parameter and
13197  an array in xdata memory.
13198  The example uses an MCS51 here but is easily adapted for other architectures.
13199  This is a buffer routine which should be optimized:
13200 \layout Verse
13201
13202
13203 \family typewriter 
13204 \size footnotesize 
13205 unsigned char __far
13206 \begin_inset LatexCommand \index{far (storage class)}
13207
13208 \end_inset 
13209
13210
13211 \begin_inset LatexCommand \index{\_\_far (storage class)}
13212
13213 \end_inset 
13214
13215  __at
13216 \begin_inset LatexCommand \index{at}
13217
13218 \end_inset 
13219
13220
13221 \begin_inset LatexCommand \index{\_\_at}
13222
13223 \end_inset 
13224
13225 (0x7f00) buf[0x100];
13226 \begin_inset LatexCommand \index{Aligned array}
13227
13228 \end_inset 
13229
13230
13231 \newline 
13232 unsigned char head, tail;\SpecialChar ~
13233 \SpecialChar ~
13234 \SpecialChar ~
13235 \SpecialChar ~
13236 \SpecialChar ~
13237 \SpecialChar ~
13238 \SpecialChar ~
13239 \SpecialChar ~
13240 \SpecialChar ~
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 \SpecialChar ~
13246 \SpecialChar ~
13247 \SpecialChar ~
13248 \SpecialChar ~
13249 /* if interrupts
13250 \begin_inset LatexCommand \index{interrupt}
13251
13252 \end_inset 
13253
13254  are involved see
13255 \newline 
13256 \SpecialChar ~
13257 \SpecialChar ~
13258 \SpecialChar ~
13259 \SpecialChar ~
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 \SpecialChar ~
13263 \SpecialChar ~
13264 \SpecialChar ~
13265 \SpecialChar ~
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 \SpecialChar ~
13269 \SpecialChar ~
13270 \SpecialChar ~
13271 \SpecialChar ~
13272 \SpecialChar ~
13273 \SpecialChar ~
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 \SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 \SpecialChar ~
13288 \SpecialChar ~
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 \SpecialChar ~
13299 \SpecialChar ~
13300 \SpecialChar ~
13301 section 
13302 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13303
13304 \end_inset 
13305
13306  about
13307 \series bold 
13308  volatile
13309 \series default 
13310  */
13311 \newline 
13312
13313 \newline 
13314 void to_buffer( unsigned char c ) 
13315 \newline 
13316 {
13317 \newline 
13318 \SpecialChar ~
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13323 /* cast 
13324 \series bold 
13325 needed
13326 \series default 
13327  to avoid promotion
13328 \begin_inset LatexCommand \index{promotion to signed int}
13329
13330 \end_inset 
13331
13332
13333 \begin_inset LatexCommand \index{type promotion}
13334
13335 \end_inset 
13336
13337  to integer */
13338 \begin_inset Marginal
13339 collapsed true
13340
13341 \layout Standard
13342
13343
13344 \series bold 
13345 \SpecialChar ~
13346 !
13347 \end_inset 
13348
13349
13350 \newline 
13351 \SpecialChar ~
13352 \SpecialChar ~
13353 \SpecialChar ~
13354 \SpecialChar ~
13355 \SpecialChar ~
13356 \SpecialChar ~
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 buf[ head++ ] = c;\SpecialChar ~
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 \SpecialChar ~
13363 \SpecialChar ~
13364 \SpecialChar ~
13365 \SpecialChar ~
13366 \SpecialChar ~
13367 \SpecialChar ~
13368 \SpecialChar ~
13369 \SpecialChar ~
13370 \SpecialChar ~
13371 \SpecialChar ~
13372 \SpecialChar ~
13373 \SpecialChar ~
13374 \SpecialChar ~
13375 /* access to a 256 byte aligned array */
13376 \newline 
13377
13378 \layout Standard
13379
13380 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13381  then a corresponding buffer.asm file is generated.
13382  We define a new function 
13383 \family typewriter 
13384 to_buffer_asm()
13385 \family default 
13386  in file buffer.c in which we cut and paste the generated code, removing
13387  unwanted comments and some ':'.
13388  Then add 
13389 \begin_inset Quotes sld
13390 \end_inset 
13391
13392 _asm
13393 \begin_inset Quotes srd
13394 \end_inset 
13395
13396  and 
13397 \begin_inset Quotes sld
13398 \end_inset 
13399
13400 _endasm;
13401 \begin_inset Quotes srd
13402 \end_inset 
13403
13404  to the beginning and the end of the function body:
13405 \layout Verse
13406
13407
13408 \family typewriter 
13409 \size footnotesize 
13410 /* With a cut and paste from the .asm file, we have something to start with.
13411 \newline 
13412 \SpecialChar ~
13413 \SpecialChar ~
13414 \SpecialChar ~
13415 The function is not yet OK! (registers aren't saved) */ 
13416 \newline 
13417 void to_buffer_asm( unsigned char c ) 
13418 \newline 
13419
13420 \newline 
13421 \SpecialChar ~
13422 \SpecialChar ~
13423 \SpecialChar ~
13424 \SpecialChar ~
13425 _asm
13426 \begin_inset LatexCommand \index{\_asm}
13427
13428 \end_inset 
13429
13430
13431 \begin_inset LatexCommand \index{\_\_asm}
13432
13433 \end_inset 
13434
13435
13436 \newline 
13437 \SpecialChar ~
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 mov\SpecialChar ~
13442 \SpecialChar ~
13443 r2,dpl 
13444 \newline 
13445 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13446 /* cast 
13447 \series bold 
13448 needed
13449 \series default 
13450  to avoid promotion
13451 \begin_inset LatexCommand \index{promotion to signed int}
13452
13453 \end_inset 
13454
13455
13456 \begin_inset LatexCommand \index{type promotion}
13457
13458 \end_inset 
13459
13460  to integer */
13461 \newline 
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 mov\SpecialChar ~
13467 \SpecialChar ~
13468 a,_tail 
13469 \newline 
13470 \SpecialChar ~
13471 \SpecialChar ~
13472 \SpecialChar ~
13473 \SpecialChar ~
13474 dec\SpecialChar ~
13475 \SpecialChar ~
13476
13477 \newline 
13478 \SpecialChar ~
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 mov\SpecialChar ~
13483 \SpecialChar ~
13484 r3,a 
13485 \newline 
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 \SpecialChar ~
13490 mov\SpecialChar ~
13491 \SpecialChar ~
13492 a,_head 
13493 \newline 
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 \SpecialChar ~
13497 \SpecialChar ~
13498 cjne a,ar3,00106$ 
13499 \newline 
13500 \SpecialChar ~
13501 \SpecialChar ~
13502 \SpecialChar ~
13503 \SpecialChar ~
13504 ret
13505 \newline 
13506 00106$: 
13507 \newline 
13508 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13509 \begin_inset LatexCommand \index{Aligned array}
13510
13511 \end_inset 
13512
13513
13514 \newline 
13515 \SpecialChar ~
13516 \SpecialChar ~
13517 \SpecialChar ~
13518 \SpecialChar ~
13519 mov\SpecialChar ~
13520 \SpecialChar ~
13521 r3,_head 
13522 \newline 
13523 \SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 \SpecialChar ~
13527 inc\SpecialChar ~
13528 \SpecialChar ~
13529 _head 
13530 \newline 
13531 \SpecialChar ~
13532 \SpecialChar ~
13533 \SpecialChar ~
13534 \SpecialChar ~
13535 mov\SpecialChar ~
13536 \SpecialChar ~
13537 dpl,r3 
13538 \newline 
13539 \SpecialChar ~
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 \SpecialChar ~
13543 mov\SpecialChar ~
13544 \SpecialChar ~
13545 dph,#(_buf >> 8) 
13546 \newline 
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 \SpecialChar ~
13551 mov\SpecialChar ~
13552 \SpecialChar ~
13553 a,r2 
13554 \newline 
13555 \SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 \SpecialChar ~
13559 movx @dptr,a 
13560 \newline 
13561 00103$: 
13562 \newline 
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 ret
13568 \newline 
13569 \SpecialChar ~
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 _endasm
13574 \begin_inset LatexCommand \index{\_endasm}
13575
13576 \end_inset 
13577
13578
13579 \begin_inset LatexCommand \index{\_\_endasm}
13580
13581 \end_inset 
13582
13583 ;
13584 \newline 
13585
13586 \layout Standard
13587
13588 The new file buffer.c should compile with only one warning about the unreferenced
13589  function argument 'c'.
13590  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13591  (1) and finally have:
13592 \layout Verse
13593
13594
13595 \family typewriter 
13596 \size footnotesize 
13597 unsigned char __far __at(0x7f00) buf[0x100];
13598 \newline 
13599 unsigned char head, tail;
13600 \newline 
13601 #define USE_ASSEMBLY (1)
13602 \newline 
13603
13604 \newline 
13605 #if !USE_ASSEMBLY
13606 \newline 
13607
13608 \newline 
13609 void to_buffer( unsigned char c )
13610 \newline 
13611 {
13612 \newline 
13613 \SpecialChar ~
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 if( head != (unsigned char)(tail-1) )
13618 \newline 
13619 \SpecialChar ~
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 buf[ head++ ] = c;
13628 \newline 
13629 }
13630 \newline 
13631
13632 \newline 
13633 #else
13634 \newline 
13635
13636 \newline 
13637 void to_buffer( unsigned char c )
13638 \newline 
13639 {
13640 \newline 
13641 \SpecialChar ~
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 c; // to avoid warning: unreferenced function argument
13646 \newline 
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 _asm
13652 \begin_inset LatexCommand \index{\_asm}
13653
13654 \end_inset 
13655
13656
13657 \begin_inset LatexCommand \index{\_\_asm}
13658
13659 \end_inset 
13660
13661
13662 \newline 
13663 \SpecialChar ~
13664 \SpecialChar ~
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 \SpecialChar ~
13668 \SpecialChar ~
13669 \SpecialChar ~
13670 \SpecialChar ~
13671 ; save used registers here.
13672  
13673 \newline 
13674 \SpecialChar ~
13675 \SpecialChar ~
13676 \SpecialChar ~
13677 \SpecialChar ~
13678 \SpecialChar ~
13679 \SpecialChar ~
13680 \SpecialChar ~
13681 \SpecialChar ~
13682 ; If we were still using r2,r3 we would have to push them here.
13683  
13684 \newline 
13685 ; if( head != (unsigned char)(tail-1) )
13686 \newline 
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 \SpecialChar ~
13694 \SpecialChar ~
13695 mov\SpecialChar ~
13696  a,_tail
13697 \newline 
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 \SpecialChar ~
13704 \SpecialChar ~
13705 \SpecialChar ~
13706 dec\SpecialChar ~
13707  a
13708 \newline 
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 xrl\SpecialChar ~
13718  a,_head
13719 \newline 
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13729 \newline 
13730 \SpecialChar ~
13731 \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 jz\SpecialChar ~
13739 \SpecialChar ~
13740  t_b_end$
13741 \newline 
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 ;
13751 \newline 
13752 ; buf[ head++ ] = c;
13753 \newline 
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 mov\SpecialChar ~
13763  a,dpl \SpecialChar ~
13764 \SpecialChar ~
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 \SpecialChar ~
13770 ; dpl holds lower byte of function argument
13771 \newline 
13772 \SpecialChar ~
13773 \SpecialChar ~
13774 \SpecialChar ~
13775 \SpecialChar ~
13776 \SpecialChar ~
13777 \SpecialChar ~
13778 \SpecialChar ~
13779 \SpecialChar ~
13780 mov\SpecialChar ~
13781  dpl,_head \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 ; buf is 0x100 byte aligned so head can be used directly
13785 \newline 
13786 \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 mov\SpecialChar ~
13795  dph,#(_buf>>8)
13796 \newline 
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 movx @dptr,a
13806 \newline 
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 inc \SpecialChar ~
13816 _head
13817 \newline 
13818 \SpecialChar ~
13819 \SpecialChar ~
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13827 \newline 
13828 t_b_end$:
13829 \newline 
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 \SpecialChar ~
13838 ; restore used registers here 
13839 \newline 
13840 \SpecialChar ~
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 _endasm
13845 \begin_inset LatexCommand \index{\_endasm}
13846
13847 \end_inset 
13848
13849
13850 \begin_inset LatexCommand \index{\_\_endasm}
13851
13852 \end_inset 
13853
13854 ;
13855 \newline 
13856 }
13857 \newline 
13858 #endif
13859 \layout Standard
13860
13861 The inline assembler code can contain any valid code understood by the assembler
13862 , this includes any assembler directives and comment lines.
13863  The assembler does not like some characters like ':' or ''' in comments.
13864  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13865 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13866
13867 \end_inset 
13868
13869
13870 \begin_inset LatexCommand \index{Assembler documentation}
13871
13872 \end_inset 
13873
13874  or online at 
13875 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13876
13877 \end_inset 
13878
13879 \SpecialChar ~
13880 .
13881 \layout Standard
13882
13883 The compiler does not do any validation of the code within the 
13884 \family typewriter 
13885 _asm
13886 \begin_inset LatexCommand \index{\_asm}
13887
13888 \end_inset 
13889
13890
13891 \begin_inset LatexCommand \index{\_\_asm}
13892
13893 \end_inset 
13894
13895  ...
13896  _endasm
13897 \size footnotesize 
13898
13899 \begin_inset LatexCommand \index{\_endasm}
13900
13901 \end_inset 
13902
13903
13904 \begin_inset LatexCommand \index{\_\_endasm}
13905
13906 \end_inset 
13907
13908
13909 \size default 
13910 ;
13911 \family default 
13912  keyword pair.
13913  Specifically it will not know which registers are used and thus register
13914  pushing/popping
13915 \begin_inset LatexCommand \index{push/pop}
13916
13917 \end_inset 
13918
13919  has to be done manually.
13920  
13921 \layout Standard
13922
13923 It is recommended that each assembly instruction (including labels) be placed
13924  in a separate line (as the example shows).
13925  When the -
13926 \begin_inset ERT
13927 status Collapsed
13928
13929 \layout Standard
13930
13931 \backslash 
13932 /
13933 \end_inset 
13934
13935 -
13936 \emph on 
13937 peep-asm
13938 \begin_inset LatexCommand \index{-\/-peep-asm}
13939
13940 \end_inset 
13941
13942
13943 \emph default 
13944  command line option is used, the inline assembler code will be passed through
13945  the peephole optimizer
13946 \begin_inset LatexCommand \index{Peephole optimizer}
13947
13948 \end_inset 
13949
13950 .
13951  There are only a few (if any) cases where this option makes sense, it might
13952  cause some unexpected changes in the inline assembler code.
13953  Please go through the peephole optimizer rules defined in file 
13954 \emph on 
13955 SDCCpeeph.def
13956 \emph default 
13957  before using this option.
13958 \layout Subsection
13959
13960 Naked Functions
13961 \begin_inset LatexCommand \label{sub:Naked-Functions}
13962
13963 \end_inset 
13964
13965
13966 \begin_inset LatexCommand \index{Naked functions}
13967
13968 \end_inset 
13969
13970
13971 \layout Standard
13972
13973 A special keyword may be associated with a function declaring it as 
13974 \emph on 
13975 _naked
13976 \begin_inset LatexCommand \index{\_naked}
13977
13978 \end_inset 
13979
13980
13981 \begin_inset LatexCommand \index{\_\_naked}
13982
13983 \end_inset 
13984
13985 .
13986  
13987 \emph default 
13988 The 
13989 \emph on 
13990 _naked
13991 \emph default 
13992  function modifier attribute prevents the compiler from generating prologue
13993 \begin_inset LatexCommand \index{function prologue}
13994
13995 \end_inset 
13996
13997  and epilogue
13998 \begin_inset LatexCommand \index{function epilogue}
13999
14000 \end_inset 
14001
14002  code for that function.
14003  This means that the user is entirely responsible for such things as saving
14004  any registers that may need to be preserved, selecting the proper register
14005  bank, generating the 
14006 \emph on 
14007 return
14008 \emph default 
14009  instruction at the end, etc.
14010  Practically, this means that the contents of the function must be written
14011  in inline assembler.
14012  This is particularly useful for interrupt functions, which can have a large
14013  (and often unnecessary) prologue/epilogue.
14014  For example, compare the code generated by these two functions:
14015 \layout Verse
14016
14017
14018 \family typewriter 
14019 volatile
14020 \begin_inset LatexCommand \index{volatile}
14021
14022 \end_inset 
14023
14024  data unsigned char counter;
14025 \newline 
14026
14027 \newline 
14028 void simpleInterrupt(void) __interrupt
14029 \begin_inset LatexCommand \index{interrupt}
14030
14031 \end_inset 
14032
14033
14034 \begin_inset LatexCommand \index{\_\_interrupt}
14035
14036 \end_inset 
14037
14038  (1)
14039 \newline 
14040 {
14041 \newline 
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 \SpecialChar ~
14045 \SpecialChar ~
14046 counter++;
14047 \newline 
14048 }
14049 \newline 
14050
14051 \newline 
14052 void nakedInterrupt(void) __interrupt (2) __naked
14053 \newline 
14054 {
14055 \newline 
14056 \SpecialChar ~
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 _asm
14061 \begin_inset LatexCommand \index{\_asm}
14062
14063 \end_inset 
14064
14065
14066 \begin_inset LatexCommand \index{\_\_asm}
14067
14068 \end_inset 
14069
14070
14071 \newline 
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 inc\SpecialChar ~
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 _counter ; does not change flags, no need to save psw
14084 \newline 
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 reti\SpecialChar ~
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 \SpecialChar ~
14095 ; MUST explicitly include ret or reti in _naked function.
14096 \newline 
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 _endasm
14102 \begin_inset LatexCommand \index{\_endasm}
14103
14104 \end_inset 
14105
14106
14107 \begin_inset LatexCommand \index{\_\_endasm}
14108
14109 \end_inset 
14110
14111 ;
14112 \newline 
14113 }
14114 \layout Standard
14115
14116 For an 8051 target, the generated simpleInterrupt looks like:
14117 \layout Verse
14118
14119
14120 \family typewriter 
14121 Note, this is an 
14122 \emph on 
14123 outdated
14124 \emph default 
14125  example, recent versions of SDCC generate
14126 \newline 
14127 the 
14128 \emph on 
14129 same
14130 \emph default 
14131  code for simpleInterrupt() and nakedInterrupt()!
14132 \newline 
14133
14134 \newline 
14135 _simpleInterrupt:
14136 \newline 
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 push\SpecialChar ~
14142 \SpecialChar ~
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 acc
14146 \newline 
14147 \SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 push\SpecialChar ~
14152 \SpecialChar ~
14153 \SpecialChar ~
14154 \SpecialChar ~
14155 b
14156 \newline 
14157 \SpecialChar ~
14158 \SpecialChar ~
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 push\SpecialChar ~
14162 \SpecialChar ~
14163 \SpecialChar ~
14164 \SpecialChar ~
14165 dpl
14166 \newline 
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 \SpecialChar ~
14170 \SpecialChar ~
14171 push\SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 \SpecialChar ~
14175 dph
14176 \newline 
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 \SpecialChar ~
14181 push\SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 psw
14186 \newline 
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 mov\SpecialChar ~
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 psw,#0x00
14197 \newline 
14198 \SpecialChar ~
14199 \SpecialChar ~
14200 \SpecialChar ~
14201 \SpecialChar ~
14202 inc\SpecialChar ~
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 _counter
14208 \newline 
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 pop\SpecialChar ~
14214 \SpecialChar ~
14215 \SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 psw
14219 \newline 
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 pop\SpecialChar ~
14225 \SpecialChar ~
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 dph
14230 \newline 
14231 \SpecialChar ~
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 pop\SpecialChar ~
14236 \SpecialChar ~
14237 \SpecialChar ~
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 dpl
14241 \newline 
14242 \SpecialChar ~
14243 \SpecialChar ~
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 pop\SpecialChar ~
14247 \SpecialChar ~
14248 \SpecialChar ~
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 b
14252 \newline 
14253 \SpecialChar ~
14254 \SpecialChar ~
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 pop\SpecialChar ~
14258 \SpecialChar ~
14259 \SpecialChar ~
14260 \SpecialChar ~
14261 \SpecialChar ~
14262 acc
14263 \newline 
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 reti
14269 \layout Standard
14270
14271 whereas nakedInterrupt looks like:
14272 \layout Verse
14273
14274
14275 \family typewriter 
14276 _nakedInterrupt:
14277 \newline 
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 \SpecialChar ~
14281 \SpecialChar ~
14282 inc\SpecialChar ~
14283 \SpecialChar ~
14284 \SpecialChar ~
14285 \SpecialChar ~
14286 _counter ; does not change flags, no need to save psw
14287 \newline 
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 \SpecialChar ~
14291 \SpecialChar ~
14292 reti\SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 \SpecialChar ~
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 \SpecialChar ~
14302 \SpecialChar ~
14303 \SpecialChar ~
14304 ; MUST explicitly include ret or reti in _naked function
14305 \layout Standard
14306
14307 The related directive #pragma exclude
14308 \begin_inset LatexCommand \index{\#pragma exclude}
14309
14310 \end_inset 
14311
14312  allows a more fine grained control over pushing & popping
14313 \begin_inset LatexCommand \index{push/pop}
14314
14315 \end_inset 
14316
14317  the registers.
14318 \layout Standard
14319
14320 While there is nothing preventing you from writing C code inside a 
14321 \family typewriter 
14322 _naked
14323 \family default 
14324  function, there are many ways to shoot yourself in the foot doing this,
14325  and it is recommended that you stick to inline assembler.
14326 \layout Subsection
14327
14328 Use of Labels within Inline Assembler
14329 \layout Standard
14330
14331 SDCC allows the use of in-line assembler with a few restrictions regarding
14332  labels.
14333  In older versions of the compiler all labels defined within inline assembler
14334  code 
14335 \emph on 
14336 had to be
14337 \emph default 
14338  of the form 
14339 \emph on 
14340 nnnnn$
14341 \emph default 
14342  where nnnn is a number less than 100 (which implies a limit of utmost 100
14343  inline assembler labels 
14344 \emph on 
14345 per function
14346 \emph default 
14347 \noun on 
14348 )
14349 \noun default 
14350 .
14351  
14352 \layout Verse
14353
14354
14355 \family typewriter 
14356 _asm
14357 \begin_inset LatexCommand \index{\_asm}
14358
14359 \end_inset 
14360
14361
14362 \begin_inset LatexCommand \index{\_\_asm}
14363
14364 \end_inset 
14365
14366  
14367 \newline 
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 mov\SpecialChar ~
14373 \SpecialChar ~
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 b,#10 
14378 \newline 
14379 00001$: 
14380 \newline 
14381 \SpecialChar ~
14382 \SpecialChar ~
14383 \SpecialChar ~
14384 \SpecialChar ~
14385 djnz\SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 \SpecialChar ~
14389 b,00001$ 
14390 \newline 
14391 _endasm
14392 \begin_inset LatexCommand \index{\_endasm}
14393
14394 \end_inset 
14395
14396
14397 \begin_inset LatexCommand \index{\_\_endasm}
14398
14399 \end_inset 
14400
14401  ;
14402 \layout Standard
14403
14404 Inline assembler code cannot reference any C-Labels, however it can reference
14405  labels
14406 \begin_inset LatexCommand \index{Labels}
14407
14408 \end_inset 
14409
14410  defined by the inline assembler, e.g.:
14411 \layout Verse
14412
14413
14414 \family typewriter 
14415 foo() { 
14416 \newline 
14417 \SpecialChar ~
14418 \SpecialChar ~
14419 \SpecialChar ~
14420 \SpecialChar ~
14421 /* some c code */ 
14422 \newline 
14423 \SpecialChar ~
14424 \SpecialChar ~
14425 \SpecialChar ~
14426 \SpecialChar ~
14427 _asm 
14428 \newline 
14429 \SpecialChar ~
14430 \SpecialChar ~
14431 \SpecialChar ~
14432 \SpecialChar ~
14433 \SpecialChar ~
14434 \SpecialChar ~
14435 ; some assembler code 
14436 \newline 
14437 \SpecialChar ~
14438 \SpecialChar ~
14439 \SpecialChar ~
14440 \SpecialChar ~
14441 \SpecialChar ~
14442 \SpecialChar ~
14443 ljmp $0003 
14444 \newline 
14445 \SpecialChar ~
14446 \SpecialChar ~
14447 \SpecialChar ~
14448 \SpecialChar ~
14449 _endasm; 
14450 \newline 
14451 \SpecialChar ~
14452 \SpecialChar ~
14453 \SpecialChar ~
14454 \SpecialChar ~
14455 /* some more c code */ 
14456 \newline 
14457 clabel:\SpecialChar ~
14458 \SpecialChar ~
14459 /* inline assembler cannot reference this label */ 
14460 \newline 
14461 \SpecialChar ~
14462 \SpecialChar ~
14463 \SpecialChar ~
14464 \SpecialChar ~
14465 _asm
14466 \newline 
14467 \SpecialChar ~
14468 \SpecialChar ~
14469 \SpecialChar ~
14470 \SpecialChar ~
14471 $0003: ;label (can be referenced by inline assembler only) 
14472 \newline 
14473 \SpecialChar ~
14474 \SpecialChar ~
14475 \SpecialChar ~
14476 \SpecialChar ~
14477 _endasm
14478 \begin_inset LatexCommand \index{\_endasm}
14479
14480 \end_inset 
14481
14482
14483 \begin_inset LatexCommand \index{\_\_endasm}
14484
14485 \end_inset 
14486
14487  ; 
14488 \newline 
14489 \SpecialChar ~
14490 \SpecialChar ~
14491 \SpecialChar ~
14492 \SpecialChar ~
14493 /* some more c code */
14494 \newline 
14495 }
14496 \layout Standard
14497
14498 In other words inline assembly code can access labels defined in inline
14499  assembly within the scope of the function.
14500  The same goes the other way, i.e.
14501  labels defines in inline assembly can not be accessed by C statements.
14502 \layout Section
14503
14504 Interfacing with Assembler Code
14505 \begin_inset LatexCommand \index{Assembler routines}
14506
14507 \end_inset 
14508
14509
14510 \layout Subsection
14511
14512 Global Registers used for Parameter Passing
14513 \begin_inset LatexCommand \index{Parameter passing}
14514
14515 \end_inset 
14516
14517
14518 \layout Standard
14519
14520 The compiler always uses the global registers 
14521 \emph on 
14522 DPL, DPH
14523 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14524
14525 \end_inset 
14526
14527
14528 \begin_inset LatexCommand \index{DPTR}
14529
14530 \end_inset 
14531
14532 , B
14533 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14534
14535 \end_inset 
14536
14537  
14538 \emph default 
14539 and
14540 \emph on 
14541  ACC
14542 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14543
14544 \end_inset 
14545
14546
14547 \emph default 
14548  to pass the first parameter to a routine.
14549  The second parameter onwards is either allocated on the stack (for reentrant
14550  routines or if -
14551 \begin_inset ERT
14552 status Collapsed
14553
14554 \layout Standard
14555
14556 \backslash 
14557 /
14558 \end_inset 
14559
14560 -stack-auto is used) or in data / xdata memory (depending on the memory
14561  model).
14562  
14563 \layout Subsection
14564
14565 Assembler Routine (non-reentrant)
14566 \layout Standard
14567
14568 In the following example
14569 \begin_inset LatexCommand \index{reentrant}
14570
14571 \end_inset 
14572
14573
14574 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14575
14576 \end_inset 
14577
14578  the function c_func calls an assembler routine asm_func, which takes two
14579  parameters
14580 \begin_inset LatexCommand \index{function parameter}
14581
14582 \end_inset 
14583
14584 .
14585 \layout Verse
14586
14587
14588 \family typewriter 
14589 extern int asm_func(unsigned char, unsigned char);
14590 \newline 
14591
14592 \newline 
14593 int c_func (unsigned char i, unsigned char j)
14594 \newline 
14595 {
14596 \newline 
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 \SpecialChar ~
14600 \SpecialChar ~
14601 return asm_func(i,j);
14602 \newline 
14603 }
14604 \newline 
14605
14606 \newline 
14607 int main()
14608 \newline 
14609 {
14610 \newline 
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 return c_func(10,9);
14616 \newline 
14617 }
14618 \layout Standard
14619
14620 The corresponding assembler function is:
14621 \layout Verse
14622
14623
14624 \family typewriter 
14625 .globl _asm_func_PARM_2 
14626 \newline 
14627 \SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 \SpecialChar ~
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 \SpecialChar ~
14634 \SpecialChar ~
14635 .globl _asm_func 
14636 \newline 
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 \SpecialChar ~
14645 .area OSEG 
14646 \newline 
14647 _asm_func_PARM_2:
14648 \newline 
14649 \SpecialChar ~
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 \SpecialChar ~
14653 \SpecialChar ~
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 .ds    1 
14658 \newline 
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667 .area CSEG 
14668 \newline 
14669 _asm_func: 
14670 \newline 
14671 \SpecialChar ~
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 \SpecialChar ~
14679 mov\SpecialChar ~
14680 \SpecialChar ~
14681 \SpecialChar ~
14682 \SpecialChar ~
14683 a,dpl 
14684 \newline 
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 \SpecialChar ~
14693 add\SpecialChar ~
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 a,_asm_func_PARM_2 
14698 \newline 
14699 \SpecialChar ~
14700 \SpecialChar ~
14701 \SpecialChar ~
14702 \SpecialChar ~
14703 \SpecialChar ~
14704 \SpecialChar ~
14705 \SpecialChar ~
14706 \SpecialChar ~
14707 mov\SpecialChar ~
14708 \SpecialChar ~
14709 \SpecialChar ~
14710 \SpecialChar ~
14711 dpl,a 
14712 \newline 
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 \SpecialChar ~
14717 \SpecialChar ~
14718 \SpecialChar ~
14719 \SpecialChar ~
14720 \SpecialChar ~
14721 mov\SpecialChar ~
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 dph
14726 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14727
14728 \end_inset 
14729
14730 ,#0x00 
14731 \newline 
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 \SpecialChar ~
14735 \SpecialChar ~
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 ret
14741 \layout Standard
14742
14743 Note here that the return values
14744 \begin_inset LatexCommand \index{return value}
14745
14746 \end_inset 
14747
14748  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14749  two byte values.
14750  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14751 b' & 'acc' for four byte values.
14752 \layout Standard
14753
14754 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14755  the parameter number starting from 1, and counting from the left.
14756  The first parameter is passed in 
14757 \begin_inset Quotes eld
14758 \end_inset 
14759
14760 dpl
14761 \begin_inset Quotes erd
14762 \end_inset 
14763
14764  for a one byte parameter, 
14765 \begin_inset Quotes eld
14766 \end_inset 
14767
14768 dptr
14769 \begin_inset Quotes erd
14770 \end_inset 
14771
14772  for two bytes, 
14773 \begin_inset Quotes eld
14774 \end_inset 
14775
14776 b,dptr
14777 \begin_inset Quotes erd
14778 \end_inset 
14779
14780  for three bytes and 
14781 \begin_inset Quotes eld
14782 \end_inset 
14783
14784 acc,b,dptr
14785 \begin_inset Quotes erd
14786 \end_inset 
14787
14788  for a four bytes parameter.
14789  The variable name for the second parameter will be _<function_name>_PARM_2.
14790 \newline 
14791
14792 \newline 
14793 Assemble the assembler routine with the following command:
14794 \newline 
14795
14796 \newline 
14797
14798 \family sans 
14799 \series bold 
14800 asx8051 -losg asmfunc.asm
14801 \newline 
14802
14803 \newline 
14804
14805 \family default 
14806 \series default 
14807 Then compile and link the assembler routine to the C source file with the
14808  following command:
14809 \newline 
14810
14811 \newline 
14812
14813 \family sans 
14814 \series bold 
14815 sdcc cfunc.c asmfunc.rel
14816 \layout Subsection
14817
14818 Assembler Routine (reentrant)
14819 \layout Standard
14820
14821 In this case
14822 \begin_inset LatexCommand \index{reentrant}
14823
14824 \end_inset 
14825
14826
14827 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14828
14829 \end_inset 
14830
14831  the second parameter
14832 \begin_inset LatexCommand \index{function parameter}
14833
14834 \end_inset 
14835
14836  onwards will be passed on the stack, the parameters are pushed from right
14837  to left i.e.
14838  after the call the leftmost parameter will be on the top of the stack.
14839  Here is an example:
14840 \layout Verse
14841
14842
14843 \family typewriter 
14844 extern int asm_func(unsigned char, unsigned char);
14845 \newline 
14846
14847 \newline 
14848 int c_func (unsigned char i, unsigned char j) reentrant 
14849 \newline 
14850
14851 \newline 
14852 \SpecialChar ~
14853 \SpecialChar ~
14854 \SpecialChar ~
14855 \SpecialChar ~
14856 return asm_func(i,j); 
14857 \newline 
14858
14859 \newline 
14860
14861 \newline 
14862 int main() 
14863 \newline 
14864
14865 \newline 
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 return c_func(10,9); 
14871 \newline 
14872 }
14873 \layout Standard
14874
14875 The corresponding assembler routine is:
14876 \layout Verse
14877
14878
14879 \family typewriter 
14880 .globl _asm_func 
14881 \newline 
14882 _asm_func: 
14883 \newline 
14884 \SpecialChar ~
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 \SpecialChar ~
14888 push  _bp 
14889 \newline 
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 mov _bp,sp 
14895 \newline 
14896 \SpecialChar ~
14897 \SpecialChar ~
14898 \SpecialChar ~
14899 \SpecialChar ~
14900 mov r2,dpl
14901 \newline 
14902 \SpecialChar ~
14903 \SpecialChar ~
14904 \SpecialChar ~
14905 \SpecialChar ~
14906 mov a,_bp 
14907 \newline 
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 \SpecialChar ~
14911 \SpecialChar ~
14912 add a,#0xfd 
14913 \newline 
14914 \SpecialChar ~
14915 \SpecialChar ~
14916 \SpecialChar ~
14917 \SpecialChar ~
14918 mov r0,a 
14919 \newline 
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 \SpecialChar ~
14924 add  a,#0xfc ;?
14925 \newline 
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 \SpecialChar ~
14930 mov  r1,a 
14931 \newline 
14932 \SpecialChar ~
14933 \SpecialChar ~
14934 \SpecialChar ~
14935 \SpecialChar ~
14936 mov  a,@r0 
14937 \newline 
14938 \SpecialChar ~
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 \SpecialChar ~
14942 add  a,r2 ;?
14943 \newline 
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 \SpecialChar ~
14948 mov  dpl,a 
14949 \newline 
14950 \SpecialChar ~
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 \SpecialChar ~
14954 mov  dph,#0x00 
14955 \newline 
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 \SpecialChar ~
14959 \SpecialChar ~
14960 mov  sp,_bp 
14961 \newline 
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 \SpecialChar ~
14965 \SpecialChar ~
14966 pop  _bp 
14967 \newline 
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 \SpecialChar ~
14971 \SpecialChar ~
14972 ret
14973 \layout Standard
14974 \added_space_bottom bigskip 
14975 The compiling and linking procedure remains the same, however note the extra
14976  entry & exit linkage required for the assembler code, _bp is the stack
14977  frame pointer and is used to compute the offset into the stack for parameters
14978  and local variables.
14979 \layout Section
14980
14981 int (16 bit)
14982 \begin_inset LatexCommand \index{int (16 bit)}
14983
14984 \end_inset 
14985
14986  and long (32 bit)
14987 \begin_inset LatexCommand \index{long (32 bit)}
14988
14989 \end_inset 
14990
14991  Support
14992 \layout Standard
14993
14994 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14995  multiplication and modulus operations are implemented by support routines.
14996  These support routines are all developed in ANSI-C to facilitate porting
14997  to other MCUs, although some model specific assembler optimizations are
14998  used.
14999  The following files contain the described routines, all of them can be
15000  found in <installdir>/share/sdcc/lib.
15001 \newline 
15002
15003 \layout Standard
15004 \align center 
15005
15006 \begin_inset  Tabular
15007 <lyxtabular version="3" rows="11" columns="2">
15008 <features>
15009 <column alignment="left" valignment="top" leftline="true" width="0">
15010 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15011 <row topline="true" bottomline="true">
15012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15013 \begin_inset Text
15014
15015 \layout Standard
15016
15017
15018 \series bold 
15019 Function
15020 \end_inset 
15021 </cell>
15022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15023 \begin_inset Text
15024
15025 \layout Standard
15026
15027
15028 \series bold 
15029 Description
15030 \end_inset 
15031 </cell>
15032 </row>
15033 <row topline="true">
15034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15035 \begin_inset Text
15036
15037 \layout Standard
15038
15039 _mulint.c 
15040 \end_inset 
15041 </cell>
15042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15043 \begin_inset Text
15044
15045 \layout Standard
15046
15047 16 bit multiplication
15048 \end_inset 
15049 </cell>
15050 </row>
15051 <row topline="true">
15052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15053 \begin_inset Text
15054
15055 \layout Standard
15056
15057 _divsint.c 
15058 \end_inset 
15059 </cell>
15060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15061 \begin_inset Text
15062
15063 \layout Standard
15064
15065  signed 16 bit division (calls _divuint)
15066 \end_inset 
15067 </cell>
15068 </row>
15069 <row topline="true">
15070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15071 \begin_inset Text
15072
15073 \layout Standard
15074
15075 _divuint.c 
15076 \end_inset 
15077 </cell>
15078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15079 \begin_inset Text
15080
15081 \layout Standard
15082
15083  unsigned 16 bit division
15084 \end_inset 
15085 </cell>
15086 </row>
15087 <row topline="true">
15088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15089 \begin_inset Text
15090
15091 \layout Standard
15092
15093 _modsint.c
15094 \end_inset 
15095 </cell>
15096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15097 \begin_inset Text
15098
15099 \layout Standard
15100
15101 signed 16 bit modulus (calls _moduint)
15102 \end_inset 
15103 </cell>
15104 </row>
15105 <row topline="true">
15106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15107 \begin_inset Text
15108
15109 \layout Standard
15110
15111 _moduint.c
15112 \end_inset 
15113 </cell>
15114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15115 \begin_inset Text
15116
15117 \layout Standard
15118
15119 unsigned 16 bit modulus
15120 \end_inset 
15121 </cell>
15122 </row>
15123 <row topline="true">
15124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15125 \begin_inset Text
15126
15127 \layout Standard
15128
15129 _mullong.c
15130 \end_inset 
15131 </cell>
15132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15133 \begin_inset Text
15134
15135 \layout Standard
15136
15137 32 bit multiplication
15138 \end_inset 
15139 </cell>
15140 </row>
15141 <row topline="true">
15142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15143 \begin_inset Text
15144
15145 \layout Standard
15146
15147 _divslong.c 
15148 \end_inset 
15149 </cell>
15150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15151 \begin_inset Text
15152
15153 \layout Standard
15154
15155  signed 32 division (calls _divulong)
15156 \end_inset 
15157 </cell>
15158 </row>
15159 <row topline="true">
15160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15161 \begin_inset Text
15162
15163 \layout Standard
15164
15165 _divulong.c 
15166 \end_inset 
15167 </cell>
15168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15169 \begin_inset Text
15170
15171 \layout Standard
15172
15173 unsigned 32 division
15174 \end_inset 
15175 </cell>
15176 </row>
15177 <row topline="true">
15178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15179 \begin_inset Text
15180
15181 \layout Standard
15182
15183 _modslong.c
15184 \end_inset 
15185 </cell>
15186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15187 \begin_inset Text
15188
15189 \layout Standard
15190
15191  signed 32 bit modulus (calls _modulong)
15192 \end_inset 
15193 </cell>
15194 </row>
15195 <row topline="true" bottomline="true">
15196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15197 \begin_inset Text
15198
15199 \layout Standard
15200
15201 _modulong.c
15202 \end_inset 
15203 </cell>
15204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15205 \begin_inset Text
15206
15207 \layout Standard
15208
15209 unsigned 32 bit modulus
15210 \end_inset 
15211 </cell>
15212 </row>
15213 </lyxtabular>
15214
15215 \end_inset 
15216
15217
15218 \newline 
15219
15220 \layout Standard
15221
15222 Since they are compiled as 
15223 \emph on 
15224 non-reentrant
15225 \emph default 
15226
15227 \begin_inset LatexCommand \index{reentrant}
15228
15229 \end_inset 
15230
15231 , interrupt
15232 \begin_inset LatexCommand \index{interrupt}
15233
15234 \end_inset 
15235
15236  service routines should not do any of the above operations.
15237  If this is unavoidable then the above routines will need to be compiled
15238  with the 
15239 \emph on 
15240 -
15241 \begin_inset ERT
15242 status Collapsed
15243
15244 \layout Standard
15245
15246 \backslash 
15247 /
15248 \end_inset 
15249
15250 -stack-auto
15251 \begin_inset LatexCommand \index{-\/-stack-auto}
15252
15253 \end_inset 
15254
15255
15256 \emph default 
15257  option, after which the source program will have to be compiled with 
15258 \emph on 
15259 -
15260 \begin_inset ERT
15261 status Collapsed
15262
15263 \layout Standard
15264
15265 \backslash 
15266 /
15267 \end_inset 
15268
15269 -int-long-reent
15270 \begin_inset LatexCommand \index{-\/-int-long-reent}
15271
15272 \end_inset 
15273
15274
15275 \emph default 
15276  option.
15277  Notice that you don't have to call these routines directly.
15278  The compiler will use them automatically every time an integer operation
15279  is required.
15280 \layout Section
15281
15282 Floating Point Support
15283 \begin_inset LatexCommand \index{Floating point support}
15284
15285 \end_inset 
15286
15287
15288 \layout Standard
15289
15290 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15291  The floating point support routines are derived from gcc's floatlib.c and
15292  consist of the following routines:
15293 \newline 
15294
15295 \layout Standard
15296 \align center 
15297
15298 \size footnotesize 
15299
15300 \begin_inset  Tabular
15301 <lyxtabular version="3" rows="17" columns="2">
15302 <features>
15303 <column alignment="left" valignment="top" leftline="true" width="0">
15304 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15305 <row topline="true" bottomline="true">
15306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15307 \begin_inset Text
15308
15309 \layout Standard
15310
15311
15312 \family roman 
15313 \series medium 
15314 \shape up 
15315 \size normal 
15316 \emph off 
15317 \bar no 
15318 \noun off 
15319 \color none
15320 Function 
15321 \end_inset 
15322 </cell>
15323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15324 \begin_inset Text
15325
15326 \layout Standard
15327
15328 Description
15329 \end_inset 
15330 </cell>
15331 </row>
15332 <row topline="true">
15333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15334 \begin_inset Text
15335
15336 \layout Standard
15337
15338
15339 \family roman 
15340 \series medium 
15341 \shape up 
15342 \size normal 
15343 \emph off 
15344 \bar no 
15345 \noun off 
15346 \color none
15347 _fsadd.c
15348 \end_inset 
15349 </cell>
15350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15351 \begin_inset Text
15352
15353 \layout Standard
15354
15355
15356 \family roman 
15357 \series medium 
15358 \shape up 
15359 \size normal 
15360 \emph off 
15361 \bar no 
15362 \noun off 
15363 \color none
15364 add floating point numbers
15365 \end_inset 
15366 </cell>
15367 </row>
15368 <row topline="true">
15369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15370 \begin_inset Text
15371
15372 \layout Standard
15373
15374
15375 \family roman 
15376 \series medium 
15377 \shape up 
15378 \size normal 
15379 \emph off 
15380 \bar no 
15381 \noun off 
15382 \color none
15383 _fssub.c 
15384 \end_inset 
15385 </cell>
15386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15387 \begin_inset Text
15388
15389 \layout Standard
15390
15391
15392 \family roman 
15393 \series medium 
15394 \shape up 
15395 \size normal 
15396 \emph off 
15397 \bar no 
15398 \noun off 
15399 \color none
15400 subtract floating point numbers 
15401 \end_inset 
15402 </cell>
15403 </row>
15404 <row topline="true">
15405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15406 \begin_inset Text
15407
15408 \layout Standard
15409
15410
15411 \family roman 
15412 \series medium 
15413 \shape up 
15414 \size normal 
15415 \emph off 
15416 \bar no 
15417 \noun off 
15418 \color none
15419 _fsdiv.c 
15420 \end_inset 
15421 </cell>
15422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15423 \begin_inset Text
15424
15425 \layout Standard
15426
15427
15428 \family roman 
15429 \series medium 
15430 \shape up 
15431 \size normal 
15432 \emph off 
15433 \bar no 
15434 \noun off 
15435 \color none
15436 divide floating point numbers 
15437 \end_inset 
15438 </cell>
15439 </row>
15440 <row topline="true">
15441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15442 \begin_inset Text
15443
15444 \layout Standard
15445
15446
15447 \family roman 
15448 \series medium 
15449 \shape up 
15450 \size normal 
15451 \emph off 
15452 \bar no 
15453 \noun off 
15454 \color none
15455 _fsmul.c 
15456 \end_inset 
15457 </cell>
15458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15459 \begin_inset Text
15460
15461 \layout Standard
15462
15463
15464 \family roman 
15465 \series medium 
15466 \shape up 
15467 \size normal 
15468 \emph off 
15469 \bar no 
15470 \noun off 
15471 \color none
15472 multiply floating point numbers 
15473 \end_inset 
15474 </cell>
15475 </row>
15476 <row topline="true">
15477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15478 \begin_inset Text
15479
15480 \layout Standard
15481
15482
15483 \family roman 
15484 \series medium 
15485 \shape up 
15486 \size normal 
15487 \emph off 
15488 \bar no 
15489 \noun off 
15490 \color none
15491 _fs2uchar.c
15492 \end_inset 
15493 </cell>
15494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15495 \begin_inset Text
15496
15497 \layout Standard
15498
15499
15500 \family roman 
15501 \series medium 
15502 \shape up 
15503 \size normal 
15504 \emph off 
15505 \bar no 
15506 \noun off 
15507 \color none
15508 convert floating point to unsigned char
15509 \end_inset 
15510 </cell>
15511 </row>
15512 <row topline="true">
15513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15514 \begin_inset Text
15515
15516 \layout Standard
15517
15518
15519 \family roman 
15520 \series medium 
15521 \shape up 
15522 \size normal 
15523 \emph off 
15524 \bar no 
15525 \noun off 
15526 \color none
15527 _fs2char.c
15528 \end_inset 
15529 </cell>
15530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15531 \begin_inset Text
15532
15533 \layout Standard
15534
15535
15536 \family roman 
15537 \series medium 
15538 \shape up 
15539 \size normal 
15540 \emph off 
15541 \bar no 
15542 \noun off 
15543 \color none
15544 convert floating point to signed char
15545 \end_inset 
15546 </cell>
15547 </row>
15548 <row topline="true">
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15550 \begin_inset Text
15551
15552 \layout Standard
15553
15554
15555 \family roman 
15556 \series medium 
15557 \shape up 
15558 \size normal 
15559 \emph off 
15560 \bar no 
15561 \noun off 
15562 \color none
15563 _fs2uint.c
15564 \end_inset 
15565 </cell>
15566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15567 \begin_inset Text
15568
15569 \layout Standard
15570
15571
15572 \family roman 
15573 \series medium 
15574 \shape up 
15575 \size normal 
15576 \emph off 
15577 \bar no 
15578 \noun off 
15579 \color none
15580 convert floating point to unsigned int
15581 \end_inset 
15582 </cell>
15583 </row>
15584 <row topline="true">
15585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15586 \begin_inset Text
15587
15588 \layout Standard
15589
15590
15591 \family roman 
15592 \series medium 
15593 \shape up 
15594 \size normal 
15595 \emph off 
15596 \bar no 
15597 \noun off 
15598 \color none
15599 _fs2int.c
15600 \end_inset 
15601 </cell>
15602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15603 \begin_inset Text
15604
15605 \layout Standard
15606
15607
15608 \family roman 
15609 \series medium 
15610 \shape up 
15611 \size normal 
15612 \emph off 
15613 \bar no 
15614 \noun off 
15615 \color none
15616 convert floating point to signed int
15617 \end_inset 
15618 </cell>
15619 </row>
15620 <row topline="true">
15621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15622 \begin_inset Text
15623
15624 \layout Standard
15625
15626
15627 \family roman 
15628 \series medium 
15629 \shape up 
15630 \size normal 
15631 \emph off 
15632 \bar no 
15633 \noun off 
15634 \color none
15635 _fs2ulong.
15636 \family default 
15637 \series default 
15638 \shape default 
15639 \size default 
15640 \emph default 
15641 \bar default 
15642 \noun default 
15643 \color default
15644 c
15645 \end_inset 
15646 </cell>
15647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15648 \begin_inset Text
15649
15650 \layout Standard
15651
15652
15653 \family roman 
15654 \series medium 
15655 \shape up 
15656 \size normal 
15657 \emph off 
15658 \bar no 
15659 \noun off 
15660 \color none
15661 convert floating point to unsigned long
15662 \end_inset 
15663 </cell>
15664 </row>
15665 <row topline="true">
15666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15667 \begin_inset Text
15668
15669 \layout Standard
15670
15671
15672 \family roman 
15673 \series medium 
15674 \shape up 
15675 \size normal 
15676 \emph off 
15677 \bar no 
15678 \noun off 
15679 \color none
15680 _fs2long.c
15681 \end_inset 
15682 </cell>
15683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15684 \begin_inset Text
15685
15686 \layout Standard
15687
15688
15689 \family roman 
15690 \series medium 
15691 \shape up 
15692 \size normal 
15693 \emph off 
15694 \bar no 
15695 \noun off 
15696 \color none
15697 convert floating point to signed long
15698 \end_inset 
15699 </cell>
15700 </row>
15701 <row topline="true">
15702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15703 \begin_inset Text
15704
15705 \layout Standard
15706
15707
15708 \family roman 
15709 \series medium 
15710 \shape up 
15711 \size normal 
15712 \emph off 
15713 \bar no 
15714 \noun off 
15715 \color none
15716 _uchar2fs.c
15717 \end_inset 
15718 </cell>
15719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15720 \begin_inset Text
15721
15722 \layout Standard
15723
15724
15725 \family roman 
15726 \series medium 
15727 \shape up 
15728 \size normal 
15729 \emph off 
15730 \bar no 
15731 \noun off 
15732 \color none
15733 convert unsigned char to floating point
15734 \end_inset 
15735 </cell>
15736 </row>
15737 <row topline="true">
15738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15739 \begin_inset Text
15740
15741 \layout Standard
15742
15743
15744 \family roman 
15745 \series medium 
15746 \shape up 
15747 \size normal 
15748 \emph off 
15749 \bar no 
15750 \noun off 
15751 \color none
15752 _char2fs.c
15753 \end_inset 
15754 </cell>
15755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15756 \begin_inset Text
15757
15758 \layout Standard
15759
15760
15761 \family roman 
15762 \series medium 
15763 \shape up 
15764 \size normal 
15765 \emph off 
15766 \bar no 
15767 \noun off 
15768 \color none
15769 convert char to floating point number
15770 \end_inset 
15771 </cell>
15772 </row>
15773 <row topline="true">
15774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15775 \begin_inset Text
15776
15777 \layout Standard
15778
15779
15780 \family roman 
15781 \series medium 
15782 \shape up 
15783 \size normal 
15784 \emph off 
15785 \bar no 
15786 \noun off 
15787 \color none
15788 _uint2fs.c
15789 \end_inset 
15790 </cell>
15791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15792 \begin_inset Text
15793
15794 \layout Standard
15795
15796
15797 \family roman 
15798 \series medium 
15799 \shape up 
15800 \size normal 
15801 \emph off 
15802 \bar no 
15803 \noun off 
15804 \color none
15805 convert unsigned int to floating point
15806 \end_inset 
15807 </cell>
15808 </row>
15809 <row topline="true">
15810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15811 \begin_inset Text
15812
15813 \layout Standard
15814
15815
15816 \family roman 
15817 \series medium 
15818 \shape up 
15819 \size normal 
15820 \emph off 
15821 \bar no 
15822 \noun off 
15823 \color none
15824 _int2fs.c
15825 \end_inset 
15826 </cell>
15827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15828 \begin_inset Text
15829
15830 \layout Standard
15831
15832
15833 \family roman 
15834 \series medium 
15835 \shape up 
15836 \size normal 
15837 \emph off 
15838 \bar no 
15839 \noun off 
15840 \color none
15841 convert int to floating point numbers
15842 \end_inset 
15843 </cell>
15844 </row>
15845 <row topline="true">
15846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15847 \begin_inset Text
15848
15849 \layout Standard
15850
15851
15852 \family roman 
15853 \series medium 
15854 \shape up 
15855 \size normal 
15856 \emph off 
15857 \bar no 
15858 \noun off 
15859 \color none
15860 _ulong2fs.c
15861 \end_inset 
15862 </cell>
15863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15864 \begin_inset Text
15865
15866 \layout Standard
15867
15868
15869 \family roman 
15870 \series medium 
15871 \shape up 
15872 \size normal 
15873 \emph off 
15874 \bar no 
15875 \noun off 
15876 \color none
15877 convert unsigned long to floating point number
15878 \end_inset 
15879 </cell>
15880 </row>
15881 <row topline="true" bottomline="true">
15882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15883 \begin_inset Text
15884
15885 \layout Standard
15886
15887
15888 \family roman 
15889 \series medium 
15890 \shape up 
15891 \size normal 
15892 \emph off 
15893 \bar no 
15894 \noun off 
15895 \color none
15896 _long2fs.c
15897 \end_inset 
15898 </cell>
15899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15900 \begin_inset Text
15901
15902 \layout Standard
15903
15904
15905 \family roman 
15906 \series medium 
15907 \shape up 
15908 \size normal 
15909 \emph off 
15910 \bar no 
15911 \noun off 
15912 \color none
15913 convert long to floating point number
15914 \end_inset 
15915 </cell>
15916 </row>
15917 </lyxtabular>
15918
15919 \end_inset 
15920
15921
15922 \newline 
15923
15924 \layout Standard
15925 \added_space_bottom bigskip 
15926 These support routines are developed in ANSI-C so there is room for space
15927  and speed improvement
15928 \begin_inset Foot
15929 collapsed false
15930
15931 \layout Standard
15932
15933 These floating point routines (
15934 \emph on 
15935 not
15936 \emph default 
15937  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15938  
15939 \end_inset 
15940
15941 .
15942  Note if all these routines are used simultaneously the data space might
15943  overflow.
15944  For serious floating point usage the large model might be needed.
15945  Also notice that you don't have to call this routines directly.
15946  The compiler will use them automatically every time a floating point operation
15947  is required.
15948 \layout Section
15949
15950 Library Routines
15951 \begin_inset LatexCommand \index{Libraries}
15952
15953 \end_inset 
15954
15955
15956 \layout Standard
15957
15958
15959 \emph on 
15960 <pending: this is messy and incomplete - a little more information is in
15961  sdcc/doc/libdoc.txt
15962 \emph default 
15963  >
15964 \layout Subsection
15965
15966 Compiler support routines (_gptrget, _mulint etc.)
15967 \layout Subsection
15968
15969 Stdclib functions (puts, printf, strcat etc.)
15970 \layout Subsubsection
15971
15972 <stdio.h>
15973 \layout Standard
15974
15975
15976 \begin_inset LatexCommand \index{<stdio.h>}
15977
15978 \end_inset 
15979
15980 As usual on embedded systems you have to provide your own 
15981 \family typewriter 
15982 getchar()
15983 \begin_inset LatexCommand \index{getchar()}
15984
15985 \end_inset 
15986
15987  
15988 \family default 
15989 and 
15990 \family typewriter 
15991 putchar()
15992 \begin_inset LatexCommand \index{putchar()}
15993
15994 \end_inset 
15995
15996
15997 \family default 
15998  routines.
15999  SDCC does not know whether the system connects to a serial line with or
16000  without handshake, LCD, keyboard or other device.
16001  And whether a 
16002 \family typewriter 
16003 lf
16004 \family default 
16005  to 
16006 \family typewriter 
16007 crlf
16008 \family default 
16009  conversion within 
16010 \family typewriter 
16011 putchar()
16012 \family default 
16013  is intended.
16014  You'll find examples for serial routines f.e.
16015  in sdcc/device/lib.
16016 \layout Standard
16017
16018 The default
16019 \family typewriter 
16020  printf()
16021 \begin_inset LatexCommand \index{printf()}
16022
16023 \end_inset 
16024
16025
16026 \family default 
16027 implementation in
16028 \family typewriter 
16029  printf_large.c
16030 \family default 
16031  does not support float (except on ds390).
16032  To enable this recompile it with the option 
16033 \emph on 
16034 -
16035 \begin_inset ERT
16036 status Collapsed
16037
16038 \layout Standard
16039
16040 \backslash 
16041 /
16042 \end_inset 
16043
16044 DUSE_FLOATS=1
16045 \begin_inset LatexCommand \index{USE\_FLOATS}
16046
16047 \end_inset 
16048
16049
16050 \emph default 
16051  on the command line.
16052  Use
16053 \emph on 
16054  -
16055 \begin_inset ERT
16056 status Collapsed
16057
16058 \layout Standard
16059
16060 \backslash 
16061 /
16062 \end_inset 
16063
16064 -model-large
16065 \begin_inset LatexCommand \index{-\/-model-large}
16066
16067 \end_inset 
16068
16069
16070 \emph default 
16071  for the mcs51 port, since this uses a lot of memory.
16072 \layout Standard
16073
16074 If you're short on memory you might want to use 
16075 \family typewriter 
16076 printf_small()
16077 \begin_inset LatexCommand \index{printf\_small()}
16078
16079 \end_inset 
16080
16081
16082 \family default 
16083  
16084 \emph on 
16085 instead
16086 \emph default 
16087  of
16088 \family typewriter 
16089  printf().
16090
16091 \family default 
16092  For the mcs51 there additionally are assembly versions 
16093 \family typewriter 
16094 printf_tiny()
16095 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16096
16097 \end_inset 
16098
16099
16100 \family default 
16101  (subset of printf using less than 270 bytes) and 
16102 \family typewriter 
16103 printf_fast()
16104 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16105
16106 \end_inset 
16107
16108  
16109 \family default 
16110 and
16111 \family typewriter 
16112  printf_fast_f()
16113 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16114
16115 \end_inset 
16116
16117
16118 \family default 
16119  (floating-point aware version of printf_fast) which should fit the requirements
16120  of many embedded systems (printf_fast() can be customized by unsetting
16121  #defines to 
16122 \emph on 
16123 not
16124 \emph default 
16125  support long variables and field widths).
16126 \layout Subsubsection
16127
16128 <malloc.h>
16129 \begin_inset LatexCommand \index{malloc.h}
16130
16131 \end_inset 
16132
16133
16134 \layout Standard
16135
16136 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16137  using dynamic memory allocation
16138 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16139
16140 \end_inset 
16141
16142  and a default heap
16143 \begin_inset LatexCommand \index{heap (malloc)}
16144
16145 \end_inset 
16146
16147  space of 1024 bytes is provided for malloc to allocate memory from.
16148  If you need a different heap size you need to recompile _heap.c with the
16149  required size defined in HEAP_SIZE.
16150  It is recommended to make a copy of this file into your project directory
16151  and compile it there with:
16152 \layout Verse
16153
16154
16155 \family typewriter 
16156 sdcc -c _heap.c -D HEAD_SIZE=2048
16157 \newline 
16158
16159 \family default 
16160 And then link it with:
16161 \layout Verse
16162
16163
16164 \family typewriter 
16165 sdcc main.rel _heap.rel
16166 \newline 
16167
16168 \layout Subsection
16169
16170 Math functions (sinf, powf, sqrtf etc.)
16171 \layout Subsubsection
16172
16173 <math.h>
16174 \layout Standard
16175
16176 See definitions in file <math.h>.
16177 \layout Subsection
16178
16179 Other libraries
16180 \layout Standard
16181
16182 Libraries
16183 \begin_inset LatexCommand \index{Libraries}
16184
16185 \end_inset 
16186
16187  included in SDCC should have a license at least as liberal as the GNU Lesser
16188  General Public License
16189 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16190
16191 \end_inset 
16192
16193  
16194 \emph on 
16195 LGPL
16196 \emph default 
16197 .
16198 \layout Comment
16199
16200 license statements for the libraries are missing.
16201  sdcc/device/lib/ser_ir.c
16202 \layout Comment
16203
16204 or _decdptr f.e.
16205  come with a GPL (as opposed to LGPL) License - this will not be liberal
16206  enough for many embedded programmers.
16207 \layout Standard
16208
16209 If you have ported some library or want to share experience about some code
16210  which f.e.
16211  falls into any of these categories Busses (I
16212 \begin_inset Formula $^{\textrm{2}}$
16213 \end_inset 
16214
16215 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16216  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16217  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16218 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16219
16220 \end_inset 
16221
16222 \SpecialChar ~
16223 would certainly like to hear about it.
16224 \layout Standard
16225 \added_space_bottom bigskip 
16226 Programmers coding for embedded systems are not especially famous for being
16227  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16228 e these references are very valuable.
16229  Let's help to create a climate where information is shared.
16230 \layout Section
16231
16232 Memory Models
16233 \layout Subsection
16234
16235 MCS51 Memory Models
16236 \begin_inset LatexCommand \index{Memory model}
16237
16238 \end_inset 
16239
16240
16241 \begin_inset LatexCommand \index{MCS51 memory model}
16242
16243 \end_inset 
16244
16245
16246 \layout Subsubsection
16247
16248 Small, Medium and Large
16249 \layout Standard
16250
16251 SDCC allows three memory models for MCS51 code, 
16252 \shape slanted 
16253 small, medium
16254 \shape default 
16255  and 
16256 \shape slanted 
16257 large
16258 \shape default 
16259 .
16260  Modules compiled with different memory models should 
16261 \emph on 
16262 never
16263 \emph default 
16264  be combined together or the results would be unpredictable.
16265  The library routines supplied with the compiler are compiled as small,
16266  medium and large.
16267  The compiled library modules are contained in separate directories as small,
16268  medium and large so that you can link to the appropriate set.
16269 \layout Standard
16270
16271 When the medium or large model is used all variables declared without a
16272  storage class will be allocated into the external ram, this includes all
16273  parameters and local variables (for non-reentrant
16274 \begin_inset LatexCommand \index{reentrant}
16275
16276 \end_inset 
16277
16278  functions).
16279  When the small model is used variables without storage class are allocated
16280  in the internal ram.
16281 \layout Standard
16282
16283 Judicious usage of the processor specific storage classes
16284 \begin_inset LatexCommand \index{Storage class}
16285
16286 \end_inset 
16287
16288  and the 'reentrant' function type will yield much more efficient code,
16289  than using the large model.
16290  Several optimizations are disabled when the program is compiled using the
16291  large model, it is therefore recommended that the small model be used unless
16292  absolutely required.
16293 \layout Subsubsection
16294
16295 External Stack
16296 \begin_inset LatexCommand \label{sub:External-Stack}
16297
16298 \end_inset 
16299
16300
16301 \begin_inset LatexCommand \index{stack}
16302
16303 \end_inset 
16304
16305
16306 \begin_inset LatexCommand \index{External stack (mcs51)}
16307
16308 \end_inset 
16309
16310
16311 \layout Standard
16312
16313 The external stack (-
16314 \begin_inset ERT
16315 status Collapsed
16316
16317 \layout Standard
16318
16319 \backslash 
16320 /
16321 \end_inset 
16322
16323 -xstack option
16324 \begin_inset LatexCommand \index{-\/-xstack}
16325
16326 \end_inset 
16327
16328 ) is located in pdata
16329 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16330
16331 \end_inset 
16332
16333  memory (usually at the start of the external ram segment) and uses all
16334  unused space in pdata (max.
16335  256 bytes).
16336  When -
16337 \begin_inset ERT
16338 status Collapsed
16339
16340 \layout Standard
16341
16342 \backslash 
16343 /
16344 \end_inset 
16345
16346 -xstack option is used to compile the program, the parameters and local
16347  variables
16348 \begin_inset LatexCommand \index{local variables}
16349
16350 \end_inset 
16351
16352  of all reentrant functions are allocated in this area.
16353  This option is provided for programs with large stack space requirements.
16354  When used with the -
16355 \begin_inset ERT
16356 status Collapsed
16357
16358 \layout Standard
16359
16360 \backslash 
16361 /
16362 \end_inset 
16363
16364 -stack-auto
16365 \begin_inset LatexCommand \index{-\/-stack-auto}
16366
16367 \end_inset 
16368
16369  option, all parameters and local variables are allocated on the external
16370  stack (note: support libraries will need to be recompiled with the same
16371  options.
16372  There is a predefined target in the library makefile).
16373 \layout Standard
16374
16375 The compiler outputs the higher order address byte of the external ram segment
16376  into port P2
16377 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16378
16379 \end_inset 
16380
16381  (see also section 
16382 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16383
16384 \end_inset 
16385
16386 ), therefore when using the External Stack option, this port 
16387 \emph on 
16388 may not
16389 \emph default 
16390  be used by the application program.
16391 \layout Subsection
16392
16393 DS390 Memory Model
16394 \begin_inset LatexCommand \index{Memory model}
16395
16396 \end_inset 
16397
16398
16399 \begin_inset LatexCommand \index{DS390 memory model}
16400
16401 \end_inset 
16402
16403
16404 \layout Standard
16405
16406 The only model supported is Flat 24
16407 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16408
16409 \end_inset 
16410
16411 .
16412  This generates code for the 24 bit contiguous addressing mode of the Dallas
16413  DS80C390 part.
16414  In this mode, up to four meg of external RAM or code space can be directly
16415  addressed.
16416  See the data sheets at www.dalsemi.com for further information on this part.
16417 \newline 
16418
16419 \newline 
16420 Note that the compiler does not generate any code to place the processor
16421  into 24 bitmode (although 
16422 \emph on 
16423 tinibios
16424 \emph default 
16425  in the ds390 libraries will do that for you).
16426  If you don't use 
16427 \emph on 
16428 tinibios
16429 \emph default 
16430
16431 \begin_inset LatexCommand \index{Tinibios (DS390)}
16432
16433 \end_inset 
16434
16435 , the boot loader or similar code must ensure that the processor is in 24
16436  bit contiguous addressing mode before calling the SDCC startup code.
16437 \newline 
16438
16439 \newline 
16440 Like the 
16441 \emph on 
16442 -
16443 \begin_inset ERT
16444 status Collapsed
16445
16446 \layout Standard
16447
16448 \backslash 
16449 /
16450 \end_inset 
16451
16452 -model-large
16453 \emph default 
16454  option, variables will by default be placed into the XDATA segment.
16455  
16456 \newline 
16457
16458 \newline 
16459 Segments may be placed anywhere in the 4 meg address space using the usual
16460  -
16461 \begin_inset ERT
16462 status Collapsed
16463
16464 \layout Standard
16465
16466 \backslash 
16467 /
16468 \end_inset 
16469
16470 -*-loc options.
16471  Note that if any segments are located above 64K, the -r flag must be passed
16472  to the linker to generate the proper segment relocations, and the Intel
16473  HEX output format must be used.
16474  The -r flag can be passed to the linker by using the option 
16475 \emph on 
16476 -Wl-r
16477 \emph default 
16478  on the SDCC command line.
16479  However, currently the linker can not handle code segments > 64k.
16480 \layout Section
16481
16482 Pragmas
16483 \begin_inset LatexCommand \label{sec:Pragmas}
16484
16485 \end_inset 
16486
16487
16488 \begin_inset LatexCommand \index{Pragmas}
16489
16490 \end_inset 
16491
16492
16493 \layout Standard
16494
16495 SDCC supports the following #pragma directives:
16496 \layout Itemize
16497
16498
16499 \series bold 
16500 save
16501 \series default 
16502
16503 \begin_inset LatexCommand \index{\#pragma save}
16504
16505 \end_inset 
16506
16507  - this will save most current options to the save/restore stack.
16508  See #pragma\SpecialChar ~
16509 restore.
16510 \layout Itemize
16511
16512
16513 \series bold 
16514 restore
16515 \series default 
16516
16517 \begin_inset LatexCommand \index{\#pragma restore}
16518
16519 \end_inset 
16520
16521  - will restore saved options from the last save.
16522  saves & restores can be nested.
16523  SDCC uses a save/restore stack: save pushes current options to the stack,
16524  restore pulls current options from the stack.
16525  See #pragma\SpecialChar ~
16526 save.
16527 \newline 
16528
16529 \layout Itemize
16530
16531
16532 \series bold 
16533 callee_saves
16534 \series default 
16535
16536 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16537
16538 \end_inset 
16539
16540
16541 \begin_inset LatexCommand \index{function prologue}
16542
16543 \end_inset 
16544
16545  function1[,function2[,function3...]] - The compiler by default uses a caller
16546  saves convention for register saving across function calls, however this
16547  can cause unnecessary register pushing & popping
16548 \begin_inset LatexCommand \index{push/pop}
16549
16550 \end_inset 
16551
16552  when calling small functions from larger functions.
16553  This option can be used to switch off the register saving convention for
16554  the function names specified.
16555  The compiler will not save registers when calling these functions, extra
16556  code need to be manually inserted at the entry & exit for these functions
16557  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16558  reduce code & improve run time performance of the generated code.
16559  In the future the compiler (with inter procedural analysis) may be able
16560  to determine the appropriate scheme to use for each function call.
16561  If -
16562 \begin_inset ERT
16563 status Collapsed
16564
16565 \layout Standard
16566
16567 \backslash 
16568 /
16569 \end_inset 
16570
16571 -callee-saves command line option is used, the function names specified
16572  in #pragma\SpecialChar ~
16573 callee_saves
16574 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16575
16576 \end_inset 
16577
16578  is appended to the list of functions specified in the command line.
16579 \layout Itemize
16580
16581
16582 \series bold 
16583 exclude
16584 \series default 
16585
16586 \begin_inset LatexCommand \index{\#pragma exclude}
16587
16588 \end_inset 
16589
16590  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16591  of pairs of push/pop
16592 \begin_inset LatexCommand \index{push/pop}
16593
16594 \end_inset 
16595
16596  instructions in 
16597 \emph on 
16598 I
16599 \emph default 
16600 nterrupt
16601 \begin_inset LatexCommand \index{interrupt}
16602
16603 \end_inset 
16604
16605  
16606 \emph on 
16607 S
16608 \emph default 
16609 ervice 
16610 \emph on 
16611 R
16612 \emph default 
16613 outines.
16614  The directive should be placed immediately before the ISR function definition
16615  and it affects ALL ISR functions following it.
16616  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16617 exclude\SpecialChar ~
16618 none
16619 \begin_inset LatexCommand \index{\#pragma exclude}
16620
16621 \end_inset 
16622
16623 .
16624  See also the related keyword _naked
16625 \begin_inset LatexCommand \index{\_naked}
16626
16627 \end_inset 
16628
16629
16630 \begin_inset LatexCommand \index{\_\_naked}
16631
16632 \end_inset 
16633
16634 .
16635 \layout Itemize
16636
16637
16638 \series bold 
16639 less_pedantic
16640 \series default 
16641
16642 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16643
16644 \end_inset 
16645
16646  - the compiler will not warn you anymore for obvious mistakes, you'r on
16647  your own now ;-(
16648 \layout Itemize
16649
16650
16651 \series bold 
16652 disable_warning
16653 \series default 
16654  <nnnn>
16655 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16656
16657 \end_inset 
16658
16659  - the compiler will not warn you anymore about warning number <nnnn>.
16660 \layout Itemize
16661
16662
16663 \series bold 
16664 nogcse
16665 \series default 
16666
16667 \begin_inset LatexCommand \index{\#pragma nogcse}
16668
16669 \end_inset 
16670
16671  - will stop global common subexpression elimination.
16672 \layout Itemize
16673
16674
16675 \series bold 
16676 noinduction
16677 \series default 
16678
16679 \begin_inset LatexCommand \index{\#pragma noinduction}
16680
16681 \end_inset 
16682
16683  - will stop loop induction optimizations.
16684 \layout Itemize
16685
16686
16687 \series bold 
16688 noinvariant
16689 \series default 
16690
16691 \begin_inset LatexCommand \index{\#pragma noinvariant}
16692
16693 \end_inset 
16694
16695  - will not do loop invariant optimizations.
16696  For more details see Loop Invariants in section
16697 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16698
16699 \end_inset 
16700
16701 .
16702 \layout Itemize
16703
16704
16705 \series bold 
16706 noiv
16707 \series default 
16708
16709 \begin_inset LatexCommand \index{\#pragma noiv}
16710
16711 \end_inset 
16712
16713  - Do not generate interrupt
16714 \begin_inset LatexCommand \index{interrupt}
16715
16716 \end_inset 
16717
16718  vector table
16719 \begin_inset LatexCommand \index{interrupt vector table}
16720
16721 \end_inset 
16722
16723  entries for all ISR functions defined after the pragma.
16724  This is useful in cases where the interrupt vector table must be defined
16725  manually, or when there is a secondary, manually defined interrupt vector
16726  table (e.g.
16727  for the autovector feature of the Cypress EZ-USB FX2).
16728  More elegantly this can be achieved by obmitting the optional interrupt
16729  number after the interrupt keyword, see section 
16730 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16731
16732 \end_inset 
16733
16734 \SpecialChar ~
16735 about interrupts.
16736 \layout Itemize
16737
16738
16739 \series bold 
16740 nojtbound
16741 \series default 
16742
16743 \begin_inset LatexCommand \index{\#pragma nojtbound}
16744
16745 \end_inset 
16746
16747  - will not generate code for boundary value checking, when switch statements
16748  are turned into jump-tables (dangerous).
16749  For more details see section 
16750 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16751
16752 \end_inset 
16753
16754 .
16755 \layout Itemize
16756
16757
16758 \series bold 
16759 noloopreverse
16760 \series default 
16761
16762 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16763
16764 \end_inset 
16765
16766  - Will not do loop reversal optimization
16767 \layout Itemize
16768
16769
16770 \series bold 
16771 nooverlay
16772 \series default 
16773
16774 \begin_inset LatexCommand \index{\#pragma nooverlay}
16775
16776 \end_inset 
16777
16778  - the compiler will not overlay the parameters and local variables of a
16779  function.
16780 \layout Itemize
16781
16782
16783 \series bold 
16784 stackauto
16785 \series default 
16786
16787 \begin_inset LatexCommand \index{\#pragma stackauto}
16788
16789 \end_inset 
16790
16791 - See option -
16792 \begin_inset ERT
16793 status Collapsed
16794
16795 \layout Standard
16796
16797 \backslash 
16798 /
16799 \end_inset 
16800
16801 -stack-auto
16802 \begin_inset LatexCommand \index{-\/-stack-auto}
16803
16804 \end_inset 
16805
16806  and section 
16807 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16808
16809 \end_inset 
16810
16811  Parameters and Local Variables.
16812 \layout Itemize
16813
16814
16815 \series bold 
16816 opt_code_speed
16817 \series default 
16818  
16819 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16820
16821 \end_inset 
16822
16823 - The compiler will optimize code generation towards fast code, possibly
16824  at the expense of code size.
16825  Currently this has little effect.
16826 \layout Itemize
16827
16828
16829 \series bold 
16830 opt_code_size
16831 \series default 
16832  
16833 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16834
16835 \end_inset 
16836
16837 - The compiler will optimize code generation towards compact code, possibly
16838  at the expense of code speed.
16839  Currently this has little effect.
16840 \layout Itemize
16841
16842
16843 \series bold 
16844 opt_code_balanced
16845 \series default 
16846  
16847 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16848
16849 \end_inset 
16850
16851 - The compiler will attempt to generate code that is both compact and fast,
16852  as long as meeting one goal is not a detriment to the other (this is the
16853  default).
16854  
16855 \layout Itemize
16856
16857
16858 \series bold 
16859 std_sdcc89
16860 \series default 
16861  
16862 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16863
16864 \end_inset 
16865
16866 - Generally follow the C89 standard, but allow SDCC features that conflict
16867  with the standard (default).
16868 \layout Itemize
16869
16870
16871 \series bold 
16872 std_c89
16873 \series default 
16874  
16875 \begin_inset LatexCommand \index{\#pragma std\_c89}
16876
16877 \end_inset 
16878
16879 - Follow the C89 standard and disable SDCC features that conflict with the
16880  standard.
16881 \layout Itemize
16882
16883
16884 \series bold 
16885 std_sdcc99
16886 \series default 
16887  
16888 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16889
16890 \end_inset 
16891
16892 - Generally follow the C99 standard, but allow SDCC features that conflict
16893  with the standard (incomplete support).
16894 \layout Itemize
16895
16896
16897 \series bold 
16898 std_c99
16899 \series default 
16900  
16901 \begin_inset LatexCommand \index{\#pragma std\_c99}
16902
16903 \end_inset 
16904
16905 - Follow the C99 standard and disable SDCC features that conflict with the
16906  standard (incomplete support).
16907 \layout Itemize
16908
16909
16910 \series bold 
16911 codeseg
16912 \series default 
16913  <name>
16914 \begin_inset LatexCommand \index{\#pragma codeseg}
16915
16916 \end_inset 
16917
16918 - Use this name (max.
16919  8 characters) for the code segment.
16920  See option -
16921 \begin_inset ERT
16922 status Collapsed
16923
16924 \layout Standard
16925
16926 \backslash 
16927 /
16928 \end_inset 
16929
16930 -codeseg.
16931 \layout Itemize
16932
16933
16934 \series bold 
16935 constseg
16936 \series default 
16937  <name>
16938 \begin_inset LatexCommand \index{\#pragma constseg}
16939
16940 \end_inset 
16941
16942 - Use this name (max.
16943  8 characters) for the const segment.
16944  See option -
16945 \begin_inset ERT
16946 status Collapsed
16947
16948 \layout Standard
16949
16950 \backslash 
16951 /
16952 \end_inset 
16953
16954 -constseg.
16955 \layout Standard
16956
16957 The preprocessor SDCPP
16958 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16959
16960 \end_inset 
16961
16962  supports the following #pragma directives:
16963 \layout Itemize
16964
16965
16966 \series bold 
16967 pedantic_parse_number
16968 \series default 
16969
16970 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
16971
16972 \end_inset 
16973
16974  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
16975  parsed properly and the macro LO_B(3) gets expanded.
16976  Default is off.
16977  Below is an example on how to use this pragma.
16978
16979 \emph on 
16980  Note: this functionality is not in conformance with standard!
16981 \layout Verse
16982
16983
16984 \family typewriter 
16985 #pragma pedantic_parse_number +
16986 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
16987
16988 \end_inset 
16989
16990
16991 \newline 
16992
16993 \newline 
16994 #define LO_B(x) ((x) & 0xff)
16995 \newline 
16996
16997 \newline 
16998 unsigned char foo(void)
16999 \newline 
17000 {
17001 \newline 
17002 \SpecialChar ~
17003 \SpecialChar ~
17004 \SpecialChar ~
17005 unsigned char c=0xfe-LO_B(3);
17006 \newline 
17007
17008 \newline 
17009 \SpecialChar ~
17010 \SpecialChar ~
17011 \SpecialChar ~
17012 return c;
17013 \newline 
17014 }
17015 \newline 
17016
17017 \layout Itemize
17018
17019
17020 \series bold 
17021 preproc_asm
17022 \series default 
17023
17024 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17025
17026 \end_inset 
17027
17028  (+ | -) - switch _asm _endasm block preprocessing on / off.
17029  Default is on.
17030  You use this prama to define multilines of assembly code.
17031  This will prevent the preprocessor from changing the formating required
17032  by assembly code.
17033  Below is an example on how to use this pragma.
17034 \layout Verse
17035
17036
17037 \family typewriter 
17038 #pragma preproc_asm -
17039 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17040
17041 \end_inset 
17042
17043
17044 \newline 
17045 #define MYDELAY _asm
17046 \newline 
17047 \SpecialChar ~
17048 \SpecialChar ~
17049 \SpecialChar ~
17050 nop ;my assembly comment...
17051 \newline 
17052 \SpecialChar ~
17053 \SpecialChar ~
17054 \SpecialChar ~
17055 nop
17056 \newline 
17057 \SpecialChar ~
17058 \SpecialChar ~
17059 \SpecialChar ~
17060 nop
17061 \newline 
17062 _endasm
17063 \newline 
17064 #pragma preproc_asm +
17065 \newline 
17066
17067 \newline 
17068 void foo (void) 
17069 \newline 
17070
17071 \newline 
17072 \SpecialChar ~
17073 \SpecialChar ~
17074 \SpecialChar ~
17075  ...
17076  
17077 \newline 
17078 \SpecialChar ~
17079 \SpecialChar ~
17080 \SpecialChar ~
17081  MYDELAY;
17082 \newline 
17083 \SpecialChar ~
17084 \SpecialChar ~
17085 \SpecialChar ~
17086  ...
17087  
17088 \newline 
17089
17090 \newline 
17091
17092 \layout Itemize
17093
17094
17095 \series bold 
17096 sdcc_hash
17097 \series default 
17098
17099 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17100
17101 \end_inset 
17102
17103  (+ | -) - Allow "naked" hash in macro definition, for example:
17104 \newline 
17105
17106 \family typewriter 
17107 #define DIR_LO(x) #(x & 0xff)
17108 \family default 
17109
17110 \newline 
17111 Default is off.
17112  Below is an example on how to use this pragma.
17113 \layout Verse
17114
17115
17116 \family typewriter 
17117 #pragma preproc_asm +
17118 \newline 
17119 #pragma sdcc_hash +
17120 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17121
17122 \end_inset 
17123
17124
17125 \newline 
17126
17127 \newline 
17128 #define ROMCALL(x) 
17129 \backslash 
17130
17131 \newline 
17132 \SpecialChar ~
17133 \SpecialChar ~
17134 \SpecialChar ~
17135 mov R6_B3, #(x & 0xff) 
17136 \backslash 
17137
17138 \newline 
17139 \SpecialChar ~
17140 \SpecialChar ~
17141 \SpecialChar ~
17142 mov R7_B3, #((x >> 8) & 0xff) 
17143 \backslash 
17144
17145 \newline 
17146 \SpecialChar ~
17147 \SpecialChar ~
17148 \SpecialChar ~
17149 lcall __romcall
17150 \newline 
17151
17152 \newline 
17153 ...
17154 \newline 
17155 _asm
17156 \newline 
17157 ROMCALL(72)
17158 \newline 
17159 _endasm;
17160 \newline 
17161 ...
17162 \newline 
17163
17164 \layout Standard
17165
17166 The pragma's are intended to be used to turn-on or off certain optimizations
17167  which might cause the compiler to generate extra stack / data space to
17168  store compiler generated temporary variables.
17169  This usually happens in large functions.
17170  Pragma directives should be used as shown in the following example, they
17171  are used to control options & optimizations for a given function; pragmas
17172  should be placed before and/or after a function, placing pragma's inside
17173  a function body could have unpredictable results.
17174 \layout Verse
17175
17176
17177 \family typewriter 
17178 #pragma save
17179 \begin_inset LatexCommand \index{\#pragma save}
17180
17181 \end_inset 
17182
17183  \SpecialChar ~
17184 \SpecialChar ~
17185 \SpecialChar ~
17186 \SpecialChar ~
17187 \SpecialChar ~
17188 \SpecialChar ~
17189 \SpecialChar ~
17190 /* save the current settings */ 
17191 \newline 
17192 #pragma nogcse
17193 \begin_inset LatexCommand \index{\#pragma nogcse}
17194
17195 \end_inset 
17196
17197  \SpecialChar ~
17198 \SpecialChar ~
17199 \SpecialChar ~
17200 \SpecialChar ~
17201 \SpecialChar ~
17202 /* turnoff global subexpression elimination */ 
17203 \newline 
17204 #pragma noinduction
17205 \begin_inset LatexCommand \index{\#pragma noinduction}
17206
17207 \end_inset 
17208
17209  /* turn off induction optimizations */ 
17210 \newline 
17211 int foo () 
17212 \newline 
17213
17214 \newline 
17215 \SpecialChar ~
17216  \SpecialChar ~
17217  ...
17218  
17219 \newline 
17220 \SpecialChar ~
17221  \SpecialChar ~
17222  /* large code */ 
17223 \newline 
17224 \SpecialChar ~
17225  \SpecialChar ~
17226  ...
17227  
17228 \newline 
17229
17230 \newline 
17231 #pragma restore
17232 \begin_inset LatexCommand \index{\#pragma restore}
17233
17234 \end_inset 
17235
17236  /* turn the optimizations back on */
17237 \layout Standard
17238
17239 The compiler will generate a warning message when extra space is allocated.
17240  It is strongly recommended that the save and restore pragma's be used when
17241  changing options for a function.
17242 \newline 
17243
17244 \newline 
17245
17246 \newline 
17247
17248 \layout Section
17249
17250 Defines Created by the Compiler
17251 \layout Standard
17252
17253 The compiler creates the following #defines
17254 \begin_inset LatexCommand \index{\#defines}
17255
17256 \end_inset 
17257
17258
17259 \begin_inset LatexCommand \index{Defines created by the compiler}
17260
17261 \end_inset 
17262
17263 :
17264 \newline 
17265
17266 \layout Standard
17267
17268
17269 \begin_inset  Tabular
17270 <lyxtabular version="3" rows="11" columns="2">
17271 <features>
17272 <column alignment="left" valignment="top" leftline="true" width="3in">
17273 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17274 <row topline="true" bottomline="true">
17275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17276 \begin_inset Text
17277
17278 \layout Standard
17279
17280
17281 \series bold 
17282 #define
17283 \end_inset 
17284 </cell>
17285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17286 \begin_inset Text
17287
17288 \layout Standard
17289
17290
17291 \series bold 
17292 Description
17293 \end_inset 
17294 </cell>
17295 </row>
17296 <row topline="true">
17297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17298 \begin_inset Text
17299
17300 \layout Standard
17301
17302 SDCC
17303 \begin_inset LatexCommand \index{SDCC}
17304
17305 \end_inset 
17306
17307  
17308 \end_inset 
17309 </cell>
17310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17311 \begin_inset Text
17312
17313 \layout Standard
17314
17315 Always defined.
17316  Since version 2.5.6 the version number as an int (ex.
17317  256)
17318 \end_inset 
17319 </cell>
17320 </row>
17321 <row topline="true">
17322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17323 \begin_inset Text
17324
17325 \layout Standard
17326
17327 SDCC_mcs51
17328 \begin_inset LatexCommand \index{SDCC\_mcs51}
17329
17330 \end_inset 
17331
17332  or SDCC_ds390
17333 \begin_inset LatexCommand \index{SDCC\_ds390}
17334
17335 \end_inset 
17336
17337  or SDCC_z80
17338 \begin_inset LatexCommand \index{SDCC\_z80}
17339
17340 \end_inset 
17341
17342 , etc.
17343 \end_inset 
17344 </cell>
17345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17346 \begin_inset Text
17347
17348 \layout Standard
17349
17350 depending on the model used (e.g.: -mds390)
17351 \end_inset 
17352 </cell>
17353 </row>
17354 <row topline="true">
17355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17356 \begin_inset Text
17357
17358 \layout Standard
17359
17360 __mcs51
17361 \begin_inset LatexCommand \index{\_\_mcs51}
17362
17363 \end_inset 
17364
17365 , __ds390
17366 \begin_inset LatexCommand \index{\_\_ds390}
17367
17368 \end_inset 
17369
17370 , __hc08
17371 \begin_inset LatexCommand \index{\_\_hc08}
17372
17373 \end_inset 
17374
17375 , __z80
17376 \begin_inset LatexCommand \index{\_\_z80}
17377
17378 \end_inset 
17379
17380 , etc
17381 \end_inset 
17382 </cell>
17383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17384 \begin_inset Text
17385
17386 \layout Standard
17387
17388 depending on the model used (e.g.
17389  -mz80)
17390 \end_inset 
17391 </cell>
17392 </row>
17393 <row topline="true">
17394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17395 \begin_inset Text
17396
17397 \layout Standard
17398
17399 SDCC_STACK_AUTO
17400 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17401
17402 \end_inset 
17403
17404
17405 \end_inset 
17406 </cell>
17407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17408 \begin_inset Text
17409
17410 \layout Standard
17411
17412 when 
17413 \emph on 
17414 -
17415 \begin_inset ERT
17416 status Collapsed
17417
17418 \layout Standard
17419
17420 \backslash 
17421 /
17422 \end_inset 
17423
17424 -stack-auto
17425 \emph default 
17426  option is used
17427 \end_inset 
17428 </cell>
17429 </row>
17430 <row topline="true">
17431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17432 \begin_inset Text
17433
17434 \layout Standard
17435
17436 SDCC_MODEL_SMALL
17437 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17438
17439 \end_inset 
17440
17441
17442 \end_inset 
17443 </cell>
17444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17445 \begin_inset Text
17446
17447 \layout Standard
17448
17449 when 
17450 \emph on 
17451 -
17452 \begin_inset ERT
17453 status Collapsed
17454
17455 \layout Standard
17456
17457 \backslash 
17458 /
17459 \end_inset 
17460
17461 -model-small
17462 \emph default 
17463  is used
17464 \end_inset 
17465 </cell>
17466 </row>
17467 <row topline="true">
17468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17469 \begin_inset Text
17470
17471 \layout Standard
17472
17473 SDCC_MODEL_MEDIUM
17474 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17475
17476 \end_inset 
17477
17478
17479 \end_inset 
17480 </cell>
17481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17482 \begin_inset Text
17483
17484 \layout Standard
17485
17486 when 
17487 \emph on 
17488 -
17489 \begin_inset ERT
17490 status Collapsed
17491
17492 \layout Standard
17493
17494 \backslash 
17495 /
17496 \end_inset 
17497
17498 -model-medium
17499 \emph default 
17500  is used
17501 \end_inset 
17502 </cell>
17503 </row>
17504 <row topline="true">
17505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17506 \begin_inset Text
17507
17508 \layout Standard
17509
17510 SDCC_MODEL_LARGE
17511 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17512
17513 \end_inset 
17514
17515
17516 \end_inset 
17517 </cell>
17518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17519 \begin_inset Text
17520
17521 \layout Standard
17522
17523 when 
17524 \emph on 
17525 -
17526 \begin_inset ERT
17527 status Collapsed
17528
17529 \layout Standard
17530
17531 \backslash 
17532 /
17533 \end_inset 
17534
17535 -model-large
17536 \emph default 
17537  is used
17538 \end_inset 
17539 </cell>
17540 </row>
17541 <row topline="true">
17542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17543 \begin_inset Text
17544
17545 \layout Standard
17546
17547 SDCC_USE_XSTACK
17548 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17549
17550 \end_inset 
17551
17552
17553 \end_inset 
17554 </cell>
17555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17556 \begin_inset Text
17557
17558 \layout Standard
17559
17560 when 
17561 \emph on 
17562 -
17563 \begin_inset ERT
17564 status Collapsed
17565
17566 \layout Standard
17567
17568 \backslash 
17569 /
17570 \end_inset 
17571
17572 -xstack
17573 \emph default 
17574  option is used
17575 \end_inset 
17576 </cell>
17577 </row>
17578 <row topline="true">
17579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17580 \begin_inset Text
17581
17582 \layout Standard
17583
17584 SDCC_STACK_TENBIT
17585 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17586
17587 \end_inset 
17588
17589  
17590 \end_inset 
17591 </cell>
17592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17593 \begin_inset Text
17594
17595 \layout Standard
17596
17597 when 
17598 \emph on 
17599 -mds390
17600 \emph default 
17601  is used
17602 \end_inset 
17603 </cell>
17604 </row>
17605 <row topline="true" bottomline="true">
17606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17607 \begin_inset Text
17608
17609 \layout Standard
17610
17611 SDCC_MODEL_FLAT24
17612 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17613
17614 \end_inset 
17615
17616
17617 \end_inset 
17618 </cell>
17619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17620 \begin_inset Text
17621
17622 \layout Standard
17623
17624 when 
17625 \emph on 
17626 -mds390
17627 \emph default 
17628  is used
17629 \end_inset 
17630 </cell>
17631 </row>
17632 </lyxtabular>
17633
17634 \end_inset 
17635
17636
17637 \layout Chapter
17638
17639 Notes on supported Processors
17640 \layout Section
17641
17642 MCS51 variants
17643 \begin_inset LatexCommand \label{sub:MCS51-variants}
17644
17645 \end_inset 
17646
17647
17648 \begin_inset LatexCommand \index{MCS51 variants}
17649
17650 \end_inset 
17651
17652
17653 \layout Standard
17654
17655 MCS51 processors are available from many vendors and come in many different
17656  flavours.
17657  While they might differ considerably in respect to Special Function Registers
17658  the core MCS51 is usually not modified or is kept compatible.
17659  
17660 \layout Subsection
17661
17662 pdata access by SFR 
17663 \layout Standard
17664
17665 With the upcome of devices with internal xdata and flash memory devices
17666  using port P2
17667 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17668
17669 \end_inset 
17670
17671  as dedicated I/O port is becoming more popular.
17672  Switching the high byte for pdata
17673 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17674
17675 \end_inset 
17676
17677  access which was formerly done by port P2 is then achieved by a Special
17678  Function Register
17679 \begin_inset LatexCommand \index{sfr}
17680
17681 \end_inset 
17682
17683 .
17684  In well-established MCS51 tradition the address of this 
17685 \emph on 
17686 sfr
17687 \emph default 
17688  is where the chip designers decided to put it.
17689  Needless to say that they didn't agree on a common name either.
17690  So that the startup code can correctly initialize xdata variables, you
17691  should define an sfr with the name _XPAGE
17692 \family typewriter 
17693
17694 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17695
17696 \end_inset 
17697
17698
17699 \family default 
17700  at the appropriate location if the default, port P2, is not used for this.
17701  Some examples are:
17702 \layout Verse
17703
17704
17705 \family typewriter 
17706 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17707 \layout Verse
17708
17709
17710 \family typewriter 
17711 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17712 \layout Verse
17713
17714
17715 \family typewriter 
17716 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17717 \layout Standard
17718
17719 For more exotic implementations further customizations may be needed.
17720  See section 
17721 \begin_inset LatexCommand \ref{sub:Startup-Code}
17722
17723 \end_inset 
17724
17725  for other possibilities.
17726 \layout Subsection
17727
17728 Other Features available by SFR
17729 \layout Standard
17730 \added_space_bottom bigskip 
17731 Some MCS51 variants offer features like Double DPTR
17732 \begin_inset LatexCommand \index{DPTR}
17733
17734 \end_inset 
17735
17736 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17737  These are currently not used for the MCS51 port.
17738  If you absolutely need them you can fall back to inline assembly or submit
17739  a patch to SDCC.
17740 \layout Section
17741
17742 DS400 port
17743 \layout Standard
17744 \added_space_bottom bigskip 
17745 The DS80C400
17746 \begin_inset LatexCommand \index{DS80C400}
17747
17748 \end_inset 
17749
17750
17751 \begin_inset LatexCommand \index{DS400}
17752
17753 \end_inset 
17754
17755  microcontroller has a rich set of peripherals.
17756  In its built-in ROM library it includes functions to access some of the
17757  features, among them is a TCP stack with IP4 and IP6 support.
17758  Library headers (currently in beta status) and other files are provided
17759  at 
17760 \size footnotesize 
17761
17762 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17763
17764 \end_inset 
17765
17766 .
17767  
17768 \layout Section
17769
17770 The Z80 and gbz80 port
17771 \layout Standard
17772
17773 SDCC can target both the Zilog Z80
17774 \begin_inset LatexCommand \index{Z80}
17775
17776 \end_inset 
17777
17778  and the Nintendo Gameboy's Z80-like gbz80
17779 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17780
17781 \end_inset 
17782
17783 .
17784  The Z80 port is passed through the same 
17785 \emph on 
17786 regressions tests
17787 \begin_inset LatexCommand \index{Regression test}
17788
17789 \end_inset 
17790
17791
17792 \emph default 
17793  (see section 
17794 \begin_inset LatexCommand \ref{sec:Quality-control}
17795
17796 \end_inset 
17797
17798 ) as the MCS51 and DS390 ports, so floating point support, support for long
17799  variables and bitfield support is fine.
17800  See mailing lists and forums about interrupt routines.
17801 \layout Standard
17802 \added_space_bottom bigskip 
17803 As always, the code is the authoritative reference - see z80/ralloc.c and
17804  z80/gen.c.
17805  The stack
17806 \begin_inset LatexCommand \index{Z80!stack}
17807
17808 \end_inset 
17809
17810  frame is similar to that generated by the IAR Z80 compiler.
17811  IX is used as the base pointer, HL and IY are used as a temporary registers,
17812  and BC and DE are available for holding variables.
17813  Return values
17814 \begin_inset LatexCommand \index{Z80!return value}
17815
17816 \end_inset 
17817
17818  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17819  bytes).
17820  The gbz80 port use the same set of registers for the return values, but
17821  in a different order of significance: E (one byte), DE (two bytes), or
17822  HLDE (four bytes).
17823 \layout Section
17824
17825 The HC08 port
17826 \layout Standard
17827
17828 The port to the Freescale/Motorola HC08
17829 \begin_inset LatexCommand \index{HC08}
17830
17831 \end_inset 
17832
17833  family has been added in October 2003, and is still undergoing some basic
17834  development.
17835  The code generator is complete, but the register allocation is still quite
17836  unoptimized.
17837  Some of the SDCC's standard C library functions have embedded non-HC08
17838  inline assembly and so are not yet usable.
17839 \layout Standard
17840 \added_space_bottom bigskip 
17841 The HC08 port passes the regression test suite (see section 
17842 \begin_inset LatexCommand \ref{sec:Quality-control}
17843
17844 \end_inset 
17845
17846 ).
17847 \layout Section
17848 \pagebreak_top 
17849 The PIC14 port
17850 \layout Standard
17851
17852 The 14bit PIC
17853 \begin_inset LatexCommand \index{PIC14}
17854
17855 \end_inset 
17856
17857  port still requires a major effort from the development community.
17858  However it can work for simple code.
17859  It passes its (smaller set of) regression tests
17860 \begin_inset LatexCommand \index{Regression test (PIC14)}
17861
17862 \end_inset 
17863
17864  in the directory 
17865 \shape italic 
17866 sdcc/src/regression
17867 \shape default 
17868 .
17869 \layout Subsection
17870
17871 C code and 14bit PIC code page
17872 \begin_inset LatexCommand \index{code page (pic14)}
17873
17874 \end_inset 
17875
17876  and RAM banks
17877 \begin_inset LatexCommand \index{RAM bank (pic14)}
17878
17879 \end_inset 
17880
17881
17882 \layout Standard
17883
17884 The linker organizes allocation for the code page and RAM banks.
17885  It does not have intimate knowledge of the code flow.
17886  It will put all the code section of a single asm file into a single code
17887  page.
17888  In order to make use of multiple code pages, separate asm files must be
17889  used.
17890  The compiler treats all functions of a single C file as being in the same
17891  code page unless it is non static.
17892 \newline 
17893
17894 \newline 
17895 To get the best follow these guide lines:
17896 \layout Enumerate
17897
17898 Make local functions static, as non static functions require code page selection
17899  overhead.
17900 \layout Enumerate
17901
17902 For devices that have multiple code pages it is more efficient to use the
17903  same number of files as pages, i.e.
17904  for the 16F877 use 4 separate files and i.e.
17905  for the 16F874 use 2 separate files.
17906  This way the linker can put the code for each file into different code
17907  pages and there's less page selection overhead.
17908 \layout Enumerate
17909
17910  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17911  instruction set), use 'unsigned char' whereever possible instead of 'int'.
17912 \layout Subsection
17913
17914 Creating a device include file 
17915 \layout Standard
17916
17917 For generating a device include file
17918 \begin_inset LatexCommand \index{PIC14!Header files}
17919
17920 \end_inset 
17921
17922  use the support perl script inc2h.pl kept in directory support/script.
17923 \layout Subsection
17924
17925 Interrupt code
17926 \layout Standard
17927
17928 For the interrupt function, use the keyword '__interrupt'
17929 \begin_inset LatexCommand \index{PIC14!interrupt}
17930
17931 \end_inset 
17932
17933  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17934  there to avoid a syntax error - it ought to be fixed).
17935  E.g.:
17936 \layout Verse
17937
17938
17939 \family typewriter 
17940 void Intr(void) __interrupt 0
17941 \newline 
17942 {
17943 \newline 
17944 \SpecialChar ~
17945 \SpecialChar ~
17946 T0IF = 0; /* Clear timer interrupt */
17947 \newline 
17948 }
17949 \layout Subsection
17950
17951 Linking and assembling
17952 \layout Standard
17953
17954 For assembling you can use either GPUTILS'
17955 \begin_inset LatexCommand \index{gputils (pic tools)}
17956
17957 \end_inset 
17958
17959  gpasm.exe or MPLAB's mpasmwin.exe.
17960  GPUTILS is available from 
17961 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17962
17963 \end_inset 
17964
17965 .
17966  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17967  If you use MPLAB and an interrupt function then the linker script file
17968  vectors section will need to be enlarged to link with mplink.
17969 \newline 
17970
17971 \newline 
17972 Here is a 
17973 \family typewriter 
17974 Makefile
17975 \family default 
17976  using GPUTILS:
17977 \layout Verse
17978
17979
17980 \family typewriter 
17981 .c.o:
17982 \newline 
17983 \SpecialChar ~
17984 \SpecialChar ~
17985 \SpecialChar ~
17986 \SpecialChar ~
17987 \SpecialChar ~
17988 \SpecialChar ~
17989 \SpecialChar ~
17990 \SpecialChar ~
17991 sdcc -S -V -mpic14 -p16F877 $< 
17992 \newline 
17993 \SpecialChar ~
17994 \SpecialChar ~
17995 \SpecialChar ~
17996 \SpecialChar ~
17997 \SpecialChar ~
17998 \SpecialChar ~
17999 \SpecialChar ~
18000 \SpecialChar ~
18001 gpasm -c $*.asm
18002 \newline 
18003
18004 \newline 
18005 $(PRJ).hex: $(OBJS) 
18006 \newline 
18007 \SpecialChar ~
18008 \SpecialChar ~
18009 \SpecialChar ~
18010 \SpecialChar ~
18011 \SpecialChar ~
18012 \SpecialChar ~
18013 \SpecialChar ~
18014 \SpecialChar ~
18015 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
18016 \layout Standard
18017
18018 Here is a 
18019 \family typewriter 
18020 Makefile
18021 \family default 
18022  using MPLAB:
18023 \layout Verse
18024
18025
18026 \family typewriter 
18027 .c.o: 
18028 \newline 
18029 \SpecialChar ~
18030 \SpecialChar ~
18031 \SpecialChar ~
18032 \SpecialChar ~
18033 \SpecialChar ~
18034 \SpecialChar ~
18035 \SpecialChar ~
18036 \SpecialChar ~
18037 sdcc -S -V -mpic14 -p16F877 $< 
18038 \newline 
18039 \SpecialChar ~
18040 \SpecialChar ~
18041 \SpecialChar ~
18042 \SpecialChar ~
18043 \SpecialChar ~
18044 \SpecialChar ~
18045 \SpecialChar ~
18046 \SpecialChar ~
18047 mpasmwin /q /o $*.asm
18048 \newline 
18049
18050 \newline 
18051 $(PRJ).hex: $(OBJS) 
18052 \newline 
18053 \SpecialChar ~
18054 \SpecialChar ~
18055 \SpecialChar ~
18056 \SpecialChar ~
18057 \SpecialChar ~
18058 \SpecialChar ~
18059 \SpecialChar ~
18060 \SpecialChar ~
18061 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
18062 \layout Standard
18063
18064 Please note that indentations within a
18065 \family typewriter 
18066  Makefile
18067 \family default 
18068  have to be done with a tabulator character.
18069 \layout Subsection
18070
18071 Command-line options
18072 \layout Standard
18073
18074 Besides the switches common to all SDCC backends, the PIC14 port accepts
18075  the following options (for an updated list see sdcc -
18076 \begin_inset ERT
18077 status Collapsed
18078
18079 \layout Standard
18080
18081 \backslash 
18082 /
18083 \end_inset 
18084
18085 -help):
18086 \layout List
18087 \labelwidthstring 00.00.0000
18088
18089 -
18090 \begin_inset ERT
18091 status Collapsed
18092
18093 \layout Standard
18094
18095 \backslash 
18096 /
18097 \end_inset 
18098
18099 -debug-extra
18100 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
18101
18102 \end_inset 
18103
18104  emit debug info in assembly output
18105 \layout List
18106 \labelwidthstring 00.00.0000
18107
18108 -
18109 \begin_inset ERT
18110 status Collapsed
18111
18112 \layout Standard
18113
18114 \backslash 
18115 /
18116 \end_inset 
18117
18118 -no-pcode-opt
18119 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
18120
18121 \end_inset 
18122
18123  disable (slightly faulty) optimization on pCode
18124 \layout List
18125 \labelwidthstring 00.00.0000
18126
18127 -
18128 \begin_inset ERT
18129 status Collapsed
18130
18131 \layout Standard
18132
18133 \backslash 
18134 /
18135 \end_inset 
18136
18137 -stack-loc
18138 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
18139
18140 \end_inset 
18141
18142  sets the lowest address of the argument passing stack (defaults to a suitably
18143  large shared databank to reduce BANKSEL overhead)
18144 \layout List
18145 \labelwidthstring 00.00.0000
18146
18147 -
18148 \begin_inset ERT
18149 status Collapsed
18150
18151 \layout Standard
18152
18153 \backslash 
18154 /
18155 \end_inset 
18156
18157 -stack-size
18158 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
18159
18160 \end_inset 
18161
18162  sets the size if the argument passing stack (default: 16, minimum: 4)
18163 \layout Subsection
18164
18165 The library
18166 \layout Subsubsection
18167
18168 error: missing definition for symbol 
18169 \begin_inset Quotes sld
18170 \end_inset 
18171
18172 __gptrget1
18173 \begin_inset Quotes srd
18174 \end_inset 
18175
18176
18177 \layout Standard
18178
18179 The PIC14 port uses library routines to provide more complex operations
18180  like multiplication, division/modulus and (generic) pointer dereferencing.
18181  In order to add these routines to your project, you must link with PIC14's
18182  
18183 \family typewriter 
18184 libsdcc.lib
18185 \family default 
18186 .
18187  For single source file projects this is done automatically, more complex
18188  projects must add 
18189 \family typewriter 
18190 libsdcc.lib
18191 \family default 
18192  to the linker's arguments.
18193  Make sure you also add an include path for the library (using the -I switch
18194  to the linker)!
18195 \layout Subsubsection
18196
18197 Processor mismatch in file 
18198 \begin_inset Quotes sld
18199 \end_inset 
18200
18201 XXX
18202 \begin_inset Quotes srd
18203 \end_inset 
18204
18205 .
18206 \layout Standard
18207
18208 This warning can usually be ignored due to the very good compatibility amongst
18209  14 bit PIC
18210 \begin_inset LatexCommand \index{PIC14}
18211
18212 \end_inset 
18213
18214  devices.
18215 \layout Standard
18216
18217 You might also consider recompiling the library for your specific device
18218  by changing the ARCH=p16f877 (default target) entry in 
18219 \family typewriter 
18220 device/lib/pic/Makefile.in
18221 \family default 
18222  and 
18223 \family typewriter 
18224 device/lib/pic/Makefile
18225 \family default 
18226  to reflect your device.
18227  This might even improve performance for smaller devices as unneccesary
18228  BANKSELs migth be removed.
18229 \layout Subsection
18230
18231 Known bugs
18232 \layout Subsubsection
18233
18234 initialized data
18235 \layout Standard
18236
18237 Currently, data can only be initialized if it resides in the source file
18238  together with 
18239 \emph on 
18240 main()
18241 \emph default 
18242 .
18243  Data in other source files will silently 
18244 \series bold 
18245 not
18246 \series default 
18247  be initialized.
18248 \family typewriter 
18249 \size footnotesize 
18250
18251 \begin_inset Marginal
18252 collapsed true
18253
18254 \layout Standard
18255
18256
18257 \series bold 
18258 \SpecialChar ~
18259 !
18260 \end_inset 
18261
18262
18263 \layout Section
18264 \pagebreak_top 
18265 The PIC16
18266 \begin_inset LatexCommand \index{PIC16}
18267
18268 \end_inset 
18269
18270  port
18271 \layout Standard
18272
18273 The PIC16
18274 \begin_inset LatexCommand \index{PIC16}
18275
18276 \end_inset 
18277
18278  port is the portion of SDCC that is responsible to produce code for the
18279  Microchip
18280 \begin_inset LatexCommand \index{Microchip}
18281
18282 \end_inset 
18283
18284 (TM) microcontrollers with 16 bit core.
18285  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18286  Currently supported devices are:
18287 \layout Standard
18288 \align center 
18289
18290 \begin_inset  Tabular
18291 <lyxtabular version="3" rows="4" columns="6">
18292 <features>
18293 <column alignment="center" valignment="top" leftline="true" width="0">
18294 <column alignment="center" valignment="top" leftline="true" width="0">
18295 <column alignment="center" valignment="top" leftline="true" width="0">
18296 <column alignment="center" valignment="top" leftline="true" width="0">
18297 <column alignment="center" valignment="top" leftline="true" width="0">
18298 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18299 <row topline="true">
18300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18301 \begin_inset Text
18302
18303 \layout Standard
18304
18305 18F242
18306 \end_inset 
18307 </cell>
18308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18309 \begin_inset Text
18310
18311 \layout Standard
18312
18313 18F248
18314 \end_inset 
18315 </cell>
18316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18317 \begin_inset Text
18318
18319 \layout Standard
18320
18321 18F252
18322 \end_inset 
18323 </cell>
18324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18325 \begin_inset Text
18326
18327 \layout Standard
18328
18329 18F258
18330 \end_inset 
18331 </cell>
18332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18333 \begin_inset Text
18334
18335 \layout Standard
18336
18337 18F442
18338 \end_inset 
18339 </cell>
18340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18341 \begin_inset Text
18342
18343 \layout Standard
18344
18345 18F448
18346 \end_inset 
18347 </cell>
18348 </row>
18349 <row topline="true">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18351 \begin_inset Text
18352
18353 \layout Standard
18354
18355 18F452
18356 \end_inset 
18357 </cell>
18358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18359 \begin_inset Text
18360
18361 \layout Standard
18362
18363 18F458
18364 \end_inset 
18365 </cell>
18366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18367 \begin_inset Text
18368
18369 \layout Standard
18370
18371 18F1220
18372 \end_inset 
18373 </cell>
18374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18375 \begin_inset Text
18376
18377 \layout Standard
18378
18379 18F2220
18380 \end_inset 
18381 </cell>
18382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18383 \begin_inset Text
18384
18385 \layout Standard
18386
18387 18F2550
18388 \end_inset 
18389 </cell>
18390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18391 \begin_inset Text
18392
18393 \layout Standard
18394
18395 18F4331
18396 \end_inset 
18397 </cell>
18398 </row>
18399 <row topline="true">
18400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18401 \begin_inset Text
18402
18403 \layout Standard
18404
18405 18F4455
18406 \end_inset 
18407 </cell>
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18409 \begin_inset Text
18410
18411 \layout Standard
18412
18413 18F6520
18414 \end_inset 
18415 </cell>
18416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18417 \begin_inset Text
18418
18419 \layout Standard
18420
18421 18F6620
18422 \end_inset 
18423 </cell>
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18425 \begin_inset Text
18426
18427 \layout Standard
18428
18429 18F6680
18430 \end_inset 
18431 </cell>
18432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18433 \begin_inset Text
18434
18435 \layout Standard
18436
18437 18F6720
18438 \end_inset 
18439 </cell>
18440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18441 \begin_inset Text
18442
18443 \layout Standard
18444
18445 18F8520
18446 \end_inset 
18447 </cell>
18448 </row>
18449 <row topline="true" bottomline="true">
18450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18451 \begin_inset Text
18452
18453 \layout Standard
18454
18455 18F8620
18456 \end_inset 
18457 </cell>
18458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18459 \begin_inset Text
18460
18461 \layout Standard
18462
18463 18F8680
18464 \end_inset 
18465 </cell>
18466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18467 \begin_inset Text
18468
18469 \layout Standard
18470
18471 18F8720
18472 \end_inset 
18473 </cell>
18474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18475 \begin_inset Text
18476
18477 \layout Standard
18478
18479 \end_inset 
18480 </cell>
18481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18482 \begin_inset Text
18483
18484 \layout Standard
18485
18486 \end_inset 
18487 </cell>
18488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18489 \begin_inset Text
18490
18491 \layout Standard
18492
18493 \end_inset 
18494 </cell>
18495 </row>
18496 </lyxtabular>
18497
18498 \end_inset 
18499
18500
18501 \layout Subsection
18502
18503 Global Options
18504 \layout Standard
18505
18506 PIC16 port supports the standard command line arguments as supposed, with
18507  the exception of certain cases that will be mentioned in the following
18508  list:
18509 \layout List
18510 \labelwidthstring 00.00.0000
18511
18512 -
18513 \begin_inset ERT
18514 status Collapsed
18515
18516 \layout Standard
18517
18518 \backslash 
18519 /
18520 \end_inset 
18521
18522 -callee-saves
18523 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18524
18525 \end_inset 
18526
18527  See -
18528 \begin_inset ERT
18529 status Collapsed
18530
18531 \layout Standard
18532
18533 \backslash 
18534 /
18535 \end_inset 
18536
18537 -all-callee-saves
18538 \layout List
18539 \labelwidthstring 00.00.0000
18540
18541 -
18542 \begin_inset ERT
18543 status Collapsed
18544
18545 \layout Standard
18546
18547 \backslash 
18548 /
18549 \end_inset 
18550
18551 -all-callee-saves
18552 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18553
18554 \end_inset 
18555
18556  All function arguments are passed on stack by default.
18557  
18558 \emph on 
18559 There is no need to specify this in the command line.
18560 \layout List
18561 \labelwidthstring 00.00.0000
18562
18563 -
18564 \begin_inset ERT
18565 status Collapsed
18566
18567 \layout Standard
18568
18569 \backslash 
18570 /
18571 \end_inset 
18572
18573 -fommit-frame-pointer
18574 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18575
18576 \end_inset 
18577
18578  Frame pointer will be omitted when the function uses no local variables.
18579 \layout Subsection
18580
18581 Port Specific Options
18582 \begin_inset LatexCommand \index{Options PIC16}
18583
18584 \end_inset 
18585
18586
18587 \layout Standard
18588
18589 The port specific options appear after the global options in the sdcc --help
18590  output.
18591 \layout Subsubsection
18592
18593 General Options
18594 \layout Standard
18595
18596 General options enable certain port features and optimizations.
18597 \layout List
18598 \labelwidthstring 00.00.0000
18599
18600 -
18601 \begin_inset ERT
18602 status Collapsed
18603
18604 \layout Standard
18605
18606 \backslash 
18607 /
18608 \end_inset 
18609
18610 -pstack-model=[model] Used in conjuction with the command above.
18611  Defines the stack model to be used, valid stack models are : 
18612 \begin_deeper 
18613 \layout List
18614 \labelwidthstring 00.00.0000
18615
18616
18617 \emph on 
18618 small
18619 \emph default 
18620  Selects small stack model.
18621  8 bit stack and frame pointers.
18622  Supports 256 bytes stack size.
18623 \layout List
18624 \labelwidthstring 00.00.0000
18625
18626
18627 \emph on 
18628 large
18629 \emph default 
18630  Selects large stack model.
18631  16 bit stack and frame pointers.
18632  Supports 65536 bytes stack size.
18633 \end_deeper 
18634 \layout List
18635 \labelwidthstring 00.00.0000
18636
18637 -
18638 \begin_inset ERT
18639 status Collapsed
18640
18641 \layout Standard
18642
18643 \backslash 
18644 /
18645 \end_inset 
18646
18647 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18648  unitialized data variables with [kword].
18649  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18650 \layout List
18651 \labelwidthstring 00.00.0000
18652
18653 -
18654 \begin_inset ERT
18655 status Collapsed
18656
18657 \layout Standard
18658
18659 \backslash 
18660 /
18661 \end_inset 
18662
18663 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18664  Useful for bootloaders.
18665 \layout List
18666 \labelwidthstring 00.00.0000
18667
18668 -
18669 \begin_inset ERT
18670 status Collapsed
18671
18672 \layout Standard
18673
18674 \backslash 
18675 /
18676 \end_inset 
18677
18678 -asm= sets the full path and name of an external assembler to call.
18679 \layout List
18680 \labelwidthstring 00.00.0000
18681
18682 -
18683 \begin_inset ERT
18684 status Collapsed
18685
18686 \layout Standard
18687
18688 \backslash 
18689 /
18690 \end_inset 
18691
18692 -link= sets the full path and name of an external linker to call.
18693 \layout List
18694 \labelwidthstring 00.00.0000
18695
18696 -
18697 \begin_inset ERT
18698 status Collapsed
18699
18700 \layout Standard
18701
18702 \backslash 
18703 /
18704 \end_inset 
18705
18706 -mplab-comp MPLAB
18707 \begin_inset LatexCommand \index{PIC16!MPLAB}
18708
18709 \end_inset 
18710
18711  compatibility option.
18712  Currently only suppresses special gpasm directives.
18713 \layout Subsubsection
18714
18715 Optimization Options
18716 \layout List
18717 \labelwidthstring 00.00.0000
18718
18719 -
18720 \begin_inset ERT
18721 status Collapsed
18722
18723 \layout Standard
18724
18725 \backslash 
18726 /
18727 \end_inset 
18728
18729 -optimize-goto Try to use (conditional) BRA instead of GOTO
18730 \layout List
18731 \labelwidthstring 00.00.0000
18732
18733 -
18734 \begin_inset ERT
18735 status Collapsed
18736
18737 \layout Standard
18738
18739 \backslash 
18740 /
18741 \end_inset 
18742
18743 -optimize-cmp Try to optimize some compares.
18744 \layout List
18745 \labelwidthstring 00.00.0000
18746
18747 -
18748 \begin_inset ERT
18749 status Collapsed
18750
18751 \layout Standard
18752
18753 \backslash 
18754 /
18755 \end_inset 
18756
18757 -optimize-df Analyze the dataflow of the generated code and improve it.
18758 \layout List
18759 \labelwidthstring 00.00.0000
18760
18761 -
18762 \begin_inset ERT
18763 status Collapsed
18764
18765 \layout Standard
18766
18767 \backslash 
18768 /
18769 \end_inset 
18770
18771 -obanksel=nn Set optimization level for inserting BANKSELs.
18772 \newline 
18773
18774 \begin_deeper 
18775 \layout List
18776 \labelwidthstring 00.00.0000
18777
18778 0 no optimization
18779 \layout List
18780 \labelwidthstring 00.00.0000
18781
18782 1 checks previous used register and if it is the same then does not emit
18783  BANKSEL, accounts only for labels.
18784 \layout List
18785 \labelwidthstring 00.00.0000
18786
18787 2 tries to check the location of (even different) symbols and removes BANKSELs
18788  if they are in the same bank.
18789  
18790 \newline 
18791
18792 \emph on 
18793 Important: There might be problems if the linker script has data sections
18794  across bank borders!
18795 \end_deeper 
18796 \layout Subsubsection
18797
18798 Linking Options
18799 \layout List
18800 \labelwidthstring 00.00.0000
18801
18802 -
18803 \begin_inset ERT
18804 status Collapsed
18805
18806 \layout Standard
18807
18808 \backslash 
18809 /
18810 \end_inset 
18811
18812 -nodefaultlibs do not link default libraries when linking
18813 \layout List
18814 \labelwidthstring 00.00.0000
18815
18816 -
18817 \begin_inset ERT
18818 status Collapsed
18819
18820 \layout Standard
18821
18822 \backslash 
18823 /
18824 \end_inset 
18825
18826 -no-crt Don't link the default run-time modules
18827 \layout List
18828 \labelwidthstring 00.00.0000
18829
18830 -
18831 \begin_inset ERT
18832 status Collapsed
18833
18834 \layout Standard
18835
18836 \backslash 
18837 /
18838 \end_inset 
18839
18840 -use-crt= Use a custom run-time module instead of the defaults.
18841 \layout Subsubsection
18842
18843 Debugging Options
18844 \layout Standard
18845
18846 Debugging options enable extra debugging information in the output files.
18847 \layout List
18848 \labelwidthstring 00.00.0000
18849
18850 -
18851 \begin_inset ERT
18852 status Collapsed
18853
18854 \layout Standard
18855
18856 \backslash 
18857 /
18858 \end_inset 
18859
18860 -debug-xtra Similar to -
18861 \begin_inset ERT
18862 status Collapsed
18863
18864 \layout Standard
18865
18866 \backslash 
18867 /
18868 \end_inset 
18869
18870 -debug
18871 \begin_inset LatexCommand \index{-\/-debug}
18872
18873 \end_inset 
18874
18875 , but dumps more information.
18876 \layout List
18877 \labelwidthstring 00.00.0000
18878
18879 -
18880 \begin_inset ERT
18881 status Collapsed
18882
18883 \layout Standard
18884
18885 \backslash 
18886 /
18887 \end_inset 
18888
18889 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18890  information.
18891  <source> is the name of the file compiled.
18892 \layout List
18893 \labelwidthstring 00.00.0000
18894
18895 -
18896 \begin_inset ERT
18897 status Collapsed
18898
18899 \layout Standard
18900
18901 \backslash 
18902 /
18903 \end_inset 
18904
18905 -pcode-verbose Enable pcode debugging information in translation.
18906 \layout List
18907 \labelwidthstring 00.00.0000
18908
18909 -
18910 \begin_inset ERT
18911 status Collapsed
18912
18913 \layout Standard
18914
18915 \backslash 
18916 /
18917 \end_inset 
18918
18919 -denable-peeps Force the usage of peepholes.
18920  Use with care.
18921 \layout List
18922 \labelwidthstring 00.00.0000
18923
18924 -
18925 \begin_inset ERT
18926 status Collapsed
18927
18928 \layout Standard
18929
18930 \backslash 
18931 /
18932 \end_inset 
18933
18934 -gstack Trace push/pops for stack pointer overflow
18935 \layout List
18936 \labelwidthstring 00.00.0000
18937
18938 -
18939 \begin_inset ERT
18940 status Collapsed
18941
18942 \layout Standard
18943
18944 \backslash 
18945 /
18946 \end_inset 
18947
18948 -call-tree dump call tree in .calltree file
18949 \layout Subsection
18950
18951 Enviromental Variables
18952 \layout Standard
18953
18954 There is a number of enviromental variables that can be used when running
18955  SDCC to enable certain optimizations or force a specific program behaviour.
18956  these variables are primarily for debugging purposes so they can be enabled/dis
18957 abled at will.
18958 \layout Standard
18959
18960 Currently there is only two such variables available:
18961 \layout List
18962 \labelwidthstring 00.00.0000
18963
18964 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18965  bitfields is optimized by directly loading FSR0 with the address of the
18966  bitfield structure.
18967  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18968  then load FSR0.
18969  This step saves data ram and code space for functions that perform heavy
18970  use of bitfields.
18971  (ie.
18972  80 bytes of code space are saved when compiling malloc.c with this option).
18973  
18974 \layout List
18975 \labelwidthstring 00.00.0000
18976
18977 NO_REG_OPT do not perform pCode registers optimization.
18978  This should be used for debugging purposes.
18979  In some where bugs in the pcode optimizer are found, users can benefit
18980  from temporarily disabling the optimizer until the bug is fixed.
18981 \layout Subsection
18982
18983 Preprocessor Macros
18984 \layout Standard
18985
18986 PIC16
18987 \begin_inset LatexCommand \index{PIC16}
18988
18989 \end_inset 
18990
18991  port defines the following preprocessor macros while translating a source.
18992 \layout Standard
18993 \align center 
18994
18995 \begin_inset  Tabular
18996 <lyxtabular version="3" rows="6" columns="2">
18997 <features>
18998 <column alignment="center" valignment="top" leftline="true" width="0">
18999 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19000 <row topline="true" bottomline="true">
19001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19002 \begin_inset Text
19003
19004 \layout Standard
19005
19006 Macro
19007 \end_inset 
19008 </cell>
19009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19010 \begin_inset Text
19011
19012 \layout Standard
19013
19014 Description
19015 \end_inset 
19016 </cell>
19017 </row>
19018 <row topline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19020 \begin_inset Text
19021
19022 \layout Standard
19023
19024 SDCC_pic16
19025 \end_inset 
19026 </cell>
19027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19028 \begin_inset Text
19029
19030 \layout Standard
19031
19032 Port identification
19033 \end_inset 
19034 </cell>
19035 </row>
19036 <row topline="true">
19037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19038 \begin_inset Text
19039
19040 \layout Standard
19041
19042 _
19043 \begin_inset ERT
19044 status Collapsed
19045
19046 \layout Standard
19047
19048 \backslash 
19049 /
19050 \end_inset 
19051
19052 _pic16
19053 \end_inset 
19054 </cell>
19055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19056 \begin_inset Text
19057
19058 \layout Standard
19059
19060 Port identification (same as above)
19061 \end_inset 
19062 </cell>
19063 </row>
19064 <row topline="true">
19065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19066 \begin_inset Text
19067
19068 \layout Standard
19069
19070 pic18fxxxx
19071 \end_inset 
19072 </cell>
19073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19074 \begin_inset Text
19075
19076 \layout Standard
19077
19078 MCU Identification.
19079  
19080 \emph on 
19081 xxxx
19082 \emph default 
19083  is the microcontrol identification number, i.e.
19084  452, 6620, etc
19085 \end_inset 
19086 </cell>
19087 </row>
19088 <row topline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19090 \begin_inset Text
19091
19092 \layout Standard
19093
19094 _
19095 \begin_inset ERT
19096 status Collapsed
19097
19098 \layout Standard
19099
19100 \backslash 
19101 /
19102 \end_inset 
19103
19104 _18Fxxxx
19105 \end_inset 
19106 </cell>
19107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19108 \begin_inset Text
19109
19110 \layout Standard
19111
19112 MCU Identification (same as above)
19113 \end_inset 
19114 </cell>
19115 </row>
19116 <row topline="true" bottomline="true">
19117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19118 \begin_inset Text
19119
19120 \layout Standard
19121
19122 STACK_MODEL_nnn
19123 \end_inset 
19124 </cell>
19125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19126 \begin_inset Text
19127
19128 \layout Standard
19129
19130 nnn = SMALL or LARGE respectively according to the stack model used
19131 \end_inset 
19132 </cell>
19133 </row>
19134 </lyxtabular>
19135
19136 \end_inset 
19137
19138
19139 \layout Standard
19140
19141 In addition the following macros are defined when calling assembler:
19142 \layout Standard
19143 \align center 
19144
19145 \begin_inset  Tabular
19146 <lyxtabular version="3" rows="4" columns="2">
19147 <features>
19148 <column alignment="center" valignment="top" leftline="true" width="0">
19149 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19150 <row topline="true" bottomline="true">
19151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19152 \begin_inset Text
19153
19154 \layout Standard
19155
19156 Macro
19157 \end_inset 
19158 </cell>
19159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19160 \begin_inset Text
19161
19162 \layout Standard
19163
19164 Description
19165 \end_inset 
19166 </cell>
19167 </row>
19168 <row topline="true">
19169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19170 \begin_inset Text
19171
19172 \layout Standard
19173
19174 __18Fxxxx
19175 \end_inset 
19176 </cell>
19177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19178 \begin_inset Text
19179
19180 \layout Standard
19181
19182 MCU Identification.
19183  
19184 \emph on 
19185 xxxx
19186 \emph default 
19187  is the microcontrol identification number, i.e.
19188  452, 6620, etc
19189 \end_inset 
19190 </cell>
19191 </row>
19192 <row topline="true">
19193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19194 \begin_inset Text
19195
19196 \layout Standard
19197
19198 SDCC_MODEL_nnn
19199 \end_inset 
19200 </cell>
19201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19202 \begin_inset Text
19203
19204 \layout Standard
19205
19206 nnn = SMALL or LARGE respectively according to the memory model used for
19207  SDCC
19208 \end_inset 
19209 </cell>
19210 </row>
19211 <row topline="true" bottomline="true">
19212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19213 \begin_inset Text
19214
19215 \layout Standard
19216
19217 STACK_MODEL_nnn
19218 \end_inset 
19219 </cell>
19220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19221 \begin_inset Text
19222
19223 \layout Standard
19224
19225 nnn = SMALL or LARGE respectively according to the stack model used
19226 \end_inset 
19227 </cell>
19228 </row>
19229 </lyxtabular>
19230
19231 \end_inset 
19232
19233
19234 \layout Subsection
19235
19236 Directories
19237 \layout Standard
19238
19239 PIC16
19240 \begin_inset LatexCommand \index{PIC16}
19241
19242 \end_inset 
19243
19244  port uses the following directories for searching header files and libraries.
19245 \layout Standard
19246 \align center 
19247
19248 \begin_inset  Tabular
19249 <lyxtabular version="3" rows="3" columns="4">
19250 <features>
19251 <column alignment="center" valignment="top" leftline="true" width="0">
19252 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19253 <column alignment="center" valignment="top" width="0">
19254 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19255 <row topline="true" bottomline="true">
19256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19257 \begin_inset Text
19258
19259 \layout Standard
19260
19261 Directory
19262 \end_inset 
19263 </cell>
19264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19265 \begin_inset Text
19266
19267 \layout Standard
19268
19269 Description
19270 \end_inset 
19271 </cell>
19272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19273 \begin_inset Text
19274
19275 \layout Standard
19276
19277 Target
19278 \end_inset 
19279 </cell>
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19281 \begin_inset Text
19282
19283 \layout Standard
19284
19285 Command prefix
19286 \end_inset 
19287 </cell>
19288 </row>
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \layout Standard
19294
19295 PREFIX/sdcc/include/pic16
19296 \end_inset 
19297 </cell>
19298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19299 \begin_inset Text
19300
19301 \layout Standard
19302
19303 PIC16 specific headers
19304 \end_inset 
19305 </cell>
19306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19307 \begin_inset Text
19308
19309 \layout Standard
19310
19311 Compiler
19312 \end_inset 
19313 </cell>
19314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19315 \begin_inset Text
19316
19317 \layout Standard
19318
19319 -I
19320 \end_inset 
19321 </cell>
19322 </row>
19323 <row topline="true" bottomline="true">
19324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19325 \begin_inset Text
19326
19327 \layout Standard
19328
19329 PREFIX/sdcc/lib/pic16
19330 \end_inset 
19331 </cell>
19332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19333 \begin_inset Text
19334
19335 \layout Standard
19336
19337 PIC16 specific libraries
19338 \end_inset 
19339 </cell>
19340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19341 \begin_inset Text
19342
19343 \layout Standard
19344
19345 Linker
19346 \end_inset 
19347 </cell>
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19349 \begin_inset Text
19350
19351 \layout Standard
19352
19353 -L
19354 \end_inset 
19355 </cell>
19356 </row>
19357 </lyxtabular>
19358
19359 \end_inset 
19360
19361
19362 \layout Subsection
19363
19364 Pragmas
19365 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19366
19367 \end_inset 
19368
19369
19370 \layout Standard
19371
19372 PIC16
19373 \begin_inset LatexCommand \index{PIC16}
19374
19375 \end_inset 
19376
19377  port currently supports the following pragmas:
19378 \layout List
19379 \labelwidthstring 00.00.0000
19380
19381 stack
19382 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19383
19384 \end_inset 
19385
19386  pragma stack
19387 \begin_inset LatexCommand \index{PIC16!stack}
19388
19389 \end_inset 
19390
19391  forces the code generator to initialize the stack & frame pointers at a
19392  specific address.
19393  This is an adhoc solution for cases where no STACK directive is available
19394  in the linker script or gplink is not instructed to create a stack section.
19395 \newline 
19396 The stack pragma should be used only once in a project.
19397  Multiple pragmas may result in indeterminate behaviour of the program.
19398 \begin_inset Foot
19399 collapsed false
19400
19401 \layout Standard
19402
19403 The old format (ie.
19404  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19405  cross page boundaries (or even exceed the available data RAM) and crash
19406  the program.
19407  Make sure that stack does not cross page boundaries when using the SMALL
19408  stack model.
19409 \end_inset 
19410
19411
19412 \newline 
19413 The format is as follows:
19414 \layout LyX-Code
19415
19416 #pragma stack bottom_address [stack_size]
19417 \layout Standard
19418
19419
19420 \emph on 
19421 bottom_address
19422 \emph default 
19423  is the lower bound of the stack section.
19424  The stack pointer initially will point at address (bottom_address+stack_size-1).
19425 \layout LyX-Code
19426
19427 Example:
19428 \layout LyX-Code
19429
19430 \layout LyX-Code
19431
19432 /* initializes stack of 100 bytes at RAM address 0x200 */
19433 \layout LyX-Code
19434
19435 #pragma stack 0x200 100
19436 \layout Standard
19437
19438 If the stack_size field is omitted then a stack is created with the default
19439  size of 64.
19440  This size might be enough for most programs, but its not enough for operations
19441  with deep function nesting or excessive stack usage.
19442 \layout List
19443 \labelwidthstring 00.00.0000
19444
19445 code
19446 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19447
19448 \end_inset 
19449
19450  place a function symbol at static FLASH address
19451 \layout LyX-Code
19452
19453 Example:
19454 \layout LyX-Code
19455
19456 \layout LyX-Code
19457
19458 /* place function test_func at 0x4000 */
19459 \layout LyX-Code
19460
19461 #pragma code test_func 0x4000
19462 \layout LyX-Code
19463
19464 \layout List
19465 \labelwidthstring 00.00.0000
19466
19467 library instructs the linker to use a library module.
19468 \newline 
19469 Usage:
19470 \layout LyX-Code
19471
19472 #pragma library module_name
19473 \layout Standard
19474
19475
19476 \emph on 
19477 module_name
19478 \emph default 
19479  can be any library or object file (including its path).
19480  Note that there are four reserved keywords which have special meaning.
19481  These are:
19482 \layout Standard
19483 \align center 
19484
19485 \begin_inset  Tabular
19486 <lyxtabular version="3" rows="6" columns="3">
19487 <features>
19488 <column alignment="center" valignment="top" leftline="true" width="0">
19489 <column alignment="block" valignment="top" leftline="true" width="20page%">
19490 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19491 <row topline="true" bottomline="true">
19492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19493 \begin_inset Text
19494
19495 \layout Standard
19496
19497 Keyword
19498 \end_inset 
19499 </cell>
19500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 \begin_inset Text
19502
19503 \layout Standard
19504
19505 Description
19506 \end_inset 
19507 </cell>
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19509 \begin_inset Text
19510
19511 \layout Standard
19512
19513 Module to link
19514 \end_inset 
19515 </cell>
19516 </row>
19517 <row topline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_inset Text
19520
19521 \layout Standard
19522
19523
19524 \series bold 
19525 ignore
19526 \end_inset 
19527 </cell>
19528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19529 \begin_inset Text
19530
19531 \layout Standard
19532
19533 ignore all library pragmas
19534 \end_inset 
19535 </cell>
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_inset Text
19538
19539 \layout Standard
19540
19541
19542 \emph on 
19543 (none)
19544 \end_inset 
19545 </cell>
19546 </row>
19547 <row topline="true">
19548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19549 \begin_inset Text
19550
19551 \layout Standard
19552
19553
19554 \series bold 
19555 c
19556 \end_inset 
19557 </cell>
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19559 \begin_inset Text
19560
19561 \layout Standard
19562
19563 link the C library
19564 \end_inset 
19565 </cell>
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19567 \begin_inset Text
19568
19569 \layout Standard
19570
19571
19572 \emph on 
19573 libc18f
19574 \emph default 
19575 .lib
19576 \end_inset 
19577 </cell>
19578 </row>
19579 <row topline="true">
19580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19581 \begin_inset Text
19582
19583 \layout Standard
19584
19585
19586 \series bold 
19587 math
19588 \end_inset 
19589 </cell>
19590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19591 \begin_inset Text
19592
19593 \layout Standard
19594
19595 link the Math libarary
19596 \end_inset 
19597 </cell>
19598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19599 \begin_inset Text
19600
19601 \layout Standard
19602
19603
19604 \emph on 
19605 libm18f
19606 \emph default 
19607 .lib
19608 \end_inset 
19609 </cell>
19610 </row>
19611 <row topline="true">
19612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19613 \begin_inset Text
19614
19615 \layout Standard
19616
19617
19618 \series bold 
19619 io
19620 \end_inset 
19621 </cell>
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19623 \begin_inset Text
19624
19625 \layout Standard
19626
19627 link the I/O library
19628 \end_inset 
19629 </cell>
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19631 \begin_inset Text
19632
19633 \layout Standard
19634
19635
19636 \emph on 
19637 libio18f*
19638 \emph default 
19639 .lib
19640 \end_inset 
19641 </cell>
19642 </row>
19643 <row topline="true" bottomline="true">
19644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19645 \begin_inset Text
19646
19647 \layout Standard
19648
19649
19650 \series bold 
19651 debug
19652 \end_inset 
19653 </cell>
19654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19655 \begin_inset Text
19656
19657 \layout Standard
19658
19659 link the debug library
19660 \end_inset 
19661 </cell>
19662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19663 \begin_inset Text
19664
19665 \layout Standard
19666
19667
19668 \emph on 
19669 libdebug
19670 \emph default 
19671 .lib
19672 \end_inset 
19673 </cell>
19674 </row>
19675 </lyxtabular>
19676
19677 \end_inset 
19678
19679
19680 \newline 
19681 * is the device number, i.e.
19682  452 for PIC18F452 MCU.
19683 \layout Standard
19684
19685 This feature allows for linking with specific libraries withoug having to
19686  explicit name them in the command line.
19687  Note that the 
19688 \noun on 
19689 ignore
19690 \noun default 
19691  keyword will reject all modules specified by the library pragma.
19692 \layout List
19693 \labelwidthstring 00.00.0000
19694
19695 udata pragma udata instructs the compiler to emit code so that linker will
19696  place a variable at a specific memory bank
19697 \layout LyX-Code
19698
19699 Example:
19700 \layout LyX-Code
19701
19702 \layout LyX-Code
19703
19704 /* places variable foo at bank2 */
19705 \layout LyX-Code
19706
19707 #pragma udata bank2 foo
19708 \layout LyX-Code
19709
19710 char foo;
19711 \layout Standard
19712
19713 In order for this pragma to work extra SECTION directives should be added
19714  in the .lkr script.
19715  In the following example a sample .lkr file is shown:
19716 \layout LyX-Code
19717
19718 \layout LyX-Code
19719
19720 // Sample linker script for the PIC18F452 processor
19721 \layout LyX-Code
19722
19723 LIBPATH .
19724 \layout LyX-Code
19725
19726 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19727 \layout LyX-Code
19728
19729 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19730 \layout LyX-Code
19731
19732 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19733 \layout LyX-Code
19734
19735 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19736 \layout LyX-Code
19737
19738 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19739 \layout LyX-Code
19740
19741 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19742 \layout LyX-Code
19743
19744 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19745 \layout LyX-Code
19746
19747 \layout LyX-Code
19748
19749 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19750 \layout LyX-Code
19751
19752 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19753 \layout LyX-Code
19754
19755 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19756 \layout LyX-Code
19757
19758 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19759 \layout LyX-Code
19760
19761 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19762 \layout LyX-Code
19763
19764 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19765 \layout LyX-Code
19766
19767 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19768 \layout LyX-Code
19769
19770 \layout LyX-Code
19771
19772 SECTION    NAME=CONFIG     ROM=config
19773 \layout LyX-Code
19774
19775 \layout LyX-Code
19776
19777 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19778 \layout LyX-Code
19779
19780 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19781 \layout LyX-Code
19782
19783 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19784 \layout LyX-Code
19785
19786 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19787 \layout LyX-Code
19788
19789 SECTION    NAME=bank4      RAM=gpr4
19790 \layout LyX-Code
19791
19792 SECTION    NAME=bank5      RAM=gpr5
19793 \layout Standard
19794
19795 The linker will recognise the section name set in the pragma statement and
19796  will position the variable at the memory bank set with the RAM field at
19797  the SECTION line in the linker script file.
19798 \layout Subsection
19799
19800 Header Files
19801 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19802
19803 \end_inset 
19804
19805
19806 \layout Standard
19807
19808 There is one main header file
19809 \begin_inset LatexCommand \index{PIC16!Header files}
19810
19811 \end_inset 
19812
19813  that can be included to the source files using the pic16
19814 \begin_inset LatexCommand \index{PIC16}
19815
19816 \end_inset 
19817
19818  port.
19819  That file is the 
19820 \series bold 
19821 pic18fregs.h
19822 \series default 
19823 .
19824  This header file contains the definitions for the processor special registers,
19825  so it is necessary if the source accesses them.
19826  It can be included by adding the following line in the beginning of the
19827  file:
19828 \layout LyX-Code
19829
19830 #include <pic18fregs.h>
19831 \layout Standard
19832
19833 The specific microcontroller is selected within the pic18fregs.h automatically,
19834  so the same source can be used with a variety of devices.
19835 \layout Subsection
19836
19837 Libraries
19838 \layout Standard
19839
19840 The libraries
19841 \begin_inset LatexCommand \index{PIC16!Libraries}
19842
19843 \end_inset 
19844
19845  that PIC16
19846 \begin_inset LatexCommand \index{PIC16}
19847
19848 \end_inset 
19849
19850  port depends on are the microcontroller device libraries which contain
19851  the symbol definitions for the microcontroller special function registers.
19852  These libraries have the format pic18fxxxx.lib, where 
19853 \emph on 
19854 xxxx
19855 \emph default 
19856  is the microcontroller identification number.
19857  The specific library is selected automatically by the compiler at link
19858  stage according to the selected device.
19859 \layout Standard
19860
19861 Libraries are created with gplib which is part of the gputils package 
19862 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19863
19864 \end_inset 
19865
19866 .
19867 \layout Subsubsection*
19868
19869 Building the libraries
19870 \layout Standard
19871
19872 Before using SDCC/pic16 there are some libraries that need to be compiled.
19873  This process is not done automatically by SDCC since not all users use
19874  SDCC for pic16 projects.
19875  So each user should compile the libraries separately.
19876 \layout Standard
19877
19878 The steps to compile the pic16 libraries under Linux are:
19879 \layout LyX-Code
19880
19881 cd device/lib/pic16
19882 \layout LyX-Code
19883
19884 ./configure
19885 \layout LyX-Code
19886
19887 make
19888 \layout LyX-Code
19889
19890 cd ..
19891 \layout LyX-Code
19892
19893 make model-pic16
19894 \layout LyX-Code
19895
19896 su -c 'make install'     # install the libraries, you need the root password
19897 \layout Standard
19898
19899 If you need to install the headers too, do:
19900 \layout LyX-Code
19901
19902 cd device/include
19903 \layout LyX-Code
19904
19905 su -c 'make install'     # install the headers, you need the root password
19906 \layout Standard
19907
19908 There exist a special target to build the I/O libraries.
19909  This target is not automatically build because it will build the I/O library
19910  for 
19911 \emph on 
19912 every
19913 \emph default 
19914  supported device.
19915  This way building will take quite a lot of time.
19916  Users are advised to edit the 
19917 \series bold 
19918 device/lib/pic16/pics.build
19919 \series default 
19920  file and then execute:
19921 \layout LyX-Code
19922
19923 make lib-io
19924 \layout Subsection
19925
19926 Memory Models
19927 \layout Standard
19928
19929 The following memory models are supported by the PIC16 port:
19930 \layout Itemize
19931
19932 small model
19933 \layout Itemize
19934
19935 large model
19936 \layout Standard
19937
19938 Memory model affects the default size of pointers within the source.
19939  The sizes are shown in the next table:
19940 \layout Standard
19941 \align center 
19942
19943 \begin_inset  Tabular
19944 <lyxtabular version="3" rows="3" columns="3">
19945 <features>
19946 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19947 <column alignment="center" valignment="top" leftline="true" width="0">
19948 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19949 <row topline="true" bottomline="true">
19950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_inset Text
19952
19953 \layout Standard
19954
19955 Pointer sizes according to memory model
19956 \end_inset 
19957 </cell>
19958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19959 \begin_inset Text
19960
19961 \layout Standard
19962
19963 small model
19964 \end_inset 
19965 </cell>
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19967 \begin_inset Text
19968
19969 \layout Standard
19970
19971 large model
19972 \end_inset 
19973 </cell>
19974 </row>
19975 <row topline="true" bottomline="true">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19977 \begin_inset Text
19978
19979 \layout Standard
19980
19981 code pointers
19982 \end_inset 
19983 </cell>
19984 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19985 \begin_inset Text
19986
19987 \layout Standard
19988
19989 16-bits
19990 \end_inset 
19991 </cell>
19992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19993 \begin_inset Text
19994
19995 \layout Standard
19996
19997 24-bits
19998 \end_inset 
19999 </cell>
20000 </row>
20001 <row topline="true" bottomline="true">
20002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20003 \begin_inset Text
20004
20005 \layout Standard
20006
20007 data pointers
20008 \end_inset 
20009 </cell>
20010 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
20011 \begin_inset Text
20012
20013 \layout Standard
20014
20015 16-bits
20016 \end_inset 
20017 </cell>
20018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20019 \begin_inset Text
20020
20021 \layout Standard
20022
20023 16-bits
20024 \end_inset 
20025 </cell>
20026 </row>
20027 </lyxtabular>
20028
20029 \end_inset 
20030
20031
20032 \layout Standard
20033
20034 It is advisable that all sources within a project are compiled with the
20035  same memory model.
20036  If one wants to override the default memory model, this can be done by
20037  declaring a pointer as 
20038 \series bold 
20039 far
20040 \series default 
20041  or 
20042 \series bold 
20043 near
20044 \series default 
20045 .
20046  Far selects large memory model's pointers, while near selects small memory
20047  model's pointers.
20048 \layout Standard
20049
20050 The standard device libraries (see 
20051 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
20052
20053 \end_inset 
20054
20055 ) contain no reference to pointers, so they can be used with both memory
20056  models.
20057 \layout Subsection
20058
20059 Stack
20060 \layout Standard
20061
20062 The stack
20063 \begin_inset LatexCommand \index{PIC16!stack}
20064
20065 \end_inset 
20066
20067  implementation for the PIC16 port uses two indirect registers, FSR1 and
20068  FSR2.
20069 \layout List
20070 \labelwidthstring 00.00.0000
20071
20072 FSR1 is assigned as stack pointer
20073 \layout List
20074 \labelwidthstring 00.00.0000
20075
20076 FSR2 is assigned as frame pointer
20077 \layout Standard
20078
20079 The following stack models are supported by the PIC16 port
20080 \layout Itemize
20081
20082
20083 \noun on 
20084 small
20085 \noun default 
20086  model
20087 \layout Itemize
20088
20089
20090 \noun on 
20091 large
20092 \noun default 
20093  model
20094 \layout Standard
20095
20096
20097 \noun on 
20098 Small
20099 \noun default 
20100  model means that only the FSRxL byte is used to access stack and frame,
20101  while 
20102 \emph on 
20103 \noun on 
20104 large
20105 \emph default 
20106 \noun default 
20107  uses both FSRxL and FSRxH registers.
20108  The following table shows the stack/frame pointers sizes according to stack
20109  model and the maximum space they can address:
20110 \layout Standard
20111 \align center 
20112
20113 \begin_inset  Tabular
20114 <lyxtabular version="3" rows="3" columns="3">
20115 <features>
20116 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20117 <column alignment="center" valignment="top" leftline="true" width="0">
20118 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20119 <row topline="true" bottomline="true">
20120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20121 \begin_inset Text
20122
20123 \layout Standard
20124
20125 Stack & Frame pointer sizes according to stack model
20126 \end_inset 
20127 </cell>
20128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20129 \begin_inset Text
20130
20131 \layout Standard
20132
20133 small
20134 \end_inset 
20135 </cell>
20136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20137 \begin_inset Text
20138
20139 \layout Standard
20140
20141 large
20142 \end_inset 
20143 </cell>
20144 </row>
20145 <row topline="true">
20146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20147 \begin_inset Text
20148
20149 \layout Standard
20150
20151 Stack pointer FSR1
20152 \end_inset 
20153 </cell>
20154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20155 \begin_inset Text
20156
20157 \layout Standard
20158
20159 8-bits
20160 \end_inset 
20161 </cell>
20162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20163 \begin_inset Text
20164
20165 \layout Standard
20166
20167 16-bits
20168 \end_inset 
20169 </cell>
20170 </row>
20171 <row topline="true" bottomline="true">
20172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20173 \begin_inset Text
20174
20175 \layout Standard
20176
20177 Frame pointer FSR2
20178 \end_inset 
20179 </cell>
20180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20181 \begin_inset Text
20182
20183 \layout Standard
20184
20185 8-bits
20186 \end_inset 
20187 </cell>
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20189 \begin_inset Text
20190
20191 \layout Standard
20192
20193 16-bits
20194 \end_inset 
20195 </cell>
20196 </row>
20197 </lyxtabular>
20198
20199 \end_inset 
20200
20201
20202 \layout Standard
20203
20204
20205 \noun on 
20206 Large 
20207 \noun default 
20208 stack model is currently not working properly throughout the code generator.
20209  So its use is not advised.
20210  Also there are some other points that need special care:
20211 \newline 
20212
20213 \layout Enumerate
20214
20215 Do not create stack sections with size more than one physical bank (that
20216  is 256 bytes)
20217 \layout Enumerate
20218
20219 Stack sections should no cross physical bank limits (i.e.
20220  #pragma stack 0x50 0x100)
20221 \layout Standard
20222
20223 These limitations are caused by the fact that only FSRxL is modified when
20224  using SMALL stack model, so no more than 256 bytes of stack can be used.
20225  This problem will disappear after LARGE model is fully implemented.
20226 \layout Subsection
20227
20228 Functions
20229 \layout Standard
20230
20231 In addition to the standard SDCC function keywords, PIC16
20232 \begin_inset LatexCommand \index{PIC16}
20233
20234 \end_inset 
20235
20236  port makes available two more:
20237 \layout List
20238 \labelwidthstring 00.00.0000
20239
20240 wparam
20241 \begin_inset LatexCommand \index{PIC16!wparam}
20242
20243 \end_inset 
20244
20245  Use the WREG to pass one byte of the first function argument.
20246  This improves speed but you may not use this for functions with arguments
20247  that are called via function pointers, otherwise the first byte of the
20248  first parameter will get lost.
20249  Usage:
20250 \layout LyX-Code
20251
20252 void func_wparam(int a) wparam
20253 \layout LyX-Code
20254
20255 {
20256 \layout LyX-Code
20257
20258     /* WREG hold the lower part of a */
20259 \layout LyX-Code
20260
20261     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20262  */
20263 \layout LyX-Code
20264
20265 ...
20266 \layout LyX-Code
20267
20268 }
20269 \layout List
20270 \labelwidthstring 00.00.0000
20271
20272 shadowregs
20273 \begin_inset LatexCommand \index{PIC16!shadowregs}
20274
20275 \end_inset 
20276
20277  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20278  hardware shadow registers which hold the values of WREG, STATUS and BSR
20279  registers.
20280  This can be done by adding the keyword 
20281 \emph on 
20282 shadowregs
20283 \emph default 
20284  before the 
20285 \emph on 
20286 interrupt
20287 \emph default 
20288  keyword in the function's header.
20289 \layout LyX-Code
20290
20291 void isr_shadow(void) shadowregs interrupt 1
20292 \layout LyX-Code
20293
20294 {
20295 \layout LyX-Code
20296
20297 ...
20298 \layout LyX-Code
20299
20300 }
20301 \layout Standard
20302
20303
20304 \emph on 
20305 shadowregs
20306 \emph default 
20307  instructs the code generator not to store/restore WREG, STATUS, BSR when
20308  entering/exiting the ISR.
20309 \layout Subsection
20310
20311 Function return values
20312 \layout Standard
20313
20314 Return values from functions are placed to the appropriate registers following
20315  a modified Microchip policy optimized for SDCC.
20316  The following table shows these registers:
20317 \layout Standard
20318 \align center 
20319
20320 \begin_inset  Tabular
20321 <lyxtabular version="3" rows="6" columns="2">
20322 <features>
20323 <column alignment="center" valignment="top" leftline="true" width="0">
20324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20325 <row topline="true" bottomline="true">
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20327 \begin_inset Text
20328
20329 \layout Standard
20330
20331 size
20332 \end_inset 
20333 </cell>
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20335 \begin_inset Text
20336
20337 \layout Standard
20338
20339 destination register
20340 \end_inset 
20341 </cell>
20342 </row>
20343 <row topline="true">
20344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20345 \begin_inset Text
20346
20347 \layout Standard
20348
20349 8 bits
20350 \end_inset 
20351 </cell>
20352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20353 \begin_inset Text
20354
20355 \layout Standard
20356
20357 WREG
20358 \end_inset 
20359 </cell>
20360 </row>
20361 <row topline="true">
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_inset Text
20364
20365 \layout Standard
20366
20367 16 bits
20368 \end_inset 
20369 </cell>
20370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20371 \begin_inset Text
20372
20373 \layout Standard
20374
20375 PRODL:WREG
20376 \end_inset 
20377 </cell>
20378 </row>
20379 <row topline="true">
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20381 \begin_inset Text
20382
20383 \layout Standard
20384
20385 24 bits
20386 \end_inset 
20387 </cell>
20388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20389 \begin_inset Text
20390
20391 \layout Standard
20392
20393 PRODH:PRODL:WREG
20394 \end_inset 
20395 </cell>
20396 </row>
20397 <row topline="true">
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20399 \begin_inset Text
20400
20401 \layout Standard
20402
20403 32 bits
20404 \end_inset 
20405 </cell>
20406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20407 \begin_inset Text
20408
20409 \layout Standard
20410
20411 FSR0L:PRODH:PRODL:WREG
20412 \end_inset 
20413 </cell>
20414 </row>
20415 <row topline="true" bottomline="true">
20416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20417 \begin_inset Text
20418
20419 \layout Standard
20420
20421 >32 bits
20422 \end_inset 
20423 </cell>
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20425 \begin_inset Text
20426
20427 \layout Standard
20428
20429 on stack, FSR0 points to the beginning
20430 \end_inset 
20431 </cell>
20432 </row>
20433 </lyxtabular>
20434
20435 \end_inset 
20436
20437
20438 \layout Subsection
20439
20440 Interrupts
20441 \layout Standard
20442
20443 An interrupt
20444 \begin_inset LatexCommand \index{PIC16!interrupt}
20445
20446 \end_inset 
20447
20448  service routine (ISR) is declared using the 
20449 \emph on 
20450 interrupt
20451 \emph default 
20452  keyword.
20453 \layout LyX-Code
20454
20455 void isr(void) interrupt 
20456 \emph on 
20457 n
20458 \layout LyX-Code
20459
20460 {
20461 \layout LyX-Code
20462
20463 ...
20464 \layout LyX-Code
20465
20466 }
20467 \layout Standard
20468
20469
20470 \emph on 
20471 n
20472 \emph default 
20473  is the interrupt number, which for PIC18F devices can be:
20474 \layout Standard
20475 \align center 
20476
20477 \begin_inset  Tabular
20478 <lyxtabular version="3" rows="4" columns="3">
20479 <features>
20480 <column alignment="center" valignment="top" leftline="true" width="0">
20481 <column alignment="center" valignment="top" leftline="true" width="0">
20482 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20483 <row topline="true" bottomline="true">
20484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20485 \begin_inset Text
20486
20487 \layout Standard
20488
20489
20490 \emph on 
20491 n
20492 \end_inset 
20493 </cell>
20494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20495 \begin_inset Text
20496
20497 \layout Standard
20498
20499 Interrupt Vector
20500 \end_inset 
20501 </cell>
20502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20503 \begin_inset Text
20504
20505 \layout Standard
20506
20507 Interrupt Vector Address
20508 \end_inset 
20509 </cell>
20510 </row>
20511 <row topline="true">
20512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20513 \begin_inset Text
20514
20515 \layout Standard
20516
20517 0
20518 \end_inset 
20519 </cell>
20520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20521 \begin_inset Text
20522
20523 \layout Standard
20524
20525 RESET vector
20526 \end_inset 
20527 </cell>
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20529 \begin_inset Text
20530
20531 \layout Standard
20532
20533 0x000000
20534 \end_inset 
20535 </cell>
20536 </row>
20537 <row topline="true">
20538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20539 \begin_inset Text
20540
20541 \layout Standard
20542
20543
20544 \family roman 
20545 \series medium 
20546 \shape up 
20547 \size normal 
20548 \emph off 
20549 \bar no 
20550 \noun off 
20551 \color none
20552 1
20553 \end_inset 
20554 </cell>
20555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20556 \begin_inset Text
20557
20558 \layout Standard
20559
20560
20561 \family roman 
20562 \series medium 
20563 \shape up 
20564 \size normal 
20565 \emph off 
20566 \bar no 
20567 \noun off 
20568 \color none
20569 HIGH priority interrupts
20570 \end_inset 
20571 </cell>
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20573 \begin_inset Text
20574
20575 \layout Standard
20576
20577 0x000008
20578 \end_inset 
20579 </cell>
20580 </row>
20581 <row topline="true" bottomline="true">
20582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20583 \begin_inset Text
20584
20585 \layout Standard
20586
20587 2
20588 \end_inset 
20589 </cell>
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20591 \begin_inset Text
20592
20593 \layout Standard
20594
20595 LOW priority interrupts
20596 \end_inset 
20597 </cell>
20598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20599 \begin_inset Text
20600
20601 \layout Standard
20602
20603 0x000018
20604 \end_inset 
20605 </cell>
20606 </row>
20607 </lyxtabular>
20608
20609 \end_inset 
20610
20611
20612 \layout Standard
20613
20614 When generating assembly code for ISR the code generator places a 
20615 \noun on 
20616 goto 
20617 \noun default 
20618 instruction at the 
20619 \emph on 
20620 Interrupt Vector Address
20621 \emph default 
20622  which points at the genetated ISR.
20623  This single GOTO instruction is part of an automatically generated 
20624 \emph on 
20625 interrupt entry point
20626 \emph default 
20627  function.
20628  The actuall ISR code is placed as normally would in the code space.
20629  Upon interrupt request, the GOTO instruction is executed which jumps to
20630  the ISR code.
20631  When declaring interrupt functions as _naked this GOTO instruction is 
20632 \series bold 
20633 not
20634 \series default 
20635  generated.
20636  The whole interrupt functions is therefore placed at the Interrupt Vector
20637  Address of the specific interrupt.
20638  This is not a problem for the LOW priority interrupts, but it is a problem
20639  for the RESET and the HIGH priority interrupts because code may be written
20640  at the next interrupt´s vector address and cause undeterminate program
20641  behaviour if that interrupt is raised.
20642 \begin_inset Foot
20643 collapsed false
20644
20645 \layout Standard
20646
20647 This is not a problem when
20648 \layout Enumerate
20649
20650 this is a HIGH interrupt ISR and LOW interrupts are 
20651 \emph on 
20652 disabled
20653 \emph default 
20654  or not used.
20655 \layout Enumerate
20656
20657 when the ISR is small enough not to reach the next interrupt´s vector address.
20658 \end_inset 
20659
20660
20661 \layout Standard
20662
20663
20664 \emph on 
20665 n
20666 \emph default 
20667  is possible to be omitted.
20668  This way a function is generated similar to an ISR, but it is not assigned
20669  to any interrupt.
20670 \layout Standard
20671
20672 When entering an interrupt, currently the PIC16
20673 \begin_inset LatexCommand \index{PIC16}
20674
20675 \end_inset 
20676
20677  port automatically saves the following registers:
20678 \layout Itemize
20679
20680 WREG
20681 \layout Itemize
20682
20683 STATUS
20684 \layout Itemize
20685
20686 BSR
20687 \layout Itemize
20688
20689 PROD (PRODL and PRODH)
20690 \layout Itemize
20691
20692 FSR0 (FSR0L and FSR0H)
20693 \layout Standard
20694
20695 These registers are restored upon return from the interrupt routine.
20696 \begin_inset Foot
20697 collapsed false
20698
20699 \layout Standard
20700
20701 NOTE that when the _naked attribute is specified for an interrupt routine,
20702  then NO registers are stored or restored.
20703 \end_inset 
20704
20705
20706 \layout Subsection
20707
20708 Generic Pointers
20709 \layout Standard
20710
20711 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20712  There are 3 types of generic pointers currently implemented data, code
20713  and eeprom pointers.
20714  They are differentiated by the value of the 7th and 6th bits of the upper
20715  byte:
20716 \layout Standard
20717 \align center 
20718
20719 \begin_inset  Tabular
20720 <lyxtabular version="3" rows="5" columns="5">
20721 <features>
20722 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20723 <column alignment="center" valignment="top" width="0">
20724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20725 <column alignment="center" valignment="top" width="0">
20726 <column alignment="left" valignment="top" rightline="true" width="0">
20727 <row topline="true" bottomline="true">
20728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20729 \begin_inset Text
20730
20731 \layout Standard
20732
20733 pointer type
20734 \end_inset 
20735 </cell>
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_inset Text
20738
20739 \layout Standard
20740
20741 7th bit
20742 \end_inset 
20743 </cell>
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \layout Standard
20748
20749 6th bit
20750 \end_inset 
20751 </cell>
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20753 \begin_inset Text
20754
20755 \layout Standard
20756
20757 rest of the pointer
20758 \end_inset 
20759 </cell>
20760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20761 \begin_inset Text
20762
20763 \layout Standard
20764
20765 description
20766 \end_inset 
20767 </cell>
20768 </row>
20769 <row topline="true" bottomline="true">
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20771 \begin_inset Text
20772
20773 \layout Standard
20774
20775 data 
20776 \end_inset 
20777 </cell>
20778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20779 \begin_inset Text
20780
20781 \layout Standard
20782
20783 1
20784 \end_inset 
20785 </cell>
20786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20787 \begin_inset Text
20788
20789 \layout Standard
20790
20791 0
20792 \end_inset 
20793 </cell>
20794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20795 \begin_inset Text
20796
20797 \layout Standard
20798
20799
20800 \family typewriter 
20801 \shape slanted 
20802 \emph on 
20803 uuuuuu uuuuxxxx xxxxxxxx
20804 \end_inset 
20805 </cell>
20806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20807 \begin_inset Text
20808
20809 \layout Standard
20810
20811 a 12-bit data pointer in data RAM memory
20812 \end_inset 
20813 </cell>
20814 </row>
20815 <row bottomline="true">
20816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20817 \begin_inset Text
20818
20819 \layout Standard
20820
20821 code
20822 \end_inset 
20823 </cell>
20824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20825 \begin_inset Text
20826
20827 \layout Standard
20828
20829 0
20830 \end_inset 
20831 </cell>
20832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20833 \begin_inset Text
20834
20835 \layout Standard
20836
20837 0
20838 \end_inset 
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \layout Standard
20844
20845
20846 \family typewriter 
20847 \shape slanted 
20848 \emph on 
20849 uxxxxx xxxxxxxx xxxxxxxx
20850 \end_inset 
20851 </cell>
20852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20853 \begin_inset Text
20854
20855 \layout Standard
20856
20857 a 21-bit code pointer in FLASH memory
20858 \end_inset 
20859 </cell>
20860 </row>
20861 <row bottomline="true">
20862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20863 \begin_inset Text
20864
20865 \layout Standard
20866
20867 eeprom
20868 \end_inset 
20869 </cell>
20870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20871 \begin_inset Text
20872
20873 \layout Standard
20874
20875 0
20876 \end_inset 
20877 </cell>
20878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20879 \begin_inset Text
20880
20881 \layout Standard
20882
20883 1
20884 \end_inset 
20885 </cell>
20886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20887 \begin_inset Text
20888
20889 \layout Standard
20890
20891
20892 \family typewriter 
20893 \shape slanted 
20894 \emph on 
20895 uuuuuu uuuuuuxx xxxxxxxx
20896 \end_inset 
20897 </cell>
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20899 \begin_inset Text
20900
20901 \layout Standard
20902
20903 a 10-bit eeprom pointer in EEPROM memory
20904 \end_inset 
20905 </cell>
20906 </row>
20907 <row bottomline="true">
20908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20909 \begin_inset Text
20910
20911 \layout Standard
20912
20913 (unimplemented)
20914 \end_inset 
20915 </cell>
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_inset Text
20918
20919 \layout Standard
20920
20921 1
20922 \end_inset 
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \layout Standard
20928
20929 1
20930 \end_inset 
20931 </cell>
20932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20933 \begin_inset Text
20934
20935 \layout Standard
20936
20937
20938 \family typewriter 
20939 \shape slanted 
20940 \emph on 
20941 xxxxxx xxxxxxxx xxxxxxxx
20942 \end_inset 
20943 </cell>
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20945 \begin_inset Text
20946
20947 \layout Standard
20948
20949 unimplemented pointer type
20950 \end_inset 
20951 </cell>
20952 </row>
20953 </lyxtabular>
20954
20955 \end_inset 
20956
20957
20958 \layout Standard
20959
20960 Generic pointer are read and written with a set of library functions which
20961  read/write 1, 2, 3, 4 bytes.
20962 \layout Subsection
20963
20964 PIC16 C Libraries
20965 \layout Subsubsection
20966
20967 Standard I/O Streams
20968 \layout Standard
20969
20970 In the 
20971 \emph on 
20972 stdio.h
20973 \emph default 
20974  the type FILE is defined as:
20975 \layout LyX-Code
20976
20977 typedef char * FILE;
20978 \layout Standard
20979
20980 This type is the stream type implemented I/O in the PIC18F devices.
20981  Also the standard input and output streams are declared in stdio.h:
20982 \layout LyX-Code
20983
20984 extern FILE * stdin;
20985 \layout LyX-Code
20986
20987 extern FILE * stdout;
20988 \layout Standard
20989
20990 The FILE type is actually a generic pointer which defines one more type
20991  of generic pointers, the 
20992 \emph on 
20993 stream 
20994 \emph default 
20995 pointer.
20996  This new type has the format:
20997 \layout Standard
20998 \align center 
20999
21000 \begin_inset  Tabular
21001 <lyxtabular version="3" rows="2" columns="7">
21002 <features>
21003 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21004 <column alignment="center" valignment="top" width="0">
21005 <column alignment="center" valignment="top" leftline="true" width="0">
21006 <column alignment="center" valignment="top" leftline="true" width="0">
21007 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21008 <column alignment="center" valignment="top" width="0">
21009 <column alignment="left" valignment="top" rightline="true" width="0">
21010 <row topline="true" bottomline="true">
21011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21012 \begin_inset Text
21013
21014 \layout Standard
21015
21016 pointer type
21017 \end_inset 
21018 </cell>
21019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21020 \begin_inset Text
21021
21022 \layout Standard
21023
21024 <7:6>
21025 \end_inset 
21026 </cell>
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21028 \begin_inset Text
21029
21030 \layout Standard
21031
21032 <5>
21033 \end_inset 
21034 </cell>
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21036 \begin_inset Text
21037
21038 \layout Standard
21039
21040 <4>
21041 \end_inset 
21042 </cell>
21043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21044 \begin_inset Text
21045
21046 \layout Standard
21047
21048 <3:0>
21049 \end_inset 
21050 </cell>
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21052 \begin_inset Text
21053
21054 \layout Standard
21055
21056 rest of the pointer
21057 \end_inset 
21058 </cell>
21059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21060 \begin_inset Text
21061
21062 \layout Standard
21063
21064 descrption
21065 \end_inset 
21066 </cell>
21067 </row>
21068 <row topline="true" bottomline="true">
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_inset Text
21071
21072 \layout Standard
21073
21074 stream
21075 \end_inset 
21076 </cell>
21077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21078 \begin_inset Text
21079
21080 \layout Standard
21081
21082 00
21083 \end_inset 
21084 </cell>
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21086 \begin_inset Text
21087
21088 \layout Standard
21089
21090 1
21091 \end_inset 
21092 </cell>
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21094 \begin_inset Text
21095
21096 \layout Standard
21097
21098 0
21099 \end_inset 
21100 </cell>
21101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21102 \begin_inset Text
21103
21104 \layout Standard
21105
21106 nnnn
21107 \end_inset 
21108 </cell>
21109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21110 \begin_inset Text
21111
21112 \layout Standard
21113
21114
21115 \family typewriter 
21116 \shape slanted 
21117 \emph on 
21118 uuuuuuuu uuuuuuuu
21119 \end_inset 
21120 </cell>
21121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21122 \begin_inset Text
21123
21124 \layout Standard
21125
21126 upper byte high nubble is 0x2n, the rest are zeroes
21127 \end_inset 
21128 </cell>
21129 </row>
21130 </lyxtabular>
21131
21132 \end_inset 
21133
21134
21135 \layout Standard
21136
21137 Currently implemented there are 3 types of streams defined:
21138 \layout Standard
21139 \align center 
21140
21141 \begin_inset  Tabular
21142 <lyxtabular version="3" rows="4" columns="4">
21143 <features>
21144 <column alignment="center" valignment="top" leftline="true" width="0">
21145 <column alignment="center" valignment="top" leftline="true" width="0">
21146 <column alignment="center" valignment="top" leftline="true" width="0">
21147 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21148 <row topline="true" bottomline="true">
21149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21150 \begin_inset Text
21151
21152 \layout Standard
21153
21154 stream type
21155 \end_inset 
21156 </cell>
21157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21158 \begin_inset Text
21159
21160 \layout Standard
21161
21162 value
21163 \end_inset 
21164 </cell>
21165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21166 \begin_inset Text
21167
21168 \layout Standard
21169
21170 module
21171 \end_inset 
21172 </cell>
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21174 \begin_inset Text
21175
21176 \layout Standard
21177
21178 description
21179 \end_inset 
21180 </cell>
21181 </row>
21182 <row topline="true">
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \layout Standard
21187
21188 STREAM_USART
21189 \end_inset 
21190 </cell>
21191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21192 \begin_inset Text
21193
21194 \layout Standard
21195
21196
21197 \family typewriter 
21198 0x200000UL
21199 \end_inset 
21200 </cell>
21201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21202 \begin_inset Text
21203
21204 \layout Standard
21205
21206 USART
21207 \end_inset 
21208 </cell>
21209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21210 \begin_inset Text
21211
21212 \layout Standard
21213
21214 Writes/Reads characters via the USART peripheral
21215 \end_inset 
21216 </cell>
21217 </row>
21218 <row topline="true">
21219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21220 \begin_inset Text
21221
21222 \layout Standard
21223
21224 STREAM_MSSP
21225 \end_inset 
21226 </cell>
21227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21228 \begin_inset Text
21229
21230 \layout Standard
21231
21232
21233 \family typewriter 
21234 0x210000UL
21235 \end_inset 
21236 </cell>
21237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21238 \begin_inset Text
21239
21240 \layout Standard
21241
21242 MSSP
21243 \end_inset 
21244 </cell>
21245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21246 \begin_inset Text
21247
21248 \layout Standard
21249
21250 Writes/Reads characters via the MSSP peripheral
21251 \end_inset 
21252 </cell>
21253 </row>
21254 <row topline="true" bottomline="true">
21255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21256 \begin_inset Text
21257
21258 \layout Standard
21259
21260 STREAM_USER
21261 \end_inset 
21262 </cell>
21263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21264 \begin_inset Text
21265
21266 \layout Standard
21267
21268
21269 \family typewriter 
21270 0x2f0000UL
21271 \end_inset 
21272 </cell>
21273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21274 \begin_inset Text
21275
21276 \layout Standard
21277
21278 (none)
21279 \end_inset 
21280 </cell>
21281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21282 \begin_inset Text
21283
21284 \layout Standard
21285
21286 Writes/Reads characters via used defined functions
21287 \end_inset 
21288 </cell>
21289 </row>
21290 </lyxtabular>
21291
21292 \end_inset 
21293
21294
21295 \layout Standard
21296
21297 The stream identifiers are declared as macros in the stdio.h header.
21298 \layout Standard
21299
21300 In the libc library there exist the functions that are used to write to
21301  each of the above streams.
21302  These are
21303 \layout List
21304 \labelwidthstring 00.00.0000
21305
21306 _
21307 \begin_inset ERT
21308 status Collapsed
21309
21310 \layout Standard
21311
21312 \backslash 
21313 /
21314 \end_inset 
21315
21316 _stream_usart_putchar writes a character at the USART stream
21317 \layout List
21318 \labelwidthstring 00.00.0000
21319
21320 _
21321 \begin_inset ERT
21322 status Collapsed
21323
21324 \layout Standard
21325
21326 \backslash 
21327 /
21328 \end_inset 
21329
21330 _stream_mssp_putchar writes a character at the MSSP stream
21331 \layout List
21332 \labelwidthstring 00.00.0000
21333
21334 putchar dummy function.
21335  This writes a character to a user specified manner.
21336 \layout Standard
21337
21338 In order to increase performance 
21339 \emph on 
21340 putchar 
21341 \emph default 
21342 is declared in stdio.h as having its parameter in WREG (it has the wparam
21343  keyword).
21344  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21345  in a user-friendly way.
21346  
21347 \emph on 
21348 arg
21349 \emph default 
21350  is the name of the variable that holds the character to print.
21351  An example follows:
21352 \layout LyX-Code
21353
21354 #include <pic18fregs.h>
21355 \newline 
21356 #include <stdio.h>
21357 \newline 
21358
21359 \newline 
21360 PUTCHAR( c )
21361 \layout LyX-Code
21362
21363 {
21364 \layout LyX-Code
21365
21366     PORTA = c;    /* dump character c to PORTA */
21367 \layout LyX-Code
21368
21369
21370 \newline 
21371
21372 \newline 
21373 void main(void)
21374 \layout LyX-Code
21375
21376 {
21377 \layout LyX-Code
21378
21379     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21380 \layout LyX-Code
21381
21382                               * by default to STREAM_USER */
21383 \layout LyX-Code
21384
21385     printf (¨This is a printf test
21386 \backslash 
21387 n¨);
21388 \layout LyX-Code
21389
21390 }
21391 \layout LyX-Code
21392
21393 \layout Subsubsection
21394
21395 Printing functions
21396 \layout Standard
21397
21398 PIC16 contains an implementation of the printf-family of functions.
21399  There exist the following functions:
21400 \layout LyX-Code
21401
21402 extern unsigned int sprintf(char *buf, char *fmt, ...);
21403 \layout LyX-Code
21404
21405 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21406 \layout LyX-Code
21407
21408 \layout LyX-Code
21409
21410 extern unsigned int printf(char *fmt, ...);
21411 \layout LyX-Code
21412
21413 extern unsigned int vprintf(char *fmt, va_lista ap);
21414 \layout LyX-Code
21415
21416 \layout LyX-Code
21417
21418 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21419 \layout LyX-Code
21420
21421 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21422 \layout Standard
21423
21424 For sprintf and vsprintf 
21425 \emph on 
21426 buf 
21427 \emph default 
21428 should normally be a data pointer where the resulting string will be placed.
21429  No range checking is done so the user should allocate the necessery buffer.
21430  For fprintf and vfprintf 
21431 \emph on 
21432 fp
21433 \emph default 
21434  should be a stream pointer (i.e.
21435  stdout, STREAM_MSSP, etc...).
21436 \layout Subsubsection
21437
21438 Signals
21439 \layout Standard
21440
21441 The PIC18F family of microcontrollers supports a number of interrupt sources.
21442  A list of these interrupts is shown in the following table:
21443 \layout Standard
21444 \align center 
21445
21446 \begin_inset  Tabular
21447 <lyxtabular version="3" rows="11" columns="4">
21448 <features>
21449 <column alignment="left" valignment="top" leftline="true" width="0">
21450 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21451 <column alignment="left" valignment="top" leftline="true" width="0">
21452 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21453 <row topline="true" bottomline="true">
21454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21455 \begin_inset Text
21456
21457 \layout Standard
21458
21459 signal name
21460 \end_inset 
21461 </cell>
21462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21463 \begin_inset Text
21464
21465 \layout Standard
21466
21467 description
21468 \end_inset 
21469 </cell>
21470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21471 \begin_inset Text
21472
21473 \layout Standard
21474
21475 signal name
21476 \end_inset 
21477 </cell>
21478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21479 \begin_inset Text
21480
21481 \layout Standard
21482
21483 descritpion
21484 \end_inset 
21485 </cell>
21486 </row>
21487 <row topline="true">
21488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21489 \begin_inset Text
21490
21491 \layout Standard
21492
21493 SIG_RB
21494 \end_inset 
21495 </cell>
21496 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21497 \begin_inset Text
21498
21499 \layout Standard
21500
21501 PORTB change interrupt
21502 \end_inset 
21503 </cell>
21504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21505 \begin_inset Text
21506
21507 \layout Standard
21508
21509 SIG_EE
21510 \end_inset 
21511 </cell>
21512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21513 \begin_inset Text
21514
21515 \layout Standard
21516
21517 EEPROM/FLASH write complete interrupt
21518 \end_inset 
21519 </cell>
21520 </row>
21521 <row topline="true">
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21523 \begin_inset Text
21524
21525 \layout Standard
21526
21527 SIG_INT0
21528 \end_inset 
21529 </cell>
21530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21531 \begin_inset Text
21532
21533 \layout Standard
21534
21535 INT0 external interrupt
21536 \end_inset 
21537 </cell>
21538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21539 \begin_inset Text
21540
21541 \layout Standard
21542
21543 SIG_BCOL
21544 \end_inset 
21545 </cell>
21546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21547 \begin_inset Text
21548
21549 \layout Standard
21550
21551 Bus collision interrupt
21552 \end_inset 
21553 </cell>
21554 </row>
21555 <row topline="true">
21556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21557 \begin_inset Text
21558
21559 \layout Standard
21560
21561 SIG_INT1
21562 \end_inset 
21563 </cell>
21564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21565 \begin_inset Text
21566
21567 \layout Standard
21568
21569 INT1 external interrupt
21570 \end_inset 
21571 </cell>
21572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21573 \begin_inset Text
21574
21575 \layout Standard
21576
21577 SIG_LVD
21578 \end_inset 
21579 </cell>
21580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21581 \begin_inset Text
21582
21583 \layout Standard
21584
21585 Low voltage detect interrupt
21586 \end_inset 
21587 </cell>
21588 </row>
21589 <row topline="true">
21590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21591 \begin_inset Text
21592
21593 \layout Standard
21594
21595 SIG_INT2
21596 \end_inset 
21597 </cell>
21598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21599 \begin_inset Text
21600
21601 \layout Standard
21602
21603 INT2 external interrupt
21604 \end_inset 
21605 </cell>
21606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21607 \begin_inset Text
21608
21609 \layout Standard
21610
21611 SIG_PSP
21612 \end_inset 
21613 </cell>
21614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21615 \begin_inset Text
21616
21617 \layout Standard
21618
21619 Parallel slave port interrupt
21620 \end_inset 
21621 </cell>
21622 </row>
21623 <row topline="true">
21624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21625 \begin_inset Text
21626
21627 \layout Standard
21628
21629 SIG_CCP1
21630 \end_inset 
21631 </cell>
21632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21633 \begin_inset Text
21634
21635 \layout Standard
21636
21637 CCP1 module interrupt
21638 \end_inset 
21639 </cell>
21640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21641 \begin_inset Text
21642
21643 \layout Standard
21644
21645 SIG_AD
21646 \end_inset 
21647 </cell>
21648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21649 \begin_inset Text
21650
21651 \layout Standard
21652
21653 AD convertion complete interrupt
21654 \end_inset 
21655 </cell>
21656 </row>
21657 <row topline="true">
21658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21659 \begin_inset Text
21660
21661 \layout Standard
21662
21663 SIG_CCP2
21664 \end_inset 
21665 </cell>
21666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21667 \begin_inset Text
21668
21669 \layout Standard
21670
21671 CCP2 module interrupt
21672 \end_inset 
21673 </cell>
21674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21675 \begin_inset Text
21676
21677 \layout Standard
21678
21679 SIG_RC
21680 \end_inset 
21681 </cell>
21682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21683 \begin_inset Text
21684
21685 \layout Standard
21686
21687 USART receive interrupt
21688 \end_inset 
21689 </cell>
21690 </row>
21691 <row topline="true">
21692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21693 \begin_inset Text
21694
21695 \layout Standard
21696
21697 SIG_TMR0
21698 \end_inset 
21699 </cell>
21700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21701 \begin_inset Text
21702
21703 \layout Standard
21704
21705 TMR0 overflow interrupt
21706 \end_inset 
21707 </cell>
21708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21709 \begin_inset Text
21710
21711 \layout Standard
21712
21713 SIG_TX
21714 \end_inset 
21715 </cell>
21716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21717 \begin_inset Text
21718
21719 \layout Standard
21720
21721 USART transmit interrupt
21722 \end_inset 
21723 </cell>
21724 </row>
21725 <row topline="true">
21726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21727 \begin_inset Text
21728
21729 \layout Standard
21730
21731 SIG_TMR1
21732 \end_inset 
21733 </cell>
21734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21735 \begin_inset Text
21736
21737 \layout Standard
21738
21739 TMR1 overflow interrupt
21740 \end_inset 
21741 </cell>
21742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21743 \begin_inset Text
21744
21745 \layout Standard
21746
21747 SIG_MSSP
21748 \end_inset 
21749 </cell>
21750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21751 \begin_inset Text
21752
21753 \layout Standard
21754
21755 SSP receive/transmit interrupt
21756 \end_inset 
21757 </cell>
21758 </row>
21759 <row topline="true">
21760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21761 \begin_inset Text
21762
21763 \layout Standard
21764
21765 SIG_TMR2
21766 \end_inset 
21767 </cell>
21768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21769 \begin_inset Text
21770
21771 \layout Standard
21772
21773 TMR2 matches PR2 interrupt
21774 \end_inset 
21775 </cell>
21776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21777 \begin_inset Text
21778
21779 \layout Standard
21780
21781 \end_inset 
21782 </cell>
21783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21784 \begin_inset Text
21785
21786 \layout Standard
21787
21788 \end_inset 
21789 </cell>
21790 </row>
21791 <row topline="true" bottomline="true">
21792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21793 \begin_inset Text
21794
21795 \layout Standard
21796
21797 SIG_TMR3
21798 \end_inset 
21799 </cell>
21800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21801 \begin_inset Text
21802
21803 \layout Standard
21804
21805 TMR3 overflow interrupt
21806 \end_inset 
21807 </cell>
21808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21809 \begin_inset Text
21810
21811 \layout Standard
21812
21813 \end_inset 
21814 </cell>
21815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21816 \begin_inset Text
21817
21818 \layout Standard
21819
21820 \end_inset 
21821 </cell>
21822 </row>
21823 </lyxtabular>
21824
21825 \end_inset 
21826
21827
21828 \layout Standard
21829
21830 The prototypes for these names are defined in the header file 
21831 \emph on 
21832 signal.h
21833 \emph default 
21834  .
21835 \layout Standard
21836
21837 In order to simplify signal handling, a number of macros is provided:
21838 \layout List
21839 \labelwidthstring 00.00.0000
21840
21841 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21842  high priority interrupts.
21843  
21844 \emph on 
21845 name
21846 \emph default 
21847  is the function name to use.
21848 \layout List
21849 \labelwidthstring 00.00.0000
21850
21851 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21852  low priority interrupt.
21853  
21854 \emph on 
21855 name
21856 \emph default 
21857  is the function name to use.
21858 \layout List
21859 \labelwidthstring 00.00.0000
21860
21861 DEF_HANDLER(sig,handler) define a handler for signal 
21862 \emph on 
21863 sig.
21864 \layout List
21865 \labelwidthstring 00.00.0000
21866
21867 END_DEF end the declaration of the dispatch table.
21868 \layout Standard
21869
21870 Additionally there are two more macros to simplify the declaration of the
21871  signal handler:
21872 \layout List
21873 \labelwidthstring 00.00.0000
21874
21875
21876 \series medium 
21877 SIGHANDLER(handler) 
21878 \series default 
21879 this declares the function prototype for the 
21880 \emph on 
21881 handler
21882 \emph default 
21883  function.
21884 \layout List
21885 \labelwidthstring 00.00.0000
21886
21887 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21888 \layout Standard
21889
21890 An example of using the macros above is shown below:
21891 \layout LyX-Code
21892
21893 #include <pic18fregs.h>
21894 \layout LyX-Code
21895
21896 #include <signal.h>
21897 \newline 
21898
21899 \newline 
21900 DEF_INTHIGH(high_int)
21901 \layout LyX-Code
21902
21903 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21904 \layout LyX-Code
21905
21906 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21907 \layout LyX-Code
21908
21909 END_DEF
21910 \newline 
21911
21912 \newline 
21913 SIGHANDLER(_tmr0_handler)
21914 \layout LyX-Code
21915
21916 {
21917 \layout LyX-Code
21918
21919   /* action to be taken when timer 0 overflows */
21920 \layout LyX-Code
21921
21922 }
21923 \newline 
21924
21925 \newline 
21926 SIGHANDLERNAKED(_bcol_handler)
21927 \layout LyX-Code
21928
21929 {
21930 \layout LyX-Code
21931
21932   _asm
21933 \layout LyX-Code
21934
21935     /* action to be taken when bus collision occurs */
21936 \layout LyX-Code
21937
21938     retfie
21939 \layout LyX-Code
21940
21941  _endasm;
21942 \layout LyX-Code
21943
21944 }
21945 \layout Standard
21946
21947
21948 \series bold 
21949 NOTES:
21950 \series default 
21951  Special care should be taken when using the above scheme:
21952 \layout Itemize
21953
21954 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21955 \layout Itemize
21956
21957 when declaring SIGHANDLERNAKED handler never forget to use 
21958 \emph on 
21959 retfie
21960 \emph default 
21961  for proper returning.
21962 \layout Subsection
21963
21964 PIC16 Port -- Tips
21965 \layout Standard
21966
21967 Here you can find some general tips for compiling programs with SDCC/pic16.
21968 \layout Subsubsection
21969
21970 Stack size
21971 \layout Standard
21972
21973 The default stack
21974 \begin_inset LatexCommand \index{PIC16!stack}
21975
21976 \end_inset 
21977
21978  size (that is 64 bytes) probably is enough for many programs.
21979  One must take care that when there are many levels of function nesting,
21980  or there is excessive usage of stack, its size should be extended.
21981  An example of such a case is the printf/sprintf family of functions.
21982  If you encounter problems like not being able to print integers, then you
21983  need to set the stack size around the maximum (256 for small stack model).
21984  The following diagram shows what happens when calling printf to print an
21985  integer:
21986 \layout LyX-Code
21987
21988 printf () --> ltoa () --> ultoa () --> divschar ()
21989 \layout Standard
21990
21991 It is should be understood that stack is easily consumed when calling complicate
21992 d functions.
21993  Using command line arguments like -
21994 \begin_inset ERT
21995 status Collapsed
21996
21997 \layout Standard
21998
21999 \backslash 
22000 /
22001 \end_inset 
22002
22003 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
22004  stack frames.
22005  Other ways to reduce stack usage may exist.
22006 \layout Subsection
22007
22008 Known bugs
22009 \layout Standard
22010
22011 The PIC16 Port currently does not pass SDCC's regression test
22012 \begin_inset LatexCommand \index{Regression test (PIC16)}
22013
22014 \end_inset 
22015
22016  suite (see section 
22017 \begin_inset LatexCommand \ref{sec:Quality-control}
22018
22019 \end_inset 
22020
22021 ) and thus the nightly regression tests for the PIC16 target are currently
22022  disabled for all hosts except for 
22023 \emph on 
22024 Linux on Opteron.
22025
22026 \emph default 
22027  This means you can see the result of the PIC16 regression tests f.e.
22028  by checking the log files in 
22029 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
22030
22031 \end_inset 
22032
22033  (pick the most up to date file there, scroll down, lend a hand).
22034 \layout Chapter
22035
22036 Debugging
22037 \layout Standard
22038
22039 There are several approaches to debugging your code.
22040  This chapter is meant to show your options and to give detail on some of
22041  them:
22042 \newline 
22043
22044 \newline 
22045 When writing your code:
22046 \layout Itemize
22047
22048 write your code with debugging in mind (avoid duplicating code, put conceptually
22049  similar variables into structs, use structured code, have strategic points
22050  within your code where all variables are consistent, ...)
22051 \layout Itemize
22052
22053 run a syntax-checking tool like splint
22054 \begin_inset LatexCommand \index{splint (syntax checking tool)}
22055
22056 \end_inset 
22057
22058
22059 \begin_inset LatexCommand \index{lint (syntax checking tool)}
22060
22061 \end_inset 
22062
22063  (see -
22064 \begin_inset ERT
22065 status Collapsed
22066
22067 \layout Standard
22068
22069 \backslash 
22070 /
22071 \end_inset 
22072
22073 -more-pedantic 
22074 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22075
22076 \end_inset 
22077
22078 ) over the code.
22079 \layout Itemize
22080
22081 for the high level code use a C-compiler (like f.e.
22082  GCC) to compile run and debug the code on your host.
22083  See (see -
22084 \begin_inset ERT
22085 status Collapsed
22086
22087 \layout Standard
22088
22089 \backslash 
22090 /
22091 \end_inset 
22092
22093 -more-pedantic 
22094 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22095
22096 \end_inset 
22097
22098  ) on howto handle syntax extensions like __xdata, __at(), ...
22099  
22100 \layout Itemize
22101
22102 use another C-compiler to compile code for your target.
22103  Always an option but not recommended:) And not very likely to help you.
22104  If you seriously consider walking this path you should at least occasionally
22105  check portability of your code.
22106  Most commercial compiler vendors will offer an evaluation version so you
22107  can test compile your code or snippets of your code.
22108 \layout Standard
22109
22110 Debugging on a simulator:
22111 \layout Itemize
22112
22113 there is a separate section about SDCDB (section 
22114 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
22115
22116 \end_inset 
22117
22118 ) below.
22119 \layout Itemize
22120
22121 or (8051 specific) use a freeware/commercial simulator which interfaces
22122  to the AOMF
22123 \begin_inset LatexCommand \index{AOMF, AOMF51}
22124
22125 \end_inset 
22126
22127  file (see 
22128 \begin_inset LatexCommand \ref{OMF file}
22129
22130 \end_inset 
22131
22132 ) optionally generated by SDCC.
22133 \layout Standard
22134
22135 Debugging On-target: 
22136 \layout Itemize
22137
22138 use a MCU port pin to serially output debug data to the RS232 port of your
22139  host.
22140  You'll probably want some level shifting device typically involving a MAX232
22141  or similar IC.
22142  If the hardware serial port of the MCU is not available search for 'Software
22143  UART' in your favourite search machine.
22144 \layout Itemize
22145
22146 use an on-target monitor.
22147  In this context a monitor is a small program which usually accepts commands
22148  via a serial line and allows to set program counter, to single step through
22149  a program and read/write memory locations.
22150  For the 8051 good examples of monitors are paulmon and cmon51 (see section
22151  
22152 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
22153
22154 \end_inset 
22155
22156 ).
22157 \layout Itemize
22158
22159 toggle MCU port pins at strategic points within your code and use an oscilloscop
22160 e.
22161  A 
22162 \emph on 
22163 digital oscilloscope
22164 \emph default 
22165
22166 \begin_inset LatexCommand \index{Oscilloscope}
22167
22168 \end_inset 
22169
22170  with deep trace memory is really helpful especially if you have to debug
22171  a realtime application.
22172  If you need to monitor more pins than your oscilloscope provides you can
22173  sometimes get away with a small R-2R network.
22174  On a single channel oscilloscope you could f.e.
22175  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22176 k
22177 \begin_inset Formula $\Omega$
22178 \end_inset 
22179
22180  resistor and the other one by a 5\SpecialChar ~
22181 k
22182 \begin_inset Formula $\Omega$
22183 \end_inset 
22184
22185  resistor to the oscilloscope probe (check output drive capability of the
22186  pins you want to monitor).
22187  If you need to monitor many more pins a 
22188 \emph on 
22189 logic analyzer
22190 \emph default 
22191  will be handy.
22192 \layout Itemize
22193
22194 use an ICE (
22195 \emph on 
22196 i
22197 \emph default 
22198
22199 \emph on 
22200 c
22201 \emph default 
22202 ircuit 
22203 \emph on 
22204 e
22205 \emph default 
22206 mulator
22207 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22208
22209 \end_inset 
22210
22211 ).
22212  Usually very expensive.
22213  And very nice to have too.
22214  And usually locks you (for years...) to the devices the ICE can emulate.
22215  
22216 \layout Itemize
22217
22218 use a remote debugger.
22219  In most 8-bit systems the symbol information is not available on the target,
22220  and a complete debugger is too bulky for the target system.
22221  Therefore usually a debugger on the host system connects to an on-target
22222  debugging stub which accepts only primitive commands.
22223  
22224 \newline 
22225 Terms to enter into your favourite search engine could be 'remote debugging',
22226  'gdb stub' or 'inferior debugger'.
22227  (is there one?)
22228 \layout Itemize
22229
22230 use an on target hardware debugger.
22231  Some of the more modern MCUs include hardware support for setting break
22232  points and monitoring/changing variables by using dedicated hardware pins.
22233  This facility doesn't require additional code to run on the target and
22234  
22235 \emph on 
22236 usually
22237 \emph default 
22238  doesn't affect runtime behaviour until a breakpoint is hit.
22239  For the mcs51 most hardware debuggers use the AOMF
22240 \begin_inset LatexCommand \index{AOMF, AOMF51}
22241
22242 \end_inset 
22243
22244  file (see 
22245 \begin_inset LatexCommand \ref{OMF file}
22246
22247 \end_inset 
22248
22249 ) as input file.
22250  
22251 \layout Standard
22252
22253 Last not least:
22254 \layout Itemize
22255
22256 if you are not familiar with any of the following terms you're likely to
22257  run into problems rather sooner than later: 
22258 \emph on 
22259 volatile
22260 \emph default 
22261
22262 \emph on 
22263 atomic
22264 \emph default 
22265
22266 \emph on 
22267 memory map
22268 \emph default 
22269
22270 \emph on 
22271 overlay
22272 \emph default 
22273 .
22274  As an embedded programmer you 
22275 \emph on 
22276 have
22277 \emph default 
22278  to know them so why not look them up 
22279 \emph on 
22280 before
22281 \emph default 
22282  you have problems?)
22283 \layout Itemize
22284
22285 tell someone else about your problem (actually this is a surprisingly effective
22286  means to hunt down the bug even if the listener is not familiar with your
22287  environment).
22288  As 'failure to communicate' is probably one of the job-induced deformations
22289  of an embedded programmer this is highly encouraged.
22290 \layout Section
22291
22292 Debugging with SDCDB
22293 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22294
22295 \end_inset 
22296
22297
22298 \begin_inset LatexCommand \index{SDCDB (debugger)}
22299
22300 \end_inset 
22301
22302  
22303 \layout Standard
22304
22305 SDCC is distributed with a source level debugger
22306 \begin_inset LatexCommand \index{Debugger}
22307
22308 \end_inset 
22309
22310 .
22311  The debugger uses a command line interface, the command repertoire of the
22312  debugger has been kept as close to gdb
22313 \begin_inset LatexCommand \index{gdb}
22314
22315 \end_inset 
22316
22317  (the GNU debugger) as possible.
22318  The configuration and build process is part of the standard compiler installati
22319 on, which also builds and installs the debugger in the target directory
22320  specified during configuration.
22321  The debugger allows you debug BOTH at the C source and at the ASM source
22322  level.
22323 \layout Subsection
22324
22325 Compiling for Debugging
22326 \layout Standard
22327
22328 The -
22329 \begin_inset ERT
22330 status Collapsed
22331
22332 \layout Standard
22333
22334 \backslash 
22335 /
22336 \end_inset 
22337
22338 -debug
22339 \begin_inset LatexCommand \index{-\/-debug}
22340
22341 \end_inset 
22342
22343  option must be specified for all files for which debug information is to
22344  be generated.
22345  The compiler generates a .adb file for each of these files.
22346  The linker creates the .cdb
22347 \begin_inset LatexCommand \index{<file>.cdb}
22348
22349 \end_inset 
22350
22351  file from the .adb
22352 \begin_inset LatexCommand \index{<file>.adb}
22353
22354 \end_inset 
22355
22356  files and the address information.
22357  This .cdb is used by the debugger.
22358 \layout Subsection
22359
22360 How the Debugger Works
22361 \layout Standard
22362
22363 When the -
22364 \begin_inset ERT
22365 status Collapsed
22366
22367 \layout Standard
22368
22369 \backslash 
22370 /
22371 \end_inset 
22372
22373 -debug option is specified the compiler generates extra symbol information
22374  some of which are put into the assembler source and some are put into the
22375  .adb file.
22376  Then the linker creates the .cdb file from the individual .adb files with
22377  the address information for the symbols.
22378  The debugger reads the symbolic information generated by the compiler &
22379  the address information generated by the linker.
22380  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22381  execution is controlled by the debugger.
22382  When a command is issued for the debugger, it translates it into appropriate
22383  commands for the simulator.
22384  (Currently SDCDM only connects to the simulator but 
22385 \emph on 
22386 newcdb
22387 \emph default 
22388  at 
22389 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22390
22391 \end_inset 
22392
22393  is an effort to connect directly to the hardware.) 
22394 \layout Subsection
22395
22396 Starting the Debugger SDCDB
22397 \layout Standard
22398
22399 The debugger can be started using the following command line.
22400  (Assume the file you are debugging has the file name foo).
22401 \newline 
22402
22403 \newline 
22404
22405 \family sans 
22406 \series bold 
22407 sdcdb foo
22408 \newline 
22409
22410 \family default 
22411 \series default 
22412
22413 \newline 
22414 The debugger will look for the following files.
22415 \layout Itemize
22416
22417 foo.c - the source file.
22418 \layout Itemize
22419
22420 foo.cdb - the debugger symbol information file.
22421 \layout Itemize
22422
22423 foo.ihx - the Intel hex format
22424 \begin_inset LatexCommand \index{Intel hex format}
22425
22426 \end_inset 
22427
22428  object file.
22429 \layout Subsection
22430
22431 SDCDB Command Line Options
22432 \layout Itemize
22433
22434 -
22435 \begin_inset ERT
22436 status Collapsed
22437
22438 \layout Standard
22439
22440 \backslash 
22441 /
22442 \end_inset 
22443
22444 -directory=<source file directory> this option can used to specify the directory
22445  search list.
22446  The debugger will look into the directory list specified for source, cdb
22447  & ihx files.
22448  The items in the directory list must be separated by ':', e.g.
22449  if the source files can be in the directories /home/src1 and /home/src2,
22450  the -
22451 \begin_inset ERT
22452 status Collapsed
22453
22454 \layout Standard
22455
22456 \backslash 
22457 /
22458 \end_inset 
22459
22460 -directory option should be -
22461 \begin_inset ERT
22462 status Collapsed
22463
22464 \layout Standard
22465
22466 \backslash 
22467 /
22468 \end_inset 
22469
22470 -directory=/home/src1:/home/src2.
22471  Note there can be no spaces in the option.
22472  
22473 \layout Itemize
22474
22475 -cd <directory> - change to the <directory>.
22476 \layout Itemize
22477
22478 -fullname - used by GUI front ends.
22479 \layout Itemize
22480
22481 -cpu <cpu-type> - this argument is passed to the simulator please see the
22482  simulator docs for details.
22483 \layout Itemize
22484
22485 -X <Clock frequency > this options is passed to the simulator please see
22486  the simulator docs for details.
22487 \layout Itemize
22488
22489 -s <serial port file> passed to simulator see the simulator docs for details.
22490 \layout Itemize
22491
22492 -S <serial in,out> passed to simulator see the simulator docs for details.
22493 \layout Itemize
22494
22495 -k <port number> passed to simulator see the simulator docs for details.
22496 \layout Subsection
22497
22498 SDCDB Debugger Commands
22499 \layout Standard
22500
22501 As mentioned earlier the command interface for the debugger has been deliberatel
22502 y kept as close the GNU debugger gdb, as possible.
22503  This will help the integration with existing graphical user interfaces
22504  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22505  If you use a graphical user interface for the debugger you can skip this
22506  section.
22507 \layout Subsubsection*
22508
22509 break [line | file:line | function | file:function]
22510 \layout Standard
22511
22512 Set breakpoint at specified line or function:
22513 \newline 
22514
22515 \newline 
22516
22517 \family sans 
22518 \series bold 
22519 sdcdb>break 100 
22520 \newline 
22521 sdcdb>break foo.c:100
22522 \newline 
22523 sdcdb>break funcfoo
22524 \newline 
22525 sdcdb>break foo.c:funcfoo
22526 \layout Subsubsection*
22527
22528 clear [line | file:line | function | file:function ]
22529 \layout Standard
22530
22531 Clear breakpoint at specified line or function:
22532 \newline 
22533
22534 \newline 
22535
22536 \family sans 
22537 \series bold 
22538 sdcdb>clear 100
22539 \newline 
22540 sdcdb>clear foo.c:100
22541 \newline 
22542 sdcdb>clear funcfoo
22543 \newline 
22544 sdcdb>clear foo.c:funcfoo
22545 \layout Subsubsection*
22546
22547 continue
22548 \layout Standard
22549
22550 Continue program being debugged, after breakpoint.
22551 \layout Subsubsection*
22552
22553 finish
22554 \layout Standard
22555
22556 Execute till the end of the current function.
22557 \layout Subsubsection*
22558
22559 delete [n]
22560 \layout Standard
22561
22562 Delete breakpoint number 'n'.
22563  If used without any option clear ALL user defined break points.
22564 \layout Subsubsection*
22565
22566 info [break | stack | frame | registers ]
22567 \layout Itemize
22568
22569 info break - list all breakpoints
22570 \layout Itemize
22571
22572 info stack - show the function call stack.
22573 \layout Itemize
22574
22575 info frame - show information about the current execution frame.
22576 \layout Itemize
22577
22578 info registers - show content of all registers.
22579 \layout Subsubsection*
22580
22581 step
22582 \layout Standard
22583
22584 Step program until it reaches a different source line.
22585  Note: pressing <return> repeats the last command.
22586 \layout Subsubsection*
22587
22588 next
22589 \layout Standard
22590
22591 Step program, proceeding through subroutine calls.
22592 \layout Subsubsection*
22593
22594 run
22595 \layout Standard
22596
22597 Start debugged program.
22598 \layout Subsubsection*
22599
22600 ptype variable 
22601 \layout Standard
22602
22603 Print type information of the variable.
22604 \layout Subsubsection*
22605
22606 print variable
22607 \layout Standard
22608
22609 print value of variable.
22610 \layout Subsubsection*
22611
22612 file filename
22613 \layout Standard
22614
22615 load the given file name.
22616  Note this is an alternate method of loading file for debugging.
22617 \layout Subsubsection*
22618
22619 frame
22620 \layout Standard
22621
22622 print information about current frame.
22623 \layout Subsubsection*
22624
22625 set srcmode
22626 \layout Standard
22627
22628 Toggle between C source & assembly source.
22629 \layout Subsubsection*
22630
22631 ! simulator command
22632 \layout Standard
22633
22634 Send the string following '!' to the simulator, the simulator response is
22635  displayed.
22636  Note the debugger does not interpret the command being sent to the simulator,
22637  so if a command like 'go' is sent the debugger can loose its execution
22638  context and may display incorrect values.
22639 \layout Subsubsection*
22640
22641 quit
22642 \layout Standard
22643
22644 "Watch me now.
22645  Iam going Down.
22646  My name is Bobby Brown"
22647 \layout Subsection
22648
22649 Interfacing SDCDB with DDD
22650 \layout Comment
22651
22652 The screenshot was converted from png to eps with: 
22653 \begin_inset Quotes sld
22654 \end_inset 
22655
22656 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22657 \begin_inset Quotes srd
22658 \end_inset 
22659
22660  which produces a pretty compact eps file which is free from compression
22661  artifacts.
22662 \layout Comment
22663
22664 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22665  as this broke the build system on Sourceforge (pdf-file was broken.
22666  pdflatex does not accept eps files).
22667 \layout Standard
22668
22669 The 
22670 \emph on 
22671 p
22672 \emph default 
22673 ortable 
22674 \emph on 
22675 n
22676 \emph default 
22677 etwork 
22678 \emph on 
22679 g
22680 \emph default 
22681 raphics File 
22682 \size footnotesize 
22683
22684 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22685
22686 \end_inset 
22687
22688
22689 \size default 
22690  shows a screenshot of a debugging session with DDD
22691 \begin_inset LatexCommand \index{DDD (debugger)}
22692
22693 \end_inset 
22694
22695  (Unix only) on a simulated 8032.
22696  The debugging session might not run as smoothly as the screenshot suggests.
22697  The debugger allows setting of breakpoints, displaying and changing variables,
22698  single stepping through C and assembler code.
22699  
22700 \newline 
22701 The source was compiled with 
22702 \family sans 
22703 \series bold 
22704
22705 \newline 
22706
22707 \newline 
22708 sdcc -
22709 \family default 
22710 \series default 
22711
22712 \begin_inset ERT
22713 status Collapsed
22714
22715 \layout Standard
22716
22717 \backslash 
22718 /
22719 \end_inset 
22720
22721
22722 \family sans 
22723 \series bold 
22724 -debug ddd_example.c
22725 \family default 
22726 \series default 
22727  
22728 \family sans 
22729 \series bold 
22730
22731 \newline 
22732
22733 \family default 
22734 \series default 
22735
22736 \newline 
22737 and DDD was invoked with 
22738 \family sans 
22739 \series bold 
22740
22741 \newline 
22742
22743 \newline 
22744 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22745 \layout Subsection
22746
22747 Interfacing SDCDB with XEmacs
22748 \begin_inset LatexCommand \index{XEmacs}
22749
22750 \end_inset 
22751
22752
22753 \begin_inset LatexCommand \index{Emacs}
22754
22755 \end_inset 
22756
22757
22758 \layout Standard
22759
22760 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22761  sdcdb.el and sdcdbsrc.el.
22762  These two files can be found in the $(prefix)/bin directory after the installat
22763 ion is complete.
22764  These files need to be loaded into XEmacs for the interface to work.
22765  This can be done at XEmacs startup time by inserting the following into
22766  your '.xemacs' file (which can be found in your HOME directory): 
22767 \newline 
22768
22769 \newline 
22770
22771 \family typewriter 
22772 (load-file sdcdbsrc.el) 
22773 \family default 
22774
22775 \newline 
22776
22777 \newline 
22778 .xemacs is a lisp file so the () around the command is REQUIRED.
22779  The files can also be loaded dynamically while XEmacs is running, set the
22780  environment variable 'EMACSLOADPATH' to the installation bin directory
22781  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22782  To start the interface enter the following command: 
22783 \newline 
22784
22785 \newline 
22786
22787 \family sans 
22788 \series bold 
22789 ESC-x sdcdbsrc
22790 \family default 
22791 \series default 
22792
22793 \newline 
22794
22795 \newline 
22796 You will prompted to enter the file name to be debugged.
22797  
22798 \newline 
22799
22800 \newline 
22801 The command line options that are passed to the simulator directly are bound
22802  to default values in the file sdcdbsrc.el.
22803  The variables are listed below, these values maybe changed as required.
22804 \layout Itemize
22805
22806 sdcdbsrc-cpu-type '51
22807 \layout Itemize
22808
22809 sdcdbsrc-frequency '11059200
22810 \layout Itemize
22811
22812 sdcdbsrc-serial nil
22813 \layout Standard
22814
22815 The following is a list of key mapping for the debugger interface.
22816 \layout Standard
22817
22818 \SpecialChar ~
22819
22820 \family typewriter 
22821
22822 \newline 
22823 ;;\SpecialChar ~
22824 Current Listing :: 
22825 \newline 
22826 ;;key\SpecialChar ~
22827 \SpecialChar ~
22828 \SpecialChar ~
22829 \SpecialChar ~
22830 \SpecialChar ~
22831 \SpecialChar ~
22832 \SpecialChar ~
22833 \SpecialChar ~
22834 \SpecialChar ~
22835 \SpecialChar ~
22836 \SpecialChar ~
22837 \SpecialChar ~
22838 \SpecialChar ~
22839 \SpecialChar ~
22840 binding\SpecialChar ~
22841 \SpecialChar ~
22842 \SpecialChar ~
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 \SpecialChar ~
22846 \SpecialChar ~
22847 \SpecialChar ~
22848 \SpecialChar ~
22849 \SpecialChar ~
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 \SpecialChar ~
22853 \SpecialChar ~
22854 \SpecialChar ~
22855 \SpecialChar ~
22856 \SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 \SpecialChar ~
22862 Comment 
22863 \newline 
22864 ;;---\SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 \SpecialChar ~
22872 \SpecialChar ~
22873 \SpecialChar ~
22874 \SpecialChar ~
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 -------\SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 \SpecialChar ~
22886 \SpecialChar ~
22887 \SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 -------
22901 \newline 
22902 ;; 
22903 \newline 
22904 ;;\SpecialChar ~
22905 n\SpecialChar ~
22906 \SpecialChar ~
22907 \SpecialChar ~
22908 \SpecialChar ~
22909 \SpecialChar ~
22910 \SpecialChar ~
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 \SpecialChar ~
22914 \SpecialChar ~
22915 \SpecialChar ~
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 \SpecialChar ~
22920 sdcdb-next-from-src\SpecialChar ~
22921 \SpecialChar ~
22922 \SpecialChar ~
22923 \SpecialChar ~
22924 \SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 SDCDB next command 
22931 \newline 
22932 ;;\SpecialChar ~
22933 b\SpecialChar ~
22934 \SpecialChar ~
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 \SpecialChar ~
22938 \SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 \SpecialChar ~
22943 \SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 sdcdb-back-from-src\SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 \SpecialChar ~
22953 \SpecialChar ~
22954 \SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 SDCDB back command 
22959 \newline 
22960 ;;\SpecialChar ~
22961 c\SpecialChar ~
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 \SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 \SpecialChar ~
22969 \SpecialChar ~
22970 \SpecialChar ~
22971 \SpecialChar ~
22972 \SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 sdcdb-cont-from-src\SpecialChar ~
22977 \SpecialChar ~
22978 \SpecialChar ~
22979 \SpecialChar ~
22980 \SpecialChar ~
22981 \SpecialChar ~
22982 \SpecialChar ~
22983 \SpecialChar ~
22984 \SpecialChar ~
22985 \SpecialChar ~
22986 SDCDB continue command
22987 \newline 
22988 ;;\SpecialChar ~
22989 s\SpecialChar ~
22990 \SpecialChar ~
22991 \SpecialChar ~
22992 \SpecialChar ~
22993 \SpecialChar ~
22994 \SpecialChar ~
22995 \SpecialChar ~
22996 \SpecialChar ~
22997 \SpecialChar ~
22998 \SpecialChar ~
22999 \SpecialChar ~
23000 \SpecialChar ~
23001 \SpecialChar ~
23002 \SpecialChar ~
23003 \SpecialChar ~
23004 sdcdb-step-from-src\SpecialChar ~
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 \SpecialChar ~
23008 \SpecialChar ~
23009 \SpecialChar ~
23010 \SpecialChar ~
23011 \SpecialChar ~
23012 \SpecialChar ~
23013 \SpecialChar ~
23014 SDCDB step command 
23015 \newline 
23016 ;;\SpecialChar ~
23017 ?\SpecialChar ~
23018 \SpecialChar ~
23019 \SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 \SpecialChar ~
23025 \SpecialChar ~
23026 \SpecialChar ~
23027 \SpecialChar ~
23028 \SpecialChar ~
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 \SpecialChar ~
23032 sdcdb-whatis-c-sexp\SpecialChar ~
23033 \SpecialChar ~
23034 \SpecialChar ~
23035 \SpecialChar ~
23036 \SpecialChar ~
23037 \SpecialChar ~
23038 \SpecialChar ~
23039 \SpecialChar ~
23040 \SpecialChar ~
23041 \SpecialChar ~
23042 SDCDB ptypecommand for data at 
23043 \newline 
23044 ;;\SpecialChar ~
23045 \SpecialChar ~
23046 \SpecialChar ~
23047 \SpecialChar ~
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 \SpecialChar ~
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 \SpecialChar ~
23056 \SpecialChar ~
23057 \SpecialChar ~
23058 \SpecialChar ~
23059 \SpecialChar ~
23060 \SpecialChar ~
23061 \SpecialChar ~
23062 \SpecialChar ~
23063 \SpecialChar ~
23064 \SpecialChar ~
23065 \SpecialChar ~
23066 \SpecialChar ~
23067 \SpecialChar ~
23068 \SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 \SpecialChar ~
23073 \SpecialChar ~
23074 \SpecialChar ~
23075 \SpecialChar ~
23076 \SpecialChar ~
23077 \SpecialChar ~
23078 \SpecialChar ~
23079 \SpecialChar ~
23080 \SpecialChar ~
23081 \SpecialChar ~
23082 \SpecialChar ~
23083 \SpecialChar ~
23084 \SpecialChar ~
23085 \SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 buffer point 
23092 \newline 
23093 ;;\SpecialChar ~
23094 x\SpecialChar ~
23095 \SpecialChar ~
23096 \SpecialChar ~
23097 \SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 sdcdbsrc-delete\SpecialChar ~
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 SDCDB Delete all breakpoints if no arg 
23124 \newline 
23125 ;;\SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 \SpecialChar ~
23133 \SpecialChar ~
23134 \SpecialChar ~
23135 \SpecialChar ~
23136 \SpecialChar ~
23137 \SpecialChar ~
23138 \SpecialChar ~
23139 \SpecialChar ~
23140 \SpecialChar ~
23141 \SpecialChar ~
23142 \SpecialChar ~
23143 \SpecialChar ~
23144 \SpecialChar ~
23145 \SpecialChar ~
23146 \SpecialChar ~
23147 \SpecialChar ~
23148 \SpecialChar ~
23149 \SpecialChar ~
23150 \SpecialChar ~
23151 \SpecialChar ~
23152 \SpecialChar ~
23153 \SpecialChar ~
23154 \SpecialChar ~
23155 \SpecialChar ~
23156 \SpecialChar ~
23157 \SpecialChar ~
23158 \SpecialChar ~
23159 \SpecialChar ~
23160 \SpecialChar ~
23161 \SpecialChar ~
23162 \SpecialChar ~
23163 \SpecialChar ~
23164 \SpecialChar ~
23165 \SpecialChar ~
23166 \SpecialChar ~
23167 \SpecialChar ~
23168 \SpecialChar ~
23169 \SpecialChar ~
23170 \SpecialChar ~
23171 \SpecialChar ~
23172 given or delete arg (C-u arg x) 
23173 \newline 
23174 ;;\SpecialChar ~
23175 m\SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 \SpecialChar ~
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 \SpecialChar ~
23186 \SpecialChar ~
23187 \SpecialChar ~
23188 \SpecialChar ~
23189 \SpecialChar ~
23190 sdcdbsrc-frame\SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 \SpecialChar ~
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 \SpecialChar ~
23199 \SpecialChar ~
23200 \SpecialChar ~
23201 \SpecialChar ~
23202 \SpecialChar ~
23203 \SpecialChar ~
23204 \SpecialChar ~
23205 SDCDB Display current frame if no arg, 
23206 \newline 
23207 ;;\SpecialChar ~
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 \SpecialChar ~
23211 \SpecialChar ~
23212 \SpecialChar ~
23213 \SpecialChar ~
23214 \SpecialChar ~
23215 \SpecialChar ~
23216 \SpecialChar ~
23217 \SpecialChar ~
23218 \SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226 \SpecialChar ~
23227 \SpecialChar ~
23228 \SpecialChar ~
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235 \SpecialChar ~
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 \SpecialChar ~
23239 \SpecialChar ~
23240 \SpecialChar ~
23241 \SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249 \SpecialChar ~
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 \SpecialChar ~
23253 \SpecialChar ~
23254 given or display frame arg 
23255 \newline 
23256 ;;\SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 \SpecialChar ~
23260 \SpecialChar ~
23261 \SpecialChar ~
23262 \SpecialChar ~
23263 \SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 \SpecialChar ~
23267 \SpecialChar ~
23268 \SpecialChar ~
23269 \SpecialChar ~
23270 \SpecialChar ~
23271 \SpecialChar ~
23272 \SpecialChar ~
23273 \SpecialChar ~
23274 \SpecialChar ~
23275 \SpecialChar ~
23276 \SpecialChar ~
23277 \SpecialChar ~
23278 \SpecialChar ~
23279 \SpecialChar ~
23280 \SpecialChar ~
23281 \SpecialChar ~
23282 \SpecialChar ~
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 \SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 \SpecialChar ~
23290 \SpecialChar ~
23291 \SpecialChar ~
23292 \SpecialChar ~
23293 \SpecialChar ~
23294 \SpecialChar ~
23295 \SpecialChar ~
23296 \SpecialChar ~
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 \SpecialChar ~
23301 \SpecialChar ~
23302 \SpecialChar ~
23303 buffer point 
23304 \newline 
23305 ;;\SpecialChar ~
23306 !\SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 sdcdbsrc-goto-sdcdb\SpecialChar ~
23322 \SpecialChar ~
23323 \SpecialChar ~
23324 \SpecialChar ~
23325 \SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 \SpecialChar ~
23329 \SpecialChar ~
23330 \SpecialChar ~
23331 Goto the SDCDB output buffer 
23332 \newline 
23333 ;;\SpecialChar ~
23334 p\SpecialChar ~
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 sdcdb-print-c-sexp\SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 \SpecialChar ~
23355 \SpecialChar ~
23356 \SpecialChar ~
23357 \SpecialChar ~
23358 \SpecialChar ~
23359 \SpecialChar ~
23360 SDCDB print command for data at 
23361 \newline 
23362 ;;\SpecialChar ~
23363 \SpecialChar ~
23364 \SpecialChar ~
23365 \SpecialChar ~
23366 \SpecialChar ~
23367 \SpecialChar ~
23368 \SpecialChar ~
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 \SpecialChar ~
23372 \SpecialChar ~
23373 \SpecialChar ~
23374 \SpecialChar ~
23375 \SpecialChar ~
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 \SpecialChar ~
23379 \SpecialChar ~
23380 \SpecialChar ~
23381 \SpecialChar ~
23382 \SpecialChar ~
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 \SpecialChar ~
23386 \SpecialChar ~
23387 \SpecialChar ~
23388 \SpecialChar ~
23389 \SpecialChar ~
23390 \SpecialChar ~
23391 \SpecialChar ~
23392 \SpecialChar ~
23393 \SpecialChar ~
23394 \SpecialChar ~
23395 \SpecialChar ~
23396 \SpecialChar ~
23397 \SpecialChar ~
23398 \SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 \SpecialChar ~
23403 \SpecialChar ~
23404 \SpecialChar ~
23405 \SpecialChar ~
23406 \SpecialChar ~
23407 \SpecialChar ~
23408 \SpecialChar ~
23409 buffer point 
23410 \newline 
23411 ;;\SpecialChar ~
23412 g\SpecialChar ~
23413 \SpecialChar ~
23414 \SpecialChar ~
23415 \SpecialChar ~
23416 \SpecialChar ~
23417 \SpecialChar ~
23418 \SpecialChar ~
23419 \SpecialChar ~
23420 \SpecialChar ~
23421 \SpecialChar ~
23422 \SpecialChar ~
23423 \SpecialChar ~
23424 \SpecialChar ~
23425 \SpecialChar ~
23426 \SpecialChar ~
23427 sdcdbsrc-goto-sdcdb\SpecialChar ~
23428 \SpecialChar ~
23429 \SpecialChar ~
23430 \SpecialChar ~
23431 \SpecialChar ~
23432 \SpecialChar ~
23433 \SpecialChar ~
23434 \SpecialChar ~
23435 \SpecialChar ~
23436 \SpecialChar ~
23437 Goto the SDCDB output buffer 
23438 \newline 
23439 ;;\SpecialChar ~
23440 t\SpecialChar ~
23441 \SpecialChar ~
23442 \SpecialChar ~
23443 \SpecialChar ~
23444 \SpecialChar ~
23445 \SpecialChar ~
23446 \SpecialChar ~
23447 \SpecialChar ~
23448 \SpecialChar ~
23449 \SpecialChar ~
23450 \SpecialChar ~
23451 \SpecialChar ~
23452 \SpecialChar ~
23453 \SpecialChar ~
23454 \SpecialChar ~
23455 sdcdbsrc-mode\SpecialChar ~
23456 \SpecialChar ~
23457 \SpecialChar ~
23458 \SpecialChar ~
23459 \SpecialChar ~
23460 \SpecialChar ~
23461 \SpecialChar ~
23462 \SpecialChar ~
23463 \SpecialChar ~
23464 \SpecialChar ~
23465 \SpecialChar ~
23466 \SpecialChar ~
23467 \SpecialChar ~
23468 \SpecialChar ~
23469 \SpecialChar ~
23470 \SpecialChar ~
23471 Toggles Sdcdbsrc mode (turns it off) 
23472 \newline 
23473 ;; 
23474 \newline 
23475 ;;\SpecialChar ~
23476 C-c\SpecialChar ~
23477 C-f\SpecialChar ~
23478 \SpecialChar ~
23479 \SpecialChar ~
23480 \SpecialChar ~
23481 \SpecialChar ~
23482 \SpecialChar ~
23483 \SpecialChar ~
23484 \SpecialChar ~
23485 \SpecialChar ~
23486 sdcdb-finish-from-src\SpecialChar ~
23487 \SpecialChar ~
23488 \SpecialChar ~
23489 \SpecialChar ~
23490 \SpecialChar ~
23491 \SpecialChar ~
23492 \SpecialChar ~
23493 \SpecialChar ~
23494 SDCDB finish command 
23495 \newline 
23496 ;; 
23497 \newline 
23498 ;;\SpecialChar ~
23499 C-x\SpecialChar ~
23500 SPC\SpecialChar ~
23501 \SpecialChar ~
23502 \SpecialChar ~
23503 \SpecialChar ~
23504 \SpecialChar ~
23505 \SpecialChar ~
23506 \SpecialChar ~
23507 \SpecialChar ~
23508 \SpecialChar ~
23509 sdcdb-break\SpecialChar ~
23510 \SpecialChar ~
23511 \SpecialChar ~
23512 \SpecialChar ~
23513 \SpecialChar ~
23514 \SpecialChar ~
23515 \SpecialChar ~
23516 \SpecialChar ~
23517 \SpecialChar ~
23518 \SpecialChar ~
23519 \SpecialChar ~
23520 \SpecialChar ~
23521 \SpecialChar ~
23522 \SpecialChar ~
23523 \SpecialChar ~
23524 \SpecialChar ~
23525 \SpecialChar ~
23526 \SpecialChar ~
23527 Set break for line with point 
23528 \newline 
23529 ;;\SpecialChar ~
23530 ESC\SpecialChar ~
23531 t\SpecialChar ~
23532 \SpecialChar ~
23533 \SpecialChar ~
23534 \SpecialChar ~
23535 \SpecialChar ~
23536 \SpecialChar ~
23537 \SpecialChar ~
23538 \SpecialChar ~
23539 \SpecialChar ~
23540 \SpecialChar ~
23541 \SpecialChar ~
23542 sdcdbsrc-mode\SpecialChar ~
23543 \SpecialChar ~
23544 \SpecialChar ~
23545 \SpecialChar ~
23546 \SpecialChar ~
23547 \SpecialChar ~
23548 \SpecialChar ~
23549 \SpecialChar ~
23550 \SpecialChar ~
23551 \SpecialChar ~
23552 \SpecialChar ~
23553 \SpecialChar ~
23554 \SpecialChar ~
23555 \SpecialChar ~
23556 \SpecialChar ~
23557 \SpecialChar ~
23558 Toggle Sdcdbsrc mode 
23559 \newline 
23560 ;;\SpecialChar ~
23561 ESC\SpecialChar ~
23562 m\SpecialChar ~
23563 \SpecialChar ~
23564 \SpecialChar ~
23565 \SpecialChar ~
23566 \SpecialChar ~
23567 \SpecialChar ~
23568 \SpecialChar ~
23569 \SpecialChar ~
23570 \SpecialChar ~
23571 \SpecialChar ~
23572 \SpecialChar ~
23573 sdcdbsrc-srcmode\SpecialChar ~
23574 \SpecialChar ~
23575 \SpecialChar ~
23576 \SpecialChar ~
23577 \SpecialChar ~
23578 \SpecialChar ~
23579 \SpecialChar ~
23580 \SpecialChar ~
23581 \SpecialChar ~
23582 \SpecialChar ~
23583 \SpecialChar ~
23584 \SpecialChar ~
23585 \SpecialChar ~
23586 Toggle list mode 
23587 \newline 
23588 ;; 
23589 \newline 
23590
23591 \layout Chapter
23592 \pagebreak_top 
23593 TIPS
23594 \layout Standard
23595
23596 Here are a few guidelines that will help the compiler generate more efficient
23597  code, some of the tips are specific to this compiler others are generally
23598  good programming practice.
23599 \layout Itemize
23600
23601 Use the smallest data type to represent your data-value.
23602  If it is known in advance that the value is going to be less than 256 then
23603  use an 'unsigned char' instead of a 'short' or 'int'.
23604  Please note, that ANSI C requires both signed and unsigned chars to be
23605  promoted to 'signed int'
23606 \begin_inset LatexCommand \index{promotion to signed int}
23607
23608 \end_inset 
23609
23610
23611 \begin_inset Marginal
23612 collapsed true
23613
23614 \layout Standard
23615
23616
23617 \series bold 
23618 \SpecialChar ~
23619 !
23620 \end_inset 
23621
23622  before doing any operation.
23623  This promotion
23624 \begin_inset LatexCommand \index{type promotion}
23625
23626 \end_inset 
23627
23628
23629 \begin_inset LatexCommand \label{type promotion}
23630
23631 \end_inset 
23632
23633  can be omitted, if the result is the same.
23634  The effect of the promotion rules together with the sign-extension is often
23635  surprising:
23636 \begin_deeper 
23637 \layout Verse
23638
23639
23640 \family typewriter 
23641 unsigned char uc = 0xfe;
23642 \newline 
23643 if (uc * uc < 0) /* this is true! */
23644 \newline 
23645 {
23646 \newline 
23647 \SpecialChar ~
23648 \SpecialChar ~
23649 \SpecialChar ~
23650 \SpecialChar ~
23651 ....
23652 \newline 
23653 }
23654 \layout Standard
23655
23656
23657 \family typewriter 
23658 uc * uc
23659 \family default 
23660  is evaluated as 
23661 \family typewriter 
23662 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23663 \family default 
23664 .
23665  
23666 \newline 
23667 Another one:
23668 \layout Verse
23669
23670
23671 \family typewriter 
23672 (unsigned char) -12 / (signed char) -3 = ...
23673 \layout Standard
23674
23675 No, the result is not 4:
23676 \layout Verse
23677
23678
23679 \family typewriter 
23680 (int) (unsigned char) -12 / (int) (signed char) -3 =
23681 \newline 
23682 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23683 \newline 
23684 (int) 0x00f4 / (int) 0xfffd =
23685 \newline 
23686 (int) 0x00f4 / (int) 0xfffd =
23687 \newline 
23688 (int) 244 / (int) -3 =
23689 \newline 
23690 (int) -81 = (int) 0xffaf;
23691 \layout Standard
23692
23693 Don't complain, that gcc gives you a different result.
23694  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23695  Therefore the results are different.
23696 \newline 
23697 From 
23698 \begin_inset Quotes sld
23699 \end_inset 
23700
23701 comp.lang.c FAQ
23702 \begin_inset Quotes srd
23703 \end_inset 
23704
23705 :
23706 \layout Quote
23707
23708
23709 \emph on 
23710 If well-defined overflow characteristics are important and negative values
23711  are not, or if you want to steer clear of sign-extension problems when
23712  manipulating bits or bytes, use one of the corresponding unsigned types.
23713  (Beware when mixing signed and unsigned values in expressions, though.)
23714 \newline 
23715 Although character types (especially unsigned char) can be used as "tiny"
23716  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23717 ble sign extension and increased code size.
23718 \end_deeper 
23719 \layout Itemize
23720
23721 Use unsigned when it is known in advance that the value is not going to
23722  be negative.
23723  This helps especially if you are doing division or multiplication, bit-shifting
23724  or are using an array index.
23725 \layout Itemize
23726
23727 NEVER jump into a LOOP.
23728 \layout Itemize
23729
23730 Declare the variables to be local
23731 \begin_inset LatexCommand \index{local variables}
23732
23733 \end_inset 
23734
23735  whenever possible, especially loop control variables (induction).
23736 \layout Itemize
23737
23738 Have a look at the assembly listing to get a 
23739 \begin_inset Quotes sld
23740 \end_inset 
23741
23742 feeling
23743 \begin_inset Quotes srd
23744 \end_inset 
23745
23746  for the code generation.
23747 \layout Section
23748
23749 Porting code from or to other compilers
23750 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23751
23752 \end_inset 
23753
23754
23755 \layout Itemize
23756
23757 check whether endianness of the compilers differs and adapt where needed.
23758 \layout Itemize
23759
23760 check the device specific header files
23761 \begin_inset LatexCommand \index{Header files}
23762
23763 \end_inset 
23764
23765
23766 \begin_inset LatexCommand \index{Include files}
23767
23768 \end_inset 
23769
23770  for compiler specific syntax.
23771  Eventually include the file <compiler.h
23772 \begin_inset LatexCommand \index{compiler.h (include file)}
23773
23774 \end_inset 
23775
23776
23777 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23778
23779 \end_inset 
23780
23781  to allow using common header files.
23782  (see f.e.
23783  cc2510fx.h 
23784 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23785
23786 \end_inset 
23787
23788 ).
23789 \layout Itemize
23790
23791 check whether the startup code contains the correct initialization (watchdog,
23792  peripherals).
23793 \layout Itemize
23794
23795 check whether the sizes of short, int, long match.
23796 \layout Itemize
23797
23798 check if some 16 or 32 bit hardware registers require a specific addressing
23799  order (least significant or most significant byte first) and adapt if needed
23800  (
23801 \emph on 
23802 first
23803 \emph default 
23804  and 
23805 \emph on 
23806 last
23807 \emph default 
23808  relate to time and not to lower/upper memory location here, so this is
23809  
23810 \emph on 
23811 not
23812 \emph default 
23813  the same as endianness).
23814 \layout Itemize
23815
23816 check whether the keyword 
23817 \emph on 
23818 volatile
23819 \emph default 
23820  is used where needed.
23821  The compilers might differ in their optimization characteristics (as different
23822  versions of the same compiler might also use more clever optimizations
23823  this is good idea anyway).
23824  See section 
23825 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23826
23827 \end_inset 
23828
23829 .
23830 \layout Itemize
23831
23832 check that the compilers are not told to supress warnings.
23833 \layout Itemize
23834
23835 check and convert compiler specific extensions (interrupts, memory areas,
23836  pragmas etc.).
23837 \layout Itemize
23838
23839 check for differences in type promotion.
23840  Especially check for math operations on 
23841 \family typewriter 
23842 char
23843 \family default 
23844  or 
23845 \family typewriter 
23846 unsigned char
23847 \family default 
23848  variables.
23849  For the sake of C99 compatibility SDCC will probably promote these to 
23850 \family typewriter 
23851 int
23852 \family default 
23853  more often than other compilers.
23854  Eventually insert explicit casts to 
23855 \family typewriter 
23856 (char) 
23857 \family default 
23858 or
23859 \family typewriter 
23860  (unsigned char)
23861 \family default 
23862 .
23863  Also check that the ~\SpecialChar ~
23864 operator
23865 \begin_inset LatexCommand \index{\~\/ Operator}
23866
23867 \end_inset 
23868
23869  is not used on 
23870 \family typewriter 
23871 bit
23872 \begin_inset LatexCommand \index{bit}
23873
23874 \end_inset 
23875
23876
23877 \family default 
23878  variables, use the !\SpecialChar ~
23879 operator instead.
23880  See sections 
23881 \begin_inset LatexCommand \ref{type promotion}
23882
23883 \end_inset 
23884
23885  and 
23886 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23887
23888 \end_inset 
23889
23890 .
23891 \layout Itemize
23892
23893 check the assembly code generated for interrupt routines (f.e.
23894  for calls to possibly non-reentrant library functions).
23895 \layout Itemize
23896
23897 check whether timing loops result in proper timing (or preferably consider
23898  a rewrite of the code with timer based delays instead).
23899 \layout Itemize
23900
23901 check for differences in printf parameters (some compilers push (va_arg
23902 \begin_inset LatexCommand \index{vararg, va\_arg}
23903
23904 \end_inset 
23905
23906 ) char variables as 
23907 \family typewriter 
23908 int
23909 \family default 
23910  others push them as 
23911 \family typewriter 
23912 char
23913 \family default 
23914 .
23915  See section 
23916 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23917
23918 \end_inset 
23919
23920 ).
23921 \layout Itemize
23922
23923 check the resulting memory map
23924 \begin_inset LatexCommand \index{Memory map}
23925
23926 \end_inset 
23927
23928 .
23929  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23930 ly idata, pdata, xdata).
23931  Eventually check if unexpected library functions are included.
23932 \layout Section
23933
23934 Tools
23935 \begin_inset LatexCommand \index{Tools}
23936
23937 \end_inset 
23938
23939  included in the distribution
23940 \layout Standard
23941 \align left 
23942
23943 \begin_inset  Tabular
23944 <lyxtabular version="3" rows="12" columns="3">
23945 <features>
23946 <column alignment="left" valignment="top" leftline="true" width="0pt">
23947 <column alignment="left" valignment="top" leftline="true" width="0pt">
23948 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23949 <row topline="true" bottomline="true">
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23951 \begin_inset Text
23952
23953 \layout Standard
23954
23955
23956 \series bold 
23957 Name
23958 \end_inset 
23959 </cell>
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23961 \begin_inset Text
23962
23963 \layout Standard
23964
23965
23966 \series bold 
23967 Purpose
23968 \end_inset 
23969 </cell>
23970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23971 \begin_inset Text
23972
23973 \layout Standard
23974
23975
23976 \series bold 
23977 Directory
23978 \end_inset 
23979 </cell>
23980 </row>
23981 <row topline="true">
23982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23983 \begin_inset Text
23984
23985 \layout Standard
23986
23987 ucSsim
23988 \end_inset 
23989 </cell>
23990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23991 \begin_inset Text
23992
23993 \layout Standard
23994
23995 Simulator for various architectures
23996 \end_inset 
23997 </cell>
23998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23999 \begin_inset Text
24000
24001 \layout Standard
24002
24003 sdcc/sim/ucsim
24004 \end_inset 
24005 </cell>
24006 </row>
24007 <row topline="true">
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24009 \begin_inset Text
24010
24011 \layout Standard
24012
24013 keil2sdcc.pl
24014 \end_inset 
24015 </cell>
24016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24017 \begin_inset Text
24018
24019 \layout Standard
24020
24021 header file
24022 \begin_inset LatexCommand \index{Header files}
24023
24024 \end_inset 
24025
24026
24027 \begin_inset LatexCommand \index{Include files}
24028
24029 \end_inset 
24030
24031  conversion
24032 \end_inset 
24033 </cell>
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24035 \begin_inset Text
24036
24037 \layout Standard
24038
24039 sdcc/support/scripts
24040 \end_inset 
24041 </cell>
24042 </row>
24043 <row topline="true">
24044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24045 \begin_inset Text
24046
24047 \layout Standard
24048
24049 mh2h.c
24050 \end_inset 
24051 </cell>
24052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24053 \begin_inset Text
24054
24055 \layout Standard
24056
24057 header file conversion
24058 \end_inset 
24059 </cell>
24060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24061 \begin_inset Text
24062
24063 \layout Standard
24064
24065 sdcc/support/scripts
24066 \end_inset 
24067 </cell>
24068 </row>
24069 <row topline="true">
24070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24071 \begin_inset Text
24072
24073 \layout Standard
24074
24075 as-gbz80
24076 \end_inset 
24077 </cell>
24078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24079 \begin_inset Text
24080
24081 \layout Standard
24082
24083 Assembler
24084 \end_inset 
24085 </cell>
24086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24087 \begin_inset Text
24088
24089 \layout Standard
24090
24091
24092 \family roman 
24093 \series medium 
24094 \shape up 
24095 \size normal 
24096 \emph off 
24097 \bar no 
24098 \noun off 
24099 \color none
24100 sdcc/bin
24101 \end_inset 
24102 </cell>
24103 </row>
24104 <row topline="true">
24105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24106 \begin_inset Text
24107
24108 \layout Standard
24109
24110 as-z80
24111 \end_inset 
24112 </cell>
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24114 \begin_inset Text
24115
24116 \layout Standard
24117
24118 Assembler
24119 \end_inset 
24120 </cell>
24121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24122 \begin_inset Text
24123
24124 \layout Standard
24125
24126
24127 \family roman 
24128 \series medium 
24129 \shape up 
24130 \size normal 
24131 \emph off 
24132 \bar no 
24133 \noun off 
24134 \color none
24135 sdcc/bin
24136 \end_inset 
24137 </cell>
24138 </row>
24139 <row topline="true">
24140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24141 \begin_inset Text
24142
24143 \layout Standard
24144
24145 asx8051
24146 \end_inset 
24147 </cell>
24148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24149 \begin_inset Text
24150
24151 \layout Standard
24152
24153 Assembler
24154 \end_inset 
24155 </cell>
24156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24157 \begin_inset Text
24158
24159 \layout Standard
24160
24161
24162 \family roman 
24163 \series medium 
24164 \shape up 
24165 \size normal 
24166 \emph off 
24167 \bar no 
24168 \noun off 
24169 \color none
24170 sdcc/bin
24171 \end_inset 
24172 </cell>
24173 </row>
24174 <row topline="true">
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24176 \begin_inset Text
24177
24178 \layout Standard
24179
24180 SDCDB
24181 \end_inset 
24182 </cell>
24183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24184 \begin_inset Text
24185
24186 \layout Standard
24187
24188 Simulator
24189 \end_inset 
24190 </cell>
24191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24192 \begin_inset Text
24193
24194 \layout Standard
24195
24196
24197 \family roman 
24198 \series medium 
24199 \shape up 
24200 \size normal 
24201 \emph off 
24202 \bar no 
24203 \noun off 
24204 \color none
24205 sdcc/bin
24206 \end_inset 
24207 </cell>
24208 </row>
24209 <row topline="true">
24210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24211 \begin_inset Text
24212
24213 \layout Standard
24214
24215 aslink
24216 \end_inset 
24217 </cell>
24218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24219 \begin_inset Text
24220
24221 \layout Standard
24222
24223 Linker
24224 \end_inset 
24225 </cell>
24226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24227 \begin_inset Text
24228
24229 \layout Standard
24230
24231
24232 \family roman 
24233 \series medium 
24234 \shape up 
24235 \size normal 
24236 \emph off 
24237 \bar no 
24238 \noun off 
24239 \color none
24240 sdcc/bin
24241 \end_inset 
24242 </cell>
24243 </row>
24244 <row topline="true">
24245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24246 \begin_inset Text
24247
24248 \layout Standard
24249
24250 link-z80
24251 \end_inset 
24252 </cell>
24253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24254 \begin_inset Text
24255
24256 \layout Standard
24257
24258 Linker
24259 \end_inset 
24260 </cell>
24261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24262 \begin_inset Text
24263
24264 \layout Standard
24265
24266
24267 \family roman 
24268 \series medium 
24269 \shape up 
24270 \size normal 
24271 \emph off 
24272 \bar no 
24273 \noun off 
24274 \color none
24275 sdcc/bin
24276 \end_inset 
24277 </cell>
24278 </row>
24279 <row topline="true">
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24281 \begin_inset Text
24282
24283 \layout Standard
24284
24285 link-gbz80
24286 \end_inset 
24287 </cell>
24288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24289 \begin_inset Text
24290
24291 \layout Standard
24292
24293 Linker
24294 \end_inset 
24295 </cell>
24296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24297 \begin_inset Text
24298
24299 \layout Standard
24300
24301
24302 \family roman 
24303 \series medium 
24304 \shape up 
24305 \size normal 
24306 \emph off 
24307 \bar no 
24308 \noun off 
24309 \color none
24310 sdcc/bin
24311 \end_inset 
24312 </cell>
24313 </row>
24314 <row topline="true" bottomline="true">
24315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24316 \begin_inset Text
24317
24318 \layout Standard
24319
24320 packihx
24321 \end_inset 
24322 </cell>
24323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24324 \begin_inset Text
24325
24326 \layout Standard
24327
24328 Intel Hex packer 
24329 \begin_inset LatexCommand \index{packihx (tool)}
24330
24331 \end_inset 
24332
24333
24334 \end_inset 
24335 </cell>
24336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24337 \begin_inset Text
24338
24339 \layout Standard
24340
24341
24342 \family roman 
24343 \series medium 
24344 \shape up 
24345 \size normal 
24346 \emph off 
24347 \bar no 
24348 \noun off 
24349 \color none
24350 sdcc/bin
24351 \end_inset 
24352 </cell>
24353 </row>
24354 </lyxtabular>
24355
24356 \end_inset 
24357
24358
24359 \newline 
24360
24361 \layout Section
24362
24363 Documentation
24364 \begin_inset LatexCommand \index{Documentation}
24365
24366 \end_inset 
24367
24368  included in the distribution
24369 \layout Standard
24370 \align left 
24371
24372 \begin_inset  Tabular
24373 <lyxtabular version="3" rows="10" columns="2">
24374 <features>
24375 <column alignment="block" valignment="top" leftline="true" width="40col%">
24376 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
24377 <row topline="true" bottomline="true" endhead="true">
24378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24379 \begin_inset Text
24380
24381 \layout Standard
24382
24383
24384 \series bold 
24385 Subject / Title
24386 \end_inset 
24387 </cell>
24388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24389 \begin_inset Text
24390
24391 \layout Standard
24392
24393
24394 \series bold 
24395 Filename / Where to get
24396 \end_inset 
24397 </cell>
24398 </row>
24399 <row topline="true">
24400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24401 \begin_inset Text
24402
24403 \layout Standard
24404
24405 SDCC Compiler User Guide
24406 \end_inset 
24407 </cell>
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24409 \begin_inset Text
24410
24411 \layout Standard
24412
24413 You're reading it right now
24414 \emph on 
24415  \SpecialChar ~
24416 \SpecialChar ~
24417 \SpecialChar ~
24418
24419 \hfill 
24420 online at:
24421 \emph default 
24422
24423 \newline 
24424
24425 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
24426
24427 \end_inset 
24428
24429
24430 \end_inset 
24431 </cell>
24432 </row>
24433 <row topline="true">
24434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24435 \begin_inset Text
24436
24437 \layout Standard
24438
24439 Changelog of SDCC
24440 \end_inset 
24441 </cell>
24442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24443 \begin_inset Text
24444
24445 \layout Standard
24446
24447 sdcc/Changelog
24448 \emph on 
24449  \SpecialChar ~
24450 \SpecialChar ~
24451 \SpecialChar ~
24452
24453 \hfill 
24454 online at:
24455 \emph default 
24456
24457 \newline 
24458
24459 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
24460
24461 \end_inset 
24462
24463
24464 \end_inset 
24465 </cell>
24466 </row>
24467 <row topline="true">
24468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24469 \begin_inset Text
24470
24471 \layout Standard
24472
24473 ASXXXX
24474 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24475
24476 \end_inset 
24477
24478
24479 \begin_inset LatexCommand \index{Assembler documentation}
24480
24481 \end_inset 
24482
24483  Assemblers and
24484 \newline 
24485 ASLINK
24486 \begin_inset LatexCommand \index{aslink}
24487
24488 \end_inset 
24489
24490
24491 \begin_inset LatexCommand \index{Linker documentation}
24492
24493 \end_inset 
24494
24495  Relocating Linker
24496 \end_inset 
24497 </cell>
24498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24499 \begin_inset Text
24500
24501 \layout Standard
24502
24503 sdcc/as/doc/asxhtm.html 
24504 \emph on 
24505 \SpecialChar ~
24506 \SpecialChar ~
24507 \SpecialChar ~
24508
24509 \hfill 
24510 online at:
24511 \emph default 
24512
24513 \newline 
24514
24515 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
24516
24517 \end_inset 
24518
24519
24520 \end_inset 
24521 </cell>
24522 </row>
24523 <row topline="true">
24524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24525 \begin_inset Text
24526
24527 \layout Standard
24528
24529 SDCC regression test
24530 \begin_inset LatexCommand \index{Regression test}
24531
24532 \end_inset 
24533
24534
24535 \end_inset 
24536 </cell>
24537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24538 \begin_inset Text
24539
24540 \layout Standard
24541
24542 sdcc/doc/test_suite_spec.pdf 
24543 \emph on 
24544 \SpecialChar ~
24545 \SpecialChar ~
24546 \SpecialChar ~
24547
24548 \hfill 
24549 online at:
24550 \emph default 
24551
24552 \newline 
24553
24554 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
24555
24556 \end_inset 
24557
24558
24559 \end_inset 
24560 </cell>
24561 </row>
24562 <row topline="true">
24563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24564 \begin_inset Text
24565
24566 \layout Standard
24567
24568 Various notes
24569 \end_inset 
24570 </cell>
24571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24572 \begin_inset Text
24573
24574 \layout Standard
24575
24576 sdcc/doc/* 
24577 \emph on 
24578 \SpecialChar ~
24579 \SpecialChar ~
24580 \SpecialChar ~
24581
24582 \hfill 
24583 online at:
24584 \emph default 
24585
24586 \newline 
24587
24588 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
24589
24590 \end_inset 
24591
24592
24593 \end_inset 
24594 </cell>
24595 </row>
24596 <row topline="true">
24597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24598 \begin_inset Text
24599
24600 \layout Standard
24601
24602 Notes on debugging with SDCDB
24603 \begin_inset LatexCommand \index{SDCDB (debugger)}
24604
24605 \end_inset 
24606
24607
24608 \end_inset 
24609 </cell>
24610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24611 \begin_inset Text
24612
24613 \layout Standard
24614
24615 sdcc/debugger/README 
24616 \emph on 
24617 \SpecialChar ~
24618 \SpecialChar ~
24619 \SpecialChar ~
24620
24621 \hfill 
24622 online at
24623 \emph default 
24624 :
24625 \newline 
24626
24627 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
24628
24629 \end_inset 
24630
24631
24632 \end_inset 
24633 </cell>
24634 </row>
24635 <row topline="true">
24636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24637 \begin_inset Text
24638
24639 \layout Standard
24640
24641 Software simulator for microcontrollers
24642 \end_inset 
24643 </cell>
24644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24645 \begin_inset Text
24646
24647 \layout Standard
24648
24649
24650 \family roman 
24651 \series medium 
24652 \shape up 
24653 \size normal 
24654 \emph off 
24655 \bar no 
24656 \noun off 
24657 \color none
24658 sdcc/sim/ucsim/doc
24659 \family default 
24660 \series default 
24661 \shape default 
24662 \size default 
24663 \emph default 
24664 \bar default 
24665 \noun default 
24666 \color default
24667 /index.html 
24668 \emph on 
24669 \SpecialChar ~
24670 \SpecialChar ~
24671 \SpecialChar ~
24672
24673 \hfill 
24674 online at:
24675 \emph default 
24676
24677 \newline 
24678
24679 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
24680
24681 \end_inset 
24682
24683
24684 \end_inset 
24685 </cell>
24686 </row>
24687 <row topline="true">
24688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24689 \begin_inset Text
24690
24691 \layout Standard
24692
24693 Temporary notes on the pic16
24694 \begin_inset LatexCommand \index{PIC16}
24695
24696 \end_inset 
24697
24698  port
24699 \end_inset 
24700 </cell>
24701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24702 \begin_inset Text
24703
24704 \layout Standard
24705
24706 sdcc/src/pic16/NOTES 
24707 \emph on 
24708 \SpecialChar ~
24709 \SpecialChar ~
24710 \SpecialChar ~
24711
24712 \hfill 
24713 online at:
24714 \newline 
24715
24716 \emph default 
24717
24718 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
24719
24720 \end_inset 
24721
24722
24723 \end_inset 
24724 </cell>
24725 </row>
24726 <row topline="true" bottomline="true">
24727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24728 \begin_inset Text
24729
24730 \layout Standard
24731
24732 SDCC internal documentation (debugging file format)
24733 \end_inset 
24734 </cell>
24735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24736 \begin_inset Text
24737
24738 \layout Standard
24739
24740 sdcc/doc/
24741 \family roman 
24742 \series medium 
24743 \shape up 
24744 \size normal 
24745 \emph off 
24746 \bar no 
24747 \noun off 
24748 \color none
24749 cdbfileformat.pd
24750 \family default 
24751 \series default 
24752 \shape default 
24753 \size default 
24754 \emph default 
24755 \bar default 
24756 \noun default 
24757 \color default
24758 f
24759 \emph on 
24760  \SpecialChar ~
24761 \SpecialChar ~
24762 \SpecialChar ~
24763
24764 \hfill 
24765 online at:
24766 \emph default 
24767
24768 \newline 
24769
24770 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
24771
24772 \end_inset 
24773
24774
24775 \end_inset 
24776 </cell>
24777 </row>
24778 </lyxtabular>
24779
24780 \end_inset 
24781
24782
24783 \newline 
24784
24785 \layout Section
24786
24787 Related open source tools
24788 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24789
24790 \end_inset 
24791
24792
24793 \begin_inset LatexCommand \index{Related tools}
24794
24795 \end_inset 
24796
24797
24798 \layout Standard
24799 \align left 
24800
24801 \begin_inset  Tabular
24802 <lyxtabular version="3" rows="14" columns="3">
24803 <features>
24804 <column alignment="left" valignment="top" leftline="true" width="0pt">
24805 <column alignment="block" valignment="top" leftline="true" width="30line%">
24806 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24807 <row topline="true" bottomline="true">
24808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24809 \begin_inset Text
24810
24811 \layout Standard
24812
24813
24814 \series bold 
24815 Name
24816 \end_inset 
24817 </cell>
24818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24819 \begin_inset Text
24820
24821 \layout Standard
24822
24823
24824 \series bold 
24825 Purpose
24826 \end_inset 
24827 </cell>
24828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24829 \begin_inset Text
24830
24831 \layout Standard
24832
24833
24834 \series bold 
24835 Where to get
24836 \end_inset 
24837 </cell>
24838 </row>
24839 <row topline="true">
24840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24841 \begin_inset Text
24842
24843 \layout Standard
24844
24845 gpsim
24846 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24847
24848 \end_inset 
24849
24850
24851 \end_inset 
24852 </cell>
24853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24854 \begin_inset Text
24855
24856 \layout Standard
24857
24858 PIC simulator
24859 \end_inset 
24860 </cell>
24861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24862 \begin_inset Text
24863
24864 \layout Standard
24865
24866
24867 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24868
24869 \end_inset 
24870
24871
24872 \end_inset 
24873 </cell>
24874 </row>
24875 <row topline="true">
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24877 \begin_inset Text
24878
24879 \layout Standard
24880
24881 gputils
24882 \begin_inset LatexCommand \index{gputils (pic tools)}
24883
24884 \end_inset 
24885
24886
24887 \end_inset 
24888 </cell>
24889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24890 \begin_inset Text
24891
24892 \layout Standard
24893
24894 GNU PIC utilities
24895 \end_inset 
24896 </cell>
24897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24898 \begin_inset Text
24899
24900 \layout Standard
24901
24902
24903 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24904
24905 \end_inset 
24906
24907
24908 \end_inset 
24909 </cell>
24910 </row>
24911 <row topline="true">
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24913 \begin_inset Text
24914
24915 \layout Standard
24916
24917 flP5
24918 \end_inset 
24919 </cell>
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24921 \begin_inset Text
24922
24923 \layout Standard
24924
24925 PIC programmer
24926 \end_inset 
24927 </cell>
24928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24929 \begin_inset Text
24930
24931 \layout Standard
24932
24933
24934 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24935
24936 \end_inset 
24937
24938
24939 \end_inset 
24940 </cell>
24941 </row>
24942 <row topline="true">
24943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24944 \begin_inset Text
24945
24946 \layout Standard
24947
24948 ec2drv/newcdb
24949 \end_inset 
24950 </cell>
24951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24952 \begin_inset Text
24953
24954 \layout Standard
24955
24956 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24957  (Unix only)
24958 \end_inset 
24959 </cell>
24960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24961 \begin_inset Text
24962
24963 \layout Standard
24964
24965
24966 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24967
24968 \end_inset 
24969
24970
24971 \end_inset 
24972 </cell>
24973 </row>
24974 <row topline="true">
24975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24976 \begin_inset Text
24977
24978 \layout Standard
24979
24980 indent
24981 \begin_inset LatexCommand \index{indent (source formatting tool)}
24982
24983 \end_inset 
24984
24985
24986 \end_inset 
24987 </cell>
24988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24989 \begin_inset Text
24990
24991 \layout Standard
24992
24993 Formats C source - Master of the white spaces
24994 \end_inset 
24995 </cell>
24996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24997 \begin_inset Text
24998
24999 \layout Standard
25000
25001
25002 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
25003
25004 \end_inset 
25005
25006
25007 \end_inset 
25008 </cell>
25009 </row>
25010 <row topline="true">
25011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25012 \begin_inset Text
25013
25014 \layout Standard
25015
25016 srecord
25017 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
25018
25019 \end_inset 
25020
25021
25022 \end_inset 
25023 </cell>
25024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25025 \begin_inset Text
25026
25027 \layout Standard
25028
25029 Object file conversion, checksumming, ...
25030 \end_inset 
25031 </cell>
25032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25033 \begin_inset Text
25034
25035 \layout Standard
25036
25037
25038 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
25039
25040 \end_inset 
25041
25042
25043 \end_inset 
25044 </cell>
25045 </row>
25046 <row topline="true">
25047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25048 \begin_inset Text
25049
25050 \layout Standard
25051
25052 objdump
25053 \begin_inset LatexCommand \index{objdump (tool)}
25054
25055 \end_inset 
25056
25057
25058 \end_inset 
25059 </cell>
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25061 \begin_inset Text
25062
25063 \layout Standard
25064
25065 Object file conversion, ...
25066 \end_inset 
25067 </cell>
25068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25069 \begin_inset Text
25070
25071 \layout Standard
25072
25073 Part of binutils (should be there anyway)
25074 \end_inset 
25075 </cell>
25076 </row>
25077 <row topline="true">
25078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25079 \begin_inset Text
25080
25081 \layout Standard
25082
25083 cmon51
25084 \end_inset 
25085 </cell>
25086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25087 \begin_inset Text
25088
25089 \layout Standard
25090
25091 8051 monitor (hex up-/download, single step, disassemble)
25092 \end_inset 
25093 </cell>
25094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25095 \begin_inset Text
25096
25097 \layout Standard
25098
25099
25100 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
25101
25102 \end_inset 
25103
25104
25105 \end_inset 
25106 </cell>
25107 </row>
25108 <row topline="true">
25109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25110 \begin_inset Text
25111
25112 \layout Standard
25113
25114 doxygen
25115 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
25116
25117 \end_inset 
25118
25119
25120 \end_inset 
25121 </cell>
25122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25123 \begin_inset Text
25124
25125 \layout Standard
25126
25127 Source code documentation system
25128 \end_inset 
25129 </cell>
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25131 \begin_inset Text
25132
25133 \layout Standard
25134
25135
25136 \begin_inset LatexCommand \url{http://www.doxygen.org}
25137
25138 \end_inset 
25139
25140
25141 \end_inset 
25142 </cell>
25143 </row>
25144 <row topline="true">
25145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25146 \begin_inset Text
25147
25148 \layout Standard
25149
25150 kdevelop
25151 \end_inset 
25152 </cell>
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25154 \begin_inset Text
25155
25156 \layout Standard
25157
25158 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
25159 \end_inset 
25160 </cell>
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25162 \begin_inset Text
25163
25164 \layout Standard
25165
25166
25167 \begin_inset LatexCommand \url{http://www.kdevelop.org}
25168
25169 \end_inset 
25170
25171
25172 \end_inset 
25173 </cell>
25174 </row>
25175 <row topline="true">
25176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25177 \begin_inset Text
25178
25179 \layout Standard
25180
25181 paulmon
25182 \end_inset 
25183 </cell>
25184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25185 \begin_inset Text
25186
25187 \layout Standard
25188
25189 8051 monitor (hex up-/download, single step, disassemble)
25190 \end_inset 
25191 </cell>
25192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25193 \begin_inset Text
25194
25195 \layout Standard
25196
25197
25198 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
25199
25200 \end_inset 
25201
25202
25203 \end_inset 
25204 </cell>
25205 </row>
25206 <row topline="true">
25207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25208 \begin_inset Text
25209
25210 \layout Standard
25211
25212 splint
25213 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25214
25215 \end_inset 
25216
25217
25218 \end_inset 
25219 </cell>
25220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25221 \begin_inset Text
25222
25223 \layout Standard
25224
25225 Statically checks c sources (see 
25226 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25227
25228 \end_inset 
25229
25230 )
25231 \end_inset 
25232 </cell>
25233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25234 \begin_inset Text
25235
25236 \layout Standard
25237
25238
25239 \begin_inset LatexCommand \url{http://www.splint.org}
25240
25241 \end_inset 
25242
25243
25244 \end_inset 
25245 </cell>
25246 </row>
25247 <row topline="true" bottomline="true">
25248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25249 \begin_inset Text
25250
25251 \layout Standard
25252
25253 ddd
25254 \begin_inset LatexCommand \index{DDD (debugger)}
25255
25256 \end_inset 
25257
25258
25259 \end_inset 
25260 </cell>
25261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25262 \begin_inset Text
25263
25264 \layout Standard
25265
25266 Debugger, serves nicely as GUI to SDCDB
25267 \begin_inset LatexCommand \index{SDCDB (debugger)}
25268
25269 \end_inset 
25270
25271  (Unix only)
25272 \end_inset 
25273 </cell>
25274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25275 \begin_inset Text
25276
25277 \layout Standard
25278
25279
25280 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
25281
25282 \end_inset 
25283
25284
25285 \end_inset 
25286 </cell>
25287 </row>
25288 </lyxtabular>
25289
25290 \end_inset 
25291
25292
25293 \newline 
25294
25295 \layout Section
25296
25297 Related documentation / recommended reading
25298 \layout Standard
25299 \align left 
25300
25301 \begin_inset  Tabular
25302 <lyxtabular version="3" rows="7" columns="3">
25303 <features>
25304 <column alignment="left" valignment="top" leftline="true" width="0pt">
25305 <column alignment="left" valignment="top" leftline="true" width="0">
25306 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25307 <row topline="true" bottomline="true">
25308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25309 \begin_inset Text
25310
25311 \layout Standard
25312
25313
25314 \series bold 
25315 Name
25316 \end_inset 
25317 </cell>
25318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25319 \begin_inset Text
25320
25321 \layout Standard
25322
25323
25324 \series bold 
25325 Subject / Title
25326 \end_inset 
25327 </cell>
25328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25329 \begin_inset Text
25330
25331 \layout Standard
25332
25333
25334 \series bold 
25335 Where to get
25336 \end_inset 
25337 </cell>
25338 </row>
25339 <row topline="true">
25340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25341 \begin_inset Text
25342
25343 \layout Standard
25344
25345
25346 \family roman 
25347 \series medium 
25348 \shape up 
25349 \size normal 
25350 \emph off 
25351 \bar no 
25352 \noun off 
25353 \color none
25354 c-refcard.pdf
25355 \end_inset 
25356 </cell>
25357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25358 \begin_inset Text
25359
25360 \layout Standard
25361
25362 C Reference Card
25363 \begin_inset LatexCommand \index{C Reference card}
25364
25365 \end_inset 
25366
25367 , 2 pages
25368 \end_inset 
25369 </cell>
25370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25371 \begin_inset Text
25372
25373 \layout Standard
25374
25375
25376 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25377
25378 \end_inset 
25379
25380
25381 \end_inset 
25382 </cell>
25383 </row>
25384 <row topline="true">
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25386 \begin_inset Text
25387
25388 \layout Standard
25389
25390 c-faq
25391 \end_inset 
25392 </cell>
25393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25394 \begin_inset Text
25395
25396 \layout Standard
25397
25398 C-FAQ
25399 \begin_inset LatexCommand \index{C FAQ}
25400
25401 \end_inset 
25402
25403
25404 \end_inset 
25405 </cell>
25406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25407 \begin_inset Text
25408
25409 \layout Standard
25410
25411
25412 \begin_inset LatexCommand \url{http://www.c-faq.com}
25413
25414 \end_inset 
25415
25416
25417 \end_inset 
25418 </cell>
25419 </row>
25420 <row topline="true">
25421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25422 \begin_inset Text
25423
25424 \layout Standard
25425
25426 ISO/IEC 9899:TC2
25427 \end_inset 
25428 </cell>
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25430 \begin_inset Text
25431
25432 \layout Standard
25433
25434
25435 \begin_inset Quotes sld
25436 \end_inset 
25437
25438 C-Standard
25439 \begin_inset Quotes srd
25440 \end_inset 
25441
25442
25443 \end_inset 
25444 </cell>
25445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25446 \begin_inset Text
25447
25448 \layout Standard
25449
25450
25451 \size footnotesize 
25452
25453 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25454
25455 \end_inset 
25456
25457
25458 \end_inset 
25459 </cell>
25460 </row>
25461 <row topline="true">
25462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25463 \begin_inset Text
25464
25465 \layout Standard
25466
25467 ISO/IEC DTR 18037
25468 \end_inset 
25469 </cell>
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25471 \begin_inset Text
25472
25473 \layout Standard
25474
25475
25476 \begin_inset Quotes sld
25477 \end_inset 
25478
25479 Extensions for Embedded C
25480 \begin_inset Quotes srd
25481 \end_inset 
25482
25483
25484 \end_inset 
25485 </cell>
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25487 \begin_inset Text
25488
25489 \layout Standard
25490
25491
25492 \size footnotesize 
25493
25494 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25495
25496 \end_inset 
25497
25498
25499 \end_inset 
25500 </cell>
25501 </row>
25502 <row topline="true">
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25504 \begin_inset Text
25505
25506 \layout Standard
25507
25508 \end_inset 
25509 </cell>
25510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25511 \begin_inset Text
25512
25513 \layout Standard
25514
25515 Latest datasheet of target CPU
25516 \end_inset 
25517 </cell>
25518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25519 \begin_inset Text
25520
25521 \layout Standard
25522
25523 vendor
25524 \end_inset 
25525 </cell>
25526 </row>
25527 <row topline="true" bottomline="true">
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25529 \begin_inset Text
25530
25531 \layout Standard
25532
25533 \end_inset 
25534 </cell>
25535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25536 \begin_inset Text
25537
25538 \layout Standard
25539
25540 Revision history of datasheet
25541 \end_inset 
25542 </cell>
25543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25544 \begin_inset Text
25545
25546 \layout Standard
25547
25548 vendor
25549 \end_inset 
25550 </cell>
25551 </row>
25552 </lyxtabular>
25553
25554 \end_inset 
25555
25556
25557 \newline 
25558
25559 \layout Section
25560
25561 Application notes specifically for SDCC
25562 \layout Standard
25563
25564 SDCC makes no claims about the completeness of this list and about up-to-datenes
25565 s or correctness of the application notes
25566 \begin_inset LatexCommand \index{Application notes}
25567
25568 \end_inset 
25569
25570 .
25571 \layout Standard
25572 \align left 
25573
25574 \size footnotesize 
25575
25576 \begin_inset  Tabular
25577 <lyxtabular version="3" rows="7" columns="3">
25578 <features>
25579 <column alignment="block" valignment="top" leftline="true" width="17col%">
25580 <column alignment="block" valignment="top" leftline="true" width="27col%">
25581 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25582 <row topline="true" bottomline="true">
25583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25584 \begin_inset Text
25585
25586 \layout Standard
25587
25588
25589 \series bold 
25590 \size footnotesize 
25591 Vendor
25592 \end_inset 
25593 </cell>
25594 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25595 \begin_inset Text
25596
25597 \layout Standard
25598
25599
25600 \series bold 
25601 \size footnotesize 
25602 Subject / Title
25603 \end_inset 
25604 </cell>
25605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25606 \begin_inset Text
25607
25608 \layout Standard
25609
25610
25611 \series bold 
25612 \size footnotesize 
25613 Where to get
25614 \end_inset 
25615 </cell>
25616 </row>
25617 <row topline="true">
25618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25619 \begin_inset Text
25620
25621 \layout Standard
25622
25623
25624 \size footnotesize 
25625 Maxim / Dallas
25626 \end_inset 
25627 </cell>
25628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25629 \begin_inset Text
25630
25631 \layout Standard
25632
25633
25634 \size footnotesize 
25635 Using the SDCC Compiler for the DS80C400
25636 \begin_inset LatexCommand \index{DS80C400}
25637
25638 \end_inset 
25639
25640
25641 \end_inset 
25642 </cell>
25643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25644 \begin_inset Text
25645
25646 \layout Standard
25647
25648
25649 \size footnotesize 
25650
25651 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25652
25653 \end_inset 
25654
25655
25656 \end_inset 
25657 </cell>
25658 </row>
25659 <row topline="true">
25660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25661 \begin_inset Text
25662
25663 \layout Standard
25664
25665
25666 \size footnotesize 
25667 Maxim / Dallas
25668 \end_inset 
25669 </cell>
25670 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25671 \begin_inset Text
25672
25673 \layout Standard
25674
25675
25676 \size footnotesize 
25677 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25678 \begin_inset LatexCommand \index{DS89C4x0}
25679
25680 \end_inset 
25681
25682  Family of Microcontrollers
25683 \end_inset 
25684 </cell>
25685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25686 \begin_inset Text
25687
25688 \layout Standard
25689
25690
25691 \size footnotesize 
25692
25693 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25694
25695 \end_inset 
25696
25697
25698 \end_inset 
25699 </cell>
25700 </row>
25701 <row topline="true">
25702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25703 \begin_inset Text
25704
25705 \layout Standard
25706
25707
25708 \size footnotesize 
25709 Silicon Laboratories / Cygnal
25710 \end_inset 
25711 </cell>
25712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25713 \begin_inset Text
25714
25715 \layout Standard
25716
25717
25718 \size footnotesize 
25719 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25720 \begin_inset LatexCommand \index{IDE}
25721
25722 \end_inset 
25723
25724
25725 \end_inset 
25726 </cell>
25727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25728 \begin_inset Text
25729
25730 \layout Standard
25731
25732
25733 \size footnotesize 
25734
25735 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25736
25737 \end_inset 
25738
25739
25740 \end_inset 
25741 </cell>
25742 </row>
25743 <row topline="true">
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25745 \begin_inset Text
25746
25747 \layout Standard
25748
25749
25750 \size footnotesize 
25751 Ramtron / Goal Semiconductor
25752 \end_inset 
25753 </cell>
25754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25755 \begin_inset Text
25756
25757 \layout Standard
25758
25759
25760 \size footnotesize 
25761 Interfacing SDCC to Syn and Textpad
25762 \end_inset 
25763 </cell>
25764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25765 \begin_inset Text
25766
25767 \layout Standard
25768
25769
25770 \size footnotesize 
25771
25772 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25773
25774 \end_inset 
25775
25776
25777 \end_inset 
25778 </cell>
25779 </row>
25780 <row topline="true">
25781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25782 \begin_inset Text
25783
25784 \layout Standard
25785
25786
25787 \size footnotesize 
25788 Ramtron / Goal Semiconductor
25789 \end_inset 
25790 </cell>
25791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25792 \begin_inset Text
25793
25794 \layout Standard
25795
25796
25797 \size footnotesize 
25798 Installing and Configuring SDCC and Crimson Editor 
25799 \end_inset 
25800 </cell>
25801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25802 \begin_inset Text
25803
25804 \layout Standard
25805
25806
25807 \size footnotesize 
25808
25809 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25810
25811 \end_inset 
25812
25813
25814 \end_inset 
25815 </cell>
25816 </row>
25817 <row topline="true" bottomline="true">
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25819 \begin_inset Text
25820
25821 \layout Standard
25822
25823
25824 \size footnotesize 
25825 Texas Instruments
25826 \end_inset 
25827 </cell>
25828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25829 \begin_inset Text
25830
25831 \layout Standard
25832
25833
25834 \size footnotesize 
25835 MSC12xx Programming with SDCC
25836 \end_inset 
25837 </cell>
25838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25839 \begin_inset Text
25840
25841 \layout Standard
25842
25843
25844 \size footnotesize 
25845
25846 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25847
25848 \end_inset 
25849
25850
25851 \end_inset 
25852 </cell>
25853 </row>
25854 </lyxtabular>
25855
25856 \end_inset 
25857
25858
25859 \layout Section
25860
25861 Some Questions
25862 \layout Standard
25863
25864 Some questions answered, some pointers given - it might be time to in turn
25865  ask 
25866 \emph on 
25867 you
25868 \emph default 
25869  some questions: 
25870 \layout Itemize
25871
25872 can you solve your project with the selected microcontroller? Would you
25873  find out early or rather late that your target is too small/slow/whatever?
25874  Can you switch to a slightly better device if it doesn't fit?
25875 \layout Itemize
25876
25877 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25878  and/or another programming language be more adequate? Would an operating
25879  system on the target device help?
25880 \layout Itemize
25881
25882 if you solved the problem, will the marketing department be happy?
25883 \layout Itemize
25884
25885 if the marketing department is happy, will customers be happy?
25886 \layout Itemize
25887
25888 if you're the project manager, marketing department and maybe even the customer
25889  in one person, have you tried to see the project from the outside?
25890 \layout Itemize
25891
25892 is the project done if you think it is done? Or is just that other interface/pro
25893 tocol/feature/configuration/option missing? How about website, manual(s),
25894  internationali(z|s)ation, packaging, labels, 2nd source for components,
25895  electromagnetic compatability/interference, documentation for production,
25896  production test software, update mechanism, patent issues?
25897 \layout Itemize
25898
25899 is your project adequately positioned in that magic triangle: fame, fortune,
25900  fun?
25901 \layout Standard
25902
25903 Maybe not all answers to these questions are known and some answers may
25904  even be 
25905 \emph on 
25906 no
25907 \emph default 
25908 , nevertheless knowing these questions may help you to avoid burnout
25909 \begin_inset Foot
25910 collapsed false
25911
25912 \layout Standard
25913
25914 burnout is bad for electronic devices, programmers and motorcycle tyres
25915 \end_inset 
25916
25917 .
25918  Chances are you didn't want to hear some of them...
25919 \layout Chapter
25920
25921 Support
25922 \begin_inset LatexCommand \index{Support}
25923
25924 \end_inset 
25925
25926
25927 \layout Standard
25928
25929 SDCC has grown to be a large project.
25930  The compiler alone (without the preprocessor, assembler and linker) is
25931  well over 150,000 lines of code (blank stripped).
25932  The open source nature of this project is a key to its continued growth
25933  and support.
25934  You gain the benefit and support of many active software developers and
25935  end users.
25936  Is SDCC perfect? No, that's why we need your help.
25937  The developers take pride in fixing reported bugs.
25938  You can help by reporting the bugs and helping other SDCC users.
25939  There are lots of ways to contribute, and we encourage you to take part
25940  in making SDCC a great software package.
25941  
25942 \layout Standard
25943
25944 The SDCC project is hosted on the SDCC sourceforge site at 
25945 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25946
25947 \end_inset 
25948
25949 .
25950  You'll find the complete set of mailing lists
25951 \begin_inset LatexCommand \index{Mailing list(s)}
25952
25953 \end_inset 
25954
25955 , forums, bug reporting system, patch submission
25956 \begin_inset LatexCommand \index{Patch submission}
25957
25958 \end_inset 
25959
25960  system, download
25961 \begin_inset LatexCommand \index{download}
25962
25963 \end_inset 
25964
25965  area and Subversion code repository
25966 \begin_inset LatexCommand \index{Subversion code repository}
25967
25968 \end_inset 
25969
25970  there.
25971 \layout Section
25972
25973 Reporting Bugs
25974 \begin_inset LatexCommand \index{Bug reporting}
25975
25976 \end_inset 
25977
25978
25979 \begin_inset LatexCommand \index{Reporting bugs}
25980
25981 \end_inset 
25982
25983
25984 \layout Standard
25985
25986 The recommended way of reporting bugs is using the infrastructure of the
25987  sourceforge site.
25988  You can follow the status of bug reports there and have an overview about
25989  the known bugs.
25990 \layout Standard
25991
25992 Bug reports are automatically forwarded to the developer mailing list and
25993  will be fixed ASAP.
25994  When reporting a bug, it is very useful to include a small test program
25995  (the smaller the better) which reproduces the problem.
25996  If you can isolate the problem by looking at the generated assembly code,
25997  this can be very helpful.
25998  Compiling your program with the -
25999 \begin_inset ERT
26000 status Collapsed
26001
26002 \layout Standard
26003
26004 \backslash 
26005 /
26006 \end_inset 
26007
26008 -dumpall
26009 \begin_inset LatexCommand \index{-\/-dumpall}
26010
26011 \end_inset 
26012
26013  option can sometimes be useful in locating optimization problems.
26014  When reporting a bug please make sure you:
26015 \layout Enumerate
26016
26017 Attach the code you are compiling with SDCC.
26018  
26019 \layout Enumerate
26020
26021 Specify the exact command you use to run SDCC, or attach your Makefile.
26022  
26023 \layout Enumerate
26024
26025 Specify the SDCC version (type "
26026 \family sans 
26027 \series bold 
26028 sdcc -v
26029 \family default 
26030 \series default 
26031 "), your platform, and operating system.
26032  
26033 \layout Enumerate
26034
26035 Provide an exact copy of any error message or incorrect output.
26036  
26037 \layout Enumerate
26038
26039 Put something meaningful in the subject of your message.
26040 \layout Standard
26041
26042 Please attempt to include these 5 important parts, as applicable, in all
26043  requests for support or when reporting any problems or bugs with SDCC.
26044  Though this will make your message lengthy, it will greatly improve your
26045  chance that SDCC users and developers will be able to help you.
26046  Some SDCC developers are frustrated by bug reports without code provided
26047  that they can use to reproduce and ultimately fix the problem, so please
26048  be sure to provide sample code if you are reporting a bug! 
26049 \layout Standard
26050
26051 Please have a short check that you are using a recent version of SDCC and
26052  the bug is not yet known.
26053  This is the link for reporting bugs: 
26054 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
26055
26056 \end_inset 
26057
26058 .
26059  With SDCC on average having more than 200 downloads
26060 \begin_inset LatexCommand \index{download}
26061
26062 \end_inset 
26063
26064  on sourceforge per day
26065 \begin_inset Foot
26066 collapsed false
26067
26068 \layout Standard
26069
26070 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
26071  between 2002 and 2005.
26072  This does not include other methods of distribution.
26073 \end_inset 
26074
26075  there must be some users.
26076  So it's not exactly easy to find a new bug.
26077  If you find one we need it: 
26078 \emph on 
26079 reporting bugs is good
26080 \emph default 
26081 .
26082 \layout Section
26083
26084 Requesting Features
26085 \begin_inset LatexCommand \label{sub:Requesting-Features}
26086
26087 \end_inset 
26088
26089
26090 \begin_inset LatexCommand \index{Feature request}
26091
26092 \end_inset 
26093
26094
26095 \begin_inset LatexCommand \index{Requesting features}
26096
26097 \end_inset 
26098
26099
26100 \layout Standard
26101
26102 Like bug reports feature requests are forwarded to the developer mailing
26103  list.
26104  This is the link for requesting features: 
26105 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26106
26107 \end_inset 
26108
26109 .
26110 \layout Section
26111
26112 Submitting patches
26113 \layout Standard
26114
26115 Like bug reports contributed patches are forwarded to the developer mailing
26116  list.
26117  This is the link for submitting patches
26118 \begin_inset LatexCommand \index{Patch submission}
26119
26120 \end_inset 
26121
26122
26123 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
26124
26125 \end_inset 
26126
26127 .
26128 \layout Standard
26129
26130 You need to specify some parameters to the 
26131 \family typewriter 
26132 diff
26133 \family default 
26134  command for the patches to be useful.
26135  If you modified more than one file a patch created f.e.
26136  with 
26137 \family sans 
26138 \series bold 
26139
26140 \begin_inset Quotes sld
26141 \end_inset 
26142
26143 diff -Naur unmodified_directory modified_directory >my_changes.patch
26144 \begin_inset Quotes srd
26145 \end_inset 
26146
26147
26148 \family default 
26149 \series default 
26150  will be fine, otherwise 
26151 \family sans 
26152 \series bold 
26153
26154 \begin_inset Quotes sld
26155 \end_inset 
26156
26157 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
26158 \begin_inset Quotes srd
26159 \end_inset 
26160
26161
26162 \series default 
26163  
26164 \family default 
26165 will do.
26166 \layout Section
26167
26168 Getting Help
26169 \layout Standard
26170
26171 These links should take you directly to the 
26172 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
26173
26174 \end_inset 
26175
26176
26177 \begin_inset Foot
26178 collapsed false
26179
26180 \layout Standard
26181
26182 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
26183  automated messages (mid 2003)
26184 \end_inset 
26185
26186  and the 
26187 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
26188
26189 \end_inset 
26190
26191 , lists
26192 \begin_inset LatexCommand \index{Mailing list(s)}
26193
26194 \end_inset 
26195
26196  and forums are archived and searchable so if you are lucky someone already
26197  had a similar problem.
26198  While mails to the lists themselves are delivered promptly their web front
26199  end on sourceforge sometimes shows a severe time lag (up to several weeks),
26200  if you're seriously using SDCC please consider subscribing to the lists.
26201 \layout Section
26202
26203 ChangeLog
26204 \layout Standard
26205
26206 You can follow the status of the Subversion version
26207 \begin_inset LatexCommand \index{version}
26208
26209 \end_inset 
26210
26211  of SDCC by watching the Changelog
26212 \begin_inset LatexCommand \index{Changelog}
26213
26214 \end_inset 
26215
26216  in the Subversion repository
26217 \size footnotesize 
26218  
26219 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26220
26221 \end_inset 
26222
26223 .
26224 \layout Section
26225
26226 Subversion Source Code Repository
26227 \layout Standard
26228
26229 The output of 
26230 \family sans 
26231 \series bold 
26232 sdcc --version
26233 \family default 
26234 \series default 
26235  or the filenames of the snapshot versions of SDCC include date and its
26236  Subversion
26237 \begin_inset LatexCommand \index{Subversion code repository}
26238
26239 \end_inset 
26240
26241  number.
26242  Subversion allows to download the source of recent or previous versions
26243  
26244 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
26245
26246 \end_inset 
26247
26248  (by number or by date).
26249  An on-line source code browser and detailled instructions are also available
26250  there.
26251  SDCC versions starting from 1999 up to now are available (currently the
26252  versions prior to the conversion from cvs
26253 \begin_inset LatexCommand \index{cvs|see{Subversion}}
26254
26255 \end_inset 
26256
26257  to Subversion (April 2006) are either by accessible by Subversion or by
26258  cvs).
26259 \layout Section
26260
26261 Release policy
26262 \begin_inset LatexCommand \index{Release policy}
26263
26264 \end_inset 
26265
26266
26267 \layout Standard
26268
26269 Historically there often were long delays between official releases and
26270  the sourceforge download area tends to get not updated at all.
26271  Excuses in the past might have referred to problems with live range analysis,
26272  but as this was fixed a while ago, the current problem is that another
26273  excuse has to be found.
26274  Kidding aside, we have to get better there! On the other hand there are
26275  daily snapshots available at 
26276 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
26277
26278 \end_inset 
26279
26280 , and you can always build the very last version (hopefully with many bugs
26281  fixed, and features added) from the source code available at 
26282 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
26283
26284 \end_inset 
26285
26286 .
26287  A release wiki
26288 \begin_inset LatexCommand \index{wiki}
26289
26290 \end_inset 
26291
26292
26293 \begin_inset LatexCommand \index{Release wiki}
26294
26295 \end_inset 
26296
26297  at 
26298 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
26299
26300 \end_inset 
26301
26302  also holds some information about past and future releases.
26303 \layout Section
26304
26305 Examples
26306 \begin_inset LatexCommand \index{Examples}
26307
26308 \end_inset 
26309
26310
26311 \layout Standard
26312
26313 You'll find some small examples in the directory 
26314 \emph on 
26315 sdcc/device/examples/.
26316  
26317 \emph default 
26318 More examples and libraries are available at
26319 \emph on 
26320  The SDCC Open Knowledge Resource 
26321 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
26322
26323 \end_inset 
26324
26325  
26326 \emph default 
26327 web site or at 
26328 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
26329
26330 \end_inset 
26331
26332 .
26333 \layout Comment
26334
26335 I did insert a reference to Paul's web site here although it seems rather
26336  dedicated to a specific 8032 board (I think it's okay because it f.e.
26337  shows LCD/Harddisc interface and has a free 8051 monitor.
26338  Independent 8032 board vendors face hard competition of heavily subsidized
26339  development boards anyway).
26340 \layout Comment
26341
26342 Maybe we should include some links to real world applications.
26343  Preferably pointer to pointers (one for each architecture) so this stays
26344  manageable here?
26345 \layout Section
26346
26347 Quality control
26348 \begin_inset LatexCommand \label{sec:Quality-control}
26349
26350 \end_inset 
26351
26352
26353 \begin_inset LatexCommand \index{Quality control}
26354
26355 \end_inset 
26356
26357
26358 \layout Standard
26359
26360 The compiler is passed through nightly compile and build checks.
26361  The so called 
26362 \shape italic 
26363 regression tests
26364 \shape default 
26365
26366 \begin_inset LatexCommand \index{Regression test}
26367
26368 \end_inset 
26369
26370  check that SDCC itself compiles flawlessly on several host platforms (i386,
26371  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26372  the quality of the code generated by SDCC by running the code for several
26373  target platforms through simulators.
26374  The regression test suite comprises more than 100 files which expand to
26375  more than 500 test cases which include more than 4500 tests.
26376  The results of these tests are published daily on SDCC's snapshot page
26377  (click on the red or green symbols on the right side of 
26378 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26379
26380 \end_inset 
26381
26382 ).
26383 \layout Standard
26384
26385 There is a separate document 
26386 \shape italic 
26387 test_suite.pdf 
26388 \begin_inset LatexCommand \index{Test suite}
26389
26390 \end_inset 
26391
26392
26393 \shape default 
26394  
26395 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26396
26397 \end_inset 
26398
26399  about the regression test suite.
26400 \layout Standard
26401
26402 You'll find the test code in the directory 
26403 \shape italic 
26404 sdcc/support/regression
26405 \shape default 
26406 .
26407  You can run these tests manually by running 
26408 \family sans 
26409 make
26410 \family default 
26411  in this directory (or f.e.
26412  
26413 \family sans 
26414 \series bold 
26415
26416 \begin_inset Quotes sld
26417 \end_inset 
26418
26419 make test-mcs51
26420 \begin_inset Quotes srd
26421 \end_inset 
26422
26423
26424 \family default 
26425 \series default 
26426  if you don't want to run the complete tests).
26427  The test code might also be interesting if you want to look for examples
26428 \begin_inset LatexCommand \index{Examples}
26429
26430 \end_inset 
26431
26432  checking corner cases of SDCC or if you plan to submit patches
26433 \begin_inset LatexCommand \index{Patch submission}
26434
26435 \end_inset 
26436
26437 .
26438 \layout Standard
26439
26440 The 14bit pic port uses a different set of regression tests 
26441 \begin_inset LatexCommand \index{Regression test (PIC14)}
26442
26443 \end_inset 
26444
26445 , you'll find them in the directory 
26446 \shape italic 
26447 sdcc/src/regression
26448 \shape default 
26449 .
26450 \layout Section
26451
26452 Use of SDCC in Education
26453 \layout Standard
26454
26455 In short: 
26456 \emph on 
26457 highly
26458 \emph default 
26459  encouraged
26460 \begin_inset Foot
26461 collapsed false
26462
26463 \layout Standard
26464
26465 the phrase "use in education" might evoke the association "
26466 \emph on 
26467 only
26468 \emph default 
26469  fit for use in education".
26470  This connotation is not intended but nevertheless risked as the licensing
26471  of SDCC makes it difficult to offer educational discounts
26472 \end_inset 
26473
26474 .
26475  If your rationales are to:
26476 \layout Enumerate
26477
26478 give students a chance to understand the 
26479 \emph on 
26480 complete
26481 \emph default 
26482  steps of code generation
26483 \layout Enumerate
26484
26485 have a curriculum that can be extended for years.
26486  Then you could use an fpga board as target and your curriculum will seamlessly
26487  extend from logic synthesis (
26488 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26489
26490 \end_inset 
26491
26492
26493 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26494
26495 \end_inset 
26496
26497 ), over assembly programming, to C to FPGA compilers (
26498 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26499
26500 \end_inset 
26501
26502 ) and to C.
26503 \layout Enumerate
26504
26505 be able to insert excursions about skills like using a revision control
26506  system, submitting/applying patches, using a type-setting (as opposed to
26507  word-processing) engine LyX/LaTeX, using 
26508 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26509
26510 \end_inset 
26511
26512 , following some 
26513 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26514
26515 \end_inset 
26516
26517 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26518  Source Software, CPU simulation, compiler regression tests
26519 \begin_inset LatexCommand \index{Regression test}
26520
26521 \end_inset 
26522
26523 .
26524  
26525 \newline 
26526 And if there should be a shortage of ideas then you can always point students
26527  to the ever-growing feature request list 
26528 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26529
26530 \end_inset 
26531
26532 .
26533 \layout Enumerate
26534
26535 not tie students to a specific host platform and instead allow them to use
26536  a host platform of 
26537 \emph on 
26538 their
26539 \emph default 
26540  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26541  eventually 
26542 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26543
26544 \end_inset 
26545
26546 )
26547 \layout Enumerate
26548
26549 not encourage students to use illegal copies of educational software
26550 \layout Enumerate
26551
26552 be immune to licensing/availability/price changes of the chosen tool chain
26553 \layout Enumerate
26554
26555 be able to change to a new target platform without having to adopt a new
26556  tool chain
26557 \layout Enumerate
26558
26559 have complete control over and insight into the tool chain
26560 \layout Enumerate
26561
26562 make your students aware about the pros and cons of open source software
26563  development
26564 \layout Enumerate
26565
26566 give back to the public as you are probably at least partially publically
26567  funded
26568 \layout Enumerate
26569
26570 give students a chance to publically prove their skills and to possibly
26571  see a world wide impact
26572 \layout Standard
26573
26574 then SDCC is probably among the first choices.
26575  Well, probably SDCC might be the only choice.
26576 \layout Chapter
26577 \pagebreak_top 
26578 SDCC Technical Data
26579 \layout Section
26580
26581 Optimizations
26582 \begin_inset LatexCommand \index{Optimizations}
26583
26584 \end_inset 
26585
26586
26587 \layout Standard
26588
26589 SDCC performs a host of standard optimizations in addition to some MCU specific
26590  optimizations.
26591  
26592 \layout Subsection
26593
26594 Sub-expression Elimination
26595 \begin_inset LatexCommand \index{Subexpression elimination}
26596
26597 \end_inset 
26598
26599
26600 \layout Standard
26601
26602 The compiler does local and 
26603 \emph on 
26604 g
26605 \emph default 
26606 lobal 
26607 \emph on 
26608 c
26609 \emph default 
26610 ommon 
26611 \emph on 
26612 s
26613 \emph default 
26614 ubexpression 
26615 \emph on 
26616 e
26617 \emph default 
26618 limination, e.g.: 
26619 \layout Verse
26620
26621
26622 \family typewriter 
26623 i = x + y + 1; 
26624 \newline 
26625 j = x + y;
26626 \layout Standard
26627
26628 will be translated to
26629 \layout Verse
26630
26631
26632 \family typewriter 
26633 iTemp = x + y; 
26634 \newline 
26635 i = iTemp + 1; 
26636 \newline 
26637 j = iTemp;
26638 \layout Standard
26639
26640 Some subexpressions are not as obvious as the above example, e.g.:
26641 \layout Verse
26642
26643
26644 \family typewriter 
26645 a->b[i].c = 10; 
26646 \newline 
26647 a->b[i].d = 11;
26648 \layout Standard
26649
26650 In this case the address arithmetic a->b[i] will be computed only once;
26651  the equivalent code in C would be.
26652 \layout Verse
26653
26654
26655 \family typewriter 
26656 iTemp = a->b[i]; 
26657 \newline 
26658 iTemp.c = 10; 
26659 \newline 
26660 iTemp.d = 11;
26661 \layout Standard
26662
26663 The compiler will try to keep these temporary variables in registers.
26664 \layout Subsection
26665
26666 Dead-Code Elimination
26667 \begin_inset LatexCommand \index{Dead-code elimination}
26668
26669 \end_inset 
26670
26671
26672 \layout Verse
26673
26674
26675 \family typewriter 
26676 int global;
26677 \newline 
26678
26679 \newline 
26680 void f () { 
26681 \newline 
26682 \SpecialChar ~
26683 \SpecialChar ~
26684 int i; 
26685 \newline 
26686 \SpecialChar ~
26687 \SpecialChar ~
26688 i = 1; \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692 \SpecialChar ~
26693 /* dead store */ 
26694 \newline 
26695 \SpecialChar ~
26696 \SpecialChar ~
26697 global = 1;\SpecialChar ~
26698 /* dead store */ 
26699 \newline 
26700 \SpecialChar ~
26701 \SpecialChar ~
26702 global = 2; 
26703 \newline 
26704 \SpecialChar ~
26705 \SpecialChar ~
26706 return; 
26707 \newline 
26708 \SpecialChar ~
26709 \SpecialChar ~
26710 global = 3;\SpecialChar ~
26711 /* unreachable */ 
26712 \newline 
26713 }
26714 \layout Standard
26715
26716 will be changed to
26717 \layout Verse
26718
26719
26720 \family typewriter 
26721 int global;
26722 \newline 
26723
26724 \newline 
26725 void f () {
26726 \newline 
26727 \SpecialChar ~
26728 \SpecialChar ~
26729 global = 2; 
26730 \newline 
26731 }
26732 \layout Subsection
26733
26734 Copy-Propagation
26735 \begin_inset LatexCommand \index{Copy propagation}
26736
26737 \end_inset 
26738
26739
26740 \layout Verse
26741
26742
26743 \family typewriter 
26744 int f() { 
26745 \newline 
26746 \SpecialChar ~
26747 \SpecialChar ~
26748 int i, j; 
26749 \newline 
26750 \SpecialChar ~
26751 \SpecialChar ~
26752 i = 10; 
26753 \newline 
26754 \SpecialChar ~
26755 \SpecialChar ~
26756 j = i; 
26757 \newline 
26758 \SpecialChar ~
26759 \SpecialChar ~
26760 return j; 
26761 \newline 
26762 }
26763 \layout Standard
26764
26765 will be changed to 
26766 \layout Verse
26767
26768
26769 \family typewriter 
26770 int f() { 
26771 \newline 
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 int i, j; 
26775 \newline 
26776 \SpecialChar ~
26777 \SpecialChar ~
26778 i = 10; 
26779 \newline 
26780 \SpecialChar ~
26781 \SpecialChar ~
26782 j = 10; 
26783 \newline 
26784 \SpecialChar ~
26785 \SpecialChar ~
26786 return 10; 
26787 \newline 
26788 }
26789 \layout Standard
26790
26791 Note: the dead stores created by this copy propagation will be eliminated
26792  by dead-code elimination.
26793 \layout Subsection
26794
26795 Loop Optimizations
26796 \begin_inset LatexCommand \index{Loop optimization}
26797
26798 \end_inset 
26799
26800
26801 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26802
26803 \end_inset 
26804
26805
26806 \layout Standard
26807
26808 Two types of loop optimizations are done by SDCC 
26809 \emph on 
26810 loop invariant
26811 \emph default 
26812  lifting and
26813 \emph on 
26814  strength reduction
26815 \emph default 
26816  of loop induction variables.
26817  In addition to the strength reduction the optimizer marks the induction
26818  variables and the register allocator tries to keep the induction variables
26819  in registers for the duration of the loop.
26820  Because of this preference of the register allocator
26821 \begin_inset LatexCommand \index{Register allocation}
26822
26823 \end_inset 
26824
26825 , loop induction optimization causes an increase in register pressure, which
26826  may cause unwanted spilling of other temporary variables into the stack
26827 \begin_inset LatexCommand \index{stack}
26828
26829 \end_inset 
26830
26831  / data space.
26832  The compiler will generate a warning message when it is forced to allocate
26833  extra space either on the stack or data space.
26834  If this extra space allocation is undesirable then induction optimization
26835  can be eliminated either for the entire source file (with -
26836 \begin_inset ERT
26837 status Collapsed
26838
26839 \layout Standard
26840
26841 \backslash 
26842 /
26843 \end_inset 
26844
26845 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26846 noinduction
26847 \begin_inset LatexCommand \index{\#pragma noinduction}
26848
26849 \end_inset 
26850
26851 .
26852 \newline 
26853
26854 \newline 
26855 Loop Invariant:
26856 \layout Verse
26857
26858
26859 \family typewriter 
26860 for (i = 0 ; i < 100 ; i ++) 
26861 \newline 
26862 \SpecialChar ~
26863 \SpecialChar ~
26864 \SpecialChar ~
26865 \SpecialChar ~
26866 f += k + l;
26867 \layout Standard
26868
26869 changed to
26870 \layout Verse
26871
26872
26873 \family typewriter 
26874 itemp = k + l; 
26875 \newline 
26876 for (i = 0; i < 100; i++) 
26877 \newline 
26878 \SpecialChar ~
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 f += itemp;
26883 \layout Standard
26884
26885 As mentioned previously some loop invariants are not as apparent, all static
26886  address computations are also moved out of the loop.
26887 \newline 
26888
26889 \newline 
26890 Strength Reduction
26891 \begin_inset LatexCommand \index{Strength reduction}
26892
26893 \end_inset 
26894
26895 , this optimization substitutes an expression by a cheaper expression:
26896 \layout Verse
26897
26898
26899 \family typewriter 
26900 for (i=0;i < 100; i++)
26901 \newline 
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 \SpecialChar ~
26906 ar[i*5] = i*3;
26907 \layout Standard
26908
26909 changed to
26910 \layout Verse
26911
26912
26913 \family typewriter 
26914 itemp1 = 0; 
26915 \newline 
26916 itemp2 = 0; 
26917 \newline 
26918 for (i=0;i< 100;i++) { 
26919 \newline 
26920 \SpecialChar ~
26921 \SpecialChar ~
26922 \SpecialChar ~
26923 \SpecialChar ~
26924 ar[itemp1] = itemp2; 
26925 \newline 
26926 \SpecialChar ~
26927 \SpecialChar ~
26928 \SpecialChar ~
26929 \SpecialChar ~
26930 itemp1 += 5; 
26931 \newline 
26932 \SpecialChar ~
26933 \SpecialChar ~
26934 \SpecialChar ~
26935 \SpecialChar ~
26936 itemp2 += 3; 
26937 \newline 
26938 }
26939 \layout Standard
26940
26941 The more expensive multiplication
26942 \begin_inset LatexCommand \index{Multiplication}
26943
26944 \end_inset 
26945
26946  is changed to a less expensive addition.
26947 \layout Subsection
26948
26949 Loop Reversing
26950 \begin_inset LatexCommand \index{Loop reversing}
26951
26952 \end_inset 
26953
26954
26955 \layout Standard
26956
26957 This optimization is done to reduce the overhead of checking loop boundaries
26958  for every iteration.
26959  Some simple loops can be reversed and implemented using a 
26960 \begin_inset Quotes eld
26961 \end_inset 
26962
26963 decrement and jump if not zero
26964 \begin_inset Quotes erd
26965 \end_inset 
26966
26967  instruction.
26968  SDCC checks for the following criterion to determine if a loop is reversible
26969  (note: more sophisticated compilers use data-dependency analysis to make
26970  this determination, SDCC uses a more simple minded analysis).
26971 \layout Itemize
26972
26973 The 'for' loop is of the form 
26974 \newline 
26975
26976 \newline 
26977
26978 \family typewriter 
26979 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26980  += 1])
26981 \newline 
26982 \SpecialChar ~
26983 \SpecialChar ~
26984 \SpecialChar ~
26985 \SpecialChar ~
26986 <for body>
26987 \layout Itemize
26988
26989 The <for body> does not contain 
26990 \begin_inset Quotes eld
26991 \end_inset 
26992
26993 continue
26994 \begin_inset Quotes erd
26995 \end_inset 
26996
26997  or 'break
26998 \begin_inset Quotes erd
26999 \end_inset 
27000
27001 .
27002 \layout Itemize
27003
27004 All goto's are contained within the loop.
27005 \layout Itemize
27006
27007 No function calls within the loop.
27008 \layout Itemize
27009
27010 The loop control variable <sym> is not assigned any value within the loop
27011 \layout Itemize
27012
27013 The loop control variable does NOT participate in any arithmetic operation
27014  within the loop.
27015 \layout Itemize
27016
27017 There are NO switch statements in the loop.
27018 \layout Subsection
27019
27020 Algebraic Simplifications
27021 \layout Standard
27022
27023 SDCC does numerous algebraic simplifications, the following is a small sub-set
27024  of these optimizations.
27025 \layout Verse
27026
27027
27028 \family typewriter 
27029 i = j + 0;\SpecialChar ~
27030 \SpecialChar ~
27031 \SpecialChar ~
27032 \SpecialChar ~
27033  /* changed to: */\SpecialChar ~
27034 \SpecialChar ~
27035 \SpecialChar ~
27036 \SpecialChar ~
27037  i = j; 
27038 \newline 
27039 i /= 2;\SpecialChar ~
27040 \SpecialChar ~
27041 \SpecialChar ~
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 \SpecialChar ~
27046  /* changed to: */\SpecialChar ~
27047 \SpecialChar ~
27048 \SpecialChar ~
27049 \SpecialChar ~
27050  i >>= 1; 
27051 \newline 
27052 i = j - j;\SpecialChar ~
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 \SpecialChar ~
27056  /* changed to: */\SpecialChar ~
27057 \SpecialChar ~
27058 \SpecialChar ~
27059 \SpecialChar ~
27060  i = 0; 
27061 \newline 
27062 i = j / 1;\SpecialChar ~
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 \SpecialChar ~
27066  /* changed to: */\SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069 \SpecialChar ~
27070  i = j;
27071 \layout Standard
27072
27073 Note the subexpressions
27074 \begin_inset LatexCommand \index{Subexpression}
27075
27076 \end_inset 
27077
27078  given above are generally introduced by macro expansions or as a result
27079  of copy/constant propagation.
27080 \layout Subsection
27081
27082 'switch' Statements
27083 \begin_inset LatexCommand \label{sub:'switch'-Statements}
27084
27085 \end_inset 
27086
27087
27088 \begin_inset LatexCommand \index{switch statement}
27089
27090 \end_inset 
27091
27092
27093 \layout Standard
27094
27095 SDCC can optimize switch statements to jump tables
27096 \begin_inset LatexCommand \index{jump tables}
27097
27098 \end_inset 
27099
27100 .
27101  It makes the decision based on an estimate of the generated code size.
27102  SDCC is quite liberal in the requirements for jump table generation: 
27103 \layout Itemize
27104
27105 The labels need not be in order, and the starting number need not be one
27106  or zero, the case labels are in numerical sequence or not too many case
27107  labels are missing.
27108 \begin_deeper 
27109 \layout Verse
27110
27111
27112 \family typewriter 
27113 switch(i) {\SpecialChar ~
27114 \SpecialChar ~
27115 \SpecialChar ~
27116 \SpecialChar ~
27117 \SpecialChar ~
27118 \SpecialChar ~
27119 \SpecialChar ~
27120 \SpecialChar ~
27121 \SpecialChar ~
27122 \SpecialChar ~
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 \SpecialChar ~
27126 \SpecialChar ~
27127 \SpecialChar ~
27128 \SpecialChar ~
27129 \SpecialChar ~
27130 \SpecialChar ~
27131 \SpecialChar ~
27132 \SpecialChar ~
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 \SpecialChar ~
27138 \SpecialChar ~
27139 switch (i) { 
27140 \newline 
27141 \SpecialChar ~
27142 \SpecialChar ~
27143 \SpecialChar ~
27144 case 4: ...\SpecialChar ~
27145 \SpecialChar ~
27146 \SpecialChar ~
27147 \SpecialChar ~
27148 \SpecialChar ~
27149 \SpecialChar ~
27150 \SpecialChar ~
27151 \SpecialChar ~
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 \SpecialChar ~
27155 \SpecialChar ~
27156 \SpecialChar ~
27157 \SpecialChar ~
27158 \SpecialChar ~
27159 \SpecialChar ~
27160 \SpecialChar ~
27161 \SpecialChar ~
27162 \SpecialChar ~
27163 \SpecialChar ~
27164 \SpecialChar ~
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 \SpecialChar ~
27168 \SpecialChar ~
27169 \SpecialChar ~
27170 case 0: ...
27171  
27172 \newline 
27173 \SpecialChar ~
27174 \SpecialChar ~
27175 \SpecialChar ~
27176 case 5: ...\SpecialChar ~
27177 \SpecialChar ~
27178 \SpecialChar ~
27179 \SpecialChar ~
27180 \SpecialChar ~
27181 \SpecialChar ~
27182 \SpecialChar ~
27183 \SpecialChar ~
27184 \SpecialChar ~
27185 \SpecialChar ~
27186 \SpecialChar ~
27187 \SpecialChar ~
27188 \SpecialChar ~
27189 \SpecialChar ~
27190 \SpecialChar ~
27191 \SpecialChar ~
27192 \SpecialChar ~
27193 \SpecialChar ~
27194 \SpecialChar ~
27195 \SpecialChar ~
27196 \SpecialChar ~
27197 \SpecialChar ~
27198 \SpecialChar ~
27199 \SpecialChar ~
27200 \SpecialChar ~
27201 \SpecialChar ~
27202 case 1: ...
27203  
27204 \newline 
27205 \SpecialChar ~
27206 \SpecialChar ~
27207 \SpecialChar ~
27208 case 3: ...\SpecialChar ~
27209 \SpecialChar ~
27210 \SpecialChar ~
27211 \SpecialChar ~
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 \SpecialChar ~
27215 \SpecialChar ~
27216 \SpecialChar ~
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 \SpecialChar ~
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 \SpecialChar ~
27223 \SpecialChar ~
27224 \SpecialChar ~
27225 \SpecialChar ~
27226 \SpecialChar ~
27227 \SpecialChar ~
27228 \SpecialChar ~
27229 \SpecialChar ~
27230 \SpecialChar ~
27231 \SpecialChar ~
27232 \SpecialChar ~
27233 \SpecialChar ~
27234
27235 \newline 
27236 \SpecialChar ~
27237 \SpecialChar ~
27238 \SpecialChar ~
27239 case 6: ...\SpecialChar ~
27240 \SpecialChar ~
27241 \SpecialChar ~
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 \SpecialChar ~
27245 \SpecialChar ~
27246 \SpecialChar ~
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 \SpecialChar ~
27250 \SpecialChar ~
27251 \SpecialChar ~
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 \SpecialChar ~
27257 \SpecialChar ~
27258 \SpecialChar ~
27259 \SpecialChar ~
27260 \SpecialChar ~
27261 \SpecialChar ~
27262 \SpecialChar ~
27263 \SpecialChar ~
27264 \SpecialChar ~
27265 case 3: ...
27266  
27267 \newline 
27268 \SpecialChar ~
27269 \SpecialChar ~
27270 \SpecialChar ~
27271 case 7: ...\SpecialChar ~
27272 \SpecialChar ~
27273 \SpecialChar ~
27274 \SpecialChar ~
27275 \SpecialChar ~
27276 \SpecialChar ~
27277 \SpecialChar ~
27278 \SpecialChar ~
27279 \SpecialChar ~
27280 \SpecialChar ~
27281 \SpecialChar ~
27282 \SpecialChar ~
27283 \SpecialChar ~
27284 \SpecialChar ~
27285 \SpecialChar ~
27286 \SpecialChar ~
27287 \SpecialChar ~
27288 \SpecialChar ~
27289 \SpecialChar ~
27290 \SpecialChar ~
27291 \SpecialChar ~
27292 \SpecialChar ~
27293 \SpecialChar ~
27294 \SpecialChar ~
27295 \SpecialChar ~
27296 \SpecialChar ~
27297 case 4: ...
27298  
27299 \newline 
27300 \SpecialChar ~
27301 \SpecialChar ~
27302 \SpecialChar ~
27303 case 8: ...\SpecialChar ~
27304 \SpecialChar ~
27305 \SpecialChar ~
27306 \SpecialChar ~
27307 \SpecialChar ~
27308 \SpecialChar ~
27309 \SpecialChar ~
27310 \SpecialChar ~
27311 \SpecialChar ~
27312 \SpecialChar ~
27313 \SpecialChar ~
27314 \SpecialChar ~
27315 \SpecialChar ~
27316 \SpecialChar ~
27317 \SpecialChar ~
27318 \SpecialChar ~
27319 \SpecialChar ~
27320 \SpecialChar ~
27321 \SpecialChar ~
27322 \SpecialChar ~
27323 \SpecialChar ~
27324 \SpecialChar ~
27325 \SpecialChar ~
27326 \SpecialChar ~
27327 \SpecialChar ~
27328 \SpecialChar ~
27329 case 5: ...
27330  
27331 \newline 
27332 \SpecialChar ~
27333 \SpecialChar ~
27334 \SpecialChar ~
27335 case 9: ...\SpecialChar ~
27336 \SpecialChar ~
27337 \SpecialChar ~
27338 \SpecialChar ~
27339 \SpecialChar ~
27340 \SpecialChar ~
27341 \SpecialChar ~
27342 \SpecialChar ~
27343 \SpecialChar ~
27344 \SpecialChar ~
27345 \SpecialChar ~
27346 \SpecialChar ~
27347 \SpecialChar ~
27348 \SpecialChar ~
27349 \SpecialChar ~
27350 \SpecialChar ~
27351 \SpecialChar ~
27352 \SpecialChar ~
27353 \SpecialChar ~
27354 \SpecialChar ~
27355 \SpecialChar ~
27356 \SpecialChar ~
27357 \SpecialChar ~
27358 \SpecialChar ~
27359 \SpecialChar ~
27360 \SpecialChar ~
27361 case 6: ...
27362  
27363 \newline 
27364 \SpecialChar ~
27365 \SpecialChar ~
27366 \SpecialChar ~
27367 case 10: ...\SpecialChar ~
27368 \SpecialChar ~
27369 \SpecialChar ~
27370 \SpecialChar ~
27371 \SpecialChar ~
27372 \SpecialChar ~
27373 \SpecialChar ~
27374 \SpecialChar ~
27375 \SpecialChar ~
27376 \SpecialChar ~
27377 \SpecialChar ~
27378 \SpecialChar ~
27379 \SpecialChar ~
27380 \SpecialChar ~
27381 \SpecialChar ~
27382 \SpecialChar ~
27383 \SpecialChar ~
27384 \SpecialChar ~
27385 \SpecialChar ~
27386 \SpecialChar ~
27387 \SpecialChar ~
27388 \SpecialChar ~
27389 \SpecialChar ~
27390 \SpecialChar ~
27391 \SpecialChar ~
27392 case 7: ...
27393  
27394 \newline 
27395 \SpecialChar ~
27396 \SpecialChar ~
27397 \SpecialChar ~
27398 case 11: ...\SpecialChar ~
27399 \SpecialChar ~
27400 \SpecialChar ~
27401 \SpecialChar ~
27402 \SpecialChar ~
27403 \SpecialChar ~
27404 \SpecialChar ~
27405 \SpecialChar ~
27406 \SpecialChar ~
27407 \SpecialChar ~
27408 \SpecialChar ~
27409 \SpecialChar ~
27410 \SpecialChar ~
27411 \SpecialChar ~
27412 \SpecialChar ~
27413 \SpecialChar ~
27414 \SpecialChar ~
27415 \SpecialChar ~
27416 \SpecialChar ~
27417 \SpecialChar ~
27418 \SpecialChar ~
27419 \SpecialChar ~
27420 \SpecialChar ~
27421 \SpecialChar ~
27422 \SpecialChar ~
27423 case 8: ...
27424  
27425 \newline 
27426 }\SpecialChar ~
27427 \SpecialChar ~
27428 \SpecialChar ~
27429 \SpecialChar ~
27430 \SpecialChar ~
27431 \SpecialChar ~
27432 \SpecialChar ~
27433 \SpecialChar ~
27434 \SpecialChar ~
27435 \SpecialChar ~
27436 \SpecialChar ~
27437 \SpecialChar ~
27438 \SpecialChar ~
27439 \SpecialChar ~
27440 \SpecialChar ~
27441 \SpecialChar ~
27442 \SpecialChar ~
27443 \SpecialChar ~
27444 \SpecialChar ~
27445 \SpecialChar ~
27446 \SpecialChar ~
27447 \SpecialChar ~
27448 \SpecialChar ~
27449 \SpecialChar ~
27450 \SpecialChar ~
27451 \SpecialChar ~
27452 \SpecialChar ~
27453 \SpecialChar ~
27454 \SpecialChar ~
27455 \SpecialChar ~
27456 \SpecialChar ~
27457 \SpecialChar ~
27458 \SpecialChar ~
27459 \SpecialChar ~
27460 \SpecialChar ~
27461 \SpecialChar ~
27462 }
27463 \layout Standard
27464
27465 Both the above switch statements will be implemented using a jump-table.
27466  The example to the right side is slightly more efficient as the check for
27467  the lower boundary of the jump-table is not needed.
27468 \end_deeper 
27469 \layout Itemize
27470
27471 The number of case labels is not larger than supported by the target architectur
27472 e.
27473 \layout Itemize
27474
27475 If the case labels are not in numerical sequence ('gaps' between cases)
27476  SDCC checks whether a jump table with additionally inserted dummy cases
27477  is still attractive.
27478  
27479 \layout Itemize
27480
27481 If the starting number is not zero and a check for the lower boundary of
27482  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27483  ...
27484  .
27485 \layout Standard
27486
27487 Switch statements which have large gaps in the numeric sequence or those
27488  that have too many case labels can be split into more than one switch statement
27489  for efficient code generation, e.g.:
27490 \layout Verse
27491
27492
27493 \family typewriter 
27494 switch (i) { 
27495 \newline 
27496 \SpecialChar ~
27497 \SpecialChar ~
27498 case 1: ...
27499  
27500 \newline 
27501 \SpecialChar ~
27502 \SpecialChar ~
27503 case 2: ...
27504  
27505 \newline 
27506 \SpecialChar ~
27507 \SpecialChar ~
27508 case 3: ...
27509  
27510 \newline 
27511 \SpecialChar ~
27512 \SpecialChar ~
27513 case 4: ...
27514  
27515 \newline 
27516 \SpecialChar ~
27517 \SpecialChar ~
27518 case 5: ...
27519  
27520 \newline 
27521 \SpecialChar ~
27522 \SpecialChar ~
27523 case 6: ...
27524  
27525 \newline 
27526 \SpecialChar ~
27527 \SpecialChar ~
27528 case 7: ...
27529  
27530 \newline 
27531 \SpecialChar ~
27532 \SpecialChar ~
27533 case 101: ...
27534  
27535 \newline 
27536 \SpecialChar ~
27537 \SpecialChar ~
27538 case 102: ...
27539  
27540 \newline 
27541 \SpecialChar ~
27542 \SpecialChar ~
27543 case 103: ...
27544  
27545 \newline 
27546 \SpecialChar ~
27547 \SpecialChar ~
27548 case 104: ...
27549  
27550 \newline 
27551 \SpecialChar ~
27552 \SpecialChar ~
27553 case 105: ...
27554  
27555 \newline 
27556 \SpecialChar ~
27557 \SpecialChar ~
27558 case 106: ...
27559  
27560 \newline 
27561 \SpecialChar ~
27562 \SpecialChar ~
27563 case 107: ...
27564  
27565 \newline 
27566 }
27567 \layout Standard
27568
27569 If the above switch statement is broken down into two switch statements
27570 \layout Verse
27571
27572
27573 \family typewriter 
27574 switch (i) { 
27575 \newline 
27576 \SpecialChar ~
27577 \SpecialChar ~
27578 case 1: ...
27579  
27580 \newline 
27581 \SpecialChar ~
27582 \SpecialChar ~
27583 case 2: ...
27584  
27585 \newline 
27586 \SpecialChar ~
27587 \SpecialChar ~
27588 case 3: ...
27589  
27590 \newline 
27591 \SpecialChar ~
27592 \SpecialChar ~
27593 case 4: ...
27594  
27595 \newline 
27596 \SpecialChar ~
27597 \SpecialChar ~
27598 case 5: ...
27599  
27600 \newline 
27601 \SpecialChar ~
27602 \SpecialChar ~
27603 case 6: ...
27604  
27605 \newline 
27606 \SpecialChar ~
27607 \SpecialChar ~
27608 case 7: ...
27609  
27610 \newline 
27611 }
27612 \layout Standard
27613
27614 and
27615 \layout Verse
27616
27617
27618 \family typewriter 
27619 switch (i) { 
27620 \newline 
27621 \SpecialChar ~
27622 \SpecialChar ~
27623 case 101: ...
27624  
27625 \newline 
27626 \SpecialChar ~
27627 \SpecialChar ~
27628 case 102: ...
27629  
27630 \newline 
27631 \SpecialChar ~
27632 \SpecialChar ~
27633 case 103: ...
27634  
27635 \newline 
27636 \SpecialChar ~
27637 \SpecialChar ~
27638 case 104: ...
27639  
27640 \newline 
27641 \SpecialChar ~
27642 \SpecialChar ~
27643 case 105: ...
27644  
27645 \newline 
27646 \SpecialChar ~
27647 \SpecialChar ~
27648 case 106: ...
27649  
27650 \newline 
27651 \SpecialChar ~
27652 \SpecialChar ~
27653 case 107: ...
27654  
27655 \newline 
27656 }
27657 \layout Standard
27658
27659 then both the switch statements will be implemented using jump-tables whereas
27660  the unmodified switch statement will not be.
27661 \layout Comment
27662
27663 There might be reasons which SDCC cannot know about to either favour or
27664  not favour jump tables.
27665  If the target system has to be as quick for the last switch case as for
27666  the first (pro jump table), or if the switch argument is known to be zero
27667  in the majority of the cases (contra jump table).
27668 \layout Standard
27669
27670 The pragma nojtbound
27671 \begin_inset LatexCommand \index{\#pragma nojtbound}
27672
27673 \end_inset 
27674
27675  can be used to turn off checking the 
27676 \emph on 
27677 j
27678 \emph default 
27679 ump 
27680 \emph on 
27681 t
27682 \emph default 
27683 able 
27684 \emph on 
27685 bound
27686 \emph default 
27687 aries.
27688  It has no effect if a default label is supplied.
27689  Use of this pragma is dangerous: if the switch
27690 \begin_inset LatexCommand \index{switch statement}
27691
27692 \end_inset 
27693
27694  argument is not matched by a case statement the processor will happily
27695  jump into Nirvana.
27696 \layout Subsection
27697
27698 Bit-shifting Operations
27699 \begin_inset LatexCommand \index{Bit shifting}
27700
27701 \end_inset 
27702
27703 .
27704 \layout Standard
27705
27706 Bit shifting is one of the most frequently used operation in embedded programmin
27707 g.
27708  SDCC tries to implement bit-shift operations in the most efficient way
27709  possible, e.g.:
27710 \layout Verse
27711
27712
27713 \family typewriter 
27714 unsigned char i;
27715 \newline 
27716 ...
27717  
27718 \newline 
27719 i >>= 4; 
27720 \newline 
27721 ...
27722 \layout Standard
27723
27724 generates the following code:
27725 \layout Verse
27726
27727
27728 \family typewriter 
27729 mov\SpecialChar ~
27730  a,_i 
27731 \newline 
27732 swap a 
27733 \newline 
27734 anl\SpecialChar ~
27735  a,#0x0f 
27736 \newline 
27737 mov\SpecialChar ~
27738  _i,a
27739 \layout Standard
27740
27741 In general SDCC will never setup a loop if the shift count is known.
27742  Another example:
27743 \layout Verse
27744
27745
27746 \family typewriter 
27747 unsigned int i; 
27748 \newline 
27749 ...
27750  
27751 \newline 
27752 i >>= 9; 
27753 \newline 
27754 ...
27755 \layout Standard
27756
27757 will generate:
27758 \layout Verse
27759
27760
27761 \family typewriter 
27762 mov\SpecialChar ~
27763 \SpecialChar ~
27764 a,(_i + 1) 
27765 \newline 
27766 mov\SpecialChar ~
27767 \SpecialChar ~
27768 (_i + 1),#0x00 
27769 \newline 
27770 clr\SpecialChar ~
27771 \SpecialChar ~
27772
27773 \newline 
27774 rrc\SpecialChar ~
27775 \SpecialChar ~
27776
27777 \newline 
27778 mov\SpecialChar ~
27779 \SpecialChar ~
27780 _i,a
27781 \layout Subsection
27782
27783 Bit-rotation
27784 \begin_inset LatexCommand \index{Bit rotation}
27785
27786 \end_inset 
27787
27788
27789 \layout Standard
27790
27791 A special case of the bit-shift operation is bit rotation
27792 \begin_inset LatexCommand \index{rotating bits}
27793
27794 \end_inset 
27795
27796 , SDCC recognizes the following expression to be a left bit-rotation:
27797 \layout Verse
27798
27799
27800 \family typewriter 
27801 \series bold 
27802 unsigned
27803 \series default 
27804 \SpecialChar ~
27805 \SpecialChar ~
27806 char i;\SpecialChar ~
27807 \SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 \SpecialChar ~
27812 \SpecialChar ~
27813 \SpecialChar ~
27814 \SpecialChar ~
27815 \SpecialChar ~
27816 \SpecialChar ~
27817 /* unsigned is needed for rotation */ 
27818 \newline 
27819 ...
27820  
27821 \newline 
27822 i = ((i << 1) | (i >> 7)); 
27823 \family default 
27824
27825 \newline 
27826
27827 \family typewriter 
27828 ...
27829 \layout Standard
27830
27831 will generate the following code:
27832 \layout Verse
27833
27834
27835 \family typewriter 
27836 mov\SpecialChar ~
27837 \SpecialChar ~
27838 a,_i 
27839 \newline 
27840 rl\SpecialChar ~
27841 \SpecialChar ~
27842 \SpecialChar ~
27843
27844 \newline 
27845 mov\SpecialChar ~
27846 \SpecialChar ~
27847 _i,a
27848 \layout Standard
27849
27850 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27851 ns of this case will also be recognized as bit-rotation, i.e.: 
27852 \layout Verse
27853
27854
27855 \family typewriter 
27856 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27857 \layout Subsection
27858
27859 Nibble and Byte Swapping
27860 \layout Standard
27861
27862 Other special cases of the bit-shift operations are nibble or byte swapping
27863 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27864
27865 \end_inset 
27866
27867 , SDCC recognizes the following expressions:
27868 \layout Verse
27869
27870
27871 \family typewriter 
27872 \series bold 
27873 unsigned
27874 \series default 
27875 \SpecialChar ~
27876 \SpecialChar ~
27877 char i; 
27878 \newline 
27879
27880 \series bold 
27881 unsigned
27882 \series default 
27883 \SpecialChar ~
27884 \SpecialChar ~
27885 int j; 
27886 \newline 
27887 ...
27888  
27889 \newline 
27890 i = ((i << 4) | (i >> 4)); 
27891 \family default 
27892
27893 \newline 
27894
27895 \family typewriter 
27896 j = ((j << 8) | (j >> 8)); 
27897 \layout Standard
27898
27899 and generates a swap instruction for the nibble swapping
27900 \begin_inset LatexCommand \index{Nibble swapping}
27901
27902 \end_inset 
27903
27904  or move instructions for the byte swapping
27905 \begin_inset LatexCommand \index{Byte swapping}
27906
27907 \end_inset 
27908
27909 .
27910  The 
27911 \begin_inset Quotes sld
27912 \end_inset 
27913
27914 j
27915 \begin_inset Quotes srd
27916 \end_inset 
27917
27918  example can be used to convert from little to big-endian or vice versa.
27919  If you want to change the endianness of a 
27920 \emph on 
27921 signed
27922 \emph default 
27923  integer you have to cast to 
27924 \family typewriter 
27925 (unsigned int)
27926 \family default 
27927  first.
27928 \layout Standard
27929
27930 Note that SDCC stores numbers in little-endian
27931 \begin_inset Foot
27932 collapsed false
27933
27934 \layout Standard
27935
27936 Usually 8-bit processors don't care much about endianness.
27937  This is not the case for the standard 8051 which only has an instruction
27938  to increment its 
27939 \emph on 
27940 dptr
27941 \emph default 
27942
27943 \begin_inset LatexCommand \index{DPTR}
27944
27945 \end_inset 
27946
27947 -datapointer
27948 \emph on 
27949  
27950 \emph default 
27951 so little-endian is the more efficient byte order.
27952 \end_inset 
27953
27954
27955 \begin_inset LatexCommand \index{little-endian}
27956
27957 \end_inset 
27958
27959
27960 \begin_inset LatexCommand \index{Endianness}
27961
27962 \end_inset 
27963
27964  format (i.e.
27965  lowest order first).
27966 \layout Subsection
27967
27968 Highest Order Bit
27969 \begin_inset LatexCommand \index{Highest Order Bit}
27970
27971 \end_inset 
27972
27973  / Any Order Bit
27974 \begin_inset LatexCommand \index{Any Order Bit}
27975
27976 \end_inset 
27977
27978
27979 \layout Standard
27980
27981 It is frequently required to obtain the highest order bit of an integral
27982  type (long, int, short or char types).
27983  Also obtaining any other order bit is not uncommon.
27984  SDCC recognizes the following expressions to yield the highest order bit
27985  and generates optimized code for it, e.g.:
27986 \layout Verse
27987
27988
27989 \family typewriter 
27990 unsigned int gint; 
27991 \newline 
27992
27993 \newline 
27994 foo () { 
27995 \newline 
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 unsigned char hob1, aob1; 
27999 \newline 
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 bit hob2, hob3, aob2, aob3; 
28003 \newline 
28004 \SpecialChar ~
28005 \SpecialChar ~
28006 ...
28007  
28008 \newline 
28009 \SpecialChar ~
28010 \SpecialChar ~
28011 hob1 = (gint >> 15) & 1; 
28012 \newline 
28013 \SpecialChar ~
28014 \SpecialChar ~
28015 hob2 = (gint >> 15) & 1; 
28016 \newline 
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 hob3 = gint & 0x8000; 
28020 \newline 
28021 \SpecialChar ~
28022 \SpecialChar ~
28023 aob1 = (gint >> 9) & 1; 
28024 \newline 
28025 \SpecialChar ~
28026 \SpecialChar ~
28027 aob2 = (gint >> 8) & 1; 
28028 \newline 
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 aob3 = gint & 0x0800; 
28032 \newline 
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 ..
28036  
28037 \newline 
28038 }
28039 \layout Standard
28040
28041 will generate the following code:
28042 \layout Verse
28043
28044
28045 \family typewriter 
28046 \SpecialChar ~
28047 \SpecialChar ~
28048 \SpecialChar ~
28049 \SpecialChar ~
28050 \SpecialChar ~
28051 \SpecialChar ~
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 \SpecialChar ~
28055 \SpecialChar ~
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 \SpecialChar ~
28064 \SpecialChar ~
28065 \SpecialChar ~
28066 \SpecialChar ~
28067 \SpecialChar ~
28068 \SpecialChar ~
28069 \SpecialChar ~
28070 \SpecialChar ~
28071  61 ;\SpecialChar ~
28072  hob.c 7 
28073 \newline 
28074 000A E5*01\SpecialChar ~
28075 \SpecialChar ~
28076 \SpecialChar ~
28077 \SpecialChar ~
28078 \SpecialChar ~
28079 \SpecialChar ~
28080 \SpecialChar ~
28081 \SpecialChar ~
28082 \SpecialChar ~
28083 \SpecialChar ~
28084 \SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088 \SpecialChar ~
28089  62\SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097  mov\SpecialChar ~
28098 \SpecialChar ~
28099  a,(_gint + 1) 
28100 \newline 
28101 000C 23\SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104 \SpecialChar ~
28105 \SpecialChar ~
28106 \SpecialChar ~
28107 \SpecialChar ~
28108 \SpecialChar ~
28109 \SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 \SpecialChar ~
28114 \SpecialChar ~
28115 \SpecialChar ~
28116 \SpecialChar ~
28117 \SpecialChar ~
28118 \SpecialChar ~
28119  63\SpecialChar ~
28120 \SpecialChar ~
28121 \SpecialChar ~
28122 \SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127  rl\SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130  a 
28131 \newline 
28132 000D 54 01\SpecialChar ~
28133 \SpecialChar ~
28134 \SpecialChar ~
28135 \SpecialChar ~
28136 \SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147  64\SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150 \SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155  anl\SpecialChar ~
28156 \SpecialChar ~
28157  a,#0x01 
28158 \newline 
28159 000F F5*02\SpecialChar ~
28160 \SpecialChar ~
28161 \SpecialChar ~
28162 \SpecialChar ~
28163 \SpecialChar ~
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 \SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174  65\SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182  mov\SpecialChar ~
28183 \SpecialChar ~
28184  _foo_hob1_1_1,a 
28185 \newline 
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189 \SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192 \SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202 \SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211  66 ;\SpecialChar ~
28212  hob.c 8 
28213 \newline 
28214 0011 E5*01\SpecialChar ~
28215 \SpecialChar ~
28216 \SpecialChar ~
28217 \SpecialChar ~
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226 \SpecialChar ~
28227 \SpecialChar ~
28228 \SpecialChar ~
28229  67\SpecialChar ~
28230 \SpecialChar ~
28231 \SpecialChar ~
28232 \SpecialChar ~
28233 \SpecialChar ~
28234 \SpecialChar ~
28235 \SpecialChar ~
28236 \SpecialChar ~
28237  mov\SpecialChar ~
28238 \SpecialChar ~
28239  a,(_gint + 1) 
28240 \newline 
28241 0013 33\SpecialChar ~
28242 \SpecialChar ~
28243 \SpecialChar ~
28244 \SpecialChar ~
28245 \SpecialChar ~
28246 \SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249 \SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252 \SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259  68\SpecialChar ~
28260 \SpecialChar ~
28261 \SpecialChar ~
28262 \SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267  rlc\SpecialChar ~
28268 \SpecialChar ~
28269  a 
28270 \newline 
28271 0014 92*00\SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274 \SpecialChar ~
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 \SpecialChar ~
28278 \SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 \SpecialChar ~
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 \SpecialChar ~
28286  69\SpecialChar ~
28287 \SpecialChar ~
28288 \SpecialChar ~
28289 \SpecialChar ~
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294  mov\SpecialChar ~
28295 \SpecialChar ~
28296  _foo_hob2_1_1,c 
28297 \newline 
28298 \SpecialChar ~
28299 \SpecialChar ~
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 \SpecialChar ~
28303 \SpecialChar ~
28304 \SpecialChar ~
28305 \SpecialChar ~
28306 \SpecialChar ~
28307 \SpecialChar ~
28308 \SpecialChar ~
28309 \SpecialChar ~
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 \SpecialChar ~
28313 \SpecialChar ~
28314 \SpecialChar ~
28315 \SpecialChar ~
28316 \SpecialChar ~
28317 \SpecialChar ~
28318 \SpecialChar ~
28319 \SpecialChar ~
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323  66 ;\SpecialChar ~
28324  hob.c 9 
28325 \newline 
28326 0016 E5*01\SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329 \SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 \SpecialChar ~
28338 \SpecialChar ~
28339 \SpecialChar ~
28340 \SpecialChar ~
28341  67\SpecialChar ~
28342 \SpecialChar ~
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349  mov\SpecialChar ~
28350 \SpecialChar ~
28351  a,(_gint + 1) 
28352 \newline 
28353 0018 33\SpecialChar ~
28354 \SpecialChar ~
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 \SpecialChar ~
28362 \SpecialChar ~
28363 \SpecialChar ~
28364 \SpecialChar ~
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369 \SpecialChar ~
28370 \SpecialChar ~
28371  68\SpecialChar ~
28372 \SpecialChar ~
28373 \SpecialChar ~
28374 \SpecialChar ~
28375 \SpecialChar ~
28376 \SpecialChar ~
28377 \SpecialChar ~
28378 \SpecialChar ~
28379  rlc\SpecialChar ~
28380 \SpecialChar ~
28381  a 
28382 \newline 
28383 0019 92*01\SpecialChar ~
28384 \SpecialChar ~
28385 \SpecialChar ~
28386 \SpecialChar ~
28387 \SpecialChar ~
28388 \SpecialChar ~
28389 \SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398  69\SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406  mov\SpecialChar ~
28407 \SpecialChar ~
28408  _foo_hob3_1_1,c 
28409 \newline 
28410 \SpecialChar ~
28411 \SpecialChar ~
28412 \SpecialChar ~
28413 \SpecialChar ~
28414 \SpecialChar ~
28415 \SpecialChar ~
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 \SpecialChar ~
28419 \SpecialChar ~
28420 \SpecialChar ~
28421 \SpecialChar ~
28422 \SpecialChar ~
28423 \SpecialChar ~
28424 \SpecialChar ~
28425 \SpecialChar ~
28426 \SpecialChar ~
28427 \SpecialChar ~
28428 \SpecialChar ~
28429 \SpecialChar ~
28430 \SpecialChar ~
28431 \SpecialChar ~
28432 \SpecialChar ~
28433 \SpecialChar ~
28434 \SpecialChar ~
28435  70 ;\SpecialChar ~
28436  hob.c 10 
28437 \newline 
28438 001B E5*01\SpecialChar ~
28439 \SpecialChar ~
28440 \SpecialChar ~
28441 \SpecialChar ~
28442 \SpecialChar ~
28443 \SpecialChar ~
28444 \SpecialChar ~
28445 \SpecialChar ~
28446 \SpecialChar ~
28447 \SpecialChar ~
28448 \SpecialChar ~
28449 \SpecialChar ~
28450 \SpecialChar ~
28451 \SpecialChar ~
28452 \SpecialChar ~
28453  71\SpecialChar ~
28454 \SpecialChar ~
28455 \SpecialChar ~
28456 \SpecialChar ~
28457 \SpecialChar ~
28458 \SpecialChar ~
28459 \SpecialChar ~
28460 \SpecialChar ~
28461  mov\SpecialChar ~
28462 \SpecialChar ~
28463  a,(_gint + 1) 
28464 \newline 
28465 001D 03\SpecialChar ~
28466 \SpecialChar ~
28467 \SpecialChar ~
28468 \SpecialChar ~
28469 \SpecialChar ~
28470 \SpecialChar ~
28471 \SpecialChar ~
28472 \SpecialChar ~
28473 \SpecialChar ~
28474 \SpecialChar ~
28475 \SpecialChar ~
28476 \SpecialChar ~
28477 \SpecialChar ~
28478 \SpecialChar ~
28479 \SpecialChar ~
28480 \SpecialChar ~
28481 \SpecialChar ~
28482 \SpecialChar ~
28483  72\SpecialChar ~
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 \SpecialChar ~
28487 \SpecialChar ~
28488 \SpecialChar ~
28489 \SpecialChar ~
28490 \SpecialChar ~
28491  rr\SpecialChar ~
28492 \SpecialChar ~
28493 \SpecialChar ~
28494  a 
28495 \newline 
28496 001E 54 01\SpecialChar ~
28497 \SpecialChar ~
28498 \SpecialChar ~
28499 \SpecialChar ~
28500 \SpecialChar ~
28501 \SpecialChar ~
28502 \SpecialChar ~
28503 \SpecialChar ~
28504 \SpecialChar ~
28505 \SpecialChar ~
28506 \SpecialChar ~
28507 \SpecialChar ~
28508 \SpecialChar ~
28509 \SpecialChar ~
28510 \SpecialChar ~
28511  73\SpecialChar ~
28512 \SpecialChar ~
28513 \SpecialChar ~
28514 \SpecialChar ~
28515 \SpecialChar ~
28516 \SpecialChar ~
28517 \SpecialChar ~
28518 \SpecialChar ~
28519  anl\SpecialChar ~
28520 \SpecialChar ~
28521  a,#0x01 
28522 \newline 
28523 0020 F5*03\SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526 \SpecialChar ~
28527 \SpecialChar ~
28528 \SpecialChar ~
28529 \SpecialChar ~
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 \SpecialChar ~
28533 \SpecialChar ~
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 \SpecialChar ~
28537 \SpecialChar ~
28538  74\SpecialChar ~
28539 \SpecialChar ~
28540 \SpecialChar ~
28541 \SpecialChar ~
28542 \SpecialChar ~
28543 \SpecialChar ~
28544 \SpecialChar ~
28545 \SpecialChar ~
28546  mov\SpecialChar ~
28547 \SpecialChar ~
28548  _foo_aob1_1_1,a 
28549 \newline 
28550 \SpecialChar ~
28551 \SpecialChar ~
28552 \SpecialChar ~
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 \SpecialChar ~
28556 \SpecialChar ~
28557 \SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 \SpecialChar ~
28562 \SpecialChar ~
28563 \SpecialChar ~
28564 \SpecialChar ~
28565 \SpecialChar ~
28566 \SpecialChar ~
28567 \SpecialChar ~
28568 \SpecialChar ~
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 \SpecialChar ~
28572 \SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575  75 ;\SpecialChar ~
28576  hob.c 11 
28577 \newline 
28578 0022 E5*01\SpecialChar ~
28579 \SpecialChar ~
28580 \SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 \SpecialChar ~
28591 \SpecialChar ~
28592 \SpecialChar ~
28593  76\SpecialChar ~
28594 \SpecialChar ~
28595 \SpecialChar ~
28596 \SpecialChar ~
28597 \SpecialChar ~
28598 \SpecialChar ~
28599 \SpecialChar ~
28600 \SpecialChar ~
28601  mov\SpecialChar ~
28602 \SpecialChar ~
28603  a,(_gint + 1) 
28604 \newline 
28605 0024 13\SpecialChar ~
28606 \SpecialChar ~
28607 \SpecialChar ~
28608 \SpecialChar ~
28609 \SpecialChar ~
28610 \SpecialChar ~
28611 \SpecialChar ~
28612 \SpecialChar ~
28613 \SpecialChar ~
28614 \SpecialChar ~
28615 \SpecialChar ~
28616 \SpecialChar ~
28617 \SpecialChar ~
28618 \SpecialChar ~
28619 \SpecialChar ~
28620 \SpecialChar ~
28621 \SpecialChar ~
28622 \SpecialChar ~
28623  77\SpecialChar ~
28624 \SpecialChar ~
28625 \SpecialChar ~
28626 \SpecialChar ~
28627 \SpecialChar ~
28628 \SpecialChar ~
28629 \SpecialChar ~
28630 \SpecialChar ~
28631  rrc\SpecialChar ~
28632 \SpecialChar ~
28633  a 
28634 \newline 
28635 0025 92*02\SpecialChar ~
28636 \SpecialChar ~
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 \SpecialChar ~
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 \SpecialChar ~
28644 \SpecialChar ~
28645 \SpecialChar ~
28646 \SpecialChar ~
28647 \SpecialChar ~
28648 \SpecialChar ~
28649 \SpecialChar ~
28650  78\SpecialChar ~
28651 \SpecialChar ~
28652 \SpecialChar ~
28653 \SpecialChar ~
28654 \SpecialChar ~
28655 \SpecialChar ~
28656 \SpecialChar ~
28657 \SpecialChar ~
28658  mov\SpecialChar ~
28659 \SpecialChar ~
28660  _foo_aob2_1_1,c 
28661 \newline 
28662 \SpecialChar ~
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 \SpecialChar ~
28667 \SpecialChar ~
28668 \SpecialChar ~
28669 \SpecialChar ~
28670 \SpecialChar ~
28671 \SpecialChar ~
28672 \SpecialChar ~
28673 \SpecialChar ~
28674 \SpecialChar ~
28675 \SpecialChar ~
28676 \SpecialChar ~
28677 \SpecialChar ~
28678 \SpecialChar ~
28679 \SpecialChar ~
28680 \SpecialChar ~
28681 \SpecialChar ~
28682 \SpecialChar ~
28683 \SpecialChar ~
28684 \SpecialChar ~
28685 \SpecialChar ~
28686 \SpecialChar ~
28687  79 ;\SpecialChar ~
28688  hob.c 12 
28689 \newline 
28690 0027 E5*01\SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693 \SpecialChar ~
28694 \SpecialChar ~
28695 \SpecialChar ~
28696 \SpecialChar ~
28697 \SpecialChar ~
28698 \SpecialChar ~
28699 \SpecialChar ~
28700 \SpecialChar ~
28701 \SpecialChar ~
28702 \SpecialChar ~
28703 \SpecialChar ~
28704 \SpecialChar ~
28705  80\SpecialChar ~
28706 \SpecialChar ~
28707 \SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710 \SpecialChar ~
28711 \SpecialChar ~
28712 \SpecialChar ~
28713  mov\SpecialChar ~
28714 \SpecialChar ~
28715  a,(_gint + 1) 
28716 \newline 
28717 0029 A2 E3\SpecialChar ~
28718 \SpecialChar ~
28719 \SpecialChar ~
28720 \SpecialChar ~
28721 \SpecialChar ~
28722 \SpecialChar ~
28723 \SpecialChar ~
28724 \SpecialChar ~
28725 \SpecialChar ~
28726 \SpecialChar ~
28727 \SpecialChar ~
28728 \SpecialChar ~
28729 \SpecialChar ~
28730 \SpecialChar ~
28731 \SpecialChar ~
28732  81\SpecialChar ~
28733 \SpecialChar ~
28734 \SpecialChar ~
28735 \SpecialChar ~
28736 \SpecialChar ~
28737 \SpecialChar ~
28738 \SpecialChar ~
28739 \SpecialChar ~
28740  mov\SpecialChar ~
28741 \SpecialChar ~
28742  c,acc[3] 
28743 \newline 
28744 002B 92*03\SpecialChar ~
28745 \SpecialChar ~
28746 \SpecialChar ~
28747 \SpecialChar ~
28748 \SpecialChar ~
28749 \SpecialChar ~
28750 \SpecialChar ~
28751 \SpecialChar ~
28752 \SpecialChar ~
28753 \SpecialChar ~
28754 \SpecialChar ~
28755 \SpecialChar ~
28756 \SpecialChar ~
28757 \SpecialChar ~
28758 \SpecialChar ~
28759  82\SpecialChar ~
28760 \SpecialChar ~
28761 \SpecialChar ~
28762 \SpecialChar ~
28763 \SpecialChar ~
28764 \SpecialChar ~
28765 \SpecialChar ~
28766 \SpecialChar ~
28767  mov\SpecialChar ~
28768 \SpecialChar ~
28769  _foo_aob3_1_1,c 
28770 \layout Standard
28771
28772 Other variations of these cases however will 
28773 \emph on 
28774 not
28775 \emph default 
28776  be recognized.
28777  They are standard C expressions, so I heartily recommend these be the only
28778  way to get the highest order bit, (it is portable).
28779  Of course it will be recognized even if it is embedded in other expressions,
28780  e.g.:
28781 \layout Verse
28782
28783
28784 \family typewriter 
28785 xyz = gint + ((gint >> 15) & 1);
28786 \layout Standard
28787
28788 will still be recognized.
28789 \layout Subsection
28790
28791 Higher Order Byte
28792 \begin_inset LatexCommand \index{Higher Order Byte}
28793
28794 \end_inset 
28795
28796  / Higher Order Word
28797 \begin_inset LatexCommand \index{Higher Order Word}
28798
28799 \end_inset 
28800
28801
28802 \layout Standard
28803
28804 It is also frequently required to obtain a higher order byte or word of
28805  a larger integral type (long, int or short types).
28806  SDCC recognizes the following expressions to yield the higher order byte
28807  or word and generates optimized code for it, e.g.:
28808 \layout Verse
28809
28810
28811 \family typewriter 
28812 unsigned int gint; 
28813 \newline 
28814 unsigned long int glong; 
28815 \newline 
28816
28817 \newline 
28818 foo () { 
28819 \newline 
28820 \SpecialChar ~
28821 \SpecialChar ~
28822 unsigned char hob1, hob2; 
28823 \newline 
28824 \SpecialChar ~
28825 \SpecialChar ~
28826 unsigned int how1, how2; 
28827 \newline 
28828 \SpecialChar ~
28829 \SpecialChar ~
28830 ...
28831  
28832 \newline 
28833 \SpecialChar ~
28834 \SpecialChar ~
28835 hob1 = (gint >> 8) & 0xFF; 
28836 \newline 
28837 \SpecialChar ~
28838 \SpecialChar ~
28839 hob2 = glong >> 24; 
28840 \newline 
28841 \SpecialChar ~
28842 \SpecialChar ~
28843 how1 = (glong >> 16) & 0xFFFF; 
28844 \newline 
28845 \SpecialChar ~
28846 \SpecialChar ~
28847 how2 = glong >> 8; 
28848 \newline 
28849 \SpecialChar ~
28850 \SpecialChar ~
28851 ..
28852  
28853 \newline 
28854 }
28855 \layout Standard
28856
28857 will generate the following code:
28858 \layout Verse
28859
28860
28861 \family typewriter 
28862 \SpecialChar ~
28863 \SpecialChar ~
28864 \SpecialChar ~
28865 \SpecialChar ~
28866 \SpecialChar ~
28867 \SpecialChar ~
28868 \SpecialChar ~
28869 \SpecialChar ~
28870 \SpecialChar ~
28871 \SpecialChar ~
28872 \SpecialChar ~
28873 \SpecialChar ~
28874 \SpecialChar ~
28875 \SpecialChar ~
28876 \SpecialChar ~
28877 \SpecialChar ~
28878 \SpecialChar ~
28879 \SpecialChar ~
28880 \SpecialChar ~
28881 \SpecialChar ~
28882 \SpecialChar ~
28883 \SpecialChar ~
28884 \SpecialChar ~
28885 \SpecialChar ~
28886 \SpecialChar ~
28887  91 ;\SpecialChar ~
28888  hob.c 15 
28889 \newline 
28890 0037 85*01*06\SpecialChar ~
28891 \SpecialChar ~
28892 \SpecialChar ~
28893 \SpecialChar ~
28894 \SpecialChar ~
28895 \SpecialChar ~
28896 \SpecialChar ~
28897 \SpecialChar ~
28898 \SpecialChar ~
28899 \SpecialChar ~
28900 \SpecialChar ~
28901 \SpecialChar ~
28902  92\SpecialChar ~
28903 \SpecialChar ~
28904 \SpecialChar ~
28905 \SpecialChar ~
28906 \SpecialChar ~
28907 \SpecialChar ~
28908 \SpecialChar ~
28909 \SpecialChar ~
28910  mov\SpecialChar ~
28911 \SpecialChar ~
28912  _foo_hob1_1_1,(_gint + 1) 
28913 \newline 
28914 \SpecialChar ~
28915 \SpecialChar ~
28916 \SpecialChar ~
28917 \SpecialChar ~
28918 \SpecialChar ~
28919 \SpecialChar ~
28920 \SpecialChar ~
28921 \SpecialChar ~
28922 \SpecialChar ~
28923 \SpecialChar ~
28924 \SpecialChar ~
28925 \SpecialChar ~
28926 \SpecialChar ~
28927 \SpecialChar ~
28928 \SpecialChar ~
28929 \SpecialChar ~
28930 \SpecialChar ~
28931 \SpecialChar ~
28932 \SpecialChar ~
28933 \SpecialChar ~
28934 \SpecialChar ~
28935 \SpecialChar ~
28936 \SpecialChar ~
28937 \SpecialChar ~
28938 \SpecialChar ~
28939  93 ;\SpecialChar ~
28940  hob.c 16 
28941 \newline 
28942 003A 85*05*07\SpecialChar ~
28943 \SpecialChar ~
28944 \SpecialChar ~
28945 \SpecialChar ~
28946 \SpecialChar ~
28947 \SpecialChar ~
28948 \SpecialChar ~
28949 \SpecialChar ~
28950 \SpecialChar ~
28951 \SpecialChar ~
28952 \SpecialChar ~
28953 \SpecialChar ~
28954  94\SpecialChar ~
28955 \SpecialChar ~
28956 \SpecialChar ~
28957 \SpecialChar ~
28958 \SpecialChar ~
28959 \SpecialChar ~
28960 \SpecialChar ~
28961 \SpecialChar ~
28962  mov\SpecialChar ~
28963 \SpecialChar ~
28964  _foo_hob2_1_1,(_glong + 3) 
28965 \newline 
28966 \SpecialChar ~
28967 \SpecialChar ~
28968 \SpecialChar ~
28969 \SpecialChar ~
28970 \SpecialChar ~
28971 \SpecialChar ~
28972 \SpecialChar ~
28973 \SpecialChar ~
28974 \SpecialChar ~
28975 \SpecialChar ~
28976 \SpecialChar ~
28977 \SpecialChar ~
28978 \SpecialChar ~
28979 \SpecialChar ~
28980 \SpecialChar ~
28981 \SpecialChar ~
28982 \SpecialChar ~
28983 \SpecialChar ~
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 \SpecialChar ~
28987 \SpecialChar ~
28988 \SpecialChar ~
28989 \SpecialChar ~
28990 \SpecialChar ~
28991  95 ;\SpecialChar ~
28992  hob.c 17 
28993 \newline 
28994 003D 85*04*08\SpecialChar ~
28995 \SpecialChar ~
28996 \SpecialChar ~
28997 \SpecialChar ~
28998 \SpecialChar ~
28999 \SpecialChar ~
29000 \SpecialChar ~
29001 \SpecialChar ~
29002 \SpecialChar ~
29003 \SpecialChar ~
29004 \SpecialChar ~
29005 \SpecialChar ~
29006  96\SpecialChar ~
29007 \SpecialChar ~
29008 \SpecialChar ~
29009 \SpecialChar ~
29010 \SpecialChar ~
29011 \SpecialChar ~
29012 \SpecialChar ~
29013 \SpecialChar ~
29014  mov\SpecialChar ~
29015 \SpecialChar ~
29016  _foo_how1_1_1,(_glong + 2) 
29017 \newline 
29018 0040 85*05*09\SpecialChar ~
29019 \SpecialChar ~
29020 \SpecialChar ~
29021 \SpecialChar ~
29022 \SpecialChar ~
29023 \SpecialChar ~
29024 \SpecialChar ~
29025 \SpecialChar ~
29026 \SpecialChar ~
29027 \SpecialChar ~
29028 \SpecialChar ~
29029 \SpecialChar ~
29030  97\SpecialChar ~
29031 \SpecialChar ~
29032 \SpecialChar ~
29033 \SpecialChar ~
29034 \SpecialChar ~
29035 \SpecialChar ~
29036 \SpecialChar ~
29037 \SpecialChar ~
29038  mov\SpecialChar ~
29039 \SpecialChar ~
29040  (_foo_how1_1_1 + 1),(_glong + 3) 
29041 \newline 
29042 0043 85*03*0A\SpecialChar ~
29043 \SpecialChar ~
29044 \SpecialChar ~
29045 \SpecialChar ~
29046 \SpecialChar ~
29047 \SpecialChar ~
29048 \SpecialChar ~
29049 \SpecialChar ~
29050 \SpecialChar ~
29051 \SpecialChar ~
29052 \SpecialChar ~
29053 \SpecialChar ~
29054  98\SpecialChar ~
29055 \SpecialChar ~
29056 \SpecialChar ~
29057 \SpecialChar ~
29058 \SpecialChar ~
29059 \SpecialChar ~
29060 \SpecialChar ~
29061 \SpecialChar ~
29062  mov\SpecialChar ~
29063 \SpecialChar ~
29064  _foo_how2_1_1,(_glong + 1) 
29065 \newline 
29066 0046 85*04*0B\SpecialChar ~
29067 \SpecialChar ~
29068 \SpecialChar ~
29069 \SpecialChar ~
29070 \SpecialChar ~
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 \SpecialChar ~
29074 \SpecialChar ~
29075 \SpecialChar ~
29076 \SpecialChar ~
29077 \SpecialChar ~
29078  99\SpecialChar ~
29079 \SpecialChar ~
29080 \SpecialChar ~
29081 \SpecialChar ~
29082 \SpecialChar ~
29083 \SpecialChar ~
29084 \SpecialChar ~
29085 \SpecialChar ~
29086  mov\SpecialChar ~
29087 \SpecialChar ~
29088  (_foo_how2_1_1 + 1),(_glong + 2) 
29089 \layout Standard
29090
29091 Again, variations of these cases may 
29092 \emph on 
29093 not
29094 \emph default 
29095  be recognized.
29096  They are standard C expressions, so I heartily recommend these be the only
29097  way to get the higher order byte/word, (it is portable).
29098  Of course it will be recognized even if it is embedded in other expressions,
29099  e.g.:
29100 \layout Verse
29101
29102
29103 \family typewriter 
29104 xyz = gint + ((gint >> 8) & 0xFF);
29105 \layout Standard
29106
29107 will still be recognized.
29108 \layout Subsection
29109
29110 Peephole Optimizer
29111 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
29112
29113 \end_inset 
29114
29115
29116 \begin_inset LatexCommand \index{Peephole optimizer}
29117
29118 \end_inset 
29119
29120
29121 \layout Standard
29122
29123 The compiler uses a rule based, pattern matching and re-writing mechanism
29124  for peep-hole optimization.
29125  It is inspired by 
29126 \emph on 
29127 copt
29128 \emph default 
29129  a peep-hole optimizer by Christopher W.
29130  Fraser (cwfraser\SpecialChar ~
29131 @\SpecialChar ~
29132 microsoft.com).
29133  A default set of rules are compiled into the compiler, additional rules
29134  may be added with the 
29135 \emph on 
29136 -
29137 \begin_inset ERT
29138 status Collapsed
29139
29140 \layout Standard
29141
29142 \backslash 
29143 /
29144 \end_inset 
29145
29146 -peep-file
29147 \begin_inset LatexCommand \index{-\/-peep-file}
29148
29149 \end_inset 
29150
29151  <filename>
29152 \emph default 
29153  option.
29154  The rule language is best illustrated with examples.
29155 \layout Verse
29156
29157
29158 \family typewriter 
29159 replace { 
29160 \newline 
29161 \SpecialChar ~
29162 \SpecialChar ~
29163 mov %1,a 
29164 \newline 
29165 \SpecialChar ~
29166 \SpecialChar ~
29167 mov a,%1
29168 \newline 
29169 } by {
29170 \newline 
29171 \SpecialChar ~
29172 \SpecialChar ~
29173 mov %1,a
29174 \newline 
29175 }
29176 \layout Standard
29177
29178 The above rule will change the following assembly
29179 \begin_inset LatexCommand \index{Assembler routines}
29180
29181 \end_inset 
29182
29183  sequence:
29184 \layout Verse
29185
29186
29187 \family typewriter 
29188 mov r1,a 
29189 \newline 
29190 mov a,r1
29191 \layout Standard
29192
29193 to
29194 \layout Verse
29195
29196
29197 \family typewriter 
29198 mov r1,a
29199 \layout Standard
29200
29201 Note: All occurrences of a 
29202 \emph on 
29203 %n
29204 \emph default 
29205  (pattern variable) must denote the same string.
29206  With the above rule, the assembly sequence:
29207 \layout Verse
29208
29209
29210 \family typewriter 
29211 mov r1,a 
29212 \newline 
29213 mov a,r2
29214 \layout Standard
29215
29216 will remain unmodified.
29217 \newline 
29218
29219 \newline 
29220 Other special case optimizations may be added by the user (via 
29221 \emph on 
29222 -
29223 \begin_inset ERT
29224 status Collapsed
29225
29226 \layout Standard
29227
29228 \backslash 
29229 /
29230 \end_inset 
29231
29232 -peep-file option
29233 \emph default 
29234 ).
29235  E.g.
29236  some variants of the 8051 MCU
29237 \begin_inset LatexCommand \index{MCS51 variants}
29238
29239 \end_inset 
29240
29241  allow only 
29242 \family typewriter 
29243 ajmp
29244 \family default 
29245  and 
29246 \family typewriter 
29247 acall
29248 \family default 
29249 .
29250  The following two rules will change all 
29251 \family typewriter 
29252 ljmp
29253 \family default 
29254  and 
29255 \family typewriter 
29256 lcall
29257 \family default 
29258  to 
29259 \family typewriter 
29260 ajmp
29261 \family default 
29262  and 
29263 \family typewriter 
29264 acall
29265 \layout Verse
29266
29267
29268 \family typewriter 
29269 replace { lcall %1 } by { acall %1 } 
29270 \newline 
29271 replace { ljmp %1 } by { ajmp %1 }
29272 \layout Standard
29273
29274 The 
29275 \emph on 
29276 inline-assembler code
29277 \emph default 
29278  is also passed through the peep hole optimizer, thus the peephole optimizer
29279  can also be used as an assembly level macro expander.
29280  The rules themselves are MCU dependent whereas the rule language infra-structur
29281 e is MCU independent.
29282  Peephole optimization rules for other MCU can be easily programmed using
29283  the rule language.
29284 \newline 
29285
29286 \newline 
29287 The syntax for a rule is as follows:
29288 \layout Verse
29289
29290
29291 \family typewriter 
29292 rule := replace [ restart ] '{' <assembly sequence> '
29293 \backslash 
29294 n' 
29295 \newline 
29296 \SpecialChar ~
29297  \SpecialChar ~
29298  \SpecialChar ~
29299  \SpecialChar ~
29300  \SpecialChar ~
29301  \SpecialChar ~
29302  \SpecialChar ~
29303  \SpecialChar ~
29304  \SpecialChar ~
29305  \SpecialChar ~
29306  \SpecialChar ~
29307  \SpecialChar ~
29308  \SpecialChar ~
29309  \SpecialChar ~
29310  '}' by '{' '
29311 \backslash 
29312 n' 
29313 \newline 
29314 \SpecialChar ~
29315  \SpecialChar ~
29316  \SpecialChar ~
29317  \SpecialChar ~
29318  \SpecialChar ~
29319  \SpecialChar ~
29320  \SpecialChar ~
29321  \SpecialChar ~
29322  \SpecialChar ~
29323  \SpecialChar ~
29324  \SpecialChar ~
29325  \SpecialChar ~
29326  \SpecialChar ~
29327  \SpecialChar ~
29328  \SpecialChar ~
29329  \SpecialChar ~
29330  <assembly sequence> '
29331 \backslash 
29332 n' 
29333 \newline 
29334 \SpecialChar ~
29335  \SpecialChar ~
29336  \SpecialChar ~
29337  \SpecialChar ~
29338  \SpecialChar ~
29339  \SpecialChar ~
29340  \SpecialChar ~
29341  \SpecialChar ~
29342  \SpecialChar ~
29343  \SpecialChar ~
29344  \SpecialChar ~
29345  \SpecialChar ~
29346  \SpecialChar ~
29347  \SpecialChar ~
29348  '}' [if <functionName> ] '
29349 \backslash 
29350 n' 
29351 \layout Standard
29352
29353 <assembly sequence> := assembly instruction (each instruction including
29354  labels must be on a separate line).
29355 \newline 
29356
29357 \newline 
29358 The optimizer will apply to the rules one by one from the top in the sequence
29359  of their appearance, it will terminate when all rules are exhausted.
29360  If the 'restart' option is specified, then the optimizer will start matching
29361  the rules again from the top, this option for a rule is expensive (performance)
29362 , it is intended to be used in situations where a transformation will trigger
29363  the same rule again.
29364  An example of this (not a good one, it has side effects) is the following
29365  rule:
29366 \layout Verse
29367
29368
29369 \family typewriter 
29370 replace restart { 
29371 \newline 
29372 \SpecialChar ~
29373 \SpecialChar ~
29374 pop %1 
29375 \newline 
29376 \SpecialChar ~
29377 \SpecialChar ~
29378 push %1 } by { 
29379 \newline 
29380 \SpecialChar ~
29381 \SpecialChar ~
29382 ; nop 
29383 \newline 
29384 }
29385 \layout Standard
29386
29387 Note that the replace pattern cannot be a blank, but can be a comment line.
29388  Without the 'restart' option only the innermost 'pop' 'push' pair would
29389  be eliminated, i.e.:
29390 \layout Verse
29391
29392
29393 \family typewriter 
29394 pop ar1 
29395 \newline 
29396 pop ar2 
29397 \newline 
29398 push ar2 
29399 \newline 
29400 push ar1
29401 \layout Standard
29402
29403 would result in:
29404 \layout Verse
29405
29406
29407 \family typewriter 
29408 pop ar1 
29409 \newline 
29410 ; nop 
29411 \newline 
29412 push ar1
29413 \layout Standard
29414
29415
29416 \emph on 
29417 with
29418 \emph default 
29419  the restart option the rule will be applied again to the resulting code
29420  and then all the pop-push pairs will be eliminated to yield:
29421 \layout Verse
29422
29423
29424 \family typewriter 
29425 ; nop 
29426 \newline 
29427 ; nop
29428 \layout Standard
29429
29430 A conditional function can be attached to a rule.
29431  Attaching rules are somewhat more involved, let me illustrate this with
29432  an example.
29433 \layout Verse
29434
29435
29436 \family typewriter 
29437 replace { 
29438 \newline 
29439 \SpecialChar ~
29440  \SpecialChar ~
29441  \SpecialChar ~
29442 ljmp %5 
29443 \newline 
29444 %2:
29445 \newline 
29446 } by { 
29447 \newline 
29448 \SpecialChar ~
29449  \SpecialChar ~
29450  \SpecialChar ~
29451 sjmp %5 
29452 \newline 
29453 %2:
29454 \newline 
29455 } if labelInRange
29456 \layout Standard
29457
29458 The optimizer does a look-up of a function name table defined in function
29459  
29460 \emph on 
29461 callFuncByName
29462 \emph default 
29463  in the source file SDCCpeeph.c, with the name 
29464 \emph on 
29465 labelInRange
29466 \emph default 
29467 .
29468  If it finds a corresponding entry the function is called.
29469  Note there can be no parameters specified for these functions, in this
29470  case the use of 
29471 \emph on 
29472 %5
29473 \emph default 
29474  is crucial, since the function 
29475 \emph on 
29476 labelInRange
29477 \emph default 
29478  expects to find the label in that particular variable (the hash table containin
29479 g the variable bindings is passed as a parameter).
29480  If you want to code more such functions, take a close look at the function
29481  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29482  Currently implemented are 
29483 \emph on 
29484 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29485  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29486 \emph default 
29487 and
29488 \emph on 
29489  notVolatile
29490 \emph default 
29491 .
29492 \layout Standard
29493
29494 I know this whole thing is a little kludgey, but maybe some day we will
29495  have some better means.
29496  If you are looking at this file, you will see the default rules that are
29497  compiled into the compiler, you can add your own rules in the default set
29498  there if you get tired of specifying the -
29499 \begin_inset ERT
29500 status Collapsed
29501
29502 \layout Standard
29503
29504 \backslash 
29505 /
29506 \end_inset 
29507
29508 -peep-file option.
29509 \layout Section
29510
29511 ANSI-Compliance
29512 \begin_inset LatexCommand \index{ANSI-compliance}
29513
29514 \end_inset 
29515
29516
29517 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29518
29519 \end_inset 
29520
29521
29522 \layout Standard
29523
29524 The latest publically available version of the standard 
29525 \emph on 
29526 ISO/IEC 9899 - Programming languages - C
29527 \emph default 
29528  should be available at: 
29529 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29530
29531 \end_inset 
29532
29533 .
29534 \newline 
29535
29536 \layout Standard
29537
29538 Deviations from the compliance:
29539 \layout Itemize
29540
29541 functions are not reentrant
29542 \begin_inset LatexCommand \index{reentrant}
29543
29544 \end_inset 
29545
29546  unless explicitly declared as such or the 
29547 \series bold 
29548 -
29549 \begin_inset ERT
29550 status Collapsed
29551
29552 \layout Standard
29553
29554 \backslash 
29555 /
29556 \end_inset 
29557
29558 -stack-auto
29559 \begin_inset LatexCommand \index{-\/-stack-auto}
29560
29561 \end_inset 
29562
29563
29564 \series default 
29565  command line option is specified.
29566 \layout Itemize
29567
29568 structures
29569 \begin_inset LatexCommand \index{struct}
29570
29571 \end_inset 
29572
29573  and unions
29574 \begin_inset LatexCommand \index{union}
29575
29576 \end_inset 
29577
29578  cannot be assigned values directly, cannot be passed as function parameters
29579  or assigned to each other and cannot be a return value
29580 \begin_inset LatexCommand \index{return value}
29581
29582 \end_inset 
29583
29584  from a function, e.g.:
29585 \begin_deeper 
29586 \layout Verse
29587
29588
29589 \family typewriter 
29590 struct s { ...
29591  }; 
29592 \newline 
29593 struct s s1, s2; 
29594 \newline 
29595 foo() 
29596 \newline 
29597
29598 \newline 
29599 \SpecialChar ~
29600 \SpecialChar ~
29601 \SpecialChar ~
29602 \SpecialChar ~
29603 ...
29604  
29605 \newline 
29606 \SpecialChar ~
29607 \SpecialChar ~
29608 \SpecialChar ~
29609 \SpecialChar ~
29610 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29611 \newline 
29612 \SpecialChar ~
29613 \SpecialChar ~
29614 \SpecialChar ~
29615 \SpecialChar ~
29616 ...
29617  
29618 \newline 
29619 }
29620 \newline 
29621
29622 \series bold 
29623 struct
29624 \series default 
29625  s foo1 (
29626 \series bold 
29627 struct
29628 \series default 
29629  s parms) /* invalid in SDCC although allowed in ANSI */
29630 \newline 
29631
29632 \newline 
29633 \SpecialChar ~
29634 \SpecialChar ~
29635 \SpecialChar ~
29636 \SpecialChar ~
29637 struct s rets; 
29638 \newline 
29639 \SpecialChar ~
29640 \SpecialChar ~
29641 \SpecialChar ~
29642 \SpecialChar ~
29643 ...
29644  
29645 \newline 
29646 \SpecialChar ~
29647 \SpecialChar ~
29648 \SpecialChar ~
29649 \SpecialChar ~
29650 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29651 \newline 
29652 }
29653 \end_deeper 
29654 \layout Itemize
29655
29656 initialization of structure arrays must be fully braced.
29657 \begin_deeper 
29658 \layout Verse
29659
29660
29661 \family typewriter 
29662 struct s { char x } a[] = {1, 2};\SpecialChar ~
29663 \SpecialChar ~
29664 \SpecialChar ~
29665 \SpecialChar ~
29666 \SpecialChar ~
29667 /* invalid in SDCC */
29668 \newline 
29669 struct s { char x } a[] = {{1}, {2}}; /* OK */
29670 \end_deeper 
29671 \layout Itemize
29672
29673 'long long
29674 \begin_inset LatexCommand \index{long long (not supported)}
29675
29676 \end_inset 
29677
29678 ' (64 bit integers
29679 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29680
29681 \end_inset 
29682
29683 ) not supported.
29684 \layout Itemize
29685
29686 'double
29687 \begin_inset LatexCommand \index{double (not supported)}
29688
29689 \end_inset 
29690
29691 ' precision floating point 
29692 \begin_inset LatexCommand \index{Floating point support}
29693
29694 \end_inset 
29695
29696 not supported.
29697 \layout Itemize
29698
29699 Old K&R style
29700 \begin_inset LatexCommand \index{K\&R style}
29701
29702 \end_inset 
29703
29704  function declarations are NOT allowed.
29705 \begin_deeper 
29706 \layout Verse
29707
29708
29709 \family typewriter 
29710 foo(i,j) /* this old style of function declarations */ 
29711 \newline 
29712 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29713 \newline 
29714
29715 \newline 
29716 \SpecialChar ~
29717 \SpecialChar ~
29718 \SpecialChar ~
29719 \SpecialChar ~
29720 ...
29721  
29722 \newline 
29723 }
29724 \end_deeper 
29725 \layout Itemize
29726
29727 Most enhancements in C99 are not supported, f.e.:
29728 \begin_deeper 
29729 \layout Verse
29730
29731
29732 \family typewriter 
29733 \series bold 
29734 inline
29735 \begin_inset LatexCommand \index{inline (not supported)}
29736
29737 \end_inset 
29738
29739
29740 \series default 
29741  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29742  in C99.
29743  An empty define 
29744 \emph on 
29745 #define inline
29746 \emph default 
29747  can be used as a work around */
29748 \newline 
29749
29750 \newline 
29751 for (
29752 \series bold 
29753 int
29754 \series default 
29755  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29756 \end_deeper 
29757 \layout Itemize
29758
29759 Certain words that are valid identifiers in the standard may be reserved
29760  words in SDCC unless the 
29761 \series bold 
29762 -
29763 \begin_inset ERT
29764 status Collapsed
29765
29766 \layout Standard
29767
29768 \backslash 
29769 /
29770 \end_inset 
29771
29772 -std-c89
29773 \begin_inset LatexCommand \index{-\/-std-c89}
29774
29775 \end_inset 
29776
29777  or -
29778 \begin_inset ERT
29779 status Collapsed
29780
29781 \layout Standard
29782
29783 \backslash 
29784 /
29785 \end_inset 
29786
29787 -std-c99
29788 \begin_inset LatexCommand \index{-\/-std-c99}
29789
29790 \end_inset 
29791
29792
29793 \series default 
29794  command line options are used.
29795  These may include (depending on the selected processor): 'at', 'banked',
29796  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29797 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29798  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29799  '_naked'.
29800  Compliant equivalents of these keywords are always available in a form
29801  that begin with two underscores
29802 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29803
29804 \end_inset 
29805
29806 , f.e.
29807  '__data' instead of 'data'.
29808 \layout Section
29809
29810 Cyclomatic Complexity
29811 \begin_inset LatexCommand \index{Cyclomatic complexity}
29812
29813 \end_inset 
29814
29815
29816 \layout Standard
29817
29818 Cyclomatic complexity of a function is defined as the number of independent
29819  paths the program can take during execution of the function.
29820  This is an important number since it defines the number test cases you
29821  have to generate to validate the function.
29822  The accepted industry standard for complexity number is 10, if the cyclomatic
29823  complexity reported by SDCC exceeds 10 you should think about simplification
29824  of the function logic.
29825  Note that the complexity level is not related to the number of lines of
29826  code in a function.
29827  Large functions can have low complexity, and small functions can have large
29828  complexity levels.
29829  
29830 \newline 
29831
29832 \newline 
29833 SDCC uses the following formula to compute the complexity:
29834 \newline 
29835
29836 \layout Standard
29837
29838 complexity = (number of edges in control flow graph) - (number of nodes
29839  in control flow graph) + 2;
29840 \newline 
29841
29842 \newline 
29843 Having said that the industry standard is 10, you should be aware that in
29844  some cases it be may unavoidable to have a complexity level of less than
29845  10.
29846  For example if you have switch statement with more than 10 case labels,
29847  each case label adds one to the complexity level.
29848  The complexity level is by no means an absolute measure of the algorithmic
29849  complexity of the function, it does however provide a good starting point
29850  for which functions you might look at for further optimization.
29851 \layout Section
29852
29853 Retargetting for other Processors
29854 \layout Standard
29855
29856 The issues for retargetting the compiler are far too numerous to be covered
29857  by this document.
29858  What follows is a brief description of each of the seven phases of the
29859  compiler and its MCU dependency.
29860 \layout Itemize
29861
29862 Parsing the source and building the annotated parse tree.
29863  This phase is largely MCU independent (except for the language extensions).
29864  Syntax & semantic checks are also done in this phase, along with some initial
29865  optimizations like back patching labels and the pattern matching optimizations
29866  like bit-rotation etc.
29867 \layout Itemize
29868
29869 The second phase involves generating an intermediate code which can be easy
29870  manipulated during the later phases.
29871  This phase is entirely MCU independent.
29872  The intermediate code generation assumes the target machine has unlimited
29873  number of registers, and designates them with the name iTemp.
29874  The compiler can be made to dump a human readable form of the code generated
29875  by using the -
29876 \begin_inset ERT
29877 status Collapsed
29878
29879 \layout Standard
29880
29881 \backslash 
29882 /
29883 \end_inset 
29884
29885 -dumpraw option.
29886 \layout Itemize
29887
29888 This phase does the bulk of the standard optimizations and is also MCU independe
29889 nt.
29890  This phase can be broken down into several sub-phases:
29891 \newline 
29892
29893 \newline 
29894 Break down intermediate code (iCode) into basic blocks.
29895 \newline 
29896 Do control flow & data flow analysis on the basic blocks.
29897 \newline 
29898 Do local common subexpression elimination, then global subexpression elimination
29899 \newline 
29900 Dead code elimination
29901 \newline 
29902 Loop optimizations
29903 \newline 
29904 If loop optimizations caused any changes then do 'global subexpression eliminati
29905 on' and 'dead code elimination' again.
29906 \layout Itemize
29907
29908 This phase determines the live-ranges; by live range I mean those iTemp
29909  variables defined by the compiler that still survive after all the optimization
29910 s.
29911  Live range analysis
29912 \begin_inset LatexCommand \index{Live range analysis}
29913
29914 \end_inset 
29915
29916  is essential for register allocation, since these computation determines
29917  which of these iTemps will be assigned to registers, and for how long.
29918 \layout Itemize
29919
29920 Phase five is register allocation.
29921  There are two parts to this process.
29922 \newline 
29923
29924 \newline 
29925 The first part I call 'register packing' (for lack of a better term).
29926  In this case several MCU specific expression folding is done to reduce
29927  register pressure.
29928 \newline 
29929
29930 \newline 
29931 The second part is more MCU independent and deals with allocating registers
29932  to the remaining live ranges.
29933  A lot of MCU specific code does creep into this phase because of the limited
29934  number of index registers available in the 8051.
29935 \layout Itemize
29936
29937 The Code generation phase is (unhappily), entirely MCU dependent and very
29938  little (if any at all) of this code can be reused for other MCU.
29939  However the scheme for allocating a homogenized assembler operand for each
29940  iCode operand may be reused.
29941 \layout Itemize
29942
29943 As mentioned in the optimization section the peep-hole optimizer is rule
29944  based system, which can reprogrammed for other MCUs.
29945 \layout Standard
29946
29947 More information is available in a wiki
29948 \begin_inset LatexCommand \index{wiki}
29949
29950 \end_inset 
29951
29952  (preliminary link 
29953 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
29954
29955 \end_inset 
29956
29957 ) and in the thread 
29958 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
29959
29960 \end_inset 
29961
29962  .
29963 \layout Chapter
29964
29965 Compiler internals
29966 \begin_inset LatexCommand \index{Compiler internals}
29967
29968 \end_inset 
29969
29970
29971 \layout Section
29972
29973 The anatomy of the compiler
29974 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29975
29976 \end_inset 
29977
29978
29979 \layout Standard
29980
29981
29982 \shape italic 
29983 This is an excerpt from an article published in Circuit Cellar Magazine
29984  in 
29985 \series bold 
29986 August 2000
29987 \series default 
29988 .
29989  It's a little outdated (the compiler is much more efficient now and user/develo
29990 per friendly), but pretty well exposes the guts of it all.
29991 \shape default 
29992
29993 \newline 
29994
29995 \newline 
29996 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29997  It is fairly easy to retarget for other 8-bit MCU.
29998  Here we take a look at some of the internals of the compiler.
29999  
30000 \layout Paragraph*
30001
30002 Parsing
30003 \begin_inset LatexCommand \index{Parsing}
30004
30005 \end_inset 
30006
30007  
30008 \layout Standard
30009
30010 Parsing the input source file and creating an AST (Annotated Syntax Tree
30011 \begin_inset LatexCommand \index{Annotated syntax tree}
30012
30013 \end_inset 
30014
30015 ).
30016  This phase also involves propagating types (annotating each node of the
30017  parse tree with type information) and semantic analysis.
30018  There are some MCU specific parsing rules.
30019  For example the storage classes, the extended storage classes are MCU specific
30020  while there may be a xdata storage class for 8051 there is no such storage
30021  class for z80 or Atmel AVR.
30022  SDCC allows MCU specific storage class extensions, i.e.
30023  xdata will be treated as a storage class specifier when parsing 8051 C
30024  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
30025  C code.
30026 \layout Paragraph*
30027
30028 Generating iCode
30029 \begin_inset LatexCommand \index{iCode}
30030
30031 \end_inset 
30032
30033
30034 \layout Standard
30035
30036 Intermediate code generation.
30037  In this phase the AST is broken down into three-operand form (iCode).
30038  These three operand forms are represented as doubly linked lists.
30039  ICode is the term given to the intermediate form generated by the compiler.
30040  ICode example section shows some examples of iCode generated for some simple
30041  C source functions.
30042 \layout Paragraph*
30043
30044 Optimizations
30045 \begin_inset LatexCommand \index{Optimizations}
30046
30047 \end_inset 
30048
30049 .
30050 \layout Standard
30051
30052 Bulk of the target independent optimizations is performed in this phase.
30053  The optimizations include constant propagation, common sub-expression eliminati
30054 on, loop invariant code movement, strength reduction of loop induction variables
30055  and dead-code elimination.
30056 \layout Paragraph*
30057
30058 Live range analysis
30059 \begin_inset LatexCommand \index{Live range analysis}
30060
30061 \end_inset 
30062
30063
30064 \layout Standard
30065
30066 During intermediate code generation phase, the compiler assumes the target
30067  machine has infinite number of registers and generates a lot of temporary
30068  variables.
30069  The live range computation determines the lifetime of each of these compiler-ge
30070 nerated temporaries.
30071  A picture speaks a thousand words.
30072  ICode example sections show the live range annotations for each of the
30073  operand.
30074  It is important to note here, each iCode is assigned a number in the order
30075  of its execution in the function.
30076  The live ranges are computed in terms of these numbers.
30077  The from number is the number of the iCode which first defines the operand
30078  and the to number signifies the iCode which uses this operand last.
30079 \layout Paragraph*
30080
30081 Register Allocation
30082 \begin_inset LatexCommand \index{Register allocation}
30083
30084 \end_inset 
30085
30086
30087 \layout Standard
30088
30089 The register allocation determines the type and number of registers needed
30090  by each operand.
30091  In most MCUs only a few registers can be used for indirect addressing.
30092  In case of 8051 for example the registers R0 & R1 can be used to indirectly
30093  address the internal ram and DPTR to indirectly address the external ram.
30094  The compiler will try to allocate the appropriate register to pointer variables
30095  if it can.
30096  ICode example section shows the operands annotated with the registers assigned
30097  to them.
30098  The compiler will try to keep operands in registers as much as possible;
30099  there are several schemes the compiler uses to do achieve this.
30100  When the compiler runs out of registers the compiler will check to see
30101  if there are any live operands which is not used or defined in the current
30102  basic block being processed, if there are any found then it will push that
30103  operand and use the registers in this block, the operand will then be popped
30104  at the end of the basic block.
30105  
30106 \layout Standard
30107
30108 There are other MCU specific considerations in this phase.
30109  Some MCUs have an accumulator; very short-lived operands could be assigned
30110  to the accumulator instead of a general-purpose register.
30111 \layout Paragraph*
30112
30113 Code generation
30114 \layout Standard
30115
30116 Figure II gives a table of iCode
30117 \begin_inset LatexCommand \index{iCode}
30118
30119 \end_inset 
30120
30121  operations supported by the compiler.
30122  The code generation involves translating these operations into corresponding
30123  assembly code for the processor.
30124  This sounds overly simple but that is the essence of code generation.
30125  Some of the iCode operations are generated on a MCU specific manner for
30126  example, the z80 port does not use registers to pass parameters so the
30127  SEND and RECV iCode operations will not be generated, and it also does
30128  not support JUMPTABLES.
30129  
30130 \newline 
30131
30132 \layout Standard
30133
30134
30135 \size footnotesize 
30136 Figure II 
30137 \begin_inset  Tabular
30138 <lyxtabular version="3" rows="39" columns="4">
30139 <features islongtable="true" headBottomDL="true">
30140 <column alignment="block" valignment="top" leftline="true" width="13col%">
30141 <column alignment="left" valignment="top" leftline="true" width="13col%">
30142 <column alignment="block" valignment="top" leftline="true" width="22col%">
30143 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
30144 <row topline="true" bottomline="true" endhead="true">
30145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30146 \begin_inset Text
30147
30148 \layout Standard
30149
30150
30151 \series bold 
30152 iCode
30153 \series default 
30154
30155 \begin_inset LatexCommand \index{iCode}
30156
30157 \end_inset 
30158
30159
30160 \end_inset 
30161 </cell>
30162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30163 \begin_inset Text
30164
30165 \layout Standard
30166
30167
30168 \series bold 
30169 Operands
30170 \end_inset 
30171 </cell>
30172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30173 \begin_inset Text
30174
30175 \layout Standard
30176
30177
30178 \series bold 
30179 Description
30180 \end_inset 
30181 </cell>
30182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30183 \begin_inset Text
30184
30185 \layout Standard
30186
30187
30188 \series bold 
30189 C Equivalent
30190 \end_inset 
30191 </cell>
30192 </row>
30193 <row topline="true">
30194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30195 \begin_inset Text
30196
30197 \layout Standard
30198
30199
30200 \size footnotesize 
30201 '!'
30202 \end_inset 
30203 </cell>
30204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30205 \begin_inset Text
30206
30207 \layout Standard
30208
30209
30210 \size footnotesize 
30211 IC_LEFT() IC_RESULT()
30212 \end_inset 
30213 </cell>
30214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30215 \begin_inset Text
30216
30217 \layout Standard
30218
30219
30220 \size footnotesize 
30221 NOT operation 
30222 \end_inset 
30223 </cell>
30224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30225 \begin_inset Text
30226
30227 \layout Standard
30228
30229
30230 \size footnotesize 
30231 IC_RESULT = ! IC_LEFT;
30232 \end_inset 
30233 </cell>
30234 </row>
30235 <row topline="true">
30236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30237 \begin_inset Text
30238
30239 \layout Standard
30240
30241
30242 \size footnotesize 
30243 '~'
30244 \end_inset 
30245 </cell>
30246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30247 \begin_inset Text
30248
30249 \layout Standard
30250
30251
30252 \size footnotesize 
30253 IC_LEFT() IC_RESULT()
30254 \end_inset 
30255 </cell>
30256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30257 \begin_inset Text
30258
30259 \layout Standard
30260
30261
30262 \size footnotesize 
30263 Bitwise complement of 
30264 \end_inset 
30265 </cell>
30266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30267 \begin_inset Text
30268
30269 \layout Standard
30270
30271
30272 \size footnotesize 
30273 IC_RESULT = ~IC_LEFT;
30274 \end_inset 
30275 </cell>
30276 </row>
30277 <row topline="true">
30278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30279 \begin_inset Text
30280
30281 \layout Standard
30282
30283
30284 \size footnotesize 
30285 RRC
30286 \end_inset 
30287 </cell>
30288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30289 \begin_inset Text
30290
30291 \layout Standard
30292
30293
30294 \size footnotesize 
30295 IC_LEFT() IC_RESULT()
30296 \end_inset 
30297 </cell>
30298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30299 \begin_inset Text
30300
30301 \layout Standard
30302
30303
30304 \size footnotesize 
30305 Rotate right with carry
30306 \end_inset 
30307 </cell>
30308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30309 \begin_inset Text
30310
30311 \layout Standard
30312
30313
30314 \size footnotesize 
30315 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
30316 \end_inset 
30317 </cell>
30318 </row>
30319 <row topline="true">
30320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30321 \begin_inset Text
30322
30323 \layout Standard
30324
30325
30326 \size footnotesize 
30327 RLC
30328 \end_inset 
30329 </cell>
30330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30331 \begin_inset Text
30332
30333 \layout Standard
30334
30335
30336 \size footnotesize 
30337 IC_LEFT() IC_RESULT()
30338 \end_inset 
30339 </cell>
30340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30341 \begin_inset Text
30342
30343 \layout Standard
30344
30345
30346 \size footnotesize 
30347 Rotate left with carry
30348 \end_inset 
30349 </cell>
30350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30351 \begin_inset Text
30352
30353 \layout Standard
30354
30355
30356 \size footnotesize 
30357 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
30358 \end_inset 
30359 </cell>
30360 </row>
30361 <row topline="true">
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30363 \begin_inset Text
30364
30365 \layout Standard
30366
30367
30368 \size footnotesize 
30369 GETHBIT
30370 \end_inset 
30371 </cell>
30372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30373 \begin_inset Text
30374
30375 \layout Standard
30376
30377
30378 \size footnotesize 
30379 IC_LEFT() IC_RESULT()
30380 \end_inset 
30381 </cell>
30382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30383 \begin_inset Text
30384
30385 \layout Standard
30386
30387
30388 \size footnotesize 
30389 Get the highest order bit of IC_LEFT
30390 \end_inset 
30391 </cell>
30392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30393 \begin_inset Text
30394
30395 \layout Standard
30396
30397
30398 \size footnotesize 
30399 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
30400 \end_inset 
30401 </cell>
30402 </row>
30403 <row topline="true">
30404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30405 \begin_inset Text
30406
30407 \layout Standard
30408
30409
30410 \size footnotesize 
30411 UNARYMINUS
30412 \end_inset 
30413 </cell>
30414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30415 \begin_inset Text
30416
30417 \layout Standard
30418
30419
30420 \size footnotesize 
30421 IC_LEFT() IC_RESULT()
30422 \end_inset 
30423 </cell>
30424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30425 \begin_inset Text
30426
30427 \layout Standard
30428
30429
30430 \size footnotesize 
30431 Unary minus
30432 \end_inset 
30433 </cell>
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30435 \begin_inset Text
30436
30437 \layout Standard
30438
30439
30440 \size footnotesize 
30441 IC_RESULT = - IC_LEFT;
30442 \end_inset 
30443 </cell>
30444 </row>
30445 <row topline="true">
30446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30447 \begin_inset Text
30448
30449 \layout Standard
30450
30451
30452 \size footnotesize 
30453 IPUSH
30454 \end_inset 
30455 </cell>
30456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30457 \begin_inset Text
30458
30459 \layout Standard
30460
30461
30462 \size footnotesize 
30463 IC_LEFT()
30464 \end_inset 
30465 </cell>
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30467 \begin_inset Text
30468
30469 \layout Standard
30470
30471
30472 \size footnotesize 
30473 Push the operand into stack
30474 \end_inset 
30475 </cell>
30476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30477 \begin_inset Text
30478
30479 \layout Standard
30480
30481
30482 \size footnotesize 
30483 NONE
30484 \end_inset 
30485 </cell>
30486 </row>
30487 <row topline="true">
30488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30489 \begin_inset Text
30490
30491 \layout Standard
30492
30493
30494 \size footnotesize 
30495 IPOP
30496 \end_inset 
30497 </cell>
30498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30499 \begin_inset Text
30500
30501 \layout Standard
30502
30503
30504 \size footnotesize 
30505 IC_LEFT()
30506 \end_inset 
30507 </cell>
30508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30509 \begin_inset Text
30510
30511 \layout Standard
30512
30513
30514 \size footnotesize 
30515 Pop the operand from the stack 
30516 \end_inset 
30517 </cell>
30518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30519 \begin_inset Text
30520
30521 \layout Standard
30522
30523
30524 \size footnotesize 
30525 NONE
30526 \end_inset 
30527 </cell>
30528 </row>
30529 <row topline="true">
30530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30531 \begin_inset Text
30532
30533 \layout Standard
30534
30535
30536 \size footnotesize 
30537 CALL
30538 \end_inset 
30539 </cell>
30540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30541 \begin_inset Text
30542
30543 \layout Standard
30544
30545
30546 \size footnotesize 
30547 IC_LEFT() IC_RESULT()
30548 \end_inset 
30549 </cell>
30550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30551 \begin_inset Text
30552
30553 \layout Standard
30554
30555
30556 \size footnotesize 
30557 Call the function represented by IC_LEFT 
30558 \end_inset 
30559 </cell>
30560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30561 \begin_inset Text
30562
30563 \layout Standard
30564
30565
30566 \size footnotesize 
30567 IC_RESULT = IC_LEFT();
30568 \end_inset 
30569 </cell>
30570 </row>
30571 <row topline="true">
30572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30573 \begin_inset Text
30574
30575 \layout Standard
30576
30577
30578 \size footnotesize 
30579 PCALL
30580 \end_inset 
30581 </cell>
30582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30583 \begin_inset Text
30584
30585 \layout Standard
30586
30587
30588 \size footnotesize 
30589 IC_LEFT() IC_RESULT()
30590 \end_inset 
30591 </cell>
30592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30593 \begin_inset Text
30594
30595 \layout Standard
30596
30597
30598 \size footnotesize 
30599 Call via function pointer
30600 \end_inset 
30601 </cell>
30602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30603 \begin_inset Text
30604
30605 \layout Standard
30606
30607
30608 \size footnotesize 
30609 IC_RESULT = (*IC_LEFT)();
30610 \end_inset 
30611 </cell>
30612 </row>
30613 <row topline="true">
30614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30615 \begin_inset Text
30616
30617 \layout Standard
30618
30619
30620 \size footnotesize 
30621 RETURN
30622 \end_inset 
30623 </cell>
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30625 \begin_inset Text
30626
30627 \layout Standard
30628
30629
30630 \size footnotesize 
30631 IC_LEFT()
30632 \end_inset 
30633 </cell>
30634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30635 \begin_inset Text
30636
30637 \layout Standard
30638
30639
30640 \size footnotesize 
30641 Return the value in operand IC_LEFT 
30642 \end_inset 
30643 </cell>
30644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30645 \begin_inset Text
30646
30647 \layout Standard
30648
30649
30650 \size footnotesize 
30651 return IC_LEFT;
30652 \end_inset 
30653 </cell>
30654 </row>
30655 <row topline="true">
30656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30657 \begin_inset Text
30658
30659 \layout Standard
30660
30661
30662 \size footnotesize 
30663 LABEL
30664 \end_inset 
30665 </cell>
30666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30667 \begin_inset Text
30668
30669 \layout Standard
30670
30671
30672 \size footnotesize 
30673 IC_LABEL() 
30674 \end_inset 
30675 </cell>
30676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30677 \begin_inset Text
30678
30679 \layout Standard
30680
30681
30682 \size footnotesize 
30683 Label
30684 \end_inset 
30685 </cell>
30686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30687 \begin_inset Text
30688
30689 \layout Standard
30690
30691
30692 \size footnotesize 
30693 IC_LABEL:
30694 \end_inset 
30695 </cell>
30696 </row>
30697 <row topline="true">
30698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30699 \begin_inset Text
30700
30701 \layout Standard
30702
30703
30704 \size footnotesize 
30705 GOTO
30706 \end_inset 
30707 </cell>
30708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30709 \begin_inset Text
30710
30711 \layout Standard
30712
30713
30714 \size footnotesize 
30715 IC_LABEL() 
30716 \end_inset 
30717 </cell>
30718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30719 \begin_inset Text
30720
30721 \layout Standard
30722
30723
30724 \size footnotesize 
30725 Goto label
30726 \end_inset 
30727 </cell>
30728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30729 \begin_inset Text
30730
30731 \layout Standard
30732
30733
30734 \size footnotesize 
30735 goto IC_LABEL();
30736 \end_inset 
30737 </cell>
30738 </row>
30739 <row topline="true">
30740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30741 \begin_inset Text
30742
30743 \layout Standard
30744
30745
30746 \size footnotesize 
30747 '+'
30748 \end_inset 
30749 </cell>
30750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30751 \begin_inset Text
30752
30753 \layout Standard
30754
30755
30756 \size footnotesize 
30757 IC_LEFT() IC_RIGHT() IC_RESULT()
30758 \end_inset 
30759 </cell>
30760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30761 \begin_inset Text
30762
30763 \layout Standard
30764
30765
30766 \size footnotesize 
30767 Addition
30768 \end_inset 
30769 </cell>
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30771 \begin_inset Text
30772
30773 \layout Standard
30774
30775
30776 \size footnotesize 
30777 IC_RESULT = IC_LEFT + IC_RIGHT
30778 \end_inset 
30779 </cell>
30780 </row>
30781 <row topline="true">
30782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30783 \begin_inset Text
30784
30785 \layout Standard
30786
30787
30788 \size footnotesize 
30789 '-'
30790 \end_inset 
30791 </cell>
30792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30793 \begin_inset Text
30794
30795 \layout Standard
30796
30797
30798 \size footnotesize 
30799 IC_LEFT() IC_RIGHT() IC_RESULT()
30800 \end_inset 
30801 </cell>
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30803 \begin_inset Text
30804
30805 \layout Standard
30806
30807
30808 \size footnotesize 
30809 Subtraction
30810 \end_inset 
30811 </cell>
30812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30813 \begin_inset Text
30814
30815 \layout Standard
30816
30817
30818 \size footnotesize 
30819 IC_RESULT = IC_LEFT - IC_RIGHT 
30820 \end_inset 
30821 </cell>
30822 </row>
30823 <row topline="true">
30824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30825 \begin_inset Text
30826
30827 \layout Standard
30828
30829
30830 \size footnotesize 
30831 '*'
30832 \end_inset 
30833 </cell>
30834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30835 \begin_inset Text
30836
30837 \layout Standard
30838
30839
30840 \size footnotesize 
30841 IC_LEFT() IC_RIGHT() IC_RESULT()
30842 \end_inset 
30843 </cell>
30844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30845 \begin_inset Text
30846
30847 \layout Standard
30848
30849
30850 \size footnotesize 
30851 Multiplication 
30852 \end_inset 
30853 </cell>
30854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30855 \begin_inset Text
30856
30857 \layout Standard
30858
30859
30860 \size footnotesize 
30861 IC_RESULT = IC_LEFT * IC_RIGHT;
30862 \end_inset 
30863 </cell>
30864 </row>
30865 <row topline="true">
30866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30867 \begin_inset Text
30868
30869 \layout Standard
30870
30871
30872 \size footnotesize 
30873 '/'
30874 \end_inset 
30875 </cell>
30876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30877 \begin_inset Text
30878
30879 \layout Standard
30880
30881
30882 \size footnotesize 
30883 IC_LEFT() IC_RIGHT() IC_RESULT()
30884 \end_inset 
30885 </cell>
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30887 \begin_inset Text
30888
30889 \layout Standard
30890
30891
30892 \size footnotesize 
30893 Division
30894 \end_inset 
30895 </cell>
30896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30897 \begin_inset Text
30898
30899 \layout Standard
30900
30901
30902 \size footnotesize 
30903 IC_RESULT = IC_LEFT / IC_RIGHT;
30904 \end_inset 
30905 </cell>
30906 </row>
30907 <row topline="true">
30908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30909 \begin_inset Text
30910
30911 \layout Standard
30912
30913
30914 \size footnotesize 
30915 '%'
30916 \end_inset 
30917 </cell>
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30919 \begin_inset Text
30920
30921 \layout Standard
30922
30923
30924 \size footnotesize 
30925 IC_LEFT() IC_RIGHT() IC_RESULT()
30926 \end_inset 
30927 </cell>
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30929 \begin_inset Text
30930
30931 \layout Standard
30932
30933
30934 \size footnotesize 
30935 Modulus
30936 \end_inset 
30937 </cell>
30938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30939 \begin_inset Text
30940
30941 \layout Standard
30942
30943
30944 \size footnotesize 
30945 IC_RESULT = IC_LEFT % IC_RIGHT;
30946 \end_inset 
30947 </cell>
30948 </row>
30949 <row topline="true">
30950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30951 \begin_inset Text
30952
30953 \layout Standard
30954
30955
30956 \size footnotesize 
30957 '<'
30958 \end_inset 
30959 </cell>
30960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30961 \begin_inset Text
30962
30963 \layout Standard
30964
30965
30966 \size footnotesize 
30967 IC_LEFT() IC_RIGHT() IC_RESULT()
30968 \end_inset 
30969 </cell>
30970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30971 \begin_inset Text
30972
30973 \layout Standard
30974
30975
30976 \size footnotesize 
30977 Less than
30978 \end_inset 
30979 </cell>
30980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30981 \begin_inset Text
30982
30983 \layout Standard
30984
30985
30986 \size footnotesize 
30987 IC_RESULT = IC_LEFT < IC_RIGHT;
30988 \end_inset 
30989 </cell>
30990 </row>
30991 <row topline="true">
30992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30993 \begin_inset Text
30994
30995 \layout Standard
30996
30997
30998 \size footnotesize 
30999 '>'
31000 \end_inset 
31001 </cell>
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31003 \begin_inset Text
31004
31005 \layout Standard
31006
31007
31008 \size footnotesize 
31009 IC_LEFT() IC_RIGHT() IC_RESULT()
31010 \end_inset 
31011 </cell>
31012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31013 \begin_inset Text
31014
31015 \layout Standard
31016
31017
31018 \size footnotesize 
31019 Greater than 
31020 \end_inset 
31021 </cell>
31022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31023 \begin_inset Text
31024
31025 \layout Standard
31026
31027
31028 \size footnotesize 
31029 IC_RESULT = IC_LEFT > IC_RIGHT;
31030 \end_inset 
31031 </cell>
31032 </row>
31033 <row topline="true">
31034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31035 \begin_inset Text
31036
31037 \layout Standard
31038
31039
31040 \size footnotesize 
31041 EQ_OP
31042 \end_inset 
31043 </cell>
31044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31045 \begin_inset Text
31046
31047 \layout Standard
31048
31049
31050 \size footnotesize 
31051 IC_LEFT() IC_RIGHT() IC_RESULT()
31052 \end_inset 
31053 </cell>
31054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31055 \begin_inset Text
31056
31057 \layout Standard
31058
31059
31060 \size footnotesize 
31061 Equal to 
31062 \end_inset 
31063 </cell>
31064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31065 \begin_inset Text
31066
31067 \layout Standard
31068
31069
31070 \size footnotesize 
31071 IC_RESULT = IC_LEFT == IC_RIGHT;
31072 \end_inset 
31073 </cell>
31074 </row>
31075 <row topline="true">
31076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31077 \begin_inset Text
31078
31079 \layout Standard
31080
31081
31082 \size footnotesize 
31083 AND_OP
31084 \end_inset 
31085 </cell>
31086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31087 \begin_inset Text
31088
31089 \layout Standard
31090
31091
31092 \size footnotesize 
31093 IC_LEFT() IC_RIGHT() IC_RESULT() 
31094 \end_inset 
31095 </cell>
31096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31097 \begin_inset Text
31098
31099 \layout Standard
31100
31101
31102 \size footnotesize 
31103 Logical and operation
31104 \end_inset 
31105 </cell>
31106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31107 \begin_inset Text
31108
31109 \layout Standard
31110
31111
31112 \size footnotesize 
31113 IC_RESULT = IC_LEFT && IC_RIGHT; 
31114 \end_inset 
31115 </cell>
31116 </row>
31117 <row topline="true">
31118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31119 \begin_inset Text
31120
31121 \layout Standard
31122
31123
31124 \size footnotesize 
31125 OR_OP
31126 \end_inset 
31127 </cell>
31128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31129 \begin_inset Text
31130
31131 \layout Standard
31132
31133
31134 \size footnotesize 
31135 IC_LEFT() IC_RIGHT() IC_RESULT() 
31136 \end_inset 
31137 </cell>
31138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31139 \begin_inset Text
31140
31141 \layout Standard
31142
31143
31144 \size footnotesize 
31145 Logical or operation 
31146 \end_inset 
31147 </cell>
31148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31149 \begin_inset Text
31150
31151 \layout Standard
31152
31153
31154 \size footnotesize 
31155 IC_RESULT = IC_LEFT || IC_RIGHT; 
31156 \end_inset 
31157 </cell>
31158 </row>
31159 <row topline="true">
31160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31161 \begin_inset Text
31162
31163 \layout Standard
31164
31165
31166 \size footnotesize 
31167 '^'
31168 \end_inset 
31169 </cell>
31170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31171 \begin_inset Text
31172
31173 \layout Standard
31174
31175
31176 \size footnotesize 
31177 IC_LEFT() IC_RIGHT() IC_RESULT() 
31178 \end_inset 
31179 </cell>
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \layout Standard
31184
31185
31186 \size footnotesize 
31187 Exclusive OR
31188 \end_inset 
31189 </cell>
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31191 \begin_inset Text
31192
31193 \layout Standard
31194
31195
31196 \size footnotesize 
31197 IC_RESULT = IC_LEFT ^ IC_RIGHT;
31198 \end_inset 
31199 </cell>
31200 </row>
31201 <row topline="true">
31202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31203 \begin_inset Text
31204
31205 \layout Standard
31206
31207
31208 \size footnotesize 
31209 '|'
31210 \end_inset 
31211 </cell>
31212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31213 \begin_inset Text
31214
31215 \layout Standard
31216
31217
31218 \size footnotesize 
31219 IC_LEFT() IC_RIGHT() IC_RESULT() 
31220 \end_inset 
31221 </cell>
31222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31223 \begin_inset Text
31224
31225 \layout Standard
31226
31227
31228 \size footnotesize 
31229 Bitwise OR 
31230 \end_inset 
31231 </cell>
31232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31233 \begin_inset Text
31234
31235 \layout Standard
31236
31237
31238 \size footnotesize 
31239 IC_RESULT = IC_LEFT | IC_RIGHT;
31240 \end_inset 
31241 </cell>
31242 </row>
31243 <row topline="true">
31244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31245 \begin_inset Text
31246
31247 \layout Standard
31248
31249
31250 \size footnotesize 
31251 BITWISEAND
31252 \end_inset 
31253 </cell>
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31255 \begin_inset Text
31256
31257 \layout Standard
31258
31259
31260 \size footnotesize 
31261 IC_LEFT() IC_RIGHT() IC_RESULT()
31262 \end_inset 
31263 </cell>
31264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31265 \begin_inset Text
31266
31267 \layout Standard
31268
31269
31270 \size footnotesize 
31271 Bitwise AND 
31272 \end_inset 
31273 </cell>
31274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31275 \begin_inset Text
31276
31277 \layout Standard
31278
31279
31280 \size footnotesize 
31281 IC_RESULT = IC_LEFT & IC_RIGHT;
31282 \end_inset 
31283 </cell>
31284 </row>
31285 <row topline="true">
31286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31287 \begin_inset Text
31288
31289 \layout Standard
31290
31291
31292 \size footnotesize 
31293 LEFT_OP
31294 \end_inset 
31295 </cell>
31296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31297 \begin_inset Text
31298
31299 \layout Standard
31300
31301
31302 \size footnotesize 
31303 IC_LEFT() IC_RIGHT() IC_RESULT()
31304 \end_inset 
31305 </cell>
31306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31307 \begin_inset Text
31308
31309 \layout Standard
31310
31311
31312 \size footnotesize 
31313 Left shift 
31314 \end_inset 
31315 </cell>
31316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31317 \begin_inset Text
31318
31319 \layout Standard
31320
31321
31322 \size footnotesize 
31323 IC_RESULT = IC_LEFT << IC_RIGHT 
31324 \end_inset 
31325 </cell>
31326 </row>
31327 <row topline="true">
31328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31329 \begin_inset Text
31330
31331 \layout Standard
31332
31333
31334 \size footnotesize 
31335 RIGHT_OP
31336 \end_inset 
31337 </cell>
31338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31339 \begin_inset Text
31340
31341 \layout Standard
31342
31343
31344 \size footnotesize 
31345 IC_LEFT() IC_RIGHT() IC_RESULT()
31346 \end_inset 
31347 </cell>
31348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31349 \begin_inset Text
31350
31351 \layout Standard
31352
31353
31354 \size footnotesize 
31355 Right shift
31356 \end_inset 
31357 </cell>
31358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31359 \begin_inset Text
31360
31361 \layout Standard
31362
31363
31364 \size footnotesize 
31365 IC_RESULT = IC_LEFT >> IC_RIGHT 
31366 \end_inset 
31367 </cell>
31368 </row>
31369 <row topline="true">
31370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31371 \begin_inset Text
31372
31373 \layout Standard
31374
31375
31376 \size footnotesize 
31377 GET_VALUE_
31378 \newline 
31379 AT_ ADDRESS
31380 \end_inset 
31381 </cell>
31382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31383 \begin_inset Text
31384
31385 \layout Standard
31386
31387
31388 \size footnotesize 
31389 IC_LEFT() IC_RESULT()
31390 \end_inset 
31391 </cell>
31392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31393 \begin_inset Text
31394
31395 \layout Standard
31396
31397
31398 \size footnotesize 
31399 Indirect fetch 
31400 \end_inset 
31401 </cell>
31402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31403 \begin_inset Text
31404
31405 \layout Standard
31406
31407
31408 \size footnotesize 
31409 IC_RESULT = (*IC_LEFT);
31410 \end_inset 
31411 </cell>
31412 </row>
31413 <row topline="true">
31414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31415 \begin_inset Text
31416
31417 \layout Standard
31418
31419
31420 \size footnotesize 
31421 POINTER_SET
31422 \end_inset 
31423 </cell>
31424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31425 \begin_inset Text
31426
31427 \layout Standard
31428
31429
31430 \size footnotesize 
31431 IC_RIGHT() IC_RESULT() 
31432 \end_inset 
31433 </cell>
31434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31435 \begin_inset Text
31436
31437 \layout Standard
31438
31439
31440 \size footnotesize 
31441 Indirect set
31442 \end_inset 
31443 </cell>
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31445 \begin_inset Text
31446
31447 \layout Standard
31448
31449
31450 \size footnotesize 
31451 (*IC_RESULT) = IC_RIGHT;
31452 \end_inset 
31453 </cell>
31454 </row>
31455 <row topline="true">
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31457 \begin_inset Text
31458
31459 \layout Standard
31460
31461
31462 \size footnotesize 
31463 '='
31464 \end_inset 
31465 </cell>
31466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31467 \begin_inset Text
31468
31469 \layout Standard
31470
31471
31472 \size footnotesize 
31473 IC_RIGHT() IC_RESULT()
31474 \end_inset 
31475 </cell>
31476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31477 \begin_inset Text
31478
31479 \layout Standard
31480
31481
31482 \size footnotesize 
31483 Assignment
31484 \end_inset 
31485 </cell>
31486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31487 \begin_inset Text
31488
31489 \layout Standard
31490
31491
31492 \size footnotesize 
31493 IC_RESULT = IC_RIGHT;
31494 \end_inset 
31495 </cell>
31496 </row>
31497 <row topline="true">
31498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31499 \begin_inset Text
31500
31501 \layout Standard
31502
31503
31504 \size footnotesize 
31505 IFX
31506 \end_inset 
31507 </cell>
31508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31509 \begin_inset Text
31510
31511 \layout Standard
31512
31513
31514 \size footnotesize 
31515 IC_COND IC_TRUE IC_LABEL
31516 \end_inset 
31517 </cell>
31518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31519 \begin_inset Text
31520
31521 \layout Standard
31522
31523
31524 \size footnotesize 
31525 Conditional jump.
31526  If true label is present then jump to true label if condition is true else
31527  jump to false label if condition is false 
31528 \end_inset 
31529 </cell>
31530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31531 \begin_inset Text
31532
31533 \layout Standard
31534
31535
31536 \size footnotesize 
31537 if (IC_COND) goto IC_TRUE; 
31538 \newline 
31539 \SpecialChar ~
31540 \SpecialChar ~
31541 Or 
31542 \newline 
31543 If (!IC_COND) goto IC_FALSE;
31544 \end_inset 
31545 </cell>
31546 </row>
31547 <row topline="true">
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31549 \begin_inset Text
31550
31551 \layout Standard
31552
31553
31554 \size footnotesize 
31555 ADDRESS_OF
31556 \end_inset 
31557 </cell>
31558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31559 \begin_inset Text
31560
31561 \layout Standard
31562
31563
31564 \size footnotesize 
31565 IC_LEFT() IC_RESULT()
31566 \end_inset 
31567 </cell>
31568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31569 \begin_inset Text
31570
31571 \layout Standard
31572
31573
31574 \size footnotesize 
31575 Address of 
31576 \end_inset 
31577 </cell>
31578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31579 \begin_inset Text
31580
31581 \layout Standard
31582
31583
31584 \size footnotesize 
31585 IC_RESULT = &IC_LEFT();
31586 \end_inset 
31587 </cell>
31588 </row>
31589 <row topline="true">
31590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31591 \begin_inset Text
31592
31593 \layout Standard
31594
31595
31596 \size footnotesize 
31597 JUMPTABLE
31598 \end_inset 
31599 </cell>
31600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31601 \begin_inset Text
31602
31603 \layout Standard
31604
31605
31606 \size footnotesize 
31607 IC_JTCOND IC_JTLABELS
31608 \end_inset 
31609 </cell>
31610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31611 \begin_inset Text
31612
31613 \layout Standard
31614
31615
31616 \size footnotesize 
31617 Jump to list of labels depending on the value of JTCOND
31618 \end_inset 
31619 </cell>
31620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31621 \begin_inset Text
31622
31623 \layout Standard
31624
31625
31626 \size footnotesize 
31627 Switch statement
31628 \end_inset 
31629 </cell>
31630 </row>
31631 <row topline="true">
31632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31633 \begin_inset Text
31634
31635 \layout Standard
31636
31637
31638 \size footnotesize 
31639 CAST
31640 \end_inset 
31641 </cell>
31642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31643 \begin_inset Text
31644
31645 \layout Standard
31646
31647
31648 \size footnotesize 
31649 IC_RIGHT() IC_LEFT() IC_RESULT()
31650 \end_inset 
31651 </cell>
31652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31653 \begin_inset Text
31654
31655 \layout Standard
31656
31657
31658 \size footnotesize 
31659 Cast types 
31660 \end_inset 
31661 </cell>
31662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31663 \begin_inset Text
31664
31665 \layout Standard
31666
31667
31668 \size footnotesize 
31669 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
31670 \end_inset 
31671 </cell>
31672 </row>
31673 <row topline="true">
31674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31675 \begin_inset Text
31676
31677 \layout Standard
31678
31679
31680 \size footnotesize 
31681 SEND
31682 \end_inset 
31683 </cell>
31684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31685 \begin_inset Text
31686
31687 \layout Standard
31688
31689
31690 \size footnotesize 
31691 IC_LEFT()
31692 \end_inset 
31693 </cell>
31694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31695 \begin_inset Text
31696
31697 \layout Standard
31698
31699
31700 \size footnotesize 
31701 This is used for passing parameters in registers; 
31702 \newline 
31703 move IC_LEFT to the next available parameter register.
31704 \end_inset 
31705 </cell>
31706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31707 \begin_inset Text
31708
31709 \layout Standard
31710
31711
31712 \size footnotesize 
31713 None
31714 \end_inset 
31715 </cell>
31716 </row>
31717 <row topline="true">
31718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31719 \begin_inset Text
31720
31721 \layout Standard
31722
31723
31724 \size footnotesize 
31725 RECV
31726 \end_inset 
31727 </cell>
31728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31729 \begin_inset Text
31730
31731 \layout Standard
31732
31733
31734 \size footnotesize 
31735 IC_RESULT()
31736 \end_inset 
31737 </cell>
31738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31739 \begin_inset Text
31740
31741 \layout Standard
31742
31743
31744 \size footnotesize 
31745 This is used for receiving parameters passed in registers;
31746 \newline 
31747 Move the values in the next parameter register to IC_RESULT 
31748 \end_inset 
31749 </cell>
31750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31751 \begin_inset Text
31752
31753 \layout Standard
31754
31755
31756 \size footnotesize 
31757 None
31758 \end_inset 
31759 </cell>
31760 </row>
31761 <row topline="true" bottomline="true">
31762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31763 \begin_inset Text
31764
31765 \layout Standard
31766
31767
31768 \shape slanted 
31769 \size footnotesize 
31770 (some more have been added)
31771 \end_inset 
31772 </cell>
31773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31774 \begin_inset Text
31775
31776 \layout Standard
31777
31778 \end_inset 
31779 </cell>
31780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31781 \begin_inset Text
31782
31783 \layout Standard
31784
31785 \end_inset 
31786 </cell>
31787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31788 \begin_inset Text
31789
31790 \layout Standard
31791
31792
31793 \shape slanted 
31794 \size footnotesize 
31795 see f.e.
31796  
31797 \family typewriter 
31798 gen51Code()
31799 \family default 
31800  in 
31801 \family typewriter 
31802 src/mcs51/gen.c
31803 \end_inset 
31804 </cell>
31805 </row>
31806 </lyxtabular>
31807
31808 \end_inset 
31809
31810
31811 \layout Comment
31812
31813 In the original article Figure II was announced to be downloadable on 
31814 \shape italic 
31815 Circuit Cellar
31816 \shape default 
31817 's web site.
31818  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
31819 \layout Paragraph*
31820
31821 ICode Example
31822 \begin_inset LatexCommand \index{iCode}
31823
31824 \end_inset 
31825
31826
31827 \layout Standard
31828
31829 This section shows some details of iCode.
31830  The example C code does not do anything useful; it is used as an example
31831  to illustrate the intermediate code generated by the compiler.
31832 \layout Verse
31833
31834
31835 \family typewriter 
31836 1.\SpecialChar ~
31837 xdata int * p;
31838 \newline 
31839 2.\SpecialChar ~
31840 int gint;
31841 \newline 
31842 3.\SpecialChar ~
31843 /* This function does nothing useful.
31844  It is used
31845 \newline 
31846 4.\SpecialChar ~
31847 \SpecialChar ~
31848 \SpecialChar ~
31849 \SpecialChar ~
31850 for the purpose of explaining iCode */
31851 \newline 
31852 5.\SpecialChar ~
31853 short function (data int *x)
31854 \newline 
31855 6.\SpecialChar ~
31856 {
31857 \newline 
31858 7.\SpecialChar ~
31859 \SpecialChar ~
31860 \SpecialChar ~
31861 short i=10; \SpecialChar ~
31862 \SpecialChar ~
31863 /* dead initialization eliminated */
31864 \newline 
31865 8.\SpecialChar ~
31866 \SpecialChar ~
31867 \SpecialChar ~
31868 short sum=10; /* dead initialization eliminated */
31869 \newline 
31870 9.\SpecialChar ~
31871 \SpecialChar ~
31872 \SpecialChar ~
31873 short mul;
31874 \newline 
31875 10.\SpecialChar ~
31876 \SpecialChar ~
31877 int j ;
31878 \newline 
31879 11.\SpecialChar ~
31880 \SpecialChar ~
31881 while (*x) *x++ = *p++; 
31882 \newline 
31883 12.\SpecialChar ~
31884 \SpecialChar ~
31885 \SpecialChar ~
31886 \SpecialChar ~
31887 sum = 0 ; 
31888 \newline 
31889 13.\SpecialChar ~
31890 \SpecialChar ~
31891 mul = 0;
31892 \newline 
31893 14.\SpecialChar ~
31894 \SpecialChar ~
31895 /* compiler detects i,j to be induction variables */
31896 \newline 
31897 15.\SpecialChar ~
31898 \SpecialChar ~
31899 for (i = 0, j = 10 ; i < 10 ; i++, j
31900 \family default 
31901 -
31902 \begin_inset ERT
31903 status Collapsed
31904
31905 \layout Standard
31906
31907 \backslash 
31908 /
31909 \end_inset 
31910
31911 -
31912 \family typewriter 
31913 ) {
31914 \newline 
31915 16.\SpecialChar ~
31916 \SpecialChar ~
31917 \SpecialChar ~
31918 \SpecialChar ~
31919 sum += i;
31920 \newline 
31921 17.\SpecialChar ~
31922 \SpecialChar ~
31923 \SpecialChar ~
31924 \SpecialChar ~
31925 mul += i * 3; \SpecialChar ~
31926 \SpecialChar ~
31927 /* this multiplication remains */
31928 \newline 
31929 18.\SpecialChar ~
31930 \SpecialChar ~
31931 \SpecialChar ~
31932 \SpecialChar ~
31933 gint += j * 3;\SpecialChar ~
31934 \SpecialChar ~
31935 /* this multiplication changed to addition */
31936 \newline 
31937 19.\SpecialChar ~
31938 \SpecialChar ~
31939 }
31940 \newline 
31941 20.\SpecialChar ~
31942 \SpecialChar ~
31943 return sum+mul;
31944 \newline 
31945 21.\SpecialChar ~
31946 }
31947 \layout Standard
31948
31949 In addition to the operands each iCode contains information about the filename
31950  and line it corresponds to in the source file.
31951  The first field in the listing should be interpreted as follows:
31952 \newline 
31953
31954 \shape italic 
31955 \size footnotesize 
31956 Filename(linenumber: iCode Execution sequence number : ICode hash table
31957  key : loop depth of the iCode).
31958 \shape default 
31959 \size default 
31960
31961 \newline 
31962 Then follows the human readable form of the ICode operation.
31963  Each operand of this triplet form can be of three basic types a) compiler
31964  generated temporary b) user defined variable c) a constant value.
31965  Note that local variables and parameters are replaced by compiler generated
31966  temporaries.
31967  Live ranges
31968 \begin_inset LatexCommand \index{Live range analysis}
31969
31970 \end_inset 
31971
31972  are computed only for temporaries (i.e.
31973  live ranges are not computed for global variables).
31974  Registers
31975 \begin_inset LatexCommand \index{Register allocation}
31976
31977 \end_inset 
31978
31979  are allocated for temporaries only.
31980  Operands are formatted in the following manner:
31981 \newline 
31982
31983 \shape italic 
31984 \size footnotesize 
31985 Operand Name [lr live-from : live-to ] { type information } [ registers
31986  allocated ].
31987 \shape default 
31988 \size default 
31989
31990 \newline 
31991 As mentioned earlier the live ranges are computed in terms of the execution
31992  sequence number of the iCodes, for example 
31993 \newline 
31994 the iTemp0 is live from (i.e.
31995  first defined in iCode with execution sequence number 3, and is last used
31996  in the iCode with sequence number 5).
31997  For induction variables such as iTemp21 the live range computation extends
31998  the lifetime from the start to the end of the loop.
31999 \newline 
32000 The register allocator used the live range information to allocate registers,
32001  the same registers may be used for different temporaries if their live
32002  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
32003  iTemp17 since their live ranges do not overlap.
32004  In addition the allocator also takes into consideration the type and usage
32005  of a temporary, for example itemp6 is a pointer to near space and is used
32006  as to fetch data from (i.e.
32007  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
32008  Some short lived temporaries are allocated to special registers which have
32009  meaning to the code generator e.g.
32010  iTemp13 is allocated to a pseudo register CC which tells the back end that
32011  the temporary is used only for a conditional jump the code generation makes
32012  use of this information to optimize a compare and jump ICode.
32013 \newline 
32014 There are several loop optimizations
32015 \begin_inset LatexCommand \index{Loop optimization}
32016
32017 \end_inset 
32018
32019  performed by the compiler.
32020  It can detect induction variables iTemp21(i) and iTemp23(j).
32021  Also note the compiler does selective strength reduction
32022 \begin_inset LatexCommand \index{Strength reduction}
32023
32024 \end_inset 
32025
32026 , i.e.
32027  the multiplication of an induction variable in line 18 (gint = j * 3) is
32028  changed to addition, a new temporary iTemp17 is allocated and assigned
32029  a initial value, a constant 3 is then added for each iteration of the loop.
32030  The compiler does not change the multiplication
32031 \begin_inset LatexCommand \index{Multiplication}
32032
32033 \end_inset 
32034
32035  in line 17 however since the processor does support an 8 * 8 bit multiplication.
32036 \newline 
32037 Note the dead code elimination
32038 \begin_inset LatexCommand \index{Dead-code elimination}
32039
32040 \end_inset 
32041
32042  optimization eliminated the dead assignments in line 7 & 8 to I and sum
32043  respectively.
32044 \newline 
32045
32046 \layout Standard
32047
32048
32049 \size footnotesize 
32050 Sample.c (5:1:0:0) _entry($9) :
32051 \layout Standard
32052
32053
32054 \size footnotesize 
32055 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
32056 \layout Standard
32057
32058
32059 \size footnotesize 
32060 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
32061 \layout Standard
32062
32063
32064 \size footnotesize 
32065 Sample.c(11:4:53:0) preHeaderLbl0($11) :
32066 \layout Standard
32067
32068
32069 \size footnotesize 
32070 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
32071  * int}[r2]
32072 \layout Standard
32073
32074
32075 \size footnotesize 
32076 Sample.c(11:6:5:1) _whilecontinue_0($1) :
32077 \layout Standard
32078
32079
32080 \size footnotesize 
32081 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
32082  int}[r0]]
32083 \layout Standard
32084
32085
32086 \size footnotesize 
32087 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32088 \layout Standard
32089
32090
32091 \size footnotesize 
32092 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
32093  * int}
32094 \layout Standard
32095
32096
32097 \size footnotesize 
32098 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
32099  {short}
32100 \layout Standard
32101
32102
32103 \size footnotesize 
32104 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
32105  * int}[DPTR]]
32106 \layout Standard
32107
32108
32109 \size footnotesize 
32110 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
32111 }[r2 r3]
32112 \layout Standard
32113
32114
32115 \size footnotesize 
32116 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
32117  * int}[r0] + 0x2 {short}
32118 \layout Standard
32119
32120
32121 \size footnotesize 
32122 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
32123 \layout Standard
32124
32125
32126 \size footnotesize 
32127 Sample.c(11:17:21:0)_whilebreak_0($3) :
32128 \layout Standard
32129
32130
32131 \size footnotesize 
32132 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32133 \layout Standard
32134
32135
32136 \size footnotesize 
32137 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32138 \layout Standard
32139
32140
32141 \size footnotesize 
32142 Sample.c(15:20:54:0)preHeaderLbl1($13) :
32143 \layout Standard
32144
32145
32146 \size footnotesize 
32147 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32148 \layout Standard
32149
32150
32151 \size footnotesize 
32152 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32153 \layout Standard
32154
32155
32156 \size footnotesize 
32157 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32158 \layout Standard
32159
32160
32161 \size footnotesize 
32162 Sample.c(15:24:26:1)_forcond_0($4) :
32163 \layout Standard
32164
32165
32166 \size footnotesize 
32167 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
32168  < 0xa {short}
32169 \layout Standard
32170
32171
32172 \size footnotesize 
32173 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32174 \layout Standard
32175
32176
32177 \size footnotesize 
32178 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
32179  + ITemp21 [lr21:38]{short}[r4]
32180 \layout Standard
32181
32182
32183 \size footnotesize 
32184 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
32185  * 0x3 {short}
32186 \layout Standard
32187
32188
32189 \size footnotesize 
32190 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
32191  + iTemp15 [lr29:30]{short}[r1]
32192 \layout Standard
32193
32194
32195 \size footnotesize 
32196 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
32197  r0]- 0x3 {short}
32198 \layout Standard
32199
32200
32201 \size footnotesize 
32202 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
32203 int}[r7 r0]
32204 \layout Standard
32205
32206
32207 \size footnotesize 
32208 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
32209  + 0x1 {short}
32210 \layout Standard
32211
32212
32213 \size footnotesize 
32214 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
32215  r6]- 0x1 {short}
32216 \layout Standard
32217
32218
32219 \size footnotesize 
32220 Sample.c(19:38:47:1) goto _forcond_0($4)
32221 \layout Standard
32222
32223
32224 \size footnotesize 
32225 Sample.c(19:39:48:0)_forbreak_0($7) :
32226 \layout Standard
32227
32228
32229 \size footnotesize 
32230 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
32231  + ITemp11 [lr19:40]{short}[r3]
32232 \layout Standard
32233
32234
32235 \size footnotesize 
32236 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
32237 \layout Standard
32238
32239
32240 \size footnotesize 
32241 Sample.c(20:42:51:0)_return($8) :
32242 \layout Standard
32243
32244
32245 \size footnotesize 
32246 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
32247 \size default 
32248
32249 \newline 
32250
32251 \newline 
32252 Finally the code generated for this function:
32253 \newline 
32254
32255 \layout Standard
32256
32257
32258 \size footnotesize 
32259 .area DSEG (DATA)
32260 \layout Standard
32261
32262
32263 \size footnotesize 
32264 _p::
32265 \layout Standard
32266
32267
32268 \size footnotesize 
32269 \SpecialChar ~
32270 \SpecialChar ~
32271 .ds 2
32272 \layout Standard
32273
32274
32275 \size footnotesize 
32276 _gint::
32277 \layout Standard
32278
32279
32280 \size footnotesize 
32281 \SpecialChar ~
32282 \SpecialChar ~
32283 .ds 2
32284 \layout Standard
32285
32286
32287 \size footnotesize 
32288 ; sample.c 5
32289 \layout Standard
32290
32291
32292 \size footnotesize 
32293 ; ----------------------------------------------
32294 \layout Standard
32295
32296
32297 \size footnotesize 
32298 ; function function
32299 \layout Standard
32300
32301
32302 \size footnotesize 
32303 ; ----------------------------------------------
32304 \layout Standard
32305
32306
32307 \size footnotesize 
32308 _function:
32309 \layout Standard
32310
32311
32312 \size footnotesize 
32313 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
32314 \layout Standard
32315
32316
32317 \size footnotesize 
32318 \SpecialChar ~
32319 \SpecialChar ~
32320 mov r2,dpl
32321 \layout Standard
32322
32323
32324 \size footnotesize 
32325 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
32326 \layout Standard
32327
32328
32329 \size footnotesize 
32330 \SpecialChar ~
32331 \SpecialChar ~
32332 mov ar0,r2
32333 \layout Standard
32334
32335
32336 \size footnotesize 
32337 ;_whilecontinue_0($1) :
32338 \layout Standard
32339
32340
32341 \size footnotesize 
32342 00101$:
32343 \layout Standard
32344
32345
32346 \size footnotesize 
32347 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
32348 \layout Standard
32349
32350
32351 \size footnotesize 
32352 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32353 \layout Standard
32354
32355
32356 \size footnotesize 
32357 \SpecialChar ~
32358 \SpecialChar ~
32359 mov ar2,@r0
32360 \layout Standard
32361
32362
32363 \size footnotesize 
32364 \SpecialChar ~
32365 \SpecialChar ~
32366 inc r0
32367 \layout Standard
32368
32369
32370 \size footnotesize 
32371 \SpecialChar ~
32372 \SpecialChar ~
32373 mov ar3,@r0
32374 \layout Standard
32375
32376
32377 \size footnotesize 
32378 \SpecialChar ~
32379 \SpecialChar ~
32380 dec r0
32381 \layout Standard
32382
32383
32384 \size footnotesize 
32385 \SpecialChar ~
32386 \SpecialChar ~
32387 mov a,r2
32388 \layout Standard
32389
32390
32391 \size footnotesize 
32392 \SpecialChar ~
32393 \SpecialChar ~
32394 orl a,r3
32395 \layout Standard
32396
32397
32398 \size footnotesize 
32399 \SpecialChar ~
32400 \SpecialChar ~
32401 jz 00103$
32402 \layout Standard
32403
32404
32405 \size footnotesize 
32406 00114$:
32407 \layout Standard
32408
32409
32410 \size footnotesize 
32411 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
32412 \layout Standard
32413
32414
32415 \size footnotesize 
32416 \SpecialChar ~
32417 \SpecialChar ~
32418 mov dpl,_p
32419 \layout Standard
32420
32421
32422 \size footnotesize 
32423 \SpecialChar ~
32424 \SpecialChar ~
32425 mov dph,(_p + 1)
32426 \layout Standard
32427
32428
32429 \size footnotesize 
32430 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
32431 \layout Standard
32432
32433
32434 \size footnotesize 
32435 \SpecialChar ~
32436 \SpecialChar ~
32437 mov a,#0x02
32438 \layout Standard
32439
32440
32441 \size footnotesize 
32442 \SpecialChar ~
32443 \SpecialChar ~
32444 add a,_p
32445 \layout Standard
32446
32447
32448 \size footnotesize 
32449 \SpecialChar ~
32450 \SpecialChar ~
32451 mov _p,a
32452 \layout Standard
32453
32454
32455 \size footnotesize 
32456 \SpecialChar ~
32457 \SpecialChar ~
32458 clr a
32459 \layout Standard
32460
32461
32462 \size footnotesize 
32463 \SpecialChar ~
32464 \SpecialChar ~
32465 addc a,(_p + 1)
32466 \layout Standard
32467
32468
32469 \size footnotesize 
32470 \SpecialChar ~
32471 \SpecialChar ~
32472 mov (_p + 1),a
32473 \layout Standard
32474
32475
32476 \size footnotesize 
32477 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
32478 \layout Standard
32479
32480
32481 \size footnotesize 
32482 \SpecialChar ~
32483 \SpecialChar ~
32484 movx a,@dptr
32485 \layout Standard
32486
32487
32488 \size footnotesize 
32489 \SpecialChar ~
32490 \SpecialChar ~
32491 mov r2,a
32492 \layout Standard
32493
32494
32495 \size footnotesize 
32496 \SpecialChar ~
32497 \SpecialChar ~
32498 inc dptr
32499 \layout Standard
32500
32501
32502 \size footnotesize 
32503 \SpecialChar ~
32504 \SpecialChar ~
32505 movx a,@dptr
32506 \layout Standard
32507
32508
32509 \size footnotesize 
32510 \SpecialChar ~
32511 \SpecialChar ~
32512 mov r3,a
32513 \layout Standard
32514
32515
32516 \size footnotesize 
32517 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
32518 \layout Standard
32519
32520
32521 \size footnotesize 
32522 \SpecialChar ~
32523 \SpecialChar ~
32524 mov @r0,ar2
32525 \layout Standard
32526
32527
32528 \size footnotesize 
32529 \SpecialChar ~
32530 \SpecialChar ~
32531 inc r0
32532 \layout Standard
32533
32534
32535 \size footnotesize 
32536 \SpecialChar ~
32537 \SpecialChar ~
32538 mov @r0,ar3
32539 \layout Standard
32540
32541
32542 \size footnotesize 
32543 ; iTemp6 [lr5:16]{_near * int}[r0] = 
32544 \layout Standard
32545
32546
32547 \size footnotesize 
32548 ; iTemp6 [lr5:16]{_near * int}[r0] + 
32549 \layout Standard
32550
32551
32552 \size footnotesize 
32553 ; 0x2 {short}
32554 \layout Standard
32555
32556
32557 \size footnotesize 
32558 \SpecialChar ~
32559 \SpecialChar ~
32560 inc r0
32561 \layout Standard
32562
32563
32564 \size footnotesize 
32565 ; goto _whilecontinue_0($1)
32566 \layout Standard
32567
32568
32569 \size footnotesize 
32570 \SpecialChar ~
32571 \SpecialChar ~
32572 sjmp 00101$
32573 \layout Standard
32574
32575
32576 \size footnotesize 
32577 ; _whilebreak_0($3) :
32578 \layout Standard
32579
32580
32581 \size footnotesize 
32582 00103$:
32583 \layout Standard
32584
32585
32586 \size footnotesize 
32587 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32588 \layout Standard
32589
32590
32591 \size footnotesize 
32592 \SpecialChar ~
32593 \SpecialChar ~
32594 mov r2,#0x00
32595 \layout Standard
32596
32597
32598 \size footnotesize 
32599 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32600 \layout Standard
32601
32602
32603 \size footnotesize 
32604 \SpecialChar ~
32605 \SpecialChar ~
32606 mov r3,#0x00
32607 \layout Standard
32608
32609
32610 \size footnotesize 
32611 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32612 \layout Standard
32613
32614
32615 \size footnotesize 
32616 \SpecialChar ~
32617 \SpecialChar ~
32618 mov r4,#0x00
32619 \layout Standard
32620
32621
32622 \size footnotesize 
32623 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32624 \layout Standard
32625
32626
32627 \size footnotesize 
32628 \SpecialChar ~
32629 \SpecialChar ~
32630 mov r5,#0x0A
32631 \layout Standard
32632
32633
32634 \size footnotesize 
32635 \SpecialChar ~
32636 \SpecialChar ~
32637 mov r6,#0x00
32638 \layout Standard
32639
32640
32641 \size footnotesize 
32642 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32643 \layout Standard
32644
32645
32646 \size footnotesize 
32647 \SpecialChar ~
32648 \SpecialChar ~
32649 mov r7,#0x1E
32650 \layout Standard
32651
32652
32653 \size footnotesize 
32654 \SpecialChar ~
32655 \SpecialChar ~
32656 mov r0,#0x00
32657 \layout Standard
32658
32659
32660 \size footnotesize 
32661 ; _forcond_0($4) :
32662 \layout Standard
32663
32664
32665 \size footnotesize 
32666 00104$:
32667 \layout Standard
32668
32669
32670 \size footnotesize 
32671 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
32672 \layout Standard
32673
32674
32675 \size footnotesize 
32676 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32677 \layout Standard
32678
32679
32680 \size footnotesize 
32681 \SpecialChar ~
32682 \SpecialChar ~
32683 clr c
32684 \layout Standard
32685
32686
32687 \size footnotesize 
32688 \SpecialChar ~
32689 \SpecialChar ~
32690 mov a,r4
32691 \layout Standard
32692
32693
32694 \size footnotesize 
32695 \SpecialChar ~
32696 \SpecialChar ~
32697 xrl a,#0x80
32698 \layout Standard
32699
32700
32701 \size footnotesize 
32702 \SpecialChar ~
32703 \SpecialChar ~
32704 subb a,#0x8a
32705 \layout Standard
32706
32707
32708 \size footnotesize 
32709 \SpecialChar ~
32710 \SpecialChar ~
32711 jnc 00107$
32712 \layout Standard
32713
32714
32715 \size footnotesize 
32716 00115$:
32717 \layout Standard
32718
32719
32720 \size footnotesize 
32721 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
32722 \layout Standard
32723
32724
32725 \size footnotesize 
32726 ; iTemp21 [lr21:38]{short}[r4]
32727 \layout Standard
32728
32729
32730 \size footnotesize 
32731 \SpecialChar ~
32732 \SpecialChar ~
32733 mov a,r4
32734 \layout Standard
32735
32736
32737 \size footnotesize 
32738 \SpecialChar ~
32739 \SpecialChar ~
32740 add a,r2
32741 \layout Standard
32742
32743
32744 \size footnotesize 
32745 \SpecialChar ~
32746 \SpecialChar ~
32747 mov r2,a
32748 \layout Standard
32749
32750
32751 \size footnotesize 
32752 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
32753 \layout Standard
32754
32755
32756 \size footnotesize 
32757 \SpecialChar ~
32758 \SpecialChar ~
32759 mov b,#0x03
32760 \layout Standard
32761
32762
32763 \size footnotesize 
32764 \SpecialChar ~
32765 \SpecialChar ~
32766 mov a,r4
32767 \layout Standard
32768
32769
32770 \size footnotesize 
32771 \SpecialChar ~
32772 \SpecialChar ~
32773 mul ab
32774 \layout Standard
32775
32776
32777 \size footnotesize 
32778 \SpecialChar ~
32779 \SpecialChar ~
32780 mov r1,a
32781 \layout Standard
32782
32783
32784 \size footnotesize 
32785 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
32786 \layout Standard
32787
32788
32789 \size footnotesize 
32790 ; iTemp15 [lr29:30]{short}[r1]
32791 \layout Standard
32792
32793
32794 \size footnotesize 
32795 \SpecialChar ~
32796 \SpecialChar ~
32797 add a,r3
32798 \layout Standard
32799
32800
32801 \size footnotesize 
32802 \SpecialChar ~
32803 \SpecialChar ~
32804 mov r3,a
32805 \layout Standard
32806
32807
32808 \size footnotesize 
32809 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
32810 \layout Standard
32811
32812
32813 \size footnotesize 
32814 \SpecialChar ~
32815 \SpecialChar ~
32816 mov a,r7
32817 \layout Standard
32818
32819
32820 \size footnotesize 
32821 \SpecialChar ~
32822 \SpecialChar ~
32823 add a,#0xfd
32824 \layout Standard
32825
32826
32827 \size footnotesize 
32828 \SpecialChar ~
32829 \SpecialChar ~
32830 mov r7,a
32831 \layout Standard
32832
32833
32834 \size footnotesize 
32835 \SpecialChar ~
32836 \SpecialChar ~
32837 mov a,r0
32838 \layout Standard
32839
32840
32841 \size footnotesize 
32842 \SpecialChar ~
32843 \SpecialChar ~
32844 addc a,#0xff
32845 \layout Standard
32846
32847
32848 \size footnotesize 
32849 \SpecialChar ~
32850 \SpecialChar ~
32851 mov r0,a
32852 \layout Standard
32853
32854
32855 \size footnotesize 
32856 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
32857 \layout Standard
32858
32859
32860 \size footnotesize 
32861 \SpecialChar ~
32862 \SpecialChar ~
32863 mov a,r7
32864 \layout Standard
32865
32866
32867 \size footnotesize 
32868 \SpecialChar ~
32869 \SpecialChar ~
32870 add a,_gint
32871 \layout Standard
32872
32873
32874 \size footnotesize 
32875 \SpecialChar ~
32876 \SpecialChar ~
32877 mov _gint,a
32878 \layout Standard
32879
32880
32881 \size footnotesize 
32882 \SpecialChar ~
32883 \SpecialChar ~
32884 mov a,r0
32885 \layout Standard
32886
32887
32888 \size footnotesize 
32889 \SpecialChar ~
32890 \SpecialChar ~
32891 addc a,(_gint + 1)
32892 \layout Standard
32893
32894
32895 \size footnotesize 
32896 \SpecialChar ~
32897 \SpecialChar ~
32898 mov (_gint + 1),a
32899 \layout Standard
32900
32901
32902 \size footnotesize 
32903 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
32904 \layout Standard
32905
32906
32907 \size footnotesize 
32908 \SpecialChar ~
32909 \SpecialChar ~
32910 inc r4
32911 \layout Standard
32912
32913
32914 \size footnotesize 
32915 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
32916 \layout Standard
32917
32918
32919 \size footnotesize 
32920 \SpecialChar ~
32921 \SpecialChar ~
32922 dec r5
32923 \layout Standard
32924
32925
32926 \size footnotesize 
32927 \SpecialChar ~
32928 \SpecialChar ~
32929 cjne r5,#0xff,00104$
32930 \layout Standard
32931
32932
32933 \size footnotesize 
32934 \SpecialChar ~
32935 \SpecialChar ~
32936 dec r6
32937 \layout Standard
32938
32939
32940 \size footnotesize 
32941 ; goto _forcond_0($4)
32942 \layout Standard
32943
32944
32945 \size footnotesize 
32946 \SpecialChar ~
32947 \SpecialChar ~
32948 sjmp 00104$
32949 \layout Standard
32950
32951
32952 \size footnotesize 
32953 ; _forbreak_0($7) :
32954 \layout Standard
32955
32956
32957 \size footnotesize 
32958 00107$:
32959 \layout Standard
32960
32961
32962 \size footnotesize 
32963 ; ret iTemp24 [lr40:41]{short}
32964 \layout Standard
32965
32966
32967 \size footnotesize 
32968 \SpecialChar ~
32969 \SpecialChar ~
32970 mov a,r3
32971 \layout Standard
32972
32973
32974 \size footnotesize 
32975 \SpecialChar ~
32976 \SpecialChar ~
32977 add a,r2
32978 \layout Standard
32979
32980
32981 \size footnotesize 
32982 \SpecialChar ~
32983 \SpecialChar ~
32984 mov dpl,a
32985 \layout Standard
32986
32987
32988 \size footnotesize 
32989 ; _return($8) :
32990 \layout Standard
32991
32992
32993 \size footnotesize 
32994 00108$:
32995 \layout Standard
32996
32997
32998 \size footnotesize 
32999 \SpecialChar ~
33000 \SpecialChar ~
33001 ret
33002 \newline 
33003
33004 \layout Section
33005
33006 A few words about basic block successors, predecessors and dominators
33007 \layout Standard
33008
33009 Successors are basic blocks
33010 \begin_inset LatexCommand \index{Basic blocks}
33011
33012 \end_inset 
33013
33014  that might execute after this basic block.
33015 \newline 
33016 Predecessors are basic blocks that might execute before reaching this basic
33017  block.
33018 \newline 
33019 Dominators are basic blocks that WILL execute before reaching this basic
33020  block.
33021 \newline 
33022
33023 \layout Standard
33024
33025 [basic block 1]
33026 \layout Standard
33027
33028 if (something)
33029 \layout Standard
33030
33031 \SpecialChar ~
33032 \SpecialChar ~
33033 \SpecialChar ~
33034 \SpecialChar ~
33035 [basic block 2]
33036 \layout Standard
33037
33038 else
33039 \layout Standard
33040
33041 \SpecialChar ~
33042 \SpecialChar ~
33043 \SpecialChar ~
33044 \SpecialChar ~
33045 [basic block 3]
33046 \layout Standard
33047
33048 [basic block 4]
33049 \newline 
33050
33051 \layout Standard
33052
33053 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
33054 \layout Standard
33055
33056 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
33057 \layout Standard
33058
33059 c) domVect of [BB4] = BB1 ...
33060  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
33061  was executed.
33062 \layout Chapter
33063
33064 Acknowledgments
33065 \layout Standard
33066
33067
33068 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
33069
33070 \end_inset 
33071
33072
33073 \newline 
33074
33075 \newline 
33076
33077 \emph on 
33078 Thanks to all the other volunteer developers who have helped with coding,
33079  testing, web-page creation, distribution sets, etc.
33080  You know who you are :-)
33081 \emph default 
33082
33083 \newline 
33084
33085 \newline 
33086
33087 \emph on 
33088 Also thanks to Sourceforge 
33089 \begin_inset LatexCommand \url{http://www.sf.net}
33090
33091 \end_inset 
33092
33093  which has hosted the project since 1999 and donates significant download
33094  bandwidth and probably more than 
33095 \begin_inset ERT
33096 status Collapsed
33097
33098 \layout Standard
33099 $10^{13}$
33100 \end_inset 
33101
33102 CPU cycles per day.
33103 \newline 
33104  
33105 \begin_inset Note
33106 collapsed false
33107
33108 \layout Standard
33109
33110 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
33111  minutes for (configure+make+regression test), and there is (i386, amd64,
33112  alpha, ppc64, (mingw32), sparc, macosx).
33113  
33114 \end_inset 
33115
33116
33117 \layout Standard
33118
33119 This document was initially written by Sandeep Dutta
33120 \layout Standard
33121
33122 All product names mentioned herein may be trademarks
33123 \begin_inset LatexCommand \index{Trademarks}
33124
33125 \end_inset 
33126
33127  of their respective companies.
33128  
33129 \layout Section*
33130
33131 Alphabetical index
33132 \layout Standard
33133
33134 To avoid confusion, the installation and building options for SDCC itself
33135  (chapter 2) are not part of the index.
33136 \layout Standard
33137
33138
33139 \begin_inset LatexCommand \printindex{}
33140
33141 \end_inset 
33142
33143
33144 \the_end