* support/regression/tests/swap.c: 64 bit hosts failed
[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 \labelwidthstring 00.00.0000
8777
8778
8779 \series bold 
8780 -
8781 \begin_inset ERT
8782 status Collapsed
8783
8784 \layout Standard
8785
8786 \backslash 
8787 /
8788 \end_inset 
8789
8790 -fdollars-in-identifiers
8791 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
8792
8793 \end_inset 
8794
8795
8796 \series default 
8797  Permit '$' as an identifier character
8798 \layout List
8799 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8800
8801
8802 \series bold 
8803 more-pedantic
8804 \series default 
8805  Actually this is 
8806 \series bold 
8807 \emph on 
8808 not
8809 \series default 
8810 \emph default 
8811  a SDCC compiler option but if you want 
8812 \emph on 
8813 more
8814 \emph default 
8815  warnings you can use a separate tool dedicated to syntax checking like
8816  splint
8817 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8818
8819 \end_inset 
8820
8821
8822 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8823
8824 \end_inset 
8825
8826  
8827 \begin_inset LatexCommand \url{http://www.splint.org}
8828
8829 \end_inset 
8830
8831 .
8832  To make your source files parseable by splint you will have to include
8833  
8834 \family sans 
8835 lint.h
8836 \family default 
8837
8838 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8839
8840 \end_inset 
8841
8842  in your source file and add brackets around extended keywords (like 
8843 \family sans 
8844
8845 \begin_inset Quotes sld
8846 \end_inset 
8847
8848 __at\SpecialChar ~
8849
8850 \series bold 
8851 (
8852 \series default 
8853 0xab
8854 \series bold 
8855 )
8856 \series default 
8857
8858 \begin_inset Quotes srd
8859 \end_inset 
8860
8861
8862 \family default 
8863  and 
8864 \family sans 
8865
8866 \begin_inset Quotes sld
8867 \end_inset 
8868
8869 __interrupt\SpecialChar ~
8870 (2)
8871 \begin_inset Quotes srd
8872 \end_inset 
8873
8874
8875 \family default 
8876 ).
8877  
8878 \newline 
8879 Splint has an excellent on line manual at 
8880 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8881
8882 \end_inset 
8883
8884  and it's capabilities go beyond pure syntax checking.
8885  You'll need to tell splint the location of SDCC's include files so a typical
8886  command line could look like this: 
8887 \newline 
8888
8889 \family sans 
8890 splint\SpecialChar ~
8891 -I\SpecialChar ~
8892 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8893 \SpecialChar ~
8894 myprogram.c
8895 \layout Subsection
8896
8897 Intermediate Dump Options
8898 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8899
8900 \end_inset 
8901
8902
8903 \begin_inset LatexCommand \index{Options intermediate dump}
8904
8905 \end_inset 
8906
8907
8908 \begin_inset LatexCommand \index{Intermediate dump options}
8909
8910 \end_inset 
8911
8912
8913 \layout Standard
8914
8915 The following options are provided for the purpose of retargetting and debugging
8916  the compiler.
8917  They provide a means to dump the intermediate code (iCode
8918 \begin_inset LatexCommand \index{iCode}
8919
8920 \end_inset 
8921
8922 ) generated by the compiler in human readable form at various stages of
8923  the compilation process.
8924  More on iCodes see chapter 
8925 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8926
8927 \end_inset 
8928
8929  
8930 \begin_inset Quotes srd
8931 \end_inset 
8932
8933 The anatomy of the compiler
8934 \begin_inset Quotes srd
8935 \end_inset 
8936
8937 .
8938 \layout List
8939 \labelwidthstring 00.00.0000
8940
8941
8942 \series bold 
8943 -
8944 \begin_inset ERT
8945 status Collapsed
8946
8947 \layout Standard
8948
8949 \backslash 
8950 /
8951 \end_inset 
8952
8953 -dumpraw
8954 \begin_inset LatexCommand \index{-\/-dumpraw}
8955
8956 \end_inset 
8957
8958
8959 \series default 
8960  This option will cause the compiler to dump the intermediate code into
8961  a file of named 
8962 \emph on 
8963 <source filename>.dumpraw
8964 \emph default 
8965  just after the intermediate code has been generated for a function, i.e.
8966  before any optimizations are done.
8967  The basic blocks
8968 \begin_inset LatexCommand \index{Basic blocks}
8969
8970 \end_inset 
8971
8972  at this stage ordered in the depth first number, so they may not be in
8973  sequence of execution.
8974 \layout List
8975 \labelwidthstring 00.00.0000
8976
8977
8978 \series bold 
8979 -
8980 \begin_inset ERT
8981 status Collapsed
8982
8983 \layout Standard
8984
8985 \backslash 
8986 /
8987 \end_inset 
8988
8989 -dumpgcse
8990 \begin_inset LatexCommand \index{-\/-dumpgcse}
8991
8992 \end_inset 
8993
8994
8995 \series default 
8996  Will create a dump of iCode's, after global subexpression elimination
8997 \begin_inset LatexCommand \index{Global subexpression elimination}
8998
8999 \end_inset 
9000
9001 , into a file named 
9002 \emph on 
9003 <source filename>.dumpgcse.
9004 \layout List
9005 \labelwidthstring 00.00.0000
9006
9007
9008 \series bold 
9009 -
9010 \begin_inset ERT
9011 status Collapsed
9012
9013 \layout Standard
9014
9015 \backslash 
9016 /
9017 \end_inset 
9018
9019 -dumpdeadcode
9020 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9021
9022 \end_inset 
9023
9024
9025 \series default 
9026  Will create a dump of iCode's, after deadcode elimination
9027 \begin_inset LatexCommand \index{Dead-code elimination}
9028
9029 \end_inset 
9030
9031 , into a file named 
9032 \emph on 
9033 <source filename>.dumpdeadcode.
9034 \layout List
9035 \labelwidthstring 00.00.0000
9036
9037
9038 \series bold 
9039 -
9040 \begin_inset ERT
9041 status Collapsed
9042
9043 \layout Standard
9044
9045 \backslash 
9046 /
9047 \end_inset 
9048
9049 -dumploop
9050 \begin_inset LatexCommand \index{-\/-dumploop}
9051
9052 \end_inset 
9053
9054
9055 \series default 
9056 \size large 
9057  
9058 \size default 
9059 Will create a dump of iCode's, after loop optimizations
9060 \begin_inset LatexCommand \index{Loop optimization}
9061
9062 \end_inset 
9063
9064 , into a file named 
9065 \emph on 
9066 <source filename>.dumploop.
9067 \layout List
9068 \labelwidthstring 00.00.0000
9069
9070
9071 \series bold 
9072 -
9073 \begin_inset ERT
9074 status Collapsed
9075
9076 \layout Standard
9077
9078 \backslash 
9079 /
9080 \end_inset 
9081
9082 -dumprange
9083 \begin_inset LatexCommand \index{-\/-dumprange}
9084
9085 \end_inset 
9086
9087
9088 \series default 
9089 \size large 
9090  
9091 \size default 
9092 Will create a dump of iCode's, after live range analysis
9093 \begin_inset LatexCommand \index{Live range analysis}
9094
9095 \end_inset 
9096
9097 , into a file named 
9098 \emph on 
9099 <source filename>.dumprange.
9100 \layout List
9101 \labelwidthstring 00.00.0000
9102
9103
9104 \series bold 
9105 -
9106 \begin_inset ERT
9107 status Collapsed
9108
9109 \layout Standard
9110
9111 \backslash 
9112 /
9113 \end_inset 
9114
9115 -dumlrange
9116 \begin_inset LatexCommand \index{-\/-dumlrange}
9117
9118 \end_inset 
9119
9120
9121 \series default 
9122  Will dump the life ranges
9123 \begin_inset LatexCommand \index{Live range analysis}
9124
9125 \end_inset 
9126
9127  for all symbols.
9128 \layout List
9129 \labelwidthstring 00.00.0000
9130
9131
9132 \series bold 
9133 -
9134 \begin_inset ERT
9135 status Collapsed
9136
9137 \layout Standard
9138
9139 \backslash 
9140 /
9141 \end_inset 
9142
9143 -dumpregassign
9144 \begin_inset LatexCommand \index{-\/-dumpregassign}
9145
9146 \end_inset 
9147
9148
9149 \bar under 
9150  
9151 \series default 
9152 \bar default 
9153 Will create a dump of iCode's, after register assignment
9154 \begin_inset LatexCommand \index{Register assignment}
9155
9156 \end_inset 
9157
9158 , into a file named 
9159 \emph on 
9160 <source filename>.dumprassgn.
9161 \layout List
9162 \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 -dumplrange
9177 \begin_inset LatexCommand \index{-\/-dumplrange}
9178
9179 \end_inset 
9180
9181
9182 \series default 
9183  Will create a dump of the live ranges of iTemp's
9184 \layout List
9185 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9186
9187
9188 \series bold 
9189 -
9190 \begin_inset ERT
9191 status Collapsed
9192
9193 \layout Standard
9194
9195 \backslash 
9196 /
9197 \end_inset 
9198
9199 -dumpall
9200 \begin_inset LatexCommand \index{-\/-dumpall}
9201
9202 \end_inset 
9203
9204
9205 \size large 
9206 \bar under 
9207  
9208 \series default 
9209 \size default 
9210 \bar default 
9211 Will cause all the above mentioned dumps to be created.
9212 \layout Subsection
9213
9214 Redirecting output on Windows Shells
9215 \layout Standard
9216 \added_space_bottom bigskip 
9217 By default SDCC writes it's error messages to 
9218 \begin_inset Quotes sld
9219 \end_inset 
9220
9221 standard error
9222 \begin_inset Quotes srd
9223 \end_inset 
9224
9225 .
9226  To force all messages to 
9227 \begin_inset Quotes sld
9228 \end_inset 
9229
9230 standard output
9231 \begin_inset Quotes srd
9232 \end_inset 
9233
9234  use 
9235 \series bold 
9236 -
9237 \series default 
9238 \emph on 
9239
9240 \begin_inset ERT
9241 status Collapsed
9242
9243 \layout Standard
9244
9245 \backslash 
9246 /
9247 \end_inset 
9248
9249
9250 \series bold 
9251 \emph default 
9252 -
9253 \series default 
9254 use-stdout
9255 \begin_inset LatexCommand \index{-\/-use-stdout}
9256
9257 \end_inset 
9258
9259 .
9260  Additionally, if you happen to have visual studio installed in your windows
9261  machine, you can use it to compile your sources using a custom build and
9262  the SDCC -
9263 \emph on 
9264
9265 \begin_inset ERT
9266 status Collapsed
9267
9268 \layout Standard
9269
9270 \backslash 
9271 /
9272 \end_inset 
9273
9274
9275 \emph default 
9276 -vc
9277 \begin_inset LatexCommand \index{-\/-vc}
9278
9279 \end_inset 
9280
9281  option.
9282  Something like this should work:
9283 \newline 
9284
9285 \newline 
9286
9287 \series bold 
9288 c:
9289 \backslash 
9290 sdcc
9291 \backslash 
9292 bin
9293 \backslash 
9294 sdcc.exe -
9295 \series default 
9296 \emph on 
9297
9298 \begin_inset ERT
9299 status Collapsed
9300
9301 \layout Standard
9302
9303 \backslash 
9304 /
9305 \end_inset 
9306
9307
9308 \series bold 
9309 \emph default 
9310 -vc -
9311 \series default 
9312 \emph on 
9313
9314 \begin_inset ERT
9315 status Collapsed
9316
9317 \layout Standard
9318
9319 \backslash 
9320 /
9321 \end_inset 
9322
9323
9324 \series bold 
9325 \emph default 
9326 -model-large -c $(InputPath)
9327 \layout Section
9328
9329 Environment variables
9330 \begin_inset LatexCommand \index{Environment variables}
9331
9332 \end_inset 
9333
9334
9335 \layout Standard
9336
9337 SDCC recognizes the following environment variables:
9338 \layout List
9339 \labelwidthstring 00.00.0000
9340
9341
9342 \series bold 
9343 SDCC_LEAVE_SIGNALS
9344 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9345
9346 \end_inset 
9347
9348
9349 \series default 
9350  SDCC installs a signal handler
9351 \begin_inset LatexCommand \index{signal handler}
9352
9353 \end_inset 
9354
9355  to be able to delete temporary files after an user break (^C) or an exception.
9356  If this environment variable is set, SDCC won't install the signal handler
9357  in order to be able to debug SDCC.
9358 \layout List
9359 \labelwidthstring 00.00.0000
9360
9361
9362 \series bold 
9363 TMP,\SpecialChar ~
9364 TEMP,\SpecialChar ~
9365 TMPDIR
9366 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9367
9368 \end_inset 
9369
9370
9371 \series default 
9372  Path, where temporary files will be created.
9373  The order of the variables is the search order.
9374  In a standard *nix environment these variables are not set, and there's
9375  no need to set them.
9376  On Windows it's recommended to set one of them.
9377 \layout List
9378 \labelwidthstring 00.00.0000
9379
9380
9381 \series bold 
9382 SDCC_HOME
9383 \begin_inset LatexCommand \index{SDCC\_HOME}
9384
9385 \end_inset 
9386
9387
9388 \series default 
9389  Path, see section 
9390 \begin_inset LatexCommand \ref{sub:Install-paths}
9391
9392 \end_inset 
9393
9394 \SpecialChar ~
9395
9396 \begin_inset Quotes sld
9397 \end_inset 
9398
9399  Install Paths
9400 \begin_inset Quotes srd
9401 \end_inset 
9402
9403 .
9404 \layout List
9405 \labelwidthstring 00.00.0000
9406
9407
9408 \series bold 
9409 SDCC_INCLUDE
9410 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9411
9412 \end_inset 
9413
9414
9415 \series default 
9416  Path, see section 
9417 \begin_inset LatexCommand \ref{sub:Search-Paths}
9418
9419 \end_inset 
9420
9421 \SpecialChar ~
9422
9423 \begin_inset Quotes sld
9424 \end_inset 
9425
9426 Search Paths
9427 \begin_inset Quotes srd
9428 \end_inset 
9429
9430 .
9431 \layout List
9432 \labelwidthstring 00.00.0000
9433
9434
9435 \series bold 
9436 SDCC_LIB
9437 \begin_inset LatexCommand \index{SDCC\_LIB}
9438
9439 \end_inset 
9440
9441
9442 \series default 
9443  Path, see section 
9444 \begin_inset LatexCommand \ref{sub:Search-Paths}
9445
9446 \end_inset 
9447
9448 \SpecialChar ~
9449
9450 \begin_inset Quotes sld
9451 \end_inset 
9452
9453 Search Paths
9454 \begin_inset Quotes srd
9455 \end_inset 
9456
9457 ..
9458 \layout Standard
9459 \added_space_bottom bigskip 
9460 There are some more environment variables recognized by SDCC, but these
9461  are solely used for debugging purposes.
9462  They can change or disappear very quickly, and will never be documented.
9463 \layout Section
9464
9465 Storage Class Language Extensions
9466 \layout Subsection
9467
9468 MCS51/DS390 Storage Class
9469 \begin_inset LatexCommand \index{Storage class}
9470
9471 \end_inset 
9472
9473  Language Extensions
9474 \layout Standard
9475
9476 In addition to the ANSI storage classes SDCC allows the following MCS51
9477  specific storage classes:
9478 \layout Subsubsection
9479
9480 data
9481 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9482
9483 \end_inset 
9484
9485
9486 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9487
9488 \end_inset 
9489
9490  / near
9491 \begin_inset LatexCommand \index{near (storage class)}
9492
9493 \end_inset 
9494
9495
9496 \begin_inset LatexCommand \index{\_\_near (storage class)}
9497
9498 \end_inset 
9499
9500
9501 \layout Standard
9502
9503 This is the 
9504 \series bold 
9505 default
9506 \series default 
9507  storage class for the Small Memory model (
9508 \emph on 
9509 data
9510 \emph default 
9511  and 
9512 \emph on 
9513 near
9514 \emph default 
9515  or the more ANSI-C compliant forms 
9516 \emph on 
9517 __data
9518 \emph default 
9519  and 
9520 \emph on 
9521 __near
9522 \emph default 
9523  can be used synonymously).
9524  Variables declared with this storage class will be allocated in the directly
9525  addressable portion of the internal RAM of a 8051, e.g.:
9526 \layout Verse
9527
9528
9529 \family typewriter 
9530 __data unsigned char test_data;
9531 \layout Standard
9532
9533 Writing 0x01 to this variable generates the assembly code:
9534 \layout Verse
9535
9536
9537 \family typewriter 
9538 75*00 01\SpecialChar ~
9539 \SpecialChar ~
9540 \SpecialChar ~
9541 mov\SpecialChar ~
9542 \SpecialChar ~
9543 _test_data,#0x01
9544 \layout Subsubsection
9545
9546 xdata
9547 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9548
9549 \end_inset 
9550
9551
9552 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9553
9554 \end_inset 
9555
9556  / far
9557 \begin_inset LatexCommand \index{far (storage class)}
9558
9559 \end_inset 
9560
9561
9562 \begin_inset LatexCommand \index{\_\_far (storage class)}
9563
9564 \end_inset 
9565
9566
9567 \layout Standard
9568
9569 Variables declared with this storage class will be placed in the external
9570  RAM.
9571  This is the 
9572 \series bold 
9573 default
9574 \series default 
9575  storage class for the Large Memory model, e.g.:
9576 \layout Verse
9577
9578
9579 \family typewriter 
9580 __xdata unsigned char test_xdata;
9581 \layout Standard
9582
9583 Writing 0x01 to this variable generates the assembly code:
9584 \layout Verse
9585
9586
9587 \family typewriter 
9588 90s00r00\SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 mov\SpecialChar ~
9592 \SpecialChar ~
9593 dptr,#_test_xdata 
9594 \newline 
9595 74\SpecialChar ~
9596 01\SpecialChar ~
9597 \SpecialChar ~
9598 \SpecialChar ~
9599 \SpecialChar ~
9600 \SpecialChar ~
9601 \SpecialChar ~
9602 mov\SpecialChar ~
9603 \SpecialChar ~
9604 a,#0x01 
9605 \newline 
9606 F0\SpecialChar ~
9607 \SpecialChar ~
9608 \SpecialChar ~
9609 \SpecialChar ~
9610 \SpecialChar ~
9611 \SpecialChar ~
9612 \SpecialChar ~
9613 \SpecialChar ~
9614 \SpecialChar ~
9615 movx\SpecialChar ~
9616 @dptr,a 
9617 \layout Subsubsection
9618
9619 idata
9620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9621
9622 \end_inset 
9623
9624
9625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9626
9627 \end_inset 
9628
9629
9630 \layout Standard
9631
9632 Variables declared with this storage class will be allocated into the indirectly
9633  addressable portion of the internal ram of a 8051, e.g.:
9634 \layout Verse
9635
9636
9637 \family typewriter 
9638 __idata unsigned char test_idata;
9639 \layout Standard
9640
9641 Writing 0x01 to this variable generates the assembly code:
9642 \layout Verse
9643
9644
9645 \family typewriter 
9646 78r00\SpecialChar ~
9647 \SpecialChar ~
9648 \SpecialChar ~
9649 \SpecialChar ~
9650 \SpecialChar ~
9651 \SpecialChar ~
9652 \SpecialChar ~
9653 mov\SpecialChar ~
9654 \SpecialChar ~
9655 r0,#_test_idata
9656 \newline 
9657 76\SpecialChar ~
9658 01\SpecialChar ~
9659 \SpecialChar ~
9660 \SpecialChar ~
9661 \SpecialChar ~
9662 \SpecialChar ~
9663 \SpecialChar ~
9664 \SpecialChar ~
9665 mov\SpecialChar ~
9666 \SpecialChar ~
9667 @r0,#0x01
9668 \layout Standard
9669
9670 Please note, the first 128 byte of idata physically access the same RAM
9671  as the data memory.
9672  The original 8051 had 128 byte idata memory, nowadays most devices have
9673  256 byte idata memory.
9674  The stack
9675 \begin_inset LatexCommand \index{stack}
9676
9677 \end_inset 
9678
9679  is located in idata memory.
9680 \layout Subsubsection
9681
9682 pdata
9683 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9684
9685 \end_inset 
9686
9687
9688 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9689
9690 \end_inset 
9691
9692
9693 \layout Standard
9694
9695 Paged xdata access is just as straightforward as using the other addressing
9696  modes of a 8051.
9697  It is typically located at the start of xdata and has a maximum size of
9698  256 bytes.
9699  The following example writes 0x01 to the pdata variable.
9700  Please note, pdata access physically accesses xdata memory.
9701  The high byte of the address is determined by port P2 
9702 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9703
9704 \end_inset 
9705
9706 (or in case of some 8051 variants by a separate Special Function Register,
9707  see section 
9708 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9709
9710 \end_inset 
9711
9712 ).
9713  This is the 
9714 \series bold 
9715 default
9716 \series default 
9717  storage class for the Medium Memory model, e.g.:
9718 \layout Verse
9719
9720
9721 \family typewriter 
9722 __pdata unsigned char test_pdata;
9723 \layout Standard
9724
9725 Writing 0x01 to this variable generates the assembly code:
9726 \layout Verse
9727
9728
9729 \family typewriter 
9730 78r00\SpecialChar ~
9731 \SpecialChar ~
9732 \SpecialChar ~
9733 \SpecialChar ~
9734 \SpecialChar ~
9735 \SpecialChar ~
9736 mov r0,#_test_pdata
9737 \newline 
9738 74 01\SpecialChar ~
9739 \SpecialChar ~
9740 \SpecialChar ~
9741 \SpecialChar ~
9742 \SpecialChar ~
9743 \SpecialChar ~
9744 mov a,#0x01 
9745 \newline 
9746 F2\SpecialChar ~
9747 \SpecialChar ~
9748 \SpecialChar ~
9749 \SpecialChar ~
9750 \SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 movx @r0,a
9756 \layout Standard
9757
9758 If the -
9759 \begin_inset ERT
9760 status Collapsed
9761
9762 \layout Standard
9763
9764 \backslash 
9765 /
9766 \end_inset 
9767
9768 -xstack
9769 \begin_inset LatexCommand \index{-\/-xstack}
9770
9771 \end_inset 
9772
9773  option is used the pdata memory area is followed by the xstack memory area
9774  and the sum of their sizes is limited to 256 bytes.
9775 \layout Subsubsection
9776
9777 code
9778 \begin_inset LatexCommand \index{code}
9779
9780 \end_inset 
9781
9782
9783 \begin_inset LatexCommand \index{\_\_code}
9784
9785 \end_inset 
9786
9787
9788 \layout Standard
9789
9790 'Variables' declared with this storage class will be placed in the code
9791  memory:
9792 \layout Verse
9793
9794
9795 \family typewriter 
9796 __code unsigned char test_code;
9797 \layout Standard
9798
9799 Read access to this variable generates the assembly code:
9800 \layout Verse
9801
9802
9803 \family typewriter 
9804 90s00r6F\SpecialChar ~
9805 \SpecialChar ~
9806 \SpecialChar ~
9807 mov dptr,#_test_code
9808 \newline 
9809 E4\SpecialChar ~
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 \SpecialChar ~
9817 \SpecialChar ~
9818 clr a
9819 \newline 
9820 93\SpecialChar ~
9821 \SpecialChar ~
9822 \SpecialChar ~
9823 \SpecialChar ~
9824 \SpecialChar ~
9825 \SpecialChar ~
9826 \SpecialChar ~
9827 \SpecialChar ~
9828 \SpecialChar ~
9829 movc a,@a+dptr 
9830 \layout Standard
9831
9832
9833 \family typewriter 
9834 char
9835 \family default 
9836  indexed arrays of characters in code memory can be accessed efficiently:
9837 \layout Verse
9838
9839
9840 \family typewriter 
9841 __code char test_array[] = {'c','h','e','a','p'}; 
9842 \layout Standard
9843
9844 Read access to this array using an 8-bit unsigned index generates the assembly
9845  code:
9846 \layout Verse
9847
9848
9849 \family typewriter 
9850 E5*00\SpecialChar ~
9851 \SpecialChar ~
9852 \SpecialChar ~
9853 \SpecialChar ~
9854 \SpecialChar ~
9855 \SpecialChar ~
9856 mov a,_index 
9857 \layout Verse
9858
9859
9860 \family typewriter 
9861 90s00r41\SpecialChar ~
9862 \SpecialChar ~
9863 \SpecialChar ~
9864 mov dptr,#_test_array
9865 \layout Verse
9866
9867
9868 \family typewriter 
9869 93\SpecialChar ~
9870 \SpecialChar ~
9871 \SpecialChar ~
9872 \SpecialChar ~
9873 \SpecialChar ~
9874 \SpecialChar ~
9875 \SpecialChar ~
9876 \SpecialChar ~
9877 \SpecialChar ~
9878 movc a,@a+dptr 
9879 \layout Subsubsection
9880
9881 bit
9882 \begin_inset LatexCommand \index{bit}
9883
9884 \end_inset 
9885
9886
9887 \begin_inset LatexCommand \index{\_\_bit}
9888
9889 \end_inset 
9890
9891
9892 \layout Standard
9893
9894 This is a data-type and a storage class specifier.
9895  When a variable is declared as a bit, it is allocated into the bit addressable
9896  memory of 8051, e.g.:
9897 \layout Verse
9898
9899
9900 \family typewriter 
9901 __bit test_bit;
9902 \layout Standard
9903
9904 Writing 1 to this variable generates the assembly code:
9905 \layout Verse
9906
9907
9908 \family typewriter 
9909 D2*00\SpecialChar ~
9910 \SpecialChar ~
9911 \SpecialChar ~
9912 \SpecialChar ~
9913 \SpecialChar ~
9914 \SpecialChar ~
9915 \SpecialChar ~
9916 setb\SpecialChar ~
9917 _test_bit
9918 \layout Standard
9919
9920 The bit addressable memory consists of 128 bits which are located from 0x20
9921  to 0x2f in data memory.
9922  
9923 \newline 
9924 Apart from this 8051 specific storage class most architectures support ANSI-C
9925  bitfields
9926 \begin_inset LatexCommand \index{bitfields}
9927
9928 \end_inset 
9929
9930
9931 \begin_inset Foot
9932 collapsed false
9933
9934 \layout Standard
9935
9936 Not really meant as examples, but nevertheless showing what bitfields are
9937  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9938 \end_inset 
9939
9940 .
9941  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9942  signed modifier are implemented as unsigned.
9943 \layout Subsubsection
9944
9945 sfr
9946 \begin_inset LatexCommand \index{sfr}
9947
9948 \end_inset 
9949
9950
9951 \begin_inset LatexCommand \index{\_\_sfr}
9952
9953 \end_inset 
9954
9955  / sfr16
9956 \begin_inset LatexCommand \index{sfr16}
9957
9958 \end_inset 
9959
9960
9961 \begin_inset LatexCommand \index{\_\_sfr16}
9962
9963 \end_inset 
9964
9965  / sfr32
9966 \begin_inset LatexCommand \index{sfr32}
9967
9968 \end_inset 
9969
9970
9971 \begin_inset LatexCommand \index{\_\_sfr32}
9972
9973 \end_inset 
9974
9975  / sbit
9976 \begin_inset LatexCommand \index{\_\_sbit}
9977
9978 \end_inset 
9979
9980
9981 \begin_inset LatexCommand \index{sbit}
9982
9983 \end_inset 
9984
9985
9986 \layout Standard
9987
9988 Like the bit keyword, 
9989 \emph on 
9990 sfr / sfr16 / sfr32 / sbit 
9991 \emph default 
9992 signify both a data-type and storage class, they are used to describe the
9993  
9994 \emph on 
9995 s
9996 \emph default 
9997 pecial 
9998 \emph on 
9999 f
10000 \emph default 
10001 unction 
10002 \emph on 
10003 r
10004 \emph default 
10005 egisters and 
10006 \emph on 
10007 s
10008 \emph default 
10009 pecial 
10010 \emph on 
10011 bit
10012 \emph default 
10013  variables of a 8051, eg:
10014 \layout Verse
10015
10016
10017 \family typewriter 
10018 __sfr __at
10019 \begin_inset LatexCommand \index{at}
10020
10021 \end_inset 
10022
10023
10024 \begin_inset LatexCommand \index{\_\_at}
10025
10026 \end_inset 
10027
10028  (0x80) P0;\SpecialChar ~
10029  /* special function register P0 at location 0x80 */
10030 \newline 
10031
10032 \newline 
10033 /* 16 bit special function register combination for timer 0
10034 \newline 
10035 \SpecialChar ~
10036 \SpecialChar ~
10037  with the high byte at location 0x8C and the low byte at location 0x8A */
10038 \newline 
10039 __sfr16 __at (0x8C8A) TMR0;
10040 \newline 
10041
10042 \newline 
10043 __sbit __at
10044 \begin_inset LatexCommand \index{at}
10045
10046 \end_inset 
10047
10048
10049 \begin_inset LatexCommand \index{\_\_at}
10050
10051 \end_inset 
10052
10053  (0xd7) CY;\SpecialChar ~
10054  /* CY (Carry Flag
10055 \begin_inset LatexCommand \index{Flags}
10056
10057 \end_inset 
10058
10059
10060 \begin_inset LatexCommand \index{Carry flag}
10061
10062 \end_inset 
10063
10064 ) */
10065 \layout Standard
10066
10067 Special function registers which are located on an address dividable by
10068  8 are bit-addressable, an
10069 \emph on 
10070  sbit
10071 \emph default 
10072  addresses a specific bit within these sfr.
10073 \newline 
10074 16 Bit and 32 bit special function register combinations which require a
10075  certain access order are better not declared using 
10076 \emph on 
10077 sfr16
10078 \emph default 
10079  or 
10080 \emph on 
10081 sfr32.
10082
10083 \emph default 
10084  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10085  this is not guaranteed.
10086 \newline 
10087
10088 \layout Standard
10089
10090 Please note, if you use a header file which was written for another compiler
10091  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10092  likely be 
10093 \emph on 
10094 not 
10095 \emph default 
10096 compatible.
10097  Specifically the syntax 
10098 \family typewriter 
10099 \SpecialChar ~
10100 sfr P0 = 0x80;\SpecialChar ~
10101
10102 \family default 
10103  is compiled 
10104 \emph on 
10105 without warning
10106 \emph default 
10107  by SDCC to an assignment of 0x80 to a variable called P0 
10108 \family typewriter 
10109
10110 \begin_inset Marginal
10111 collapsed true
10112
10113 \layout Standard
10114
10115
10116 \series bold 
10117 \SpecialChar ~
10118 !
10119 \end_inset 
10120
10121 .
10122  
10123 \family default 
10124 Nevertheless it is possible to write header files
10125 \begin_inset LatexCommand \index{Header files}
10126
10127 \end_inset 
10128
10129
10130 \begin_inset LatexCommand \index{Include files}
10131
10132 \end_inset 
10133
10134  which can be shared among different compilers (see section 
10135 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10136
10137 \end_inset 
10138
10139 ).
10140  
10141 \layout Subsubsection
10142
10143 Pointers
10144 \begin_inset LatexCommand \index{Pointer}
10145
10146 \end_inset 
10147
10148  to MCS51/DS390 specific memory spaces
10149 \layout Standard
10150
10151 SDCC allows (via language extensions) pointers to explicitly point to any
10152  of the memory spaces
10153 \begin_inset LatexCommand \index{Memory model}
10154
10155 \end_inset 
10156
10157  of the 8051.
10158  In addition to the explicit pointers, the compiler uses (by default) generic
10159  pointers which can be used to point to any of the memory spaces.
10160 \newline 
10161
10162 \newline 
10163 Pointer declaration examples:
10164 \layout Verse
10165
10166
10167 \family typewriter 
10168 /* pointer physically in internal ram pointing to object in external ram
10169  */ 
10170 \newline 
10171 __xdata unsigned char * __data p;
10172 \newline 
10173
10174 \newline 
10175 /* pointer physically in external ram pointing to object in internal ram
10176  */ 
10177 \newline 
10178 __data unsigned char * __xdata p;
10179 \newline 
10180
10181 \newline 
10182 /* pointer physically in code rom pointing to data in xdata space */ 
10183 \newline 
10184 __xdata unsigned char * __code p;
10185 \newline 
10186
10187 \newline 
10188 /* pointer physically in code space pointing to data in code space */ 
10189 \newline 
10190 __code unsigned char * __code p;
10191 \newline 
10192
10193 \newline 
10194 /* generic pointer physically located in xdata space */
10195 \newline 
10196 unsigned char * __xdata p;
10197 \newline 
10198
10199 \newline 
10200 /* generic pointer physically located in default memory space */
10201 \newline 
10202 unsigned char * p;
10203 \newline 
10204
10205 \newline 
10206 /* the following is a function pointer
10207 \begin_inset LatexCommand \index{function pointer}
10208
10209 \end_inset 
10210
10211  physically located in data space */
10212 \newline 
10213 char (* __data fp)(void);
10214 \layout Standard
10215
10216 Well you get the idea.
10217  
10218 \newline 
10219
10220 \newline 
10221 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10222 \emph on 
10223 generic
10224 \emph default 
10225  pointers.
10226  
10227 \size small 
10228
10229 \newline 
10230
10231 \newline 
10232
10233 \size default 
10234 The highest order byte of the 
10235 \emph on 
10236 generic
10237 \emph default 
10238  pointers contains the data space information.
10239  Assembler support routines are called whenever data is stored or retrieved
10240  using 
10241 \emph on 
10242 generic
10243 \emph default 
10244  pointers.
10245  These are useful for developing reusable library
10246 \begin_inset LatexCommand \index{Libraries}
10247
10248 \end_inset 
10249
10250  routines.
10251  Explicitly specifying the pointer
10252 \begin_inset LatexCommand \index{pointer}
10253
10254 \end_inset 
10255
10256  type will generate the most efficient code.
10257 \layout Subsubsection
10258
10259 Notes on MCS51 memory
10260 \begin_inset LatexCommand \index{MCS51 memory}
10261
10262 \end_inset 
10263
10264  layout
10265 \layout Standard
10266
10267 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10268  RAM memory which is structured as follows:
10269 \newline 
10270
10271 \newline 
10272 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10273  
10274 \newline 
10275 - Bytes 20-2F - 16 bytes to hold 128 bit
10276 \begin_inset LatexCommand \index{bit}
10277
10278 \end_inset 
10279
10280  variables and, 
10281 \newline 
10282 - Bytes 30-7F - 80 bytes for general purpose use.
10283 \newline 
10284
10285 \layout Standard
10286
10287 Additionally some members of the MCS51 family may have up to 128 bytes of
10288  additional, indirectly addressable, internal RAM memory (
10289 \emph on 
10290 idata
10291 \emph default 
10292
10293 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10294
10295 \end_inset 
10296
10297
10298 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10299
10300 \end_inset 
10301
10302 ).
10303  Furthermore, some chips may have some built in external memory (
10304 \emph on 
10305 xdata
10306 \emph default 
10307
10308 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10309
10310 \end_inset 
10311
10312
10313 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10314
10315 \end_inset 
10316
10317 ) which should not be confused with the internal, directly addressable RAM
10318  memory (
10319 \emph on 
10320 data
10321 \emph default 
10322
10323 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10324
10325 \end_inset 
10326
10327
10328 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10329
10330 \end_inset 
10331
10332 ).
10333  Sometimes this built in 
10334 \emph on 
10335 xdata
10336 \emph default 
10337  memory has to be activated before using it (you can probably find this
10338  information on the datasheet of the microcontroller your are using, see
10339  also section 
10340 \begin_inset LatexCommand \ref{sub:Startup-Code}
10341
10342 \end_inset 
10343
10344 \SpecialChar ~
10345 Startup-Code).
10346 \layout Standard
10347
10348 Normally SDCC will only use the first bank
10349 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10350
10351 \end_inset 
10352
10353  of registers (register bank 0), but it is possible to specify that other
10354  banks of registers (keyword 
10355 \emph on 
10356 using
10357 \emph default 
10358  
10359 \emph on 
10360
10361 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10362
10363 \end_inset 
10364
10365
10366 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10367
10368 \end_inset 
10369
10370
10371 \emph default 
10372 ) should be used in interrupt
10373 \begin_inset LatexCommand \index{interrupt}
10374
10375 \end_inset 
10376
10377
10378 \begin_inset LatexCommand \index{\_\_interrupt}
10379
10380 \end_inset 
10381
10382  routines.
10383  By default, the compiler will place the stack after the last byte of allocated
10384  memory for variables.
10385  For example, if the first 2 banks of registers are used, and only four
10386  bytes are used for 
10387 \emph on 
10388 data
10389 \emph default 
10390  variables, it will position the base of the internal stack at address 20
10391  (0x14).
10392  This implies that as the stack
10393 \begin_inset LatexCommand \index{stack}
10394
10395 \end_inset 
10396
10397  grows, it will use up the remaining register banks, and the 16 bytes used
10398  by the 128 bit variables, and 80 bytes for general purpose use.
10399  If any bit variables are used, the data variables will be placed in unused
10400  register banks and after the byte holding the last bit variable.
10401  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10402  (two bytes used), 
10403 \emph on 
10404 data
10405 \emph default 
10406  variables will be placed starting from address 0x10 to 0x20 and continue
10407  at address 0x22.
10408  You can also use -
10409 \begin_inset ERT
10410 status Collapsed
10411
10412 \layout Standard
10413
10414 \backslash 
10415 /
10416 \end_inset 
10417
10418 -data-loc
10419 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10420
10421 \end_inset 
10422
10423  to specify the start address of the 
10424 \emph on 
10425 data
10426 \emph default 
10427  and -
10428 \begin_inset ERT
10429 status Collapsed
10430
10431 \layout Standard
10432
10433 \backslash 
10434 /
10435 \end_inset 
10436
10437 -iram-size
10438 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10439
10440 \end_inset 
10441
10442  to specify the size of the total internal RAM (
10443 \emph on 
10444 data
10445 \emph default 
10446 +
10447 \emph on 
10448 idata
10449 \emph default 
10450 ).
10451  
10452 \newline 
10453
10454 \layout Standard
10455
10456 By default the 8051 linker will place the stack after the last byte of (i)data
10457  variables.
10458  Option -
10459 \begin_inset ERT
10460 status Collapsed
10461
10462 \layout Standard
10463
10464 \backslash 
10465 /
10466 \end_inset 
10467
10468 -stack-loc
10469 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10470
10471 \end_inset 
10472
10473  allows you to specify the start of the stack, i.e.
10474  you could start it after any data in the general purpose area.
10475  If your microcontroller has additional indirectly addressable internal
10476  RAM (
10477 \emph on 
10478 idata
10479 \emph default 
10480 ) you can place the stack on it.
10481  You may also need to use -
10482 \begin_inset ERT
10483 status Collapsed
10484
10485 \layout Standard
10486
10487 \backslash 
10488 /
10489 \end_inset 
10490
10491 -xdata-loc
10492 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10493
10494 \end_inset 
10495
10496  to set the start address of the external RAM (
10497 \emph on 
10498 xdata
10499 \emph default 
10500 ) and -
10501 \begin_inset ERT
10502 status Collapsed
10503
10504 \layout Standard
10505
10506 \backslash 
10507 /
10508 \end_inset 
10509
10510 -xram-size
10511 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10512
10513 \end_inset 
10514
10515  to specify its size.
10516  Same goes for the code memory, using -
10517 \begin_inset ERT
10518 status Collapsed
10519
10520 \layout Standard
10521
10522 \backslash 
10523 /
10524 \end_inset 
10525
10526 -code-loc
10527 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10528
10529 \end_inset 
10530
10531  and -
10532 \begin_inset ERT
10533 status Collapsed
10534
10535 \layout Standard
10536
10537 \backslash 
10538 /
10539 \end_inset 
10540
10541 -code-size
10542 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10543
10544 \end_inset 
10545
10546 .
10547  If in doubt, don't specify any options and see if the resulting memory
10548  layout is appropriate, then you can adjust it.
10549 \layout Standard
10550 \added_space_bottom bigskip 
10551 The linker generates two files with memory allocation information.
10552  The first, with extension .map
10553 \begin_inset LatexCommand \index{<file>.map}
10554
10555 \end_inset 
10556
10557  shows all the variables and segments.
10558  The second with extension .mem
10559 \begin_inset LatexCommand \index{<file>.mem}
10560
10561 \end_inset 
10562
10563  shows the final memory layout.
10564  The linker will complain either if memory segments overlap, there is not
10565  enough memory, or there is not enough space for stack.
10566  If you get any linking warnings and/or errors related to stack or segments
10567  allocation, take a look at either the .map or .mem files to find out what
10568  the problem is.
10569  The .mem file may even suggest a solution to the problem.
10570 \layout Subsection
10571
10572 Z80/Z180 Storage Class
10573 \begin_inset LatexCommand \index{Z80!Storage class}
10574
10575 \end_inset 
10576
10577  Language Extensions
10578 \layout Subsubsection
10579
10580 sfr
10581 \begin_inset LatexCommand \index{sfr}
10582
10583 \end_inset 
10584
10585
10586 \begin_inset LatexCommand \index{\_\_sfr}
10587
10588 \end_inset 
10589
10590  (in/out to 8-bit addresses)
10591 \layout Standard
10592
10593 The Z80
10594 \begin_inset LatexCommand \index{Z80}
10595
10596 \end_inset 
10597
10598  family has separate address spaces for memory and 
10599 \emph on 
10600 i
10601 \emph default 
10602 nput/
10603 \emph on 
10604 o
10605 \emph default 
10606 utput memory.
10607  I/O memory
10608 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10609
10610 \end_inset 
10611
10612
10613 \begin_inset LatexCommand \index{Z80!I/O memory}
10614
10615 \end_inset 
10616
10617
10618 \begin_inset LatexCommand \index{Z180!I/O memory}
10619
10620 \end_inset 
10621
10622  is accessed with special instructions, e.g.:
10623 \layout Verse
10624
10625
10626 \family typewriter 
10627 sfr at 0x78 IoPort;\SpecialChar ~
10628 \SpecialChar ~
10629 /* define a var in I/O space at 78h called IoPort */
10630  
10631 \layout Standard
10632
10633 Writing 0x01 to this variable generates the assembly code:
10634 \layout Verse
10635
10636
10637 \family typewriter 
10638 3E 01\SpecialChar ~
10639 \SpecialChar ~
10640 \SpecialChar ~
10641 \SpecialChar ~
10642 \SpecialChar ~
10643 \SpecialChar ~
10644 ld a,#0x01
10645 \newline 
10646 D3 78\SpecialChar ~
10647 \SpecialChar ~
10648 \SpecialChar ~
10649 \SpecialChar ~
10650 \SpecialChar ~
10651 \SpecialChar ~
10652 out (_IoPort),a 
10653 \layout Subsubsection
10654
10655 banked sfr
10656 \begin_inset LatexCommand \index{sfr}
10657
10658 \end_inset 
10659
10660
10661 \begin_inset LatexCommand \index{\_\_sfr}
10662
10663 \end_inset 
10664
10665  (in/out to 16-bit addresses)
10666 \layout Standard
10667
10668 The keyword 
10669 \emph on 
10670 banked
10671 \emph default 
10672  is used to support 16 bit addresses in I/O memory e.g.:
10673 \layout Verse
10674
10675
10676 \family typewriter 
10677 sfr banked at
10678 \begin_inset LatexCommand \index{at}
10679
10680 \end_inset 
10681
10682
10683 \begin_inset LatexCommand \index{\_\_at}
10684
10685 \end_inset 
10686
10687  0x123 IoPort; 
10688 \layout Standard
10689
10690 Writing 0x01 to this variable generates the assembly code:
10691 \layout Verse
10692
10693
10694 \family typewriter 
10695 01 23 01\SpecialChar ~
10696 \SpecialChar ~
10697 \SpecialChar ~
10698 ld bc,#_IoPort
10699 \newline 
10700 3E 01\SpecialChar ~
10701 \SpecialChar ~
10702 \SpecialChar ~
10703 \SpecialChar ~
10704 \SpecialChar ~
10705 \SpecialChar ~
10706 ld a,#0x01 
10707 \newline 
10708 ED 79\SpecialChar ~
10709 \SpecialChar ~
10710 \SpecialChar ~
10711 \SpecialChar ~
10712 \SpecialChar ~
10713 \SpecialChar ~
10714 out (c),a 
10715 \layout Subsubsection
10716
10717 sfr
10718 \begin_inset LatexCommand \index{sfr}
10719
10720 \end_inset 
10721
10722
10723 \begin_inset LatexCommand \index{\_\_sfr}
10724
10725 \end_inset 
10726
10727  (in0/out0 to 8 bit addresses on Z180
10728 \begin_inset LatexCommand \index{Z180}
10729
10730 \end_inset 
10731
10732 /HD64180
10733 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10734
10735 \end_inset 
10736
10737 )
10738 \layout Standard
10739 \added_space_bottom bigskip 
10740 The compiler option -
10741 \begin_inset ERT
10742 status Collapsed
10743
10744 \layout Standard
10745
10746 \backslash 
10747 /
10748 \end_inset 
10749
10750 -portmode
10751 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10752
10753 \end_inset 
10754
10755 =180 (80) and a compiler #pragma\SpecialChar ~
10756 portmode
10757 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10758
10759 \end_inset 
10760
10761  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10762 ns 
10763 \family typewriter 
10764 in0/out0
10765 \family default 
10766  instead of 
10767 \family typewriter 
10768 in/out
10769 \family default 
10770 .
10771  If you include the file z180.h this will be set automatically.
10772 \layout Subsection
10773
10774 HC08 Storage Class
10775 \begin_inset LatexCommand \index{HC08!Storage class}
10776
10777 \end_inset 
10778
10779  Language Extensions
10780 \layout Subsubsection
10781
10782 data
10783 \begin_inset LatexCommand \index{data (hc08 storage class)}
10784
10785 \end_inset 
10786
10787
10788 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10789
10790 \end_inset 
10791
10792  
10793 \layout Standard
10794
10795 The data storage class declares a variable that resides in the first 256
10796  bytes of memory (the direct page).
10797  The HC08
10798 \begin_inset LatexCommand \index{HC08}
10799
10800 \end_inset 
10801
10802  is most efficient at accessing variables (especially pointers) stored here.
10803 \layout Subsubsection
10804
10805 xdata
10806 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10807
10808 \end_inset 
10809
10810
10811 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10812
10813 \end_inset 
10814
10815  
10816 \layout Standard
10817 \added_space_bottom bigskip 
10818 The xdata storage class declares a variable that can reside anywhere in
10819  memory.
10820  This is the default if no storage class is specified.
10821  
10822 \layout Section
10823
10824 Absolute Addressing
10825 \begin_inset LatexCommand \index{Absolute addressing}
10826
10827 \end_inset 
10828
10829
10830 \layout Standard
10831
10832 Data items can be assigned an absolute address with the 
10833 \emph on 
10834 at
10835 \begin_inset LatexCommand \index{at}
10836
10837 \end_inset 
10838
10839
10840 \begin_inset LatexCommand \index{\_\_at}
10841
10842 \end_inset 
10843
10844  <address>
10845 \emph default 
10846  keyword, in addition to a storage class, e.g.:
10847 \layout Verse
10848
10849
10850 \family typewriter 
10851 xdata
10852 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10853
10854 \end_inset 
10855
10856
10857 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10858
10859 \end_inset 
10860
10861  at
10862 \begin_inset LatexCommand \index{at}
10863
10864 \end_inset 
10865
10866
10867 \begin_inset LatexCommand \index{\_\_at}
10868
10869 \end_inset 
10870
10871  0x7ffe unsigned int chksum;
10872 \layout Standard
10873
10874 or, better conforming to ISO/IEC 9899 C:
10875 \layout Verse
10876
10877
10878 \family typewriter 
10879 __xdata __at (0x7ffe) unsigned int chksum;
10880 \layout Standard
10881
10882 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10883  of the external ram.
10884  The compiler does 
10885 \emph on 
10886 not
10887 \emph default 
10888  reserve any space for variables declared in this way
10889 \begin_inset Marginal
10890 collapsed true
10891
10892 \layout Standard
10893
10894
10895 \series bold 
10896 \SpecialChar ~
10897 !
10898 \end_inset 
10899
10900  (they are implemented with an equate in the assembler).
10901  Thus it is left to the programmer to make sure there are no overlaps with
10902  other variables that are declared without the absolute address.
10903  The assembler listing file (.lst
10904 \begin_inset LatexCommand \index{<file>.lst}
10905
10906 \end_inset 
10907
10908 ) and the linker output files (.rst
10909 \begin_inset LatexCommand \index{<file>.rst}
10910
10911 \end_inset 
10912
10913 ) and (.map
10914 \begin_inset LatexCommand \index{<file>.map}
10915
10916 \end_inset 
10917
10918 ) are good places to look for such overlaps.
10919  Variables with an absolute address are 
10920 \emph on 
10921 not
10922 \begin_inset Marginal
10923 collapsed true
10924
10925 \layout Standard
10926
10927
10928 \series bold 
10929 \SpecialChar ~
10930 !
10931 \end_inset 
10932
10933
10934 \emph default 
10935  initialized
10936 \begin_inset LatexCommand \index{Variable initialization}
10937
10938 \end_inset 
10939
10940 .
10941 \layout Standard
10942
10943 In case of memory mapped I/O devices the keyword 
10944 \emph on 
10945 volatile
10946 \emph default 
10947  has to be used to tell the compiler that accesses might not be removed:
10948 \layout Verse
10949
10950
10951 \family typewriter 
10952 volatile
10953 \begin_inset LatexCommand \index{volatile}
10954
10955 \end_inset 
10956
10957  __xdata
10958 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10959
10960 \end_inset 
10961
10962  __at
10963 \begin_inset LatexCommand \index{at}
10964
10965 \end_inset 
10966
10967  (0x8000) unsigned char PORTA_8255;
10968 \layout Standard
10969
10970 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10971 r) array
10972 \family typewriter 
10973 \size footnotesize 
10974
10975 \begin_inset LatexCommand \index{Aligned array}
10976
10977 \end_inset 
10978
10979
10980 \family default 
10981 \size default 
10982  starts at a block (256 byte) boundary
10983 \begin_inset LatexCommand \index{block boundary}
10984
10985 \end_inset 
10986
10987  (section 
10988 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10989
10990 \end_inset 
10991
10992  has an example).
10993 \newline 
10994 Absolute addresses can be specified for variables in all storage classes,
10995  e.g.:
10996 \layout Verse
10997
10998
10999 \family typewriter 
11000 __bit
11001 \begin_inset LatexCommand \index{bit}
11002
11003 \end_inset 
11004
11005  __at
11006 \begin_inset LatexCommand \index{at}
11007
11008 \end_inset 
11009
11010  (0x02) bvar;
11011 \layout Standard
11012
11013 The above example will allocate the variable at offset 0x02 in the bit-addressab
11014 le space.
11015  There is no real advantage to assigning absolute addresses to variables
11016  in this manner, unless you want strict control over all the variables allocated.
11017  One possible use would be to write hardware portable code.
11018  For example, if you have a routine that uses one or more of the microcontroller
11019  I/O pins, and such pins are different for two different hardwares, you
11020  can declare the I/O pins in your routine using:
11021 \layout Verse
11022
11023
11024 \family typewriter 
11025 extern volatile
11026 \begin_inset LatexCommand \index{volatile}
11027
11028 \end_inset 
11029
11030  __bit MOSI;\SpecialChar ~
11031 \SpecialChar ~
11032 \SpecialChar ~
11033 \SpecialChar ~
11034 /* master out, slave in */
11035 \newline 
11036 extern volatile __bit MISO;\SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 /* master in, slave out */
11041 \newline 
11042 extern volatile __bit MCLK;\SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 /* master clock */
11047 \newline 
11048
11049 \newline 
11050 /* Input and Output of a byte on a 3-wire serial bus.
11051 \newline 
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 If needed adapt polarity of clock, polarity of data and bit order
11056 \newline 
11057 \SpecialChar ~
11058 */
11059 \newline 
11060 unsigned char spi_io(unsigned char out_byte) 
11061 \newline 
11062
11063 \newline 
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 unsigned char i=8;
11069 \newline 
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 do { 
11075 \newline 
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 MOSI = out_byte & 0x80; 
11085 \newline 
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 out_byte <<= 1;
11095 \newline 
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 MCLK = 1; 
11105 \newline 
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 \SpecialChar ~
11110 \SpecialChar ~
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 /* _asm nop _endasm; */\SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 /* for slow peripherals */
11123 \newline 
11124 \SpecialChar ~
11125 \SpecialChar ~
11126 \SpecialChar ~
11127 \SpecialChar ~
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 if(MISO) 
11133 \newline 
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 out_byte += 1; 
11147 \newline 
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 MCLK = 0; 
11157 \newline 
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 \SpecialChar ~
11162 } while(--i);
11163 \newline 
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 return out_byte; 
11169 \newline 
11170 }
11171 \layout Standard
11172
11173 Then, someplace in the code for the first hardware you would use
11174 \layout Verse
11175
11176
11177 \family typewriter 
11178 __bit __at
11179 \begin_inset LatexCommand \index{at}
11180
11181 \end_inset 
11182
11183
11184 \begin_inset LatexCommand \index{\_\_at}
11185
11186 \end_inset 
11187
11188  (0x80) MOSI;\SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 /* I/O port 0, bit 0 */
11193 \newline 
11194 __bit __at (0x81) MISO;\SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 /* I/O port 0, bit 1 */
11199 \newline 
11200 __bit __at (0x82) MCLK;\SpecialChar ~
11201 \SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 /* I/O port 0, bit 2 */
11205 \layout Standard
11206
11207 Similarly, for the second hardware you would use
11208 \layout Verse
11209
11210
11211 \family typewriter 
11212 __bit __at (0x83) MOSI;\SpecialChar ~
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 /* I/O port 0, bit 3 */
11217 \newline 
11218 __bit __at (0x91) MISO;\SpecialChar ~
11219 \SpecialChar ~
11220 \SpecialChar ~
11221 \SpecialChar ~
11222 /* I/O port 1, bit 1 */
11223 \newline 
11224 __bit
11225 \begin_inset LatexCommand \index{bit}
11226
11227 \end_inset 
11228
11229  __at (0x92) MCLK;\SpecialChar ~
11230 \SpecialChar ~
11231 \SpecialChar ~
11232 \SpecialChar ~
11233 /* I/O port 1, bit 2 */
11234 \layout Standard
11235 \added_space_bottom bigskip 
11236 and you can use the same hardware dependent routine without changes, as
11237  for example in a library.
11238  This is somehow similar to sbit, but only one absolute address has to be
11239  specified in the whole project.
11240 \layout Section
11241
11242 Parameters
11243 \begin_inset LatexCommand \index{Parameters}
11244
11245 \end_inset 
11246
11247
11248 \begin_inset LatexCommand \index{function parameter}
11249
11250 \end_inset 
11251
11252  & Local Variables
11253 \begin_inset LatexCommand \index{local variables}
11254
11255 \end_inset 
11256
11257
11258 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11259
11260 \end_inset 
11261
11262
11263 \layout Standard
11264
11265 Automatic (local) variables and parameters to functions can either be placed
11266  on the stack or in data-space.
11267  The default action of the compiler is to place these variables in the internal
11268  RAM (for small model) or external RAM (for large model).
11269  This in fact makes them similar to 
11270 \emph on 
11271 static
11272 \begin_inset LatexCommand \index{static}
11273
11274 \end_inset 
11275
11276
11277 \emph default 
11278  so by default functions are non-reentrant
11279 \begin_inset LatexCommand \index{reentrant}
11280
11281 \end_inset 
11282
11283 .
11284  
11285 \newline 
11286
11287 \newline 
11288 They can be placed on the stack
11289 \begin_inset LatexCommand \index{stack}
11290
11291 \end_inset 
11292
11293  by using the
11294 \emph on 
11295  -
11296 \begin_inset ERT
11297 status Collapsed
11298
11299 \layout Standard
11300
11301 \backslash 
11302 /
11303 \end_inset 
11304
11305 -stack-auto
11306 \begin_inset LatexCommand \index{-\/-stack-auto}
11307
11308 \end_inset 
11309
11310
11311 \emph default 
11312  option, by using 
11313 \emph on 
11314 #pragma\SpecialChar ~
11315 stackauto
11316 \emph default 
11317
11318 \begin_inset LatexCommand \index{\#pragma stackauto}
11319
11320 \end_inset 
11321
11322  or by using the 
11323 \emph on 
11324 reentrant
11325 \begin_inset LatexCommand \index{reentrant}
11326
11327 \end_inset 
11328
11329
11330 \emph default 
11331  keyword in the function declaration, e.g.:
11332 \layout Verse
11333
11334
11335 \family typewriter 
11336 unsigned char foo(char i) __reentrant 
11337 \newline 
11338
11339 \newline 
11340 \SpecialChar ~
11341 \SpecialChar ~
11342 \SpecialChar ~
11343 \SpecialChar ~
11344 ...
11345  
11346 \newline 
11347 }
11348 \layout Standard
11349
11350 Since stack space on 8051 is limited, the 
11351 \emph on 
11352 reentrant 
11353 \emph default 
11354 keyword or the
11355 \emph on 
11356  -
11357 \begin_inset ERT
11358 status Collapsed
11359
11360 \layout Standard
11361
11362 \backslash 
11363 /
11364 \end_inset 
11365
11366 -stack-auto
11367 \emph default 
11368  option should be used sparingly.
11369  Note that the reentrant keyword just means that the parameters & local
11370  variables will be allocated to the stack, it 
11371 \emph on 
11372 does not
11373 \emph default 
11374  mean that the function is register bank
11375 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11376
11377 \end_inset 
11378
11379  independent.
11380 \newline 
11381
11382 \newline 
11383 Local variables
11384 \begin_inset LatexCommand \index{local variables}
11385
11386 \end_inset 
11387
11388  can be assigned storage classes and absolute
11389 \begin_inset LatexCommand \index{Absolute addressing}
11390
11391 \end_inset 
11392
11393  addresses, e.g.: 
11394 \layout Verse
11395
11396
11397 \family typewriter 
11398 unsigned char foo() 
11399 \newline 
11400 {
11401 \newline 
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 __xdata unsigned char i;
11407 \newline 
11408 \SpecialChar ~
11409 \SpecialChar ~
11410 \SpecialChar ~
11411 \SpecialChar ~
11412 __bit bvar;
11413 \newline 
11414 \SpecialChar ~
11415 \SpecialChar ~
11416 \SpecialChar ~
11417 \SpecialChar ~
11418 __data __at
11419 \begin_inset LatexCommand \index{at}
11420
11421 \end_inset 
11422
11423  (0x31) unsigned char j;
11424 \newline 
11425 \SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 ...
11430  
11431 \newline 
11432 }
11433 \layout Standard
11434
11435 In the above example the variable 
11436 \emph on 
11437 i
11438 \emph default 
11439  will be allocated in the external ram, 
11440 \emph on 
11441 bvar
11442 \emph default 
11443  in bit addressable space and
11444 \emph on 
11445  j
11446 \emph default 
11447  in internal ram.
11448  When compiled with 
11449 \emph on 
11450 -
11451 \begin_inset ERT
11452 status Collapsed
11453
11454 \layout Standard
11455
11456 \backslash 
11457 /
11458 \end_inset 
11459
11460 -stack-auto
11461 \emph default 
11462  or when a function is declared as 
11463 \emph on 
11464 reentrant
11465 \emph default 
11466  this should only be done for static variables.
11467 \layout Standard
11468
11469 Parameters
11470 \begin_inset LatexCommand \index{function parameter}
11471
11472 \end_inset 
11473
11474  however are not allowed any storage class
11475 \begin_inset LatexCommand \index{Storage class}
11476
11477 \end_inset 
11478
11479 , (storage classes for parameters will be ignored), their allocation is
11480  governed by the memory model in use, and the reentrancy options.
11481 \layout Standard
11482
11483 It is however allowed to use bit parameters in reentrant functions and also
11484  non-static local bit variables are supported.
11485  Efficient use is limited to 8 semi-bitregisters in bit space.
11486  They are pushed and popped to stack
11487 \begin_inset LatexCommand \index{stack}
11488
11489 \end_inset 
11490
11491  as a single byte just like the normal registers.
11492 \layout Section
11493
11494 Overlaying
11495 \begin_inset LatexCommand \label{sub:Overlaying}
11496
11497 \end_inset 
11498
11499
11500 \begin_inset LatexCommand \index{Overlaying}
11501
11502 \end_inset 
11503
11504
11505 \layout Standard
11506
11507 For non-reentrant
11508 \begin_inset LatexCommand \index{reentrant}
11509
11510 \end_inset 
11511
11512  functions SDCC will try to reduce internal ram space usage by overlaying
11513  parameters and local variables of a function (if possible).
11514  Parameters and local variables
11515 \begin_inset LatexCommand \index{local variables}
11516
11517 \end_inset 
11518
11519  of a function will be allocated to an overlayable segment if the function
11520  has 
11521 \emph on 
11522 no other function calls and the function is non-reentrant and the memory
11523  model
11524 \begin_inset LatexCommand \index{Memory model}
11525
11526 \end_inset 
11527
11528  is small.
11529
11530 \emph default 
11531  If an explicit storage class
11532 \begin_inset LatexCommand \index{Storage class}
11533
11534 \end_inset 
11535
11536  is specified for a local variable, it will NOT be overlayed.
11537 \layout Standard
11538
11539 Note that the compiler (not the linkage editor) makes the decision for overlayin
11540 g the data items.
11541  Functions that are called from an interrupt service routine
11542 \begin_inset Marginal
11543 collapsed true
11544
11545 \layout Standard
11546
11547
11548 \series bold 
11549 !
11550 \end_inset 
11551
11552  should be preceded by a #pragma\SpecialChar ~
11553 nooverlay
11554 \begin_inset LatexCommand \index{\#pragma nooverlay}
11555
11556 \end_inset 
11557
11558  if they are not reentrant.
11559 \layout Standard
11560
11561 Also note that the compiler does not do any processing of inline assembler
11562  code, so the compiler might incorrectly assign local variables and parameters
11563  of a function into the overlay segment if the inline assembler code calls
11564  other c-functions that might use the overlay.
11565  In that case the #pragma\SpecialChar ~
11566 nooverlay should be used.
11567 \layout Standard
11568
11569 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11570 tion
11571 \begin_inset LatexCommand \index{Multiplication}
11572
11573 \end_inset 
11574
11575  or division
11576 \begin_inset LatexCommand \index{Division}
11577
11578 \end_inset 
11579
11580  will NOT be overlayed since these are implemented using external functions,
11581  e.g.:
11582 \layout Verse
11583
11584
11585 \family typewriter 
11586 #pragma save 
11587 \newline 
11588 #pragma nooverlay
11589 \begin_inset LatexCommand \index{\#pragma nooverlay}
11590
11591 \end_inset 
11592
11593  
11594 \newline 
11595 void set_error(unsigned char errcd) 
11596 \newline 
11597 {
11598 \newline 
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 \SpecialChar ~
11602 \SpecialChar ~
11603 P3 = errcd;
11604 \newline 
11605
11606 \newline 
11607 #pragma restore 
11608 \newline 
11609
11610 \newline 
11611 void some_isr () __interrupt
11612 \begin_inset LatexCommand \index{interrupt}
11613
11614 \end_inset 
11615
11616  (2)
11617 \newline 
11618 {
11619 \newline 
11620 \SpecialChar ~
11621 \SpecialChar ~
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 ...
11625 \newline 
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 set_error(10);
11631 \newline 
11632 \SpecialChar ~
11633 \SpecialChar ~
11634 \SpecialChar ~
11635 \SpecialChar ~
11636 ...
11637  
11638 \newline 
11639 }
11640 \layout Standard
11641 \added_space_bottom bigskip 
11642 In the above example the parameter 
11643 \emph on 
11644 errcd
11645 \emph default 
11646  for the function 
11647 \emph on 
11648 set_error
11649 \emph default 
11650  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11651 nooverlay was
11652  not present, this could cause unpredictable runtime behavior when called
11653  from an interrupt service routine.
11654  The #pragma\SpecialChar ~
11655 nooverlay ensures that the parameters and local variables for
11656  the function are NOT overlayed.
11657 \layout Section
11658
11659 Interrupt Service Routines
11660 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11661
11662 \end_inset 
11663
11664
11665 \layout Subsection
11666
11667 General Information
11668 \layout Standard
11669
11670 SDCC allows 
11671 \emph on 
11672 i
11673 \emph default 
11674 nterrupt 
11675 \emph on 
11676 s
11677 \emph default 
11678 ervice 
11679 \emph on 
11680 r
11681 \emph default 
11682 outines to be coded in C, with some extended keywords.
11683 \layout Verse
11684
11685
11686 \family typewriter 
11687 void timer_isr (void) __interrupt (1) __using (1) 
11688 \newline 
11689
11690 \newline 
11691 \SpecialChar ~
11692 \SpecialChar ~
11693 \SpecialChar ~
11694 \SpecialChar ~
11695 ...
11696  
11697 \newline 
11698 }
11699 \layout Standard
11700
11701 The optional number following the 
11702 \emph on 
11703 interrupt
11704 \begin_inset LatexCommand \index{interrupt}
11705
11706 \end_inset 
11707
11708
11709 \begin_inset LatexCommand \index{\_\_interrupt}
11710
11711 \end_inset 
11712
11713
11714 \emph default 
11715  keyword is the interrupt number this routine will service.
11716  When present, the compiler will insert a call to this routine in the interrupt
11717  vector table
11718 \begin_inset LatexCommand \index{interrupt vector table}
11719
11720 \end_inset 
11721
11722  for the interrupt number specified.
11723  If you have multiple source files in your project, interrupt service routines
11724  can be present in any of them, but a prototype of the isr MUST be present
11725  or included in the file that contains the function 
11726 \emph on 
11727 main
11728 \emph default 
11729 .
11730  The optional (8051 specific) keyword 
11731 \emph on 
11732 using
11733 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11734
11735 \end_inset 
11736
11737
11738 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11739
11740 \end_inset 
11741
11742
11743 \emph default 
11744  can be used to tell the compiler to use the specified register bank when
11745  generating code for this function.
11746  
11747 \newline 
11748 Interrupt service routines open the door for some very interesting bugs:
11749 \layout Subsubsection
11750
11751
11752 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11753
11754 \end_inset 
11755
11756 Common interrupt pitfall: variable not declared 
11757 \emph on 
11758 volatile
11759 \layout Standard
11760
11761 If an interrupt service routine changes variables which are accessed by
11762  other functions these variables have to be declared 
11763 \emph on 
11764 volatile
11765 \emph default 
11766
11767 \begin_inset LatexCommand \index{volatile}
11768
11769 \end_inset 
11770
11771 .
11772  See 
11773 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11774
11775 \end_inset 
11776
11777  .
11778 \layout Subsubsection
11779
11780
11781 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11782
11783 \end_inset 
11784
11785 Common interrupt pitfall: 
11786 \emph on 
11787 non-atomic access
11788 \layout Standard
11789
11790 If the access to these variables is not 
11791 \emph on 
11792 atomic
11793 \begin_inset LatexCommand \index{atomic}
11794
11795 \end_inset 
11796
11797
11798 \emph default 
11799  (i.e.
11800  the processor needs more than one instruction for the access and could
11801  be interrupted while accessing the variable) the interrupt must be disabled
11802  during the access to avoid inconsistent data.
11803  
11804 \newline 
11805 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11806  should be protected by disabling interrupts.
11807  You're not automatically on the safe side if you use 8 bit variables though.
11808  We need an example here: f.e.
11809  on the 8051 the harmless looking 
11810 \begin_inset Quotes srd
11811 \end_inset 
11812
11813
11814 \family typewriter 
11815 flags\SpecialChar ~
11816 |=\SpecialChar ~
11817 0x80;
11818 \family default 
11819
11820 \begin_inset Quotes sld
11821 \end_inset 
11822
11823  is not atomic if 
11824 \family typewriter 
11825 flags
11826 \family default 
11827  resides in xdata.
11828  Setting 
11829 \begin_inset Quotes srd
11830 \end_inset 
11831
11832
11833 \family typewriter 
11834 flags\SpecialChar ~
11835 |=\SpecialChar ~
11836 0x40;
11837 \family default 
11838
11839 \begin_inset Quotes sld
11840 \end_inset 
11841
11842  from within an interrupt routine might get lost if the interrupt occurs
11843  at the wrong time.
11844  
11845 \begin_inset Quotes sld
11846 \end_inset 
11847
11848
11849 \family typewriter 
11850 counter\SpecialChar ~
11851 +=\SpecialChar ~
11852 8;
11853 \family default 
11854
11855 \begin_inset Quotes srd
11856 \end_inset 
11857
11858  is not atomic on the 8051 even if 
11859 \family typewriter 
11860 counter
11861 \family default 
11862  is located in data memory.
11863 \newline 
11864 Bugs like these are hard to reproduce and can cause a lot of trouble.
11865  
11866 \layout Subsubsection
11867
11868
11869 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11870
11871 \end_inset 
11872
11873 Common interrupt pitfall: 
11874 \emph on 
11875 stack overflow
11876 \layout Standard
11877
11878 The return address and the registers used in the interrupt service routine
11879  are saved on the stack
11880 \begin_inset LatexCommand \index{stack}
11881
11882 \end_inset 
11883
11884  so there must be sufficient stack space.
11885  If there isn't variables or registers (or even the return address itself)
11886  will be corrupted.
11887  This 
11888 \emph on 
11889 stack overflow
11890 \emph default 
11891
11892 \begin_inset LatexCommand \index{stack overflow}
11893
11894 \end_inset 
11895
11896  is most likely to happen if the interrupt occurs during the 
11897 \begin_inset Quotes sld
11898 \end_inset 
11899
11900 deepest
11901 \begin_inset Quotes srd
11902 \end_inset 
11903
11904  subroutine when the stack is already in use for f.e.
11905  many return addresses.
11906 \layout Subsubsection
11907
11908
11909 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11910
11911 \end_inset 
11912
11913 Common interrupt pitfall: 
11914 \emph on 
11915 use of non-reentrant functions
11916 \layout Standard
11917
11918 A special note here, int (16 bit) and long (32 bit) integer division
11919 \begin_inset LatexCommand \index{Division}
11920
11921 \end_inset 
11922
11923 , multiplication
11924 \begin_inset LatexCommand \index{Multiplication}
11925
11926 \end_inset 
11927
11928  & modulus
11929 \begin_inset LatexCommand \index{Modulus}
11930
11931 \end_inset 
11932
11933  and floating-point
11934 \begin_inset LatexCommand \index{Floating point support}
11935
11936 \end_inset 
11937
11938  operations are implemented using external support routines.
11939  If an interrupt service routine needs to do any of these operations then
11940  the support routines (as mentioned in a following section) will have to
11941  be recompiled using the
11942 \emph on 
11943  -
11944 \begin_inset ERT
11945 status Collapsed
11946
11947 \layout Standard
11948
11949 \backslash 
11950 /
11951 \end_inset 
11952
11953 -stack-auto
11954 \begin_inset LatexCommand \index{-\/-stack-auto}
11955
11956 \end_inset 
11957
11958
11959 \emph default 
11960  option and the source file will need to be compiled using the 
11961 \emph on 
11962 -
11963 \begin_inset ERT
11964 status Collapsed
11965
11966 \layout Standard
11967
11968 \backslash 
11969 /
11970 \end_inset 
11971
11972 -int-long-reent
11973 \emph default 
11974
11975 \begin_inset LatexCommand \index{-\/-int-long-reent}
11976
11977 \end_inset 
11978
11979  compiler option.
11980  
11981 \newline 
11982 Note, the type promotion
11983 \begin_inset LatexCommand \index{type promotion}
11984
11985 \end_inset 
11986
11987  required by ANSI C can cause 16 bit routines to be used
11988 \begin_inset Marginal
11989 collapsed true
11990
11991 \layout Standard
11992
11993
11994 \series bold 
11995 \SpecialChar ~
11996 !
11997 \end_inset 
11998
11999  without the programmer being aware of it.
12000  See f.e.
12001  the cast 
12002 \family typewriter 
12003 (unsigned char)(tail-1)
12004 \family default 
12005  within the if clause in section 
12006 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12007
12008 \end_inset 
12009
12010 .
12011 \layout Standard
12012 \added_space_bottom bigskip 
12013 Calling other functions from an interrupt service routine is not recommended,
12014  avoid it if possible.
12015  Note that when some function is called from an interrupt service routine
12016  it should be preceded by a #pragma\SpecialChar ~
12017 nooverlay
12018 \begin_inset LatexCommand \index{\#pragma nooverlay}
12019
12020 \end_inset 
12021
12022  if it is not reentrant.
12023  Furthermore nonreentrant functions should not be called from the main program
12024  while the interrupt service routine might be active.
12025  They also must not be called from low priority interrupt service routines
12026  while a high priority interrupt service routine might be active.
12027  You could use semaphores or make the function
12028 \emph on 
12029  critical
12030 \emph default 
12031  if all parameters are passed in registers.
12032 \newline 
12033  Also see section 
12034 \begin_inset LatexCommand \ref{sub:Overlaying}
12035
12036 \end_inset 
12037
12038 \SpecialChar ~
12039 about Overlaying and section 
12040 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12041
12042 \end_inset 
12043
12044 \SpecialChar ~
12045 about Functions using private register banks.
12046 \layout Subsection
12047
12048 MCS51/DS390 Interrupt Service Routines
12049 \layout Standard
12050
12051 Interrupt
12052 \begin_inset LatexCommand \index{interrupt}
12053
12054 \end_inset 
12055
12056  numbers and the corresponding address & descriptions for the Standard 8051/8052
12057  are listed below.
12058  SDCC will automatically adjust the 
12059 \begin_inset LatexCommand \index{interrupt vector table}
12060
12061 \end_inset 
12062
12063  to the maximum interrupt number specified.
12064 \newline 
12065
12066 \layout Standard
12067 \align center 
12068
12069 \begin_inset  Tabular
12070 <lyxtabular version="3" rows="9" columns="3">
12071 <features>
12072 <column alignment="center" valignment="top" leftline="true" width="0in">
12073 <column alignment="left" valignment="top" leftline="true" width="0in">
12074 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12075 <row topline="true" bottomline="true">
12076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12077 \begin_inset Text
12078
12079 \layout Standard
12080
12081 Interrupt #
12082 \end_inset 
12083 </cell>
12084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12085 \begin_inset Text
12086
12087 \layout Standard
12088
12089 Description
12090 \end_inset 
12091 </cell>
12092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12093 \begin_inset Text
12094
12095 \layout Standard
12096
12097 Vector Address
12098 \end_inset 
12099 </cell>
12100 </row>
12101 <row topline="true">
12102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12103 \begin_inset Text
12104
12105 \layout Standard
12106
12107 0
12108 \end_inset 
12109 </cell>
12110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12111 \begin_inset Text
12112
12113 \layout Standard
12114
12115 External 0
12116 \end_inset 
12117 </cell>
12118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12119 \begin_inset Text
12120
12121 \layout Standard
12122
12123 0x0003
12124 \end_inset 
12125 </cell>
12126 </row>
12127 <row topline="true">
12128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12129 \begin_inset Text
12130
12131 \layout Standard
12132
12133 1
12134 \end_inset 
12135 </cell>
12136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12137 \begin_inset Text
12138
12139 \layout Standard
12140
12141 Timer 0
12142 \end_inset 
12143 </cell>
12144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12145 \begin_inset Text
12146
12147 \layout Standard
12148
12149 0x000b
12150 \end_inset 
12151 </cell>
12152 </row>
12153 <row topline="true">
12154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12155 \begin_inset Text
12156
12157 \layout Standard
12158
12159 2
12160 \end_inset 
12161 </cell>
12162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12163 \begin_inset Text
12164
12165 \layout Standard
12166
12167 External 1
12168 \end_inset 
12169 </cell>
12170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12171 \begin_inset Text
12172
12173 \layout Standard
12174
12175 0x0013
12176 \end_inset 
12177 </cell>
12178 </row>
12179 <row topline="true">
12180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12181 \begin_inset Text
12182
12183 \layout Standard
12184
12185 3
12186 \end_inset 
12187 </cell>
12188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12189 \begin_inset Text
12190
12191 \layout Standard
12192
12193 Timer 1
12194 \end_inset 
12195 </cell>
12196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12197 \begin_inset Text
12198
12199 \layout Standard
12200
12201 0x001b
12202 \end_inset 
12203 </cell>
12204 </row>
12205 <row topline="true">
12206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12207 \begin_inset Text
12208
12209 \layout Standard
12210
12211 4
12212 \end_inset 
12213 </cell>
12214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12215 \begin_inset Text
12216
12217 \layout Standard
12218
12219 Serial
12220 \end_inset 
12221 </cell>
12222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12223 \begin_inset Text
12224
12225 \layout Standard
12226
12227 0x0023
12228 \end_inset 
12229 </cell>
12230 </row>
12231 <row topline="true">
12232 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12233 \begin_inset Text
12234
12235 \layout Standard
12236
12237 5
12238 \end_inset 
12239 </cell>
12240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12241 \begin_inset Text
12242
12243 \layout Standard
12244
12245 Timer 2 (8052)
12246 \end_inset 
12247 </cell>
12248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12249 \begin_inset Text
12250
12251 \layout Standard
12252
12253 0x002b
12254 \end_inset 
12255 </cell>
12256 </row>
12257 <row topline="true">
12258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12259 \begin_inset Text
12260
12261 \layout Standard
12262
12263 ...
12264 \end_inset 
12265 </cell>
12266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12267 \begin_inset Text
12268
12269 \layout Standard
12270
12271 \end_inset 
12272 </cell>
12273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12274 \begin_inset Text
12275
12276 \layout Standard
12277
12278 ...
12279 \end_inset 
12280 </cell>
12281 </row>
12282 <row topline="true" bottomline="true">
12283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12284 \begin_inset Text
12285
12286 \layout Standard
12287
12288 n
12289 \end_inset 
12290 </cell>
12291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12292 \begin_inset Text
12293
12294 \layout Standard
12295
12296 \end_inset 
12297 </cell>
12298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12299 \begin_inset Text
12300
12301 \layout Standard
12302
12303 0x0003 + 8*n
12304 \end_inset 
12305 </cell>
12306 </row>
12307 </lyxtabular>
12308
12309 \end_inset 
12310
12311
12312 \newline 
12313
12314 \layout Standard
12315
12316 If the interrupt service routine is defined without 
12317 \emph on 
12318 using
12319 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12320
12321 \end_inset 
12322
12323
12324 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12325
12326 \end_inset 
12327
12328
12329 \emph default 
12330  a register bank or with register bank 0 (
12331 \emph on 
12332 using
12333 \emph default 
12334  0), the compiler will save the registers used by itself on the stack upon
12335  entry and restore them at exit, however if such an interrupt service routine
12336  calls another function then the entire register bank will be saved on the
12337  stack.
12338  This scheme may be advantageous for small interrupt service routines which
12339  have low register usage.
12340 \layout Standard
12341 \added_space_bottom bigskip 
12342 If the interrupt service routine is defined to be using a specific register
12343  bank then only 
12344 \emph on 
12345 a, b, dptr
12346 \emph default 
12347  & psw are saved and restored, if such an interrupt service routine calls
12348  another function (using another register bank) then the entire register
12349  bank of the called function will be saved on the stack
12350 \begin_inset LatexCommand \index{stack}
12351
12352 \end_inset 
12353
12354 .
12355  This scheme is recommended for larger interrupt service routines.
12356 \layout Subsection
12357
12358 HC08
12359 \begin_inset LatexCommand \index{HC08}
12360
12361 \end_inset 
12362
12363  Interrupt Service Routines
12364 \layout Standard
12365 \added_space_bottom bigskip 
12366 Since the number of interrupts
12367 \begin_inset LatexCommand \index{HC08!interrupt}
12368
12369 \end_inset 
12370
12371  available is chip specific and the interrupt vector table always ends at
12372  the last byte of memory, the interrupt numbers corresponds to the interrupt
12373  vectors in reverse order of address.
12374  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12375  2 will use the interrupt vector at 0xfffa, and so on.
12376  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12377  this way; instead see section 
12378 \begin_inset LatexCommand \ref{sub:Startup-Code}
12379
12380 \end_inset 
12381
12382  for details on customizing startup.
12383 \layout Subsection
12384
12385 Z80 Interrupt Service Routines
12386 \layout Standard
12387
12388 The Z80
12389 \begin_inset LatexCommand \index{Z80}
12390
12391 \end_inset 
12392
12393  uses several different methods for determining the correct interrupt
12394 \begin_inset LatexCommand \index{Z80!interrupt}
12395
12396 \end_inset 
12397
12398  vector depending on the hardware implementation.
12399  Therefore, SDCC ignores the optional interrupt number and does not attempt
12400  to generate an interrupt vector table.
12401 \layout Standard
12402
12403 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12404  instruction to return from the interrupt.
12405  To write an interrupt handler for the non-maskable interrupt, which needs
12406  a RETN instruction instead, add the 
12407 \emph on 
12408 critical
12409 \emph default 
12410  keyword:
12411 \layout Verse
12412
12413
12414 \family typewriter 
12415 void nmi_isr (void) critical interrupt
12416 \newline 
12417
12418 \newline 
12419 \SpecialChar ~
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 ...
12424  
12425 \newline 
12426 }
12427 \layout Standard
12428 \added_space_bottom bigskip 
12429 However if you need to create a non-interruptable interrupt service routine
12430  you would also require the 
12431 \emph on 
12432 critical
12433 \emph default 
12434  keyword.
12435  To distinguish between this and an nmi_isr you must provide an interrupt
12436  number.
12437 \layout Section
12438
12439 Enabling and Disabling Interrupts
12440 \layout Subsection
12441
12442 Critical Functions and Critical Statements
12443 \layout Standard
12444
12445 A special keyword may be associated with a block or a function declaring
12446  it as 
12447 \emph on 
12448 critical
12449 \emph default 
12450 .
12451  SDCC will generate code to disable all interrupts
12452 \begin_inset LatexCommand \index{interrupt}
12453
12454 \end_inset 
12455
12456  upon entry to a critical function and restore the interrupt enable to the
12457  previous state before returning.
12458  Nesting critical functions will need one additional byte on the stack
12459 \begin_inset LatexCommand \index{stack}
12460
12461 \end_inset 
12462
12463  for each call.
12464 \layout Verse
12465
12466
12467 \family typewriter 
12468 int foo () __critical
12469 \begin_inset LatexCommand \index{critical}
12470
12471 \end_inset 
12472
12473
12474 \begin_inset LatexCommand \index{\_\_critical}
12475
12476 \end_inset 
12477
12478  
12479 \newline 
12480
12481 \newline 
12482 \SpecialChar ~
12483 \SpecialChar ~
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 ...
12487  
12488 \newline 
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 \SpecialChar ~
12492 \SpecialChar ~
12493 ...
12494  
12495 \newline 
12496 }
12497 \layout Standard
12498
12499 The critical attribute maybe used with other attributes like 
12500 \emph on 
12501 reentrant.
12502 \emph default 
12503
12504 \newline 
12505 The keyword 
12506 \emph on 
12507 critical
12508 \emph default 
12509  may also be used to disable interrupts more locally:
12510 \layout Verse
12511
12512
12513 \family typewriter 
12514 __critical{ i++; }
12515 \layout Standard
12516
12517 More than one statement could have been included in the block.
12518 \layout Subsection
12519
12520 Enabling and Disabling Interrupts directly
12521 \layout Standard
12522
12523 Interrupts
12524 \begin_inset LatexCommand \index{interrupt}
12525
12526 \end_inset 
12527
12528  can also be disabled and enabled directly (8051):
12529 \layout Verse
12530
12531
12532 \family typewriter 
12533 EA = 0;\SpecialChar ~
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 \SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 or:\SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 EA_SAVE = EA;
12557 \layout Verse
12558
12559
12560 \family typewriter 
12561 ...\SpecialChar ~
12562 \SpecialChar ~
12563 \SpecialChar ~
12564 \SpecialChar ~
12565 \SpecialChar ~
12566 \SpecialChar ~
12567 \SpecialChar ~
12568 \SpecialChar ~
12569 \SpecialChar ~
12570 \SpecialChar ~
12571 \SpecialChar ~
12572 \SpecialChar ~
12573 \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 EA = 0;
12592 \layout Verse
12593
12594
12595 \family typewriter 
12596 EA = 1;\SpecialChar ~
12597 \SpecialChar ~
12598 \SpecialChar ~
12599 \SpecialChar ~
12600 \SpecialChar ~
12601 \SpecialChar ~
12602 \SpecialChar ~
12603 \SpecialChar ~
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 ...
12623 \layout Verse
12624
12625
12626 \family typewriter 
12627 \SpecialChar ~
12628 \SpecialChar ~
12629 \SpecialChar ~
12630 \SpecialChar ~
12631 \SpecialChar ~
12632 \SpecialChar ~
12633 \SpecialChar ~
12634 \SpecialChar ~
12635 \SpecialChar ~
12636 \SpecialChar ~
12637 \SpecialChar ~
12638 \SpecialChar ~
12639 \SpecialChar ~
12640 \SpecialChar ~
12641 \SpecialChar ~
12642 \SpecialChar ~
12643 \SpecialChar ~
12644 \SpecialChar ~
12645 \SpecialChar ~
12646 \SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 \SpecialChar ~
12651 \SpecialChar ~
12652 \SpecialChar ~
12653 \SpecialChar ~
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 \SpecialChar ~
12659 \SpecialChar ~
12660 EA = EA_SAVE;
12661 \layout Standard
12662
12663 On other architectures which have seperate opcodes for enabling and disabling
12664  interrupts you might want to make use of defines with inline assembly
12665 \begin_inset LatexCommand \index{Assembler routines}
12666
12667 \end_inset 
12668
12669  (HC08
12670 \begin_inset LatexCommand \index{HC08!interrupt}
12671
12672 \end_inset 
12673
12674 ):
12675 \layout Verse
12676
12677
12678 \family typewriter 
12679 #define CLI _asm
12680 \begin_inset LatexCommand \index{\_asm}
12681
12682 \end_inset 
12683
12684 \SpecialChar ~
12685 \SpecialChar ~
12686 cli\SpecialChar ~
12687 \SpecialChar ~
12688 _endasm
12689 \begin_inset LatexCommand \index{\_endasm}
12690
12691 \end_inset 
12692
12693
12694 \layout Verse
12695
12696
12697 \family typewriter 
12698 #define SEI _asm\SpecialChar ~
12699 \SpecialChar ~
12700 sei\SpecialChar ~
12701 \SpecialChar ~
12702 _endasm; 
12703 \layout Verse
12704
12705
12706 \family typewriter 
12707 ...
12708 \layout Standard
12709
12710 Note: it is sometimes sufficient to disable only a specific interrupt source
12711  like f.e.
12712  a timer or serial interrupt by manipulating an 
12713 \emph on 
12714 interrupt mask
12715 \begin_inset LatexCommand \index{interrupt mask}
12716
12717 \end_inset 
12718
12719
12720 \emph default 
12721  register.
12722  
12723 \layout Standard
12724
12725 Usually the time during which interrupts are disabled should be kept as
12726  short as possible.
12727  This minimizes both 
12728 \emph on 
12729 interrupt latency
12730 \emph default 
12731
12732 \begin_inset LatexCommand \index{interrupt latency}
12733
12734 \end_inset 
12735
12736  (the time between the occurrence of the interrupt and the execution of
12737  the first code in the interrupt routine) and 
12738 \emph on 
12739 interrupt jitter
12740 \emph default 
12741
12742 \begin_inset LatexCommand \index{interrupt jitter}
12743
12744 \end_inset 
12745
12746  (the difference between the shortest and the longest interrupt latency).
12747  These really are something different, f.e.
12748  a serial interrupt has to be served before its buffer overruns so it cares
12749  for the maximum interrupt latency, whereas it does not care about jitter.
12750  On a loudspeaker driven via a digital to analog converter which is fed
12751  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12752  a much smaller jitter will be very audible.
12753 \layout Standard
12754
12755 You can reenable interrupts within an interrupt routine and on some architecture
12756 s you can make use of two (or more) levels of 
12757 \emph on 
12758 interrupt priorities
12759 \emph default 
12760
12761 \begin_inset LatexCommand \index{interrupt priority}
12762
12763 \end_inset 
12764
12765 .
12766  On some architectures which don't support interrupt priorities these can
12767  be implemented by manipulating the interrupt mask and reenabling interrupts
12768  within the interrupt routine.
12769  Check there is sufficient space on the stack
12770 \begin_inset LatexCommand \index{stack}
12771
12772 \end_inset 
12773
12774  and don't add complexity unless you have to.
12775  
12776 \layout Subsection
12777
12778 Semaphore
12779 \begin_inset LatexCommand \index{semaphore}
12780
12781 \end_inset 
12782
12783  locking (mcs51/ds390)
12784 \layout Standard
12785
12786 Some architectures (mcs51/ds390) have an atomic
12787 \begin_inset LatexCommand \index{atomic}
12788
12789 \end_inset 
12790
12791  bit test and
12792 \emph on 
12793  
12794 \emph default 
12795 clear
12796 \emph on 
12797  
12798 \emph default 
12799 instruction.
12800  These type of instructions are typically used in preemptive multitasking
12801  systems, where a routine f.e.
12802  claims the use of a data structure ('acquires a lock
12803 \begin_inset LatexCommand \index{lock}
12804
12805 \end_inset 
12806
12807  on it'), makes some modifications and then releases the lock when the data
12808  structure is consistent again.
12809  The instruction may also be used if interrupt and non-interrupt code have
12810  to compete for a resource.
12811  With the atomic bit test and clear instruction interrupts
12812 \begin_inset LatexCommand \index{interrupt}
12813
12814 \end_inset 
12815
12816  don't have to be disabled for the locking operation.
12817  
12818 \layout Standard
12819
12820 SDCC generates this instruction if the source follows this pattern:
12821 \layout Verse
12822
12823
12824 \family typewriter 
12825 volatile
12826 \begin_inset LatexCommand \index{volatile}
12827
12828 \end_inset 
12829
12830  bit resource_is_free; 
12831 \newline 
12832
12833 \newline 
12834 if (resource_is_free) 
12835 \newline 
12836 \SpecialChar ~
12837 \SpecialChar ~
12838
12839 \newline 
12840 \SpecialChar ~
12841 \SpecialChar ~
12842 \SpecialChar ~
12843 \SpecialChar ~
12844 resource_is_free=0; 
12845 \newline 
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 ...
12851  
12852 \newline 
12853 \SpecialChar ~
12854 \SpecialChar ~
12855 \SpecialChar ~
12856 \SpecialChar ~
12857 resource_is_free=1;
12858 \newline 
12859 \SpecialChar ~
12860 \SpecialChar ~
12861
12862 \layout Standard
12863
12864 Note, mcs51 and ds390 support only an atomic
12865 \begin_inset LatexCommand \index{atomic}
12866
12867 \end_inset 
12868
12869  bit test and 
12870 \emph on 
12871 clear
12872 \emph default 
12873  instruction (as opposed to atomic bit test and 
12874 \emph on 
12875 set).
12876 \layout Section
12877
12878 Functions using private register banks
12879 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12880
12881 \end_inset 
12882
12883  (mcs51/ds390)
12884 \layout Standard
12885
12886 Some architectures have support for quickly changing register sets.
12887  SDCC supports this feature with the 
12888 \emph on 
12889 using
12890 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12891
12892 \end_inset 
12893
12894
12895 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12896
12897 \end_inset 
12898
12899
12900 \emph default 
12901  attribute (which tells the compiler to use a register bank
12902 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12903
12904 \end_inset 
12905
12906  other than the default bank zero).
12907  It should only be applied to 
12908 \emph on 
12909 interrupt
12910 \begin_inset LatexCommand \index{interrupt}
12911
12912 \end_inset 
12913
12914
12915 \emph default 
12916  functions (see footnote below).
12917  This will in most circumstances make the generated ISR code more efficient
12918  since it will not have to save registers on the stack.
12919 \layout Standard
12920
12921 The 
12922 \emph on 
12923 using
12924 \emph default 
12925  attribute will have no effect on the generated code for a 
12926 \emph on 
12927 non-interrupt
12928 \emph default 
12929  function (but may occasionally be useful anyway
12930 \begin_inset Foot
12931 collapsed false
12932
12933 \layout Standard
12934
12935 possible exception: if a function is called ONLY from 'interrupt' functions
12936  using a particular bank, it can be declared with the same 'using' attribute
12937  as the calling 'interrupt' functions.
12938  For instance, if you have several ISRs using bank one, and all of them
12939  call memcpy(), it might make sense to create a specialized version of memcpy()
12940  'using 1', since this would prevent the ISR from having to save bank zero
12941  to the stack on entry and switch to bank zero before calling the function
12942 \end_inset 
12943
12944 ).
12945 \newline 
12946
12947 \emph on 
12948 (pending: Note, nowadays the 
12949 \emph default 
12950 using
12951 \emph on 
12952  attribute has an effect on
12953 \emph default 
12954  
12955 \emph on 
12956 the generated code for a 
12957 \emph default 
12958 non-interrupt
12959 \emph on 
12960  function
12961 \emph default 
12962 .
12963 \emph on 
12964 )
12965 \layout Standard
12966
12967 An 
12968 \emph on 
12969 interrupt
12970 \emph default 
12971  function using a non-zero bank will assume that it can trash that register
12972  bank, and will not save it.
12973  Since high-priority interrupts
12974 \begin_inset LatexCommand \index{interrupts}
12975
12976 \end_inset 
12977
12978
12979 \begin_inset LatexCommand \index{interrupt priority}
12980
12981 \end_inset 
12982
12983  can interrupt low-priority ones on the 8051 and friends, this means that
12984  if a high-priority ISR 
12985 \emph on 
12986 using
12987 \emph default 
12988  a particular bank occurs while processing a low-priority ISR 
12989 \emph on 
12990 using
12991 \emph default 
12992  the same bank, terrible and bad things can happen.
12993  To prevent this, no single register bank should be 
12994 \emph on 
12995 used
12996 \emph default 
12997  by both a high priority and a low priority ISR.
12998  This is probably most easily done by having all high priority ISRs use
12999  one bank and all low priority ISRs use another.
13000  If you have an ISR which can change priority at runtime, you're on your
13001  own: I suggest using the default bank zero and taking the small performance
13002  hit.
13003 \layout Standard
13004 \added_space_bottom bigskip 
13005 It is most efficient if your ISR calls no other functions.
13006  If your ISR must call other functions, it is most efficient if those functions
13007  use the same bank as the ISR (see note 1 below); the next best is if the
13008  called functions use bank zero.
13009  It is very inefficient to call a function using a different, non-zero bank
13010  from an ISR.
13011  
13012 \layout Section
13013
13014 Startup Code
13015 \begin_inset LatexCommand \label{sub:Startup-Code}
13016
13017 \end_inset 
13018
13019
13020 \begin_inset LatexCommand \index{Startup code}
13021
13022 \end_inset 
13023
13024
13025 \layout Subsection
13026
13027 MCS51/DS390 Startup Code
13028 \layout Standard
13029
13030 The compiler inserts a call to the C routine 
13031 \emph on 
13032 _sdcc_external_startup()
13033 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13034
13035 \end_inset 
13036
13037
13038 \series bold 
13039 \emph default 
13040  
13041 \series default 
13042 at the start of the CODE area.
13043  This routine is in the runtime library
13044 \begin_inset LatexCommand \index{Runtime library}
13045
13046 \end_inset 
13047
13048 .
13049  By default this routine returns 0, if this routine returns a non-zero value,
13050  the static & global variable initialization will be skipped and the function
13051  main will be invoked.
13052  Otherwise static & global variables will be initialized before the function
13053  main is invoked.
13054  You could add a 
13055 \emph on 
13056 _sdcc_external_startup()
13057 \emph default 
13058  routine to your program to override the default if you need to setup hardware
13059  or perform some other critical operation prior to static & global variable
13060  initialization
13061 \begin_inset LatexCommand \index{Variable initialization}
13062
13063 \end_inset 
13064
13065 .
13066  On some mcs51 variants xdata
13067 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13068
13069 \end_inset 
13070
13071  memory has to be explicitly enabled before it can be accessed or if the
13072  watchdog
13073 \begin_inset LatexCommand \index{watchdog}
13074
13075 \end_inset 
13076
13077  needs to be disabled, this is the place to do it.
13078  The startup code clears all internal data memory, 256 bytes by default,
13079  but from 0 to n-1 if 
13080 \emph on 
13081 -
13082 \begin_inset ERT
13083 status Collapsed
13084
13085 \layout Standard
13086
13087 \backslash 
13088 /
13089 \end_inset 
13090
13091 -iram-size
13092 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13093
13094 \end_inset 
13095
13096 n
13097 \emph default 
13098  is used.
13099  (recommended for Chipcon CC1010).
13100 \layout Standard
13101 \added_space_bottom bigskip 
13102 See also the compiler options 
13103 \emph on 
13104 -
13105 \begin_inset ERT
13106 status Collapsed
13107
13108 \layout Standard
13109
13110 \backslash 
13111 /
13112 \end_inset 
13113
13114 -no-xinit
13115 \emph default 
13116 -
13117 \emph on 
13118 opt
13119 \emph default 
13120
13121 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13122
13123 \end_inset 
13124
13125
13126 \emph on 
13127 -
13128 \begin_inset ERT
13129 status Collapsed
13130
13131 \layout Standard
13132
13133 \backslash 
13134 /
13135 \end_inset 
13136
13137 -main-return
13138 \emph default 
13139
13140 \begin_inset LatexCommand \index{-\/-main-return}
13141
13142 \end_inset 
13143
13144  and section 
13145 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13146
13147 \end_inset 
13148
13149  about MCS51-variants.
13150 \layout Subsection
13151
13152 HC08 Startup Code
13153 \layout Standard
13154 \added_space_bottom bigskip 
13155 The HC08
13156 \begin_inset LatexCommand \index{HC08}
13157
13158 \end_inset 
13159
13160  startup code follows the same scheme as the MCS51 startup code.
13161 \layout Subsection
13162
13163 Z80 Startup Code
13164 \layout Standard
13165 \added_space_bottom bigskip 
13166 On the Z80
13167 \begin_inset LatexCommand \index{Z80}
13168
13169 \end_inset 
13170
13171  the startup code is inserted by linking with crt0.o which is generated from
13172  sdcc/device/lib/z80/crt0.s.
13173  If you need a different startup code you can use the compiler option 
13174 \emph on 
13175 -
13176 \series bold 
13177 \emph default 
13178
13179 \begin_inset ERT
13180 status Collapsed
13181
13182 \layout Standard
13183
13184 \backslash 
13185 /
13186 \end_inset 
13187
13188
13189 \series default 
13190 \emph on 
13191 -no-std-crt0
13192 \emph default 
13193
13194 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13195
13196 \end_inset 
13197
13198  and provide your own crt0.o.
13199  
13200 \layout Section
13201
13202 Inline Assembler Code
13203 \begin_inset LatexCommand \index{Assembler routines}
13204
13205 \end_inset 
13206
13207
13208 \layout Subsection
13209
13210 A Step by Step Introduction
13211 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13212
13213 \end_inset 
13214
13215
13216 \layout Standard
13217
13218 Starting from a small snippet of c-code this example shows for the MCS51
13219  how to use inline assembly, access variables, a function parameter and
13220  an array in xdata memory.
13221  The example uses an MCS51 here but is easily adapted for other architectures.
13222  This is a buffer routine which should be optimized:
13223 \layout Verse
13224
13225
13226 \family typewriter 
13227 \size footnotesize 
13228 unsigned char __far
13229 \begin_inset LatexCommand \index{far (storage class)}
13230
13231 \end_inset 
13232
13233
13234 \begin_inset LatexCommand \index{\_\_far (storage class)}
13235
13236 \end_inset 
13237
13238  __at
13239 \begin_inset LatexCommand \index{at}
13240
13241 \end_inset 
13242
13243
13244 \begin_inset LatexCommand \index{\_\_at}
13245
13246 \end_inset 
13247
13248 (0x7f00) buf[0x100];
13249 \begin_inset LatexCommand \index{Aligned array}
13250
13251 \end_inset 
13252
13253
13254 \newline 
13255 unsigned char head, tail;\SpecialChar ~
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 /* if interrupts
13273 \begin_inset LatexCommand \index{interrupt}
13274
13275 \end_inset 
13276
13277  are involved see
13278 \newline 
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 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 \SpecialChar ~
13306 \SpecialChar ~
13307 \SpecialChar ~
13308 \SpecialChar ~
13309 \SpecialChar ~
13310 \SpecialChar ~
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 \SpecialChar ~
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 \SpecialChar ~
13324 section 
13325 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13326
13327 \end_inset 
13328
13329  about
13330 \series bold 
13331  volatile
13332 \series default 
13333  */
13334 \newline 
13335
13336 \newline 
13337 void to_buffer( unsigned char c ) 
13338 \newline 
13339 {
13340 \newline 
13341 \SpecialChar ~
13342 \SpecialChar ~
13343 \SpecialChar ~
13344 \SpecialChar ~
13345 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13346 /* cast 
13347 \series bold 
13348 needed
13349 \series default 
13350  to avoid promotion
13351 \begin_inset LatexCommand \index{promotion to signed int}
13352
13353 \end_inset 
13354
13355
13356 \begin_inset LatexCommand \index{type promotion}
13357
13358 \end_inset 
13359
13360  to integer */
13361 \begin_inset Marginal
13362 collapsed true
13363
13364 \layout Standard
13365
13366
13367 \series bold 
13368 \SpecialChar ~
13369 !
13370 \end_inset 
13371
13372
13373 \newline 
13374 \SpecialChar ~
13375 \SpecialChar ~
13376 \SpecialChar ~
13377 \SpecialChar ~
13378 \SpecialChar ~
13379 \SpecialChar ~
13380 \SpecialChar ~
13381 \SpecialChar ~
13382 buf[ head++ ] = c;\SpecialChar ~
13383 \SpecialChar ~
13384 \SpecialChar ~
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 \SpecialChar ~
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 \SpecialChar ~
13398 /* access to a 256 byte aligned array */
13399 \newline 
13400
13401 \layout Standard
13402
13403 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13404  then a corresponding buffer.asm file is generated.
13405  We define a new function 
13406 \family typewriter 
13407 to_buffer_asm()
13408 \family default 
13409  in file buffer.c in which we cut and paste the generated code, removing
13410  unwanted comments and some ':'.
13411  Then add 
13412 \begin_inset Quotes sld
13413 \end_inset 
13414
13415 _asm
13416 \begin_inset Quotes srd
13417 \end_inset 
13418
13419  and 
13420 \begin_inset Quotes sld
13421 \end_inset 
13422
13423 _endasm;
13424 \begin_inset Quotes srd
13425 \end_inset 
13426
13427  to the beginning and the end of the function body:
13428 \layout Verse
13429
13430
13431 \family typewriter 
13432 \size footnotesize 
13433 /* With a cut and paste from the .asm file, we have something to start with.
13434 \newline 
13435 \SpecialChar ~
13436 \SpecialChar ~
13437 \SpecialChar ~
13438 The function is not yet OK! (registers aren't saved) */ 
13439 \newline 
13440 void to_buffer_asm( unsigned char c ) 
13441 \newline 
13442
13443 \newline 
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 _asm
13449 \begin_inset LatexCommand \index{\_asm}
13450
13451 \end_inset 
13452
13453
13454 \begin_inset LatexCommand \index{\_\_asm}
13455
13456 \end_inset 
13457
13458
13459 \newline 
13460 \SpecialChar ~
13461 \SpecialChar ~
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 mov\SpecialChar ~
13465 \SpecialChar ~
13466 r2,dpl 
13467 \newline 
13468 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13469 /* cast 
13470 \series bold 
13471 needed
13472 \series default 
13473  to avoid promotion
13474 \begin_inset LatexCommand \index{promotion to signed int}
13475
13476 \end_inset 
13477
13478
13479 \begin_inset LatexCommand \index{type promotion}
13480
13481 \end_inset 
13482
13483  to integer */
13484 \newline 
13485 \SpecialChar ~
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 mov\SpecialChar ~
13490 \SpecialChar ~
13491 a,_tail 
13492 \newline 
13493 \SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 \SpecialChar ~
13497 dec\SpecialChar ~
13498 \SpecialChar ~
13499
13500 \newline 
13501 \SpecialChar ~
13502 \SpecialChar ~
13503 \SpecialChar ~
13504 \SpecialChar ~
13505 mov\SpecialChar ~
13506 \SpecialChar ~
13507 r3,a 
13508 \newline 
13509 \SpecialChar ~
13510 \SpecialChar ~
13511 \SpecialChar ~
13512 \SpecialChar ~
13513 mov\SpecialChar ~
13514 \SpecialChar ~
13515 a,_head 
13516 \newline 
13517 \SpecialChar ~
13518 \SpecialChar ~
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 cjne a,ar3,00106$ 
13522 \newline 
13523 \SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 \SpecialChar ~
13527 ret
13528 \newline 
13529 00106$: 
13530 \newline 
13531 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13532 \begin_inset LatexCommand \index{Aligned array}
13533
13534 \end_inset 
13535
13536
13537 \newline 
13538 \SpecialChar ~
13539 \SpecialChar ~
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 mov\SpecialChar ~
13543 \SpecialChar ~
13544 r3,_head 
13545 \newline 
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 inc\SpecialChar ~
13551 \SpecialChar ~
13552 _head 
13553 \newline 
13554 \SpecialChar ~
13555 \SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 mov\SpecialChar ~
13559 \SpecialChar ~
13560 dpl,r3 
13561 \newline 
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 mov\SpecialChar ~
13567 \SpecialChar ~
13568 dph,#(_buf >> 8) 
13569 \newline 
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 mov\SpecialChar ~
13575 \SpecialChar ~
13576 a,r2 
13577 \newline 
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 movx @dptr,a 
13583 \newline 
13584 00103$: 
13585 \newline 
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 ret
13591 \newline 
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 \SpecialChar ~
13595 \SpecialChar ~
13596 _endasm
13597 \begin_inset LatexCommand \index{\_endasm}
13598
13599 \end_inset 
13600
13601
13602 \begin_inset LatexCommand \index{\_\_endasm}
13603
13604 \end_inset 
13605
13606 ;
13607 \newline 
13608
13609 \layout Standard
13610
13611 The new file buffer.c should compile with only one warning about the unreferenced
13612  function argument 'c'.
13613  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13614  (1) and finally have:
13615 \layout Verse
13616
13617
13618 \family typewriter 
13619 \size footnotesize 
13620 unsigned char __far __at(0x7f00) buf[0x100];
13621 \newline 
13622 unsigned char head, tail;
13623 \newline 
13624 #define USE_ASSEMBLY (1)
13625 \newline 
13626
13627 \newline 
13628 #if !USE_ASSEMBLY
13629 \newline 
13630
13631 \newline 
13632 void to_buffer( unsigned char c )
13633 \newline 
13634 {
13635 \newline 
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 if( head != (unsigned char)(tail-1) )
13641 \newline 
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 \SpecialChar ~
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 buf[ head++ ] = c;
13651 \newline 
13652 }
13653 \newline 
13654
13655 \newline 
13656 #else
13657 \newline 
13658
13659 \newline 
13660 void to_buffer( unsigned char c )
13661 \newline 
13662 {
13663 \newline 
13664 \SpecialChar ~
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 \SpecialChar ~
13668 c; // to avoid warning: unreferenced function argument
13669 \newline 
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 \SpecialChar ~
13674 _asm
13675 \begin_inset LatexCommand \index{\_asm}
13676
13677 \end_inset 
13678
13679
13680 \begin_inset LatexCommand \index{\_\_asm}
13681
13682 \end_inset 
13683
13684
13685 \newline 
13686 \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 \SpecialChar ~
13694 ; save used registers here.
13695  
13696 \newline 
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 \SpecialChar ~
13704 \SpecialChar ~
13705 ; If we were still using r2,r3 we would have to push them here.
13706  
13707 \newline 
13708 ; if( head != (unsigned char)(tail-1) )
13709 \newline 
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 \SpecialChar ~
13718 mov\SpecialChar ~
13719  a,_tail
13720 \newline 
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 \SpecialChar ~
13729 dec\SpecialChar ~
13730  a
13731 \newline 
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 \SpecialChar ~
13739 \SpecialChar ~
13740 xrl\SpecialChar ~
13741  a,_head
13742 \newline 
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 \SpecialChar ~
13751 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13752 \newline 
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 jz\SpecialChar ~
13762 \SpecialChar ~
13763  t_b_end$
13764 \newline 
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 \SpecialChar ~
13770 \SpecialChar ~
13771 \SpecialChar ~
13772 \SpecialChar ~
13773 ;
13774 \newline 
13775 ; buf[ head++ ] = c;
13776 \newline 
13777 \SpecialChar ~
13778 \SpecialChar ~
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 mov\SpecialChar ~
13786  a,dpl \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 ; dpl holds lower byte of function argument
13794 \newline 
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 mov\SpecialChar ~
13804  dpl,_head \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 ; buf is 0x100 byte aligned so head can be used directly
13808 \newline 
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 mov\SpecialChar ~
13818  dph,#(_buf>>8)
13819 \newline 
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 movx @dptr,a
13829 \newline 
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 \SpecialChar ~
13838 inc \SpecialChar ~
13839 _head
13840 \newline 
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 \SpecialChar ~
13849 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13850 \newline 
13851 t_b_end$:
13852 \newline 
13853 \SpecialChar ~
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 \SpecialChar ~
13860 \SpecialChar ~
13861 ; restore used registers here 
13862 \newline 
13863 \SpecialChar ~
13864 \SpecialChar ~
13865 \SpecialChar ~
13866 \SpecialChar ~
13867 _endasm
13868 \begin_inset LatexCommand \index{\_endasm}
13869
13870 \end_inset 
13871
13872
13873 \begin_inset LatexCommand \index{\_\_endasm}
13874
13875 \end_inset 
13876
13877 ;
13878 \newline 
13879 }
13880 \newline 
13881 #endif
13882 \layout Standard
13883
13884 The inline assembler code can contain any valid code understood by the assembler
13885 , this includes any assembler directives and comment lines.
13886  The assembler does not like some characters like ':' or ''' in comments.
13887  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13888 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13889
13890 \end_inset 
13891
13892
13893 \begin_inset LatexCommand \index{Assembler documentation}
13894
13895 \end_inset 
13896
13897  or online at 
13898 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13899
13900 \end_inset 
13901
13902 \SpecialChar ~
13903 .
13904 \layout Standard
13905
13906 The compiler does not do any validation of the code within the 
13907 \family typewriter 
13908 _asm
13909 \begin_inset LatexCommand \index{\_asm}
13910
13911 \end_inset 
13912
13913
13914 \begin_inset LatexCommand \index{\_\_asm}
13915
13916 \end_inset 
13917
13918  ...
13919  _endasm
13920 \size footnotesize 
13921
13922 \begin_inset LatexCommand \index{\_endasm}
13923
13924 \end_inset 
13925
13926
13927 \begin_inset LatexCommand \index{\_\_endasm}
13928
13929 \end_inset 
13930
13931
13932 \size default 
13933 ;
13934 \family default 
13935  keyword pair.
13936  Specifically it will not know which registers are used and thus register
13937  pushing/popping
13938 \begin_inset LatexCommand \index{push/pop}
13939
13940 \end_inset 
13941
13942  has to be done manually.
13943  
13944 \layout Standard
13945
13946 It is recommended that each assembly instruction (including labels) be placed
13947  in a separate line (as the example shows).
13948  When the -
13949 \begin_inset ERT
13950 status Collapsed
13951
13952 \layout Standard
13953
13954 \backslash 
13955 /
13956 \end_inset 
13957
13958 -
13959 \emph on 
13960 peep-asm
13961 \begin_inset LatexCommand \index{-\/-peep-asm}
13962
13963 \end_inset 
13964
13965
13966 \emph default 
13967  command line option is used, the inline assembler code will be passed through
13968  the peephole optimizer
13969 \begin_inset LatexCommand \index{Peephole optimizer}
13970
13971 \end_inset 
13972
13973 .
13974  There are only a few (if any) cases where this option makes sense, it might
13975  cause some unexpected changes in the inline assembler code.
13976  Please go through the peephole optimizer rules defined in file 
13977 \emph on 
13978 SDCCpeeph.def
13979 \emph default 
13980  before using this option.
13981 \layout Subsection
13982
13983 Naked Functions
13984 \begin_inset LatexCommand \label{sub:Naked-Functions}
13985
13986 \end_inset 
13987
13988
13989 \begin_inset LatexCommand \index{Naked functions}
13990
13991 \end_inset 
13992
13993
13994 \layout Standard
13995
13996 A special keyword may be associated with a function declaring it as 
13997 \emph on 
13998 _naked
13999 \begin_inset LatexCommand \index{\_naked}
14000
14001 \end_inset 
14002
14003
14004 \begin_inset LatexCommand \index{\_\_naked}
14005
14006 \end_inset 
14007
14008 .
14009  
14010 \emph default 
14011 The 
14012 \emph on 
14013 _naked
14014 \emph default 
14015  function modifier attribute prevents the compiler from generating prologue
14016 \begin_inset LatexCommand \index{function prologue}
14017
14018 \end_inset 
14019
14020  and epilogue
14021 \begin_inset LatexCommand \index{function epilogue}
14022
14023 \end_inset 
14024
14025  code for that function.
14026  This means that the user is entirely responsible for such things as saving
14027  any registers that may need to be preserved, selecting the proper register
14028  bank, generating the 
14029 \emph on 
14030 return
14031 \emph default 
14032  instruction at the end, etc.
14033  Practically, this means that the contents of the function must be written
14034  in inline assembler.
14035  This is particularly useful for interrupt functions, which can have a large
14036  (and often unnecessary) prologue/epilogue.
14037  For example, compare the code generated by these two functions:
14038 \layout Verse
14039
14040
14041 \family typewriter 
14042 volatile
14043 \begin_inset LatexCommand \index{volatile}
14044
14045 \end_inset 
14046
14047  data unsigned char counter;
14048 \newline 
14049
14050 \newline 
14051 void simpleInterrupt(void) __interrupt
14052 \begin_inset LatexCommand \index{interrupt}
14053
14054 \end_inset 
14055
14056
14057 \begin_inset LatexCommand \index{\_\_interrupt}
14058
14059 \end_inset 
14060
14061  (1)
14062 \newline 
14063 {
14064 \newline 
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 \SpecialChar ~
14069 counter++;
14070 \newline 
14071 }
14072 \newline 
14073
14074 \newline 
14075 void nakedInterrupt(void) __interrupt (2) __naked
14076 \newline 
14077 {
14078 \newline 
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 _asm
14084 \begin_inset LatexCommand \index{\_asm}
14085
14086 \end_inset 
14087
14088
14089 \begin_inset LatexCommand \index{\_\_asm}
14090
14091 \end_inset 
14092
14093
14094 \newline 
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 inc\SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 \SpecialChar ~
14105 \SpecialChar ~
14106 _counter ; does not change flags, no need to save psw
14107 \newline 
14108 \SpecialChar ~
14109 \SpecialChar ~
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 reti\SpecialChar ~
14115 \SpecialChar ~
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 ; MUST explicitly include ret or reti in _naked function.
14119 \newline 
14120 \SpecialChar ~
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 _endasm
14125 \begin_inset LatexCommand \index{\_endasm}
14126
14127 \end_inset 
14128
14129
14130 \begin_inset LatexCommand \index{\_\_endasm}
14131
14132 \end_inset 
14133
14134 ;
14135 \newline 
14136 }
14137 \layout Standard
14138
14139 For an 8051 target, the generated simpleInterrupt looks like:
14140 \layout Verse
14141
14142
14143 \family typewriter 
14144 Note, this is an 
14145 \emph on 
14146 outdated
14147 \emph default 
14148  example, recent versions of SDCC generate
14149 \newline 
14150 the 
14151 \emph on 
14152 same
14153 \emph default 
14154  code for simpleInterrupt() and nakedInterrupt()!
14155 \newline 
14156
14157 \newline 
14158 _simpleInterrupt:
14159 \newline 
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 \SpecialChar ~
14164 push\SpecialChar ~
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 acc
14169 \newline 
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 push\SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 b
14179 \newline 
14180 \SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 push\SpecialChar ~
14185 \SpecialChar ~
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 dpl
14189 \newline 
14190 \SpecialChar ~
14191 \SpecialChar ~
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 push\SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 dph
14199 \newline 
14200 \SpecialChar ~
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 \SpecialChar ~
14204 push\SpecialChar ~
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 psw
14209 \newline 
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 mov\SpecialChar ~
14215 \SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 psw,#0x00
14220 \newline 
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 inc\SpecialChar ~
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 _counter
14231 \newline 
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 pop\SpecialChar ~
14237 \SpecialChar ~
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 psw
14242 \newline 
14243 \SpecialChar ~
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 pop\SpecialChar ~
14248 \SpecialChar ~
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 dph
14253 \newline 
14254 \SpecialChar ~
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 pop\SpecialChar ~
14259 \SpecialChar ~
14260 \SpecialChar ~
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 dpl
14264 \newline 
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 pop\SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 b
14275 \newline 
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 pop\SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 \SpecialChar ~
14284 \SpecialChar ~
14285 acc
14286 \newline 
14287 \SpecialChar ~
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 \SpecialChar ~
14291 reti
14292 \layout Standard
14293
14294 whereas nakedInterrupt looks like:
14295 \layout Verse
14296
14297
14298 \family typewriter 
14299 _nakedInterrupt:
14300 \newline 
14301 \SpecialChar ~
14302 \SpecialChar ~
14303 \SpecialChar ~
14304 \SpecialChar ~
14305 inc\SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 \SpecialChar ~
14309 _counter ; does not change flags, no need to save psw
14310 \newline 
14311 \SpecialChar ~
14312 \SpecialChar ~
14313 \SpecialChar ~
14314 \SpecialChar ~
14315 reti\SpecialChar ~
14316 \SpecialChar ~
14317 \SpecialChar ~
14318 \SpecialChar ~
14319 \SpecialChar ~
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 \SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 ; MUST explicitly include ret or reti in _naked function
14328 \layout Standard
14329
14330 The related directive #pragma exclude
14331 \begin_inset LatexCommand \index{\#pragma exclude}
14332
14333 \end_inset 
14334
14335  allows a more fine grained control over pushing & popping
14336 \begin_inset LatexCommand \index{push/pop}
14337
14338 \end_inset 
14339
14340  the registers.
14341 \layout Standard
14342
14343 While there is nothing preventing you from writing C code inside a 
14344 \family typewriter 
14345 _naked
14346 \family default 
14347  function, there are many ways to shoot yourself in the foot doing this,
14348  and it is recommended that you stick to inline assembler.
14349 \layout Subsection
14350
14351 Use of Labels within Inline Assembler
14352 \layout Standard
14353
14354 SDCC allows the use of in-line assembler with a few restrictions regarding
14355  labels.
14356  In older versions of the compiler all labels defined within inline assembler
14357  code 
14358 \emph on 
14359 had to be
14360 \emph default 
14361  of the form 
14362 \emph on 
14363 nnnnn$
14364 \emph default 
14365  where nnnn is a number less than 100 (which implies a limit of utmost 100
14366  inline assembler labels 
14367 \emph on 
14368 per function
14369 \emph default 
14370 \noun on 
14371 )
14372 \noun default 
14373 .
14374  
14375 \layout Verse
14376
14377
14378 \family typewriter 
14379 _asm
14380 \begin_inset LatexCommand \index{\_asm}
14381
14382 \end_inset 
14383
14384
14385 \begin_inset LatexCommand \index{\_\_asm}
14386
14387 \end_inset 
14388
14389  
14390 \newline 
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 \SpecialChar ~
14395 mov\SpecialChar ~
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 b,#10 
14401 \newline 
14402 00001$: 
14403 \newline 
14404 \SpecialChar ~
14405 \SpecialChar ~
14406 \SpecialChar ~
14407 \SpecialChar ~
14408 djnz\SpecialChar ~
14409 \SpecialChar ~
14410 \SpecialChar ~
14411 \SpecialChar ~
14412 b,00001$ 
14413 \newline 
14414 _endasm
14415 \begin_inset LatexCommand \index{\_endasm}
14416
14417 \end_inset 
14418
14419
14420 \begin_inset LatexCommand \index{\_\_endasm}
14421
14422 \end_inset 
14423
14424  ;
14425 \layout Standard
14426
14427 Inline assembler code cannot reference any C-Labels, however it can reference
14428  labels
14429 \begin_inset LatexCommand \index{Labels}
14430
14431 \end_inset 
14432
14433  defined by the inline assembler, e.g.:
14434 \layout Verse
14435
14436
14437 \family typewriter 
14438 foo() { 
14439 \newline 
14440 \SpecialChar ~
14441 \SpecialChar ~
14442 \SpecialChar ~
14443 \SpecialChar ~
14444 /* some c code */ 
14445 \newline 
14446 \SpecialChar ~
14447 \SpecialChar ~
14448 \SpecialChar ~
14449 \SpecialChar ~
14450 _asm 
14451 \newline 
14452 \SpecialChar ~
14453 \SpecialChar ~
14454 \SpecialChar ~
14455 \SpecialChar ~
14456 \SpecialChar ~
14457 \SpecialChar ~
14458 ; some assembler code 
14459 \newline 
14460 \SpecialChar ~
14461 \SpecialChar ~
14462 \SpecialChar ~
14463 \SpecialChar ~
14464 \SpecialChar ~
14465 \SpecialChar ~
14466 ljmp $0003 
14467 \newline 
14468 \SpecialChar ~
14469 \SpecialChar ~
14470 \SpecialChar ~
14471 \SpecialChar ~
14472 _endasm; 
14473 \newline 
14474 \SpecialChar ~
14475 \SpecialChar ~
14476 \SpecialChar ~
14477 \SpecialChar ~
14478 /* some more c code */ 
14479 \newline 
14480 clabel:\SpecialChar ~
14481 \SpecialChar ~
14482 /* inline assembler cannot reference this label */ 
14483 \newline 
14484 \SpecialChar ~
14485 \SpecialChar ~
14486 \SpecialChar ~
14487 \SpecialChar ~
14488 _asm
14489 \newline 
14490 \SpecialChar ~
14491 \SpecialChar ~
14492 \SpecialChar ~
14493 \SpecialChar ~
14494 $0003: ;label (can be referenced by inline assembler only) 
14495 \newline 
14496 \SpecialChar ~
14497 \SpecialChar ~
14498 \SpecialChar ~
14499 \SpecialChar ~
14500 _endasm
14501 \begin_inset LatexCommand \index{\_endasm}
14502
14503 \end_inset 
14504
14505
14506 \begin_inset LatexCommand \index{\_\_endasm}
14507
14508 \end_inset 
14509
14510  ; 
14511 \newline 
14512 \SpecialChar ~
14513 \SpecialChar ~
14514 \SpecialChar ~
14515 \SpecialChar ~
14516 /* some more c code */
14517 \newline 
14518 }
14519 \layout Standard
14520
14521 In other words inline assembly code can access labels defined in inline
14522  assembly within the scope of the function.
14523  The same goes the other way, i.e.
14524  labels defines in inline assembly can not be accessed by C statements.
14525 \layout Section
14526
14527 Interfacing with Assembler Code
14528 \begin_inset LatexCommand \index{Assembler routines}
14529
14530 \end_inset 
14531
14532
14533 \layout Subsection
14534
14535 Global Registers used for Parameter Passing
14536 \begin_inset LatexCommand \index{Parameter passing}
14537
14538 \end_inset 
14539
14540
14541 \layout Standard
14542
14543 The compiler always uses the global registers 
14544 \emph on 
14545 DPL, DPH
14546 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14547
14548 \end_inset 
14549
14550
14551 \begin_inset LatexCommand \index{DPTR}
14552
14553 \end_inset 
14554
14555 , B
14556 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14557
14558 \end_inset 
14559
14560  
14561 \emph default 
14562 and
14563 \emph on 
14564  ACC
14565 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14566
14567 \end_inset 
14568
14569
14570 \emph default 
14571  to pass the first parameter to a routine.
14572  The second parameter onwards is either allocated on the stack (for reentrant
14573  routines or if -
14574 \begin_inset ERT
14575 status Collapsed
14576
14577 \layout Standard
14578
14579 \backslash 
14580 /
14581 \end_inset 
14582
14583 -stack-auto is used) or in data / xdata memory (depending on the memory
14584  model).
14585  
14586 \layout Subsection
14587
14588 Assembler Routine (non-reentrant)
14589 \layout Standard
14590
14591 In the following example
14592 \begin_inset LatexCommand \index{reentrant}
14593
14594 \end_inset 
14595
14596
14597 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14598
14599 \end_inset 
14600
14601  the function c_func calls an assembler routine asm_func, which takes two
14602  parameters
14603 \begin_inset LatexCommand \index{function parameter}
14604
14605 \end_inset 
14606
14607 .
14608 \layout Verse
14609
14610
14611 \family typewriter 
14612 extern int asm_func(unsigned char, unsigned char);
14613 \newline 
14614
14615 \newline 
14616 int c_func (unsigned char i, unsigned char j)
14617 \newline 
14618 {
14619 \newline 
14620 \SpecialChar ~
14621 \SpecialChar ~
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 return asm_func(i,j);
14625 \newline 
14626 }
14627 \newline 
14628
14629 \newline 
14630 int main()
14631 \newline 
14632 {
14633 \newline 
14634 \SpecialChar ~
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 return c_func(10,9);
14639 \newline 
14640 }
14641 \layout Standard
14642
14643 The corresponding assembler function is:
14644 \layout Verse
14645
14646
14647 \family typewriter 
14648 .globl _asm_func_PARM_2 
14649 \newline 
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 \SpecialChar ~
14653 \SpecialChar ~
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 .globl _asm_func 
14659 \newline 
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667 \SpecialChar ~
14668 .area OSEG 
14669 \newline 
14670 _asm_func_PARM_2:
14671 \newline 
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 \SpecialChar ~
14679 \SpecialChar ~
14680 .ds    1 
14681 \newline 
14682 \SpecialChar ~
14683 \SpecialChar ~
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 .area CSEG 
14691 \newline 
14692 _asm_func: 
14693 \newline 
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 \SpecialChar ~
14699 \SpecialChar ~
14700 \SpecialChar ~
14701 \SpecialChar ~
14702 mov\SpecialChar ~
14703 \SpecialChar ~
14704 \SpecialChar ~
14705 \SpecialChar ~
14706 a,dpl 
14707 \newline 
14708 \SpecialChar ~
14709 \SpecialChar ~
14710 \SpecialChar ~
14711 \SpecialChar ~
14712 \SpecialChar ~
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 add\SpecialChar ~
14717 \SpecialChar ~
14718 \SpecialChar ~
14719 \SpecialChar ~
14720 a,_asm_func_PARM_2 
14721 \newline 
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 \SpecialChar ~
14726 \SpecialChar ~
14727 \SpecialChar ~
14728 \SpecialChar ~
14729 \SpecialChar ~
14730 mov\SpecialChar ~
14731 \SpecialChar ~
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 dpl,a 
14735 \newline 
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 \SpecialChar ~
14741 \SpecialChar ~
14742 \SpecialChar ~
14743 \SpecialChar ~
14744 mov\SpecialChar ~
14745 \SpecialChar ~
14746 \SpecialChar ~
14747 \SpecialChar ~
14748 dph
14749 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14750
14751 \end_inset 
14752
14753 ,#0x00 
14754 \newline 
14755 \SpecialChar ~
14756 \SpecialChar ~
14757 \SpecialChar ~
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 \SpecialChar ~
14761 \SpecialChar ~
14762 \SpecialChar ~
14763 ret
14764 \layout Standard
14765
14766 Note here that the return values
14767 \begin_inset LatexCommand \index{return value}
14768
14769 \end_inset 
14770
14771  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14772  two byte values.
14773  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14774 b' & 'acc' for four byte values.
14775 \layout Standard
14776
14777 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14778  the parameter number starting from 1, and counting from the left.
14779  The first parameter is passed in 
14780 \begin_inset Quotes eld
14781 \end_inset 
14782
14783 dpl
14784 \begin_inset Quotes erd
14785 \end_inset 
14786
14787  for a one byte parameter, 
14788 \begin_inset Quotes eld
14789 \end_inset 
14790
14791 dptr
14792 \begin_inset Quotes erd
14793 \end_inset 
14794
14795  for two bytes, 
14796 \begin_inset Quotes eld
14797 \end_inset 
14798
14799 b,dptr
14800 \begin_inset Quotes erd
14801 \end_inset 
14802
14803  for three bytes and 
14804 \begin_inset Quotes eld
14805 \end_inset 
14806
14807 acc,b,dptr
14808 \begin_inset Quotes erd
14809 \end_inset 
14810
14811  for a four bytes parameter.
14812  The variable name for the second parameter will be _<function_name>_PARM_2.
14813 \newline 
14814
14815 \newline 
14816 Assemble the assembler routine with the following command:
14817 \newline 
14818
14819 \newline 
14820
14821 \family sans 
14822 \series bold 
14823 asx8051 -losg asmfunc.asm
14824 \newline 
14825
14826 \newline 
14827
14828 \family default 
14829 \series default 
14830 Then compile and link the assembler routine to the C source file with the
14831  following command:
14832 \newline 
14833
14834 \newline 
14835
14836 \family sans 
14837 \series bold 
14838 sdcc cfunc.c asmfunc.rel
14839 \layout Subsection
14840
14841 Assembler Routine (reentrant)
14842 \layout Standard
14843
14844 In this case
14845 \begin_inset LatexCommand \index{reentrant}
14846
14847 \end_inset 
14848
14849
14850 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14851
14852 \end_inset 
14853
14854  the second parameter
14855 \begin_inset LatexCommand \index{function parameter}
14856
14857 \end_inset 
14858
14859  onwards will be passed on the stack, the parameters are pushed from right
14860  to left i.e.
14861  after the call the leftmost parameter will be on the top of the stack.
14862  Here is an example:
14863 \layout Verse
14864
14865
14866 \family typewriter 
14867 extern int asm_func(unsigned char, unsigned char);
14868 \newline 
14869
14870 \newline 
14871 int c_func (unsigned char i, unsigned char j) reentrant 
14872 \newline 
14873
14874 \newline 
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 return asm_func(i,j); 
14880 \newline 
14881
14882 \newline 
14883
14884 \newline 
14885 int main() 
14886 \newline 
14887
14888 \newline 
14889 \SpecialChar ~
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 return c_func(10,9); 
14894 \newline 
14895 }
14896 \layout Standard
14897
14898 The corresponding assembler routine is:
14899 \layout Verse
14900
14901
14902 \family typewriter 
14903 .globl _asm_func 
14904 \newline 
14905 _asm_func: 
14906 \newline 
14907 \SpecialChar ~
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 \SpecialChar ~
14911 push  _bp 
14912 \newline 
14913 \SpecialChar ~
14914 \SpecialChar ~
14915 \SpecialChar ~
14916 \SpecialChar ~
14917 mov _bp,sp 
14918 \newline 
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 mov r2,dpl
14924 \newline 
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 mov a,_bp 
14930 \newline 
14931 \SpecialChar ~
14932 \SpecialChar ~
14933 \SpecialChar ~
14934 \SpecialChar ~
14935 add a,#0xfd 
14936 \newline 
14937 \SpecialChar ~
14938 \SpecialChar ~
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 mov r0,a 
14942 \newline 
14943 \SpecialChar ~
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 add  a,#0xfc ;?
14948 \newline 
14949 \SpecialChar ~
14950 \SpecialChar ~
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 mov  r1,a 
14954 \newline 
14955 \SpecialChar ~
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 \SpecialChar ~
14959 mov  a,@r0 
14960 \newline 
14961 \SpecialChar ~
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 \SpecialChar ~
14965 add  a,r2 ;?
14966 \newline 
14967 \SpecialChar ~
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 \SpecialChar ~
14971 mov  dpl,a 
14972 \newline 
14973 \SpecialChar ~
14974 \SpecialChar ~
14975 \SpecialChar ~
14976 \SpecialChar ~
14977 mov  dph,#0x00 
14978 \newline 
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 \SpecialChar ~
14982 \SpecialChar ~
14983 mov  sp,_bp 
14984 \newline 
14985 \SpecialChar ~
14986 \SpecialChar ~
14987 \SpecialChar ~
14988 \SpecialChar ~
14989 pop  _bp 
14990 \newline 
14991 \SpecialChar ~
14992 \SpecialChar ~
14993 \SpecialChar ~
14994 \SpecialChar ~
14995 ret
14996 \layout Standard
14997 \added_space_bottom bigskip 
14998 The compiling and linking procedure remains the same, however note the extra
14999  entry & exit linkage required for the assembler code, _bp is the stack
15000  frame pointer and is used to compute the offset into the stack for parameters
15001  and local variables.
15002 \layout Section
15003
15004 int (16 bit)
15005 \begin_inset LatexCommand \index{int (16 bit)}
15006
15007 \end_inset 
15008
15009  and long (32 bit)
15010 \begin_inset LatexCommand \index{long (32 bit)}
15011
15012 \end_inset 
15013
15014  Support
15015 \layout Standard
15016
15017 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15018  multiplication and modulus operations are implemented by support routines.
15019  These support routines are all developed in ANSI-C to facilitate porting
15020  to other MCUs, although some model specific assembler optimizations are
15021  used.
15022  The following files contain the described routines, all of them can be
15023  found in <installdir>/share/sdcc/lib.
15024 \newline 
15025
15026 \layout Standard
15027 \align center 
15028
15029 \begin_inset  Tabular
15030 <lyxtabular version="3" rows="11" columns="2">
15031 <features>
15032 <column alignment="left" valignment="top" leftline="true" width="0">
15033 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15034 <row topline="true" bottomline="true">
15035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15036 \begin_inset Text
15037
15038 \layout Standard
15039
15040
15041 \series bold 
15042 Function
15043 \end_inset 
15044 </cell>
15045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15046 \begin_inset Text
15047
15048 \layout Standard
15049
15050
15051 \series bold 
15052 Description
15053 \end_inset 
15054 </cell>
15055 </row>
15056 <row topline="true">
15057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15058 \begin_inset Text
15059
15060 \layout Standard
15061
15062 _mulint.c 
15063 \end_inset 
15064 </cell>
15065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15066 \begin_inset Text
15067
15068 \layout Standard
15069
15070 16 bit multiplication
15071 \end_inset 
15072 </cell>
15073 </row>
15074 <row topline="true">
15075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15076 \begin_inset Text
15077
15078 \layout Standard
15079
15080 _divsint.c 
15081 \end_inset 
15082 </cell>
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15084 \begin_inset Text
15085
15086 \layout Standard
15087
15088  signed 16 bit division (calls _divuint)
15089 \end_inset 
15090 </cell>
15091 </row>
15092 <row topline="true">
15093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15094 \begin_inset Text
15095
15096 \layout Standard
15097
15098 _divuint.c 
15099 \end_inset 
15100 </cell>
15101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15102 \begin_inset Text
15103
15104 \layout Standard
15105
15106  unsigned 16 bit division
15107 \end_inset 
15108 </cell>
15109 </row>
15110 <row topline="true">
15111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15112 \begin_inset Text
15113
15114 \layout Standard
15115
15116 _modsint.c
15117 \end_inset 
15118 </cell>
15119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15120 \begin_inset Text
15121
15122 \layout Standard
15123
15124 signed 16 bit modulus (calls _moduint)
15125 \end_inset 
15126 </cell>
15127 </row>
15128 <row topline="true">
15129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15130 \begin_inset Text
15131
15132 \layout Standard
15133
15134 _moduint.c
15135 \end_inset 
15136 </cell>
15137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15138 \begin_inset Text
15139
15140 \layout Standard
15141
15142 unsigned 16 bit modulus
15143 \end_inset 
15144 </cell>
15145 </row>
15146 <row topline="true">
15147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15148 \begin_inset Text
15149
15150 \layout Standard
15151
15152 _mullong.c
15153 \end_inset 
15154 </cell>
15155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15156 \begin_inset Text
15157
15158 \layout Standard
15159
15160 32 bit multiplication
15161 \end_inset 
15162 </cell>
15163 </row>
15164 <row topline="true">
15165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15166 \begin_inset Text
15167
15168 \layout Standard
15169
15170 _divslong.c 
15171 \end_inset 
15172 </cell>
15173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15174 \begin_inset Text
15175
15176 \layout Standard
15177
15178  signed 32 division (calls _divulong)
15179 \end_inset 
15180 </cell>
15181 </row>
15182 <row topline="true">
15183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15184 \begin_inset Text
15185
15186 \layout Standard
15187
15188 _divulong.c 
15189 \end_inset 
15190 </cell>
15191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15192 \begin_inset Text
15193
15194 \layout Standard
15195
15196 unsigned 32 division
15197 \end_inset 
15198 </cell>
15199 </row>
15200 <row topline="true">
15201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15202 \begin_inset Text
15203
15204 \layout Standard
15205
15206 _modslong.c
15207 \end_inset 
15208 </cell>
15209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15210 \begin_inset Text
15211
15212 \layout Standard
15213
15214  signed 32 bit modulus (calls _modulong)
15215 \end_inset 
15216 </cell>
15217 </row>
15218 <row topline="true" bottomline="true">
15219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15220 \begin_inset Text
15221
15222 \layout Standard
15223
15224 _modulong.c
15225 \end_inset 
15226 </cell>
15227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15228 \begin_inset Text
15229
15230 \layout Standard
15231
15232 unsigned 32 bit modulus
15233 \end_inset 
15234 </cell>
15235 </row>
15236 </lyxtabular>
15237
15238 \end_inset 
15239
15240
15241 \newline 
15242
15243 \layout Standard
15244
15245 Since they are compiled as 
15246 \emph on 
15247 non-reentrant
15248 \emph default 
15249
15250 \begin_inset LatexCommand \index{reentrant}
15251
15252 \end_inset 
15253
15254 , interrupt
15255 \begin_inset LatexCommand \index{interrupt}
15256
15257 \end_inset 
15258
15259  service routines should not do any of the above operations.
15260  If this is unavoidable then the above routines will need to be compiled
15261  with the 
15262 \emph on 
15263 -
15264 \begin_inset ERT
15265 status Collapsed
15266
15267 \layout Standard
15268
15269 \backslash 
15270 /
15271 \end_inset 
15272
15273 -stack-auto
15274 \begin_inset LatexCommand \index{-\/-stack-auto}
15275
15276 \end_inset 
15277
15278
15279 \emph default 
15280  option, after which the source program will have to be compiled with 
15281 \emph on 
15282 -
15283 \begin_inset ERT
15284 status Collapsed
15285
15286 \layout Standard
15287
15288 \backslash 
15289 /
15290 \end_inset 
15291
15292 -int-long-reent
15293 \begin_inset LatexCommand \index{-\/-int-long-reent}
15294
15295 \end_inset 
15296
15297
15298 \emph default 
15299  option.
15300  Notice that you don't have to call these routines directly.
15301  The compiler will use them automatically every time an integer operation
15302  is required.
15303 \layout Section
15304
15305 Floating Point Support
15306 \begin_inset LatexCommand \index{Floating point support}
15307
15308 \end_inset 
15309
15310
15311 \layout Standard
15312
15313 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15314  The floating point support routines are derived from gcc's floatlib.c and
15315  consist of the following routines:
15316 \newline 
15317
15318 \layout Standard
15319 \align center 
15320
15321 \size footnotesize 
15322
15323 \begin_inset  Tabular
15324 <lyxtabular version="3" rows="17" columns="2">
15325 <features>
15326 <column alignment="left" valignment="top" leftline="true" width="0">
15327 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15328 <row topline="true" bottomline="true">
15329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15330 \begin_inset Text
15331
15332 \layout Standard
15333
15334
15335 \family roman 
15336 \series medium 
15337 \shape up 
15338 \size normal 
15339 \emph off 
15340 \bar no 
15341 \noun off 
15342 \color none
15343 Function 
15344 \end_inset 
15345 </cell>
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15347 \begin_inset Text
15348
15349 \layout Standard
15350
15351 Description
15352 \end_inset 
15353 </cell>
15354 </row>
15355 <row topline="true">
15356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15357 \begin_inset Text
15358
15359 \layout Standard
15360
15361
15362 \family roman 
15363 \series medium 
15364 \shape up 
15365 \size normal 
15366 \emph off 
15367 \bar no 
15368 \noun off 
15369 \color none
15370 _fsadd.c
15371 \end_inset 
15372 </cell>
15373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15374 \begin_inset Text
15375
15376 \layout Standard
15377
15378
15379 \family roman 
15380 \series medium 
15381 \shape up 
15382 \size normal 
15383 \emph off 
15384 \bar no 
15385 \noun off 
15386 \color none
15387 add floating point numbers
15388 \end_inset 
15389 </cell>
15390 </row>
15391 <row topline="true">
15392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15393 \begin_inset Text
15394
15395 \layout Standard
15396
15397
15398 \family roman 
15399 \series medium 
15400 \shape up 
15401 \size normal 
15402 \emph off 
15403 \bar no 
15404 \noun off 
15405 \color none
15406 _fssub.c 
15407 \end_inset 
15408 </cell>
15409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15410 \begin_inset Text
15411
15412 \layout Standard
15413
15414
15415 \family roman 
15416 \series medium 
15417 \shape up 
15418 \size normal 
15419 \emph off 
15420 \bar no 
15421 \noun off 
15422 \color none
15423 subtract floating point numbers 
15424 \end_inset 
15425 </cell>
15426 </row>
15427 <row topline="true">
15428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15429 \begin_inset Text
15430
15431 \layout Standard
15432
15433
15434 \family roman 
15435 \series medium 
15436 \shape up 
15437 \size normal 
15438 \emph off 
15439 \bar no 
15440 \noun off 
15441 \color none
15442 _fsdiv.c 
15443 \end_inset 
15444 </cell>
15445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15446 \begin_inset Text
15447
15448 \layout Standard
15449
15450
15451 \family roman 
15452 \series medium 
15453 \shape up 
15454 \size normal 
15455 \emph off 
15456 \bar no 
15457 \noun off 
15458 \color none
15459 divide floating point numbers 
15460 \end_inset 
15461 </cell>
15462 </row>
15463 <row topline="true">
15464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15465 \begin_inset Text
15466
15467 \layout Standard
15468
15469
15470 \family roman 
15471 \series medium 
15472 \shape up 
15473 \size normal 
15474 \emph off 
15475 \bar no 
15476 \noun off 
15477 \color none
15478 _fsmul.c 
15479 \end_inset 
15480 </cell>
15481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15482 \begin_inset Text
15483
15484 \layout Standard
15485
15486
15487 \family roman 
15488 \series medium 
15489 \shape up 
15490 \size normal 
15491 \emph off 
15492 \bar no 
15493 \noun off 
15494 \color none
15495 multiply floating point numbers 
15496 \end_inset 
15497 </cell>
15498 </row>
15499 <row topline="true">
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15501 \begin_inset Text
15502
15503 \layout Standard
15504
15505
15506 \family roman 
15507 \series medium 
15508 \shape up 
15509 \size normal 
15510 \emph off 
15511 \bar no 
15512 \noun off 
15513 \color none
15514 _fs2uchar.c
15515 \end_inset 
15516 </cell>
15517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15518 \begin_inset Text
15519
15520 \layout Standard
15521
15522
15523 \family roman 
15524 \series medium 
15525 \shape up 
15526 \size normal 
15527 \emph off 
15528 \bar no 
15529 \noun off 
15530 \color none
15531 convert floating point to unsigned char
15532 \end_inset 
15533 </cell>
15534 </row>
15535 <row topline="true">
15536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15537 \begin_inset Text
15538
15539 \layout Standard
15540
15541
15542 \family roman 
15543 \series medium 
15544 \shape up 
15545 \size normal 
15546 \emph off 
15547 \bar no 
15548 \noun off 
15549 \color none
15550 _fs2char.c
15551 \end_inset 
15552 </cell>
15553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15554 \begin_inset Text
15555
15556 \layout Standard
15557
15558
15559 \family roman 
15560 \series medium 
15561 \shape up 
15562 \size normal 
15563 \emph off 
15564 \bar no 
15565 \noun off 
15566 \color none
15567 convert floating point to signed char
15568 \end_inset 
15569 </cell>
15570 </row>
15571 <row topline="true">
15572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15573 \begin_inset Text
15574
15575 \layout Standard
15576
15577
15578 \family roman 
15579 \series medium 
15580 \shape up 
15581 \size normal 
15582 \emph off 
15583 \bar no 
15584 \noun off 
15585 \color none
15586 _fs2uint.c
15587 \end_inset 
15588 </cell>
15589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15590 \begin_inset Text
15591
15592 \layout Standard
15593
15594
15595 \family roman 
15596 \series medium 
15597 \shape up 
15598 \size normal 
15599 \emph off 
15600 \bar no 
15601 \noun off 
15602 \color none
15603 convert floating point to unsigned int
15604 \end_inset 
15605 </cell>
15606 </row>
15607 <row topline="true">
15608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15609 \begin_inset Text
15610
15611 \layout Standard
15612
15613
15614 \family roman 
15615 \series medium 
15616 \shape up 
15617 \size normal 
15618 \emph off 
15619 \bar no 
15620 \noun off 
15621 \color none
15622 _fs2int.c
15623 \end_inset 
15624 </cell>
15625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15626 \begin_inset Text
15627
15628 \layout Standard
15629
15630
15631 \family roman 
15632 \series medium 
15633 \shape up 
15634 \size normal 
15635 \emph off 
15636 \bar no 
15637 \noun off 
15638 \color none
15639 convert floating point to signed int
15640 \end_inset 
15641 </cell>
15642 </row>
15643 <row topline="true">
15644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15645 \begin_inset Text
15646
15647 \layout Standard
15648
15649
15650 \family roman 
15651 \series medium 
15652 \shape up 
15653 \size normal 
15654 \emph off 
15655 \bar no 
15656 \noun off 
15657 \color none
15658 _fs2ulong.
15659 \family default 
15660 \series default 
15661 \shape default 
15662 \size default 
15663 \emph default 
15664 \bar default 
15665 \noun default 
15666 \color default
15667 c
15668 \end_inset 
15669 </cell>
15670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15671 \begin_inset Text
15672
15673 \layout Standard
15674
15675
15676 \family roman 
15677 \series medium 
15678 \shape up 
15679 \size normal 
15680 \emph off 
15681 \bar no 
15682 \noun off 
15683 \color none
15684 convert floating point to unsigned long
15685 \end_inset 
15686 </cell>
15687 </row>
15688 <row topline="true">
15689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15690 \begin_inset Text
15691
15692 \layout Standard
15693
15694
15695 \family roman 
15696 \series medium 
15697 \shape up 
15698 \size normal 
15699 \emph off 
15700 \bar no 
15701 \noun off 
15702 \color none
15703 _fs2long.c
15704 \end_inset 
15705 </cell>
15706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15707 \begin_inset Text
15708
15709 \layout Standard
15710
15711
15712 \family roman 
15713 \series medium 
15714 \shape up 
15715 \size normal 
15716 \emph off 
15717 \bar no 
15718 \noun off 
15719 \color none
15720 convert floating point to signed long
15721 \end_inset 
15722 </cell>
15723 </row>
15724 <row topline="true">
15725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15726 \begin_inset Text
15727
15728 \layout Standard
15729
15730
15731 \family roman 
15732 \series medium 
15733 \shape up 
15734 \size normal 
15735 \emph off 
15736 \bar no 
15737 \noun off 
15738 \color none
15739 _uchar2fs.c
15740 \end_inset 
15741 </cell>
15742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15743 \begin_inset Text
15744
15745 \layout Standard
15746
15747
15748 \family roman 
15749 \series medium 
15750 \shape up 
15751 \size normal 
15752 \emph off 
15753 \bar no 
15754 \noun off 
15755 \color none
15756 convert unsigned char to floating point
15757 \end_inset 
15758 </cell>
15759 </row>
15760 <row topline="true">
15761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15762 \begin_inset Text
15763
15764 \layout Standard
15765
15766
15767 \family roman 
15768 \series medium 
15769 \shape up 
15770 \size normal 
15771 \emph off 
15772 \bar no 
15773 \noun off 
15774 \color none
15775 _char2fs.c
15776 \end_inset 
15777 </cell>
15778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15779 \begin_inset Text
15780
15781 \layout Standard
15782
15783
15784 \family roman 
15785 \series medium 
15786 \shape up 
15787 \size normal 
15788 \emph off 
15789 \bar no 
15790 \noun off 
15791 \color none
15792 convert char to floating point number
15793 \end_inset 
15794 </cell>
15795 </row>
15796 <row topline="true">
15797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15798 \begin_inset Text
15799
15800 \layout Standard
15801
15802
15803 \family roman 
15804 \series medium 
15805 \shape up 
15806 \size normal 
15807 \emph off 
15808 \bar no 
15809 \noun off 
15810 \color none
15811 _uint2fs.c
15812 \end_inset 
15813 </cell>
15814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15815 \begin_inset Text
15816
15817 \layout Standard
15818
15819
15820 \family roman 
15821 \series medium 
15822 \shape up 
15823 \size normal 
15824 \emph off 
15825 \bar no 
15826 \noun off 
15827 \color none
15828 convert unsigned int to floating point
15829 \end_inset 
15830 </cell>
15831 </row>
15832 <row topline="true">
15833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15834 \begin_inset Text
15835
15836 \layout Standard
15837
15838
15839 \family roman 
15840 \series medium 
15841 \shape up 
15842 \size normal 
15843 \emph off 
15844 \bar no 
15845 \noun off 
15846 \color none
15847 _int2fs.c
15848 \end_inset 
15849 </cell>
15850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15851 \begin_inset Text
15852
15853 \layout Standard
15854
15855
15856 \family roman 
15857 \series medium 
15858 \shape up 
15859 \size normal 
15860 \emph off 
15861 \bar no 
15862 \noun off 
15863 \color none
15864 convert int to floating point numbers
15865 \end_inset 
15866 </cell>
15867 </row>
15868 <row topline="true">
15869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15870 \begin_inset Text
15871
15872 \layout Standard
15873
15874
15875 \family roman 
15876 \series medium 
15877 \shape up 
15878 \size normal 
15879 \emph off 
15880 \bar no 
15881 \noun off 
15882 \color none
15883 _ulong2fs.c
15884 \end_inset 
15885 </cell>
15886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15887 \begin_inset Text
15888
15889 \layout Standard
15890
15891
15892 \family roman 
15893 \series medium 
15894 \shape up 
15895 \size normal 
15896 \emph off 
15897 \bar no 
15898 \noun off 
15899 \color none
15900 convert unsigned long to floating point number
15901 \end_inset 
15902 </cell>
15903 </row>
15904 <row topline="true" bottomline="true">
15905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15906 \begin_inset Text
15907
15908 \layout Standard
15909
15910
15911 \family roman 
15912 \series medium 
15913 \shape up 
15914 \size normal 
15915 \emph off 
15916 \bar no 
15917 \noun off 
15918 \color none
15919 _long2fs.c
15920 \end_inset 
15921 </cell>
15922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15923 \begin_inset Text
15924
15925 \layout Standard
15926
15927
15928 \family roman 
15929 \series medium 
15930 \shape up 
15931 \size normal 
15932 \emph off 
15933 \bar no 
15934 \noun off 
15935 \color none
15936 convert long to floating point number
15937 \end_inset 
15938 </cell>
15939 </row>
15940 </lyxtabular>
15941
15942 \end_inset 
15943
15944
15945 \newline 
15946
15947 \layout Standard
15948 \added_space_bottom bigskip 
15949 These support routines are developed in ANSI-C so there is room for space
15950  and speed improvement
15951 \begin_inset Foot
15952 collapsed false
15953
15954 \layout Standard
15955
15956 These floating point routines (
15957 \emph on 
15958 not
15959 \emph default 
15960  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15961  
15962 \end_inset 
15963
15964 .
15965  Note if all these routines are used simultaneously the data space might
15966  overflow.
15967  For serious floating point usage the large model might be needed.
15968  Also notice that you don't have to call this routines directly.
15969  The compiler will use them automatically every time a floating point operation
15970  is required.
15971 \layout Section
15972
15973 Library Routines
15974 \begin_inset LatexCommand \index{Libraries}
15975
15976 \end_inset 
15977
15978
15979 \layout Standard
15980
15981
15982 \emph on 
15983 <pending: this is messy and incomplete - a little more information is in
15984  sdcc/doc/libdoc.txt
15985 \emph default 
15986  >
15987 \layout Subsection
15988
15989 Compiler support routines (_gptrget, _mulint etc.)
15990 \layout Subsection
15991
15992 Stdclib functions (puts, printf, strcat etc.)
15993 \layout Subsubsection
15994
15995 <stdio.h>
15996 \layout Paragraph
15997
15998 getchar(), putchar()
15999 \layout Standard
16000
16001
16002 \begin_inset LatexCommand \index{<stdio.h>}
16003
16004 \end_inset 
16005
16006 As usual on embedded systems you have to provide your own 
16007 \family typewriter 
16008 getchar()
16009 \begin_inset LatexCommand \index{getchar()}
16010
16011 \end_inset 
16012
16013  
16014 \family default 
16015 and 
16016 \family typewriter 
16017 putchar()
16018 \begin_inset LatexCommand \index{putchar()}
16019
16020 \end_inset 
16021
16022
16023 \family default 
16024  routines.
16025  SDCC does not know whether the system connects to a serial line with or
16026  without handshake, LCD, keyboard or other device.
16027  And whether a 
16028 \family typewriter 
16029 lf
16030 \family default 
16031  to 
16032 \family typewriter 
16033 crlf
16034 \family default 
16035  conversion within 
16036 \family typewriter 
16037 putchar()
16038 \family default 
16039  is intended.
16040  You'll find examples for serial routines f.e.
16041  in sdcc/device/lib.
16042  For the mcs51 this minimalistic polling 
16043 \family typewriter 
16044 putchar()
16045 \family default 
16046  routine might be a start:
16047 \layout Verse
16048
16049
16050 \family typewriter 
16051 void putchar (char c) { 
16052 \newline 
16053 \SpecialChar ~
16054 \SpecialChar ~
16055 \SpecialChar ~
16056 \SpecialChar ~
16057 while (!TI)\SpecialChar ~
16058 \SpecialChar ~
16059 \SpecialChar ~
16060  /* assumes UART is initialized */
16061 \newline 
16062 \SpecialChar ~
16063 \SpecialChar ~
16064 \SpecialChar ~
16065 \SpecialChar ~
16066 \SpecialChar ~
16067 \SpecialChar ~
16068 \SpecialChar ~
16069 \SpecialChar ~
16070 ;
16071 \newline 
16072 \SpecialChar ~
16073 \SpecialChar ~
16074 \SpecialChar ~
16075 \SpecialChar ~
16076 TI = 0;
16077 \newline 
16078 \SpecialChar ~
16079 \SpecialChar ~
16080 \SpecialChar ~
16081 \SpecialChar ~
16082 SBUF = c;
16083 \newline 
16084 }
16085 \layout Paragraph
16086
16087 printf()
16088 \layout Standard
16089
16090 The default
16091 \family typewriter 
16092  printf()
16093 \begin_inset LatexCommand \index{printf()}
16094
16095 \end_inset 
16096
16097
16098 \family default 
16099  implementation in
16100 \family typewriter 
16101  printf_large.c
16102 \family default 
16103  does not support float (except on ds390).
16104  To enable this recompile it with the option 
16105 \emph on 
16106 -
16107 \begin_inset ERT
16108 status Collapsed
16109
16110 \layout Standard
16111
16112 \backslash 
16113 /
16114 \end_inset 
16115
16116 DUSE_FLOATS=1
16117 \begin_inset LatexCommand \index{USE\_FLOATS}
16118
16119 \end_inset 
16120
16121
16122 \emph default 
16123  on the command line.
16124  Use
16125 \emph on 
16126  -
16127 \begin_inset ERT
16128 status Collapsed
16129
16130 \layout Standard
16131
16132 \backslash 
16133 /
16134 \end_inset 
16135
16136 -model-large
16137 \begin_inset LatexCommand \index{-\/-model-large}
16138
16139 \end_inset 
16140
16141
16142 \emph default 
16143  for the mcs51 port, since this uses a lot of memory.
16144 \layout Standard
16145
16146 If you're short on code memory you might want to use 
16147 \family typewriter 
16148 printf_small()
16149 \begin_inset LatexCommand \index{printf\_small()}
16150
16151 \end_inset 
16152
16153
16154 \family default 
16155  
16156 \emph on 
16157 instead
16158 \emph default 
16159  of
16160 \family typewriter 
16161  printf().
16162
16163 \family default 
16164  For the mcs51 there additionally are assembly versions 
16165 \family typewriter 
16166 printf_tiny()
16167 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16168
16169 \end_inset 
16170
16171
16172 \family default 
16173  (subset of printf using less than 270 bytes) and 
16174 \family typewriter 
16175 printf_fast()
16176 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16177
16178 \end_inset 
16179
16180  
16181 \family default 
16182 and
16183 \family typewriter 
16184  printf_fast_f()
16185 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16186
16187 \end_inset 
16188
16189
16190 \family default 
16191  (floating-point aware version of printf_fast) which should fit the requirements
16192  of many embedded systems (printf_fast() can be customized by unsetting
16193  #defines to 
16194 \emph on 
16195 not
16196 \emph default 
16197  support long variables and field widths).
16198  Be shure to only use only one of these printf options within a project.
16199 \newline 
16200
16201 \layout Standard
16202
16203 Feature matrix of different 
16204 \emph on 
16205 printf
16206 \emph default 
16207  options on mcs51.
16208 \layout Standard
16209
16210
16211 \begin_inset  Tabular
16212 <lyxtabular version="3" rows="9" columns="7">
16213 <features islongtable="true">
16214 <column alignment="left" valignment="center" leftline="true" width="14col%">
16215 <column alignment="center" valignment="top" leftline="true" width="0">
16216 <column alignment="center" valignment="top" leftline="true" width="12col%">
16217 <column alignment="center" valignment="top" leftline="true" width="10col%">
16218 <column alignment="center" valignment="top" leftline="true" width="0">
16219 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
16220 <column alignment="center" valignment="top" rightline="true" width="0">
16221 <row topline="true" bottomline="true" endhead="true">
16222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16223 \begin_inset Text
16224
16225 \layout Standard
16226
16227
16228 \series bold 
16229 \size large 
16230 mcs51
16231 \end_inset 
16232 </cell>
16233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16234 \begin_inset Text
16235
16236 \layout Standard
16237
16238 printf
16239 \begin_inset LatexCommand \index{printf}
16240
16241 \end_inset 
16242
16243
16244 \end_inset 
16245 </cell>
16246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16247 \begin_inset Text
16248
16249 \layout Standard
16250
16251 printf 
16252 \size scriptsize 
16253 USE_FLOATS=1
16254 \end_inset 
16255 </cell>
16256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16257 \begin_inset Text
16258
16259 \layout Standard
16260
16261 printf_small
16262 \end_inset 
16263 </cell>
16264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16265 \begin_inset Text
16266
16267 \layout Standard
16268
16269 printf_fast
16270 \end_inset 
16271 </cell>
16272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16273 \begin_inset Text
16274
16275 \layout Standard
16276
16277 printf_fast_f
16278 \end_inset 
16279 </cell>
16280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16281 \begin_inset Text
16282
16283 \layout Standard
16284
16285 printf_tiny
16286 \end_inset 
16287 </cell>
16288 </row>
16289 <row topline="true" endhead="true">
16290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16291 \begin_inset Text
16292
16293 \layout Standard
16294
16295 filename
16296 \end_inset 
16297 </cell>
16298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16299 \begin_inset Text
16300
16301 \layout Standard
16302
16303
16304 \size scriptsize 
16305 printf_large.c
16306 \end_inset 
16307 </cell>
16308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16309 \begin_inset Text
16310
16311 \layout Standard
16312
16313
16314 \size scriptsize 
16315 printf_large.c
16316 \end_inset 
16317 </cell>
16318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16319 \begin_inset Text
16320
16321 \layout Standard
16322
16323
16324 \size scriptsize 
16325 printfl.c
16326 \end_inset 
16327 </cell>
16328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16329 \begin_inset Text
16330
16331 \layout Standard
16332
16333
16334 \size scriptsize 
16335 printf_fast.c
16336 \end_inset 
16337 </cell>
16338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16339 \begin_inset Text
16340
16341 \layout Standard
16342
16343
16344 \size scriptsize 
16345 printf_fast_f.c
16346 \end_inset 
16347 </cell>
16348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16349 \begin_inset Text
16350
16351 \layout Standard
16352
16353
16354 \size scriptsize 
16355 printf_tiny.c
16356 \end_inset 
16357 </cell>
16358 </row>
16359 <row topline="true" endhead="true">
16360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16361 \begin_inset Text
16362
16363 \layout Standard
16364
16365 code size (small\SpecialChar ~
16366 /\SpecialChar ~
16367 large) in\SpecialChar ~
16368 kByte
16369 \end_inset 
16370 </cell>
16371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16372 \begin_inset Text
16373
16374 \layout Standard
16375
16376 1.4 / 2.0
16377 \end_inset 
16378 </cell>
16379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16380 \begin_inset Text
16381
16382 \layout Standard
16383
16384 2.8 / 3.7
16385 \end_inset 
16386 </cell>
16387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16388 \begin_inset Text
16389
16390 \layout Standard
16391
16392 0.45 / 0.47 (+ _ltoa)
16393 \end_inset 
16394 </cell>
16395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16396 \begin_inset Text
16397
16398 \layout Standard
16399
16400 1.2 / 1.2
16401 \end_inset 
16402 </cell>
16403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16404 \begin_inset Text
16405
16406 \layout Standard
16407
16408 1.6 / 1.6
16409 \end_inset 
16410 </cell>
16411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16412 \begin_inset Text
16413
16414 \layout Standard
16415
16416 0.26 / 0.26
16417 \end_inset 
16418 </cell>
16419 </row>
16420 <row topline="true">
16421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16422 \begin_inset Text
16423
16424 \layout Standard
16425
16426 formats
16427 \end_inset 
16428 </cell>
16429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16430 \begin_inset Text
16431
16432 \layout Standard
16433
16434 cd(f)i
16435 \emph on 
16436 o
16437 \emph default 
16438 psx
16439 \end_inset 
16440 </cell>
16441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16442 \begin_inset Text
16443
16444 \layout Standard
16445
16446
16447 \family roman 
16448 \series medium 
16449 \shape up 
16450 \size normal 
16451 \emph off 
16452 \bar no 
16453 \noun off 
16454 \color none
16455 cd
16456 \family default 
16457 \series default 
16458 \shape default 
16459 \size default 
16460 \emph default 
16461 \bar default 
16462 \noun default 
16463 \color default
16464 f
16465 \family roman 
16466 \series medium 
16467 \shape up 
16468 \size normal 
16469 \emph off 
16470 \bar no 
16471 \noun off 
16472 \color none
16473 i
16474 \family default 
16475 \series default 
16476 \shape default 
16477 \size default 
16478 \emph on 
16479 \bar default 
16480 \noun default 
16481 \color default
16482 o
16483 \family roman 
16484 \series medium 
16485 \shape up 
16486 \size normal 
16487 \emph off 
16488 \bar no 
16489 \noun off 
16490 \color none
16491 psx
16492 \end_inset 
16493 </cell>
16494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16495 \begin_inset Text
16496
16497 \layout Standard
16498
16499 c
16500 \family roman 
16501 \series medium 
16502 \shape up 
16503 \size normal 
16504 \emph off 
16505 \bar no 
16506 \noun off 
16507 \color none
16508 d
16509 \family default 
16510 \series default 
16511 \shape default 
16512 \size default 
16513 \emph on 
16514 \bar default 
16515 \noun default 
16516 \color default
16517 o
16518 \family roman 
16519 \series medium 
16520 \shape up 
16521 \size normal 
16522 \emph off 
16523 \bar no 
16524 \noun off 
16525 \color none
16526 s
16527 \family default 
16528 \series default 
16529 \shape default 
16530 \size default 
16531 \emph default 
16532 \bar default 
16533 \noun default 
16534 \color default
16535 x
16536 \end_inset 
16537 </cell>
16538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16539 \begin_inset Text
16540
16541 \layout Standard
16542
16543 cdsx
16544 \end_inset 
16545 </cell>
16546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16547 \begin_inset Text
16548
16549 \layout Standard
16550
16551 cdfsx
16552 \end_inset 
16553 </cell>
16554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16555 \begin_inset Text
16556
16557 \layout Standard
16558
16559 cdsx
16560 \end_inset 
16561 </cell>
16562 </row>
16563 <row topline="true">
16564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16565 \begin_inset Text
16566
16567 \layout Standard
16568
16569 long (32 bit) support
16570 \end_inset 
16571 </cell>
16572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16573 \begin_inset Text
16574
16575 \layout Standard
16576
16577 x
16578 \end_inset 
16579 </cell>
16580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16581 \begin_inset Text
16582
16583 \layout Standard
16584
16585 x
16586 \end_inset 
16587 </cell>
16588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16589 \begin_inset Text
16590
16591 \layout Standard
16592
16593 x
16594 \end_inset 
16595 </cell>
16596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16597 \begin_inset Text
16598
16599 \layout Standard
16600
16601 x/(-)
16602 \end_inset 
16603 </cell>
16604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16605 \begin_inset Text
16606
16607 \layout Standard
16608
16609
16610 \family roman 
16611 \series medium 
16612 \shape up 
16613 \size normal 
16614 \emph off 
16615 \bar no 
16616 \noun off 
16617 \color none
16618 x/(-)
16619 \end_inset 
16620 </cell>
16621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16622 \begin_inset Text
16623
16624 \layout Standard
16625
16626 -
16627 \end_inset 
16628 </cell>
16629 </row>
16630 <row topline="true">
16631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16632 \begin_inset Text
16633
16634 \layout Standard
16635
16636 byte arguments on stack
16637 \end_inset 
16638 </cell>
16639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16640 \begin_inset Text
16641
16642 \layout Standard
16643
16644 b
16645 \end_inset 
16646 </cell>
16647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16648 \begin_inset Text
16649
16650 \layout Standard
16651
16652 b
16653 \end_inset 
16654 </cell>
16655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16656 \begin_inset Text
16657
16658 \layout Standard
16659
16660 -
16661 \end_inset 
16662 </cell>
16663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16664 \begin_inset Text
16665
16666 \layout Standard
16667
16668 h
16669 \end_inset 
16670 </cell>
16671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16672 \begin_inset Text
16673
16674 \layout Standard
16675
16676 h
16677 \end_inset 
16678 </cell>
16679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16680 \begin_inset Text
16681
16682 \layout Standard
16683
16684 -
16685 \end_inset 
16686 </cell>
16687 </row>
16688 <row topline="true">
16689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16690 \begin_inset Text
16691
16692 \layout Standard
16693
16694 float format
16695 \begin_inset LatexCommand \index{Floating point support}
16696
16697 \end_inset 
16698
16699
16700 \end_inset 
16701 </cell>
16702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16703 \begin_inset Text
16704
16705 \layout Standard
16706
16707 (%f)
16708 \end_inset 
16709 </cell>
16710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16711 \begin_inset Text
16712
16713 \layout Standard
16714
16715 %f
16716 \end_inset 
16717 </cell>
16718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16719 \begin_inset Text
16720
16721 \layout Standard
16722
16723 -
16724 \end_inset 
16725 </cell>
16726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16727 \begin_inset Text
16728
16729 \layout Standard
16730
16731 (%f)
16732 \end_inset 
16733 </cell>
16734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16735 \begin_inset Text
16736
16737 \layout Standard
16738
16739 %f (limited\SpecialChar ~
16740 range)
16741 \end_inset 
16742 </cell>
16743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16744 \begin_inset Text
16745
16746 \layout Standard
16747
16748 -
16749 \end_inset 
16750 </cell>
16751 </row>
16752 <row topline="true">
16753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16754 \begin_inset Text
16755
16756 \layout Standard
16757
16758 float formats %e %g
16759 \end_inset 
16760 </cell>
16761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16762 \begin_inset Text
16763
16764 \layout Standard
16765
16766 -
16767 \end_inset 
16768 </cell>
16769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16770 \begin_inset Text
16771
16772 \layout Standard
16773
16774 -
16775 \end_inset 
16776 </cell>
16777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16778 \begin_inset Text
16779
16780 \layout Standard
16781
16782 -
16783 \end_inset 
16784 </cell>
16785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16786 \begin_inset Text
16787
16788 \layout Standard
16789
16790 -
16791 \end_inset 
16792 </cell>
16793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16794 \begin_inset Text
16795
16796 \layout Standard
16797
16798 -
16799 \end_inset 
16800 </cell>
16801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16802 \begin_inset Text
16803
16804 \layout Standard
16805
16806 -
16807 \end_inset 
16808 </cell>
16809 </row>
16810 <row topline="true" bottomline="true">
16811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16812 \begin_inset Text
16813
16814 \layout Standard
16815
16816 field width
16817 \end_inset 
16818 </cell>
16819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16820 \begin_inset Text
16821
16822 \layout Standard
16823
16824 x
16825 \end_inset 
16826 </cell>
16827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16828 \begin_inset Text
16829
16830 \layout Standard
16831
16832 x
16833 \end_inset 
16834 </cell>
16835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16836 \begin_inset Text
16837
16838 \layout Standard
16839
16840 -
16841 \end_inset 
16842 </cell>
16843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16844 \begin_inset Text
16845
16846 \layout Standard
16847
16848 x/(-)
16849 \end_inset 
16850 </cell>
16851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16852 \begin_inset Text
16853
16854 \layout Standard
16855
16856 x/(-)
16857 \end_inset 
16858 </cell>
16859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16860 \begin_inset Text
16861
16862 \layout Standard
16863
16864 -
16865 \end_inset 
16866 </cell>
16867 </row>
16868 </lyxtabular>
16869
16870 \end_inset 
16871
16872
16873 \layout Subsubsection
16874
16875 <malloc.h>
16876 \begin_inset LatexCommand \index{malloc.h}
16877
16878 \end_inset 
16879
16880
16881 \layout Standard
16882
16883 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16884  using dynamic memory allocation
16885 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16886
16887 \end_inset 
16888
16889  and a default heap
16890 \begin_inset LatexCommand \index{heap (malloc)}
16891
16892 \end_inset 
16893
16894  space of 1024 bytes is provided for malloc to allocate memory from.
16895  If you need a different heap size you need to recompile _heap.c with the
16896  required size defined in HEAP_SIZE.
16897  It is recommended to make a copy of this file into your project directory
16898  and compile it there with:
16899 \layout Verse
16900
16901
16902 \family typewriter 
16903 sdcc -c _heap.c -D HEAD_SIZE=2048
16904 \layout Standard
16905
16906 And then link it with:
16907 \layout Verse
16908
16909
16910 \family typewriter 
16911 sdcc main.rel _heap.rel
16912 \layout Subsection
16913
16914 Math functions (sinf, powf, sqrtf etc.)
16915 \layout Subsubsection
16916
16917 <math.h>
16918 \layout Standard
16919
16920 See definitions in file <math.h>.
16921 \layout Subsection
16922
16923 Other libraries
16924 \layout Standard
16925
16926 Libraries
16927 \begin_inset LatexCommand \index{Libraries}
16928
16929 \end_inset 
16930
16931  included in SDCC should have a license at least as liberal as the GNU Lesser
16932  General Public License
16933 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16934
16935 \end_inset 
16936
16937  
16938 \emph on 
16939 LGPL
16940 \emph default 
16941 .
16942 \layout Comment
16943
16944 license statements for the libraries are missing.
16945  sdcc/device/lib/ser_ir.c
16946 \layout Comment
16947
16948 or _decdptr f.e.
16949  come with a GPL (as opposed to LGPL) License - this will not be liberal
16950  enough for many embedded programmers.
16951 \layout Standard
16952
16953 If you have ported some library or want to share experience about some code
16954  which f.e.
16955  falls into any of these categories Busses (I
16956 \begin_inset Formula $^{\textrm{2}}$
16957 \end_inset 
16958
16959 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16960  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16961  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16962 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16963
16964 \end_inset 
16965
16966 \SpecialChar ~
16967 would certainly like to hear about it.
16968 \layout Standard
16969 \added_space_bottom bigskip 
16970 Programmers coding for embedded systems are not especially famous for being
16971  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16972 e these references are very valuable.
16973  Let's help to create a climate where information is shared.
16974 \layout Section
16975
16976 Memory Models
16977 \layout Subsection
16978
16979 MCS51 Memory Models
16980 \begin_inset LatexCommand \index{Memory model}
16981
16982 \end_inset 
16983
16984
16985 \begin_inset LatexCommand \index{MCS51 memory model}
16986
16987 \end_inset 
16988
16989
16990 \layout Subsubsection
16991
16992 Small, Medium and Large
16993 \layout Standard
16994
16995 SDCC allows three memory models for MCS51 code, 
16996 \shape slanted 
16997 small, medium
16998 \shape default 
16999  and 
17000 \shape slanted 
17001 large
17002 \shape default 
17003 .
17004  Modules compiled with different memory models should 
17005 \emph on 
17006 never
17007 \emph default 
17008  be combined together or the results would be unpredictable.
17009  The library routines supplied with the compiler are compiled as small,
17010  medium and large.
17011  The compiled library modules are contained in separate directories as small,
17012  medium and large so that you can link to the appropriate set.
17013 \layout Standard
17014
17015 When the medium or large model is used all variables declared without a
17016  storage class will be allocated into the external ram, this includes all
17017  parameters and local variables (for non-reentrant
17018 \begin_inset LatexCommand \index{reentrant}
17019
17020 \end_inset 
17021
17022  functions).
17023  When the small model is used variables without storage class are allocated
17024  in the internal ram.
17025 \layout Standard
17026
17027 Judicious usage of the processor specific storage classes
17028 \begin_inset LatexCommand \index{Storage class}
17029
17030 \end_inset 
17031
17032  and the 'reentrant' function type will yield much more efficient code,
17033  than using the large model.
17034  Several optimizations are disabled when the program is compiled using the
17035  large model, it is therefore recommended that the small model be used unless
17036  absolutely required.
17037 \layout Subsubsection
17038
17039 External Stack
17040 \begin_inset LatexCommand \label{sub:External-Stack}
17041
17042 \end_inset 
17043
17044
17045 \begin_inset LatexCommand \index{stack}
17046
17047 \end_inset 
17048
17049
17050 \begin_inset LatexCommand \index{External stack (mcs51)}
17051
17052 \end_inset 
17053
17054
17055 \layout Standard
17056
17057 The external stack (-
17058 \begin_inset ERT
17059 status Collapsed
17060
17061 \layout Standard
17062
17063 \backslash 
17064 /
17065 \end_inset 
17066
17067 -xstack option
17068 \begin_inset LatexCommand \index{-\/-xstack}
17069
17070 \end_inset 
17071
17072 ) is located in pdata
17073 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17074
17075 \end_inset 
17076
17077  memory (usually at the start of the external ram segment) and uses all
17078  unused space in pdata (max.
17079  256 bytes).
17080  When -
17081 \begin_inset ERT
17082 status Collapsed
17083
17084 \layout Standard
17085
17086 \backslash 
17087 /
17088 \end_inset 
17089
17090 -xstack option is used to compile the program, the parameters and local
17091  variables
17092 \begin_inset LatexCommand \index{local variables}
17093
17094 \end_inset 
17095
17096  of all reentrant functions are allocated in this area.
17097  This option is provided for programs with large stack space requirements.
17098  When used with the -
17099 \begin_inset ERT
17100 status Collapsed
17101
17102 \layout Standard
17103
17104 \backslash 
17105 /
17106 \end_inset 
17107
17108 -stack-auto
17109 \begin_inset LatexCommand \index{-\/-stack-auto}
17110
17111 \end_inset 
17112
17113  option, all parameters and local variables are allocated on the external
17114  stack (note: support libraries will need to be recompiled with the same
17115  options.
17116  There is a predefined target in the library makefile).
17117 \layout Standard
17118
17119 The compiler outputs the higher order address byte of the external ram segment
17120  into port P2
17121 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17122
17123 \end_inset 
17124
17125  (see also section 
17126 \begin_inset LatexCommand \ref{sub:MCS51-variants}
17127
17128 \end_inset 
17129
17130 ), therefore when using the External Stack option, this port 
17131 \emph on 
17132 may not
17133 \emph default 
17134  be used by the application program.
17135 \layout Subsection
17136
17137 DS390 Memory Model
17138 \begin_inset LatexCommand \index{Memory model}
17139
17140 \end_inset 
17141
17142
17143 \begin_inset LatexCommand \index{DS390 memory model}
17144
17145 \end_inset 
17146
17147
17148 \layout Standard
17149
17150 The only model supported is Flat 24
17151 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
17152
17153 \end_inset 
17154
17155 .
17156  This generates code for the 24 bit contiguous addressing mode of the Dallas
17157  DS80C390 part.
17158  In this mode, up to four meg of external RAM or code space can be directly
17159  addressed.
17160  See the data sheets at www.dalsemi.com for further information on this part.
17161 \newline 
17162
17163 \newline 
17164 Note that the compiler does not generate any code to place the processor
17165  into 24 bitmode (although 
17166 \emph on 
17167 tinibios
17168 \emph default 
17169  in the ds390 libraries will do that for you).
17170  If you don't use 
17171 \emph on 
17172 tinibios
17173 \emph default 
17174
17175 \begin_inset LatexCommand \index{Tinibios (DS390)}
17176
17177 \end_inset 
17178
17179 , the boot loader or similar code must ensure that the processor is in 24
17180  bit contiguous addressing mode before calling the SDCC startup code.
17181 \newline 
17182
17183 \newline 
17184 Like the 
17185 \emph on 
17186 -
17187 \begin_inset ERT
17188 status Collapsed
17189
17190 \layout Standard
17191
17192 \backslash 
17193 /
17194 \end_inset 
17195
17196 -model-large
17197 \emph default 
17198  option, variables will by default be placed into the XDATA segment.
17199  
17200 \newline 
17201
17202 \newline 
17203 Segments may be placed anywhere in the 4 meg address space using the usual
17204  -
17205 \begin_inset ERT
17206 status Collapsed
17207
17208 \layout Standard
17209
17210 \backslash 
17211 /
17212 \end_inset 
17213
17214 -*-loc options.
17215  Note that if any segments are located above 64K, the -r flag must be passed
17216  to the linker to generate the proper segment relocations, and the Intel
17217  HEX output format must be used.
17218  The -r flag can be passed to the linker by using the option 
17219 \emph on 
17220 -Wl-r
17221 \emph default 
17222  on the SDCC command line.
17223  However, currently the linker can not handle code segments > 64k.
17224 \layout Section
17225
17226 Pragmas
17227 \begin_inset LatexCommand \label{sec:Pragmas}
17228
17229 \end_inset 
17230
17231
17232 \begin_inset LatexCommand \index{Pragmas}
17233
17234 \end_inset 
17235
17236
17237 \layout Standard
17238
17239 SDCC supports the following #pragma directives:
17240 \layout Itemize
17241
17242
17243 \series bold 
17244 save
17245 \series default 
17246
17247 \begin_inset LatexCommand \index{\#pragma save}
17248
17249 \end_inset 
17250
17251  - this will save most current options to the save/restore stack.
17252  See #pragma\SpecialChar ~
17253 restore.
17254 \layout Itemize
17255
17256
17257 \series bold 
17258 restore
17259 \series default 
17260
17261 \begin_inset LatexCommand \index{\#pragma restore}
17262
17263 \end_inset 
17264
17265  - will restore saved options from the last save.
17266  saves & restores can be nested.
17267  SDCC uses a save/restore stack: save pushes current options to the stack,
17268  restore pulls current options from the stack.
17269  See #pragma\SpecialChar ~
17270 save.
17271 \newline 
17272
17273 \layout Itemize
17274
17275
17276 \series bold 
17277 callee_saves
17278 \series default 
17279
17280 \begin_inset LatexCommand \index{\#pragma callee\_saves}
17281
17282 \end_inset 
17283
17284
17285 \begin_inset LatexCommand \index{function prologue}
17286
17287 \end_inset 
17288
17289  function1[,function2[,function3...]] - The compiler by default uses a caller
17290  saves convention for register saving across function calls, however this
17291  can cause unnecessary register pushing & popping
17292 \begin_inset LatexCommand \index{push/pop}
17293
17294 \end_inset 
17295
17296  when calling small functions from larger functions.
17297  This option can be used to switch off the register saving convention for
17298  the function names specified.
17299  The compiler will not save registers when calling these functions, extra
17300  code need to be manually inserted at the entry & exit for these functions
17301  to save & restore the registers used by these functions, this can SUBSTANTIALLY
17302  reduce code & improve run time performance of the generated code.
17303  In the future the compiler (with inter procedural analysis) may be able
17304  to determine the appropriate scheme to use for each function call.
17305  If -
17306 \begin_inset ERT
17307 status Collapsed
17308
17309 \layout Standard
17310
17311 \backslash 
17312 /
17313 \end_inset 
17314
17315 -callee-saves command line option is used, the function names specified
17316  in #pragma\SpecialChar ~
17317 callee_saves
17318 \begin_inset LatexCommand \index{\#pragma callee\_saves}
17319
17320 \end_inset 
17321
17322  is appended to the list of functions specified in the command line.
17323 \layout Itemize
17324
17325
17326 \series bold 
17327 exclude
17328 \series default 
17329
17330 \begin_inset LatexCommand \index{\#pragma exclude}
17331
17332 \end_inset 
17333
17334  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
17335  of pairs of push/pop
17336 \begin_inset LatexCommand \index{push/pop}
17337
17338 \end_inset 
17339
17340  instructions in 
17341 \emph on 
17342 I
17343 \emph default 
17344 nterrupt
17345 \begin_inset LatexCommand \index{interrupt}
17346
17347 \end_inset 
17348
17349  
17350 \emph on 
17351 S
17352 \emph default 
17353 ervice 
17354 \emph on 
17355 R
17356 \emph default 
17357 outines.
17358  The directive should be placed immediately before the ISR function definition
17359  and it affects ALL ISR functions following it.
17360  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
17361 exclude\SpecialChar ~
17362 none
17363 \begin_inset LatexCommand \index{\#pragma exclude}
17364
17365 \end_inset 
17366
17367 .
17368  See also the related keyword _naked
17369 \begin_inset LatexCommand \index{\_naked}
17370
17371 \end_inset 
17372
17373
17374 \begin_inset LatexCommand \index{\_\_naked}
17375
17376 \end_inset 
17377
17378 .
17379 \layout Itemize
17380
17381
17382 \series bold 
17383 less_pedantic
17384 \series default 
17385
17386 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
17387
17388 \end_inset 
17389
17390  - the compiler will not warn you anymore for obvious mistakes, you'r on
17391  your own now ;-(
17392 \layout Itemize
17393
17394
17395 \series bold 
17396 disable_warning
17397 \series default 
17398  <nnnn>
17399 \begin_inset LatexCommand \index{\#pragma disable\_warning}
17400
17401 \end_inset 
17402
17403  - the compiler will not warn you anymore about warning number <nnnn>.
17404 \layout Itemize
17405
17406
17407 \series bold 
17408 nogcse
17409 \series default 
17410
17411 \begin_inset LatexCommand \index{\#pragma nogcse}
17412
17413 \end_inset 
17414
17415  - will stop global common subexpression elimination.
17416 \layout Itemize
17417
17418
17419 \series bold 
17420 noinduction
17421 \series default 
17422
17423 \begin_inset LatexCommand \index{\#pragma noinduction}
17424
17425 \end_inset 
17426
17427  - will stop loop induction optimizations.
17428 \layout Itemize
17429
17430
17431 \series bold 
17432 noinvariant
17433 \series default 
17434
17435 \begin_inset LatexCommand \index{\#pragma noinvariant}
17436
17437 \end_inset 
17438
17439  - will not do loop invariant optimizations.
17440  For more details see Loop Invariants in section
17441 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
17442
17443 \end_inset 
17444
17445 .
17446 \layout Itemize
17447
17448
17449 \series bold 
17450 noiv
17451 \series default 
17452
17453 \begin_inset LatexCommand \index{\#pragma noiv}
17454
17455 \end_inset 
17456
17457  - Do not generate interrupt
17458 \begin_inset LatexCommand \index{interrupt}
17459
17460 \end_inset 
17461
17462  vector table
17463 \begin_inset LatexCommand \index{interrupt vector table}
17464
17465 \end_inset 
17466
17467  entries for all ISR functions defined after the pragma.
17468  This is useful in cases where the interrupt vector table must be defined
17469  manually, or when there is a secondary, manually defined interrupt vector
17470  table (e.g.
17471  for the autovector feature of the Cypress EZ-USB FX2).
17472  More elegantly this can be achieved by obmitting the optional interrupt
17473  number after the interrupt keyword, see section 
17474 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
17475
17476 \end_inset 
17477
17478 \SpecialChar ~
17479 about interrupts.
17480 \layout Itemize
17481
17482
17483 \series bold 
17484 nojtbound
17485 \series default 
17486
17487 \begin_inset LatexCommand \index{\#pragma nojtbound}
17488
17489 \end_inset 
17490
17491  - will not generate code for boundary value checking, when switch statements
17492  are turned into jump-tables (dangerous).
17493  For more details see section 
17494 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
17495
17496 \end_inset 
17497
17498 .
17499 \layout Itemize
17500
17501
17502 \series bold 
17503 noloopreverse
17504 \series default 
17505
17506 \begin_inset LatexCommand \index{\#pragma noloopreverse}
17507
17508 \end_inset 
17509
17510  - Will not do loop reversal optimization
17511 \layout Itemize
17512
17513
17514 \series bold 
17515 nooverlay
17516 \series default 
17517
17518 \begin_inset LatexCommand \index{\#pragma nooverlay}
17519
17520 \end_inset 
17521
17522  - the compiler will not overlay the parameters and local variables of a
17523  function.
17524 \layout Itemize
17525
17526
17527 \series bold 
17528 stackauto
17529 \series default 
17530
17531 \begin_inset LatexCommand \index{\#pragma stackauto}
17532
17533 \end_inset 
17534
17535 - See option -
17536 \begin_inset ERT
17537 status Collapsed
17538
17539 \layout Standard
17540
17541 \backslash 
17542 /
17543 \end_inset 
17544
17545 -stack-auto
17546 \begin_inset LatexCommand \index{-\/-stack-auto}
17547
17548 \end_inset 
17549
17550  and section 
17551 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
17552
17553 \end_inset 
17554
17555  Parameters and Local Variables.
17556 \layout Itemize
17557
17558
17559 \series bold 
17560 opt_code_speed
17561 \series default 
17562  
17563 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
17564
17565 \end_inset 
17566
17567 - The compiler will optimize code generation towards fast code, possibly
17568  at the expense of code size.
17569  Currently this has little effect.
17570 \layout Itemize
17571
17572
17573 \series bold 
17574 opt_code_size
17575 \series default 
17576  
17577 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
17578
17579 \end_inset 
17580
17581 - The compiler will optimize code generation towards compact code, possibly
17582  at the expense of code speed.
17583  Currently this has little effect.
17584 \layout Itemize
17585
17586
17587 \series bold 
17588 opt_code_balanced
17589 \series default 
17590  
17591 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
17592
17593 \end_inset 
17594
17595 - The compiler will attempt to generate code that is both compact and fast,
17596  as long as meeting one goal is not a detriment to the other (this is the
17597  default).
17598  
17599 \layout Itemize
17600
17601
17602 \series bold 
17603 std_sdcc89
17604 \series default 
17605  
17606 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
17607
17608 \end_inset 
17609
17610 - Generally follow the C89 standard, but allow SDCC features that conflict
17611  with the standard (default).
17612 \layout Itemize
17613
17614
17615 \series bold 
17616 std_c89
17617 \series default 
17618  
17619 \begin_inset LatexCommand \index{\#pragma std\_c89}
17620
17621 \end_inset 
17622
17623 - Follow the C89 standard and disable SDCC features that conflict with the
17624  standard.
17625 \layout Itemize
17626
17627
17628 \series bold 
17629 std_sdcc99
17630 \series default 
17631  
17632 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
17633
17634 \end_inset 
17635
17636 - Generally follow the C99 standard, but allow SDCC features that conflict
17637  with the standard (incomplete support).
17638 \layout Itemize
17639
17640
17641 \series bold 
17642 std_c99
17643 \series default 
17644  
17645 \begin_inset LatexCommand \index{\#pragma std\_c99}
17646
17647 \end_inset 
17648
17649 - Follow the C99 standard and disable SDCC features that conflict with the
17650  standard (incomplete support).
17651 \layout Itemize
17652
17653
17654 \series bold 
17655 codeseg
17656 \series default 
17657  <name>
17658 \begin_inset LatexCommand \index{\#pragma codeseg}
17659
17660 \end_inset 
17661
17662 - Use this name (max.
17663  8 characters) for the code segment.
17664  See option -
17665 \begin_inset ERT
17666 status Collapsed
17667
17668 \layout Standard
17669
17670 \backslash 
17671 /
17672 \end_inset 
17673
17674 -codeseg.
17675 \layout Itemize
17676
17677
17678 \series bold 
17679 constseg
17680 \series default 
17681  <name>
17682 \begin_inset LatexCommand \index{\#pragma constseg}
17683
17684 \end_inset 
17685
17686 - Use this name (max.
17687  8 characters) for the const segment.
17688  See option -
17689 \begin_inset ERT
17690 status Collapsed
17691
17692 \layout Standard
17693
17694 \backslash 
17695 /
17696 \end_inset 
17697
17698 -constseg.
17699 \layout Standard
17700
17701 The preprocessor SDCPP
17702 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
17703
17704 \end_inset 
17705
17706  supports the following #pragma directives:
17707 \layout Itemize
17708
17709
17710 \series bold 
17711 pedantic_parse_number
17712 \series default 
17713
17714 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17715
17716 \end_inset 
17717
17718  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
17719  parsed properly and the macro LO_B(3) gets expanded.
17720  Default is off.
17721  Below is an example on how to use this pragma.
17722
17723 \emph on 
17724  Note: this functionality is not in conformance with standard!
17725 \layout Verse
17726
17727
17728 \family typewriter 
17729 #pragma pedantic_parse_number +
17730 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17731
17732 \end_inset 
17733
17734
17735 \newline 
17736
17737 \newline 
17738 #define LO_B(x) ((x) & 0xff)
17739 \newline 
17740
17741 \newline 
17742 unsigned char foo(void)
17743 \newline 
17744 {
17745 \newline 
17746 \SpecialChar ~
17747 \SpecialChar ~
17748 \SpecialChar ~
17749 unsigned char c=0xfe-LO_B(3);
17750 \newline 
17751
17752 \newline 
17753 \SpecialChar ~
17754 \SpecialChar ~
17755 \SpecialChar ~
17756 return c;
17757 \newline 
17758 }
17759 \newline 
17760
17761 \layout Itemize
17762
17763
17764 \series bold 
17765 preproc_asm
17766 \series default 
17767
17768 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17769
17770 \end_inset 
17771
17772  (+ | -) - switch _asm _endasm block preprocessing on / off.
17773  Default is on.
17774  You use this prama to define multilines of assembly code.
17775  This will prevent the preprocessor from changing the formating required
17776  by assembly code.
17777  Below is an example on how to use this pragma.
17778 \layout Verse
17779
17780
17781 \family typewriter 
17782 #pragma preproc_asm -
17783 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17784
17785 \end_inset 
17786
17787
17788 \newline 
17789 #define MYDELAY _asm
17790 \newline 
17791 \SpecialChar ~
17792 \SpecialChar ~
17793 \SpecialChar ~
17794 nop ;my assembly comment...
17795 \newline 
17796 \SpecialChar ~
17797 \SpecialChar ~
17798 \SpecialChar ~
17799 nop
17800 \newline 
17801 \SpecialChar ~
17802 \SpecialChar ~
17803 \SpecialChar ~
17804 nop
17805 \newline 
17806 _endasm
17807 \newline 
17808 #pragma preproc_asm +
17809 \newline 
17810
17811 \newline 
17812 void foo (void) 
17813 \newline 
17814
17815 \newline 
17816 \SpecialChar ~
17817 \SpecialChar ~
17818 \SpecialChar ~
17819  ...
17820  
17821 \newline 
17822 \SpecialChar ~
17823 \SpecialChar ~
17824 \SpecialChar ~
17825  MYDELAY;
17826 \newline 
17827 \SpecialChar ~
17828 \SpecialChar ~
17829 \SpecialChar ~
17830  ...
17831  
17832 \newline 
17833
17834 \newline 
17835
17836 \layout Itemize
17837
17838
17839 \series bold 
17840 sdcc_hash
17841 \series default 
17842
17843 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17844
17845 \end_inset 
17846
17847  (+ | -) - Allow "naked" hash in macro definition, for example:
17848 \newline 
17849
17850 \family typewriter 
17851 #define DIR_LO(x) #(x & 0xff)
17852 \family default 
17853
17854 \newline 
17855 Default is off.
17856  Below is an example on how to use this pragma.
17857 \layout Verse
17858
17859
17860 \family typewriter 
17861 #pragma preproc_asm +
17862 \newline 
17863 #pragma sdcc_hash +
17864 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17865
17866 \end_inset 
17867
17868
17869 \newline 
17870
17871 \newline 
17872 #define ROMCALL(x) 
17873 \backslash 
17874
17875 \newline 
17876 \SpecialChar ~
17877 \SpecialChar ~
17878 \SpecialChar ~
17879 mov R6_B3, #(x & 0xff) 
17880 \backslash 
17881
17882 \newline 
17883 \SpecialChar ~
17884 \SpecialChar ~
17885 \SpecialChar ~
17886 mov R7_B3, #((x >> 8) & 0xff) 
17887 \backslash 
17888
17889 \newline 
17890 \SpecialChar ~
17891 \SpecialChar ~
17892 \SpecialChar ~
17893 lcall __romcall
17894 \newline 
17895
17896 \newline 
17897 ...
17898 \newline 
17899 _asm
17900 \newline 
17901 ROMCALL(72)
17902 \newline 
17903 _endasm;
17904 \newline 
17905 ...
17906 \newline 
17907
17908 \layout Standard
17909
17910 The pragma's are intended to be used to turn-on or off certain optimizations
17911  which might cause the compiler to generate extra stack / data space to
17912  store compiler generated temporary variables.
17913  This usually happens in large functions.
17914  Pragma directives should be used as shown in the following example, they
17915  are used to control options & optimizations for a given function; pragmas
17916  should be placed before and/or after a function, placing pragma's inside
17917  a function body could have unpredictable results.
17918 \layout Verse
17919
17920
17921 \family typewriter 
17922 #pragma save
17923 \begin_inset LatexCommand \index{\#pragma save}
17924
17925 \end_inset 
17926
17927  \SpecialChar ~
17928 \SpecialChar ~
17929 \SpecialChar ~
17930 \SpecialChar ~
17931 \SpecialChar ~
17932 \SpecialChar ~
17933 \SpecialChar ~
17934 /* save the current settings */ 
17935 \newline 
17936 #pragma nogcse
17937 \begin_inset LatexCommand \index{\#pragma nogcse}
17938
17939 \end_inset 
17940
17941  \SpecialChar ~
17942 \SpecialChar ~
17943 \SpecialChar ~
17944 \SpecialChar ~
17945 \SpecialChar ~
17946 /* turnoff global subexpression elimination */ 
17947 \newline 
17948 #pragma noinduction
17949 \begin_inset LatexCommand \index{\#pragma noinduction}
17950
17951 \end_inset 
17952
17953  /* turn off induction optimizations */ 
17954 \newline 
17955 int foo () 
17956 \newline 
17957
17958 \newline 
17959 \SpecialChar ~
17960  \SpecialChar ~
17961  ...
17962  
17963 \newline 
17964 \SpecialChar ~
17965  \SpecialChar ~
17966  /* large code */ 
17967 \newline 
17968 \SpecialChar ~
17969  \SpecialChar ~
17970  ...
17971  
17972 \newline 
17973
17974 \newline 
17975 #pragma restore
17976 \begin_inset LatexCommand \index{\#pragma restore}
17977
17978 \end_inset 
17979
17980  /* turn the optimizations back on */
17981 \layout Standard
17982
17983 The compiler will generate a warning message when extra space is allocated.
17984  It is strongly recommended that the save and restore pragma's be used when
17985  changing options for a function.
17986 \newline 
17987
17988 \newline 
17989
17990 \newline 
17991
17992 \layout Section
17993
17994 Defines Created by the Compiler
17995 \layout Standard
17996
17997 The compiler creates the following #defines
17998 \begin_inset LatexCommand \index{\#defines}
17999
18000 \end_inset 
18001
18002
18003 \begin_inset LatexCommand \index{Defines created by the compiler}
18004
18005 \end_inset 
18006
18007 :
18008 \newline 
18009
18010 \layout Standard
18011
18012
18013 \begin_inset  Tabular
18014 <lyxtabular version="3" rows="11" columns="2">
18015 <features>
18016 <column alignment="left" valignment="top" leftline="true" width="3in">
18017 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
18018 <row topline="true" bottomline="true">
18019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18020 \begin_inset Text
18021
18022 \layout Standard
18023
18024
18025 \series bold 
18026 #define
18027 \end_inset 
18028 </cell>
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18030 \begin_inset Text
18031
18032 \layout Standard
18033
18034
18035 \series bold 
18036 Description
18037 \end_inset 
18038 </cell>
18039 </row>
18040 <row topline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18042 \begin_inset Text
18043
18044 \layout Standard
18045
18046 SDCC
18047 \begin_inset LatexCommand \index{SDCC}
18048
18049 \end_inset 
18050
18051  
18052 \end_inset 
18053 </cell>
18054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18055 \begin_inset Text
18056
18057 \layout Standard
18058
18059 Always defined.
18060  Since version 2.5.6 the version number as an int (ex.
18061  256)
18062 \end_inset 
18063 </cell>
18064 </row>
18065 <row topline="true">
18066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18067 \begin_inset Text
18068
18069 \layout Standard
18070
18071 SDCC_mcs51
18072 \begin_inset LatexCommand \index{SDCC\_mcs51}
18073
18074 \end_inset 
18075
18076  or SDCC_ds390
18077 \begin_inset LatexCommand \index{SDCC\_ds390}
18078
18079 \end_inset 
18080
18081  or SDCC_z80
18082 \begin_inset LatexCommand \index{SDCC\_z80}
18083
18084 \end_inset 
18085
18086 , etc.
18087 \end_inset 
18088 </cell>
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18090 \begin_inset Text
18091
18092 \layout Standard
18093
18094 depending on the model used (e.g.: -mds390)
18095 \end_inset 
18096 </cell>
18097 </row>
18098 <row topline="true">
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18100 \begin_inset Text
18101
18102 \layout Standard
18103
18104 __mcs51
18105 \begin_inset LatexCommand \index{\_\_mcs51}
18106
18107 \end_inset 
18108
18109 , __ds390
18110 \begin_inset LatexCommand \index{\_\_ds390}
18111
18112 \end_inset 
18113
18114 , __hc08
18115 \begin_inset LatexCommand \index{\_\_hc08}
18116
18117 \end_inset 
18118
18119 , __z80
18120 \begin_inset LatexCommand \index{\_\_z80}
18121
18122 \end_inset 
18123
18124 , etc
18125 \end_inset 
18126 </cell>
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18128 \begin_inset Text
18129
18130 \layout Standard
18131
18132 depending on the model used (e.g.
18133  -mz80)
18134 \end_inset 
18135 </cell>
18136 </row>
18137 <row topline="true">
18138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18139 \begin_inset Text
18140
18141 \layout Standard
18142
18143 SDCC_STACK_AUTO
18144 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
18145
18146 \end_inset 
18147
18148
18149 \end_inset 
18150 </cell>
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18152 \begin_inset Text
18153
18154 \layout Standard
18155
18156 when 
18157 \emph on 
18158 -
18159 \begin_inset ERT
18160 status Collapsed
18161
18162 \layout Standard
18163
18164 \backslash 
18165 /
18166 \end_inset 
18167
18168 -stack-auto
18169 \emph default 
18170  option is used
18171 \end_inset 
18172 </cell>
18173 </row>
18174 <row topline="true">
18175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18176 \begin_inset Text
18177
18178 \layout Standard
18179
18180 SDCC_MODEL_SMALL
18181 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
18182
18183 \end_inset 
18184
18185
18186 \end_inset 
18187 </cell>
18188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18189 \begin_inset Text
18190
18191 \layout Standard
18192
18193 when 
18194 \emph on 
18195 -
18196 \begin_inset ERT
18197 status Collapsed
18198
18199 \layout Standard
18200
18201 \backslash 
18202 /
18203 \end_inset 
18204
18205 -model-small
18206 \emph default 
18207  is used
18208 \end_inset 
18209 </cell>
18210 </row>
18211 <row topline="true">
18212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18213 \begin_inset Text
18214
18215 \layout Standard
18216
18217 SDCC_MODEL_MEDIUM
18218 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
18219
18220 \end_inset 
18221
18222
18223 \end_inset 
18224 </cell>
18225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18226 \begin_inset Text
18227
18228 \layout Standard
18229
18230 when 
18231 \emph on 
18232 -
18233 \begin_inset ERT
18234 status Collapsed
18235
18236 \layout Standard
18237
18238 \backslash 
18239 /
18240 \end_inset 
18241
18242 -model-medium
18243 \emph default 
18244  is used
18245 \end_inset 
18246 </cell>
18247 </row>
18248 <row topline="true">
18249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18250 \begin_inset Text
18251
18252 \layout Standard
18253
18254 SDCC_MODEL_LARGE
18255 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
18256
18257 \end_inset 
18258
18259
18260 \end_inset 
18261 </cell>
18262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18263 \begin_inset Text
18264
18265 \layout Standard
18266
18267 when 
18268 \emph on 
18269 -
18270 \begin_inset ERT
18271 status Collapsed
18272
18273 \layout Standard
18274
18275 \backslash 
18276 /
18277 \end_inset 
18278
18279 -model-large
18280 \emph default 
18281  is used
18282 \end_inset 
18283 </cell>
18284 </row>
18285 <row topline="true">
18286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18287 \begin_inset Text
18288
18289 \layout Standard
18290
18291 SDCC_USE_XSTACK
18292 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
18293
18294 \end_inset 
18295
18296
18297 \end_inset 
18298 </cell>
18299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18300 \begin_inset Text
18301
18302 \layout Standard
18303
18304 when 
18305 \emph on 
18306 -
18307 \begin_inset ERT
18308 status Collapsed
18309
18310 \layout Standard
18311
18312 \backslash 
18313 /
18314 \end_inset 
18315
18316 -xstack
18317 \emph default 
18318  option is used
18319 \end_inset 
18320 </cell>
18321 </row>
18322 <row topline="true">
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18324 \begin_inset Text
18325
18326 \layout Standard
18327
18328 SDCC_STACK_TENBIT
18329 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
18330
18331 \end_inset 
18332
18333  
18334 \end_inset 
18335 </cell>
18336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18337 \begin_inset Text
18338
18339 \layout Standard
18340
18341 when 
18342 \emph on 
18343 -mds390
18344 \emph default 
18345  is used
18346 \end_inset 
18347 </cell>
18348 </row>
18349 <row topline="true" bottomline="true">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18351 \begin_inset Text
18352
18353 \layout Standard
18354
18355 SDCC_MODEL_FLAT24
18356 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
18357
18358 \end_inset 
18359
18360
18361 \end_inset 
18362 </cell>
18363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18364 \begin_inset Text
18365
18366 \layout Standard
18367
18368 when 
18369 \emph on 
18370 -mds390
18371 \emph default 
18372  is used
18373 \end_inset 
18374 </cell>
18375 </row>
18376 </lyxtabular>
18377
18378 \end_inset 
18379
18380
18381 \layout Chapter
18382
18383 Notes on supported Processors
18384 \layout Section
18385
18386 MCS51 variants
18387 \begin_inset LatexCommand \label{sub:MCS51-variants}
18388
18389 \end_inset 
18390
18391
18392 \begin_inset LatexCommand \index{MCS51 variants}
18393
18394 \end_inset 
18395
18396
18397 \layout Standard
18398
18399 MCS51 processors are available from many vendors and come in many different
18400  flavours.
18401  While they might differ considerably in respect to Special Function Registers
18402  the core MCS51 is usually not modified or is kept compatible.
18403  
18404 \layout Subsection
18405
18406 pdata access by SFR 
18407 \layout Standard
18408
18409 With the upcome of devices with internal xdata and flash memory devices
18410  using port P2
18411 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18412
18413 \end_inset 
18414
18415  as dedicated I/O port is becoming more popular.
18416  Switching the high byte for pdata
18417 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18418
18419 \end_inset 
18420
18421  access which was formerly done by port P2 is then achieved by a Special
18422  Function Register
18423 \begin_inset LatexCommand \index{sfr}
18424
18425 \end_inset 
18426
18427 .
18428  In well-established MCS51 tradition the address of this 
18429 \emph on 
18430 sfr
18431 \emph default 
18432  is where the chip designers decided to put it.
18433  Needless to say that they didn't agree on a common name either.
18434  So that the startup code can correctly initialize xdata variables, you
18435  should define an sfr with the name _XPAGE
18436 \family typewriter 
18437
18438 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
18439
18440 \end_inset 
18441
18442
18443 \family default 
18444  at the appropriate location if the default, port P2, is not used for this.
18445  Some examples are:
18446 \layout Verse
18447
18448
18449 \family typewriter 
18450 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
18451 \layout Verse
18452
18453
18454 \family typewriter 
18455 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
18456 \layout Verse
18457
18458
18459 \family typewriter 
18460 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
18461 \layout Standard
18462
18463 For more exotic implementations further customizations may be needed.
18464  See section 
18465 \begin_inset LatexCommand \ref{sub:Startup-Code}
18466
18467 \end_inset 
18468
18469  for other possibilities.
18470 \layout Subsection
18471
18472 Other Features available by SFR
18473 \layout Standard
18474 \added_space_bottom bigskip 
18475 Some MCS51 variants offer features like Double DPTR
18476 \begin_inset LatexCommand \index{DPTR}
18477
18478 \end_inset 
18479
18480 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
18481  These are currently not used for the MCS51 port.
18482  If you absolutely need them you can fall back to inline assembly or submit
18483  a patch to SDCC.
18484 \layout Section
18485
18486 DS400 port
18487 \layout Standard
18488 \added_space_bottom bigskip 
18489 The DS80C400
18490 \begin_inset LatexCommand \index{DS80C400}
18491
18492 \end_inset 
18493
18494
18495 \begin_inset LatexCommand \index{DS400}
18496
18497 \end_inset 
18498
18499  microcontroller has a rich set of peripherals.
18500  In its built-in ROM library it includes functions to access some of the
18501  features, among them is a TCP stack with IP4 and IP6 support.
18502  Library headers (currently in beta status) and other files are provided
18503  at 
18504 \size footnotesize 
18505
18506 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
18507
18508 \end_inset 
18509
18510 .
18511  
18512 \layout Section
18513
18514 The Z80 and gbz80 port
18515 \layout Standard
18516
18517 SDCC can target both the Zilog Z80
18518 \begin_inset LatexCommand \index{Z80}
18519
18520 \end_inset 
18521
18522  and the Nintendo Gameboy's Z80-like gbz80
18523 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
18524
18525 \end_inset 
18526
18527 .
18528  The Z80 port is passed through the same 
18529 \emph on 
18530 regressions tests
18531 \begin_inset LatexCommand \index{Regression test}
18532
18533 \end_inset 
18534
18535
18536 \emph default 
18537  (see section 
18538 \begin_inset LatexCommand \ref{sec:Quality-control}
18539
18540 \end_inset 
18541
18542 ) as the MCS51 and DS390 ports, so floating point support, support for long
18543  variables and bitfield support is fine.
18544  See mailing lists and forums about interrupt routines.
18545 \layout Standard
18546 \added_space_bottom bigskip 
18547 As always, the code is the authoritative reference - see z80/ralloc.c and
18548  z80/gen.c.
18549  The stack
18550 \begin_inset LatexCommand \index{Z80!stack}
18551
18552 \end_inset 
18553
18554  frame is similar to that generated by the IAR Z80 compiler.
18555  IX is used as the base pointer, HL and IY are used as a temporary registers,
18556  and BC and DE are available for holding variables.
18557  Return values
18558 \begin_inset LatexCommand \index{Z80!return value}
18559
18560 \end_inset 
18561
18562  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
18563  bytes).
18564  The gbz80 port use the same set of registers for the return values, but
18565  in a different order of significance: E (one byte), DE (two bytes), or
18566  HLDE (four bytes).
18567 \layout Section
18568
18569 The HC08 port
18570 \layout Standard
18571
18572 The port to the Freescale/Motorola HC08
18573 \begin_inset LatexCommand \index{HC08}
18574
18575 \end_inset 
18576
18577  family has been added in October 2003, and is still undergoing some basic
18578  development.
18579  The code generator is complete, but the register allocation is still quite
18580  unoptimized.
18581  Some of the SDCC's standard C library functions have embedded non-HC08
18582  inline assembly and so are not yet usable.
18583 \layout Standard
18584 \added_space_bottom bigskip 
18585 The HC08 port passes the regression test suite (see section 
18586 \begin_inset LatexCommand \ref{sec:Quality-control}
18587
18588 \end_inset 
18589
18590 ).
18591 \layout Section
18592 \pagebreak_top 
18593 The PIC14 port
18594 \layout Standard
18595
18596 The 14bit PIC
18597 \begin_inset LatexCommand \index{PIC14}
18598
18599 \end_inset 
18600
18601  port still requires a major effort from the development community.
18602  However it can work for simple code.
18603  It passes its (smaller set of) regression tests
18604 \begin_inset LatexCommand \index{Regression test (PIC14)}
18605
18606 \end_inset 
18607
18608  in the directory 
18609 \shape italic 
18610 sdcc/src/regression
18611 \shape default 
18612 .
18613 \layout Subsection
18614
18615 C code and 14bit PIC code page
18616 \begin_inset LatexCommand \index{code page (pic14)}
18617
18618 \end_inset 
18619
18620  and RAM banks
18621 \begin_inset LatexCommand \index{RAM bank (pic14)}
18622
18623 \end_inset 
18624
18625
18626 \layout Standard
18627
18628 The linker organizes allocation for the code page and RAM banks.
18629  It does not have intimate knowledge of the code flow.
18630  It will put all the code section of a single asm file into a single code
18631  page.
18632  In order to make use of multiple code pages, separate asm files must be
18633  used.
18634  The compiler treats all functions of a single C file as being in the same
18635  code page unless it is non static.
18636 \newline 
18637
18638 \newline 
18639 To get the best follow these guide lines:
18640 \layout Enumerate
18641
18642 Make local functions static, as non static functions require code page selection
18643  overhead.
18644 \layout Enumerate
18645
18646 For devices that have multiple code pages it is more efficient to use the
18647  same number of files as pages, i.e.
18648  for the 16F877 use 4 separate files and i.e.
18649  for the 16F874 use 2 separate files.
18650  This way the linker can put the code for each file into different code
18651  pages and there's less page selection overhead.
18652 \layout Enumerate
18653
18654  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
18655  instruction set), use 'unsigned char' whereever possible instead of 'int'.
18656 \layout Subsection
18657
18658 Creating a device include file 
18659 \layout Standard
18660
18661 For generating a device include file
18662 \begin_inset LatexCommand \index{PIC14!Header files}
18663
18664 \end_inset 
18665
18666  use the support perl script inc2h.pl kept in directory support/script.
18667 \layout Subsection
18668
18669 Interrupt code
18670 \layout Standard
18671
18672 For the interrupt function, use the keyword '__interrupt'
18673 \begin_inset LatexCommand \index{PIC14!interrupt}
18674
18675 \end_inset 
18676
18677  with level number of 0 (PIC14 only has 1 interrupt so this number is only
18678  there to avoid a syntax error - it ought to be fixed).
18679  E.g.:
18680 \layout Verse
18681
18682
18683 \family typewriter 
18684 void Intr(void) __interrupt 0
18685 \newline 
18686 {
18687 \newline 
18688 \SpecialChar ~
18689 \SpecialChar ~
18690 T0IF = 0; /* Clear timer interrupt */
18691 \newline 
18692 }
18693 \layout Subsection
18694
18695 Linking and assembling
18696 \layout Standard
18697
18698 For assembling you can use either GPUTILS'
18699 \begin_inset LatexCommand \index{gputils (pic tools)}
18700
18701 \end_inset 
18702
18703  gpasm.exe or MPLAB's mpasmwin.exe.
18704  GPUTILS is available from 
18705 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18706
18707 \end_inset 
18708
18709 .
18710  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
18711  If you use MPLAB and an interrupt function then the linker script file
18712  vectors section will need to be enlarged to link with mplink.
18713 \newline 
18714
18715 \newline 
18716 Here is a 
18717 \family typewriter 
18718 Makefile
18719 \family default 
18720  using GPUTILS:
18721 \layout Verse
18722
18723
18724 \family typewriter 
18725 .c.o:
18726 \newline 
18727 \SpecialChar ~
18728 \SpecialChar ~
18729 \SpecialChar ~
18730 \SpecialChar ~
18731 \SpecialChar ~
18732 \SpecialChar ~
18733 \SpecialChar ~
18734 \SpecialChar ~
18735 sdcc -S -V -mpic14 -p16F877 $< 
18736 \newline 
18737 \SpecialChar ~
18738 \SpecialChar ~
18739 \SpecialChar ~
18740 \SpecialChar ~
18741 \SpecialChar ~
18742 \SpecialChar ~
18743 \SpecialChar ~
18744 \SpecialChar ~
18745 gpasm -c $*.asm
18746 \newline 
18747
18748 \newline 
18749 $(PRJ).hex: $(OBJS) 
18750 \newline 
18751 \SpecialChar ~
18752 \SpecialChar ~
18753 \SpecialChar ~
18754 \SpecialChar ~
18755 \SpecialChar ~
18756 \SpecialChar ~
18757 \SpecialChar ~
18758 \SpecialChar ~
18759 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
18760 \layout Standard
18761
18762 Here is a 
18763 \family typewriter 
18764 Makefile
18765 \family default 
18766  using MPLAB:
18767 \layout Verse
18768
18769
18770 \family typewriter 
18771 .c.o: 
18772 \newline 
18773 \SpecialChar ~
18774 \SpecialChar ~
18775 \SpecialChar ~
18776 \SpecialChar ~
18777 \SpecialChar ~
18778 \SpecialChar ~
18779 \SpecialChar ~
18780 \SpecialChar ~
18781 sdcc -S -V -mpic14 -p16F877 $< 
18782 \newline 
18783 \SpecialChar ~
18784 \SpecialChar ~
18785 \SpecialChar ~
18786 \SpecialChar ~
18787 \SpecialChar ~
18788 \SpecialChar ~
18789 \SpecialChar ~
18790 \SpecialChar ~
18791 mpasmwin /q /o $*.asm
18792 \newline 
18793
18794 \newline 
18795 $(PRJ).hex: $(OBJS) 
18796 \newline 
18797 \SpecialChar ~
18798 \SpecialChar ~
18799 \SpecialChar ~
18800 \SpecialChar ~
18801 \SpecialChar ~
18802 \SpecialChar ~
18803 \SpecialChar ~
18804 \SpecialChar ~
18805 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
18806 \layout Standard
18807
18808 Please note that indentations within a
18809 \family typewriter 
18810  Makefile
18811 \family default 
18812  have to be done with a tabulator character.
18813 \layout Subsection
18814
18815 Command-line options
18816 \layout Standard
18817
18818 Besides the switches common to all SDCC backends, the PIC14 port accepts
18819  the following options (for an updated list see sdcc -
18820 \begin_inset ERT
18821 status Collapsed
18822
18823 \layout Standard
18824
18825 \backslash 
18826 /
18827 \end_inset 
18828
18829 -help):
18830 \layout List
18831 \labelwidthstring 00.00.0000
18832
18833 -
18834 \begin_inset ERT
18835 status Collapsed
18836
18837 \layout Standard
18838
18839 \backslash 
18840 /
18841 \end_inset 
18842
18843 -debug-extra
18844 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
18845
18846 \end_inset 
18847
18848  emit debug info in assembly output
18849 \layout List
18850 \labelwidthstring 00.00.0000
18851
18852 -
18853 \begin_inset ERT
18854 status Collapsed
18855
18856 \layout Standard
18857
18858 \backslash 
18859 /
18860 \end_inset 
18861
18862 -no-pcode-opt
18863 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
18864
18865 \end_inset 
18866
18867  disable (slightly faulty) optimization on pCode
18868 \layout List
18869 \labelwidthstring 00.00.0000
18870
18871 -
18872 \begin_inset ERT
18873 status Collapsed
18874
18875 \layout Standard
18876
18877 \backslash 
18878 /
18879 \end_inset 
18880
18881 -stack-loc
18882 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
18883
18884 \end_inset 
18885
18886  sets the lowest address of the argument passing stack (defaults to a suitably
18887  large shared databank to reduce BANKSEL overhead)
18888 \layout List
18889 \labelwidthstring 00.00.0000
18890
18891 -
18892 \begin_inset ERT
18893 status Collapsed
18894
18895 \layout Standard
18896
18897 \backslash 
18898 /
18899 \end_inset 
18900
18901 -stack-size
18902 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
18903
18904 \end_inset 
18905
18906  sets the size if the argument passing stack (default: 16, minimum: 4)
18907 \layout Subsection
18908
18909 The library
18910 \layout Subsubsection
18911
18912 error: missing definition for symbol 
18913 \begin_inset Quotes sld
18914 \end_inset 
18915
18916 __gptrget1
18917 \begin_inset Quotes srd
18918 \end_inset 
18919
18920
18921 \layout Standard
18922
18923 The PIC14 port uses library routines to provide more complex operations
18924  like multiplication, division/modulus and (generic) pointer dereferencing.
18925  In order to add these routines to your project, you must link with PIC14's
18926  
18927 \family typewriter 
18928 libsdcc.lib
18929 \family default 
18930 .
18931  For single source file projects this is done automatically, more complex
18932  projects must add 
18933 \family typewriter 
18934 libsdcc.lib
18935 \family default 
18936  to the linker's arguments.
18937  Make sure you also add an include path for the library (using the -I switch
18938  to the linker)!
18939 \layout Subsubsection
18940
18941 Processor mismatch in file 
18942 \begin_inset Quotes sld
18943 \end_inset 
18944
18945 XXX
18946 \begin_inset Quotes srd
18947 \end_inset 
18948
18949 .
18950 \layout Standard
18951
18952 This warning can usually be ignored due to the very good compatibility amongst
18953  14 bit PIC
18954 \begin_inset LatexCommand \index{PIC14}
18955
18956 \end_inset 
18957
18958  devices.
18959 \layout Standard
18960
18961 You might also consider recompiling the library for your specific device
18962  by changing the ARCH=p16f877 (default target) entry in 
18963 \family typewriter 
18964 device/lib/pic/Makefile.in
18965 \family default 
18966  and 
18967 \family typewriter 
18968 device/lib/pic/Makefile
18969 \family default 
18970  to reflect your device.
18971  This might even improve performance for smaller devices as unneccesary
18972  BANKSELs migth be removed.
18973 \layout Subsection
18974
18975 Known bugs
18976 \layout Subsubsection
18977
18978 initialized data
18979 \layout Standard
18980
18981 Currently, data can only be initialized if it resides in the source file
18982  together with 
18983 \emph on 
18984 main()
18985 \emph default 
18986 .
18987  Data in other source files will silently 
18988 \series bold 
18989 not
18990 \series default 
18991  be initialized.
18992 \family typewriter 
18993 \size footnotesize 
18994
18995 \begin_inset Marginal
18996 collapsed true
18997
18998 \layout Standard
18999
19000
19001 \series bold 
19002 \SpecialChar ~
19003 !
19004 \end_inset 
19005
19006
19007 \layout Section
19008 \pagebreak_top 
19009 The PIC16
19010 \begin_inset LatexCommand \index{PIC16}
19011
19012 \end_inset 
19013
19014  port
19015 \layout Standard
19016
19017 The PIC16
19018 \begin_inset LatexCommand \index{PIC16}
19019
19020 \end_inset 
19021
19022  port is the portion of SDCC that is responsible to produce code for the
19023  Microchip
19024 \begin_inset LatexCommand \index{Microchip}
19025
19026 \end_inset 
19027
19028 (TM) microcontrollers with 16 bit core.
19029  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
19030  Currently supported devices are:
19031 \layout Standard
19032 \align center 
19033
19034 \begin_inset  Tabular
19035 <lyxtabular version="3" rows="4" columns="6">
19036 <features>
19037 <column alignment="center" valignment="top" leftline="true" width="0">
19038 <column alignment="center" valignment="top" leftline="true" width="0">
19039 <column alignment="center" valignment="top" leftline="true" width="0">
19040 <column alignment="center" valignment="top" leftline="true" width="0">
19041 <column alignment="center" valignment="top" leftline="true" width="0">
19042 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19043 <row topline="true">
19044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19045 \begin_inset Text
19046
19047 \layout Standard
19048
19049 18F242
19050 \end_inset 
19051 </cell>
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19053 \begin_inset Text
19054
19055 \layout Standard
19056
19057 18F248
19058 \end_inset 
19059 </cell>
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19061 \begin_inset Text
19062
19063 \layout Standard
19064
19065 18F252
19066 \end_inset 
19067 </cell>
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19069 \begin_inset Text
19070
19071 \layout Standard
19072
19073 18F258
19074 \end_inset 
19075 </cell>
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19077 \begin_inset Text
19078
19079 \layout Standard
19080
19081 18F442
19082 \end_inset 
19083 </cell>
19084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19085 \begin_inset Text
19086
19087 \layout Standard
19088
19089 18F448
19090 \end_inset 
19091 </cell>
19092 </row>
19093 <row topline="true">
19094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19095 \begin_inset Text
19096
19097 \layout Standard
19098
19099 18F452
19100 \end_inset 
19101 </cell>
19102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19103 \begin_inset Text
19104
19105 \layout Standard
19106
19107 18F458
19108 \end_inset 
19109 </cell>
19110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19111 \begin_inset Text
19112
19113 \layout Standard
19114
19115 18F1220
19116 \end_inset 
19117 </cell>
19118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19119 \begin_inset Text
19120
19121 \layout Standard
19122
19123 18F2220
19124 \end_inset 
19125 </cell>
19126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19127 \begin_inset Text
19128
19129 \layout Standard
19130
19131 18F2550
19132 \end_inset 
19133 </cell>
19134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19135 \begin_inset Text
19136
19137 \layout Standard
19138
19139 18F4331
19140 \end_inset 
19141 </cell>
19142 </row>
19143 <row topline="true">
19144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19145 \begin_inset Text
19146
19147 \layout Standard
19148
19149 18F4455
19150 \end_inset 
19151 </cell>
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19153 \begin_inset Text
19154
19155 \layout Standard
19156
19157 18F6520
19158 \end_inset 
19159 </cell>
19160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19161 \begin_inset Text
19162
19163 \layout Standard
19164
19165 18F6620
19166 \end_inset 
19167 </cell>
19168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19169 \begin_inset Text
19170
19171 \layout Standard
19172
19173 18F6680
19174 \end_inset 
19175 </cell>
19176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19177 \begin_inset Text
19178
19179 \layout Standard
19180
19181 18F6720
19182 \end_inset 
19183 </cell>
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19185 \begin_inset Text
19186
19187 \layout Standard
19188
19189 18F8520
19190 \end_inset 
19191 </cell>
19192 </row>
19193 <row topline="true" bottomline="true">
19194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19195 \begin_inset Text
19196
19197 \layout Standard
19198
19199 18F8620
19200 \end_inset 
19201 </cell>
19202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19203 \begin_inset Text
19204
19205 \layout Standard
19206
19207 18F8680
19208 \end_inset 
19209 </cell>
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19211 \begin_inset Text
19212
19213 \layout Standard
19214
19215 18F8720
19216 \end_inset 
19217 </cell>
19218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19219 \begin_inset Text
19220
19221 \layout Standard
19222
19223 \end_inset 
19224 </cell>
19225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19226 \begin_inset Text
19227
19228 \layout Standard
19229
19230 \end_inset 
19231 </cell>
19232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19233 \begin_inset Text
19234
19235 \layout Standard
19236
19237 \end_inset 
19238 </cell>
19239 </row>
19240 </lyxtabular>
19241
19242 \end_inset 
19243
19244
19245 \layout Subsection
19246
19247 Global Options
19248 \layout Standard
19249
19250 PIC16 port supports the standard command line arguments as supposed, with
19251  the exception of certain cases that will be mentioned in the following
19252  list:
19253 \layout List
19254 \labelwidthstring 00.00.0000
19255
19256 -
19257 \begin_inset ERT
19258 status Collapsed
19259
19260 \layout Standard
19261
19262 \backslash 
19263 /
19264 \end_inset 
19265
19266 -callee-saves
19267 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
19268
19269 \end_inset 
19270
19271  See -
19272 \begin_inset ERT
19273 status Collapsed
19274
19275 \layout Standard
19276
19277 \backslash 
19278 /
19279 \end_inset 
19280
19281 -all-callee-saves
19282 \layout List
19283 \labelwidthstring 00.00.0000
19284
19285 -
19286 \begin_inset ERT
19287 status Collapsed
19288
19289 \layout Standard
19290
19291 \backslash 
19292 /
19293 \end_inset 
19294
19295 -all-callee-saves
19296 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
19297
19298 \end_inset 
19299
19300  All function arguments are passed on stack by default.
19301  
19302 \emph on 
19303 There is no need to specify this in the command line.
19304 \layout List
19305 \labelwidthstring 00.00.0000
19306
19307 -
19308 \begin_inset ERT
19309 status Collapsed
19310
19311 \layout Standard
19312
19313 \backslash 
19314 /
19315 \end_inset 
19316
19317 -fommit-frame-pointer
19318 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
19319
19320 \end_inset 
19321
19322  Frame pointer will be omitted when the function uses no local variables.
19323 \layout Subsection
19324
19325 Port Specific Options
19326 \begin_inset LatexCommand \index{Options PIC16}
19327
19328 \end_inset 
19329
19330
19331 \layout Standard
19332
19333 The port specific options appear after the global options in the sdcc --help
19334  output.
19335 \layout Subsubsection
19336
19337 General Options
19338 \layout Standard
19339
19340 General options enable certain port features and optimizations.
19341 \layout List
19342 \labelwidthstring 00.00.0000
19343
19344 -
19345 \begin_inset ERT
19346 status Collapsed
19347
19348 \layout Standard
19349
19350 \backslash 
19351 /
19352 \end_inset 
19353
19354 -pstack-model=[model] Used in conjuction with the command above.
19355  Defines the stack model to be used, valid stack models are : 
19356 \begin_deeper 
19357 \layout List
19358 \labelwidthstring 00.00.0000
19359
19360
19361 \emph on 
19362 small
19363 \emph default 
19364  Selects small stack model.
19365  8 bit stack and frame pointers.
19366  Supports 256 bytes stack size.
19367 \layout List
19368 \labelwidthstring 00.00.0000
19369
19370
19371 \emph on 
19372 large
19373 \emph default 
19374  Selects large stack model.
19375  16 bit stack and frame pointers.
19376  Supports 65536 bytes stack size.
19377 \end_deeper 
19378 \layout List
19379 \labelwidthstring 00.00.0000
19380
19381 -
19382 \begin_inset ERT
19383 status Collapsed
19384
19385 \layout Standard
19386
19387 \backslash 
19388 /
19389 \end_inset 
19390
19391 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
19392  unitialized data variables with [kword].
19393  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
19394 \layout List
19395 \labelwidthstring 00.00.0000
19396
19397 -
19398 \begin_inset ERT
19399 status Collapsed
19400
19401 \layout Standard
19402
19403 \backslash 
19404 /
19405 \end_inset 
19406
19407 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
19408  Useful for bootloaders.
19409 \layout List
19410 \labelwidthstring 00.00.0000
19411
19412 -
19413 \begin_inset ERT
19414 status Collapsed
19415
19416 \layout Standard
19417
19418 \backslash 
19419 /
19420 \end_inset 
19421
19422 -asm= sets the full path and name of an external assembler to call.
19423 \layout List
19424 \labelwidthstring 00.00.0000
19425
19426 -
19427 \begin_inset ERT
19428 status Collapsed
19429
19430 \layout Standard
19431
19432 \backslash 
19433 /
19434 \end_inset 
19435
19436 -link= sets the full path and name of an external linker to call.
19437 \layout List
19438 \labelwidthstring 00.00.0000
19439
19440 -
19441 \begin_inset ERT
19442 status Collapsed
19443
19444 \layout Standard
19445
19446 \backslash 
19447 /
19448 \end_inset 
19449
19450 -mplab-comp MPLAB
19451 \begin_inset LatexCommand \index{PIC16!MPLAB}
19452
19453 \end_inset 
19454
19455  compatibility option.
19456  Currently only suppresses special gpasm directives.
19457 \layout Subsubsection
19458
19459 Optimization Options
19460 \layout List
19461 \labelwidthstring 00.00.0000
19462
19463 -
19464 \begin_inset ERT
19465 status Collapsed
19466
19467 \layout Standard
19468
19469 \backslash 
19470 /
19471 \end_inset 
19472
19473 -optimize-goto Try to use (conditional) BRA instead of GOTO
19474 \layout List
19475 \labelwidthstring 00.00.0000
19476
19477 -
19478 \begin_inset ERT
19479 status Collapsed
19480
19481 \layout Standard
19482
19483 \backslash 
19484 /
19485 \end_inset 
19486
19487 -optimize-cmp Try to optimize some compares.
19488 \layout List
19489 \labelwidthstring 00.00.0000
19490
19491 -
19492 \begin_inset ERT
19493 status Collapsed
19494
19495 \layout Standard
19496
19497 \backslash 
19498 /
19499 \end_inset 
19500
19501 -optimize-df Analyze the dataflow of the generated code and improve it.
19502 \layout List
19503 \labelwidthstring 00.00.0000
19504
19505 -
19506 \begin_inset ERT
19507 status Collapsed
19508
19509 \layout Standard
19510
19511 \backslash 
19512 /
19513 \end_inset 
19514
19515 -obanksel=nn Set optimization level for inserting BANKSELs.
19516 \newline 
19517
19518 \begin_deeper 
19519 \layout List
19520 \labelwidthstring 00.00.0000
19521
19522 0 no optimization
19523 \layout List
19524 \labelwidthstring 00.00.0000
19525
19526 1 checks previous used register and if it is the same then does not emit
19527  BANKSEL, accounts only for labels.
19528 \layout List
19529 \labelwidthstring 00.00.0000
19530
19531 2 tries to check the location of (even different) symbols and removes BANKSELs
19532  if they are in the same bank.
19533  
19534 \newline 
19535
19536 \emph on 
19537 Important: There might be problems if the linker script has data sections
19538  across bank borders!
19539 \end_deeper 
19540 \layout Subsubsection
19541
19542 Linking Options
19543 \layout List
19544 \labelwidthstring 00.00.0000
19545
19546 -
19547 \begin_inset ERT
19548 status Collapsed
19549
19550 \layout Standard
19551
19552 \backslash 
19553 /
19554 \end_inset 
19555
19556 -nodefaultlibs do not link default libraries when linking
19557 \layout List
19558 \labelwidthstring 00.00.0000
19559
19560 -
19561 \begin_inset ERT
19562 status Collapsed
19563
19564 \layout Standard
19565
19566 \backslash 
19567 /
19568 \end_inset 
19569
19570 -no-crt Don't link the default run-time modules
19571 \layout List
19572 \labelwidthstring 00.00.0000
19573
19574 -
19575 \begin_inset ERT
19576 status Collapsed
19577
19578 \layout Standard
19579
19580 \backslash 
19581 /
19582 \end_inset 
19583
19584 -use-crt= Use a custom run-time module instead of the defaults.
19585 \layout Subsubsection
19586
19587 Debugging Options
19588 \layout Standard
19589
19590 Debugging options enable extra debugging information in the output files.
19591 \layout List
19592 \labelwidthstring 00.00.0000
19593
19594 -
19595 \begin_inset ERT
19596 status Collapsed
19597
19598 \layout Standard
19599
19600 \backslash 
19601 /
19602 \end_inset 
19603
19604 -debug-xtra Similar to -
19605 \begin_inset ERT
19606 status Collapsed
19607
19608 \layout Standard
19609
19610 \backslash 
19611 /
19612 \end_inset 
19613
19614 -debug
19615 \begin_inset LatexCommand \index{-\/-debug}
19616
19617 \end_inset 
19618
19619 , but dumps more information.
19620 \layout List
19621 \labelwidthstring 00.00.0000
19622
19623 -
19624 \begin_inset ERT
19625 status Collapsed
19626
19627 \layout Standard
19628
19629 \backslash 
19630 /
19631 \end_inset 
19632
19633 -debug-ralloc Force register allocator to dump <source>.d file with debugging
19634  information.
19635  <source> is the name of the file compiled.
19636 \layout List
19637 \labelwidthstring 00.00.0000
19638
19639 -
19640 \begin_inset ERT
19641 status Collapsed
19642
19643 \layout Standard
19644
19645 \backslash 
19646 /
19647 \end_inset 
19648
19649 -pcode-verbose Enable pcode debugging information in translation.
19650 \layout List
19651 \labelwidthstring 00.00.0000
19652
19653 -
19654 \begin_inset ERT
19655 status Collapsed
19656
19657 \layout Standard
19658
19659 \backslash 
19660 /
19661 \end_inset 
19662
19663 -denable-peeps Force the usage of peepholes.
19664  Use with care.
19665 \layout List
19666 \labelwidthstring 00.00.0000
19667
19668 -
19669 \begin_inset ERT
19670 status Collapsed
19671
19672 \layout Standard
19673
19674 \backslash 
19675 /
19676 \end_inset 
19677
19678 -gstack Trace push/pops for stack pointer overflow
19679 \layout List
19680 \labelwidthstring 00.00.0000
19681
19682 -
19683 \begin_inset ERT
19684 status Collapsed
19685
19686 \layout Standard
19687
19688 \backslash 
19689 /
19690 \end_inset 
19691
19692 -call-tree dump call tree in .calltree file
19693 \layout Subsection
19694
19695 Enviromental Variables
19696 \layout Standard
19697
19698 There is a number of enviromental variables that can be used when running
19699  SDCC to enable certain optimizations or force a specific program behaviour.
19700  these variables are primarily for debugging purposes so they can be enabled/dis
19701 abled at will.
19702 \layout Standard
19703
19704 Currently there is only two such variables available:
19705 \layout List
19706 \labelwidthstring 00.00.0000
19707
19708 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
19709  bitfields is optimized by directly loading FSR0 with the address of the
19710  bitfield structure.
19711  Normally SDCC will cast the bitfield structure to a bitfield pointer and
19712  then load FSR0.
19713  This step saves data ram and code space for functions that perform heavy
19714  use of bitfields.
19715  (ie.
19716  80 bytes of code space are saved when compiling malloc.c with this option).
19717  
19718 \layout List
19719 \labelwidthstring 00.00.0000
19720
19721 NO_REG_OPT do not perform pCode registers optimization.
19722  This should be used for debugging purposes.
19723  In some where bugs in the pcode optimizer are found, users can benefit
19724  from temporarily disabling the optimizer until the bug is fixed.
19725 \layout Subsection
19726
19727 Preprocessor Macros
19728 \layout Standard
19729
19730 PIC16
19731 \begin_inset LatexCommand \index{PIC16}
19732
19733 \end_inset 
19734
19735  port defines the following preprocessor macros while translating a source.
19736 \layout Standard
19737 \align center 
19738
19739 \begin_inset  Tabular
19740 <lyxtabular version="3" rows="6" columns="2">
19741 <features>
19742 <column alignment="center" valignment="top" leftline="true" width="0">
19743 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19744 <row topline="true" bottomline="true">
19745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19746 \begin_inset Text
19747
19748 \layout Standard
19749
19750 Macro
19751 \end_inset 
19752 </cell>
19753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19754 \begin_inset Text
19755
19756 \layout Standard
19757
19758 Description
19759 \end_inset 
19760 </cell>
19761 </row>
19762 <row topline="true">
19763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19764 \begin_inset Text
19765
19766 \layout Standard
19767
19768 SDCC_pic16
19769 \end_inset 
19770 </cell>
19771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19772 \begin_inset Text
19773
19774 \layout Standard
19775
19776 Port identification
19777 \end_inset 
19778 </cell>
19779 </row>
19780 <row topline="true">
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19782 \begin_inset Text
19783
19784 \layout Standard
19785
19786 _
19787 \begin_inset ERT
19788 status Collapsed
19789
19790 \layout Standard
19791
19792 \backslash 
19793 /
19794 \end_inset 
19795
19796 _pic16
19797 \end_inset 
19798 </cell>
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19800 \begin_inset Text
19801
19802 \layout Standard
19803
19804 Port identification (same as above)
19805 \end_inset 
19806 </cell>
19807 </row>
19808 <row topline="true">
19809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19810 \begin_inset Text
19811
19812 \layout Standard
19813
19814 pic18fxxxx
19815 \end_inset 
19816 </cell>
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19818 \begin_inset Text
19819
19820 \layout Standard
19821
19822 MCU Identification.
19823  
19824 \emph on 
19825 xxxx
19826 \emph default 
19827  is the microcontrol identification number, i.e.
19828  452, 6620, etc
19829 \end_inset 
19830 </cell>
19831 </row>
19832 <row topline="true">
19833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 \begin_inset Text
19835
19836 \layout Standard
19837
19838 _
19839 \begin_inset ERT
19840 status Collapsed
19841
19842 \layout Standard
19843
19844 \backslash 
19845 /
19846 \end_inset 
19847
19848 _18Fxxxx
19849 \end_inset 
19850 </cell>
19851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19852 \begin_inset Text
19853
19854 \layout Standard
19855
19856 MCU Identification (same as above)
19857 \end_inset 
19858 </cell>
19859 </row>
19860 <row topline="true" bottomline="true">
19861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19862 \begin_inset Text
19863
19864 \layout Standard
19865
19866 STACK_MODEL_nnn
19867 \end_inset 
19868 </cell>
19869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19870 \begin_inset Text
19871
19872 \layout Standard
19873
19874 nnn = SMALL or LARGE respectively according to the stack model used
19875 \end_inset 
19876 </cell>
19877 </row>
19878 </lyxtabular>
19879
19880 \end_inset 
19881
19882
19883 \layout Standard
19884
19885 In addition the following macros are defined when calling assembler:
19886 \layout Standard
19887 \align center 
19888
19889 \begin_inset  Tabular
19890 <lyxtabular version="3" rows="4" columns="2">
19891 <features>
19892 <column alignment="center" valignment="top" leftline="true" width="0">
19893 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19894 <row topline="true" bottomline="true">
19895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19896 \begin_inset Text
19897
19898 \layout Standard
19899
19900 Macro
19901 \end_inset 
19902 </cell>
19903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19904 \begin_inset Text
19905
19906 \layout Standard
19907
19908 Description
19909 \end_inset 
19910 </cell>
19911 </row>
19912 <row topline="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19914 \begin_inset Text
19915
19916 \layout Standard
19917
19918 __18Fxxxx
19919 \end_inset 
19920 </cell>
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19922 \begin_inset Text
19923
19924 \layout Standard
19925
19926 MCU Identification.
19927  
19928 \emph on 
19929 xxxx
19930 \emph default 
19931  is the microcontrol identification number, i.e.
19932  452, 6620, etc
19933 \end_inset 
19934 </cell>
19935 </row>
19936 <row topline="true">
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19938 \begin_inset Text
19939
19940 \layout Standard
19941
19942 SDCC_MODEL_nnn
19943 \end_inset 
19944 </cell>
19945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19946 \begin_inset Text
19947
19948 \layout Standard
19949
19950 nnn = SMALL or LARGE respectively according to the memory model used for
19951  SDCC
19952 \end_inset 
19953 </cell>
19954 </row>
19955 <row topline="true" bottomline="true">
19956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19957 \begin_inset Text
19958
19959 \layout Standard
19960
19961 STACK_MODEL_nnn
19962 \end_inset 
19963 </cell>
19964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19965 \begin_inset Text
19966
19967 \layout Standard
19968
19969 nnn = SMALL or LARGE respectively according to the stack model used
19970 \end_inset 
19971 </cell>
19972 </row>
19973 </lyxtabular>
19974
19975 \end_inset 
19976
19977
19978 \layout Subsection
19979
19980 Directories
19981 \layout Standard
19982
19983 PIC16
19984 \begin_inset LatexCommand \index{PIC16}
19985
19986 \end_inset 
19987
19988  port uses the following directories for searching header files and libraries.
19989 \layout Standard
19990 \align center 
19991
19992 \begin_inset  Tabular
19993 <lyxtabular version="3" rows="3" columns="4">
19994 <features>
19995 <column alignment="center" valignment="top" leftline="true" width="0">
19996 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19997 <column alignment="center" valignment="top" width="0">
19998 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19999 <row topline="true" bottomline="true">
20000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20001 \begin_inset Text
20002
20003 \layout Standard
20004
20005 Directory
20006 \end_inset 
20007 </cell>
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20009 \begin_inset Text
20010
20011 \layout Standard
20012
20013 Description
20014 \end_inset 
20015 </cell>
20016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20017 \begin_inset Text
20018
20019 \layout Standard
20020
20021 Target
20022 \end_inset 
20023 </cell>
20024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20025 \begin_inset Text
20026
20027 \layout Standard
20028
20029 Command prefix
20030 \end_inset 
20031 </cell>
20032 </row>
20033 <row topline="true">
20034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20035 \begin_inset Text
20036
20037 \layout Standard
20038
20039 PREFIX/sdcc/include/pic16
20040 \end_inset 
20041 </cell>
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20043 \begin_inset Text
20044
20045 \layout Standard
20046
20047 PIC16 specific headers
20048 \end_inset 
20049 </cell>
20050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20051 \begin_inset Text
20052
20053 \layout Standard
20054
20055 Compiler
20056 \end_inset 
20057 </cell>
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20059 \begin_inset Text
20060
20061 \layout Standard
20062
20063 -I
20064 \end_inset 
20065 </cell>
20066 </row>
20067 <row topline="true" bottomline="true">
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20069 \begin_inset Text
20070
20071 \layout Standard
20072
20073 PREFIX/sdcc/lib/pic16
20074 \end_inset 
20075 </cell>
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20077 \begin_inset Text
20078
20079 \layout Standard
20080
20081 PIC16 specific libraries
20082 \end_inset 
20083 </cell>
20084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20085 \begin_inset Text
20086
20087 \layout Standard
20088
20089 Linker
20090 \end_inset 
20091 </cell>
20092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20093 \begin_inset Text
20094
20095 \layout Standard
20096
20097 -L
20098 \end_inset 
20099 </cell>
20100 </row>
20101 </lyxtabular>
20102
20103 \end_inset 
20104
20105
20106 \layout Subsection
20107
20108 Pragmas
20109 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
20110
20111 \end_inset 
20112
20113
20114 \layout Standard
20115
20116 PIC16
20117 \begin_inset LatexCommand \index{PIC16}
20118
20119 \end_inset 
20120
20121  port currently supports the following pragmas:
20122 \layout List
20123 \labelwidthstring 00.00.0000
20124
20125 stack
20126 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
20127
20128 \end_inset 
20129
20130  pragma stack
20131 \begin_inset LatexCommand \index{PIC16!stack}
20132
20133 \end_inset 
20134
20135  forces the code generator to initialize the stack & frame pointers at a
20136  specific address.
20137  This is an adhoc solution for cases where no STACK directive is available
20138  in the linker script or gplink is not instructed to create a stack section.
20139 \newline 
20140 The stack pragma should be used only once in a project.
20141  Multiple pragmas may result in indeterminate behaviour of the program.
20142 \begin_inset Foot
20143 collapsed false
20144
20145 \layout Standard
20146
20147 The old format (ie.
20148  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
20149  cross page boundaries (or even exceed the available data RAM) and crash
20150  the program.
20151  Make sure that stack does not cross page boundaries when using the SMALL
20152  stack model.
20153 \end_inset 
20154
20155
20156 \newline 
20157 The format is as follows:
20158 \layout LyX-Code
20159
20160 #pragma stack bottom_address [stack_size]
20161 \layout Standard
20162
20163
20164 \emph on 
20165 bottom_address
20166 \emph default 
20167  is the lower bound of the stack section.
20168  The stack pointer initially will point at address (bottom_address+stack_size-1).
20169 \layout LyX-Code
20170
20171 Example:
20172 \layout LyX-Code
20173
20174 \layout LyX-Code
20175
20176 /* initializes stack of 100 bytes at RAM address 0x200 */
20177 \layout LyX-Code
20178
20179 #pragma stack 0x200 100
20180 \layout Standard
20181
20182 If the stack_size field is omitted then a stack is created with the default
20183  size of 64.
20184  This size might be enough for most programs, but its not enough for operations
20185  with deep function nesting or excessive stack usage.
20186 \layout List
20187 \labelwidthstring 00.00.0000
20188
20189 code
20190 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
20191
20192 \end_inset 
20193
20194  place a function symbol at static FLASH address
20195 \layout LyX-Code
20196
20197 Example:
20198 \layout LyX-Code
20199
20200 \layout LyX-Code
20201
20202 /* place function test_func at 0x4000 */
20203 \layout LyX-Code
20204
20205 #pragma code test_func 0x4000
20206 \layout LyX-Code
20207
20208 \layout List
20209 \labelwidthstring 00.00.0000
20210
20211 library instructs the linker to use a library module.
20212 \newline 
20213 Usage:
20214 \layout LyX-Code
20215
20216 #pragma library module_name
20217 \layout Standard
20218
20219
20220 \emph on 
20221 module_name
20222 \emph default 
20223  can be any library or object file (including its path).
20224  Note that there are four reserved keywords which have special meaning.
20225  These are:
20226 \layout Standard
20227 \align center 
20228
20229 \begin_inset  Tabular
20230 <lyxtabular version="3" rows="6" columns="3">
20231 <features>
20232 <column alignment="center" valignment="top" leftline="true" width="0">
20233 <column alignment="block" valignment="top" leftline="true" width="20page%">
20234 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20235 <row topline="true" bottomline="true">
20236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20237 \begin_inset Text
20238
20239 \layout Standard
20240
20241 Keyword
20242 \end_inset 
20243 </cell>
20244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20245 \begin_inset Text
20246
20247 \layout Standard
20248
20249 Description
20250 \end_inset 
20251 </cell>
20252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20253 \begin_inset Text
20254
20255 \layout Standard
20256
20257 Module to link
20258 \end_inset 
20259 </cell>
20260 </row>
20261 <row topline="true">
20262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20263 \begin_inset Text
20264
20265 \layout Standard
20266
20267
20268 \series bold 
20269 ignore
20270 \end_inset 
20271 </cell>
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20273 \begin_inset Text
20274
20275 \layout Standard
20276
20277 ignore all library pragmas
20278 \end_inset 
20279 </cell>
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20281 \begin_inset Text
20282
20283 \layout Standard
20284
20285
20286 \emph on 
20287 (none)
20288 \end_inset 
20289 </cell>
20290 </row>
20291 <row topline="true">
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20293 \begin_inset Text
20294
20295 \layout Standard
20296
20297
20298 \series bold 
20299 c
20300 \end_inset 
20301 </cell>
20302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20303 \begin_inset Text
20304
20305 \layout Standard
20306
20307 link the C library
20308 \end_inset 
20309 </cell>
20310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20311 \begin_inset Text
20312
20313 \layout Standard
20314
20315
20316 \emph on 
20317 libc18f
20318 \emph default 
20319 .lib
20320 \end_inset 
20321 </cell>
20322 </row>
20323 <row topline="true">
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20325 \begin_inset Text
20326
20327 \layout Standard
20328
20329
20330 \series bold 
20331 math
20332 \end_inset 
20333 </cell>
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20335 \begin_inset Text
20336
20337 \layout Standard
20338
20339 link the Math libarary
20340 \end_inset 
20341 </cell>
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20343 \begin_inset Text
20344
20345 \layout Standard
20346
20347
20348 \emph on 
20349 libm18f
20350 \emph default 
20351 .lib
20352 \end_inset 
20353 </cell>
20354 </row>
20355 <row topline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_inset Text
20358
20359 \layout Standard
20360
20361
20362 \series bold 
20363 io
20364 \end_inset 
20365 </cell>
20366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20367 \begin_inset Text
20368
20369 \layout Standard
20370
20371 link the I/O library
20372 \end_inset 
20373 </cell>
20374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20375 \begin_inset Text
20376
20377 \layout Standard
20378
20379
20380 \emph on 
20381 libio18f*
20382 \emph default 
20383 .lib
20384 \end_inset 
20385 </cell>
20386 </row>
20387 <row topline="true" bottomline="true">
20388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20389 \begin_inset Text
20390
20391 \layout Standard
20392
20393
20394 \series bold 
20395 debug
20396 \end_inset 
20397 </cell>
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20399 \begin_inset Text
20400
20401 \layout Standard
20402
20403 link the debug library
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
20412 \emph on 
20413 libdebug
20414 \emph default 
20415 .lib
20416 \end_inset 
20417 </cell>
20418 </row>
20419 </lyxtabular>
20420
20421 \end_inset 
20422
20423
20424 \newline 
20425 * is the device number, i.e.
20426  452 for PIC18F452 MCU.
20427 \layout Standard
20428
20429 This feature allows for linking with specific libraries withoug having to
20430  explicit name them in the command line.
20431  Note that the 
20432 \noun on 
20433 ignore
20434 \noun default 
20435  keyword will reject all modules specified by the library pragma.
20436 \layout List
20437 \labelwidthstring 00.00.0000
20438
20439 udata pragma udata instructs the compiler to emit code so that linker will
20440  place a variable at a specific memory bank
20441 \layout LyX-Code
20442
20443 Example:
20444 \layout LyX-Code
20445
20446 \layout LyX-Code
20447
20448 /* places variable foo at bank2 */
20449 \layout LyX-Code
20450
20451 #pragma udata bank2 foo
20452 \layout LyX-Code
20453
20454 char foo;
20455 \layout Standard
20456
20457 In order for this pragma to work extra SECTION directives should be added
20458  in the .lkr script.
20459  In the following example a sample .lkr file is shown:
20460 \layout LyX-Code
20461
20462 \layout LyX-Code
20463
20464 // Sample linker script for the PIC18F452 processor
20465 \layout LyX-Code
20466
20467 LIBPATH .
20468 \layout LyX-Code
20469
20470 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
20471 \layout LyX-Code
20472
20473 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
20474 \layout LyX-Code
20475
20476 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
20477 \layout LyX-Code
20478
20479 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
20480 \layout LyX-Code
20481
20482 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
20483 \layout LyX-Code
20484
20485 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
20486 \layout LyX-Code
20487
20488 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
20489 \layout LyX-Code
20490
20491 \layout LyX-Code
20492
20493 DATABANK   NAME=gpr0       START=0x80           END=0xFF
20494 \layout LyX-Code
20495
20496 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
20497 \layout LyX-Code
20498
20499 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
20500 \layout LyX-Code
20501
20502 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
20503 \layout LyX-Code
20504
20505 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
20506 \layout LyX-Code
20507
20508 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
20509 \layout LyX-Code
20510
20511 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
20512 \layout LyX-Code
20513
20514 \layout LyX-Code
20515
20516 SECTION    NAME=CONFIG     ROM=config
20517 \layout LyX-Code
20518
20519 \layout LyX-Code
20520
20521 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
20522 \layout LyX-Code
20523
20524 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
20525 \layout LyX-Code
20526
20527 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
20528 \layout LyX-Code
20529
20530 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
20531 \layout LyX-Code
20532
20533 SECTION    NAME=bank4      RAM=gpr4
20534 \layout LyX-Code
20535
20536 SECTION    NAME=bank5      RAM=gpr5
20537 \layout Standard
20538
20539 The linker will recognise the section name set in the pragma statement and
20540  will position the variable at the memory bank set with the RAM field at
20541  the SECTION line in the linker script file.
20542 \layout Subsection
20543
20544 Header Files
20545 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
20546
20547 \end_inset 
20548
20549
20550 \layout Standard
20551
20552 There is one main header file
20553 \begin_inset LatexCommand \index{PIC16!Header files}
20554
20555 \end_inset 
20556
20557  that can be included to the source files using the pic16
20558 \begin_inset LatexCommand \index{PIC16}
20559
20560 \end_inset 
20561
20562  port.
20563  That file is the 
20564 \series bold 
20565 pic18fregs.h
20566 \series default 
20567 .
20568  This header file contains the definitions for the processor special registers,
20569  so it is necessary if the source accesses them.
20570  It can be included by adding the following line in the beginning of the
20571  file:
20572 \layout LyX-Code
20573
20574 #include <pic18fregs.h>
20575 \layout Standard
20576
20577 The specific microcontroller is selected within the pic18fregs.h automatically,
20578  so the same source can be used with a variety of devices.
20579 \layout Subsection
20580
20581 Libraries
20582 \layout Standard
20583
20584 The libraries
20585 \begin_inset LatexCommand \index{PIC16!Libraries}
20586
20587 \end_inset 
20588
20589  that PIC16
20590 \begin_inset LatexCommand \index{PIC16}
20591
20592 \end_inset 
20593
20594  port depends on are the microcontroller device libraries which contain
20595  the symbol definitions for the microcontroller special function registers.
20596  These libraries have the format pic18fxxxx.lib, where 
20597 \emph on 
20598 xxxx
20599 \emph default 
20600  is the microcontroller identification number.
20601  The specific library is selected automatically by the compiler at link
20602  stage according to the selected device.
20603 \layout Standard
20604
20605 Libraries are created with gplib which is part of the gputils package 
20606 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
20607
20608 \end_inset 
20609
20610 .
20611 \layout Subsubsection*
20612
20613 Building the libraries
20614 \layout Standard
20615
20616 Before using SDCC/pic16 there are some libraries that need to be compiled.
20617  This process is not done automatically by SDCC since not all users use
20618  SDCC for pic16 projects.
20619  So each user should compile the libraries separately.
20620 \layout Standard
20621
20622 The steps to compile the pic16 libraries under Linux are:
20623 \layout LyX-Code
20624
20625 cd device/lib/pic16
20626 \layout LyX-Code
20627
20628 ./configure
20629 \layout LyX-Code
20630
20631 make
20632 \layout LyX-Code
20633
20634 cd ..
20635 \layout LyX-Code
20636
20637 make model-pic16
20638 \layout LyX-Code
20639
20640 su -c 'make install'     # install the libraries, you need the root password
20641 \layout Standard
20642
20643 If you need to install the headers too, do:
20644 \layout LyX-Code
20645
20646 cd device/include
20647 \layout LyX-Code
20648
20649 su -c 'make install'     # install the headers, you need the root password
20650 \layout Standard
20651
20652 There exist a special target to build the I/O libraries.
20653  This target is not automatically build because it will build the I/O library
20654  for 
20655 \emph on 
20656 every
20657 \emph default 
20658  supported device.
20659  This way building will take quite a lot of time.
20660  Users are advised to edit the 
20661 \series bold 
20662 device/lib/pic16/pics.build
20663 \series default 
20664  file and then execute:
20665 \layout LyX-Code
20666
20667 make lib-io
20668 \layout Subsection
20669
20670 Memory Models
20671 \layout Standard
20672
20673 The following memory models are supported by the PIC16 port:
20674 \layout Itemize
20675
20676 small model
20677 \layout Itemize
20678
20679 large model
20680 \layout Standard
20681
20682 Memory model affects the default size of pointers within the source.
20683  The sizes are shown in the next table:
20684 \layout Standard
20685 \align center 
20686
20687 \begin_inset  Tabular
20688 <lyxtabular version="3" rows="3" columns="3">
20689 <features>
20690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20691 <column alignment="center" valignment="top" leftline="true" width="0">
20692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20693 <row topline="true" bottomline="true">
20694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20695 \begin_inset Text
20696
20697 \layout Standard
20698
20699 Pointer sizes according to memory model
20700 \end_inset 
20701 </cell>
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20703 \begin_inset Text
20704
20705 \layout Standard
20706
20707 small model
20708 \end_inset 
20709 </cell>
20710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20711 \begin_inset Text
20712
20713 \layout Standard
20714
20715 large model
20716 \end_inset 
20717 </cell>
20718 </row>
20719 <row topline="true" bottomline="true">
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20721 \begin_inset Text
20722
20723 \layout Standard
20724
20725 code pointers
20726 \end_inset 
20727 </cell>
20728 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20729 \begin_inset Text
20730
20731 \layout Standard
20732
20733 16-bits
20734 \end_inset 
20735 </cell>
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20737 \begin_inset Text
20738
20739 \layout Standard
20740
20741 24-bits
20742 \end_inset 
20743 </cell>
20744 </row>
20745 <row topline="true" bottomline="true">
20746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20747 \begin_inset Text
20748
20749 \layout Standard
20750
20751 data pointers
20752 \end_inset 
20753 </cell>
20754 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
20755 \begin_inset Text
20756
20757 \layout Standard
20758
20759 16-bits
20760 \end_inset 
20761 </cell>
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \layout Standard
20766
20767 16-bits
20768 \end_inset 
20769 </cell>
20770 </row>
20771 </lyxtabular>
20772
20773 \end_inset 
20774
20775
20776 \layout Standard
20777
20778 It is advisable that all sources within a project are compiled with the
20779  same memory model.
20780  If one wants to override the default memory model, this can be done by
20781  declaring a pointer as 
20782 \series bold 
20783 far
20784 \series default 
20785  or 
20786 \series bold 
20787 near
20788 \series default 
20789 .
20790  Far selects large memory model's pointers, while near selects small memory
20791  model's pointers.
20792 \layout Standard
20793
20794 The standard device libraries (see 
20795 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
20796
20797 \end_inset 
20798
20799 ) contain no reference to pointers, so they can be used with both memory
20800  models.
20801 \layout Subsection
20802
20803 Stack
20804 \layout Standard
20805
20806 The stack
20807 \begin_inset LatexCommand \index{PIC16!stack}
20808
20809 \end_inset 
20810
20811  implementation for the PIC16 port uses two indirect registers, FSR1 and
20812  FSR2.
20813 \layout List
20814 \labelwidthstring 00.00.0000
20815
20816 FSR1 is assigned as stack pointer
20817 \layout List
20818 \labelwidthstring 00.00.0000
20819
20820 FSR2 is assigned as frame pointer
20821 \layout Standard
20822
20823 The following stack models are supported by the PIC16 port
20824 \layout Itemize
20825
20826
20827 \noun on 
20828 small
20829 \noun default 
20830  model
20831 \layout Itemize
20832
20833
20834 \noun on 
20835 large
20836 \noun default 
20837  model
20838 \layout Standard
20839
20840
20841 \noun on 
20842 Small
20843 \noun default 
20844  model means that only the FSRxL byte is used to access stack and frame,
20845  while 
20846 \emph on 
20847 \noun on 
20848 large
20849 \emph default 
20850 \noun default 
20851  uses both FSRxL and FSRxH registers.
20852  The following table shows the stack/frame pointers sizes according to stack
20853  model and the maximum space they can address:
20854 \layout Standard
20855 \align center 
20856
20857 \begin_inset  Tabular
20858 <lyxtabular version="3" rows="3" columns="3">
20859 <features>
20860 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20861 <column alignment="center" valignment="top" leftline="true" width="0">
20862 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20863 <row topline="true" bottomline="true">
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20865 \begin_inset Text
20866
20867 \layout Standard
20868
20869 Stack & Frame pointer sizes according to stack model
20870 \end_inset 
20871 </cell>
20872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20873 \begin_inset Text
20874
20875 \layout Standard
20876
20877 small
20878 \end_inset 
20879 </cell>
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20881 \begin_inset Text
20882
20883 \layout Standard
20884
20885 large
20886 \end_inset 
20887 </cell>
20888 </row>
20889 <row topline="true">
20890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20891 \begin_inset Text
20892
20893 \layout Standard
20894
20895 Stack pointer FSR1
20896 \end_inset 
20897 </cell>
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20899 \begin_inset Text
20900
20901 \layout Standard
20902
20903 8-bits
20904 \end_inset 
20905 </cell>
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20907 \begin_inset Text
20908
20909 \layout Standard
20910
20911 16-bits
20912 \end_inset 
20913 </cell>
20914 </row>
20915 <row topline="true" bottomline="true">
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_inset Text
20918
20919 \layout Standard
20920
20921 Frame pointer FSR2
20922 \end_inset 
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \layout Standard
20928
20929 8-bits
20930 \end_inset 
20931 </cell>
20932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20933 \begin_inset Text
20934
20935 \layout Standard
20936
20937 16-bits
20938 \end_inset 
20939 </cell>
20940 </row>
20941 </lyxtabular>
20942
20943 \end_inset 
20944
20945
20946 \layout Standard
20947
20948
20949 \noun on 
20950 Large 
20951 \noun default 
20952 stack model is currently not working properly throughout the code generator.
20953  So its use is not advised.
20954  Also there are some other points that need special care:
20955 \newline 
20956
20957 \layout Enumerate
20958
20959 Do not create stack sections with size more than one physical bank (that
20960  is 256 bytes)
20961 \layout Enumerate
20962
20963 Stack sections should no cross physical bank limits (i.e.
20964  #pragma stack 0x50 0x100)
20965 \layout Standard
20966
20967 These limitations are caused by the fact that only FSRxL is modified when
20968  using SMALL stack model, so no more than 256 bytes of stack can be used.
20969  This problem will disappear after LARGE model is fully implemented.
20970 \layout Subsection
20971
20972 Functions
20973 \layout Standard
20974
20975 In addition to the standard SDCC function keywords, PIC16
20976 \begin_inset LatexCommand \index{PIC16}
20977
20978 \end_inset 
20979
20980  port makes available two more:
20981 \layout List
20982 \labelwidthstring 00.00.0000
20983
20984 wparam
20985 \begin_inset LatexCommand \index{PIC16!wparam}
20986
20987 \end_inset 
20988
20989  Use the WREG to pass one byte of the first function argument.
20990  This improves speed but you may not use this for functions with arguments
20991  that are called via function pointers, otherwise the first byte of the
20992  first parameter will get lost.
20993  Usage:
20994 \layout LyX-Code
20995
20996 void func_wparam(int a) wparam
20997 \layout LyX-Code
20998
20999 {
21000 \layout LyX-Code
21001
21002     /* WREG hold the lower part of a */
21003 \layout LyX-Code
21004
21005     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
21006  */
21007 \layout LyX-Code
21008
21009 ...
21010 \layout LyX-Code
21011
21012 }
21013 \layout List
21014 \labelwidthstring 00.00.0000
21015
21016 shadowregs
21017 \begin_inset LatexCommand \index{PIC16!shadowregs}
21018
21019 \end_inset 
21020
21021  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
21022  hardware shadow registers which hold the values of WREG, STATUS and BSR
21023  registers.
21024  This can be done by adding the keyword 
21025 \emph on 
21026 shadowregs
21027 \emph default 
21028  before the 
21029 \emph on 
21030 interrupt
21031 \emph default 
21032  keyword in the function's header.
21033 \layout LyX-Code
21034
21035 void isr_shadow(void) shadowregs interrupt 1
21036 \layout LyX-Code
21037
21038 {
21039 \layout LyX-Code
21040
21041 ...
21042 \layout LyX-Code
21043
21044 }
21045 \layout Standard
21046
21047
21048 \emph on 
21049 shadowregs
21050 \emph default 
21051  instructs the code generator not to store/restore WREG, STATUS, BSR when
21052  entering/exiting the ISR.
21053 \layout Subsection
21054
21055 Function return values
21056 \layout Standard
21057
21058 Return values from functions are placed to the appropriate registers following
21059  a modified Microchip policy optimized for SDCC.
21060  The following table shows these registers:
21061 \layout Standard
21062 \align center 
21063
21064 \begin_inset  Tabular
21065 <lyxtabular version="3" rows="6" columns="2">
21066 <features>
21067 <column alignment="center" valignment="top" leftline="true" width="0">
21068 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21069 <row topline="true" bottomline="true">
21070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21071 \begin_inset Text
21072
21073 \layout Standard
21074
21075 size
21076 \end_inset 
21077 </cell>
21078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21079 \begin_inset Text
21080
21081 \layout Standard
21082
21083 destination register
21084 \end_inset 
21085 </cell>
21086 </row>
21087 <row topline="true">
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21089 \begin_inset Text
21090
21091 \layout Standard
21092
21093 8 bits
21094 \end_inset 
21095 </cell>
21096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21097 \begin_inset Text
21098
21099 \layout Standard
21100
21101 WREG
21102 \end_inset 
21103 </cell>
21104 </row>
21105 <row topline="true">
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21107 \begin_inset Text
21108
21109 \layout Standard
21110
21111 16 bits
21112 \end_inset 
21113 </cell>
21114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21115 \begin_inset Text
21116
21117 \layout Standard
21118
21119 PRODL:WREG
21120 \end_inset 
21121 </cell>
21122 </row>
21123 <row topline="true">
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21125 \begin_inset Text
21126
21127 \layout Standard
21128
21129 24 bits
21130 \end_inset 
21131 </cell>
21132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21133 \begin_inset Text
21134
21135 \layout Standard
21136
21137 PRODH:PRODL:WREG
21138 \end_inset 
21139 </cell>
21140 </row>
21141 <row topline="true">
21142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21143 \begin_inset Text
21144
21145 \layout Standard
21146
21147 32 bits
21148 \end_inset 
21149 </cell>
21150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21151 \begin_inset Text
21152
21153 \layout Standard
21154
21155 FSR0L:PRODH:PRODL:WREG
21156 \end_inset 
21157 </cell>
21158 </row>
21159 <row topline="true" bottomline="true">
21160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21161 \begin_inset Text
21162
21163 \layout Standard
21164
21165 >32 bits
21166 \end_inset 
21167 </cell>
21168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21169 \begin_inset Text
21170
21171 \layout Standard
21172
21173 on stack, FSR0 points to the beginning
21174 \end_inset 
21175 </cell>
21176 </row>
21177 </lyxtabular>
21178
21179 \end_inset 
21180
21181
21182 \layout Subsection
21183
21184 Interrupts
21185 \layout Standard
21186
21187 An interrupt
21188 \begin_inset LatexCommand \index{PIC16!interrupt}
21189
21190 \end_inset 
21191
21192  service routine (ISR) is declared using the 
21193 \emph on 
21194 interrupt
21195 \emph default 
21196  keyword.
21197 \layout LyX-Code
21198
21199 void isr(void) interrupt 
21200 \emph on 
21201 n
21202 \layout LyX-Code
21203
21204 {
21205 \layout LyX-Code
21206
21207 ...
21208 \layout LyX-Code
21209
21210 }
21211 \layout Standard
21212
21213
21214 \emph on 
21215 n
21216 \emph default 
21217  is the interrupt number, which for PIC18F devices can be:
21218 \layout Standard
21219 \align center 
21220
21221 \begin_inset  Tabular
21222 <lyxtabular version="3" rows="4" columns="3">
21223 <features>
21224 <column alignment="center" valignment="top" leftline="true" width="0">
21225 <column alignment="center" valignment="top" leftline="true" width="0">
21226 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21227 <row topline="true" bottomline="true">
21228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21229 \begin_inset Text
21230
21231 \layout Standard
21232
21233
21234 \emph on 
21235 n
21236 \end_inset 
21237 </cell>
21238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21239 \begin_inset Text
21240
21241 \layout Standard
21242
21243 Interrupt Vector
21244 \end_inset 
21245 </cell>
21246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21247 \begin_inset Text
21248
21249 \layout Standard
21250
21251 Interrupt Vector Address
21252 \end_inset 
21253 </cell>
21254 </row>
21255 <row topline="true">
21256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21257 \begin_inset Text
21258
21259 \layout Standard
21260
21261 0
21262 \end_inset 
21263 </cell>
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21265 \begin_inset Text
21266
21267 \layout Standard
21268
21269 RESET vector
21270 \end_inset 
21271 </cell>
21272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21273 \begin_inset Text
21274
21275 \layout Standard
21276
21277 0x000000
21278 \end_inset 
21279 </cell>
21280 </row>
21281 <row topline="true">
21282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21283 \begin_inset Text
21284
21285 \layout Standard
21286
21287
21288 \family roman 
21289 \series medium 
21290 \shape up 
21291 \size normal 
21292 \emph off 
21293 \bar no 
21294 \noun off 
21295 \color none
21296 1
21297 \end_inset 
21298 </cell>
21299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21300 \begin_inset Text
21301
21302 \layout Standard
21303
21304
21305 \family roman 
21306 \series medium 
21307 \shape up 
21308 \size normal 
21309 \emph off 
21310 \bar no 
21311 \noun off 
21312 \color none
21313 HIGH priority interrupts
21314 \end_inset 
21315 </cell>
21316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21317 \begin_inset Text
21318
21319 \layout Standard
21320
21321 0x000008
21322 \end_inset 
21323 </cell>
21324 </row>
21325 <row topline="true" bottomline="true">
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21327 \begin_inset Text
21328
21329 \layout Standard
21330
21331 2
21332 \end_inset 
21333 </cell>
21334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21335 \begin_inset Text
21336
21337 \layout Standard
21338
21339 LOW priority interrupts
21340 \end_inset 
21341 </cell>
21342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21343 \begin_inset Text
21344
21345 \layout Standard
21346
21347 0x000018
21348 \end_inset 
21349 </cell>
21350 </row>
21351 </lyxtabular>
21352
21353 \end_inset 
21354
21355
21356 \layout Standard
21357
21358 When generating assembly code for ISR the code generator places a 
21359 \noun on 
21360 goto 
21361 \noun default 
21362 instruction at the 
21363 \emph on 
21364 Interrupt Vector Address
21365 \emph default 
21366  which points at the genetated ISR.
21367  This single GOTO instruction is part of an automatically generated 
21368 \emph on 
21369 interrupt entry point
21370 \emph default 
21371  function.
21372  The actuall ISR code is placed as normally would in the code space.
21373  Upon interrupt request, the GOTO instruction is executed which jumps to
21374  the ISR code.
21375  When declaring interrupt functions as _naked this GOTO instruction is 
21376 \series bold 
21377 not
21378 \series default 
21379  generated.
21380  The whole interrupt functions is therefore placed at the Interrupt Vector
21381  Address of the specific interrupt.
21382  This is not a problem for the LOW priority interrupts, but it is a problem
21383  for the RESET and the HIGH priority interrupts because code may be written
21384  at the next interrupt´s vector address and cause undeterminate program
21385  behaviour if that interrupt is raised.
21386 \begin_inset Foot
21387 collapsed false
21388
21389 \layout Standard
21390
21391 This is not a problem when
21392 \layout Enumerate
21393
21394 this is a HIGH interrupt ISR and LOW interrupts are 
21395 \emph on 
21396 disabled
21397 \emph default 
21398  or not used.
21399 \layout Enumerate
21400
21401 when the ISR is small enough not to reach the next interrupt´s vector address.
21402 \end_inset 
21403
21404
21405 \layout Standard
21406
21407
21408 \emph on 
21409 n
21410 \emph default 
21411  is possible to be omitted.
21412  This way a function is generated similar to an ISR, but it is not assigned
21413  to any interrupt.
21414 \layout Standard
21415
21416 When entering an interrupt, currently the PIC16
21417 \begin_inset LatexCommand \index{PIC16}
21418
21419 \end_inset 
21420
21421  port automatically saves the following registers:
21422 \layout Itemize
21423
21424 WREG
21425 \layout Itemize
21426
21427 STATUS
21428 \layout Itemize
21429
21430 BSR
21431 \layout Itemize
21432
21433 PROD (PRODL and PRODH)
21434 \layout Itemize
21435
21436 FSR0 (FSR0L and FSR0H)
21437 \layout Standard
21438
21439 These registers are restored upon return from the interrupt routine.
21440 \begin_inset Foot
21441 collapsed false
21442
21443 \layout Standard
21444
21445 NOTE that when the _naked attribute is specified for an interrupt routine,
21446  then NO registers are stored or restored.
21447 \end_inset 
21448
21449
21450 \layout Subsection
21451
21452 Generic Pointers
21453 \layout Standard
21454
21455 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
21456  There are 3 types of generic pointers currently implemented data, code
21457  and eeprom pointers.
21458  They are differentiated by the value of the 7th and 6th bits of the upper
21459  byte:
21460 \layout Standard
21461 \align center 
21462
21463 \begin_inset  Tabular
21464 <lyxtabular version="3" rows="5" columns="5">
21465 <features>
21466 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21467 <column alignment="center" valignment="top" width="0">
21468 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21469 <column alignment="center" valignment="top" width="0">
21470 <column alignment="left" valignment="top" rightline="true" width="0">
21471 <row topline="true" bottomline="true">
21472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21473 \begin_inset Text
21474
21475 \layout Standard
21476
21477 pointer type
21478 \end_inset 
21479 </cell>
21480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21481 \begin_inset Text
21482
21483 \layout Standard
21484
21485 7th bit
21486 \end_inset 
21487 </cell>
21488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21489 \begin_inset Text
21490
21491 \layout Standard
21492
21493 6th bit
21494 \end_inset 
21495 </cell>
21496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21497 \begin_inset Text
21498
21499 \layout Standard
21500
21501 rest of the pointer
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 description
21510 \end_inset 
21511 </cell>
21512 </row>
21513 <row topline="true" bottomline="true">
21514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21515 \begin_inset Text
21516
21517 \layout Standard
21518
21519 data 
21520 \end_inset 
21521 </cell>
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21523 \begin_inset Text
21524
21525 \layout Standard
21526
21527 1
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 0
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
21544 \family typewriter 
21545 \shape slanted 
21546 \emph on 
21547 uuuuuu uuuuxxxx xxxxxxxx
21548 \end_inset 
21549 </cell>
21550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21551 \begin_inset Text
21552
21553 \layout Standard
21554
21555 a 12-bit data pointer in data RAM memory
21556 \end_inset 
21557 </cell>
21558 </row>
21559 <row bottomline="true">
21560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21561 \begin_inset Text
21562
21563 \layout Standard
21564
21565 code
21566 \end_inset 
21567 </cell>
21568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21569 \begin_inset Text
21570
21571 \layout Standard
21572
21573 0
21574 \end_inset 
21575 </cell>
21576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21577 \begin_inset Text
21578
21579 \layout Standard
21580
21581 0
21582 \end_inset 
21583 </cell>
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21585 \begin_inset Text
21586
21587 \layout Standard
21588
21589
21590 \family typewriter 
21591 \shape slanted 
21592 \emph on 
21593 uxxxxx xxxxxxxx xxxxxxxx
21594 \end_inset 
21595 </cell>
21596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21597 \begin_inset Text
21598
21599 \layout Standard
21600
21601 a 21-bit code pointer in FLASH memory
21602 \end_inset 
21603 </cell>
21604 </row>
21605 <row bottomline="true">
21606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21607 \begin_inset Text
21608
21609 \layout Standard
21610
21611 eeprom
21612 \end_inset 
21613 </cell>
21614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21615 \begin_inset Text
21616
21617 \layout Standard
21618
21619 0
21620 \end_inset 
21621 </cell>
21622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21623 \begin_inset Text
21624
21625 \layout Standard
21626
21627 1
21628 \end_inset 
21629 </cell>
21630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21631 \begin_inset Text
21632
21633 \layout Standard
21634
21635
21636 \family typewriter 
21637 \shape slanted 
21638 \emph on 
21639 uuuuuu uuuuuuxx xxxxxxxx
21640 \end_inset 
21641 </cell>
21642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21643 \begin_inset Text
21644
21645 \layout Standard
21646
21647 a 10-bit eeprom pointer in EEPROM memory
21648 \end_inset 
21649 </cell>
21650 </row>
21651 <row bottomline="true">
21652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21653 \begin_inset Text
21654
21655 \layout Standard
21656
21657 (unimplemented)
21658 \end_inset 
21659 </cell>
21660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21661 \begin_inset Text
21662
21663 \layout Standard
21664
21665 1
21666 \end_inset 
21667 </cell>
21668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21669 \begin_inset Text
21670
21671 \layout Standard
21672
21673 1
21674 \end_inset 
21675 </cell>
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21677 \begin_inset Text
21678
21679 \layout Standard
21680
21681
21682 \family typewriter 
21683 \shape slanted 
21684 \emph on 
21685 xxxxxx xxxxxxxx xxxxxxxx
21686 \end_inset 
21687 </cell>
21688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21689 \begin_inset Text
21690
21691 \layout Standard
21692
21693 unimplemented pointer type
21694 \end_inset 
21695 </cell>
21696 </row>
21697 </lyxtabular>
21698
21699 \end_inset 
21700
21701
21702 \layout Standard
21703
21704 Generic pointer are read and written with a set of library functions which
21705  read/write 1, 2, 3, 4 bytes.
21706 \layout Subsection
21707
21708 PIC16 C Libraries
21709 \layout Subsubsection
21710
21711 Standard I/O Streams
21712 \layout Standard
21713
21714 In the 
21715 \emph on 
21716 stdio.h
21717 \emph default 
21718  the type FILE is defined as:
21719 \layout LyX-Code
21720
21721 typedef char * FILE;
21722 \layout Standard
21723
21724 This type is the stream type implemented I/O in the PIC18F devices.
21725  Also the standard input and output streams are declared in stdio.h:
21726 \layout LyX-Code
21727
21728 extern FILE * stdin;
21729 \layout LyX-Code
21730
21731 extern FILE * stdout;
21732 \layout Standard
21733
21734 The FILE type is actually a generic pointer which defines one more type
21735  of generic pointers, the 
21736 \emph on 
21737 stream 
21738 \emph default 
21739 pointer.
21740  This new type has the format:
21741 \layout Standard
21742 \align center 
21743
21744 \begin_inset  Tabular
21745 <lyxtabular version="3" rows="2" columns="7">
21746 <features>
21747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21748 <column alignment="center" valignment="top" width="0">
21749 <column alignment="center" valignment="top" leftline="true" width="0">
21750 <column alignment="center" valignment="top" leftline="true" width="0">
21751 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21752 <column alignment="center" valignment="top" width="0">
21753 <column alignment="left" valignment="top" rightline="true" width="0">
21754 <row topline="true" bottomline="true">
21755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21756 \begin_inset Text
21757
21758 \layout Standard
21759
21760 pointer type
21761 \end_inset 
21762 </cell>
21763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21764 \begin_inset Text
21765
21766 \layout Standard
21767
21768 <7:6>
21769 \end_inset 
21770 </cell>
21771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21772 \begin_inset Text
21773
21774 \layout Standard
21775
21776 <5>
21777 \end_inset 
21778 </cell>
21779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21780 \begin_inset Text
21781
21782 \layout Standard
21783
21784 <4>
21785 \end_inset 
21786 </cell>
21787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21788 \begin_inset Text
21789
21790 \layout Standard
21791
21792 <3:0>
21793 \end_inset 
21794 </cell>
21795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21796 \begin_inset Text
21797
21798 \layout Standard
21799
21800 rest of the pointer
21801 \end_inset 
21802 </cell>
21803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21804 \begin_inset Text
21805
21806 \layout Standard
21807
21808 descrption
21809 \end_inset 
21810 </cell>
21811 </row>
21812 <row topline="true" bottomline="true">
21813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21814 \begin_inset Text
21815
21816 \layout Standard
21817
21818 stream
21819 \end_inset 
21820 </cell>
21821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21822 \begin_inset Text
21823
21824 \layout Standard
21825
21826 00
21827 \end_inset 
21828 </cell>
21829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21830 \begin_inset Text
21831
21832 \layout Standard
21833
21834 1
21835 \end_inset 
21836 </cell>
21837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21838 \begin_inset Text
21839
21840 \layout Standard
21841
21842 0
21843 \end_inset 
21844 </cell>
21845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21846 \begin_inset Text
21847
21848 \layout Standard
21849
21850 nnnn
21851 \end_inset 
21852 </cell>
21853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21854 \begin_inset Text
21855
21856 \layout Standard
21857
21858
21859 \family typewriter 
21860 \shape slanted 
21861 \emph on 
21862 uuuuuuuu uuuuuuuu
21863 \end_inset 
21864 </cell>
21865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21866 \begin_inset Text
21867
21868 \layout Standard
21869
21870 upper byte high nubble is 0x2n, the rest are zeroes
21871 \end_inset 
21872 </cell>
21873 </row>
21874 </lyxtabular>
21875
21876 \end_inset 
21877
21878
21879 \layout Standard
21880
21881 Currently implemented there are 3 types of streams defined:
21882 \layout Standard
21883 \align center 
21884
21885 \begin_inset  Tabular
21886 <lyxtabular version="3" rows="4" columns="4">
21887 <features>
21888 <column alignment="center" valignment="top" leftline="true" width="0">
21889 <column alignment="center" valignment="top" leftline="true" width="0">
21890 <column alignment="center" valignment="top" leftline="true" width="0">
21891 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21892 <row topline="true" bottomline="true">
21893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21894 \begin_inset Text
21895
21896 \layout Standard
21897
21898 stream type
21899 \end_inset 
21900 </cell>
21901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21902 \begin_inset Text
21903
21904 \layout Standard
21905
21906 value
21907 \end_inset 
21908 </cell>
21909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21910 \begin_inset Text
21911
21912 \layout Standard
21913
21914 module
21915 \end_inset 
21916 </cell>
21917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21918 \begin_inset Text
21919
21920 \layout Standard
21921
21922 description
21923 \end_inset 
21924 </cell>
21925 </row>
21926 <row topline="true">
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21928 \begin_inset Text
21929
21930 \layout Standard
21931
21932 STREAM_USART
21933 \end_inset 
21934 </cell>
21935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21936 \begin_inset Text
21937
21938 \layout Standard
21939
21940
21941 \family typewriter 
21942 0x200000UL
21943 \end_inset 
21944 </cell>
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21946 \begin_inset Text
21947
21948 \layout Standard
21949
21950 USART
21951 \end_inset 
21952 </cell>
21953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21954 \begin_inset Text
21955
21956 \layout Standard
21957
21958 Writes/Reads characters via the USART peripheral
21959 \end_inset 
21960 </cell>
21961 </row>
21962 <row topline="true">
21963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21964 \begin_inset Text
21965
21966 \layout Standard
21967
21968 STREAM_MSSP
21969 \end_inset 
21970 </cell>
21971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21972 \begin_inset Text
21973
21974 \layout Standard
21975
21976
21977 \family typewriter 
21978 0x210000UL
21979 \end_inset 
21980 </cell>
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21982 \begin_inset Text
21983
21984 \layout Standard
21985
21986 MSSP
21987 \end_inset 
21988 </cell>
21989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21990 \begin_inset Text
21991
21992 \layout Standard
21993
21994 Writes/Reads characters via the MSSP peripheral
21995 \end_inset 
21996 </cell>
21997 </row>
21998 <row topline="true" bottomline="true">
21999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22000 \begin_inset Text
22001
22002 \layout Standard
22003
22004 STREAM_USER
22005 \end_inset 
22006 </cell>
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22008 \begin_inset Text
22009
22010 \layout Standard
22011
22012
22013 \family typewriter 
22014 0x2f0000UL
22015 \end_inset 
22016 </cell>
22017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22018 \begin_inset Text
22019
22020 \layout Standard
22021
22022 (none)
22023 \end_inset 
22024 </cell>
22025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22026 \begin_inset Text
22027
22028 \layout Standard
22029
22030 Writes/Reads characters via used defined functions
22031 \end_inset 
22032 </cell>
22033 </row>
22034 </lyxtabular>
22035
22036 \end_inset 
22037
22038
22039 \layout Standard
22040
22041 The stream identifiers are declared as macros in the stdio.h header.
22042 \layout Standard
22043
22044 In the libc library there exist the functions that are used to write to
22045  each of the above streams.
22046  These are
22047 \layout List
22048 \labelwidthstring 00.00.0000
22049
22050 _
22051 \begin_inset ERT
22052 status Collapsed
22053
22054 \layout Standard
22055
22056 \backslash 
22057 /
22058 \end_inset 
22059
22060 _stream_usart_putchar writes a character at the USART stream
22061 \layout List
22062 \labelwidthstring 00.00.0000
22063
22064 _
22065 \begin_inset ERT
22066 status Collapsed
22067
22068 \layout Standard
22069
22070 \backslash 
22071 /
22072 \end_inset 
22073
22074 _stream_mssp_putchar writes a character at the MSSP stream
22075 \layout List
22076 \labelwidthstring 00.00.0000
22077
22078 putchar dummy function.
22079  This writes a character to a user specified manner.
22080 \layout Standard
22081
22082 In order to increase performance 
22083 \emph on 
22084 putchar 
22085 \emph default 
22086 is declared in stdio.h as having its parameter in WREG (it has the wparam
22087  keyword).
22088  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
22089  in a user-friendly way.
22090  
22091 \emph on 
22092 arg
22093 \emph default 
22094  is the name of the variable that holds the character to print.
22095  An example follows:
22096 \layout LyX-Code
22097
22098 #include <pic18fregs.h>
22099 \newline 
22100 #include <stdio.h>
22101 \newline 
22102
22103 \newline 
22104 PUTCHAR( c )
22105 \layout LyX-Code
22106
22107 {
22108 \layout LyX-Code
22109
22110     PORTA = c;    /* dump character c to PORTA */
22111 \layout LyX-Code
22112
22113
22114 \newline 
22115
22116 \newline 
22117 void main(void)
22118 \layout LyX-Code
22119
22120 {
22121 \layout LyX-Code
22122
22123     stdout = STREAM_USER;    /* this is not necessary, since stdout points
22124 \layout LyX-Code
22125
22126                               * by default to STREAM_USER */
22127 \layout LyX-Code
22128
22129     printf (¨This is a printf test
22130 \backslash 
22131 n¨);
22132 \layout LyX-Code
22133
22134 }
22135 \layout LyX-Code
22136
22137 \layout Subsubsection
22138
22139 Printing functions
22140 \layout Standard
22141
22142 PIC16 contains an implementation of the printf-family of functions.
22143  There exist the following functions:
22144 \layout LyX-Code
22145
22146 extern unsigned int sprintf(char *buf, char *fmt, ...);
22147 \layout LyX-Code
22148
22149 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
22150 \layout LyX-Code
22151
22152 \layout LyX-Code
22153
22154 extern unsigned int printf(char *fmt, ...);
22155 \layout LyX-Code
22156
22157 extern unsigned int vprintf(char *fmt, va_lista ap);
22158 \layout LyX-Code
22159
22160 \layout LyX-Code
22161
22162 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
22163 \layout LyX-Code
22164
22165 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
22166 \layout Standard
22167
22168 For sprintf and vsprintf 
22169 \emph on 
22170 buf 
22171 \emph default 
22172 should normally be a data pointer where the resulting string will be placed.
22173  No range checking is done so the user should allocate the necessery buffer.
22174  For fprintf and vfprintf 
22175 \emph on 
22176 fp
22177 \emph default 
22178  should be a stream pointer (i.e.
22179  stdout, STREAM_MSSP, etc...).
22180 \layout Subsubsection
22181
22182 Signals
22183 \layout Standard
22184
22185 The PIC18F family of microcontrollers supports a number of interrupt sources.
22186  A list of these interrupts is shown in the following table:
22187 \layout Standard
22188 \align center 
22189
22190 \begin_inset  Tabular
22191 <lyxtabular version="3" rows="11" columns="4">
22192 <features>
22193 <column alignment="left" valignment="top" leftline="true" width="0">
22194 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22195 <column alignment="left" valignment="top" leftline="true" width="0">
22196 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22197 <row topline="true" bottomline="true">
22198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22199 \begin_inset Text
22200
22201 \layout Standard
22202
22203 signal name
22204 \end_inset 
22205 </cell>
22206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22207 \begin_inset Text
22208
22209 \layout Standard
22210
22211 description
22212 \end_inset 
22213 </cell>
22214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22215 \begin_inset Text
22216
22217 \layout Standard
22218
22219 signal name
22220 \end_inset 
22221 </cell>
22222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22223 \begin_inset Text
22224
22225 \layout Standard
22226
22227 descritpion
22228 \end_inset 
22229 </cell>
22230 </row>
22231 <row topline="true">
22232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22233 \begin_inset Text
22234
22235 \layout Standard
22236
22237 SIG_RB
22238 \end_inset 
22239 </cell>
22240 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22241 \begin_inset Text
22242
22243 \layout Standard
22244
22245 PORTB change interrupt
22246 \end_inset 
22247 </cell>
22248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22249 \begin_inset Text
22250
22251 \layout Standard
22252
22253 SIG_EE
22254 \end_inset 
22255 </cell>
22256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22257 \begin_inset Text
22258
22259 \layout Standard
22260
22261 EEPROM/FLASH write complete interrupt
22262 \end_inset 
22263 </cell>
22264 </row>
22265 <row topline="true">
22266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22267 \begin_inset Text
22268
22269 \layout Standard
22270
22271 SIG_INT0
22272 \end_inset 
22273 </cell>
22274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22275 \begin_inset Text
22276
22277 \layout Standard
22278
22279 INT0 external interrupt
22280 \end_inset 
22281 </cell>
22282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22283 \begin_inset Text
22284
22285 \layout Standard
22286
22287 SIG_BCOL
22288 \end_inset 
22289 </cell>
22290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22291 \begin_inset Text
22292
22293 \layout Standard
22294
22295 Bus collision interrupt
22296 \end_inset 
22297 </cell>
22298 </row>
22299 <row topline="true">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22301 \begin_inset Text
22302
22303 \layout Standard
22304
22305 SIG_INT1
22306 \end_inset 
22307 </cell>
22308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22309 \begin_inset Text
22310
22311 \layout Standard
22312
22313 INT1 external interrupt
22314 \end_inset 
22315 </cell>
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22317 \begin_inset Text
22318
22319 \layout Standard
22320
22321 SIG_LVD
22322 \end_inset 
22323 </cell>
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22325 \begin_inset Text
22326
22327 \layout Standard
22328
22329 Low voltage detect interrupt
22330 \end_inset 
22331 </cell>
22332 </row>
22333 <row topline="true">
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22335 \begin_inset Text
22336
22337 \layout Standard
22338
22339 SIG_INT2
22340 \end_inset 
22341 </cell>
22342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22343 \begin_inset Text
22344
22345 \layout Standard
22346
22347 INT2 external interrupt
22348 \end_inset 
22349 </cell>
22350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22351 \begin_inset Text
22352
22353 \layout Standard
22354
22355 SIG_PSP
22356 \end_inset 
22357 </cell>
22358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22359 \begin_inset Text
22360
22361 \layout Standard
22362
22363 Parallel slave port interrupt
22364 \end_inset 
22365 </cell>
22366 </row>
22367 <row topline="true">
22368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22369 \begin_inset Text
22370
22371 \layout Standard
22372
22373 SIG_CCP1
22374 \end_inset 
22375 </cell>
22376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22377 \begin_inset Text
22378
22379 \layout Standard
22380
22381 CCP1 module interrupt
22382 \end_inset 
22383 </cell>
22384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22385 \begin_inset Text
22386
22387 \layout Standard
22388
22389 SIG_AD
22390 \end_inset 
22391 </cell>
22392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22393 \begin_inset Text
22394
22395 \layout Standard
22396
22397 AD convertion complete interrupt
22398 \end_inset 
22399 </cell>
22400 </row>
22401 <row topline="true">
22402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22403 \begin_inset Text
22404
22405 \layout Standard
22406
22407 SIG_CCP2
22408 \end_inset 
22409 </cell>
22410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22411 \begin_inset Text
22412
22413 \layout Standard
22414
22415 CCP2 module interrupt
22416 \end_inset 
22417 </cell>
22418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22419 \begin_inset Text
22420
22421 \layout Standard
22422
22423 SIG_RC
22424 \end_inset 
22425 </cell>
22426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22427 \begin_inset Text
22428
22429 \layout Standard
22430
22431 USART receive interrupt
22432 \end_inset 
22433 </cell>
22434 </row>
22435 <row topline="true">
22436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22437 \begin_inset Text
22438
22439 \layout Standard
22440
22441 SIG_TMR0
22442 \end_inset 
22443 </cell>
22444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22445 \begin_inset Text
22446
22447 \layout Standard
22448
22449 TMR0 overflow interrupt
22450 \end_inset 
22451 </cell>
22452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22453 \begin_inset Text
22454
22455 \layout Standard
22456
22457 SIG_TX
22458 \end_inset 
22459 </cell>
22460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22461 \begin_inset Text
22462
22463 \layout Standard
22464
22465 USART transmit interrupt
22466 \end_inset 
22467 </cell>
22468 </row>
22469 <row topline="true">
22470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22471 \begin_inset Text
22472
22473 \layout Standard
22474
22475 SIG_TMR1
22476 \end_inset 
22477 </cell>
22478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22479 \begin_inset Text
22480
22481 \layout Standard
22482
22483 TMR1 overflow interrupt
22484 \end_inset 
22485 </cell>
22486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22487 \begin_inset Text
22488
22489 \layout Standard
22490
22491 SIG_MSSP
22492 \end_inset 
22493 </cell>
22494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22495 \begin_inset Text
22496
22497 \layout Standard
22498
22499 SSP receive/transmit interrupt
22500 \end_inset 
22501 </cell>
22502 </row>
22503 <row topline="true">
22504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22505 \begin_inset Text
22506
22507 \layout Standard
22508
22509 SIG_TMR2
22510 \end_inset 
22511 </cell>
22512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22513 \begin_inset Text
22514
22515 \layout Standard
22516
22517 TMR2 matches PR2 interrupt
22518 \end_inset 
22519 </cell>
22520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22521 \begin_inset Text
22522
22523 \layout Standard
22524
22525 \end_inset 
22526 </cell>
22527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22528 \begin_inset Text
22529
22530 \layout Standard
22531
22532 \end_inset 
22533 </cell>
22534 </row>
22535 <row topline="true" bottomline="true">
22536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22537 \begin_inset Text
22538
22539 \layout Standard
22540
22541 SIG_TMR3
22542 \end_inset 
22543 </cell>
22544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22545 \begin_inset Text
22546
22547 \layout Standard
22548
22549 TMR3 overflow interrupt
22550 \end_inset 
22551 </cell>
22552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22553 \begin_inset Text
22554
22555 \layout Standard
22556
22557 \end_inset 
22558 </cell>
22559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22560 \begin_inset Text
22561
22562 \layout Standard
22563
22564 \end_inset 
22565 </cell>
22566 </row>
22567 </lyxtabular>
22568
22569 \end_inset 
22570
22571
22572 \layout Standard
22573
22574 The prototypes for these names are defined in the header file 
22575 \emph on 
22576 signal.h
22577 \emph default 
22578  .
22579 \layout Standard
22580
22581 In order to simplify signal handling, a number of macros is provided:
22582 \layout List
22583 \labelwidthstring 00.00.0000
22584
22585 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
22586  high priority interrupts.
22587  
22588 \emph on 
22589 name
22590 \emph default 
22591  is the function name to use.
22592 \layout List
22593 \labelwidthstring 00.00.0000
22594
22595 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
22596  low priority interrupt.
22597  
22598 \emph on 
22599 name
22600 \emph default 
22601  is the function name to use.
22602 \layout List
22603 \labelwidthstring 00.00.0000
22604
22605 DEF_HANDLER(sig,handler) define a handler for signal 
22606 \emph on 
22607 sig.
22608 \layout List
22609 \labelwidthstring 00.00.0000
22610
22611 END_DEF end the declaration of the dispatch table.
22612 \layout Standard
22613
22614 Additionally there are two more macros to simplify the declaration of the
22615  signal handler:
22616 \layout List
22617 \labelwidthstring 00.00.0000
22618
22619
22620 \series medium 
22621 SIGHANDLER(handler) 
22622 \series default 
22623 this declares the function prototype for the 
22624 \emph on 
22625 handler
22626 \emph default 
22627  function.
22628 \layout List
22629 \labelwidthstring 00.00.0000
22630
22631 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
22632 \layout Standard
22633
22634 An example of using the macros above is shown below:
22635 \layout LyX-Code
22636
22637 #include <pic18fregs.h>
22638 \layout LyX-Code
22639
22640 #include <signal.h>
22641 \newline 
22642
22643 \newline 
22644 DEF_INTHIGH(high_int)
22645 \layout LyX-Code
22646
22647 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
22648 \layout LyX-Code
22649
22650 DEF_HANDLER(SIG_BCOL, _bcol_handler)
22651 \layout LyX-Code
22652
22653 END_DEF
22654 \newline 
22655
22656 \newline 
22657 SIGHANDLER(_tmr0_handler)
22658 \layout LyX-Code
22659
22660 {
22661 \layout LyX-Code
22662
22663   /* action to be taken when timer 0 overflows */
22664 \layout LyX-Code
22665
22666 }
22667 \newline 
22668
22669 \newline 
22670 SIGHANDLERNAKED(_bcol_handler)
22671 \layout LyX-Code
22672
22673 {
22674 \layout LyX-Code
22675
22676   _asm
22677 \layout LyX-Code
22678
22679     /* action to be taken when bus collision occurs */
22680 \layout LyX-Code
22681
22682     retfie
22683 \layout LyX-Code
22684
22685  _endasm;
22686 \layout LyX-Code
22687
22688 }
22689 \layout Standard
22690
22691
22692 \series bold 
22693 NOTES:
22694 \series default 
22695  Special care should be taken when using the above scheme:
22696 \layout Itemize
22697
22698 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
22699 \layout Itemize
22700
22701 when declaring SIGHANDLERNAKED handler never forget to use 
22702 \emph on 
22703 retfie
22704 \emph default 
22705  for proper returning.
22706 \layout Subsection
22707
22708 PIC16 Port -- Tips
22709 \layout Standard
22710
22711 Here you can find some general tips for compiling programs with SDCC/pic16.
22712 \layout Subsubsection
22713
22714 Stack size
22715 \layout Standard
22716
22717 The default stack
22718 \begin_inset LatexCommand \index{PIC16!stack}
22719
22720 \end_inset 
22721
22722  size (that is 64 bytes) probably is enough for many programs.
22723  One must take care that when there are many levels of function nesting,
22724  or there is excessive usage of stack, its size should be extended.
22725  An example of such a case is the printf/sprintf family of functions.
22726  If you encounter problems like not being able to print integers, then you
22727  need to set the stack size around the maximum (256 for small stack model).
22728  The following diagram shows what happens when calling printf to print an
22729  integer:
22730 \layout LyX-Code
22731
22732 printf () --> ltoa () --> ultoa () --> divschar ()
22733 \layout Standard
22734
22735 It is should be understood that stack is easily consumed when calling complicate
22736 d functions.
22737  Using command line arguments like -
22738 \begin_inset ERT
22739 status Collapsed
22740
22741 \layout Standard
22742
22743 \backslash 
22744 /
22745 \end_inset 
22746
22747 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
22748  stack frames.
22749  Other ways to reduce stack usage may exist.
22750 \layout Subsection
22751
22752 Known bugs
22753 \layout Standard
22754
22755 The PIC16 Port currently does not pass SDCC's regression test
22756 \begin_inset LatexCommand \index{Regression test (PIC16)}
22757
22758 \end_inset 
22759
22760  suite (see section 
22761 \begin_inset LatexCommand \ref{sec:Quality-control}
22762
22763 \end_inset 
22764
22765 ) and thus the nightly regression tests for the PIC16 target are currently
22766  disabled for all hosts except for 
22767 \emph on 
22768 Linux on Opteron.
22769
22770 \emph default 
22771  This means you can see the result of the PIC16 regression tests f.e.
22772  by checking the log files in 
22773 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
22774
22775 \end_inset 
22776
22777  (pick the most up to date file there, scroll down, lend a hand).
22778 \layout Chapter
22779
22780 Debugging
22781 \layout Standard
22782
22783 There are several approaches to debugging your code.
22784  This chapter is meant to show your options and to give detail on some of
22785  them:
22786 \newline 
22787
22788 \newline 
22789 When writing your code:
22790 \layout Itemize
22791
22792 write your code with debugging in mind (avoid duplicating code, put conceptually
22793  similar variables into structs, use structured code, have strategic points
22794  within your code where all variables are consistent, ...)
22795 \layout Itemize
22796
22797 run a syntax-checking tool like splint
22798 \begin_inset LatexCommand \index{splint (syntax checking tool)}
22799
22800 \end_inset 
22801
22802
22803 \begin_inset LatexCommand \index{lint (syntax checking tool)}
22804
22805 \end_inset 
22806
22807  (see -
22808 \begin_inset ERT
22809 status Collapsed
22810
22811 \layout Standard
22812
22813 \backslash 
22814 /
22815 \end_inset 
22816
22817 -more-pedantic 
22818 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22819
22820 \end_inset 
22821
22822 ) over the code.
22823 \layout Itemize
22824
22825 for the high level code use a C-compiler (like f.e.
22826  GCC) to compile run and debug the code on your host.
22827  See (see -
22828 \begin_inset ERT
22829 status Collapsed
22830
22831 \layout Standard
22832
22833 \backslash 
22834 /
22835 \end_inset 
22836
22837 -more-pedantic 
22838 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22839
22840 \end_inset 
22841
22842  ) on howto handle syntax extensions like __xdata, __at(), ...
22843  
22844 \layout Itemize
22845
22846 use another C-compiler to compile code for your target.
22847  Always an option but not recommended:) And not very likely to help you.
22848  If you seriously consider walking this path you should at least occasionally
22849  check portability of your code.
22850  Most commercial compiler vendors will offer an evaluation version so you
22851  can test compile your code or snippets of your code.
22852 \layout Standard
22853
22854 Debugging on a simulator:
22855 \layout Itemize
22856
22857 there is a separate section about SDCDB (section 
22858 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
22859
22860 \end_inset 
22861
22862 ) below.
22863 \layout Itemize
22864
22865 or (8051 specific) use a freeware/commercial simulator which interfaces
22866  to the AOMF
22867 \begin_inset LatexCommand \index{AOMF, AOMF51}
22868
22869 \end_inset 
22870
22871  file (see 
22872 \begin_inset LatexCommand \ref{OMF file}
22873
22874 \end_inset 
22875
22876 ) optionally generated by SDCC.
22877 \layout Standard
22878
22879 Debugging On-target: 
22880 \layout Itemize
22881
22882 use a MCU port pin to serially output debug data to the RS232 port of your
22883  host.
22884  You'll probably want some level shifting device typically involving a MAX232
22885  or similar IC.
22886  If the hardware serial port of the MCU is not available search for 'Software
22887  UART' in your favourite search machine.
22888 \layout Itemize
22889
22890 use an on-target monitor.
22891  In this context a monitor is a small program which usually accepts commands
22892  via a serial line and allows to set program counter, to single step through
22893  a program and read/write memory locations.
22894  For the 8051 good examples of monitors are paulmon and cmon51 (see section
22895  
22896 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
22897
22898 \end_inset 
22899
22900 ).
22901 \layout Itemize
22902
22903 toggle MCU port pins at strategic points within your code and use an oscilloscop
22904 e.
22905  A 
22906 \emph on 
22907 digital oscilloscope
22908 \emph default 
22909
22910 \begin_inset LatexCommand \index{Oscilloscope}
22911
22912 \end_inset 
22913
22914  with deep trace memory is really helpful especially if you have to debug
22915  a realtime application.
22916  If you need to monitor more pins than your oscilloscope provides you can
22917  sometimes get away with a small R-2R network.
22918  On a single channel oscilloscope you could f.e.
22919  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22920 k
22921 \begin_inset Formula $\Omega$
22922 \end_inset 
22923
22924  resistor and the other one by a 5\SpecialChar ~
22925 k
22926 \begin_inset Formula $\Omega$
22927 \end_inset 
22928
22929  resistor to the oscilloscope probe (check output drive capability of the
22930  pins you want to monitor).
22931  If you need to monitor many more pins a 
22932 \emph on 
22933 logic analyzer
22934 \emph default 
22935  will be handy.
22936 \layout Itemize
22937
22938 use an ICE (
22939 \emph on 
22940 i
22941 \emph default 
22942
22943 \emph on 
22944 c
22945 \emph default 
22946 ircuit 
22947 \emph on 
22948 e
22949 \emph default 
22950 mulator
22951 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22952
22953 \end_inset 
22954
22955 ).
22956  Usually very expensive.
22957  And very nice to have too.
22958  And usually locks you (for years...) to the devices the ICE can emulate.
22959  
22960 \layout Itemize
22961
22962 use a remote debugger.
22963  In most 8-bit systems the symbol information is not available on the target,
22964  and a complete debugger is too bulky for the target system.
22965  Therefore usually a debugger on the host system connects to an on-target
22966  debugging stub which accepts only primitive commands.
22967  
22968 \newline 
22969 Terms to enter into your favourite search engine could be 'remote debugging',
22970  'gdb stub' or 'inferior debugger'.
22971  (is there one?)
22972 \layout Itemize
22973
22974 use an on target hardware debugger.
22975  Some of the more modern MCUs include hardware support for setting break
22976  points and monitoring/changing variables by using dedicated hardware pins.
22977  This facility doesn't require additional code to run on the target and
22978  
22979 \emph on 
22980 usually
22981 \emph default 
22982  doesn't affect runtime behaviour until a breakpoint is hit.
22983  For the mcs51 most hardware debuggers use the AOMF
22984 \begin_inset LatexCommand \index{AOMF, AOMF51}
22985
22986 \end_inset 
22987
22988  file (see 
22989 \begin_inset LatexCommand \ref{OMF file}
22990
22991 \end_inset 
22992
22993 ) as input file.
22994  
22995 \layout Standard
22996
22997 Last not least:
22998 \layout Itemize
22999
23000 if you are not familiar with any of the following terms you're likely to
23001  run into problems rather sooner than later: 
23002 \emph on 
23003 volatile
23004 \emph default 
23005
23006 \emph on 
23007 atomic
23008 \emph default 
23009
23010 \emph on 
23011 memory map
23012 \emph default 
23013
23014 \emph on 
23015 overlay
23016 \emph default 
23017 .
23018  As an embedded programmer you 
23019 \emph on 
23020 have
23021 \emph default 
23022  to know them so why not look them up 
23023 \emph on 
23024 before
23025 \emph default 
23026  you have problems?)
23027 \layout Itemize
23028
23029 tell someone else about your problem (actually this is a surprisingly effective
23030  means to hunt down the bug even if the listener is not familiar with your
23031  environment).
23032  As 'failure to communicate' is probably one of the job-induced deformations
23033  of an embedded programmer this is highly encouraged.
23034 \layout Section
23035
23036 Debugging with SDCDB
23037 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
23038
23039 \end_inset 
23040
23041
23042 \begin_inset LatexCommand \index{SDCDB (debugger)}
23043
23044 \end_inset 
23045
23046  
23047 \layout Standard
23048
23049 SDCC is distributed with a source level debugger
23050 \begin_inset LatexCommand \index{Debugger}
23051
23052 \end_inset 
23053
23054 .
23055  The debugger uses a command line interface, the command repertoire of the
23056  debugger has been kept as close to gdb
23057 \begin_inset LatexCommand \index{gdb}
23058
23059 \end_inset 
23060
23061  (the GNU debugger) as possible.
23062  The configuration and build process is part of the standard compiler installati
23063 on, which also builds and installs the debugger in the target directory
23064  specified during configuration.
23065  The debugger allows you debug BOTH at the C source and at the ASM source
23066  level.
23067 \layout Subsection
23068
23069 Compiling for Debugging
23070 \layout Standard
23071
23072 The -
23073 \begin_inset ERT
23074 status Collapsed
23075
23076 \layout Standard
23077
23078 \backslash 
23079 /
23080 \end_inset 
23081
23082 -debug
23083 \begin_inset LatexCommand \index{-\/-debug}
23084
23085 \end_inset 
23086
23087  option must be specified for all files for which debug information is to
23088  be generated.
23089  The compiler generates a .adb file for each of these files.
23090  The linker creates the .cdb
23091 \begin_inset LatexCommand \index{<file>.cdb}
23092
23093 \end_inset 
23094
23095  file from the .adb
23096 \begin_inset LatexCommand \index{<file>.adb}
23097
23098 \end_inset 
23099
23100  files and the address information.
23101  This .cdb is used by the debugger.
23102 \layout Subsection
23103
23104 How the Debugger Works
23105 \layout Standard
23106
23107 When the -
23108 \begin_inset ERT
23109 status Collapsed
23110
23111 \layout Standard
23112
23113 \backslash 
23114 /
23115 \end_inset 
23116
23117 -debug option is specified the compiler generates extra symbol information
23118  some of which are put into the assembler source and some are put into the
23119  .adb file.
23120  Then the linker creates the .cdb file from the individual .adb files with
23121  the address information for the symbols.
23122  The debugger reads the symbolic information generated by the compiler &
23123  the address information generated by the linker.
23124  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
23125  execution is controlled by the debugger.
23126  When a command is issued for the debugger, it translates it into appropriate
23127  commands for the simulator.
23128  (Currently SDCDM only connects to the simulator but 
23129 \emph on 
23130 newcdb
23131 \emph default 
23132  at 
23133 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
23134
23135 \end_inset 
23136
23137  is an effort to connect directly to the hardware.) 
23138 \layout Subsection
23139
23140 Starting the Debugger SDCDB
23141 \layout Standard
23142
23143 The debugger can be started using the following command line.
23144  (Assume the file you are debugging has the file name foo).
23145 \newline 
23146
23147 \newline 
23148
23149 \family sans 
23150 \series bold 
23151 sdcdb foo
23152 \newline 
23153
23154 \family default 
23155 \series default 
23156
23157 \newline 
23158 The debugger will look for the following files.
23159 \layout Itemize
23160
23161 foo.c - the source file.
23162 \layout Itemize
23163
23164 foo.cdb - the debugger symbol information file.
23165 \layout Itemize
23166
23167 foo.ihx - the Intel hex format
23168 \begin_inset LatexCommand \index{Intel hex format}
23169
23170 \end_inset 
23171
23172  object file.
23173 \layout Subsection
23174
23175 SDCDB Command Line Options
23176 \layout Itemize
23177
23178 -
23179 \begin_inset ERT
23180 status Collapsed
23181
23182 \layout Standard
23183
23184 \backslash 
23185 /
23186 \end_inset 
23187
23188 -directory=<source file directory> this option can used to specify the directory
23189  search list.
23190  The debugger will look into the directory list specified for source, cdb
23191  & ihx files.
23192  The items in the directory list must be separated by ':', e.g.
23193  if the source files can be in the directories /home/src1 and /home/src2,
23194  the -
23195 \begin_inset ERT
23196 status Collapsed
23197
23198 \layout Standard
23199
23200 \backslash 
23201 /
23202 \end_inset 
23203
23204 -directory option should be -
23205 \begin_inset ERT
23206 status Collapsed
23207
23208 \layout Standard
23209
23210 \backslash 
23211 /
23212 \end_inset 
23213
23214 -directory=/home/src1:/home/src2.
23215  Note there can be no spaces in the option.
23216  
23217 \layout Itemize
23218
23219 -cd <directory> - change to the <directory>.
23220 \layout Itemize
23221
23222 -fullname - used by GUI front ends.
23223 \layout Itemize
23224
23225 -cpu <cpu-type> - this argument is passed to the simulator please see the
23226  simulator docs for details.
23227 \layout Itemize
23228
23229 -X <Clock frequency > this options is passed to the simulator please see
23230  the simulator docs for details.
23231 \layout Itemize
23232
23233 -s <serial port file> passed to simulator see the simulator docs for details.
23234 \layout Itemize
23235
23236 -S <serial in,out> passed to simulator see the simulator docs for details.
23237 \layout Itemize
23238
23239 -k <port number> passed to simulator see the simulator docs for details.
23240 \layout Subsection
23241
23242 SDCDB Debugger Commands
23243 \layout Standard
23244
23245 As mentioned earlier the command interface for the debugger has been deliberatel
23246 y kept as close the GNU debugger gdb, as possible.
23247  This will help the integration with existing graphical user interfaces
23248  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
23249  If you use a graphical user interface for the debugger you can skip this
23250  section.
23251 \layout Subsubsection*
23252
23253 break [line | file:line | function | file:function]
23254 \layout Standard
23255
23256 Set breakpoint at specified line or function:
23257 \newline 
23258
23259 \newline 
23260
23261 \family sans 
23262 \series bold 
23263 sdcdb>break 100 
23264 \newline 
23265 sdcdb>break foo.c:100
23266 \newline 
23267 sdcdb>break funcfoo
23268 \newline 
23269 sdcdb>break foo.c:funcfoo
23270 \layout Subsubsection*
23271
23272 clear [line | file:line | function | file:function ]
23273 \layout Standard
23274
23275 Clear breakpoint at specified line or function:
23276 \newline 
23277
23278 \newline 
23279
23280 \family sans 
23281 \series bold 
23282 sdcdb>clear 100
23283 \newline 
23284 sdcdb>clear foo.c:100
23285 \newline 
23286 sdcdb>clear funcfoo
23287 \newline 
23288 sdcdb>clear foo.c:funcfoo
23289 \layout Subsubsection*
23290
23291 continue
23292 \layout Standard
23293
23294 Continue program being debugged, after breakpoint.
23295 \layout Subsubsection*
23296
23297 finish
23298 \layout Standard
23299
23300 Execute till the end of the current function.
23301 \layout Subsubsection*
23302
23303 delete [n]
23304 \layout Standard
23305
23306 Delete breakpoint number 'n'.
23307  If used without any option clear ALL user defined break points.
23308 \layout Subsubsection*
23309
23310 info [break | stack | frame | registers ]
23311 \layout Itemize
23312
23313 info break - list all breakpoints
23314 \layout Itemize
23315
23316 info stack - show the function call stack.
23317 \layout Itemize
23318
23319 info frame - show information about the current execution frame.
23320 \layout Itemize
23321
23322 info registers - show content of all registers.
23323 \layout Subsubsection*
23324
23325 step
23326 \layout Standard
23327
23328 Step program until it reaches a different source line.
23329  Note: pressing <return> repeats the last command.
23330 \layout Subsubsection*
23331
23332 next
23333 \layout Standard
23334
23335 Step program, proceeding through subroutine calls.
23336 \layout Subsubsection*
23337
23338 run
23339 \layout Standard
23340
23341 Start debugged program.
23342 \layout Subsubsection*
23343
23344 ptype variable 
23345 \layout Standard
23346
23347 Print type information of the variable.
23348 \layout Subsubsection*
23349
23350 print variable
23351 \layout Standard
23352
23353 print value of variable.
23354 \layout Subsubsection*
23355
23356 file filename
23357 \layout Standard
23358
23359 load the given file name.
23360  Note this is an alternate method of loading file for debugging.
23361 \layout Subsubsection*
23362
23363 frame
23364 \layout Standard
23365
23366 print information about current frame.
23367 \layout Subsubsection*
23368
23369 set srcmode
23370 \layout Standard
23371
23372 Toggle between C source & assembly source.
23373 \layout Subsubsection*
23374
23375 ! simulator command
23376 \layout Standard
23377
23378 Send the string following '!' to the simulator, the simulator response is
23379  displayed.
23380  Note the debugger does not interpret the command being sent to the simulator,
23381  so if a command like 'go' is sent the debugger can loose its execution
23382  context and may display incorrect values.
23383 \layout Subsubsection*
23384
23385 quit
23386 \layout Standard
23387
23388 "Watch me now.
23389  Iam going Down.
23390  My name is Bobby Brown"
23391 \layout Subsection
23392
23393 Interfacing SDCDB with DDD
23394 \layout Comment
23395
23396 The screenshot was converted from png to eps with: 
23397 \begin_inset Quotes sld
23398 \end_inset 
23399
23400 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
23401 \begin_inset Quotes srd
23402 \end_inset 
23403
23404  which produces a pretty compact eps file which is free from compression
23405  artifacts.
23406 \layout Comment
23407
23408 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
23409  as this broke the build system on Sourceforge (pdf-file was broken.
23410  pdflatex does not accept eps files).
23411 \layout Standard
23412
23413 The 
23414 \emph on 
23415 p
23416 \emph default 
23417 ortable 
23418 \emph on 
23419 n
23420 \emph default 
23421 etwork 
23422 \emph on 
23423 g
23424 \emph default 
23425 raphics File 
23426 \size footnotesize 
23427
23428 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
23429
23430 \end_inset 
23431
23432
23433 \size default 
23434  shows a screenshot of a debugging session with DDD
23435 \begin_inset LatexCommand \index{DDD (debugger)}
23436
23437 \end_inset 
23438
23439  (Unix only) on a simulated 8032.
23440  The debugging session might not run as smoothly as the screenshot suggests.
23441  The debugger allows setting of breakpoints, displaying and changing variables,
23442  single stepping through C and assembler code.
23443  
23444 \newline 
23445 The source was compiled with 
23446 \family sans 
23447 \series bold 
23448
23449 \newline 
23450
23451 \newline 
23452 sdcc -
23453 \family default 
23454 \series default 
23455
23456 \begin_inset ERT
23457 status Collapsed
23458
23459 \layout Standard
23460
23461 \backslash 
23462 /
23463 \end_inset 
23464
23465
23466 \family sans 
23467 \series bold 
23468 -debug ddd_example.c
23469 \family default 
23470 \series default 
23471  
23472 \family sans 
23473 \series bold 
23474
23475 \newline 
23476
23477 \family default 
23478 \series default 
23479
23480 \newline 
23481 and DDD was invoked with 
23482 \family sans 
23483 \series bold 
23484
23485 \newline 
23486
23487 \newline 
23488 ddd -debugger "sdcdb -cpu 8032 ddd_example"
23489 \layout Standard
23490
23491
23492 \begin_inset Note
23493 collapsed false
23494
23495 \layout Standard
23496
23497 Check that the double quotes or an apostroph within the command line survive
23498  the LyX tool chain.
23499  Previously the apostrophs got slanted in the PDF output so a cut and paste
23500  did not work.
23501 \end_inset 
23502
23503
23504 \layout Subsection
23505
23506 Interfacing SDCDB with XEmacs
23507 \begin_inset LatexCommand \index{XEmacs}
23508
23509 \end_inset 
23510
23511
23512 \begin_inset LatexCommand \index{Emacs}
23513
23514 \end_inset 
23515
23516
23517 \layout Standard
23518
23519 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
23520  sdcdb.el and sdcdbsrc.el.
23521  These two files can be found in the $(prefix)/bin directory after the installat
23522 ion is complete.
23523  These files need to be loaded into XEmacs for the interface to work.
23524  This can be done at XEmacs startup time by inserting the following into
23525  your '.xemacs' file (which can be found in your HOME directory): 
23526 \newline 
23527
23528 \newline 
23529
23530 \family typewriter 
23531 (load-file sdcdbsrc.el) 
23532 \family default 
23533
23534 \newline 
23535
23536 \newline 
23537 .xemacs is a lisp file so the () around the command is REQUIRED.
23538  The files can also be loaded dynamically while XEmacs is running, set the
23539  environment variable 'EMACSLOADPATH' to the installation bin directory
23540  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
23541  To start the interface enter the following command: 
23542 \newline 
23543
23544 \newline 
23545
23546 \family sans 
23547 \series bold 
23548 ESC-x sdcdbsrc
23549 \family default 
23550 \series default 
23551
23552 \newline 
23553
23554 \newline 
23555 You will prompted to enter the file name to be debugged.
23556  
23557 \newline 
23558
23559 \newline 
23560 The command line options that are passed to the simulator directly are bound
23561  to default values in the file sdcdbsrc.el.
23562  The variables are listed below, these values maybe changed as required.
23563 \layout Itemize
23564
23565 sdcdbsrc-cpu-type '51
23566 \layout Itemize
23567
23568 sdcdbsrc-frequency '11059200
23569 \layout Itemize
23570
23571 sdcdbsrc-serial nil
23572 \layout Standard
23573
23574 The following is a list of key mapping for the debugger interface.
23575 \layout Standard
23576
23577 \SpecialChar ~
23578
23579 \family typewriter 
23580
23581 \newline 
23582 ;;\SpecialChar ~
23583 Current Listing :: 
23584 \newline 
23585 ;;key\SpecialChar ~
23586 \SpecialChar ~
23587 \SpecialChar ~
23588 \SpecialChar ~
23589 \SpecialChar ~
23590 \SpecialChar ~
23591 \SpecialChar ~
23592 \SpecialChar ~
23593 \SpecialChar ~
23594 \SpecialChar ~
23595 \SpecialChar ~
23596 \SpecialChar ~
23597 \SpecialChar ~
23598 \SpecialChar ~
23599 binding\SpecialChar ~
23600 \SpecialChar ~
23601 \SpecialChar ~
23602 \SpecialChar ~
23603 \SpecialChar ~
23604 \SpecialChar ~
23605 \SpecialChar ~
23606 \SpecialChar ~
23607 \SpecialChar ~
23608 \SpecialChar ~
23609 \SpecialChar ~
23610 \SpecialChar ~
23611 \SpecialChar ~
23612 \SpecialChar ~
23613 \SpecialChar ~
23614 \SpecialChar ~
23615 \SpecialChar ~
23616 \SpecialChar ~
23617 \SpecialChar ~
23618 \SpecialChar ~
23619 \SpecialChar ~
23620 \SpecialChar ~
23621 Comment 
23622 \newline 
23623 ;;---\SpecialChar ~
23624 \SpecialChar ~
23625 \SpecialChar ~
23626 \SpecialChar ~
23627 \SpecialChar ~
23628 \SpecialChar ~
23629 \SpecialChar ~
23630 \SpecialChar ~
23631 \SpecialChar ~
23632 \SpecialChar ~
23633 \SpecialChar ~
23634 \SpecialChar ~
23635 \SpecialChar ~
23636 \SpecialChar ~
23637 -------\SpecialChar ~
23638 \SpecialChar ~
23639 \SpecialChar ~
23640 \SpecialChar ~
23641 \SpecialChar ~
23642 \SpecialChar ~
23643 \SpecialChar ~
23644 \SpecialChar ~
23645 \SpecialChar ~
23646 \SpecialChar ~
23647 \SpecialChar ~
23648 \SpecialChar ~
23649 \SpecialChar ~
23650 \SpecialChar ~
23651 \SpecialChar ~
23652 \SpecialChar ~
23653 \SpecialChar ~
23654 \SpecialChar ~
23655 \SpecialChar ~
23656 \SpecialChar ~
23657 \SpecialChar ~
23658 \SpecialChar ~
23659 -------
23660 \newline 
23661 ;; 
23662 \newline 
23663 ;;\SpecialChar ~
23664 n\SpecialChar ~
23665 \SpecialChar ~
23666 \SpecialChar ~
23667 \SpecialChar ~
23668 \SpecialChar ~
23669 \SpecialChar ~
23670 \SpecialChar ~
23671 \SpecialChar ~
23672 \SpecialChar ~
23673 \SpecialChar ~
23674 \SpecialChar ~
23675 \SpecialChar ~
23676 \SpecialChar ~
23677 \SpecialChar ~
23678 \SpecialChar ~
23679 sdcdb-next-from-src\SpecialChar ~
23680 \SpecialChar ~
23681 \SpecialChar ~
23682 \SpecialChar ~
23683 \SpecialChar ~
23684 \SpecialChar ~
23685 \SpecialChar ~
23686 \SpecialChar ~
23687 \SpecialChar ~
23688 \SpecialChar ~
23689 SDCDB next command 
23690 \newline 
23691 ;;\SpecialChar ~
23692 b\SpecialChar ~
23693 \SpecialChar ~
23694 \SpecialChar ~
23695 \SpecialChar ~
23696 \SpecialChar ~
23697 \SpecialChar ~
23698 \SpecialChar ~
23699 \SpecialChar ~
23700 \SpecialChar ~
23701 \SpecialChar ~
23702 \SpecialChar ~
23703 \SpecialChar ~
23704 \SpecialChar ~
23705 \SpecialChar ~
23706 \SpecialChar ~
23707 sdcdb-back-from-src\SpecialChar ~
23708 \SpecialChar ~
23709 \SpecialChar ~
23710 \SpecialChar ~
23711 \SpecialChar ~
23712 \SpecialChar ~
23713 \SpecialChar ~
23714 \SpecialChar ~
23715 \SpecialChar ~
23716 \SpecialChar ~
23717 SDCDB back command 
23718 \newline 
23719 ;;\SpecialChar ~
23720 c\SpecialChar ~
23721 \SpecialChar ~
23722 \SpecialChar ~
23723 \SpecialChar ~
23724 \SpecialChar ~
23725 \SpecialChar ~
23726 \SpecialChar ~
23727 \SpecialChar ~
23728 \SpecialChar ~
23729 \SpecialChar ~
23730 \SpecialChar ~
23731 \SpecialChar ~
23732 \SpecialChar ~
23733 \SpecialChar ~
23734 \SpecialChar ~
23735 sdcdb-cont-from-src\SpecialChar ~
23736 \SpecialChar ~
23737 \SpecialChar ~
23738 \SpecialChar ~
23739 \SpecialChar ~
23740 \SpecialChar ~
23741 \SpecialChar ~
23742 \SpecialChar ~
23743 \SpecialChar ~
23744 \SpecialChar ~
23745 SDCDB continue command
23746 \newline 
23747 ;;\SpecialChar ~
23748 s\SpecialChar ~
23749 \SpecialChar ~
23750 \SpecialChar ~
23751 \SpecialChar ~
23752 \SpecialChar ~
23753 \SpecialChar ~
23754 \SpecialChar ~
23755 \SpecialChar ~
23756 \SpecialChar ~
23757 \SpecialChar ~
23758 \SpecialChar ~
23759 \SpecialChar ~
23760 \SpecialChar ~
23761 \SpecialChar ~
23762 \SpecialChar ~
23763 sdcdb-step-from-src\SpecialChar ~
23764 \SpecialChar ~
23765 \SpecialChar ~
23766 \SpecialChar ~
23767 \SpecialChar ~
23768 \SpecialChar ~
23769 \SpecialChar ~
23770 \SpecialChar ~
23771 \SpecialChar ~
23772 \SpecialChar ~
23773 SDCDB step command 
23774 \newline 
23775 ;;\SpecialChar ~
23776 ?\SpecialChar ~
23777 \SpecialChar ~
23778 \SpecialChar ~
23779 \SpecialChar ~
23780 \SpecialChar ~
23781 \SpecialChar ~
23782 \SpecialChar ~
23783 \SpecialChar ~
23784 \SpecialChar ~
23785 \SpecialChar ~
23786 \SpecialChar ~
23787 \SpecialChar ~
23788 \SpecialChar ~
23789 \SpecialChar ~
23790 \SpecialChar ~
23791 sdcdb-whatis-c-sexp\SpecialChar ~
23792 \SpecialChar ~
23793 \SpecialChar ~
23794 \SpecialChar ~
23795 \SpecialChar ~
23796 \SpecialChar ~
23797 \SpecialChar ~
23798 \SpecialChar ~
23799 \SpecialChar ~
23800 \SpecialChar ~
23801 SDCDB ptypecommand for data at 
23802 \newline 
23803 ;;\SpecialChar ~
23804 \SpecialChar ~
23805 \SpecialChar ~
23806 \SpecialChar ~
23807 \SpecialChar ~
23808 \SpecialChar ~
23809 \SpecialChar ~
23810 \SpecialChar ~
23811 \SpecialChar ~
23812 \SpecialChar ~
23813 \SpecialChar ~
23814 \SpecialChar ~
23815 \SpecialChar ~
23816 \SpecialChar ~
23817 \SpecialChar ~
23818 \SpecialChar ~
23819 \SpecialChar ~
23820 \SpecialChar ~
23821 \SpecialChar ~
23822 \SpecialChar ~
23823 \SpecialChar ~
23824 \SpecialChar ~
23825 \SpecialChar ~
23826 \SpecialChar ~
23827 \SpecialChar ~
23828 \SpecialChar ~
23829 \SpecialChar ~
23830 \SpecialChar ~
23831 \SpecialChar ~
23832 \SpecialChar ~
23833 \SpecialChar ~
23834 \SpecialChar ~
23835 \SpecialChar ~
23836 \SpecialChar ~
23837 \SpecialChar ~
23838 \SpecialChar ~
23839 \SpecialChar ~
23840 \SpecialChar ~
23841 \SpecialChar ~
23842 \SpecialChar ~
23843 \SpecialChar ~
23844 \SpecialChar ~
23845 \SpecialChar ~
23846 \SpecialChar ~
23847 \SpecialChar ~
23848 \SpecialChar ~
23849 \SpecialChar ~
23850 buffer point 
23851 \newline 
23852 ;;\SpecialChar ~
23853 x\SpecialChar ~
23854 \SpecialChar ~
23855 \SpecialChar ~
23856 \SpecialChar ~
23857 \SpecialChar ~
23858 \SpecialChar ~
23859 \SpecialChar ~
23860 \SpecialChar ~
23861 \SpecialChar ~
23862 \SpecialChar ~
23863 \SpecialChar ~
23864 \SpecialChar ~
23865 \SpecialChar ~
23866 \SpecialChar ~
23867 \SpecialChar ~
23868 sdcdbsrc-delete\SpecialChar ~
23869 \SpecialChar ~
23870 \SpecialChar ~
23871 \SpecialChar ~
23872 \SpecialChar ~
23873 \SpecialChar ~
23874 \SpecialChar ~
23875 \SpecialChar ~
23876 \SpecialChar ~
23877 \SpecialChar ~
23878 \SpecialChar ~
23879 \SpecialChar ~
23880 \SpecialChar ~
23881 \SpecialChar ~
23882 SDCDB Delete all breakpoints if no arg 
23883 \newline 
23884 ;;\SpecialChar ~
23885 \SpecialChar ~
23886 \SpecialChar ~
23887 \SpecialChar ~
23888 \SpecialChar ~
23889 \SpecialChar ~
23890 \SpecialChar ~
23891 \SpecialChar ~
23892 \SpecialChar ~
23893 \SpecialChar ~
23894 \SpecialChar ~
23895 \SpecialChar ~
23896 \SpecialChar ~
23897 \SpecialChar ~
23898 \SpecialChar ~
23899 \SpecialChar ~
23900 \SpecialChar ~
23901 \SpecialChar ~
23902 \SpecialChar ~
23903 \SpecialChar ~
23904 \SpecialChar ~
23905 \SpecialChar ~
23906 \SpecialChar ~
23907 \SpecialChar ~
23908 \SpecialChar ~
23909 \SpecialChar ~
23910 \SpecialChar ~
23911 \SpecialChar ~
23912 \SpecialChar ~
23913 \SpecialChar ~
23914 \SpecialChar ~
23915 \SpecialChar ~
23916 \SpecialChar ~
23917 \SpecialChar ~
23918 \SpecialChar ~
23919 \SpecialChar ~
23920 \SpecialChar ~
23921 \SpecialChar ~
23922 \SpecialChar ~
23923 \SpecialChar ~
23924 \SpecialChar ~
23925 \SpecialChar ~
23926 \SpecialChar ~
23927 \SpecialChar ~
23928 \SpecialChar ~
23929 \SpecialChar ~
23930 \SpecialChar ~
23931 given or delete arg (C-u arg x) 
23932 \newline 
23933 ;;\SpecialChar ~
23934 m\SpecialChar ~
23935 \SpecialChar ~
23936 \SpecialChar ~
23937 \SpecialChar ~
23938 \SpecialChar ~
23939 \SpecialChar ~
23940 \SpecialChar ~
23941 \SpecialChar ~
23942 \SpecialChar ~
23943 \SpecialChar ~
23944 \SpecialChar ~
23945 \SpecialChar ~
23946 \SpecialChar ~
23947 \SpecialChar ~
23948 \SpecialChar ~
23949 sdcdbsrc-frame\SpecialChar ~
23950 \SpecialChar ~
23951 \SpecialChar ~
23952 \SpecialChar ~
23953 \SpecialChar ~
23954 \SpecialChar ~
23955 \SpecialChar ~
23956 \SpecialChar ~
23957 \SpecialChar ~
23958 \SpecialChar ~
23959 \SpecialChar ~
23960 \SpecialChar ~
23961 \SpecialChar ~
23962 \SpecialChar ~
23963 \SpecialChar ~
23964 SDCDB Display current frame if no arg, 
23965 \newline 
23966 ;;\SpecialChar ~
23967 \SpecialChar ~
23968 \SpecialChar ~
23969 \SpecialChar ~
23970 \SpecialChar ~
23971 \SpecialChar ~
23972 \SpecialChar ~
23973 \SpecialChar ~
23974 \SpecialChar ~
23975 \SpecialChar ~
23976 \SpecialChar ~
23977 \SpecialChar ~
23978 \SpecialChar ~
23979 \SpecialChar ~
23980 \SpecialChar ~
23981 \SpecialChar ~
23982 \SpecialChar ~
23983 \SpecialChar ~
23984 \SpecialChar ~
23985 \SpecialChar ~
23986 \SpecialChar ~
23987 \SpecialChar ~
23988 \SpecialChar ~
23989 \SpecialChar ~
23990 \SpecialChar ~
23991 \SpecialChar ~
23992 \SpecialChar ~
23993 \SpecialChar ~
23994 \SpecialChar ~
23995 \SpecialChar ~
23996 \SpecialChar ~
23997 \SpecialChar ~
23998 \SpecialChar ~
23999 \SpecialChar ~
24000 \SpecialChar ~
24001 \SpecialChar ~
24002 \SpecialChar ~
24003 \SpecialChar ~
24004 \SpecialChar ~
24005 \SpecialChar ~
24006 \SpecialChar ~
24007 \SpecialChar ~
24008 \SpecialChar ~
24009 \SpecialChar ~
24010 \SpecialChar ~
24011 \SpecialChar ~
24012 \SpecialChar ~
24013 given or display frame arg 
24014 \newline 
24015 ;;\SpecialChar ~
24016 \SpecialChar ~
24017 \SpecialChar ~
24018 \SpecialChar ~
24019 \SpecialChar ~
24020 \SpecialChar ~
24021 \SpecialChar ~
24022 \SpecialChar ~
24023 \SpecialChar ~
24024 \SpecialChar ~
24025 \SpecialChar ~
24026 \SpecialChar ~
24027 \SpecialChar ~
24028 \SpecialChar ~
24029 \SpecialChar ~
24030 \SpecialChar ~
24031 \SpecialChar ~
24032 \SpecialChar ~
24033 \SpecialChar ~
24034 \SpecialChar ~
24035 \SpecialChar ~
24036 \SpecialChar ~
24037 \SpecialChar ~
24038 \SpecialChar ~
24039 \SpecialChar ~
24040 \SpecialChar ~
24041 \SpecialChar ~
24042 \SpecialChar ~
24043 \SpecialChar ~
24044 \SpecialChar ~
24045 \SpecialChar ~
24046 \SpecialChar ~
24047 \SpecialChar ~
24048 \SpecialChar ~
24049 \SpecialChar ~
24050 \SpecialChar ~
24051 \SpecialChar ~
24052 \SpecialChar ~
24053 \SpecialChar ~
24054 \SpecialChar ~
24055 \SpecialChar ~
24056 \SpecialChar ~
24057 \SpecialChar ~
24058 \SpecialChar ~
24059 \SpecialChar ~
24060 \SpecialChar ~
24061 \SpecialChar ~
24062 buffer point 
24063 \newline 
24064 ;;\SpecialChar ~
24065 !\SpecialChar ~
24066 \SpecialChar ~
24067 \SpecialChar ~
24068 \SpecialChar ~
24069 \SpecialChar ~
24070 \SpecialChar ~
24071 \SpecialChar ~
24072 \SpecialChar ~
24073 \SpecialChar ~
24074 \SpecialChar ~
24075 \SpecialChar ~
24076 \SpecialChar ~
24077 \SpecialChar ~
24078 \SpecialChar ~
24079 \SpecialChar ~
24080 sdcdbsrc-goto-sdcdb\SpecialChar ~
24081 \SpecialChar ~
24082 \SpecialChar ~
24083 \SpecialChar ~
24084 \SpecialChar ~
24085 \SpecialChar ~
24086 \SpecialChar ~
24087 \SpecialChar ~
24088 \SpecialChar ~
24089 \SpecialChar ~
24090 Goto the SDCDB output buffer 
24091 \newline 
24092 ;;\SpecialChar ~
24093 p\SpecialChar ~
24094 \SpecialChar ~
24095 \SpecialChar ~
24096 \SpecialChar ~
24097 \SpecialChar ~
24098 \SpecialChar ~
24099 \SpecialChar ~
24100 \SpecialChar ~
24101 \SpecialChar ~
24102 \SpecialChar ~
24103 \SpecialChar ~
24104 \SpecialChar ~
24105 \SpecialChar ~
24106 \SpecialChar ~
24107 \SpecialChar ~
24108 sdcdb-print-c-sexp\SpecialChar ~
24109 \SpecialChar ~
24110 \SpecialChar ~
24111 \SpecialChar ~
24112 \SpecialChar ~
24113 \SpecialChar ~
24114 \SpecialChar ~
24115 \SpecialChar ~
24116 \SpecialChar ~
24117 \SpecialChar ~
24118 \SpecialChar ~
24119 SDCDB print command for data at 
24120 \newline 
24121 ;;\SpecialChar ~
24122 \SpecialChar ~
24123 \SpecialChar ~
24124 \SpecialChar ~
24125 \SpecialChar ~
24126 \SpecialChar ~
24127 \SpecialChar ~
24128 \SpecialChar ~
24129 \SpecialChar ~
24130 \SpecialChar ~
24131 \SpecialChar ~
24132 \SpecialChar ~
24133 \SpecialChar ~
24134 \SpecialChar ~
24135 \SpecialChar ~
24136 \SpecialChar ~
24137 \SpecialChar ~
24138 \SpecialChar ~
24139 \SpecialChar ~
24140 \SpecialChar ~
24141 \SpecialChar ~
24142 \SpecialChar ~
24143 \SpecialChar ~
24144 \SpecialChar ~
24145 \SpecialChar ~
24146 \SpecialChar ~
24147 \SpecialChar ~
24148 \SpecialChar ~
24149 \SpecialChar ~
24150 \SpecialChar ~
24151 \SpecialChar ~
24152 \SpecialChar ~
24153 \SpecialChar ~
24154 \SpecialChar ~
24155 \SpecialChar ~
24156 \SpecialChar ~
24157 \SpecialChar ~
24158 \SpecialChar ~
24159 \SpecialChar ~
24160 \SpecialChar ~
24161 \SpecialChar ~
24162 \SpecialChar ~
24163 \SpecialChar ~
24164 \SpecialChar ~
24165 \SpecialChar ~
24166 \SpecialChar ~
24167 \SpecialChar ~
24168 buffer point 
24169 \newline 
24170 ;;\SpecialChar ~
24171 g\SpecialChar ~
24172 \SpecialChar ~
24173 \SpecialChar ~
24174 \SpecialChar ~
24175 \SpecialChar ~
24176 \SpecialChar ~
24177 \SpecialChar ~
24178 \SpecialChar ~
24179 \SpecialChar ~
24180 \SpecialChar ~
24181 \SpecialChar ~
24182 \SpecialChar ~
24183 \SpecialChar ~
24184 \SpecialChar ~
24185 \SpecialChar ~
24186 sdcdbsrc-goto-sdcdb\SpecialChar ~
24187 \SpecialChar ~
24188 \SpecialChar ~
24189 \SpecialChar ~
24190 \SpecialChar ~
24191 \SpecialChar ~
24192 \SpecialChar ~
24193 \SpecialChar ~
24194 \SpecialChar ~
24195 \SpecialChar ~
24196 Goto the SDCDB output buffer 
24197 \newline 
24198 ;;\SpecialChar ~
24199 t\SpecialChar ~
24200 \SpecialChar ~
24201 \SpecialChar ~
24202 \SpecialChar ~
24203 \SpecialChar ~
24204 \SpecialChar ~
24205 \SpecialChar ~
24206 \SpecialChar ~
24207 \SpecialChar ~
24208 \SpecialChar ~
24209 \SpecialChar ~
24210 \SpecialChar ~
24211 \SpecialChar ~
24212 \SpecialChar ~
24213 \SpecialChar ~
24214 sdcdbsrc-mode\SpecialChar ~
24215 \SpecialChar ~
24216 \SpecialChar ~
24217 \SpecialChar ~
24218 \SpecialChar ~
24219 \SpecialChar ~
24220 \SpecialChar ~
24221 \SpecialChar ~
24222 \SpecialChar ~
24223 \SpecialChar ~
24224 \SpecialChar ~
24225 \SpecialChar ~
24226 \SpecialChar ~
24227 \SpecialChar ~
24228 \SpecialChar ~
24229 \SpecialChar ~
24230 Toggles Sdcdbsrc mode (turns it off) 
24231 \newline 
24232 ;; 
24233 \newline 
24234 ;;\SpecialChar ~
24235 C-c\SpecialChar ~
24236 C-f\SpecialChar ~
24237 \SpecialChar ~
24238 \SpecialChar ~
24239 \SpecialChar ~
24240 \SpecialChar ~
24241 \SpecialChar ~
24242 \SpecialChar ~
24243 \SpecialChar ~
24244 \SpecialChar ~
24245 sdcdb-finish-from-src\SpecialChar ~
24246 \SpecialChar ~
24247 \SpecialChar ~
24248 \SpecialChar ~
24249 \SpecialChar ~
24250 \SpecialChar ~
24251 \SpecialChar ~
24252 \SpecialChar ~
24253 SDCDB finish command 
24254 \newline 
24255 ;; 
24256 \newline 
24257 ;;\SpecialChar ~
24258 C-x\SpecialChar ~
24259 SPC\SpecialChar ~
24260 \SpecialChar ~
24261 \SpecialChar ~
24262 \SpecialChar ~
24263 \SpecialChar ~
24264 \SpecialChar ~
24265 \SpecialChar ~
24266 \SpecialChar ~
24267 \SpecialChar ~
24268 sdcdb-break\SpecialChar ~
24269 \SpecialChar ~
24270 \SpecialChar ~
24271 \SpecialChar ~
24272 \SpecialChar ~
24273 \SpecialChar ~
24274 \SpecialChar ~
24275 \SpecialChar ~
24276 \SpecialChar ~
24277 \SpecialChar ~
24278 \SpecialChar ~
24279 \SpecialChar ~
24280 \SpecialChar ~
24281 \SpecialChar ~
24282 \SpecialChar ~
24283 \SpecialChar ~
24284 \SpecialChar ~
24285 \SpecialChar ~
24286 Set break for line with point 
24287 \newline 
24288 ;;\SpecialChar ~
24289 ESC\SpecialChar ~
24290 t\SpecialChar ~
24291 \SpecialChar ~
24292 \SpecialChar ~
24293 \SpecialChar ~
24294 \SpecialChar ~
24295 \SpecialChar ~
24296 \SpecialChar ~
24297 \SpecialChar ~
24298 \SpecialChar ~
24299 \SpecialChar ~
24300 \SpecialChar ~
24301 sdcdbsrc-mode\SpecialChar ~
24302 \SpecialChar ~
24303 \SpecialChar ~
24304 \SpecialChar ~
24305 \SpecialChar ~
24306 \SpecialChar ~
24307 \SpecialChar ~
24308 \SpecialChar ~
24309 \SpecialChar ~
24310 \SpecialChar ~
24311 \SpecialChar ~
24312 \SpecialChar ~
24313 \SpecialChar ~
24314 \SpecialChar ~
24315 \SpecialChar ~
24316 \SpecialChar ~
24317 Toggle Sdcdbsrc mode 
24318 \newline 
24319 ;;\SpecialChar ~
24320 ESC\SpecialChar ~
24321 m\SpecialChar ~
24322 \SpecialChar ~
24323 \SpecialChar ~
24324 \SpecialChar ~
24325 \SpecialChar ~
24326 \SpecialChar ~
24327 \SpecialChar ~
24328 \SpecialChar ~
24329 \SpecialChar ~
24330 \SpecialChar ~
24331 \SpecialChar ~
24332 sdcdbsrc-srcmode\SpecialChar ~
24333 \SpecialChar ~
24334 \SpecialChar ~
24335 \SpecialChar ~
24336 \SpecialChar ~
24337 \SpecialChar ~
24338 \SpecialChar ~
24339 \SpecialChar ~
24340 \SpecialChar ~
24341 \SpecialChar ~
24342 \SpecialChar ~
24343 \SpecialChar ~
24344 \SpecialChar ~
24345 Toggle list mode 
24346 \newline 
24347 ;; 
24348 \newline 
24349
24350 \layout Chapter
24351 \pagebreak_top 
24352 TIPS
24353 \layout Standard
24354
24355 Here are a few guidelines that will help the compiler generate more efficient
24356  code, some of the tips are specific to this compiler others are generally
24357  good programming practice.
24358 \layout Itemize
24359
24360 Use the smallest data type to represent your data-value.
24361  If it is known in advance that the value is going to be less than 256 then
24362  use an 'unsigned char' instead of a 'short' or 'int'.
24363  Please note, that ANSI C requires both signed and unsigned chars to be
24364  promoted to 'signed int'
24365 \begin_inset LatexCommand \index{promotion to signed int}
24366
24367 \end_inset 
24368
24369
24370 \begin_inset Marginal
24371 collapsed true
24372
24373 \layout Standard
24374
24375
24376 \series bold 
24377 \SpecialChar ~
24378 !
24379 \end_inset 
24380
24381  before doing any operation.
24382  This promotion
24383 \begin_inset LatexCommand \index{type promotion}
24384
24385 \end_inset 
24386
24387
24388 \begin_inset LatexCommand \label{type promotion}
24389
24390 \end_inset 
24391
24392  can be omitted, if the result is the same.
24393  The effect of the promotion rules together with the sign-extension is often
24394  surprising:
24395 \begin_deeper 
24396 \layout Verse
24397
24398
24399 \family typewriter 
24400 unsigned char uc = 0xfe;
24401 \newline 
24402 if (uc * uc < 0) /* this is true! */
24403 \newline 
24404 {
24405 \newline 
24406 \SpecialChar ~
24407 \SpecialChar ~
24408 \SpecialChar ~
24409 \SpecialChar ~
24410 ....
24411 \newline 
24412 }
24413 \layout Standard
24414
24415
24416 \family typewriter 
24417 uc * uc
24418 \family default 
24419  is evaluated as 
24420 \family typewriter 
24421 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
24422 \family default 
24423 .
24424  
24425 \newline 
24426 Another one:
24427 \layout Verse
24428
24429
24430 \family typewriter 
24431 (unsigned char) -12 / (signed char) -3 = ...
24432 \layout Standard
24433
24434 No, the result is not 4:
24435 \layout Verse
24436
24437
24438 \family typewriter 
24439 (int) (unsigned char) -12 / (int) (signed char) -3 =
24440 \newline 
24441 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
24442 \newline 
24443 (int) 0x00f4 / (int) 0xfffd =
24444 \newline 
24445 (int) 0x00f4 / (int) 0xfffd =
24446 \newline 
24447 (int) 244 / (int) -3 =
24448 \newline 
24449 (int) -81 = (int) 0xffaf;
24450 \layout Standard
24451
24452 Don't complain, that gcc gives you a different result.
24453  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
24454  Therefore the results are different.
24455 \newline 
24456 From 
24457 \begin_inset Quotes sld
24458 \end_inset 
24459
24460 comp.lang.c FAQ
24461 \begin_inset Quotes srd
24462 \end_inset 
24463
24464 :
24465 \layout Quote
24466
24467
24468 \emph on 
24469 If well-defined overflow characteristics are important and negative values
24470  are not, or if you want to steer clear of sign-extension problems when
24471  manipulating bits or bytes, use one of the corresponding unsigned types.
24472  (Beware when mixing signed and unsigned values in expressions, though.)
24473 \newline 
24474 Although character types (especially unsigned char) can be used as "tiny"
24475  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
24476 ble sign extension and increased code size.
24477 \end_deeper 
24478 \layout Itemize
24479
24480 Use unsigned when it is known in advance that the value is not going to
24481  be negative.
24482  This helps especially if you are doing division or multiplication, bit-shifting
24483  or are using an array index.
24484 \layout Itemize
24485
24486 NEVER jump into a LOOP.
24487 \layout Itemize
24488
24489 Declare the variables to be local
24490 \begin_inset LatexCommand \index{local variables}
24491
24492 \end_inset 
24493
24494  whenever possible, especially loop control variables (induction).
24495 \layout Itemize
24496
24497 Have a look at the assembly listing to get a 
24498 \begin_inset Quotes sld
24499 \end_inset 
24500
24501 feeling
24502 \begin_inset Quotes srd
24503 \end_inset 
24504
24505  for the code generation.
24506 \layout Section
24507
24508 Porting code from or to other compilers
24509 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
24510
24511 \end_inset 
24512
24513
24514 \layout Itemize
24515
24516 check whether endianness of the compilers differs and adapt where needed.
24517 \layout Itemize
24518
24519 check the device specific header files
24520 \begin_inset LatexCommand \index{Header files}
24521
24522 \end_inset 
24523
24524
24525 \begin_inset LatexCommand \index{Include files}
24526
24527 \end_inset 
24528
24529  for compiler specific syntax.
24530  Eventually include the file <compiler.h
24531 \begin_inset LatexCommand \index{compiler.h (include file)}
24532
24533 \end_inset 
24534
24535
24536 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
24537
24538 \end_inset 
24539
24540  to allow using common header files.
24541  (see f.e.
24542  cc2510fx.h 
24543 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
24544
24545 \end_inset 
24546
24547 ).
24548 \layout Itemize
24549
24550 check whether the startup code contains the correct initialization (watchdog,
24551  peripherals).
24552 \layout Itemize
24553
24554 check whether the sizes of short, int, long match.
24555 \layout Itemize
24556
24557 check if some 16 or 32 bit hardware registers require a specific addressing
24558  order (least significant or most significant byte first) and adapt if needed
24559  (
24560 \emph on 
24561 first
24562 \emph default 
24563  and 
24564 \emph on 
24565 last
24566 \emph default 
24567  relate to time and not to lower/upper memory location here, so this is
24568  
24569 \emph on 
24570 not
24571 \emph default 
24572  the same as endianness).
24573 \layout Itemize
24574
24575 check whether the keyword 
24576 \emph on 
24577 volatile
24578 \emph default 
24579  is used where needed.
24580  The compilers might differ in their optimization characteristics (as different
24581  versions of the same compiler might also use more clever optimizations
24582  this is good idea anyway).
24583  See section 
24584 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
24585
24586 \end_inset 
24587
24588 .
24589 \layout Itemize
24590
24591 check that the compilers are not told to supress warnings.
24592 \layout Itemize
24593
24594 check and convert compiler specific extensions (interrupts, memory areas,
24595  pragmas etc.).
24596 \layout Itemize
24597
24598 check for differences in type promotion.
24599  Especially check for math operations on 
24600 \family typewriter 
24601 char
24602 \family default 
24603  or 
24604 \family typewriter 
24605 unsigned char
24606 \family default 
24607  variables.
24608  For the sake of C99 compatibility SDCC will probably promote these to 
24609 \family typewriter 
24610 int
24611 \family default 
24612  more often than other compilers.
24613  Eventually insert explicit casts to 
24614 \family typewriter 
24615 (char) 
24616 \family default 
24617 or
24618 \family typewriter 
24619  (unsigned char)
24620 \family default 
24621 .
24622  Also check that the ~\SpecialChar ~
24623 operator
24624 \begin_inset LatexCommand \index{\~\/ Operator}
24625
24626 \end_inset 
24627
24628  is not used on 
24629 \family typewriter 
24630 bit
24631 \begin_inset LatexCommand \index{bit}
24632
24633 \end_inset 
24634
24635
24636 \family default 
24637  variables, use the !\SpecialChar ~
24638 operator instead.
24639  See sections 
24640 \begin_inset LatexCommand \ref{type promotion}
24641
24642 \end_inset 
24643
24644  and 
24645 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
24646
24647 \end_inset 
24648
24649 .
24650 \layout Itemize
24651
24652 check the assembly code generated for interrupt routines (f.e.
24653  for calls to possibly non-reentrant library functions).
24654 \layout Itemize
24655
24656 check whether timing loops result in proper timing (or preferably consider
24657  a rewrite of the code with timer based delays instead).
24658 \layout Itemize
24659
24660 check for differences in printf parameters (some compilers push (va_arg
24661 \begin_inset LatexCommand \index{vararg, va\_arg}
24662
24663 \end_inset 
24664
24665 ) char variables as 
24666 \family typewriter 
24667 int
24668 \family default 
24669  others push them as 
24670 \family typewriter 
24671 char
24672 \family default 
24673 .
24674  See section 
24675 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
24676
24677 \end_inset 
24678
24679 ).
24680 \layout Itemize
24681
24682 check the resulting memory map
24683 \begin_inset LatexCommand \index{Memory map}
24684
24685 \end_inset 
24686
24687 .
24688  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
24689 ly idata, pdata, xdata).
24690  Eventually check if unexpected library functions are included.
24691 \layout Section
24692
24693 Tools
24694 \begin_inset LatexCommand \index{Tools}
24695
24696 \end_inset 
24697
24698  included in the distribution
24699 \layout Standard
24700 \align left 
24701
24702 \begin_inset  Tabular
24703 <lyxtabular version="3" rows="12" columns="3">
24704 <features>
24705 <column alignment="left" valignment="top" leftline="true" width="0pt">
24706 <column alignment="left" valignment="top" leftline="true" width="0pt">
24707 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24708 <row topline="true" bottomline="true">
24709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24710 \begin_inset Text
24711
24712 \layout Standard
24713
24714
24715 \series bold 
24716 Name
24717 \end_inset 
24718 </cell>
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24720 \begin_inset Text
24721
24722 \layout Standard
24723
24724
24725 \series bold 
24726 Purpose
24727 \end_inset 
24728 </cell>
24729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24730 \begin_inset Text
24731
24732 \layout Standard
24733
24734
24735 \series bold 
24736 Directory
24737 \end_inset 
24738 </cell>
24739 </row>
24740 <row topline="true">
24741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24742 \begin_inset Text
24743
24744 \layout Standard
24745
24746 uCsim
24747 \begin_inset LatexCommand \index{uCsim}
24748
24749 \end_inset 
24750
24751
24752 \end_inset 
24753 </cell>
24754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24755 \begin_inset Text
24756
24757 \layout Standard
24758
24759 Simulator for various architectures
24760 \end_inset 
24761 </cell>
24762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24763 \begin_inset Text
24764
24765 \layout Standard
24766
24767 sdcc/sim/ucsim
24768 \end_inset 
24769 </cell>
24770 </row>
24771 <row topline="true">
24772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24773 \begin_inset Text
24774
24775 \layout Standard
24776
24777 keil2sdcc.pl
24778 \end_inset 
24779 </cell>
24780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24781 \begin_inset Text
24782
24783 \layout Standard
24784
24785 header file
24786 \begin_inset LatexCommand \index{Header files}
24787
24788 \end_inset 
24789
24790
24791 \begin_inset LatexCommand \index{Include files}
24792
24793 \end_inset 
24794
24795  conversion
24796 \end_inset 
24797 </cell>
24798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24799 \begin_inset Text
24800
24801 \layout Standard
24802
24803 sdcc/support/scripts
24804 \end_inset 
24805 </cell>
24806 </row>
24807 <row topline="true">
24808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24809 \begin_inset Text
24810
24811 \layout Standard
24812
24813 mh2h.c
24814 \end_inset 
24815 </cell>
24816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24817 \begin_inset Text
24818
24819 \layout Standard
24820
24821 header file conversion
24822 \end_inset 
24823 </cell>
24824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24825 \begin_inset Text
24826
24827 \layout Standard
24828
24829 sdcc/support/scripts
24830 \end_inset 
24831 </cell>
24832 </row>
24833 <row topline="true">
24834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24835 \begin_inset Text
24836
24837 \layout Standard
24838
24839 as-gbz80
24840 \end_inset 
24841 </cell>
24842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24843 \begin_inset Text
24844
24845 \layout Standard
24846
24847 Assembler
24848 \end_inset 
24849 </cell>
24850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24851 \begin_inset Text
24852
24853 \layout Standard
24854
24855
24856 \family roman 
24857 \series medium 
24858 \shape up 
24859 \size normal 
24860 \emph off 
24861 \bar no 
24862 \noun off 
24863 \color none
24864 sdcc/bin
24865 \end_inset 
24866 </cell>
24867 </row>
24868 <row topline="true">
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24870 \begin_inset Text
24871
24872 \layout Standard
24873
24874 as-z80
24875 \end_inset 
24876 </cell>
24877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24878 \begin_inset Text
24879
24880 \layout Standard
24881
24882 Assembler
24883 \end_inset 
24884 </cell>
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24886 \begin_inset Text
24887
24888 \layout Standard
24889
24890
24891 \family roman 
24892 \series medium 
24893 \shape up 
24894 \size normal 
24895 \emph off 
24896 \bar no 
24897 \noun off 
24898 \color none
24899 sdcc/bin
24900 \end_inset 
24901 </cell>
24902 </row>
24903 <row topline="true">
24904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24905 \begin_inset Text
24906
24907 \layout Standard
24908
24909 asx8051
24910 \end_inset 
24911 </cell>
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24913 \begin_inset Text
24914
24915 \layout Standard
24916
24917 Assembler
24918 \end_inset 
24919 </cell>
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24921 \begin_inset Text
24922
24923 \layout Standard
24924
24925
24926 \family roman 
24927 \series medium 
24928 \shape up 
24929 \size normal 
24930 \emph off 
24931 \bar no 
24932 \noun off 
24933 \color none
24934 sdcc/bin
24935 \end_inset 
24936 </cell>
24937 </row>
24938 <row topline="true">
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24940 \begin_inset Text
24941
24942 \layout Standard
24943
24944 SDCDB
24945 \end_inset 
24946 </cell>
24947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24948 \begin_inset Text
24949
24950 \layout Standard
24951
24952 Simulator
24953 \end_inset 
24954 </cell>
24955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24956 \begin_inset Text
24957
24958 \layout Standard
24959
24960
24961 \family roman 
24962 \series medium 
24963 \shape up 
24964 \size normal 
24965 \emph off 
24966 \bar no 
24967 \noun off 
24968 \color none
24969 sdcc/bin
24970 \end_inset 
24971 </cell>
24972 </row>
24973 <row topline="true">
24974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24975 \begin_inset Text
24976
24977 \layout Standard
24978
24979 aslink
24980 \end_inset 
24981 </cell>
24982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24983 \begin_inset Text
24984
24985 \layout Standard
24986
24987 Linker
24988 \end_inset 
24989 </cell>
24990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24991 \begin_inset Text
24992
24993 \layout Standard
24994
24995
24996 \family roman 
24997 \series medium 
24998 \shape up 
24999 \size normal 
25000 \emph off 
25001 \bar no 
25002 \noun off 
25003 \color none
25004 sdcc/bin
25005 \end_inset 
25006 </cell>
25007 </row>
25008 <row topline="true">
25009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25010 \begin_inset Text
25011
25012 \layout Standard
25013
25014 link-z80
25015 \end_inset 
25016 </cell>
25017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25018 \begin_inset Text
25019
25020 \layout Standard
25021
25022 Linker
25023 \end_inset 
25024 </cell>
25025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25026 \begin_inset Text
25027
25028 \layout Standard
25029
25030
25031 \family roman 
25032 \series medium 
25033 \shape up 
25034 \size normal 
25035 \emph off 
25036 \bar no 
25037 \noun off 
25038 \color none
25039 sdcc/bin
25040 \end_inset 
25041 </cell>
25042 </row>
25043 <row topline="true">
25044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25045 \begin_inset Text
25046
25047 \layout Standard
25048
25049 link-gbz80
25050 \end_inset 
25051 </cell>
25052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25053 \begin_inset Text
25054
25055 \layout Standard
25056
25057 Linker
25058 \end_inset 
25059 </cell>
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25061 \begin_inset Text
25062
25063 \layout Standard
25064
25065
25066 \family roman 
25067 \series medium 
25068 \shape up 
25069 \size normal 
25070 \emph off 
25071 \bar no 
25072 \noun off 
25073 \color none
25074 sdcc/bin
25075 \end_inset 
25076 </cell>
25077 </row>
25078 <row topline="true" bottomline="true">
25079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25080 \begin_inset Text
25081
25082 \layout Standard
25083
25084 packihx
25085 \end_inset 
25086 </cell>
25087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25088 \begin_inset Text
25089
25090 \layout Standard
25091
25092 Intel Hex packer 
25093 \begin_inset LatexCommand \index{packihx (tool)}
25094
25095 \end_inset 
25096
25097
25098 \end_inset 
25099 </cell>
25100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25101 \begin_inset Text
25102
25103 \layout Standard
25104
25105
25106 \family roman 
25107 \series medium 
25108 \shape up 
25109 \size normal 
25110 \emph off 
25111 \bar no 
25112 \noun off 
25113 \color none
25114 sdcc/bin
25115 \end_inset 
25116 </cell>
25117 </row>
25118 </lyxtabular>
25119
25120 \end_inset 
25121
25122
25123 \newline 
25124
25125 \layout Section
25126
25127 Documentation
25128 \begin_inset LatexCommand \index{Documentation}
25129
25130 \end_inset 
25131
25132  included in the distribution
25133 \layout Standard
25134 \align left 
25135
25136 \begin_inset  Tabular
25137 <lyxtabular version="3" rows="10" columns="2">
25138 <features>
25139 <column alignment="block" valignment="top" leftline="true" width="40col%">
25140 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
25141 <row topline="true" bottomline="true" endhead="true">
25142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25143 \begin_inset Text
25144
25145 \layout Standard
25146
25147
25148 \series bold 
25149 Subject / Title
25150 \end_inset 
25151 </cell>
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25153 \begin_inset Text
25154
25155 \layout Standard
25156
25157
25158 \series bold 
25159 Filename / Where to get
25160 \end_inset 
25161 </cell>
25162 </row>
25163 <row topline="true">
25164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25165 \begin_inset Text
25166
25167 \layout Standard
25168
25169 SDCC Compiler User Guide
25170 \end_inset 
25171 </cell>
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25173 \begin_inset Text
25174
25175 \layout Standard
25176
25177 You're reading it right now
25178 \emph on 
25179  \SpecialChar ~
25180 \SpecialChar ~
25181 \SpecialChar ~
25182
25183 \hfill 
25184 online at:
25185 \emph default 
25186
25187 \newline 
25188
25189 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
25190
25191 \end_inset 
25192
25193
25194 \end_inset 
25195 </cell>
25196 </row>
25197 <row topline="true">
25198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25199 \begin_inset Text
25200
25201 \layout Standard
25202
25203 Changelog of SDCC
25204 \end_inset 
25205 </cell>
25206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25207 \begin_inset Text
25208
25209 \layout Standard
25210
25211 sdcc/Changelog
25212 \emph on 
25213  \SpecialChar ~
25214 \SpecialChar ~
25215 \SpecialChar ~
25216
25217 \hfill 
25218 online at:
25219 \emph default 
25220
25221 \newline 
25222
25223 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25224
25225 \end_inset 
25226
25227
25228 \end_inset 
25229 </cell>
25230 </row>
25231 <row topline="true">
25232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25233 \begin_inset Text
25234
25235 \layout Standard
25236
25237 ASXXXX
25238 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
25239
25240 \end_inset 
25241
25242
25243 \begin_inset LatexCommand \index{Assembler documentation}
25244
25245 \end_inset 
25246
25247  Assemblers and
25248 \newline 
25249 ASLINK
25250 \begin_inset LatexCommand \index{aslink}
25251
25252 \end_inset 
25253
25254
25255 \begin_inset LatexCommand \index{Linker documentation}
25256
25257 \end_inset 
25258
25259  Relocating Linker
25260 \end_inset 
25261 </cell>
25262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25263 \begin_inset Text
25264
25265 \layout Standard
25266
25267 sdcc/as/doc/asxhtm.html 
25268 \emph on 
25269 \SpecialChar ~
25270 \SpecialChar ~
25271 \SpecialChar ~
25272
25273 \hfill 
25274 online at:
25275 \emph default 
25276
25277 \newline 
25278
25279 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
25280
25281 \end_inset 
25282
25283
25284 \end_inset 
25285 </cell>
25286 </row>
25287 <row topline="true">
25288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25289 \begin_inset Text
25290
25291 \layout Standard
25292
25293 SDCC regression test
25294 \begin_inset LatexCommand \index{Regression test}
25295
25296 \end_inset 
25297
25298
25299 \end_inset 
25300 </cell>
25301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25302 \begin_inset Text
25303
25304 \layout Standard
25305
25306 sdcc/doc/test_suite_spec.pdf 
25307 \emph on 
25308 \SpecialChar ~
25309 \SpecialChar ~
25310 \SpecialChar ~
25311
25312 \hfill 
25313 online at:
25314 \emph default 
25315
25316 \newline 
25317
25318 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
25319
25320 \end_inset 
25321
25322
25323 \end_inset 
25324 </cell>
25325 </row>
25326 <row topline="true">
25327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25328 \begin_inset Text
25329
25330 \layout Standard
25331
25332 Various notes
25333 \end_inset 
25334 </cell>
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25336 \begin_inset Text
25337
25338 \layout Standard
25339
25340 sdcc/doc/* 
25341 \emph on 
25342 \SpecialChar ~
25343 \SpecialChar ~
25344 \SpecialChar ~
25345
25346 \hfill 
25347 online at:
25348 \emph default 
25349
25350 \newline 
25351
25352 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
25353
25354 \end_inset 
25355
25356
25357 \end_inset 
25358 </cell>
25359 </row>
25360 <row topline="true">
25361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25362 \begin_inset Text
25363
25364 \layout Standard
25365
25366 Notes on debugging with SDCDB
25367 \begin_inset LatexCommand \index{SDCDB (debugger)}
25368
25369 \end_inset 
25370
25371
25372 \end_inset 
25373 </cell>
25374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25375 \begin_inset Text
25376
25377 \layout Standard
25378
25379 sdcc/debugger/README 
25380 \emph on 
25381 \SpecialChar ~
25382 \SpecialChar ~
25383 \SpecialChar ~
25384
25385 \hfill 
25386 online at
25387 \emph default 
25388 :
25389 \newline 
25390
25391 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
25392
25393 \end_inset 
25394
25395
25396 \end_inset 
25397 </cell>
25398 </row>
25399 <row topline="true">
25400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25401 \begin_inset Text
25402
25403 \layout Standard
25404
25405 uCsim
25406 \begin_inset LatexCommand \index{uCsim}
25407
25408 \end_inset 
25409
25410  Software simulator for microcontrollers
25411 \end_inset 
25412 </cell>
25413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25414 \begin_inset Text
25415
25416 \layout Standard
25417
25418
25419 \family roman 
25420 \series medium 
25421 \shape up 
25422 \size normal 
25423 \emph off 
25424 \bar no 
25425 \noun off 
25426 \color none
25427 sdcc/sim/ucsim/doc
25428 \family default 
25429 \series default 
25430 \shape default 
25431 \size default 
25432 \emph default 
25433 \bar default 
25434 \noun default 
25435 \color default
25436 /index.html 
25437 \emph on 
25438 \SpecialChar ~
25439 \SpecialChar ~
25440 \SpecialChar ~
25441
25442 \hfill 
25443 online at:
25444 \emph default 
25445
25446 \newline 
25447
25448 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
25449
25450 \end_inset 
25451
25452
25453 \end_inset 
25454 </cell>
25455 </row>
25456 <row topline="true">
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \layout Standard
25461
25462 Temporary notes on the pic16
25463 \begin_inset LatexCommand \index{PIC16}
25464
25465 \end_inset 
25466
25467  port
25468 \end_inset 
25469 </cell>
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25471 \begin_inset Text
25472
25473 \layout Standard
25474
25475 sdcc/src/pic16/NOTES 
25476 \emph on 
25477 \SpecialChar ~
25478 \SpecialChar ~
25479 \SpecialChar ~
25480
25481 \hfill 
25482 online at:
25483 \newline 
25484
25485 \emph default 
25486
25487 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
25488
25489 \end_inset 
25490
25491
25492 \end_inset 
25493 </cell>
25494 </row>
25495 <row topline="true" bottomline="true">
25496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25497 \begin_inset Text
25498
25499 \layout Standard
25500
25501 SDCC internal documentation (debugging file format)
25502 \end_inset 
25503 </cell>
25504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25505 \begin_inset Text
25506
25507 \layout Standard
25508
25509 sdcc/doc/
25510 \family roman 
25511 \series medium 
25512 \shape up 
25513 \size normal 
25514 \emph off 
25515 \bar no 
25516 \noun off 
25517 \color none
25518 cdbfileformat.pd
25519 \family default 
25520 \series default 
25521 \shape default 
25522 \size default 
25523 \emph default 
25524 \bar default 
25525 \noun default 
25526 \color default
25527 f
25528 \emph on 
25529  \SpecialChar ~
25530 \SpecialChar ~
25531 \SpecialChar ~
25532
25533 \hfill 
25534 online at:
25535 \emph default 
25536
25537 \newline 
25538
25539 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
25540
25541 \end_inset 
25542
25543
25544 \end_inset 
25545 </cell>
25546 </row>
25547 </lyxtabular>
25548
25549 \end_inset 
25550
25551
25552 \newline 
25553
25554 \layout Section
25555
25556 Related open source tools
25557 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
25558
25559 \end_inset 
25560
25561
25562 \begin_inset LatexCommand \index{Related tools}
25563
25564 \end_inset 
25565
25566
25567 \layout Standard
25568 \align left 
25569
25570 \begin_inset  Tabular
25571 <lyxtabular version="3" rows="14" columns="3">
25572 <features>
25573 <column alignment="left" valignment="top" leftline="true" width="0pt">
25574 <column alignment="block" valignment="top" leftline="true" width="30line%">
25575 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25576 <row topline="true" bottomline="true">
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25578 \begin_inset Text
25579
25580 \layout Standard
25581
25582
25583 \series bold 
25584 Name
25585 \end_inset 
25586 </cell>
25587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25588 \begin_inset Text
25589
25590 \layout Standard
25591
25592
25593 \series bold 
25594 Purpose
25595 \end_inset 
25596 </cell>
25597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25598 \begin_inset Text
25599
25600 \layout Standard
25601
25602
25603 \series bold 
25604 Where to get
25605 \end_inset 
25606 </cell>
25607 </row>
25608 <row topline="true">
25609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25610 \begin_inset Text
25611
25612 \layout Standard
25613
25614 gpsim
25615 \begin_inset LatexCommand \index{gpsim (pic simulator)}
25616
25617 \end_inset 
25618
25619
25620 \end_inset 
25621 </cell>
25622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25623 \begin_inset Text
25624
25625 \layout Standard
25626
25627 PIC simulator
25628 \end_inset 
25629 </cell>
25630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25631 \begin_inset Text
25632
25633 \layout Standard
25634
25635
25636 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
25637
25638 \end_inset 
25639
25640
25641 \end_inset 
25642 </cell>
25643 </row>
25644 <row topline="true">
25645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25646 \begin_inset Text
25647
25648 \layout Standard
25649
25650 gputils
25651 \begin_inset LatexCommand \index{gputils (pic tools)}
25652
25653 \end_inset 
25654
25655
25656 \end_inset 
25657 </cell>
25658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25659 \begin_inset Text
25660
25661 \layout Standard
25662
25663 GNU PIC utilities
25664 \end_inset 
25665 </cell>
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25667 \begin_inset Text
25668
25669 \layout Standard
25670
25671
25672 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25673
25674 \end_inset 
25675
25676
25677 \end_inset 
25678 </cell>
25679 </row>
25680 <row topline="true">
25681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25682 \begin_inset Text
25683
25684 \layout Standard
25685
25686 flP5
25687 \end_inset 
25688 </cell>
25689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25690 \begin_inset Text
25691
25692 \layout Standard
25693
25694 PIC programmer
25695 \end_inset 
25696 </cell>
25697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25698 \begin_inset Text
25699
25700 \layout Standard
25701
25702
25703 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
25704
25705 \end_inset 
25706
25707
25708 \end_inset 
25709 </cell>
25710 </row>
25711 <row topline="true">
25712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25713 \begin_inset Text
25714
25715 \layout Standard
25716
25717 ec2drv/newcdb
25718 \end_inset 
25719 </cell>
25720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25721 \begin_inset Text
25722
25723 \layout Standard
25724
25725 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
25726  (Unix only)
25727 \end_inset 
25728 </cell>
25729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25730 \begin_inset Text
25731
25732 \layout Standard
25733
25734
25735 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
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 indent
25750 \begin_inset LatexCommand \index{indent (source formatting tool)}
25751
25752 \end_inset 
25753
25754
25755 \end_inset 
25756 </cell>
25757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25758 \begin_inset Text
25759
25760 \layout Standard
25761
25762 Formats C source - Master of the white spaces
25763 \end_inset 
25764 </cell>
25765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25766 \begin_inset Text
25767
25768 \layout Standard
25769
25770
25771 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
25772
25773 \end_inset 
25774
25775
25776 \end_inset 
25777 </cell>
25778 </row>
25779 <row topline="true">
25780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25781 \begin_inset Text
25782
25783 \layout Standard
25784
25785 srecord
25786 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
25787
25788 \end_inset 
25789
25790
25791 \end_inset 
25792 </cell>
25793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25794 \begin_inset Text
25795
25796 \layout Standard
25797
25798 Object file conversion, checksumming, ...
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 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
25808
25809 \end_inset 
25810
25811
25812 \end_inset 
25813 </cell>
25814 </row>
25815 <row topline="true">
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25817 \begin_inset Text
25818
25819 \layout Standard
25820
25821 objdump
25822 \begin_inset LatexCommand \index{objdump (tool)}
25823
25824 \end_inset 
25825
25826
25827 \end_inset 
25828 </cell>
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25830 \begin_inset Text
25831
25832 \layout Standard
25833
25834 Object file conversion, ...
25835 \end_inset 
25836 </cell>
25837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25838 \begin_inset Text
25839
25840 \layout Standard
25841
25842 Part of binutils (should be there anyway)
25843 \end_inset 
25844 </cell>
25845 </row>
25846 <row topline="true">
25847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25848 \begin_inset Text
25849
25850 \layout Standard
25851
25852 cmon51
25853 \end_inset 
25854 </cell>
25855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25856 \begin_inset Text
25857
25858 \layout Standard
25859
25860 8051 monitor (hex up-/download, single step, disassemble)
25861 \end_inset 
25862 </cell>
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25864 \begin_inset Text
25865
25866 \layout Standard
25867
25868
25869 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
25870
25871 \end_inset 
25872
25873
25874 \end_inset 
25875 </cell>
25876 </row>
25877 <row topline="true">
25878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25879 \begin_inset Text
25880
25881 \layout Standard
25882
25883 doxygen
25884 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
25885
25886 \end_inset 
25887
25888
25889 \end_inset 
25890 </cell>
25891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25892 \begin_inset Text
25893
25894 \layout Standard
25895
25896 Source code documentation system
25897 \end_inset 
25898 </cell>
25899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25900 \begin_inset Text
25901
25902 \layout Standard
25903
25904
25905 \begin_inset LatexCommand \url{http://www.doxygen.org}
25906
25907 \end_inset 
25908
25909
25910 \end_inset 
25911 </cell>
25912 </row>
25913 <row topline="true">
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25915 \begin_inset Text
25916
25917 \layout Standard
25918
25919 kdevelop
25920 \end_inset 
25921 </cell>
25922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25923 \begin_inset Text
25924
25925 \layout Standard
25926
25927 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
25928 \end_inset 
25929 </cell>
25930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25931 \begin_inset Text
25932
25933 \layout Standard
25934
25935
25936 \begin_inset LatexCommand \url{http://www.kdevelop.org}
25937
25938 \end_inset 
25939
25940
25941 \end_inset 
25942 </cell>
25943 </row>
25944 <row topline="true">
25945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25946 \begin_inset Text
25947
25948 \layout Standard
25949
25950 paulmon
25951 \end_inset 
25952 </cell>
25953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25954 \begin_inset Text
25955
25956 \layout Standard
25957
25958 8051 monitor (hex up-/download, single step, disassemble)
25959 \end_inset 
25960 </cell>
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25962 \begin_inset Text
25963
25964 \layout Standard
25965
25966
25967 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
25968
25969 \end_inset 
25970
25971
25972 \end_inset 
25973 </cell>
25974 </row>
25975 <row topline="true">
25976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25977 \begin_inset Text
25978
25979 \layout Standard
25980
25981 splint
25982 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25983
25984 \end_inset 
25985
25986
25987 \end_inset 
25988 </cell>
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25990 \begin_inset Text
25991
25992 \layout Standard
25993
25994 Statically checks c sources (see 
25995 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25996
25997 \end_inset 
25998
25999 )
26000 \end_inset 
26001 </cell>
26002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26003 \begin_inset Text
26004
26005 \layout Standard
26006
26007
26008 \begin_inset LatexCommand \url{http://www.splint.org}
26009
26010 \end_inset 
26011
26012
26013 \end_inset 
26014 </cell>
26015 </row>
26016 <row topline="true" bottomline="true">
26017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26018 \begin_inset Text
26019
26020 \layout Standard
26021
26022 ddd
26023 \begin_inset LatexCommand \index{DDD (debugger)}
26024
26025 \end_inset 
26026
26027
26028 \end_inset 
26029 </cell>
26030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26031 \begin_inset Text
26032
26033 \layout Standard
26034
26035 Debugger, serves nicely as GUI to SDCDB
26036 \begin_inset LatexCommand \index{SDCDB (debugger)}
26037
26038 \end_inset 
26039
26040  (Unix only)
26041 \end_inset 
26042 </cell>
26043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26044 \begin_inset Text
26045
26046 \layout Standard
26047
26048
26049 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
26050
26051 \end_inset 
26052
26053
26054 \end_inset 
26055 </cell>
26056 </row>
26057 </lyxtabular>
26058
26059 \end_inset 
26060
26061
26062 \newline 
26063
26064 \layout Section
26065
26066 Related documentation / recommended reading
26067 \layout Standard
26068 \align left 
26069
26070 \begin_inset  Tabular
26071 <lyxtabular version="3" rows="7" columns="3">
26072 <features>
26073 <column alignment="left" valignment="top" leftline="true" width="0pt">
26074 <column alignment="left" valignment="top" leftline="true" width="0">
26075 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26076 <row topline="true" bottomline="true">
26077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26078 \begin_inset Text
26079
26080 \layout Standard
26081
26082
26083 \series bold 
26084 Name
26085 \end_inset 
26086 </cell>
26087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26088 \begin_inset Text
26089
26090 \layout Standard
26091
26092
26093 \series bold 
26094 Subject / Title
26095 \end_inset 
26096 </cell>
26097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26098 \begin_inset Text
26099
26100 \layout Standard
26101
26102
26103 \series bold 
26104 Where to get
26105 \end_inset 
26106 </cell>
26107 </row>
26108 <row topline="true">
26109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26110 \begin_inset Text
26111
26112 \layout Standard
26113
26114
26115 \family roman 
26116 \series medium 
26117 \shape up 
26118 \size normal 
26119 \emph off 
26120 \bar no 
26121 \noun off 
26122 \color none
26123 c-refcard.pdf
26124 \end_inset 
26125 </cell>
26126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26127 \begin_inset Text
26128
26129 \layout Standard
26130
26131 C Reference Card
26132 \begin_inset LatexCommand \index{C Reference card}
26133
26134 \end_inset 
26135
26136 , 2 pages
26137 \end_inset 
26138 </cell>
26139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26140 \begin_inset Text
26141
26142 \layout Standard
26143
26144
26145 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
26146
26147 \end_inset 
26148
26149
26150 \end_inset 
26151 </cell>
26152 </row>
26153 <row topline="true">
26154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26155 \begin_inset Text
26156
26157 \layout Standard
26158
26159 c-faq
26160 \end_inset 
26161 </cell>
26162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26163 \begin_inset Text
26164
26165 \layout Standard
26166
26167 C-FAQ
26168 \begin_inset LatexCommand \index{C FAQ}
26169
26170 \end_inset 
26171
26172
26173 \end_inset 
26174 </cell>
26175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26176 \begin_inset Text
26177
26178 \layout Standard
26179
26180
26181 \begin_inset LatexCommand \url{http://www.c-faq.com}
26182
26183 \end_inset 
26184
26185
26186 \end_inset 
26187 </cell>
26188 </row>
26189 <row topline="true">
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26191 \begin_inset Text
26192
26193 \layout Standard
26194
26195 ISO/IEC 9899:TC2
26196 \end_inset 
26197 </cell>
26198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26199 \begin_inset Text
26200
26201 \layout Standard
26202
26203
26204 \begin_inset Quotes sld
26205 \end_inset 
26206
26207 C-Standard
26208 \begin_inset Quotes srd
26209 \end_inset 
26210
26211
26212 \end_inset 
26213 </cell>
26214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26215 \begin_inset Text
26216
26217 \layout Standard
26218
26219
26220 \size footnotesize 
26221
26222 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
26223
26224 \end_inset 
26225
26226
26227 \end_inset 
26228 </cell>
26229 </row>
26230 <row topline="true">
26231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26232 \begin_inset Text
26233
26234 \layout Standard
26235
26236 ISO/IEC DTR 18037
26237 \end_inset 
26238 </cell>
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26240 \begin_inset Text
26241
26242 \layout Standard
26243
26244
26245 \begin_inset Quotes sld
26246 \end_inset 
26247
26248 Extensions for Embedded C
26249 \begin_inset Quotes srd
26250 \end_inset 
26251
26252
26253 \end_inset 
26254 </cell>
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26256 \begin_inset Text
26257
26258 \layout Standard
26259
26260
26261 \size footnotesize 
26262
26263 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
26264
26265 \end_inset 
26266
26267
26268 \end_inset 
26269 </cell>
26270 </row>
26271 <row topline="true">
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26273 \begin_inset Text
26274
26275 \layout Standard
26276
26277 \end_inset 
26278 </cell>
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_inset Text
26281
26282 \layout Standard
26283
26284 Latest datasheet of target CPU
26285 \end_inset 
26286 </cell>
26287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26288 \begin_inset Text
26289
26290 \layout Standard
26291
26292 vendor
26293 \end_inset 
26294 </cell>
26295 </row>
26296 <row topline="true" bottomline="true">
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \layout Standard
26301
26302 \end_inset 
26303 </cell>
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26305 \begin_inset Text
26306
26307 \layout Standard
26308
26309 Revision history of datasheet
26310 \end_inset 
26311 </cell>
26312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26313 \begin_inset Text
26314
26315 \layout Standard
26316
26317 vendor
26318 \end_inset 
26319 </cell>
26320 </row>
26321 </lyxtabular>
26322
26323 \end_inset 
26324
26325
26326 \newline 
26327
26328 \layout Section
26329
26330 Application notes specifically for SDCC
26331 \layout Standard
26332
26333 SDCC makes no claims about the completeness of this list and about up-to-datenes
26334 s or correctness of the application notes
26335 \begin_inset LatexCommand \index{Application notes}
26336
26337 \end_inset 
26338
26339 .
26340 \layout Standard
26341 \align left 
26342
26343 \size footnotesize 
26344
26345 \begin_inset  Tabular
26346 <lyxtabular version="3" rows="7" columns="3">
26347 <features>
26348 <column alignment="block" valignment="top" leftline="true" width="17col%">
26349 <column alignment="block" valignment="top" leftline="true" width="27col%">
26350 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
26351 <row topline="true" bottomline="true">
26352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26353 \begin_inset Text
26354
26355 \layout Standard
26356
26357
26358 \series bold 
26359 \size footnotesize 
26360 Vendor
26361 \end_inset 
26362 </cell>
26363 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26364 \begin_inset Text
26365
26366 \layout Standard
26367
26368
26369 \series bold 
26370 \size footnotesize 
26371 Subject / Title
26372 \end_inset 
26373 </cell>
26374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26375 \begin_inset Text
26376
26377 \layout Standard
26378
26379
26380 \series bold 
26381 \size footnotesize 
26382 Where to get
26383 \end_inset 
26384 </cell>
26385 </row>
26386 <row topline="true">
26387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26388 \begin_inset Text
26389
26390 \layout Standard
26391
26392
26393 \size footnotesize 
26394 Maxim / Dallas
26395 \end_inset 
26396 </cell>
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26398 \begin_inset Text
26399
26400 \layout Standard
26401
26402
26403 \size footnotesize 
26404 Using the SDCC Compiler for the DS80C400
26405 \begin_inset LatexCommand \index{DS80C400}
26406
26407 \end_inset 
26408
26409
26410 \end_inset 
26411 </cell>
26412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26413 \begin_inset Text
26414
26415 \layout Standard
26416
26417
26418 \size footnotesize 
26419
26420 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
26421
26422 \end_inset 
26423
26424
26425 \end_inset 
26426 </cell>
26427 </row>
26428 <row topline="true">
26429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26430 \begin_inset Text
26431
26432 \layout Standard
26433
26434
26435 \size footnotesize 
26436 Maxim / Dallas
26437 \end_inset 
26438 </cell>
26439 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
26440 \begin_inset Text
26441
26442 \layout Standard
26443
26444
26445 \size footnotesize 
26446 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
26447 \begin_inset LatexCommand \index{DS89C4x0}
26448
26449 \end_inset 
26450
26451  Family of Microcontrollers
26452 \end_inset 
26453 </cell>
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26455 \begin_inset Text
26456
26457 \layout Standard
26458
26459
26460 \size footnotesize 
26461
26462 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
26463
26464 \end_inset 
26465
26466
26467 \end_inset 
26468 </cell>
26469 </row>
26470 <row topline="true">
26471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26472 \begin_inset Text
26473
26474 \layout Standard
26475
26476
26477 \size footnotesize 
26478 Silicon Laboratories / Cygnal
26479 \end_inset 
26480 </cell>
26481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26482 \begin_inset Text
26483
26484 \layout Standard
26485
26486
26487 \size footnotesize 
26488 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
26489 \begin_inset LatexCommand \index{IDE}
26490
26491 \end_inset 
26492
26493
26494 \end_inset 
26495 </cell>
26496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26497 \begin_inset Text
26498
26499 \layout Standard
26500
26501
26502 \size footnotesize 
26503
26504 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
26505
26506 \end_inset 
26507
26508
26509 \end_inset 
26510 </cell>
26511 </row>
26512 <row topline="true">
26513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26514 \begin_inset Text
26515
26516 \layout Standard
26517
26518
26519 \size footnotesize 
26520 Ramtron / Goal Semiconductor
26521 \end_inset 
26522 </cell>
26523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26524 \begin_inset Text
26525
26526 \layout Standard
26527
26528
26529 \size footnotesize 
26530 Interfacing SDCC to Syn and Textpad
26531 \end_inset 
26532 </cell>
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26534 \begin_inset Text
26535
26536 \layout Standard
26537
26538
26539 \size footnotesize 
26540
26541 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
26542
26543 \end_inset 
26544
26545
26546 \end_inset 
26547 </cell>
26548 </row>
26549 <row topline="true">
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26551 \begin_inset Text
26552
26553 \layout Standard
26554
26555
26556 \size footnotesize 
26557 Ramtron / Goal Semiconductor
26558 \end_inset 
26559 </cell>
26560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26561 \begin_inset Text
26562
26563 \layout Standard
26564
26565
26566 \size footnotesize 
26567 Installing and Configuring SDCC and Crimson Editor 
26568 \end_inset 
26569 </cell>
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26571 \begin_inset Text
26572
26573 \layout Standard
26574
26575
26576 \size footnotesize 
26577
26578 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
26579
26580 \end_inset 
26581
26582
26583 \end_inset 
26584 </cell>
26585 </row>
26586 <row topline="true" bottomline="true">
26587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26588 \begin_inset Text
26589
26590 \layout Standard
26591
26592
26593 \size footnotesize 
26594 Texas Instruments
26595 \end_inset 
26596 </cell>
26597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26598 \begin_inset Text
26599
26600 \layout Standard
26601
26602
26603 \size footnotesize 
26604 MSC12xx Programming with SDCC
26605 \end_inset 
26606 </cell>
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26608 \begin_inset Text
26609
26610 \layout Standard
26611
26612
26613 \size footnotesize 
26614
26615 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
26616
26617 \end_inset 
26618
26619
26620 \end_inset 
26621 </cell>
26622 </row>
26623 </lyxtabular>
26624
26625 \end_inset 
26626
26627
26628 \layout Section
26629
26630 Some Questions
26631 \layout Standard
26632
26633 Some questions answered, some pointers given - it might be time to in turn
26634  ask 
26635 \emph on 
26636 you
26637 \emph default 
26638  some questions: 
26639 \layout Itemize
26640
26641 can you solve your project with the selected microcontroller? Would you
26642  find out early or rather late that your target is too small/slow/whatever?
26643  Can you switch to a slightly better device if it doesn't fit?
26644 \layout Itemize
26645
26646 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
26647  and/or another programming language be more adequate? Would an operating
26648  system on the target device help?
26649 \layout Itemize
26650
26651 if you solved the problem, will the marketing department be happy?
26652 \layout Itemize
26653
26654 if the marketing department is happy, will customers be happy?
26655 \layout Itemize
26656
26657 if you're the project manager, marketing department and maybe even the customer
26658  in one person, have you tried to see the project from the outside?
26659 \layout Itemize
26660
26661 is the project done if you think it is done? Or is just that other interface/pro
26662 tocol/feature/configuration/option missing? How about website, manual(s),
26663  internationali(z|s)ation, packaging, labels, 2nd source for components,
26664  electromagnetic compatability/interference, documentation for production,
26665  production test software, update mechanism, patent issues?
26666 \layout Itemize
26667
26668 is your project adequately positioned in that magic triangle: fame, fortune,
26669  fun?
26670 \layout Standard
26671
26672 Maybe not all answers to these questions are known and some answers may
26673  even be 
26674 \emph on 
26675 no
26676 \emph default 
26677 , nevertheless knowing these questions may help you to avoid burnout
26678 \begin_inset Foot
26679 collapsed false
26680
26681 \layout Standard
26682
26683 burnout is bad for electronic devices, programmers and motorcycle tyres
26684 \end_inset 
26685
26686 .
26687  Chances are you didn't want to hear some of them...
26688 \layout Chapter
26689
26690 Support
26691 \begin_inset LatexCommand \index{Support}
26692
26693 \end_inset 
26694
26695
26696 \layout Standard
26697
26698 SDCC has grown to be a large project.
26699  The compiler alone (without the preprocessor, assembler and linker) is
26700  well over 150,000 lines of code (blank stripped).
26701  The open source nature of this project is a key to its continued growth
26702  and support.
26703  You gain the benefit and support of many active software developers and
26704  end users.
26705  Is SDCC perfect? No, that's why we need your help.
26706  The developers take pride in fixing reported bugs.
26707  You can help by reporting the bugs and helping other SDCC users.
26708  There are lots of ways to contribute, and we encourage you to take part
26709  in making SDCC a great software package.
26710  
26711 \layout Standard
26712
26713 The SDCC project is hosted on the SDCC sourceforge site at 
26714 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
26715
26716 \end_inset 
26717
26718 .
26719  You'll find the complete set of mailing lists
26720 \begin_inset LatexCommand \index{Mailing list(s)}
26721
26722 \end_inset 
26723
26724 , forums, bug reporting system, patch submission
26725 \begin_inset LatexCommand \index{Patch submission}
26726
26727 \end_inset 
26728
26729  system, download
26730 \begin_inset LatexCommand \index{download}
26731
26732 \end_inset 
26733
26734  area and Subversion code repository
26735 \begin_inset LatexCommand \index{Subversion code repository}
26736
26737 \end_inset 
26738
26739  there.
26740 \layout Section
26741
26742 Reporting Bugs
26743 \begin_inset LatexCommand \index{Bug reporting}
26744
26745 \end_inset 
26746
26747
26748 \begin_inset LatexCommand \index{Reporting bugs}
26749
26750 \end_inset 
26751
26752
26753 \layout Standard
26754
26755 The recommended way of reporting bugs is using the infrastructure of the
26756  sourceforge site.
26757  You can follow the status of bug reports there and have an overview about
26758  the known bugs.
26759 \layout Standard
26760
26761 Bug reports are automatically forwarded to the developer mailing list and
26762  will be fixed ASAP.
26763  When reporting a bug, it is very useful to include a small test program
26764  (the smaller the better) which reproduces the problem.
26765  If you can isolate the problem by looking at the generated assembly code,
26766  this can be very helpful.
26767  Compiling your program with the -
26768 \begin_inset ERT
26769 status Collapsed
26770
26771 \layout Standard
26772
26773 \backslash 
26774 /
26775 \end_inset 
26776
26777 -dumpall
26778 \begin_inset LatexCommand \index{-\/-dumpall}
26779
26780 \end_inset 
26781
26782  option can sometimes be useful in locating optimization problems.
26783  When reporting a bug please make sure you:
26784 \layout Enumerate
26785
26786 Attach the code you are compiling with SDCC.
26787  
26788 \layout Enumerate
26789
26790 Specify the exact command you use to run SDCC, or attach your Makefile.
26791  
26792 \layout Enumerate
26793
26794 Specify the SDCC version (type "
26795 \family sans 
26796 \series bold 
26797 sdcc -v
26798 \family default 
26799 \series default 
26800 "), your platform, and operating system.
26801  
26802 \layout Enumerate
26803
26804 Provide an exact copy of any error message or incorrect output.
26805  
26806 \layout Enumerate
26807
26808 Put something meaningful in the subject of your message.
26809 \layout Standard
26810
26811 Please attempt to include these 5 important parts, as applicable, in all
26812  requests for support or when reporting any problems or bugs with SDCC.
26813  Though this will make your message lengthy, it will greatly improve your
26814  chance that SDCC users and developers will be able to help you.
26815  Some SDCC developers are frustrated by bug reports without code provided
26816  that they can use to reproduce and ultimately fix the problem, so please
26817  be sure to provide sample code if you are reporting a bug! 
26818 \layout Standard
26819
26820 Please have a short check that you are using a recent version of SDCC and
26821  the bug is not yet known.
26822  This is the link for reporting bugs: 
26823 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
26824
26825 \end_inset 
26826
26827 .
26828  With SDCC on average having more than 200 downloads
26829 \begin_inset LatexCommand \index{download}
26830
26831 \end_inset 
26832
26833  on sourceforge per day
26834 \begin_inset Foot
26835 collapsed false
26836
26837 \layout Standard
26838
26839 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
26840  between 2002 and 2005.
26841  This does not include other methods of distribution.
26842 \end_inset 
26843
26844  there must be some users.
26845  So it's not exactly easy to find a new bug.
26846  If you find one we need it: 
26847 \emph on 
26848 reporting bugs is good
26849 \emph default 
26850 .
26851 \layout Section
26852
26853 Requesting Features
26854 \begin_inset LatexCommand \label{sub:Requesting-Features}
26855
26856 \end_inset 
26857
26858
26859 \begin_inset LatexCommand \index{Feature request}
26860
26861 \end_inset 
26862
26863
26864 \begin_inset LatexCommand \index{Requesting features}
26865
26866 \end_inset 
26867
26868
26869 \layout Standard
26870
26871 Like bug reports feature requests are forwarded to the developer mailing
26872  list.
26873  This is the link for requesting features: 
26874 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26875
26876 \end_inset 
26877
26878 .
26879 \layout Section
26880
26881 Submitting patches
26882 \layout Standard
26883
26884 Like bug reports contributed patches are forwarded to the developer mailing
26885  list.
26886  This is the link for submitting patches
26887 \begin_inset LatexCommand \index{Patch submission}
26888
26889 \end_inset 
26890
26891
26892 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
26893
26894 \end_inset 
26895
26896 .
26897 \layout Standard
26898
26899 You need to specify some parameters to the 
26900 \family typewriter 
26901 diff
26902 \family default 
26903  command for the patches to be useful.
26904  If you modified more than one file a patch created f.e.
26905  with 
26906 \family sans 
26907 \series bold 
26908
26909 \begin_inset Quotes sld
26910 \end_inset 
26911
26912 diff -Naur unmodified_directory modified_directory >my_changes.patch
26913 \begin_inset Quotes srd
26914 \end_inset 
26915
26916
26917 \family default 
26918 \series default 
26919  will be fine, otherwise 
26920 \family sans 
26921 \series bold 
26922
26923 \begin_inset Quotes sld
26924 \end_inset 
26925
26926 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
26927 \begin_inset Quotes srd
26928 \end_inset 
26929
26930
26931 \series default 
26932  
26933 \family default 
26934 will do.
26935 \layout Section
26936
26937 Getting Help
26938 \layout Standard
26939
26940 These links should take you directly to the 
26941 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
26942
26943 \end_inset 
26944
26945
26946 \begin_inset Foot
26947 collapsed false
26948
26949 \layout Standard
26950
26951 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
26952  automated messages (mid 2003)
26953 \end_inset 
26954
26955  and the 
26956 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
26957
26958 \end_inset 
26959
26960 , lists
26961 \begin_inset LatexCommand \index{Mailing list(s)}
26962
26963 \end_inset 
26964
26965  and forums are archived and searchable so if you are lucky someone already
26966  had a similar problem.
26967  While mails to the lists themselves are delivered promptly their web front
26968  end on sourceforge sometimes shows a severe time lag (up to several weeks),
26969  if you're seriously using SDCC please consider subscribing to the lists.
26970 \layout Section
26971
26972 ChangeLog
26973 \layout Standard
26974
26975 You can follow the status of the Subversion version
26976 \begin_inset LatexCommand \index{version}
26977
26978 \end_inset 
26979
26980  of SDCC by watching the Changelog
26981 \begin_inset LatexCommand \index{Changelog}
26982
26983 \end_inset 
26984
26985  in the Subversion repository
26986 \size footnotesize 
26987  
26988 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26989
26990 \end_inset 
26991
26992 .
26993 \layout Section
26994
26995 Subversion Source Code Repository
26996 \layout Standard
26997
26998 The output of 
26999 \family sans 
27000 \series bold 
27001 sdcc --version
27002 \family default 
27003 \series default 
27004  or the filenames of the snapshot versions of SDCC include date and its
27005  Subversion
27006 \begin_inset LatexCommand \index{Subversion code repository}
27007
27008 \end_inset 
27009
27010  number.
27011  Subversion allows to download the source of recent or previous versions
27012  
27013 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
27014
27015 \end_inset 
27016
27017  (by number or by date).
27018  An on-line source code browser and detailled instructions are also available
27019  there.
27020  SDCC versions starting from 1999 up to now are available (currently the
27021  versions prior to the conversion from cvs
27022 \begin_inset LatexCommand \index{cvs|see{Subversion}}
27023
27024 \end_inset 
27025
27026  to Subversion (April 2006) are either by accessible by Subversion or by
27027  cvs).
27028 \layout Section
27029
27030 Release policy
27031 \begin_inset LatexCommand \index{Release policy}
27032
27033 \end_inset 
27034
27035
27036 \layout Standard
27037
27038 Historically there often were long delays between official releases and
27039  the sourceforge download area tends to get not updated at all.
27040  Excuses in the past might have referred to problems with live range analysis,
27041  but as this was fixed a while ago, the current problem is that another
27042  excuse has to be found.
27043  Kidding aside, we have to get better there! On the other hand there are
27044  daily snapshots available at 
27045 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
27046
27047 \end_inset 
27048
27049 , and you can always build the very last version (hopefully with many bugs
27050  fixed, and features added) from the source code available at 
27051 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
27052
27053 \end_inset 
27054
27055 .
27056  A release wiki
27057 \begin_inset LatexCommand \index{wiki}
27058
27059 \end_inset 
27060
27061
27062 \begin_inset LatexCommand \index{Release wiki}
27063
27064 \end_inset 
27065
27066  at 
27067 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
27068
27069 \end_inset 
27070
27071  also holds some information about past and future releases.
27072 \layout Section
27073
27074 Examples
27075 \begin_inset LatexCommand \index{Examples}
27076
27077 \end_inset 
27078
27079
27080 \layout Standard
27081
27082 You'll find some small examples in the directory 
27083 \emph on 
27084 sdcc/device/examples/.
27085  
27086 \emph default 
27087 More examples and libraries are available at
27088 \emph on 
27089  The SDCC Open Knowledge Resource 
27090 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
27091
27092 \end_inset 
27093
27094  
27095 \emph default 
27096 web site or at 
27097 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
27098
27099 \end_inset 
27100
27101 .
27102 \layout Comment
27103
27104 I did insert a reference to Paul's web site here although it seems rather
27105  dedicated to a specific 8032 board (I think it's okay because it f.e.
27106  shows LCD/Harddisc interface and has a free 8051 monitor.
27107  Independent 8032 board vendors face hard competition of heavily subsidized
27108  development boards anyway).
27109 \layout Comment
27110
27111 Maybe we should include some links to real world applications.
27112  Preferably pointer to pointers (one for each architecture) so this stays
27113  manageable here?
27114 \layout Section
27115
27116 Quality control
27117 \begin_inset LatexCommand \label{sec:Quality-control}
27118
27119 \end_inset 
27120
27121
27122 \begin_inset LatexCommand \index{Quality control}
27123
27124 \end_inset 
27125
27126
27127 \layout Standard
27128
27129 The compiler is passed through nightly compile and build checks.
27130  The so called 
27131 \shape italic 
27132 regression tests
27133 \shape default 
27134
27135 \begin_inset LatexCommand \index{Regression test}
27136
27137 \end_inset 
27138
27139  check that SDCC itself compiles flawlessly on several host platforms (i386,
27140  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
27141  the quality of the code generated by SDCC by running the code for several
27142  target platforms through simulators.
27143  The regression test suite comprises more than 100 files which expand to
27144  more than 500 test cases which include more than 4500 tests.
27145  The results of these tests are published daily on SDCC's snapshot page
27146  (click on the red or green symbols on the right side of 
27147 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
27148
27149 \end_inset 
27150
27151 ).
27152 \layout Standard
27153
27154 There is a separate document 
27155 \shape italic 
27156 test_suite.pdf 
27157 \begin_inset LatexCommand \index{Test suite}
27158
27159 \end_inset 
27160
27161
27162 \shape default 
27163  
27164 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
27165
27166 \end_inset 
27167
27168  about the regression test suite.
27169 \layout Standard
27170
27171 You'll find the test code in the directory 
27172 \shape italic 
27173 sdcc/support/regression
27174 \shape default 
27175 .
27176  You can run these tests manually by running 
27177 \family sans 
27178 make
27179 \family default 
27180  in this directory (or f.e.
27181  
27182 \family sans 
27183 \series bold 
27184
27185 \begin_inset Quotes sld
27186 \end_inset 
27187
27188 make test-mcs51
27189 \begin_inset Quotes srd
27190 \end_inset 
27191
27192
27193 \family default 
27194 \series default 
27195  if you don't want to run the complete tests).
27196  The test code might also be interesting if you want to look for examples
27197 \begin_inset LatexCommand \index{Examples}
27198
27199 \end_inset 
27200
27201  checking corner cases of SDCC or if you plan to submit patches
27202 \begin_inset LatexCommand \index{Patch submission}
27203
27204 \end_inset 
27205
27206 .
27207 \layout Standard
27208
27209 The 14bit pic port uses a different set of regression tests 
27210 \begin_inset LatexCommand \index{Regression test (PIC14)}
27211
27212 \end_inset 
27213
27214 , you'll find them in the directory 
27215 \shape italic 
27216 sdcc/src/regression
27217 \shape default 
27218 .
27219 \layout Section
27220
27221 Use of SDCC in Education
27222 \layout Standard
27223
27224 In short: 
27225 \emph on 
27226 highly
27227 \emph default 
27228  encouraged
27229 \begin_inset Foot
27230 collapsed false
27231
27232 \layout Standard
27233
27234 the phrase "use in education" might evoke the association "
27235 \emph on 
27236 only
27237 \emph default 
27238  fit for use in education".
27239  This connotation is not intended but nevertheless risked as the licensing
27240  of SDCC makes it difficult to offer educational discounts
27241 \end_inset 
27242
27243 .
27244  If your rationales are to:
27245 \layout Enumerate
27246
27247 give students a chance to understand the 
27248 \emph on 
27249 complete
27250 \emph default 
27251  steps of code generation
27252 \layout Enumerate
27253
27254 have a curriculum that can be extended for years.
27255  Then you could use an fpga board as target and your curriculum will seamlessly
27256  extend from logic synthesis (
27257 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
27258
27259 \end_inset 
27260
27261
27262 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
27263
27264 \end_inset 
27265
27266 ), over assembly programming, to C to FPGA compilers (
27267 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
27268
27269 \end_inset 
27270
27271 ) and to C.
27272 \layout Enumerate
27273
27274 be able to insert excursions about skills like using a revision control
27275  system, submitting/applying patches, using a type-setting (as opposed to
27276  word-processing) engine LyX/LaTeX, using 
27277 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
27278
27279 \end_inset 
27280
27281 , following some 
27282 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
27283
27284 \end_inset 
27285
27286 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
27287  Source Software, CPU simulation, compiler regression tests
27288 \begin_inset LatexCommand \index{Regression test}
27289
27290 \end_inset 
27291
27292 .
27293  
27294 \newline 
27295 And if there should be a shortage of ideas then you can always point students
27296  to the ever-growing feature request list 
27297 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
27298
27299 \end_inset 
27300
27301 .
27302 \layout Enumerate
27303
27304 not tie students to a specific host platform and instead allow them to use
27305  a host platform of 
27306 \emph on 
27307 their
27308 \emph default 
27309  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
27310  eventually 
27311 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
27312
27313 \end_inset 
27314
27315 )
27316 \layout Enumerate
27317
27318 not encourage students to use illegal copies of educational software
27319 \layout Enumerate
27320
27321 be immune to licensing/availability/price changes of the chosen tool chain
27322 \layout Enumerate
27323
27324 be able to change to a new target platform without having to adopt a new
27325  tool chain
27326 \layout Enumerate
27327
27328 have complete control over and insight into the tool chain
27329 \layout Enumerate
27330
27331 make your students aware about the pros and cons of open source software
27332  development
27333 \layout Enumerate
27334
27335 give back to the public as you are probably at least partially publically
27336  funded
27337 \layout Enumerate
27338
27339 give students a chance to publically prove their skills and to possibly
27340  see a world wide impact
27341 \layout Standard
27342
27343 then SDCC is probably among the first choices.
27344  Well, probably SDCC might be the only choice.
27345 \layout Chapter
27346 \pagebreak_top 
27347 SDCC Technical Data
27348 \layout Section
27349
27350 Optimizations
27351 \begin_inset LatexCommand \index{Optimizations}
27352
27353 \end_inset 
27354
27355
27356 \layout Standard
27357
27358 SDCC performs a host of standard optimizations in addition to some MCU specific
27359  optimizations.
27360  
27361 \layout Subsection
27362
27363 Sub-expression Elimination
27364 \begin_inset LatexCommand \index{Subexpression elimination}
27365
27366 \end_inset 
27367
27368
27369 \layout Standard
27370
27371 The compiler does local and 
27372 \emph on 
27373 g
27374 \emph default 
27375 lobal 
27376 \emph on 
27377 c
27378 \emph default 
27379 ommon 
27380 \emph on 
27381 s
27382 \emph default 
27383 ubexpression 
27384 \emph on 
27385 e
27386 \emph default 
27387 limination, e.g.: 
27388 \layout Verse
27389
27390
27391 \family typewriter 
27392 i = x + y + 1; 
27393 \newline 
27394 j = x + y;
27395 \layout Standard
27396
27397 will be translated to
27398 \layout Verse
27399
27400
27401 \family typewriter 
27402 iTemp = x + y; 
27403 \newline 
27404 i = iTemp + 1; 
27405 \newline 
27406 j = iTemp;
27407 \layout Standard
27408
27409 Some subexpressions are not as obvious as the above example, e.g.:
27410 \layout Verse
27411
27412
27413 \family typewriter 
27414 a->b[i].c = 10; 
27415 \newline 
27416 a->b[i].d = 11;
27417 \layout Standard
27418
27419 In this case the address arithmetic a->b[i] will be computed only once;
27420  the equivalent code in C would be.
27421 \layout Verse
27422
27423
27424 \family typewriter 
27425 iTemp = a->b[i]; 
27426 \newline 
27427 iTemp.c = 10; 
27428 \newline 
27429 iTemp.d = 11;
27430 \layout Standard
27431
27432 The compiler will try to keep these temporary variables in registers.
27433 \layout Subsection
27434
27435 Dead-Code Elimination
27436 \begin_inset LatexCommand \index{Dead-code elimination}
27437
27438 \end_inset 
27439
27440
27441 \layout Verse
27442
27443
27444 \family typewriter 
27445 int global;
27446 \newline 
27447
27448 \newline 
27449 void f () { 
27450 \newline 
27451 \SpecialChar ~
27452 \SpecialChar ~
27453 int i; 
27454 \newline 
27455 \SpecialChar ~
27456 \SpecialChar ~
27457 i = 1; \SpecialChar ~
27458 \SpecialChar ~
27459 \SpecialChar ~
27460 \SpecialChar ~
27461 \SpecialChar ~
27462 /* dead store */ 
27463 \newline 
27464 \SpecialChar ~
27465 \SpecialChar ~
27466 global = 1;\SpecialChar ~
27467 /* dead store */ 
27468 \newline 
27469 \SpecialChar ~
27470 \SpecialChar ~
27471 global = 2; 
27472 \newline 
27473 \SpecialChar ~
27474 \SpecialChar ~
27475 return; 
27476 \newline 
27477 \SpecialChar ~
27478 \SpecialChar ~
27479 global = 3;\SpecialChar ~
27480 /* unreachable */ 
27481 \newline 
27482 }
27483 \layout Standard
27484
27485 will be changed to
27486 \layout Verse
27487
27488
27489 \family typewriter 
27490 int global;
27491 \newline 
27492
27493 \newline 
27494 void f () {
27495 \newline 
27496 \SpecialChar ~
27497 \SpecialChar ~
27498 global = 2; 
27499 \newline 
27500 }
27501 \layout Subsection
27502
27503 Copy-Propagation
27504 \begin_inset LatexCommand \index{Copy propagation}
27505
27506 \end_inset 
27507
27508
27509 \layout Verse
27510
27511
27512 \family typewriter 
27513 int f() { 
27514 \newline 
27515 \SpecialChar ~
27516 \SpecialChar ~
27517 int i, j; 
27518 \newline 
27519 \SpecialChar ~
27520 \SpecialChar ~
27521 i = 10; 
27522 \newline 
27523 \SpecialChar ~
27524 \SpecialChar ~
27525 j = i; 
27526 \newline 
27527 \SpecialChar ~
27528 \SpecialChar ~
27529 return j; 
27530 \newline 
27531 }
27532 \layout Standard
27533
27534 will be changed to 
27535 \layout Verse
27536
27537
27538 \family typewriter 
27539 int f() { 
27540 \newline 
27541 \SpecialChar ~
27542 \SpecialChar ~
27543 int i, j; 
27544 \newline 
27545 \SpecialChar ~
27546 \SpecialChar ~
27547 i = 10; 
27548 \newline 
27549 \SpecialChar ~
27550 \SpecialChar ~
27551 j = 10; 
27552 \newline 
27553 \SpecialChar ~
27554 \SpecialChar ~
27555 return 10; 
27556 \newline 
27557 }
27558 \layout Standard
27559
27560 Note: the dead stores created by this copy propagation will be eliminated
27561  by dead-code elimination.
27562 \layout Subsection
27563
27564 Loop Optimizations
27565 \begin_inset LatexCommand \index{Loop optimization}
27566
27567 \end_inset 
27568
27569
27570 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
27571
27572 \end_inset 
27573
27574
27575 \layout Standard
27576
27577 Two types of loop optimizations are done by SDCC 
27578 \emph on 
27579 loop invariant
27580 \emph default 
27581  lifting and
27582 \emph on 
27583  strength reduction
27584 \emph default 
27585  of loop induction variables.
27586  In addition to the strength reduction the optimizer marks the induction
27587  variables and the register allocator tries to keep the induction variables
27588  in registers for the duration of the loop.
27589  Because of this preference of the register allocator
27590 \begin_inset LatexCommand \index{Register allocation}
27591
27592 \end_inset 
27593
27594 , loop induction optimization causes an increase in register pressure, which
27595  may cause unwanted spilling of other temporary variables into the stack
27596 \begin_inset LatexCommand \index{stack}
27597
27598 \end_inset 
27599
27600  / data space.
27601  The compiler will generate a warning message when it is forced to allocate
27602  extra space either on the stack or data space.
27603  If this extra space allocation is undesirable then induction optimization
27604  can be eliminated either for the entire source file (with -
27605 \begin_inset ERT
27606 status Collapsed
27607
27608 \layout Standard
27609
27610 \backslash 
27611 /
27612 \end_inset 
27613
27614 -noinduction option) or for a given function only using #pragma\SpecialChar ~
27615 noinduction
27616 \begin_inset LatexCommand \index{\#pragma noinduction}
27617
27618 \end_inset 
27619
27620 .
27621 \newline 
27622
27623 \newline 
27624 Loop Invariant:
27625 \layout Verse
27626
27627
27628 \family typewriter 
27629 for (i = 0 ; i < 100 ; i ++) 
27630 \newline 
27631 \SpecialChar ~
27632 \SpecialChar ~
27633 \SpecialChar ~
27634 \SpecialChar ~
27635 f += k + l;
27636 \layout Standard
27637
27638 changed to
27639 \layout Verse
27640
27641
27642 \family typewriter 
27643 itemp = k + l; 
27644 \newline 
27645 for (i = 0; i < 100; i++) 
27646 \newline 
27647 \SpecialChar ~
27648 \SpecialChar ~
27649 \SpecialChar ~
27650 \SpecialChar ~
27651 f += itemp;
27652 \layout Standard
27653
27654 As mentioned previously some loop invariants are not as apparent, all static
27655  address computations are also moved out of the loop.
27656 \newline 
27657
27658 \newline 
27659 Strength Reduction
27660 \begin_inset LatexCommand \index{Strength reduction}
27661
27662 \end_inset 
27663
27664 , this optimization substitutes an expression by a cheaper expression:
27665 \layout Verse
27666
27667
27668 \family typewriter 
27669 for (i=0;i < 100; i++)
27670 \newline 
27671 \SpecialChar ~
27672 \SpecialChar ~
27673 \SpecialChar ~
27674 \SpecialChar ~
27675 ar[i*5] = i*3;
27676 \layout Standard
27677
27678 changed to
27679 \layout Verse
27680
27681
27682 \family typewriter 
27683 itemp1 = 0; 
27684 \newline 
27685 itemp2 = 0; 
27686 \newline 
27687 for (i=0;i< 100;i++) { 
27688 \newline 
27689 \SpecialChar ~
27690 \SpecialChar ~
27691 \SpecialChar ~
27692 \SpecialChar ~
27693 ar[itemp1] = itemp2; 
27694 \newline 
27695 \SpecialChar ~
27696 \SpecialChar ~
27697 \SpecialChar ~
27698 \SpecialChar ~
27699 itemp1 += 5; 
27700 \newline 
27701 \SpecialChar ~
27702 \SpecialChar ~
27703 \SpecialChar ~
27704 \SpecialChar ~
27705 itemp2 += 3; 
27706 \newline 
27707 }
27708 \layout Standard
27709
27710 The more expensive multiplication
27711 \begin_inset LatexCommand \index{Multiplication}
27712
27713 \end_inset 
27714
27715  is changed to a less expensive addition.
27716 \layout Subsection
27717
27718 Loop Reversing
27719 \begin_inset LatexCommand \index{Loop reversing}
27720
27721 \end_inset 
27722
27723
27724 \layout Standard
27725
27726 This optimization is done to reduce the overhead of checking loop boundaries
27727  for every iteration.
27728  Some simple loops can be reversed and implemented using a 
27729 \begin_inset Quotes eld
27730 \end_inset 
27731
27732 decrement and jump if not zero
27733 \begin_inset Quotes erd
27734 \end_inset 
27735
27736  instruction.
27737  SDCC checks for the following criterion to determine if a loop is reversible
27738  (note: more sophisticated compilers use data-dependency analysis to make
27739  this determination, SDCC uses a more simple minded analysis).
27740 \layout Itemize
27741
27742 The 'for' loop is of the form 
27743 \newline 
27744
27745 \newline 
27746
27747 \family typewriter 
27748 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
27749  += 1])
27750 \newline 
27751 \SpecialChar ~
27752 \SpecialChar ~
27753 \SpecialChar ~
27754 \SpecialChar ~
27755 <for body>
27756 \layout Itemize
27757
27758 The <for body> does not contain 
27759 \begin_inset Quotes eld
27760 \end_inset 
27761
27762 continue
27763 \begin_inset Quotes erd
27764 \end_inset 
27765
27766  or 'break
27767 \begin_inset Quotes erd
27768 \end_inset 
27769
27770 .
27771 \layout Itemize
27772
27773 All goto's are contained within the loop.
27774 \layout Itemize
27775
27776 No function calls within the loop.
27777 \layout Itemize
27778
27779 The loop control variable <sym> is not assigned any value within the loop
27780 \layout Itemize
27781
27782 The loop control variable does NOT participate in any arithmetic operation
27783  within the loop.
27784 \layout Itemize
27785
27786 There are NO switch statements in the loop.
27787 \layout Subsection
27788
27789 Algebraic Simplifications
27790 \layout Standard
27791
27792 SDCC does numerous algebraic simplifications, the following is a small sub-set
27793  of these optimizations.
27794 \layout Verse
27795
27796
27797 \family typewriter 
27798 i = j + 0;\SpecialChar ~
27799 \SpecialChar ~
27800 \SpecialChar ~
27801 \SpecialChar ~
27802  /* changed to: */\SpecialChar ~
27803 \SpecialChar ~
27804 \SpecialChar ~
27805 \SpecialChar ~
27806  i = j; 
27807 \newline 
27808 i /= 2;\SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 \SpecialChar ~
27812 \SpecialChar ~
27813 \SpecialChar ~
27814 \SpecialChar ~
27815  /* changed to: */\SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818 \SpecialChar ~
27819  i >>= 1; 
27820 \newline 
27821 i = j - j;\SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825  /* changed to: */\SpecialChar ~
27826 \SpecialChar ~
27827 \SpecialChar ~
27828 \SpecialChar ~
27829  i = 0; 
27830 \newline 
27831 i = j / 1;\SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835  /* changed to: */\SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838 \SpecialChar ~
27839  i = j;
27840 \layout Standard
27841
27842 Note the subexpressions
27843 \begin_inset LatexCommand \index{Subexpression}
27844
27845 \end_inset 
27846
27847  given above are generally introduced by macro expansions or as a result
27848  of copy/constant propagation.
27849 \layout Subsection
27850
27851 'switch' Statements
27852 \begin_inset LatexCommand \label{sub:'switch'-Statements}
27853
27854 \end_inset 
27855
27856
27857 \begin_inset LatexCommand \index{switch statement}
27858
27859 \end_inset 
27860
27861
27862 \layout Standard
27863
27864 SDCC can optimize switch statements to jump tables
27865 \begin_inset LatexCommand \index{jump tables}
27866
27867 \end_inset 
27868
27869 .
27870  It makes the decision based on an estimate of the generated code size.
27871  SDCC is quite liberal in the requirements for jump table generation: 
27872 \layout Itemize
27873
27874 The labels need not be in order, and the starting number need not be one
27875  or zero, the case labels are in numerical sequence or not too many case
27876  labels are missing.
27877 \begin_deeper 
27878 \layout Verse
27879
27880
27881 \family typewriter 
27882 switch(i) {\SpecialChar ~
27883 \SpecialChar ~
27884 \SpecialChar ~
27885 \SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 \SpecialChar ~
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 switch (i) { 
27909 \newline 
27910 \SpecialChar ~
27911 \SpecialChar ~
27912 \SpecialChar ~
27913 case 4: ...\SpecialChar ~
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920 \SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925 \SpecialChar ~
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935 \SpecialChar ~
27936 \SpecialChar ~
27937 \SpecialChar ~
27938 \SpecialChar ~
27939 case 0: ...
27940  
27941 \newline 
27942 \SpecialChar ~
27943 \SpecialChar ~
27944 \SpecialChar ~
27945 case 5: ...\SpecialChar ~
27946 \SpecialChar ~
27947 \SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950 \SpecialChar ~
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955 \SpecialChar ~
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960 \SpecialChar ~
27961 \SpecialChar ~
27962 \SpecialChar ~
27963 \SpecialChar ~
27964 \SpecialChar ~
27965 \SpecialChar ~
27966 \SpecialChar ~
27967 \SpecialChar ~
27968 \SpecialChar ~
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 case 1: ...
27972  
27973 \newline 
27974 \SpecialChar ~
27975 \SpecialChar ~
27976 \SpecialChar ~
27977 case 3: ...\SpecialChar ~
27978 \SpecialChar ~
27979 \SpecialChar ~
27980 \SpecialChar ~
27981 \SpecialChar ~
27982 \SpecialChar ~
27983 \SpecialChar ~
27984 \SpecialChar ~
27985 \SpecialChar ~
27986 \SpecialChar ~
27987 \SpecialChar ~
27988 \SpecialChar ~
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992 \SpecialChar ~
27993 \SpecialChar ~
27994 \SpecialChar ~
27995 \SpecialChar ~
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 \SpecialChar ~
28003
28004 \newline 
28005 \SpecialChar ~
28006 \SpecialChar ~
28007 \SpecialChar ~
28008 case 6: ...\SpecialChar ~
28009 \SpecialChar ~
28010 \SpecialChar ~
28011 \SpecialChar ~
28012 \SpecialChar ~
28013 \SpecialChar ~
28014 \SpecialChar ~
28015 \SpecialChar ~
28016 \SpecialChar ~
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 \SpecialChar ~
28020 \SpecialChar ~
28021 \SpecialChar ~
28022 \SpecialChar ~
28023 \SpecialChar ~
28024 \SpecialChar ~
28025 \SpecialChar ~
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 \SpecialChar ~
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 case 3: ...
28035  
28036 \newline 
28037 \SpecialChar ~
28038 \SpecialChar ~
28039 \SpecialChar ~
28040 case 7: ...\SpecialChar ~
28041 \SpecialChar ~
28042 \SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045 \SpecialChar ~
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 case 4: ...
28067  
28068 \newline 
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072 case 8: ...\SpecialChar ~
28073 \SpecialChar ~
28074 \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 \SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 case 5: ...
28099  
28100 \newline 
28101 \SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104 case 9: ...\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 \SpecialChar ~
28120 \SpecialChar ~
28121 \SpecialChar ~
28122 \SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130 case 6: ...
28131  
28132 \newline 
28133 \SpecialChar ~
28134 \SpecialChar ~
28135 \SpecialChar ~
28136 case 10: ...\SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147 \SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150 \SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 \SpecialChar ~
28160 \SpecialChar ~
28161 case 7: ...
28162  
28163 \newline 
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 case 11: ...\SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182 \SpecialChar ~
28183 \SpecialChar ~
28184 \SpecialChar ~
28185 \SpecialChar ~
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189 \SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192 case 8: ...
28193  
28194 \newline 
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 \SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214 \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 \SpecialChar ~
28230 \SpecialChar ~
28231 }
28232 \layout Standard
28233
28234 Both the above switch statements will be implemented using a jump-table.
28235  The example to the right side is slightly more efficient as the check for
28236  the lower boundary of the jump-table is not needed.
28237 \end_deeper 
28238 \layout Itemize
28239
28240 The number of case labels is not larger than supported by the target architectur
28241 e.
28242 \layout Itemize
28243
28244 If the case labels are not in numerical sequence ('gaps' between cases)
28245  SDCC checks whether a jump table with additionally inserted dummy cases
28246  is still attractive.
28247  
28248 \layout Itemize
28249
28250 If the starting number is not zero and a check for the lower boundary of
28251  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
28252  ...
28253  .
28254 \layout Standard
28255
28256 Switch statements which have large gaps in the numeric sequence or those
28257  that have too many case labels can be split into more than one switch statement
28258  for efficient code generation, e.g.:
28259 \layout Verse
28260
28261
28262 \family typewriter 
28263 switch (i) { 
28264 \newline 
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 case 1: ...
28268  
28269 \newline 
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 case 2: ...
28273  
28274 \newline 
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 case 3: ...
28278  
28279 \newline 
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 case 4: ...
28283  
28284 \newline 
28285 \SpecialChar ~
28286 \SpecialChar ~
28287 case 5: ...
28288  
28289 \newline 
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 case 6: ...
28293  
28294 \newline 
28295 \SpecialChar ~
28296 \SpecialChar ~
28297 case 7: ...
28298  
28299 \newline 
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 case 101: ...
28303  
28304 \newline 
28305 \SpecialChar ~
28306 \SpecialChar ~
28307 case 102: ...
28308  
28309 \newline 
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 case 103: ...
28313  
28314 \newline 
28315 \SpecialChar ~
28316 \SpecialChar ~
28317 case 104: ...
28318  
28319 \newline 
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 case 105: ...
28323  
28324 \newline 
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 case 106: ...
28328  
28329 \newline 
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 case 107: ...
28333  
28334 \newline 
28335 }
28336 \layout Standard
28337
28338 If the above switch statement is broken down into two switch statements
28339 \layout Verse
28340
28341
28342 \family typewriter 
28343 switch (i) { 
28344 \newline 
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 case 1: ...
28348  
28349 \newline 
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 case 2: ...
28353  
28354 \newline 
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 case 3: ...
28358  
28359 \newline 
28360 \SpecialChar ~
28361 \SpecialChar ~
28362 case 4: ...
28363  
28364 \newline 
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 case 5: ...
28368  
28369 \newline 
28370 \SpecialChar ~
28371 \SpecialChar ~
28372 case 6: ...
28373  
28374 \newline 
28375 \SpecialChar ~
28376 \SpecialChar ~
28377 case 7: ...
28378  
28379 \newline 
28380 }
28381 \layout Standard
28382
28383 and
28384 \layout Verse
28385
28386
28387 \family typewriter 
28388 switch (i) { 
28389 \newline 
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 case 101: ...
28393  
28394 \newline 
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 case 102: ...
28398  
28399 \newline 
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 case 103: ...
28403  
28404 \newline 
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 case 104: ...
28408  
28409 \newline 
28410 \SpecialChar ~
28411 \SpecialChar ~
28412 case 105: ...
28413  
28414 \newline 
28415 \SpecialChar ~
28416 \SpecialChar ~
28417 case 106: ...
28418  
28419 \newline 
28420 \SpecialChar ~
28421 \SpecialChar ~
28422 case 107: ...
28423  
28424 \newline 
28425 }
28426 \layout Standard
28427
28428 then both the switch statements will be implemented using jump-tables whereas
28429  the unmodified switch statement will not be.
28430 \layout Comment
28431
28432 There might be reasons which SDCC cannot know about to either favour or
28433  not favour jump tables.
28434  If the target system has to be as quick for the last switch case as for
28435  the first (pro jump table), or if the switch argument is known to be zero
28436  in the majority of the cases (contra jump table).
28437 \layout Standard
28438
28439 The pragma nojtbound
28440 \begin_inset LatexCommand \index{\#pragma nojtbound}
28441
28442 \end_inset 
28443
28444  can be used to turn off checking the 
28445 \emph on 
28446 j
28447 \emph default 
28448 ump 
28449 \emph on 
28450 t
28451 \emph default 
28452 able 
28453 \emph on 
28454 bound
28455 \emph default 
28456 aries.
28457  It has no effect if a default label is supplied.
28458  Use of this pragma is dangerous: if the switch
28459 \begin_inset LatexCommand \index{switch statement}
28460
28461 \end_inset 
28462
28463  argument is not matched by a case statement the processor will happily
28464  jump into Nirvana.
28465 \layout Subsection
28466
28467 Bit-shifting Operations
28468 \begin_inset LatexCommand \index{Bit shifting}
28469
28470 \end_inset 
28471
28472 .
28473 \layout Standard
28474
28475 Bit shifting is one of the most frequently used operation in embedded programmin
28476 g.
28477  SDCC tries to implement bit-shift operations in the most efficient way
28478  possible, e.g.:
28479 \layout Verse
28480
28481
28482 \family typewriter 
28483 unsigned char i;
28484 \newline 
28485 ...
28486  
28487 \newline 
28488 i >>= 4; 
28489 \newline 
28490 ...
28491 \layout Standard
28492
28493 generates the following code:
28494 \layout Verse
28495
28496
28497 \family typewriter 
28498 mov\SpecialChar ~
28499  a,_i 
28500 \newline 
28501 swap a 
28502 \newline 
28503 anl\SpecialChar ~
28504  a,#0x0f 
28505 \newline 
28506 mov\SpecialChar ~
28507  _i,a
28508 \layout Standard
28509
28510 In general SDCC will never setup a loop if the shift count is known.
28511  Another example:
28512 \layout Verse
28513
28514
28515 \family typewriter 
28516 unsigned int i; 
28517 \newline 
28518 ...
28519  
28520 \newline 
28521 i >>= 9; 
28522 \newline 
28523 ...
28524 \layout Standard
28525
28526 will generate:
28527 \layout Verse
28528
28529
28530 \family typewriter 
28531 mov\SpecialChar ~
28532 \SpecialChar ~
28533 a,(_i + 1) 
28534 \newline 
28535 mov\SpecialChar ~
28536 \SpecialChar ~
28537 (_i + 1),#0x00 
28538 \newline 
28539 clr\SpecialChar ~
28540 \SpecialChar ~
28541
28542 \newline 
28543 rrc\SpecialChar ~
28544 \SpecialChar ~
28545
28546 \newline 
28547 mov\SpecialChar ~
28548 \SpecialChar ~
28549 _i,a
28550 \layout Subsection
28551
28552 Bit-rotation
28553 \begin_inset LatexCommand \index{Bit rotation}
28554
28555 \end_inset 
28556
28557
28558 \layout Standard
28559
28560 A special case of the bit-shift operation is bit rotation
28561 \begin_inset LatexCommand \index{rotating bits}
28562
28563 \end_inset 
28564
28565 , SDCC recognizes the following expression to be a left bit-rotation:
28566 \layout Verse
28567
28568
28569 \family typewriter 
28570 \series bold 
28571 unsigned
28572 \series default 
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 char i;\SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580 \SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 /* unsigned is needed for rotation */ 
28587 \newline 
28588 ...
28589  
28590 \newline 
28591 i = ((i << 1) | (i >> 7)); 
28592 \family default 
28593
28594 \newline 
28595
28596 \family typewriter 
28597 ...
28598 \layout Standard
28599
28600 will generate the following code:
28601 \layout Verse
28602
28603
28604 \family typewriter 
28605 mov\SpecialChar ~
28606 \SpecialChar ~
28607 a,_i 
28608 \newline 
28609 rl\SpecialChar ~
28610 \SpecialChar ~
28611 \SpecialChar ~
28612
28613 \newline 
28614 mov\SpecialChar ~
28615 \SpecialChar ~
28616 _i,a
28617 \layout Standard
28618
28619 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
28620 ns of this case will also be recognized as bit-rotation, i.e.: 
28621 \layout Verse
28622
28623
28624 \family typewriter 
28625 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
28626 \layout Subsection
28627
28628 Nibble and Byte Swapping
28629 \layout Standard
28630
28631 Other special cases of the bit-shift operations are nibble or byte swapping
28632 \begin_inset LatexCommand \index{swapping nibbles/bytes}
28633
28634 \end_inset 
28635
28636 , SDCC recognizes the following expressions:
28637 \layout Verse
28638
28639
28640 \family typewriter 
28641 \series bold 
28642 unsigned
28643 \series default 
28644 \SpecialChar ~
28645 \SpecialChar ~
28646 char i; 
28647 \newline 
28648
28649 \series bold 
28650 unsigned
28651 \series default 
28652 \SpecialChar ~
28653 \SpecialChar ~
28654 int j; 
28655 \newline 
28656 ...
28657  
28658 \newline 
28659 i = ((i << 4) | (i >> 4)); 
28660 \family default 
28661
28662 \newline 
28663
28664 \family typewriter 
28665 j = ((j << 8) | (j >> 8)); 
28666 \layout Standard
28667
28668 and generates a swap instruction for the nibble swapping
28669 \begin_inset LatexCommand \index{Nibble swapping}
28670
28671 \end_inset 
28672
28673  or move instructions for the byte swapping
28674 \begin_inset LatexCommand \index{Byte swapping}
28675
28676 \end_inset 
28677
28678 .
28679  The 
28680 \begin_inset Quotes sld
28681 \end_inset 
28682
28683 j
28684 \begin_inset Quotes srd
28685 \end_inset 
28686
28687  example can be used to convert from little to big-endian or vice versa.
28688  If you want to change the endianness of a 
28689 \emph on 
28690 signed
28691 \emph default 
28692  integer you have to cast to 
28693 \family typewriter 
28694 (unsigned int)
28695 \family default 
28696  first.
28697 \layout Standard
28698
28699 Note that SDCC stores numbers in little-endian
28700 \begin_inset Foot
28701 collapsed false
28702
28703 \layout Standard
28704
28705 Usually 8-bit processors don't care much about endianness.
28706  This is not the case for the standard 8051 which only has an instruction
28707  to increment its 
28708 \emph on 
28709 dptr
28710 \emph default 
28711
28712 \begin_inset LatexCommand \index{DPTR}
28713
28714 \end_inset 
28715
28716 -datapointer
28717 \emph on 
28718  
28719 \emph default 
28720 so little-endian is the more efficient byte order.
28721 \end_inset 
28722
28723
28724 \begin_inset LatexCommand \index{little-endian}
28725
28726 \end_inset 
28727
28728
28729 \begin_inset LatexCommand \index{Endianness}
28730
28731 \end_inset 
28732
28733  format (i.e.
28734  lowest order first).
28735 \layout Subsection
28736
28737 Highest Order Bit
28738 \begin_inset LatexCommand \index{Highest Order Bit}
28739
28740 \end_inset 
28741
28742  / Any Order Bit
28743 \begin_inset LatexCommand \index{Any Order Bit}
28744
28745 \end_inset 
28746
28747
28748 \layout Standard
28749
28750 It is frequently required to obtain the highest order bit of an integral
28751  type (long, int, short or char types).
28752  Also obtaining any other order bit is not uncommon.
28753  SDCC recognizes the following expressions to yield the highest order bit
28754  and generates optimized code for it, e.g.:
28755 \layout Verse
28756
28757
28758 \family typewriter 
28759 unsigned int gint; 
28760 \newline 
28761
28762 \newline 
28763 foo () { 
28764 \newline 
28765 \SpecialChar ~
28766 \SpecialChar ~
28767 unsigned char hob1, aob1; 
28768 \newline 
28769 \SpecialChar ~
28770 \SpecialChar ~
28771 bit hob2, hob3, aob2, aob3; 
28772 \newline 
28773 \SpecialChar ~
28774 \SpecialChar ~
28775 ...
28776  
28777 \newline 
28778 \SpecialChar ~
28779 \SpecialChar ~
28780 hob1 = (gint >> 15) & 1; 
28781 \newline 
28782 \SpecialChar ~
28783 \SpecialChar ~
28784 hob2 = (gint >> 15) & 1; 
28785 \newline 
28786 \SpecialChar ~
28787 \SpecialChar ~
28788 hob3 = gint & 0x8000; 
28789 \newline 
28790 \SpecialChar ~
28791 \SpecialChar ~
28792 aob1 = (gint >> 9) & 1; 
28793 \newline 
28794 \SpecialChar ~
28795 \SpecialChar ~
28796 aob2 = (gint >> 8) & 1; 
28797 \newline 
28798 \SpecialChar ~
28799 \SpecialChar ~
28800 aob3 = gint & 0x0800; 
28801 \newline 
28802 \SpecialChar ~
28803 \SpecialChar ~
28804 ..
28805  
28806 \newline 
28807 }
28808 \layout Standard
28809
28810 will generate the following code:
28811 \layout Verse
28812
28813
28814 \family typewriter 
28815 \SpecialChar ~
28816 \SpecialChar ~
28817 \SpecialChar ~
28818 \SpecialChar ~
28819 \SpecialChar ~
28820 \SpecialChar ~
28821 \SpecialChar ~
28822 \SpecialChar ~
28823 \SpecialChar ~
28824 \SpecialChar ~
28825 \SpecialChar ~
28826 \SpecialChar ~
28827 \SpecialChar ~
28828 \SpecialChar ~
28829 \SpecialChar ~
28830 \SpecialChar ~
28831 \SpecialChar ~
28832 \SpecialChar ~
28833 \SpecialChar ~
28834 \SpecialChar ~
28835 \SpecialChar ~
28836 \SpecialChar ~
28837 \SpecialChar ~
28838 \SpecialChar ~
28839 \SpecialChar ~
28840  61 ;\SpecialChar ~
28841  hob.c 7 
28842 \newline 
28843 000A E5*01\SpecialChar ~
28844 \SpecialChar ~
28845 \SpecialChar ~
28846 \SpecialChar ~
28847 \SpecialChar ~
28848 \SpecialChar ~
28849 \SpecialChar ~
28850 \SpecialChar ~
28851 \SpecialChar ~
28852 \SpecialChar ~
28853 \SpecialChar ~
28854 \SpecialChar ~
28855 \SpecialChar ~
28856 \SpecialChar ~
28857 \SpecialChar ~
28858  62\SpecialChar ~
28859 \SpecialChar ~
28860 \SpecialChar ~
28861 \SpecialChar ~
28862 \SpecialChar ~
28863 \SpecialChar ~
28864 \SpecialChar ~
28865 \SpecialChar ~
28866  mov\SpecialChar ~
28867 \SpecialChar ~
28868  a,(_gint + 1) 
28869 \newline 
28870 000C 23\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 \SpecialChar ~
28888  63\SpecialChar ~
28889 \SpecialChar ~
28890 \SpecialChar ~
28891 \SpecialChar ~
28892 \SpecialChar ~
28893 \SpecialChar ~
28894 \SpecialChar ~
28895 \SpecialChar ~
28896  rl\SpecialChar ~
28897 \SpecialChar ~
28898 \SpecialChar ~
28899  a 
28900 \newline 
28901 000D 54 01\SpecialChar ~
28902 \SpecialChar ~
28903 \SpecialChar ~
28904 \SpecialChar ~
28905 \SpecialChar ~
28906 \SpecialChar ~
28907 \SpecialChar ~
28908 \SpecialChar ~
28909 \SpecialChar ~
28910 \SpecialChar ~
28911 \SpecialChar ~
28912 \SpecialChar ~
28913 \SpecialChar ~
28914 \SpecialChar ~
28915 \SpecialChar ~
28916  64\SpecialChar ~
28917 \SpecialChar ~
28918 \SpecialChar ~
28919 \SpecialChar ~
28920 \SpecialChar ~
28921 \SpecialChar ~
28922 \SpecialChar ~
28923 \SpecialChar ~
28924  anl\SpecialChar ~
28925 \SpecialChar ~
28926  a,#0x01 
28927 \newline 
28928 000F F5*02\SpecialChar ~
28929 \SpecialChar ~
28930 \SpecialChar ~
28931 \SpecialChar ~
28932 \SpecialChar ~
28933 \SpecialChar ~
28934 \SpecialChar ~
28935 \SpecialChar ~
28936 \SpecialChar ~
28937 \SpecialChar ~
28938 \SpecialChar ~
28939 \SpecialChar ~
28940 \SpecialChar ~
28941 \SpecialChar ~
28942 \SpecialChar ~
28943  65\SpecialChar ~
28944 \SpecialChar ~
28945 \SpecialChar ~
28946 \SpecialChar ~
28947 \SpecialChar ~
28948 \SpecialChar ~
28949 \SpecialChar ~
28950 \SpecialChar ~
28951  mov\SpecialChar ~
28952 \SpecialChar ~
28953  _foo_hob1_1_1,a 
28954 \newline 
28955 \SpecialChar ~
28956 \SpecialChar ~
28957 \SpecialChar ~
28958 \SpecialChar ~
28959 \SpecialChar ~
28960 \SpecialChar ~
28961 \SpecialChar ~
28962 \SpecialChar ~
28963 \SpecialChar ~
28964 \SpecialChar ~
28965 \SpecialChar ~
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  66 ;\SpecialChar ~
28981  hob.c 8 
28982 \newline 
28983 0011 E5*01\SpecialChar ~
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 \SpecialChar ~
28987 \SpecialChar ~
28988 \SpecialChar ~
28989 \SpecialChar ~
28990 \SpecialChar ~
28991 \SpecialChar ~
28992 \SpecialChar ~
28993 \SpecialChar ~
28994 \SpecialChar ~
28995 \SpecialChar ~
28996 \SpecialChar ~
28997 \SpecialChar ~
28998  67\SpecialChar ~
28999 \SpecialChar ~
29000 \SpecialChar ~
29001 \SpecialChar ~
29002 \SpecialChar ~
29003 \SpecialChar ~
29004 \SpecialChar ~
29005 \SpecialChar ~
29006  mov\SpecialChar ~
29007 \SpecialChar ~
29008  a,(_gint + 1) 
29009 \newline 
29010 0013 33\SpecialChar ~
29011 \SpecialChar ~
29012 \SpecialChar ~
29013 \SpecialChar ~
29014 \SpecialChar ~
29015 \SpecialChar ~
29016 \SpecialChar ~
29017 \SpecialChar ~
29018 \SpecialChar ~
29019 \SpecialChar ~
29020 \SpecialChar ~
29021 \SpecialChar ~
29022 \SpecialChar ~
29023 \SpecialChar ~
29024 \SpecialChar ~
29025 \SpecialChar ~
29026 \SpecialChar ~
29027 \SpecialChar ~
29028  68\SpecialChar ~
29029 \SpecialChar ~
29030 \SpecialChar ~
29031 \SpecialChar ~
29032 \SpecialChar ~
29033 \SpecialChar ~
29034 \SpecialChar ~
29035 \SpecialChar ~
29036  rlc\SpecialChar ~
29037 \SpecialChar ~
29038  a 
29039 \newline 
29040 0014 92*00\SpecialChar ~
29041 \SpecialChar ~
29042 \SpecialChar ~
29043 \SpecialChar ~
29044 \SpecialChar ~
29045 \SpecialChar ~
29046 \SpecialChar ~
29047 \SpecialChar ~
29048 \SpecialChar ~
29049 \SpecialChar ~
29050 \SpecialChar ~
29051 \SpecialChar ~
29052 \SpecialChar ~
29053 \SpecialChar ~
29054 \SpecialChar ~
29055  69\SpecialChar ~
29056 \SpecialChar ~
29057 \SpecialChar ~
29058 \SpecialChar ~
29059 \SpecialChar ~
29060 \SpecialChar ~
29061 \SpecialChar ~
29062 \SpecialChar ~
29063  mov\SpecialChar ~
29064 \SpecialChar ~
29065  _foo_hob2_1_1,c 
29066 \newline 
29067 \SpecialChar ~
29068 \SpecialChar ~
29069 \SpecialChar ~
29070 \SpecialChar ~
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 \SpecialChar ~
29074 \SpecialChar ~
29075 \SpecialChar ~
29076 \SpecialChar ~
29077 \SpecialChar ~
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 \SpecialChar ~
29081 \SpecialChar ~
29082 \SpecialChar ~
29083 \SpecialChar ~
29084 \SpecialChar ~
29085 \SpecialChar ~
29086 \SpecialChar ~
29087 \SpecialChar ~
29088 \SpecialChar ~
29089 \SpecialChar ~
29090 \SpecialChar ~
29091 \SpecialChar ~
29092  66 ;\SpecialChar ~
29093  hob.c 9 
29094 \newline 
29095 0016 E5*01\SpecialChar ~
29096 \SpecialChar ~
29097 \SpecialChar ~
29098 \SpecialChar ~
29099 \SpecialChar ~
29100 \SpecialChar ~
29101 \SpecialChar ~
29102 \SpecialChar ~
29103 \SpecialChar ~
29104 \SpecialChar ~
29105 \SpecialChar ~
29106 \SpecialChar ~
29107 \SpecialChar ~
29108 \SpecialChar ~
29109 \SpecialChar ~
29110  67\SpecialChar ~
29111 \SpecialChar ~
29112 \SpecialChar ~
29113 \SpecialChar ~
29114 \SpecialChar ~
29115 \SpecialChar ~
29116 \SpecialChar ~
29117 \SpecialChar ~
29118  mov\SpecialChar ~
29119 \SpecialChar ~
29120  a,(_gint + 1) 
29121 \newline 
29122 0018 33\SpecialChar ~
29123 \SpecialChar ~
29124 \SpecialChar ~
29125 \SpecialChar ~
29126 \SpecialChar ~
29127 \SpecialChar ~
29128 \SpecialChar ~
29129 \SpecialChar ~
29130 \SpecialChar ~
29131 \SpecialChar ~
29132 \SpecialChar ~
29133 \SpecialChar ~
29134 \SpecialChar ~
29135 \SpecialChar ~
29136 \SpecialChar ~
29137 \SpecialChar ~
29138 \SpecialChar ~
29139 \SpecialChar ~
29140  68\SpecialChar ~
29141 \SpecialChar ~
29142 \SpecialChar ~
29143 \SpecialChar ~
29144 \SpecialChar ~
29145 \SpecialChar ~
29146 \SpecialChar ~
29147 \SpecialChar ~
29148  rlc\SpecialChar ~
29149 \SpecialChar ~
29150  a 
29151 \newline 
29152 0019 92*01\SpecialChar ~
29153 \SpecialChar ~
29154 \SpecialChar ~
29155 \SpecialChar ~
29156 \SpecialChar ~
29157 \SpecialChar ~
29158 \SpecialChar ~
29159 \SpecialChar ~
29160 \SpecialChar ~
29161 \SpecialChar ~
29162 \SpecialChar ~
29163 \SpecialChar ~
29164 \SpecialChar ~
29165 \SpecialChar ~
29166 \SpecialChar ~
29167  69\SpecialChar ~
29168 \SpecialChar ~
29169 \SpecialChar ~
29170 \SpecialChar ~
29171 \SpecialChar ~
29172 \SpecialChar ~
29173 \SpecialChar ~
29174 \SpecialChar ~
29175  mov\SpecialChar ~
29176 \SpecialChar ~
29177  _foo_hob3_1_1,c 
29178 \newline 
29179 \SpecialChar ~
29180 \SpecialChar ~
29181 \SpecialChar ~
29182 \SpecialChar ~
29183 \SpecialChar ~
29184 \SpecialChar ~
29185 \SpecialChar ~
29186 \SpecialChar ~
29187 \SpecialChar ~
29188 \SpecialChar ~
29189 \SpecialChar ~
29190 \SpecialChar ~
29191 \SpecialChar ~
29192 \SpecialChar ~
29193 \SpecialChar ~
29194 \SpecialChar ~
29195 \SpecialChar ~
29196 \SpecialChar ~
29197 \SpecialChar ~
29198 \SpecialChar ~
29199 \SpecialChar ~
29200 \SpecialChar ~
29201 \SpecialChar ~
29202 \SpecialChar ~
29203 \SpecialChar ~
29204  70 ;\SpecialChar ~
29205  hob.c 10 
29206 \newline 
29207 001B E5*01\SpecialChar ~
29208 \SpecialChar ~
29209 \SpecialChar ~
29210 \SpecialChar ~
29211 \SpecialChar ~
29212 \SpecialChar ~
29213 \SpecialChar ~
29214 \SpecialChar ~
29215 \SpecialChar ~
29216 \SpecialChar ~
29217 \SpecialChar ~
29218 \SpecialChar ~
29219 \SpecialChar ~
29220 \SpecialChar ~
29221 \SpecialChar ~
29222  71\SpecialChar ~
29223 \SpecialChar ~
29224 \SpecialChar ~
29225 \SpecialChar ~
29226 \SpecialChar ~
29227 \SpecialChar ~
29228 \SpecialChar ~
29229 \SpecialChar ~
29230  mov\SpecialChar ~
29231 \SpecialChar ~
29232  a,(_gint + 1) 
29233 \newline 
29234 001D 03\SpecialChar ~
29235 \SpecialChar ~
29236 \SpecialChar ~
29237 \SpecialChar ~
29238 \SpecialChar ~
29239 \SpecialChar ~
29240 \SpecialChar ~
29241 \SpecialChar ~
29242 \SpecialChar ~
29243 \SpecialChar ~
29244 \SpecialChar ~
29245 \SpecialChar ~
29246 \SpecialChar ~
29247 \SpecialChar ~
29248 \SpecialChar ~
29249 \SpecialChar ~
29250 \SpecialChar ~
29251 \SpecialChar ~
29252  72\SpecialChar ~
29253 \SpecialChar ~
29254 \SpecialChar ~
29255 \SpecialChar ~
29256 \SpecialChar ~
29257 \SpecialChar ~
29258 \SpecialChar ~
29259 \SpecialChar ~
29260  rr\SpecialChar ~
29261 \SpecialChar ~
29262 \SpecialChar ~
29263  a 
29264 \newline 
29265 001E 54 01\SpecialChar ~
29266 \SpecialChar ~
29267 \SpecialChar ~
29268 \SpecialChar ~
29269 \SpecialChar ~
29270 \SpecialChar ~
29271 \SpecialChar ~
29272 \SpecialChar ~
29273 \SpecialChar ~
29274 \SpecialChar ~
29275 \SpecialChar ~
29276 \SpecialChar ~
29277 \SpecialChar ~
29278 \SpecialChar ~
29279 \SpecialChar ~
29280  73\SpecialChar ~
29281 \SpecialChar ~
29282 \SpecialChar ~
29283 \SpecialChar ~
29284 \SpecialChar ~
29285 \SpecialChar ~
29286 \SpecialChar ~
29287 \SpecialChar ~
29288  anl\SpecialChar ~
29289 \SpecialChar ~
29290  a,#0x01 
29291 \newline 
29292 0020 F5*03\SpecialChar ~
29293 \SpecialChar ~
29294 \SpecialChar ~
29295 \SpecialChar ~
29296 \SpecialChar ~
29297 \SpecialChar ~
29298 \SpecialChar ~
29299 \SpecialChar ~
29300 \SpecialChar ~
29301 \SpecialChar ~
29302 \SpecialChar ~
29303 \SpecialChar ~
29304 \SpecialChar ~
29305 \SpecialChar ~
29306 \SpecialChar ~
29307  74\SpecialChar ~
29308 \SpecialChar ~
29309 \SpecialChar ~
29310 \SpecialChar ~
29311 \SpecialChar ~
29312 \SpecialChar ~
29313 \SpecialChar ~
29314 \SpecialChar ~
29315  mov\SpecialChar ~
29316 \SpecialChar ~
29317  _foo_aob1_1_1,a 
29318 \newline 
29319 \SpecialChar ~
29320 \SpecialChar ~
29321 \SpecialChar ~
29322 \SpecialChar ~
29323 \SpecialChar ~
29324 \SpecialChar ~
29325 \SpecialChar ~
29326 \SpecialChar ~
29327 \SpecialChar ~
29328 \SpecialChar ~
29329 \SpecialChar ~
29330 \SpecialChar ~
29331 \SpecialChar ~
29332 \SpecialChar ~
29333 \SpecialChar ~
29334 \SpecialChar ~
29335 \SpecialChar ~
29336 \SpecialChar ~
29337 \SpecialChar ~
29338 \SpecialChar ~
29339 \SpecialChar ~
29340 \SpecialChar ~
29341 \SpecialChar ~
29342 \SpecialChar ~
29343 \SpecialChar ~
29344  75 ;\SpecialChar ~
29345  hob.c 11 
29346 \newline 
29347 0022 E5*01\SpecialChar ~
29348 \SpecialChar ~
29349 \SpecialChar ~
29350 \SpecialChar ~
29351 \SpecialChar ~
29352 \SpecialChar ~
29353 \SpecialChar ~
29354 \SpecialChar ~
29355 \SpecialChar ~
29356 \SpecialChar ~
29357 \SpecialChar ~
29358 \SpecialChar ~
29359 \SpecialChar ~
29360 \SpecialChar ~
29361 \SpecialChar ~
29362  76\SpecialChar ~
29363 \SpecialChar ~
29364 \SpecialChar ~
29365 \SpecialChar ~
29366 \SpecialChar ~
29367 \SpecialChar ~
29368 \SpecialChar ~
29369 \SpecialChar ~
29370  mov\SpecialChar ~
29371 \SpecialChar ~
29372  a,(_gint + 1) 
29373 \newline 
29374 0024 13\SpecialChar ~
29375 \SpecialChar ~
29376 \SpecialChar ~
29377 \SpecialChar ~
29378 \SpecialChar ~
29379 \SpecialChar ~
29380 \SpecialChar ~
29381 \SpecialChar ~
29382 \SpecialChar ~
29383 \SpecialChar ~
29384 \SpecialChar ~
29385 \SpecialChar ~
29386 \SpecialChar ~
29387 \SpecialChar ~
29388 \SpecialChar ~
29389 \SpecialChar ~
29390 \SpecialChar ~
29391 \SpecialChar ~
29392  77\SpecialChar ~
29393 \SpecialChar ~
29394 \SpecialChar ~
29395 \SpecialChar ~
29396 \SpecialChar ~
29397 \SpecialChar ~
29398 \SpecialChar ~
29399 \SpecialChar ~
29400  rrc\SpecialChar ~
29401 \SpecialChar ~
29402  a 
29403 \newline 
29404 0025 92*02\SpecialChar ~
29405 \SpecialChar ~
29406 \SpecialChar ~
29407 \SpecialChar ~
29408 \SpecialChar ~
29409 \SpecialChar ~
29410 \SpecialChar ~
29411 \SpecialChar ~
29412 \SpecialChar ~
29413 \SpecialChar ~
29414 \SpecialChar ~
29415 \SpecialChar ~
29416 \SpecialChar ~
29417 \SpecialChar ~
29418 \SpecialChar ~
29419  78\SpecialChar ~
29420 \SpecialChar ~
29421 \SpecialChar ~
29422 \SpecialChar ~
29423 \SpecialChar ~
29424 \SpecialChar ~
29425 \SpecialChar ~
29426 \SpecialChar ~
29427  mov\SpecialChar ~
29428 \SpecialChar ~
29429  _foo_aob2_1_1,c 
29430 \newline 
29431 \SpecialChar ~
29432 \SpecialChar ~
29433 \SpecialChar ~
29434 \SpecialChar ~
29435 \SpecialChar ~
29436 \SpecialChar ~
29437 \SpecialChar ~
29438 \SpecialChar ~
29439 \SpecialChar ~
29440 \SpecialChar ~
29441 \SpecialChar ~
29442 \SpecialChar ~
29443 \SpecialChar ~
29444 \SpecialChar ~
29445 \SpecialChar ~
29446 \SpecialChar ~
29447 \SpecialChar ~
29448 \SpecialChar ~
29449 \SpecialChar ~
29450 \SpecialChar ~
29451 \SpecialChar ~
29452 \SpecialChar ~
29453 \SpecialChar ~
29454 \SpecialChar ~
29455 \SpecialChar ~
29456  79 ;\SpecialChar ~
29457  hob.c 12 
29458 \newline 
29459 0027 E5*01\SpecialChar ~
29460 \SpecialChar ~
29461 \SpecialChar ~
29462 \SpecialChar ~
29463 \SpecialChar ~
29464 \SpecialChar ~
29465 \SpecialChar ~
29466 \SpecialChar ~
29467 \SpecialChar ~
29468 \SpecialChar ~
29469 \SpecialChar ~
29470 \SpecialChar ~
29471 \SpecialChar ~
29472 \SpecialChar ~
29473 \SpecialChar ~
29474  80\SpecialChar ~
29475 \SpecialChar ~
29476 \SpecialChar ~
29477 \SpecialChar ~
29478 \SpecialChar ~
29479 \SpecialChar ~
29480 \SpecialChar ~
29481 \SpecialChar ~
29482  mov\SpecialChar ~
29483 \SpecialChar ~
29484  a,(_gint + 1) 
29485 \newline 
29486 0029 A2 E3\SpecialChar ~
29487 \SpecialChar ~
29488 \SpecialChar ~
29489 \SpecialChar ~
29490 \SpecialChar ~
29491 \SpecialChar ~
29492 \SpecialChar ~
29493 \SpecialChar ~
29494 \SpecialChar ~
29495 \SpecialChar ~
29496 \SpecialChar ~
29497 \SpecialChar ~
29498 \SpecialChar ~
29499 \SpecialChar ~
29500 \SpecialChar ~
29501  81\SpecialChar ~
29502 \SpecialChar ~
29503 \SpecialChar ~
29504 \SpecialChar ~
29505 \SpecialChar ~
29506 \SpecialChar ~
29507 \SpecialChar ~
29508 \SpecialChar ~
29509  mov\SpecialChar ~
29510 \SpecialChar ~
29511  c,acc[3] 
29512 \newline 
29513 002B 92*03\SpecialChar ~
29514 \SpecialChar ~
29515 \SpecialChar ~
29516 \SpecialChar ~
29517 \SpecialChar ~
29518 \SpecialChar ~
29519 \SpecialChar ~
29520 \SpecialChar ~
29521 \SpecialChar ~
29522 \SpecialChar ~
29523 \SpecialChar ~
29524 \SpecialChar ~
29525 \SpecialChar ~
29526 \SpecialChar ~
29527 \SpecialChar ~
29528  82\SpecialChar ~
29529 \SpecialChar ~
29530 \SpecialChar ~
29531 \SpecialChar ~
29532 \SpecialChar ~
29533 \SpecialChar ~
29534 \SpecialChar ~
29535 \SpecialChar ~
29536  mov\SpecialChar ~
29537 \SpecialChar ~
29538  _foo_aob3_1_1,c 
29539 \layout Standard
29540
29541 Other variations of these cases however will 
29542 \emph on 
29543 not
29544 \emph default 
29545  be recognized.
29546  They are standard C expressions, so I heartily recommend these be the only
29547  way to get the highest order bit, (it is portable).
29548  Of course it will be recognized even if it is embedded in other expressions,
29549  e.g.:
29550 \layout Verse
29551
29552
29553 \family typewriter 
29554 xyz = gint + ((gint >> 15) & 1);
29555 \layout Standard
29556
29557 will still be recognized.
29558 \layout Subsection
29559
29560 Higher Order Byte
29561 \begin_inset LatexCommand \index{Higher Order Byte}
29562
29563 \end_inset 
29564
29565  / Higher Order Word
29566 \begin_inset LatexCommand \index{Higher Order Word}
29567
29568 \end_inset 
29569
29570
29571 \layout Standard
29572
29573 It is also frequently required to obtain a higher order byte or word of
29574  a larger integral type (long, int or short types).
29575  SDCC recognizes the following expressions to yield the higher order byte
29576  or word and generates optimized code for it, e.g.:
29577 \layout Verse
29578
29579
29580 \family typewriter 
29581 unsigned int gint; 
29582 \newline 
29583 unsigned long int glong; 
29584 \newline 
29585
29586 \newline 
29587 foo () { 
29588 \newline 
29589 \SpecialChar ~
29590 \SpecialChar ~
29591 unsigned char hob1, hob2; 
29592 \newline 
29593 \SpecialChar ~
29594 \SpecialChar ~
29595 unsigned int how1, how2; 
29596 \newline 
29597 \SpecialChar ~
29598 \SpecialChar ~
29599 ...
29600  
29601 \newline 
29602 \SpecialChar ~
29603 \SpecialChar ~
29604 hob1 = (gint >> 8) & 0xFF; 
29605 \newline 
29606 \SpecialChar ~
29607 \SpecialChar ~
29608 hob2 = glong >> 24; 
29609 \newline 
29610 \SpecialChar ~
29611 \SpecialChar ~
29612 how1 = (glong >> 16) & 0xFFFF; 
29613 \newline 
29614 \SpecialChar ~
29615 \SpecialChar ~
29616 how2 = glong >> 8; 
29617 \newline 
29618 \SpecialChar ~
29619 \SpecialChar ~
29620 ..
29621  
29622 \newline 
29623 }
29624 \layout Standard
29625
29626 will generate the following code:
29627 \layout Verse
29628
29629
29630 \family typewriter 
29631 \SpecialChar ~
29632 \SpecialChar ~
29633 \SpecialChar ~
29634 \SpecialChar ~
29635 \SpecialChar ~
29636 \SpecialChar ~
29637 \SpecialChar ~
29638 \SpecialChar ~
29639 \SpecialChar ~
29640 \SpecialChar ~
29641 \SpecialChar ~
29642 \SpecialChar ~
29643 \SpecialChar ~
29644 \SpecialChar ~
29645 \SpecialChar ~
29646 \SpecialChar ~
29647 \SpecialChar ~
29648 \SpecialChar ~
29649 \SpecialChar ~
29650 \SpecialChar ~
29651 \SpecialChar ~
29652 \SpecialChar ~
29653 \SpecialChar ~
29654 \SpecialChar ~
29655 \SpecialChar ~
29656  91 ;\SpecialChar ~
29657  hob.c 15 
29658 \newline 
29659 0037 85*01*06\SpecialChar ~
29660 \SpecialChar ~
29661 \SpecialChar ~
29662 \SpecialChar ~
29663 \SpecialChar ~
29664 \SpecialChar ~
29665 \SpecialChar ~
29666 \SpecialChar ~
29667 \SpecialChar ~
29668 \SpecialChar ~
29669 \SpecialChar ~
29670 \SpecialChar ~
29671  92\SpecialChar ~
29672 \SpecialChar ~
29673 \SpecialChar ~
29674 \SpecialChar ~
29675 \SpecialChar ~
29676 \SpecialChar ~
29677 \SpecialChar ~
29678 \SpecialChar ~
29679  mov\SpecialChar ~
29680 \SpecialChar ~
29681  _foo_hob1_1_1,(_gint + 1) 
29682 \newline 
29683 \SpecialChar ~
29684 \SpecialChar ~
29685 \SpecialChar ~
29686 \SpecialChar ~
29687 \SpecialChar ~
29688 \SpecialChar ~
29689 \SpecialChar ~
29690 \SpecialChar ~
29691 \SpecialChar ~
29692 \SpecialChar ~
29693 \SpecialChar ~
29694 \SpecialChar ~
29695 \SpecialChar ~
29696 \SpecialChar ~
29697 \SpecialChar ~
29698 \SpecialChar ~
29699 \SpecialChar ~
29700 \SpecialChar ~
29701 \SpecialChar ~
29702 \SpecialChar ~
29703 \SpecialChar ~
29704 \SpecialChar ~
29705 \SpecialChar ~
29706 \SpecialChar ~
29707 \SpecialChar ~
29708  93 ;\SpecialChar ~
29709  hob.c 16 
29710 \newline 
29711 003A 85*05*07\SpecialChar ~
29712 \SpecialChar ~
29713 \SpecialChar ~
29714 \SpecialChar ~
29715 \SpecialChar ~
29716 \SpecialChar ~
29717 \SpecialChar ~
29718 \SpecialChar ~
29719 \SpecialChar ~
29720 \SpecialChar ~
29721 \SpecialChar ~
29722 \SpecialChar ~
29723  94\SpecialChar ~
29724 \SpecialChar ~
29725 \SpecialChar ~
29726 \SpecialChar ~
29727 \SpecialChar ~
29728 \SpecialChar ~
29729 \SpecialChar ~
29730 \SpecialChar ~
29731  mov\SpecialChar ~
29732 \SpecialChar ~
29733  _foo_hob2_1_1,(_glong + 3) 
29734 \newline 
29735 \SpecialChar ~
29736 \SpecialChar ~
29737 \SpecialChar ~
29738 \SpecialChar ~
29739 \SpecialChar ~
29740 \SpecialChar ~
29741 \SpecialChar ~
29742 \SpecialChar ~
29743 \SpecialChar ~
29744 \SpecialChar ~
29745 \SpecialChar ~
29746 \SpecialChar ~
29747 \SpecialChar ~
29748 \SpecialChar ~
29749 \SpecialChar ~
29750 \SpecialChar ~
29751 \SpecialChar ~
29752 \SpecialChar ~
29753 \SpecialChar ~
29754 \SpecialChar ~
29755 \SpecialChar ~
29756 \SpecialChar ~
29757 \SpecialChar ~
29758 \SpecialChar ~
29759 \SpecialChar ~
29760  95 ;\SpecialChar ~
29761  hob.c 17 
29762 \newline 
29763 003D 85*04*08\SpecialChar ~
29764 \SpecialChar ~
29765 \SpecialChar ~
29766 \SpecialChar ~
29767 \SpecialChar ~
29768 \SpecialChar ~
29769 \SpecialChar ~
29770 \SpecialChar ~
29771 \SpecialChar ~
29772 \SpecialChar ~
29773 \SpecialChar ~
29774 \SpecialChar ~
29775  96\SpecialChar ~
29776 \SpecialChar ~
29777 \SpecialChar ~
29778 \SpecialChar ~
29779 \SpecialChar ~
29780 \SpecialChar ~
29781 \SpecialChar ~
29782 \SpecialChar ~
29783  mov\SpecialChar ~
29784 \SpecialChar ~
29785  _foo_how1_1_1,(_glong + 2) 
29786 \newline 
29787 0040 85*05*09\SpecialChar ~
29788 \SpecialChar ~
29789 \SpecialChar ~
29790 \SpecialChar ~
29791 \SpecialChar ~
29792 \SpecialChar ~
29793 \SpecialChar ~
29794 \SpecialChar ~
29795 \SpecialChar ~
29796 \SpecialChar ~
29797 \SpecialChar ~
29798 \SpecialChar ~
29799  97\SpecialChar ~
29800 \SpecialChar ~
29801 \SpecialChar ~
29802 \SpecialChar ~
29803 \SpecialChar ~
29804 \SpecialChar ~
29805 \SpecialChar ~
29806 \SpecialChar ~
29807  mov\SpecialChar ~
29808 \SpecialChar ~
29809  (_foo_how1_1_1 + 1),(_glong + 3) 
29810 \newline 
29811 0043 85*03*0A\SpecialChar ~
29812 \SpecialChar ~
29813 \SpecialChar ~
29814 \SpecialChar ~
29815 \SpecialChar ~
29816 \SpecialChar ~
29817 \SpecialChar ~
29818 \SpecialChar ~
29819 \SpecialChar ~
29820 \SpecialChar ~
29821 \SpecialChar ~
29822 \SpecialChar ~
29823  98\SpecialChar ~
29824 \SpecialChar ~
29825 \SpecialChar ~
29826 \SpecialChar ~
29827 \SpecialChar ~
29828 \SpecialChar ~
29829 \SpecialChar ~
29830 \SpecialChar ~
29831  mov\SpecialChar ~
29832 \SpecialChar ~
29833  _foo_how2_1_1,(_glong + 1) 
29834 \newline 
29835 0046 85*04*0B\SpecialChar ~
29836 \SpecialChar ~
29837 \SpecialChar ~
29838 \SpecialChar ~
29839 \SpecialChar ~
29840 \SpecialChar ~
29841 \SpecialChar ~
29842 \SpecialChar ~
29843 \SpecialChar ~
29844 \SpecialChar ~
29845 \SpecialChar ~
29846 \SpecialChar ~
29847  99\SpecialChar ~
29848 \SpecialChar ~
29849 \SpecialChar ~
29850 \SpecialChar ~
29851 \SpecialChar ~
29852 \SpecialChar ~
29853 \SpecialChar ~
29854 \SpecialChar ~
29855  mov\SpecialChar ~
29856 \SpecialChar ~
29857  (_foo_how2_1_1 + 1),(_glong + 2) 
29858 \layout Standard
29859
29860 Again, variations of these cases may 
29861 \emph on 
29862 not
29863 \emph default 
29864  be recognized.
29865  They are standard C expressions, so I heartily recommend these be the only
29866  way to get the higher order byte/word, (it is portable).
29867  Of course it will be recognized even if it is embedded in other expressions,
29868  e.g.:
29869 \layout Verse
29870
29871
29872 \family typewriter 
29873 xyz = gint + ((gint >> 8) & 0xFF);
29874 \layout Standard
29875
29876 will still be recognized.
29877 \layout Subsection
29878
29879 Peephole Optimizer
29880 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
29881
29882 \end_inset 
29883
29884
29885 \begin_inset LatexCommand \index{Peephole optimizer}
29886
29887 \end_inset 
29888
29889
29890 \layout Standard
29891
29892 The compiler uses a rule based, pattern matching and re-writing mechanism
29893  for peep-hole optimization.
29894  It is inspired by 
29895 \emph on 
29896 copt
29897 \emph default 
29898  a peep-hole optimizer by Christopher W.
29899  Fraser (cwfraser\SpecialChar ~
29900 @\SpecialChar ~
29901 microsoft.com).
29902  A default set of rules are compiled into the compiler, additional rules
29903  may be added with the 
29904 \emph on 
29905 -
29906 \begin_inset ERT
29907 status Collapsed
29908
29909 \layout Standard
29910
29911 \backslash 
29912 /
29913 \end_inset 
29914
29915 -peep-file
29916 \begin_inset LatexCommand \index{-\/-peep-file}
29917
29918 \end_inset 
29919
29920  <filename>
29921 \emph default 
29922  option.
29923  The rule language is best illustrated with examples.
29924 \layout Verse
29925
29926
29927 \family typewriter 
29928 replace { 
29929 \newline 
29930 \SpecialChar ~
29931 \SpecialChar ~
29932 mov %1,a 
29933 \newline 
29934 \SpecialChar ~
29935 \SpecialChar ~
29936 mov a,%1
29937 \newline 
29938 } by {
29939 \newline 
29940 \SpecialChar ~
29941 \SpecialChar ~
29942 mov %1,a
29943 \newline 
29944 }
29945 \layout Standard
29946
29947 The above rule will change the following assembly
29948 \begin_inset LatexCommand \index{Assembler routines}
29949
29950 \end_inset 
29951
29952  sequence:
29953 \layout Verse
29954
29955
29956 \family typewriter 
29957 mov r1,a 
29958 \newline 
29959 mov a,r1
29960 \layout Standard
29961
29962 to
29963 \layout Verse
29964
29965
29966 \family typewriter 
29967 mov r1,a
29968 \layout Standard
29969
29970 Note: All occurrences of a 
29971 \emph on 
29972 %n
29973 \emph default 
29974  (pattern variable) must denote the same string.
29975  With the above rule, the assembly sequence:
29976 \layout Verse
29977
29978
29979 \family typewriter 
29980 mov r1,a 
29981 \newline 
29982 mov a,r2
29983 \layout Standard
29984
29985 will remain unmodified.
29986 \newline 
29987
29988 \newline 
29989 Other special case optimizations may be added by the user (via 
29990 \emph on 
29991 -
29992 \begin_inset ERT
29993 status Collapsed
29994
29995 \layout Standard
29996
29997 \backslash 
29998 /
29999 \end_inset 
30000
30001 -peep-file option
30002 \emph default 
30003 ).
30004  E.g.
30005  some variants of the 8051 MCU
30006 \begin_inset LatexCommand \index{MCS51 variants}
30007
30008 \end_inset 
30009
30010  allow only 
30011 \family typewriter 
30012 ajmp
30013 \family default 
30014  and 
30015 \family typewriter 
30016 acall
30017 \family default 
30018 .
30019  The following two rules will change all 
30020 \family typewriter 
30021 ljmp
30022 \family default 
30023  and 
30024 \family typewriter 
30025 lcall
30026 \family default 
30027  to 
30028 \family typewriter 
30029 ajmp
30030 \family default 
30031  and 
30032 \family typewriter 
30033 acall
30034 \layout Verse
30035
30036
30037 \family typewriter 
30038 replace { lcall %1 } by { acall %1 } 
30039 \newline 
30040 replace { ljmp %1 } by { ajmp %1 }
30041 \layout Standard
30042
30043 The 
30044 \emph on 
30045 inline-assembler code
30046 \emph default 
30047  is also passed through the peep hole optimizer, thus the peephole optimizer
30048  can also be used as an assembly level macro expander.
30049  The rules themselves are MCU dependent whereas the rule language infra-structur
30050 e is MCU independent.
30051  Peephole optimization rules for other MCU can be easily programmed using
30052  the rule language.
30053 \newline 
30054
30055 \newline 
30056 The syntax for a rule is as follows:
30057 \layout Verse
30058
30059
30060 \family typewriter 
30061 rule := replace [ restart ] '{' <assembly sequence> '
30062 \backslash 
30063 n' 
30064 \newline 
30065 \SpecialChar ~
30066  \SpecialChar ~
30067  \SpecialChar ~
30068  \SpecialChar ~
30069  \SpecialChar ~
30070  \SpecialChar ~
30071  \SpecialChar ~
30072  \SpecialChar ~
30073  \SpecialChar ~
30074  \SpecialChar ~
30075  \SpecialChar ~
30076  \SpecialChar ~
30077  \SpecialChar ~
30078  \SpecialChar ~
30079  '}' by '{' '
30080 \backslash 
30081 n' 
30082 \newline 
30083 \SpecialChar ~
30084  \SpecialChar ~
30085  \SpecialChar ~
30086  \SpecialChar ~
30087  \SpecialChar ~
30088  \SpecialChar ~
30089  \SpecialChar ~
30090  \SpecialChar ~
30091  \SpecialChar ~
30092  \SpecialChar ~
30093  \SpecialChar ~
30094  \SpecialChar ~
30095  \SpecialChar ~
30096  \SpecialChar ~
30097  \SpecialChar ~
30098  \SpecialChar ~
30099  <assembly sequence> '
30100 \backslash 
30101 n' 
30102 \newline 
30103 \SpecialChar ~
30104  \SpecialChar ~
30105  \SpecialChar ~
30106  \SpecialChar ~
30107  \SpecialChar ~
30108  \SpecialChar ~
30109  \SpecialChar ~
30110  \SpecialChar ~
30111  \SpecialChar ~
30112  \SpecialChar ~
30113  \SpecialChar ~
30114  \SpecialChar ~
30115  \SpecialChar ~
30116  \SpecialChar ~
30117  '}' [if <functionName> ] '
30118 \backslash 
30119 n' 
30120 \layout Standard
30121
30122 <assembly sequence> := assembly instruction (each instruction including
30123  labels must be on a separate line).
30124 \newline 
30125
30126 \newline 
30127 The optimizer will apply to the rules one by one from the top in the sequence
30128  of their appearance, it will terminate when all rules are exhausted.
30129  If the 'restart' option is specified, then the optimizer will start matching
30130  the rules again from the top, this option for a rule is expensive (performance)
30131 , it is intended to be used in situations where a transformation will trigger
30132  the same rule again.
30133  An example of this (not a good one, it has side effects) is the following
30134  rule:
30135 \layout Verse
30136
30137
30138 \family typewriter 
30139 replace restart { 
30140 \newline 
30141 \SpecialChar ~
30142 \SpecialChar ~
30143 pop %1 
30144 \newline 
30145 \SpecialChar ~
30146 \SpecialChar ~
30147 push %1 } by { 
30148 \newline 
30149 \SpecialChar ~
30150 \SpecialChar ~
30151 ; nop 
30152 \newline 
30153 }
30154 \layout Standard
30155
30156 Note that the replace pattern cannot be a blank, but can be a comment line.
30157  Without the 'restart' option only the innermost 'pop' 'push' pair would
30158  be eliminated, i.e.:
30159 \layout Verse
30160
30161
30162 \family typewriter 
30163 pop ar1 
30164 \newline 
30165 pop ar2 
30166 \newline 
30167 push ar2 
30168 \newline 
30169 push ar1
30170 \layout Standard
30171
30172 would result in:
30173 \layout Verse
30174
30175
30176 \family typewriter 
30177 pop ar1 
30178 \newline 
30179 ; nop 
30180 \newline 
30181 push ar1
30182 \layout Standard
30183
30184
30185 \emph on 
30186 with
30187 \emph default 
30188  the restart option the rule will be applied again to the resulting code
30189  and then all the pop-push pairs will be eliminated to yield:
30190 \layout Verse
30191
30192
30193 \family typewriter 
30194 ; nop 
30195 \newline 
30196 ; nop
30197 \layout Standard
30198
30199 A conditional function can be attached to a rule.
30200  Attaching rules are somewhat more involved, let me illustrate this with
30201  an example.
30202 \layout Verse
30203
30204
30205 \family typewriter 
30206 replace { 
30207 \newline 
30208 \SpecialChar ~
30209  \SpecialChar ~
30210  \SpecialChar ~
30211 ljmp %5 
30212 \newline 
30213 %2:
30214 \newline 
30215 } by { 
30216 \newline 
30217 \SpecialChar ~
30218  \SpecialChar ~
30219  \SpecialChar ~
30220 sjmp %5 
30221 \newline 
30222 %2:
30223 \newline 
30224 } if labelInRange
30225 \layout Standard
30226
30227 The optimizer does a look-up of a function name table defined in function
30228  
30229 \emph on 
30230 callFuncByName
30231 \emph default 
30232  in the source file SDCCpeeph.c, with the name 
30233 \emph on 
30234 labelInRange
30235 \emph default 
30236 .
30237  If it finds a corresponding entry the function is called.
30238  Note there can be no parameters specified for these functions, in this
30239  case the use of 
30240 \emph on 
30241 %5
30242 \emph default 
30243  is crucial, since the function 
30244 \emph on 
30245 labelInRange
30246 \emph default 
30247  expects to find the label in that particular variable (the hash table containin
30248 g the variable bindings is passed as a parameter).
30249  If you want to code more such functions, take a close look at the function
30250  labelInRange and the calling mechanism in source file SDCCpeeph.c.
30251  Currently implemented are 
30252 \emph on 
30253 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
30254  24bitMode, portIsDS390, 24bitModeAndPortDS390 
30255 \emph default 
30256 and
30257 \emph on 
30258  notVolatile
30259 \emph default 
30260 .
30261 \layout Standard
30262
30263 I know this whole thing is a little kludgey, but maybe some day we will
30264  have some better means.
30265  If you are looking at this file, you will see the default rules that are
30266  compiled into the compiler, you can add your own rules in the default set
30267  there if you get tired of specifying the -
30268 \begin_inset ERT
30269 status Collapsed
30270
30271 \layout Standard
30272
30273 \backslash 
30274 /
30275 \end_inset 
30276
30277 -peep-file option.
30278 \layout Section
30279
30280 ANSI-Compliance
30281 \begin_inset LatexCommand \index{ANSI-compliance}
30282
30283 \end_inset 
30284
30285
30286 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
30287
30288 \end_inset 
30289
30290
30291 \layout Standard
30292
30293 The latest publically available version of the standard 
30294 \emph on 
30295 ISO/IEC 9899 - Programming languages - C
30296 \emph default 
30297  should be available at: 
30298 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30299
30300 \end_inset 
30301
30302 .
30303 \newline 
30304
30305 \layout Standard
30306
30307 Deviations from the compliance:
30308 \layout Itemize
30309
30310 functions are not reentrant
30311 \begin_inset LatexCommand \index{reentrant}
30312
30313 \end_inset 
30314
30315  unless explicitly declared as such or the 
30316 \series bold 
30317 -
30318 \begin_inset ERT
30319 status Collapsed
30320
30321 \layout Standard
30322
30323 \backslash 
30324 /
30325 \end_inset 
30326
30327 -stack-auto
30328 \begin_inset LatexCommand \index{-\/-stack-auto}
30329
30330 \end_inset 
30331
30332
30333 \series default 
30334  command line option is specified.
30335 \layout Itemize
30336
30337 structures
30338 \begin_inset LatexCommand \index{struct}
30339
30340 \end_inset 
30341
30342  and unions
30343 \begin_inset LatexCommand \index{union}
30344
30345 \end_inset 
30346
30347  cannot be assigned values directly, cannot be passed as function parameters
30348  or assigned to each other and cannot be a return value
30349 \begin_inset LatexCommand \index{return value}
30350
30351 \end_inset 
30352
30353  from a function, e.g.:
30354 \begin_deeper 
30355 \layout Verse
30356
30357
30358 \family typewriter 
30359 struct s { ...
30360  }; 
30361 \newline 
30362 struct s s1, s2; 
30363 \newline 
30364 foo() 
30365 \newline 
30366
30367 \newline 
30368 \SpecialChar ~
30369 \SpecialChar ~
30370 \SpecialChar ~
30371 \SpecialChar ~
30372 ...
30373  
30374 \newline 
30375 \SpecialChar ~
30376 \SpecialChar ~
30377 \SpecialChar ~
30378 \SpecialChar ~
30379 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
30380 \newline 
30381 \SpecialChar ~
30382 \SpecialChar ~
30383 \SpecialChar ~
30384 \SpecialChar ~
30385 ...
30386  
30387 \newline 
30388 }
30389 \newline 
30390
30391 \series bold 
30392 struct
30393 \series default 
30394  s foo1 (
30395 \series bold 
30396 struct
30397 \series default 
30398  s parms) /* invalid in SDCC although allowed in ANSI */
30399 \newline 
30400
30401 \newline 
30402 \SpecialChar ~
30403 \SpecialChar ~
30404 \SpecialChar ~
30405 \SpecialChar ~
30406 struct s rets; 
30407 \newline 
30408 \SpecialChar ~
30409 \SpecialChar ~
30410 \SpecialChar ~
30411 \SpecialChar ~
30412 ...
30413  
30414 \newline 
30415 \SpecialChar ~
30416 \SpecialChar ~
30417 \SpecialChar ~
30418 \SpecialChar ~
30419 return rets; /* is invalid in SDCC although allowed in ANSI */ 
30420 \newline 
30421 }
30422 \end_deeper 
30423 \layout Itemize
30424
30425 initialization of structure arrays must be fully braced.
30426 \begin_deeper 
30427 \layout Verse
30428
30429
30430 \family typewriter 
30431 struct s { char x } a[] = {1, 2};\SpecialChar ~
30432 \SpecialChar ~
30433 \SpecialChar ~
30434 \SpecialChar ~
30435 \SpecialChar ~
30436 /* invalid in SDCC */
30437 \newline 
30438 struct s { char x } a[] = {{1}, {2}}; /* OK */
30439 \end_deeper 
30440 \layout Itemize
30441
30442 'long long
30443 \begin_inset LatexCommand \index{long long (not supported)}
30444
30445 \end_inset 
30446
30447 ' (64 bit integers
30448 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
30449
30450 \end_inset 
30451
30452 ) not supported.
30453 \layout Itemize
30454
30455 'double
30456 \begin_inset LatexCommand \index{double (not supported)}
30457
30458 \end_inset 
30459
30460 ' precision floating point 
30461 \begin_inset LatexCommand \index{Floating point support}
30462
30463 \end_inset 
30464
30465 not supported.
30466 \layout Itemize
30467
30468 Old K&R style
30469 \begin_inset LatexCommand \index{K\&R style}
30470
30471 \end_inset 
30472
30473  function declarations are NOT allowed.
30474 \begin_deeper 
30475 \layout Verse
30476
30477
30478 \family typewriter 
30479 foo(i,j) /* this old style of function declarations */ 
30480 \newline 
30481 int i,j; /* are valid in ANSI but not valid in SDCC */ 
30482 \newline 
30483
30484 \newline 
30485 \SpecialChar ~
30486 \SpecialChar ~
30487 \SpecialChar ~
30488 \SpecialChar ~
30489 ...
30490  
30491 \newline 
30492 }
30493 \end_deeper 
30494 \layout Itemize
30495
30496 Most enhancements in C99 are not supported, f.e.:
30497 \begin_deeper 
30498 \layout Verse
30499
30500
30501 \family typewriter 
30502 \series bold 
30503 inline
30504 \begin_inset LatexCommand \index{inline (not supported)}
30505
30506 \end_inset 
30507
30508
30509 \series default 
30510  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
30511  in C99.
30512  An empty define 
30513 \emph on 
30514 #define inline
30515 \emph default 
30516  can be used as a work around */
30517 \newline 
30518
30519 \newline 
30520 for (
30521 \series bold 
30522 int
30523 \series default 
30524  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
30525 \end_deeper 
30526 \layout Itemize
30527
30528 Certain words that are valid identifiers in the standard may be reserved
30529  words in SDCC unless the 
30530 \series bold 
30531 -
30532 \begin_inset ERT
30533 status Collapsed
30534
30535 \layout Standard
30536
30537 \backslash 
30538 /
30539 \end_inset 
30540
30541 -std-c89
30542 \begin_inset LatexCommand \index{-\/-std-c89}
30543
30544 \end_inset 
30545
30546  or -
30547 \begin_inset ERT
30548 status Collapsed
30549
30550 \layout Standard
30551
30552 \backslash 
30553 /
30554 \end_inset 
30555
30556 -std-c99
30557 \begin_inset LatexCommand \index{-\/-std-c99}
30558
30559 \end_inset 
30560
30561
30562 \series default 
30563  command line options are used.
30564  These may include (depending on the selected processor): 'at', 'banked',
30565  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
30566 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
30567  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
30568  '_naked'.
30569  Compliant equivalents of these keywords are always available in a form
30570  that begin with two underscores
30571 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
30572
30573 \end_inset 
30574
30575 , f.e.
30576  '__data' instead of 'data'.
30577 \layout Section
30578
30579 Cyclomatic Complexity
30580 \begin_inset LatexCommand \index{Cyclomatic complexity}
30581
30582 \end_inset 
30583
30584
30585 \layout Standard
30586
30587 Cyclomatic complexity of a function is defined as the number of independent
30588  paths the program can take during execution of the function.
30589  This is an important number since it defines the number test cases you
30590  have to generate to validate the function.
30591  The accepted industry standard for complexity number is 10, if the cyclomatic
30592  complexity reported by SDCC exceeds 10 you should think about simplification
30593  of the function logic.
30594  Note that the complexity level is not related to the number of lines of
30595  code in a function.
30596  Large functions can have low complexity, and small functions can have large
30597  complexity levels.
30598  
30599 \newline 
30600
30601 \newline 
30602 SDCC uses the following formula to compute the complexity:
30603 \newline 
30604
30605 \layout Standard
30606
30607 complexity = (number of edges in control flow graph) - (number of nodes
30608  in control flow graph) + 2;
30609 \newline 
30610
30611 \newline 
30612 Having said that the industry standard is 10, you should be aware that in
30613  some cases it be may unavoidable to have a complexity level of less than
30614  10.
30615  For example if you have switch statement with more than 10 case labels,
30616  each case label adds one to the complexity level.
30617  The complexity level is by no means an absolute measure of the algorithmic
30618  complexity of the function, it does however provide a good starting point
30619  for which functions you might look at for further optimization.
30620 \layout Section
30621
30622 Retargetting for other Processors
30623 \layout Standard
30624
30625 The issues for retargetting the compiler are far too numerous to be covered
30626  by this document.
30627  What follows is a brief description of each of the seven phases of the
30628  compiler and its MCU dependency.
30629 \layout Itemize
30630
30631 Parsing the source and building the annotated parse tree.
30632  This phase is largely MCU independent (except for the language extensions).
30633  Syntax & semantic checks are also done in this phase, along with some initial
30634  optimizations like back patching labels and the pattern matching optimizations
30635  like bit-rotation etc.
30636 \layout Itemize
30637
30638 The second phase involves generating an intermediate code which can be easy
30639  manipulated during the later phases.
30640  This phase is entirely MCU independent.
30641  The intermediate code generation assumes the target machine has unlimited
30642  number of registers, and designates them with the name iTemp.
30643  The compiler can be made to dump a human readable form of the code generated
30644  by using the -
30645 \begin_inset ERT
30646 status Collapsed
30647
30648 \layout Standard
30649
30650 \backslash 
30651 /
30652 \end_inset 
30653
30654 -dumpraw option.
30655 \layout Itemize
30656
30657 This phase does the bulk of the standard optimizations and is also MCU independe
30658 nt.
30659  This phase can be broken down into several sub-phases:
30660 \newline 
30661
30662 \newline 
30663 Break down intermediate code (iCode) into basic blocks.
30664 \newline 
30665 Do control flow & data flow analysis on the basic blocks.
30666 \newline 
30667 Do local common subexpression elimination, then global subexpression elimination
30668 \newline 
30669 Dead code elimination
30670 \newline 
30671 Loop optimizations
30672 \newline 
30673 If loop optimizations caused any changes then do 'global subexpression eliminati
30674 on' and 'dead code elimination' again.
30675 \layout Itemize
30676
30677 This phase determines the live-ranges; by live range I mean those iTemp
30678  variables defined by the compiler that still survive after all the optimization
30679 s.
30680  Live range analysis
30681 \begin_inset LatexCommand \index{Live range analysis}
30682
30683 \end_inset 
30684
30685  is essential for register allocation, since these computation determines
30686  which of these iTemps will be assigned to registers, and for how long.
30687 \layout Itemize
30688
30689 Phase five is register allocation.
30690  There are two parts to this process.
30691 \newline 
30692
30693 \newline 
30694 The first part I call 'register packing' (for lack of a better term).
30695  In this case several MCU specific expression folding is done to reduce
30696  register pressure.
30697 \newline 
30698
30699 \newline 
30700 The second part is more MCU independent and deals with allocating registers
30701  to the remaining live ranges.
30702  A lot of MCU specific code does creep into this phase because of the limited
30703  number of index registers available in the 8051.
30704 \layout Itemize
30705
30706 The Code generation phase is (unhappily), entirely MCU dependent and very
30707  little (if any at all) of this code can be reused for other MCU.
30708  However the scheme for allocating a homogenized assembler operand for each
30709  iCode operand may be reused.
30710 \layout Itemize
30711
30712 As mentioned in the optimization section the peep-hole optimizer is rule
30713  based system, which can reprogrammed for other MCUs.
30714 \layout Standard
30715
30716 More information is available in a wiki
30717 \begin_inset LatexCommand \index{wiki}
30718
30719 \end_inset 
30720
30721  (preliminary link 
30722 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
30723
30724 \end_inset 
30725
30726 ) and in the thread 
30727 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
30728
30729 \end_inset 
30730
30731  .
30732 \layout Chapter
30733
30734 Compiler internals
30735 \begin_inset LatexCommand \index{Compiler internals}
30736
30737 \end_inset 
30738
30739
30740 \layout Section
30741
30742 The anatomy of the compiler
30743 \begin_inset LatexCommand \label{sub:The-anatomy-of}
30744
30745 \end_inset 
30746
30747
30748 \layout Standard
30749
30750
30751 \shape italic 
30752 This is an excerpt from an article published in Circuit Cellar Magazine
30753  in 
30754 \series bold 
30755 August 2000
30756 \series default 
30757 .
30758  It's a little outdated (the compiler is much more efficient now and user/develo
30759 per friendly), but pretty well exposes the guts of it all.
30760 \shape default 
30761
30762 \newline 
30763
30764 \newline 
30765 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
30766  It is fairly easy to retarget for other 8-bit MCU.
30767  Here we take a look at some of the internals of the compiler.
30768  
30769 \layout Paragraph*
30770
30771 Parsing
30772 \begin_inset LatexCommand \index{Parsing}
30773
30774 \end_inset 
30775
30776  
30777 \layout Standard
30778
30779 Parsing the input source file and creating an AST (Annotated Syntax Tree
30780 \begin_inset LatexCommand \index{Annotated syntax tree}
30781
30782 \end_inset 
30783
30784 ).
30785  This phase also involves propagating types (annotating each node of the
30786  parse tree with type information) and semantic analysis.
30787  There are some MCU specific parsing rules.
30788  For example the storage classes, the extended storage classes are MCU specific
30789  while there may be a xdata storage class for 8051 there is no such storage
30790  class for z80 or Atmel AVR.
30791  SDCC allows MCU specific storage class extensions, i.e.
30792  xdata will be treated as a storage class specifier when parsing 8051 C
30793  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
30794  C code.
30795 \layout Paragraph*
30796
30797 Generating iCode
30798 \begin_inset LatexCommand \index{iCode}
30799
30800 \end_inset 
30801
30802
30803 \layout Standard
30804
30805 Intermediate code generation.
30806  In this phase the AST is broken down into three-operand form (iCode).
30807  These three operand forms are represented as doubly linked lists.
30808  ICode is the term given to the intermediate form generated by the compiler.
30809  ICode example section shows some examples of iCode generated for some simple
30810  C source functions.
30811 \layout Paragraph*
30812
30813 Optimizations
30814 \begin_inset LatexCommand \index{Optimizations}
30815
30816 \end_inset 
30817
30818 .
30819 \layout Standard
30820
30821 Bulk of the target independent optimizations is performed in this phase.
30822  The optimizations include constant propagation, common sub-expression eliminati
30823 on, loop invariant code movement, strength reduction of loop induction variables
30824  and dead-code elimination.
30825 \layout Paragraph*
30826
30827 Live range analysis
30828 \begin_inset LatexCommand \index{Live range analysis}
30829
30830 \end_inset 
30831
30832
30833 \layout Standard
30834
30835 During intermediate code generation phase, the compiler assumes the target
30836  machine has infinite number of registers and generates a lot of temporary
30837  variables.
30838  The live range computation determines the lifetime of each of these compiler-ge
30839 nerated temporaries.
30840  A picture speaks a thousand words.
30841  ICode example sections show the live range annotations for each of the
30842  operand.
30843  It is important to note here, each iCode is assigned a number in the order
30844  of its execution in the function.
30845  The live ranges are computed in terms of these numbers.
30846  The from number is the number of the iCode which first defines the operand
30847  and the to number signifies the iCode which uses this operand last.
30848 \layout Paragraph*
30849
30850 Register Allocation
30851 \begin_inset LatexCommand \index{Register allocation}
30852
30853 \end_inset 
30854
30855
30856 \layout Standard
30857
30858 The register allocation determines the type and number of registers needed
30859  by each operand.
30860  In most MCUs only a few registers can be used for indirect addressing.
30861  In case of 8051 for example the registers R0 & R1 can be used to indirectly
30862  address the internal ram and DPTR to indirectly address the external ram.
30863  The compiler will try to allocate the appropriate register to pointer variables
30864  if it can.
30865  ICode example section shows the operands annotated with the registers assigned
30866  to them.
30867  The compiler will try to keep operands in registers as much as possible;
30868  there are several schemes the compiler uses to do achieve this.
30869  When the compiler runs out of registers the compiler will check to see
30870  if there are any live operands which is not used or defined in the current
30871  basic block being processed, if there are any found then it will push that
30872  operand and use the registers in this block, the operand will then be popped
30873  at the end of the basic block.
30874  
30875 \layout Standard
30876
30877 There are other MCU specific considerations in this phase.
30878  Some MCUs have an accumulator; very short-lived operands could be assigned
30879  to the accumulator instead of a general-purpose register.
30880 \layout Paragraph*
30881
30882 Code generation
30883 \layout Standard
30884
30885 Figure II gives a table of iCode
30886 \begin_inset LatexCommand \index{iCode}
30887
30888 \end_inset 
30889
30890  operations supported by the compiler.
30891  The code generation involves translating these operations into corresponding
30892  assembly code for the processor.
30893  This sounds overly simple but that is the essence of code generation.
30894  Some of the iCode operations are generated on a MCU specific manner for
30895  example, the z80 port does not use registers to pass parameters so the
30896  SEND and RECV iCode operations will not be generated, and it also does
30897  not support JUMPTABLES.
30898  
30899 \newline 
30900
30901 \layout Standard
30902
30903
30904 \size footnotesize 
30905 Figure II 
30906 \begin_inset  Tabular
30907 <lyxtabular version="3" rows="39" columns="4">
30908 <features islongtable="true" headBottomDL="true">
30909 <column alignment="block" valignment="top" leftline="true" width="13col%">
30910 <column alignment="left" valignment="top" leftline="true" width="13col%">
30911 <column alignment="block" valignment="top" leftline="true" width="22col%">
30912 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
30913 <row topline="true" bottomline="true" endhead="true">
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30915 \begin_inset Text
30916
30917 \layout Standard
30918
30919
30920 \series bold 
30921 iCode
30922 \series default 
30923
30924 \begin_inset LatexCommand \index{iCode}
30925
30926 \end_inset 
30927
30928
30929 \end_inset 
30930 </cell>
30931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30932 \begin_inset Text
30933
30934 \layout Standard
30935
30936
30937 \series bold 
30938 Operands
30939 \end_inset 
30940 </cell>
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30942 \begin_inset Text
30943
30944 \layout Standard
30945
30946
30947 \series bold 
30948 Description
30949 \end_inset 
30950 </cell>
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30952 \begin_inset Text
30953
30954 \layout Standard
30955
30956
30957 \series bold 
30958 C Equivalent
30959 \end_inset 
30960 </cell>
30961 </row>
30962 <row topline="true">
30963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30964 \begin_inset Text
30965
30966 \layout Standard
30967
30968
30969 \size footnotesize 
30970 '!'
30971 \end_inset 
30972 </cell>
30973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30974 \begin_inset Text
30975
30976 \layout Standard
30977
30978
30979 \size footnotesize 
30980 IC_LEFT() IC_RESULT()
30981 \end_inset 
30982 </cell>
30983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30984 \begin_inset Text
30985
30986 \layout Standard
30987
30988
30989 \size footnotesize 
30990 NOT operation 
30991 \end_inset 
30992 </cell>
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30994 \begin_inset Text
30995
30996 \layout Standard
30997
30998
30999 \size footnotesize 
31000 IC_RESULT = ! IC_LEFT;
31001 \end_inset 
31002 </cell>
31003 </row>
31004 <row topline="true">
31005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31006 \begin_inset Text
31007
31008 \layout Standard
31009
31010
31011 \size footnotesize 
31012 '~'
31013 \end_inset 
31014 </cell>
31015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31016 \begin_inset Text
31017
31018 \layout Standard
31019
31020
31021 \size footnotesize 
31022 IC_LEFT() IC_RESULT()
31023 \end_inset 
31024 </cell>
31025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31026 \begin_inset Text
31027
31028 \layout Standard
31029
31030
31031 \size footnotesize 
31032 Bitwise complement of 
31033 \end_inset 
31034 </cell>
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31036 \begin_inset Text
31037
31038 \layout Standard
31039
31040
31041 \size footnotesize 
31042 IC_RESULT = ~IC_LEFT;
31043 \end_inset 
31044 </cell>
31045 </row>
31046 <row topline="true">
31047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31048 \begin_inset Text
31049
31050 \layout Standard
31051
31052
31053 \size footnotesize 
31054 RRC
31055 \end_inset 
31056 </cell>
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31058 \begin_inset Text
31059
31060 \layout Standard
31061
31062
31063 \size footnotesize 
31064 IC_LEFT() IC_RESULT()
31065 \end_inset 
31066 </cell>
31067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31068 \begin_inset Text
31069
31070 \layout Standard
31071
31072
31073 \size footnotesize 
31074 Rotate right with carry
31075 \end_inset 
31076 </cell>
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31078 \begin_inset Text
31079
31080 \layout Standard
31081
31082
31083 \size footnotesize 
31084 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
31085 \end_inset 
31086 </cell>
31087 </row>
31088 <row topline="true">
31089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31090 \begin_inset Text
31091
31092 \layout Standard
31093
31094
31095 \size footnotesize 
31096 RLC
31097 \end_inset 
31098 </cell>
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \layout Standard
31103
31104
31105 \size footnotesize 
31106 IC_LEFT() IC_RESULT()
31107 \end_inset 
31108 </cell>
31109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31110 \begin_inset Text
31111
31112 \layout Standard
31113
31114
31115 \size footnotesize 
31116 Rotate left with carry
31117 \end_inset 
31118 </cell>
31119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31120 \begin_inset Text
31121
31122 \layout Standard
31123
31124
31125 \size footnotesize 
31126 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
31127 \end_inset 
31128 </cell>
31129 </row>
31130 <row topline="true">
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31132 \begin_inset Text
31133
31134 \layout Standard
31135
31136
31137 \size footnotesize 
31138 GETHBIT
31139 \end_inset 
31140 </cell>
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31142 \begin_inset Text
31143
31144 \layout Standard
31145
31146
31147 \size footnotesize 
31148 IC_LEFT() IC_RESULT()
31149 \end_inset 
31150 </cell>
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31152 \begin_inset Text
31153
31154 \layout Standard
31155
31156
31157 \size footnotesize 
31158 Get the highest order bit of IC_LEFT
31159 \end_inset 
31160 </cell>
31161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31162 \begin_inset Text
31163
31164 \layout Standard
31165
31166
31167 \size footnotesize 
31168 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
31169 \end_inset 
31170 </cell>
31171 </row>
31172 <row topline="true">
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31174 \begin_inset Text
31175
31176 \layout Standard
31177
31178
31179 \size footnotesize 
31180 UNARYMINUS
31181 \end_inset 
31182 </cell>
31183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31184 \begin_inset Text
31185
31186 \layout Standard
31187
31188
31189 \size footnotesize 
31190 IC_LEFT() IC_RESULT()
31191 \end_inset 
31192 </cell>
31193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31194 \begin_inset Text
31195
31196 \layout Standard
31197
31198
31199 \size footnotesize 
31200 Unary minus
31201 \end_inset 
31202 </cell>
31203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31204 \begin_inset Text
31205
31206 \layout Standard
31207
31208
31209 \size footnotesize 
31210 IC_RESULT = - IC_LEFT;
31211 \end_inset 
31212 </cell>
31213 </row>
31214 <row topline="true">
31215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31216 \begin_inset Text
31217
31218 \layout Standard
31219
31220
31221 \size footnotesize 
31222 IPUSH
31223 \end_inset 
31224 </cell>
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_inset Text
31227
31228 \layout Standard
31229
31230
31231 \size footnotesize 
31232 IC_LEFT()
31233 \end_inset 
31234 </cell>
31235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31236 \begin_inset Text
31237
31238 \layout Standard
31239
31240
31241 \size footnotesize 
31242 Push the operand into stack
31243 \end_inset 
31244 </cell>
31245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31246 \begin_inset Text
31247
31248 \layout Standard
31249
31250
31251 \size footnotesize 
31252 NONE
31253 \end_inset 
31254 </cell>
31255 </row>
31256 <row topline="true">
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31258 \begin_inset Text
31259
31260 \layout Standard
31261
31262
31263 \size footnotesize 
31264 IPOP
31265 \end_inset 
31266 </cell>
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31268 \begin_inset Text
31269
31270 \layout Standard
31271
31272
31273 \size footnotesize 
31274 IC_LEFT()
31275 \end_inset 
31276 </cell>
31277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31278 \begin_inset Text
31279
31280 \layout Standard
31281
31282
31283 \size footnotesize 
31284 Pop the operand from the stack 
31285 \end_inset 
31286 </cell>
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31288 \begin_inset Text
31289
31290 \layout Standard
31291
31292
31293 \size footnotesize 
31294 NONE
31295 \end_inset 
31296 </cell>
31297 </row>
31298 <row topline="true">
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \layout Standard
31303
31304
31305 \size footnotesize 
31306 CALL
31307 \end_inset 
31308 </cell>
31309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31310 \begin_inset Text
31311
31312 \layout Standard
31313
31314
31315 \size footnotesize 
31316 IC_LEFT() IC_RESULT()
31317 \end_inset 
31318 </cell>
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31320 \begin_inset Text
31321
31322 \layout Standard
31323
31324
31325 \size footnotesize 
31326 Call the function represented by IC_LEFT 
31327 \end_inset 
31328 </cell>
31329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31330 \begin_inset Text
31331
31332 \layout Standard
31333
31334
31335 \size footnotesize 
31336 IC_RESULT = IC_LEFT();
31337 \end_inset 
31338 </cell>
31339 </row>
31340 <row topline="true">
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31342 \begin_inset Text
31343
31344 \layout Standard
31345
31346
31347 \size footnotesize 
31348 PCALL
31349 \end_inset 
31350 </cell>
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31352 \begin_inset Text
31353
31354 \layout Standard
31355
31356
31357 \size footnotesize 
31358 IC_LEFT() IC_RESULT()
31359 \end_inset 
31360 </cell>
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \layout Standard
31365
31366
31367 \size footnotesize 
31368 Call via function pointer
31369 \end_inset 
31370 </cell>
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31372 \begin_inset Text
31373
31374 \layout Standard
31375
31376
31377 \size footnotesize 
31378 IC_RESULT = (*IC_LEFT)();
31379 \end_inset 
31380 </cell>
31381 </row>
31382 <row topline="true">
31383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31384 \begin_inset Text
31385
31386 \layout Standard
31387
31388
31389 \size footnotesize 
31390 RETURN
31391 \end_inset 
31392 </cell>
31393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31394 \begin_inset Text
31395
31396 \layout Standard
31397
31398
31399 \size footnotesize 
31400 IC_LEFT()
31401 \end_inset 
31402 </cell>
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31404 \begin_inset Text
31405
31406 \layout Standard
31407
31408
31409 \size footnotesize 
31410 Return the value in operand IC_LEFT 
31411 \end_inset 
31412 </cell>
31413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31414 \begin_inset Text
31415
31416 \layout Standard
31417
31418
31419 \size footnotesize 
31420 return IC_LEFT;
31421 \end_inset 
31422 </cell>
31423 </row>
31424 <row topline="true">
31425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31426 \begin_inset Text
31427
31428 \layout Standard
31429
31430
31431 \size footnotesize 
31432 LABEL
31433 \end_inset 
31434 </cell>
31435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31436 \begin_inset Text
31437
31438 \layout Standard
31439
31440
31441 \size footnotesize 
31442 IC_LABEL() 
31443 \end_inset 
31444 </cell>
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31446 \begin_inset Text
31447
31448 \layout Standard
31449
31450
31451 \size footnotesize 
31452 Label
31453 \end_inset 
31454 </cell>
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31456 \begin_inset Text
31457
31458 \layout Standard
31459
31460
31461 \size footnotesize 
31462 IC_LABEL:
31463 \end_inset 
31464 </cell>
31465 </row>
31466 <row topline="true">
31467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31468 \begin_inset Text
31469
31470 \layout Standard
31471
31472
31473 \size footnotesize 
31474 GOTO
31475 \end_inset 
31476 </cell>
31477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31478 \begin_inset Text
31479
31480 \layout Standard
31481
31482
31483 \size footnotesize 
31484 IC_LABEL() 
31485 \end_inset 
31486 </cell>
31487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_inset Text
31489
31490 \layout Standard
31491
31492
31493 \size footnotesize 
31494 Goto label
31495 \end_inset 
31496 </cell>
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \layout Standard
31501
31502
31503 \size footnotesize 
31504 goto IC_LABEL();
31505 \end_inset 
31506 </cell>
31507 </row>
31508 <row topline="true">
31509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31510 \begin_inset Text
31511
31512 \layout Standard
31513
31514
31515 \size footnotesize 
31516 '+'
31517 \end_inset 
31518 </cell>
31519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31520 \begin_inset Text
31521
31522 \layout Standard
31523
31524
31525 \size footnotesize 
31526 IC_LEFT() IC_RIGHT() IC_RESULT()
31527 \end_inset 
31528 </cell>
31529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31530 \begin_inset Text
31531
31532 \layout Standard
31533
31534
31535 \size footnotesize 
31536 Addition
31537 \end_inset 
31538 </cell>
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31540 \begin_inset Text
31541
31542 \layout Standard
31543
31544
31545 \size footnotesize 
31546 IC_RESULT = IC_LEFT + IC_RIGHT
31547 \end_inset 
31548 </cell>
31549 </row>
31550 <row topline="true">
31551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31552 \begin_inset Text
31553
31554 \layout Standard
31555
31556
31557 \size footnotesize 
31558 '-'
31559 \end_inset 
31560 </cell>
31561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31562 \begin_inset Text
31563
31564 \layout Standard
31565
31566
31567 \size footnotesize 
31568 IC_LEFT() IC_RIGHT() IC_RESULT()
31569 \end_inset 
31570 </cell>
31571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31572 \begin_inset Text
31573
31574 \layout Standard
31575
31576
31577 \size footnotesize 
31578 Subtraction
31579 \end_inset 
31580 </cell>
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31582 \begin_inset Text
31583
31584 \layout Standard
31585
31586
31587 \size footnotesize 
31588 IC_RESULT = IC_LEFT - IC_RIGHT 
31589 \end_inset 
31590 </cell>
31591 </row>
31592 <row topline="true">
31593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31594 \begin_inset Text
31595
31596 \layout Standard
31597
31598
31599 \size footnotesize 
31600 '*'
31601 \end_inset 
31602 </cell>
31603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31604 \begin_inset Text
31605
31606 \layout Standard
31607
31608
31609 \size footnotesize 
31610 IC_LEFT() IC_RIGHT() IC_RESULT()
31611 \end_inset 
31612 </cell>
31613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31614 \begin_inset Text
31615
31616 \layout Standard
31617
31618
31619 \size footnotesize 
31620 Multiplication 
31621 \end_inset 
31622 </cell>
31623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31624 \begin_inset Text
31625
31626 \layout Standard
31627
31628
31629 \size footnotesize 
31630 IC_RESULT = IC_LEFT * IC_RIGHT;
31631 \end_inset 
31632 </cell>
31633 </row>
31634 <row topline="true">
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31636 \begin_inset Text
31637
31638 \layout Standard
31639
31640
31641 \size footnotesize 
31642 '/'
31643 \end_inset 
31644 </cell>
31645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31646 \begin_inset Text
31647
31648 \layout Standard
31649
31650
31651 \size footnotesize 
31652 IC_LEFT() IC_RIGHT() IC_RESULT()
31653 \end_inset 
31654 </cell>
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31656 \begin_inset Text
31657
31658 \layout Standard
31659
31660
31661 \size footnotesize 
31662 Division
31663 \end_inset 
31664 </cell>
31665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31666 \begin_inset Text
31667
31668 \layout Standard
31669
31670
31671 \size footnotesize 
31672 IC_RESULT = IC_LEFT / IC_RIGHT;
31673 \end_inset 
31674 </cell>
31675 </row>
31676 <row topline="true">
31677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31678 \begin_inset Text
31679
31680 \layout Standard
31681
31682
31683 \size footnotesize 
31684 '%'
31685 \end_inset 
31686 </cell>
31687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31688 \begin_inset Text
31689
31690 \layout Standard
31691
31692
31693 \size footnotesize 
31694 IC_LEFT() IC_RIGHT() IC_RESULT()
31695 \end_inset 
31696 </cell>
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31698 \begin_inset Text
31699
31700 \layout Standard
31701
31702
31703 \size footnotesize 
31704 Modulus
31705 \end_inset 
31706 </cell>
31707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31708 \begin_inset Text
31709
31710 \layout Standard
31711
31712
31713 \size footnotesize 
31714 IC_RESULT = IC_LEFT % IC_RIGHT;
31715 \end_inset 
31716 </cell>
31717 </row>
31718 <row topline="true">
31719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31720 \begin_inset Text
31721
31722 \layout Standard
31723
31724
31725 \size footnotesize 
31726 '<'
31727 \end_inset 
31728 </cell>
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31730 \begin_inset Text
31731
31732 \layout Standard
31733
31734
31735 \size footnotesize 
31736 IC_LEFT() IC_RIGHT() IC_RESULT()
31737 \end_inset 
31738 </cell>
31739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31740 \begin_inset Text
31741
31742 \layout Standard
31743
31744
31745 \size footnotesize 
31746 Less than
31747 \end_inset 
31748 </cell>
31749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31750 \begin_inset Text
31751
31752 \layout Standard
31753
31754
31755 \size footnotesize 
31756 IC_RESULT = IC_LEFT < IC_RIGHT;
31757 \end_inset 
31758 </cell>
31759 </row>
31760 <row topline="true">
31761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31762 \begin_inset Text
31763
31764 \layout Standard
31765
31766
31767 \size footnotesize 
31768 '>'
31769 \end_inset 
31770 </cell>
31771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31772 \begin_inset Text
31773
31774 \layout Standard
31775
31776
31777 \size footnotesize 
31778 IC_LEFT() IC_RIGHT() IC_RESULT()
31779 \end_inset 
31780 </cell>
31781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31782 \begin_inset Text
31783
31784 \layout Standard
31785
31786
31787 \size footnotesize 
31788 Greater than 
31789 \end_inset 
31790 </cell>
31791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31792 \begin_inset Text
31793
31794 \layout Standard
31795
31796
31797 \size footnotesize 
31798 IC_RESULT = IC_LEFT > IC_RIGHT;
31799 \end_inset 
31800 </cell>
31801 </row>
31802 <row topline="true">
31803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31804 \begin_inset Text
31805
31806 \layout Standard
31807
31808
31809 \size footnotesize 
31810 EQ_OP
31811 \end_inset 
31812 </cell>
31813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31814 \begin_inset Text
31815
31816 \layout Standard
31817
31818
31819 \size footnotesize 
31820 IC_LEFT() IC_RIGHT() IC_RESULT()
31821 \end_inset 
31822 </cell>
31823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31824 \begin_inset Text
31825
31826 \layout Standard
31827
31828
31829 \size footnotesize 
31830 Equal to 
31831 \end_inset 
31832 </cell>
31833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31834 \begin_inset Text
31835
31836 \layout Standard
31837
31838
31839 \size footnotesize 
31840 IC_RESULT = IC_LEFT == IC_RIGHT;
31841 \end_inset 
31842 </cell>
31843 </row>
31844 <row topline="true">
31845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31846 \begin_inset Text
31847
31848 \layout Standard
31849
31850
31851 \size footnotesize 
31852 AND_OP
31853 \end_inset 
31854 </cell>
31855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31856 \begin_inset Text
31857
31858 \layout Standard
31859
31860
31861 \size footnotesize 
31862 IC_LEFT() IC_RIGHT() IC_RESULT() 
31863 \end_inset 
31864 </cell>
31865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31866 \begin_inset Text
31867
31868 \layout Standard
31869
31870
31871 \size footnotesize 
31872 Logical and operation
31873 \end_inset 
31874 </cell>
31875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31876 \begin_inset Text
31877
31878 \layout Standard
31879
31880
31881 \size footnotesize 
31882 IC_RESULT = IC_LEFT && IC_RIGHT; 
31883 \end_inset 
31884 </cell>
31885 </row>
31886 <row topline="true">
31887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31888 \begin_inset Text
31889
31890 \layout Standard
31891
31892
31893 \size footnotesize 
31894 OR_OP
31895 \end_inset 
31896 </cell>
31897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31898 \begin_inset Text
31899
31900 \layout Standard
31901
31902
31903 \size footnotesize 
31904 IC_LEFT() IC_RIGHT() IC_RESULT() 
31905 \end_inset 
31906 </cell>
31907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31908 \begin_inset Text
31909
31910 \layout Standard
31911
31912
31913 \size footnotesize 
31914 Logical or operation 
31915 \end_inset 
31916 </cell>
31917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31918 \begin_inset Text
31919
31920 \layout Standard
31921
31922
31923 \size footnotesize 
31924 IC_RESULT = IC_LEFT || IC_RIGHT; 
31925 \end_inset 
31926 </cell>
31927 </row>
31928 <row topline="true">
31929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31930 \begin_inset Text
31931
31932 \layout Standard
31933
31934
31935 \size footnotesize 
31936 '^'
31937 \end_inset 
31938 </cell>
31939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31940 \begin_inset Text
31941
31942 \layout Standard
31943
31944
31945 \size footnotesize 
31946 IC_LEFT() IC_RIGHT() IC_RESULT() 
31947 \end_inset 
31948 </cell>
31949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31950 \begin_inset Text
31951
31952 \layout Standard
31953
31954
31955 \size footnotesize 
31956 Exclusive OR
31957 \end_inset 
31958 </cell>
31959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31960 \begin_inset Text
31961
31962 \layout Standard
31963
31964
31965 \size footnotesize 
31966 IC_RESULT = IC_LEFT ^ IC_RIGHT;
31967 \end_inset 
31968 </cell>
31969 </row>
31970 <row topline="true">
31971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31972 \begin_inset Text
31973
31974 \layout Standard
31975
31976
31977 \size footnotesize 
31978 '|'
31979 \end_inset 
31980 </cell>
31981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31982 \begin_inset Text
31983
31984 \layout Standard
31985
31986
31987 \size footnotesize 
31988 IC_LEFT() IC_RIGHT() IC_RESULT() 
31989 \end_inset 
31990 </cell>
31991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31992 \begin_inset Text
31993
31994 \layout Standard
31995
31996
31997 \size footnotesize 
31998 Bitwise OR 
31999 \end_inset 
32000 </cell>
32001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32002 \begin_inset Text
32003
32004 \layout Standard
32005
32006
32007 \size footnotesize 
32008 IC_RESULT = IC_LEFT | IC_RIGHT;
32009 \end_inset 
32010 </cell>
32011 </row>
32012 <row topline="true">
32013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32014 \begin_inset Text
32015
32016 \layout Standard
32017
32018
32019 \size footnotesize 
32020 BITWISEAND
32021 \end_inset 
32022 </cell>
32023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32024 \begin_inset Text
32025
32026 \layout Standard
32027
32028
32029 \size footnotesize 
32030 IC_LEFT() IC_RIGHT() IC_RESULT()
32031 \end_inset 
32032 </cell>
32033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32034 \begin_inset Text
32035
32036 \layout Standard
32037
32038
32039 \size footnotesize 
32040 Bitwise AND 
32041 \end_inset 
32042 </cell>
32043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32044 \begin_inset Text
32045
32046 \layout Standard
32047
32048
32049 \size footnotesize 
32050 IC_RESULT = IC_LEFT & IC_RIGHT;
32051 \end_inset 
32052 </cell>
32053 </row>
32054 <row topline="true">
32055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32056 \begin_inset Text
32057
32058 \layout Standard
32059
32060
32061 \size footnotesize 
32062 LEFT_OP
32063 \end_inset 
32064 </cell>
32065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32066 \begin_inset Text
32067
32068 \layout Standard
32069
32070
32071 \size footnotesize 
32072 IC_LEFT() IC_RIGHT() IC_RESULT()
32073 \end_inset 
32074 </cell>
32075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32076 \begin_inset Text
32077
32078 \layout Standard
32079
32080
32081 \size footnotesize 
32082 Left shift 
32083 \end_inset 
32084 </cell>
32085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32086 \begin_inset Text
32087
32088 \layout Standard
32089
32090
32091 \size footnotesize 
32092 IC_RESULT = IC_LEFT << IC_RIGHT 
32093 \end_inset 
32094 </cell>
32095 </row>
32096 <row topline="true">
32097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32098 \begin_inset Text
32099
32100 \layout Standard
32101
32102
32103 \size footnotesize 
32104 RIGHT_OP
32105 \end_inset 
32106 </cell>
32107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32108 \begin_inset Text
32109
32110 \layout Standard
32111
32112
32113 \size footnotesize 
32114 IC_LEFT() IC_RIGHT() IC_RESULT()
32115 \end_inset 
32116 </cell>
32117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32118 \begin_inset Text
32119
32120 \layout Standard
32121
32122
32123 \size footnotesize 
32124 Right shift
32125 \end_inset 
32126 </cell>
32127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32128 \begin_inset Text
32129
32130 \layout Standard
32131
32132
32133 \size footnotesize 
32134 IC_RESULT = IC_LEFT >> IC_RIGHT 
32135 \end_inset 
32136 </cell>
32137 </row>
32138 <row topline="true">
32139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32140 \begin_inset Text
32141
32142 \layout Standard
32143
32144
32145 \size footnotesize 
32146 GET_VALUE_
32147 \newline 
32148 AT_ ADDRESS
32149 \end_inset 
32150 </cell>
32151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32152 \begin_inset Text
32153
32154 \layout Standard
32155
32156
32157 \size footnotesize 
32158 IC_LEFT() IC_RESULT()
32159 \end_inset 
32160 </cell>
32161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32162 \begin_inset Text
32163
32164 \layout Standard
32165
32166
32167 \size footnotesize 
32168 Indirect fetch 
32169 \end_inset 
32170 </cell>
32171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32172 \begin_inset Text
32173
32174 \layout Standard
32175
32176
32177 \size footnotesize 
32178 IC_RESULT = (*IC_LEFT);
32179 \end_inset 
32180 </cell>
32181 </row>
32182 <row topline="true">
32183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32184 \begin_inset Text
32185
32186 \layout Standard
32187
32188
32189 \size footnotesize 
32190 POINTER_SET
32191 \end_inset 
32192 </cell>
32193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32194 \begin_inset Text
32195
32196 \layout Standard
32197
32198
32199 \size footnotesize 
32200 IC_RIGHT() IC_RESULT() 
32201 \end_inset 
32202 </cell>
32203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32204 \begin_inset Text
32205
32206 \layout Standard
32207
32208
32209 \size footnotesize 
32210 Indirect set
32211 \end_inset 
32212 </cell>
32213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32214 \begin_inset Text
32215
32216 \layout Standard
32217
32218
32219 \size footnotesize 
32220 (*IC_RESULT) = IC_RIGHT;
32221 \end_inset 
32222 </cell>
32223 </row>
32224 <row topline="true">
32225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32226 \begin_inset Text
32227
32228 \layout Standard
32229
32230
32231 \size footnotesize 
32232 '='
32233 \end_inset 
32234 </cell>
32235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32236 \begin_inset Text
32237
32238 \layout Standard
32239
32240
32241 \size footnotesize 
32242 IC_RIGHT() IC_RESULT()
32243 \end_inset 
32244 </cell>
32245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32246 \begin_inset Text
32247
32248 \layout Standard
32249
32250
32251 \size footnotesize 
32252 Assignment
32253 \end_inset 
32254 </cell>
32255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32256 \begin_inset Text
32257
32258 \layout Standard
32259
32260
32261 \size footnotesize 
32262 IC_RESULT = IC_RIGHT;
32263 \end_inset 
32264 </cell>
32265 </row>
32266 <row topline="true">
32267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32268 \begin_inset Text
32269
32270 \layout Standard
32271
32272
32273 \size footnotesize 
32274 IFX
32275 \end_inset 
32276 </cell>
32277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32278 \begin_inset Text
32279
32280 \layout Standard
32281
32282
32283 \size footnotesize 
32284 IC_COND IC_TRUE IC_LABEL
32285 \end_inset 
32286 </cell>
32287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32288 \begin_inset Text
32289
32290 \layout Standard
32291
32292
32293 \size footnotesize 
32294 Conditional jump.
32295  If true label is present then jump to true label if condition is true else
32296  jump to false label if condition is false 
32297 \end_inset 
32298 </cell>
32299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32300 \begin_inset Text
32301
32302 \layout Standard
32303
32304
32305 \size footnotesize 
32306 if (IC_COND) goto IC_TRUE; 
32307 \newline 
32308 \SpecialChar ~
32309 \SpecialChar ~
32310 Or 
32311 \newline 
32312 If (!IC_COND) goto IC_FALSE;
32313 \end_inset 
32314 </cell>
32315 </row>
32316 <row topline="true">
32317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32318 \begin_inset Text
32319
32320 \layout Standard
32321
32322
32323 \size footnotesize 
32324 ADDRESS_OF
32325 \end_inset 
32326 </cell>
32327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 \begin_inset Text
32329
32330 \layout Standard
32331
32332
32333 \size footnotesize 
32334 IC_LEFT() IC_RESULT()
32335 \end_inset 
32336 </cell>
32337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32338 \begin_inset Text
32339
32340 \layout Standard
32341
32342
32343 \size footnotesize 
32344 Address of 
32345 \end_inset 
32346 </cell>
32347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32348 \begin_inset Text
32349
32350 \layout Standard
32351
32352
32353 \size footnotesize 
32354 IC_RESULT = &IC_LEFT();
32355 \end_inset 
32356 </cell>
32357 </row>
32358 <row topline="true">
32359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32360 \begin_inset Text
32361
32362 \layout Standard
32363
32364
32365 \size footnotesize 
32366 JUMPTABLE
32367 \end_inset 
32368 </cell>
32369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32370 \begin_inset Text
32371
32372 \layout Standard
32373
32374
32375 \size footnotesize 
32376 IC_JTCOND IC_JTLABELS
32377 \end_inset 
32378 </cell>
32379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32380 \begin_inset Text
32381
32382 \layout Standard
32383
32384
32385 \size footnotesize 
32386 Jump to list of labels depending on the value of JTCOND
32387 \end_inset 
32388 </cell>
32389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32390 \begin_inset Text
32391
32392 \layout Standard
32393
32394
32395 \size footnotesize 
32396 Switch statement
32397 \end_inset 
32398 </cell>
32399 </row>
32400 <row topline="true">
32401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32402 \begin_inset Text
32403
32404 \layout Standard
32405
32406
32407 \size footnotesize 
32408 CAST
32409 \end_inset 
32410 </cell>
32411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32412 \begin_inset Text
32413
32414 \layout Standard
32415
32416
32417 \size footnotesize 
32418 IC_RIGHT() IC_LEFT() IC_RESULT()
32419 \end_inset 
32420 </cell>
32421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32422 \begin_inset Text
32423
32424 \layout Standard
32425
32426
32427 \size footnotesize 
32428 Cast types 
32429 \end_inset 
32430 </cell>
32431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32432 \begin_inset Text
32433
32434 \layout Standard
32435
32436
32437 \size footnotesize 
32438 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
32439 \end_inset 
32440 </cell>
32441 </row>
32442 <row topline="true">
32443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32444 \begin_inset Text
32445
32446 \layout Standard
32447
32448
32449 \size footnotesize 
32450 SEND
32451 \end_inset 
32452 </cell>
32453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32454 \begin_inset Text
32455
32456 \layout Standard
32457
32458
32459 \size footnotesize 
32460 IC_LEFT()
32461 \end_inset 
32462 </cell>
32463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32464 \begin_inset Text
32465
32466 \layout Standard
32467
32468
32469 \size footnotesize 
32470 This is used for passing parameters in registers; 
32471 \newline 
32472 move IC_LEFT to the next available parameter register.
32473 \end_inset 
32474 </cell>
32475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32476 \begin_inset Text
32477
32478 \layout Standard
32479
32480
32481 \size footnotesize 
32482 None
32483 \end_inset 
32484 </cell>
32485 </row>
32486 <row topline="true">
32487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32488 \begin_inset Text
32489
32490 \layout Standard
32491
32492
32493 \size footnotesize 
32494 RECV
32495 \end_inset 
32496 </cell>
32497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32498 \begin_inset Text
32499
32500 \layout Standard
32501
32502
32503 \size footnotesize 
32504 IC_RESULT()
32505 \end_inset 
32506 </cell>
32507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32508 \begin_inset Text
32509
32510 \layout Standard
32511
32512
32513 \size footnotesize 
32514 This is used for receiving parameters passed in registers;
32515 \newline 
32516 Move the values in the next parameter register to IC_RESULT 
32517 \end_inset 
32518 </cell>
32519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32520 \begin_inset Text
32521
32522 \layout Standard
32523
32524
32525 \size footnotesize 
32526 None
32527 \end_inset 
32528 </cell>
32529 </row>
32530 <row topline="true" bottomline="true">
32531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32532 \begin_inset Text
32533
32534 \layout Standard
32535
32536
32537 \shape slanted 
32538 \size footnotesize 
32539 (some more have been added)
32540 \end_inset 
32541 </cell>
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32543 \begin_inset Text
32544
32545 \layout Standard
32546
32547 \end_inset 
32548 </cell>
32549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32550 \begin_inset Text
32551
32552 \layout Standard
32553
32554 \end_inset 
32555 </cell>
32556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32557 \begin_inset Text
32558
32559 \layout Standard
32560
32561
32562 \shape slanted 
32563 \size footnotesize 
32564 see f.e.
32565  
32566 \family typewriter 
32567 gen51Code()
32568 \family default 
32569  in 
32570 \family typewriter 
32571 src/mcs51/gen.c
32572 \end_inset 
32573 </cell>
32574 </row>
32575 </lyxtabular>
32576
32577 \end_inset 
32578
32579
32580 \layout Comment
32581
32582 In the original article Figure II was announced to be downloadable on 
32583 \shape italic 
32584 Circuit Cellar
32585 \shape default 
32586 's web site.
32587  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
32588 \layout Paragraph*
32589
32590 ICode Example
32591 \begin_inset LatexCommand \index{iCode}
32592
32593 \end_inset 
32594
32595
32596 \layout Standard
32597
32598 This section shows some details of iCode.
32599  The example C code does not do anything useful; it is used as an example
32600  to illustrate the intermediate code generated by the compiler.
32601 \layout Verse
32602
32603
32604 \family typewriter 
32605 1.\SpecialChar ~
32606 xdata int * p;
32607 \newline 
32608 2.\SpecialChar ~
32609 int gint;
32610 \newline 
32611 3.\SpecialChar ~
32612 /* This function does nothing useful.
32613  It is used
32614 \newline 
32615 4.\SpecialChar ~
32616 \SpecialChar ~
32617 \SpecialChar ~
32618 \SpecialChar ~
32619 for the purpose of explaining iCode */
32620 \newline 
32621 5.\SpecialChar ~
32622 short function (data int *x)
32623 \newline 
32624 6.\SpecialChar ~
32625 {
32626 \newline 
32627 7.\SpecialChar ~
32628 \SpecialChar ~
32629 \SpecialChar ~
32630 short i=10; \SpecialChar ~
32631 \SpecialChar ~
32632 /* dead initialization eliminated */
32633 \newline 
32634 8.\SpecialChar ~
32635 \SpecialChar ~
32636 \SpecialChar ~
32637 short sum=10; /* dead initialization eliminated */
32638 \newline 
32639 9.\SpecialChar ~
32640 \SpecialChar ~
32641 \SpecialChar ~
32642 short mul;
32643 \newline 
32644 10.\SpecialChar ~
32645 \SpecialChar ~
32646 int j ;
32647 \newline 
32648 11.\SpecialChar ~
32649 \SpecialChar ~
32650 while (*x) *x++ = *p++; 
32651 \newline 
32652 12.\SpecialChar ~
32653 \SpecialChar ~
32654 \SpecialChar ~
32655 \SpecialChar ~
32656 sum = 0 ; 
32657 \newline 
32658 13.\SpecialChar ~
32659 \SpecialChar ~
32660 mul = 0;
32661 \newline 
32662 14.\SpecialChar ~
32663 \SpecialChar ~
32664 /* compiler detects i,j to be induction variables */
32665 \newline 
32666 15.\SpecialChar ~
32667 \SpecialChar ~
32668 for (i = 0, j = 10 ; i < 10 ; i++, j
32669 \family default 
32670 -
32671 \begin_inset ERT
32672 status Collapsed
32673
32674 \layout Standard
32675
32676 \backslash 
32677 /
32678 \end_inset 
32679
32680 -
32681 \family typewriter 
32682 ) {
32683 \newline 
32684 16.\SpecialChar ~
32685 \SpecialChar ~
32686 \SpecialChar ~
32687 \SpecialChar ~
32688 sum += i;
32689 \newline 
32690 17.\SpecialChar ~
32691 \SpecialChar ~
32692 \SpecialChar ~
32693 \SpecialChar ~
32694 mul += i * 3; \SpecialChar ~
32695 \SpecialChar ~
32696 /* this multiplication remains */
32697 \newline 
32698 18.\SpecialChar ~
32699 \SpecialChar ~
32700 \SpecialChar ~
32701 \SpecialChar ~
32702 gint += j * 3;\SpecialChar ~
32703 \SpecialChar ~
32704 /* this multiplication changed to addition */
32705 \newline 
32706 19.\SpecialChar ~
32707 \SpecialChar ~
32708 }
32709 \newline 
32710 20.\SpecialChar ~
32711 \SpecialChar ~
32712 return sum+mul;
32713 \newline 
32714 21.\SpecialChar ~
32715 }
32716 \layout Standard
32717
32718 In addition to the operands each iCode contains information about the filename
32719  and line it corresponds to in the source file.
32720  The first field in the listing should be interpreted as follows:
32721 \newline 
32722
32723 \shape italic 
32724 \size footnotesize 
32725 Filename(linenumber: iCode Execution sequence number : ICode hash table
32726  key : loop depth of the iCode).
32727 \shape default 
32728 \size default 
32729
32730 \newline 
32731 Then follows the human readable form of the ICode operation.
32732  Each operand of this triplet form can be of three basic types a) compiler
32733  generated temporary b) user defined variable c) a constant value.
32734  Note that local variables and parameters are replaced by compiler generated
32735  temporaries.
32736  Live ranges
32737 \begin_inset LatexCommand \index{Live range analysis}
32738
32739 \end_inset 
32740
32741  are computed only for temporaries (i.e.
32742  live ranges are not computed for global variables).
32743  Registers
32744 \begin_inset LatexCommand \index{Register allocation}
32745
32746 \end_inset 
32747
32748  are allocated for temporaries only.
32749  Operands are formatted in the following manner:
32750 \newline 
32751
32752 \shape italic 
32753 \size footnotesize 
32754 Operand Name [lr live-from : live-to ] { type information } [ registers
32755  allocated ].
32756 \shape default 
32757 \size default 
32758
32759 \newline 
32760 As mentioned earlier the live ranges are computed in terms of the execution
32761  sequence number of the iCodes, for example 
32762 \newline 
32763 the iTemp0 is live from (i.e.
32764  first defined in iCode with execution sequence number 3, and is last used
32765  in the iCode with sequence number 5).
32766  For induction variables such as iTemp21 the live range computation extends
32767  the lifetime from the start to the end of the loop.
32768 \newline 
32769 The register allocator used the live range information to allocate registers,
32770  the same registers may be used for different temporaries if their live
32771  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
32772  iTemp17 since their live ranges do not overlap.
32773  In addition the allocator also takes into consideration the type and usage
32774  of a temporary, for example itemp6 is a pointer to near space and is used
32775  as to fetch data from (i.e.
32776  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
32777  Some short lived temporaries are allocated to special registers which have
32778  meaning to the code generator e.g.
32779  iTemp13 is allocated to a pseudo register CC which tells the back end that
32780  the temporary is used only for a conditional jump the code generation makes
32781  use of this information to optimize a compare and jump ICode.
32782 \newline 
32783 There are several loop optimizations
32784 \begin_inset LatexCommand \index{Loop optimization}
32785
32786 \end_inset 
32787
32788  performed by the compiler.
32789  It can detect induction variables iTemp21(i) and iTemp23(j).
32790  Also note the compiler does selective strength reduction
32791 \begin_inset LatexCommand \index{Strength reduction}
32792
32793 \end_inset 
32794
32795 , i.e.
32796  the multiplication of an induction variable in line 18 (gint = j * 3) is
32797  changed to addition, a new temporary iTemp17 is allocated and assigned
32798  a initial value, a constant 3 is then added for each iteration of the loop.
32799  The compiler does not change the multiplication
32800 \begin_inset LatexCommand \index{Multiplication}
32801
32802 \end_inset 
32803
32804  in line 17 however since the processor does support an 8 * 8 bit multiplication.
32805 \newline 
32806 Note the dead code elimination
32807 \begin_inset LatexCommand \index{Dead-code elimination}
32808
32809 \end_inset 
32810
32811  optimization eliminated the dead assignments in line 7 & 8 to I and sum
32812  respectively.
32813 \newline 
32814
32815 \layout Standard
32816
32817
32818 \size footnotesize 
32819 Sample.c (5:1:0:0) _entry($9) :
32820 \layout Standard
32821
32822
32823 \size footnotesize 
32824 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
32825 \layout Standard
32826
32827
32828 \size footnotesize 
32829 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
32830 \layout Standard
32831
32832
32833 \size footnotesize 
32834 Sample.c(11:4:53:0) preHeaderLbl0($11) :
32835 \layout Standard
32836
32837
32838 \size footnotesize 
32839 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
32840  * int}[r2]
32841 \layout Standard
32842
32843
32844 \size footnotesize 
32845 Sample.c(11:6:5:1) _whilecontinue_0($1) :
32846 \layout Standard
32847
32848
32849 \size footnotesize 
32850 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
32851  int}[r0]]
32852 \layout Standard
32853
32854
32855 \size footnotesize 
32856 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32857 \layout Standard
32858
32859
32860 \size footnotesize 
32861 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
32862  * int}
32863 \layout Standard
32864
32865
32866 \size footnotesize 
32867 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
32868  {short}
32869 \layout Standard
32870
32871
32872 \size footnotesize 
32873 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
32874  * int}[DPTR]]
32875 \layout Standard
32876
32877
32878 \size footnotesize 
32879 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
32880 }[r2 r3]
32881 \layout Standard
32882
32883
32884 \size footnotesize 
32885 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
32886  * int}[r0] + 0x2 {short}
32887 \layout Standard
32888
32889
32890 \size footnotesize 
32891 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
32892 \layout Standard
32893
32894
32895 \size footnotesize 
32896 Sample.c(11:17:21:0)_whilebreak_0($3) :
32897 \layout Standard
32898
32899
32900 \size footnotesize 
32901 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32902 \layout Standard
32903
32904
32905 \size footnotesize 
32906 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32907 \layout Standard
32908
32909
32910 \size footnotesize 
32911 Sample.c(15:20:54:0)preHeaderLbl1($13) :
32912 \layout Standard
32913
32914
32915 \size footnotesize 
32916 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32917 \layout Standard
32918
32919
32920 \size footnotesize 
32921 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32922 \layout Standard
32923
32924
32925 \size footnotesize 
32926 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32927 \layout Standard
32928
32929
32930 \size footnotesize 
32931 Sample.c(15:24:26:1)_forcond_0($4) :
32932 \layout Standard
32933
32934
32935 \size footnotesize 
32936 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
32937  < 0xa {short}
32938 \layout Standard
32939
32940
32941 \size footnotesize 
32942 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32943 \layout Standard
32944
32945
32946 \size footnotesize 
32947 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
32948  + ITemp21 [lr21:38]{short}[r4]
32949 \layout Standard
32950
32951
32952 \size footnotesize 
32953 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
32954  * 0x3 {short}
32955 \layout Standard
32956
32957
32958 \size footnotesize 
32959 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
32960  + iTemp15 [lr29:30]{short}[r1]
32961 \layout Standard
32962
32963
32964 \size footnotesize 
32965 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
32966  r0]- 0x3 {short}
32967 \layout Standard
32968
32969
32970 \size footnotesize 
32971 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
32972 int}[r7 r0]
32973 \layout Standard
32974
32975
32976 \size footnotesize 
32977 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
32978  + 0x1 {short}
32979 \layout Standard
32980
32981
32982 \size footnotesize 
32983 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
32984  r6]- 0x1 {short}
32985 \layout Standard
32986
32987
32988 \size footnotesize 
32989 Sample.c(19:38:47:1) goto _forcond_0($4)
32990 \layout Standard
32991
32992
32993 \size footnotesize 
32994 Sample.c(19:39:48:0)_forbreak_0($7) :
32995 \layout Standard
32996
32997
32998 \size footnotesize 
32999 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
33000  + ITemp11 [lr19:40]{short}[r3]
33001 \layout Standard
33002
33003
33004 \size footnotesize 
33005 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
33006 \layout Standard
33007
33008
33009 \size footnotesize 
33010 Sample.c(20:42:51:0)_return($8) :
33011 \layout Standard
33012
33013
33014 \size footnotesize 
33015 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
33016 \size default 
33017
33018 \newline 
33019
33020 \newline 
33021 Finally the code generated for this function:
33022 \newline 
33023
33024 \layout Standard
33025
33026
33027 \size footnotesize 
33028 .area DSEG (DATA)
33029 \layout Standard
33030
33031
33032 \size footnotesize 
33033 _p::
33034 \layout Standard
33035
33036
33037 \size footnotesize 
33038 \SpecialChar ~
33039 \SpecialChar ~
33040 .ds 2
33041 \layout Standard
33042
33043
33044 \size footnotesize 
33045 _gint::
33046 \layout Standard
33047
33048
33049 \size footnotesize 
33050 \SpecialChar ~
33051 \SpecialChar ~
33052 .ds 2
33053 \layout Standard
33054
33055
33056 \size footnotesize 
33057 ; sample.c 5
33058 \layout Standard
33059
33060
33061 \size footnotesize 
33062 ; ----------------------------------------------
33063 \layout Standard
33064
33065
33066 \size footnotesize 
33067 ; function function
33068 \layout Standard
33069
33070
33071 \size footnotesize 
33072 ; ----------------------------------------------
33073 \layout Standard
33074
33075
33076 \size footnotesize 
33077 _function:
33078 \layout Standard
33079
33080
33081 \size footnotesize 
33082 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
33083 \layout Standard
33084
33085
33086 \size footnotesize 
33087 \SpecialChar ~
33088 \SpecialChar ~
33089 mov r2,dpl
33090 \layout Standard
33091
33092
33093 \size footnotesize 
33094 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
33095 \layout Standard
33096
33097
33098 \size footnotesize 
33099 \SpecialChar ~
33100 \SpecialChar ~
33101 mov ar0,r2
33102 \layout Standard
33103
33104
33105 \size footnotesize 
33106 ;_whilecontinue_0($1) :
33107 \layout Standard
33108
33109
33110 \size footnotesize 
33111 00101$:
33112 \layout Standard
33113
33114
33115 \size footnotesize 
33116 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
33117 \layout Standard
33118
33119
33120 \size footnotesize 
33121 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
33122 \layout Standard
33123
33124
33125 \size footnotesize 
33126 \SpecialChar ~
33127 \SpecialChar ~
33128 mov ar2,@r0
33129 \layout Standard
33130
33131
33132 \size footnotesize 
33133 \SpecialChar ~
33134 \SpecialChar ~
33135 inc r0
33136 \layout Standard
33137
33138
33139 \size footnotesize 
33140 \SpecialChar ~
33141 \SpecialChar ~
33142 mov ar3,@r0
33143 \layout Standard
33144
33145
33146 \size footnotesize 
33147 \SpecialChar ~
33148 \SpecialChar ~
33149 dec r0
33150 \layout Standard
33151
33152
33153 \size footnotesize 
33154 \SpecialChar ~
33155 \SpecialChar ~
33156 mov a,r2
33157 \layout Standard
33158
33159
33160 \size footnotesize 
33161 \SpecialChar ~
33162 \SpecialChar ~
33163 orl a,r3
33164 \layout Standard
33165
33166
33167 \size footnotesize 
33168 \SpecialChar ~
33169 \SpecialChar ~
33170 jz 00103$
33171 \layout Standard
33172
33173
33174 \size footnotesize 
33175 00114$:
33176 \layout Standard
33177
33178
33179 \size footnotesize 
33180 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
33181 \layout Standard
33182
33183
33184 \size footnotesize 
33185 \SpecialChar ~
33186 \SpecialChar ~
33187 mov dpl,_p
33188 \layout Standard
33189
33190
33191 \size footnotesize 
33192 \SpecialChar ~
33193 \SpecialChar ~
33194 mov dph,(_p + 1)
33195 \layout Standard
33196
33197
33198 \size footnotesize 
33199 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
33200 \layout Standard
33201
33202
33203 \size footnotesize 
33204 \SpecialChar ~
33205 \SpecialChar ~
33206 mov a,#0x02
33207 \layout Standard
33208
33209
33210 \size footnotesize 
33211 \SpecialChar ~
33212 \SpecialChar ~
33213 add a,_p
33214 \layout Standard
33215
33216
33217 \size footnotesize 
33218 \SpecialChar ~
33219 \SpecialChar ~
33220 mov _p,a
33221 \layout Standard
33222
33223
33224 \size footnotesize 
33225 \SpecialChar ~
33226 \SpecialChar ~
33227 clr a
33228 \layout Standard
33229
33230
33231 \size footnotesize 
33232 \SpecialChar ~
33233 \SpecialChar ~
33234 addc a,(_p + 1)
33235 \layout Standard
33236
33237
33238 \size footnotesize 
33239 \SpecialChar ~
33240 \SpecialChar ~
33241 mov (_p + 1),a
33242 \layout Standard
33243
33244
33245 \size footnotesize 
33246 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
33247 \layout Standard
33248
33249
33250 \size footnotesize 
33251 \SpecialChar ~
33252 \SpecialChar ~
33253 movx a,@dptr
33254 \layout Standard
33255
33256
33257 \size footnotesize 
33258 \SpecialChar ~
33259 \SpecialChar ~
33260 mov r2,a
33261 \layout Standard
33262
33263
33264 \size footnotesize 
33265 \SpecialChar ~
33266 \SpecialChar ~
33267 inc dptr
33268 \layout Standard
33269
33270
33271 \size footnotesize 
33272 \SpecialChar ~
33273 \SpecialChar ~
33274 movx a,@dptr
33275 \layout Standard
33276
33277
33278 \size footnotesize 
33279 \SpecialChar ~
33280 \SpecialChar ~
33281 mov r3,a
33282 \layout Standard
33283
33284
33285 \size footnotesize 
33286 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
33287 \layout Standard
33288
33289
33290 \size footnotesize 
33291 \SpecialChar ~
33292 \SpecialChar ~
33293 mov @r0,ar2
33294 \layout Standard
33295
33296
33297 \size footnotesize 
33298 \SpecialChar ~
33299 \SpecialChar ~
33300 inc r0
33301 \layout Standard
33302
33303
33304 \size footnotesize 
33305 \SpecialChar ~
33306 \SpecialChar ~
33307 mov @r0,ar3
33308 \layout Standard
33309
33310
33311 \size footnotesize 
33312 ; iTemp6 [lr5:16]{_near * int}[r0] = 
33313 \layout Standard
33314
33315
33316 \size footnotesize 
33317 ; iTemp6 [lr5:16]{_near * int}[r0] + 
33318 \layout Standard
33319
33320
33321 \size footnotesize 
33322 ; 0x2 {short}
33323 \layout Standard
33324
33325
33326 \size footnotesize 
33327 \SpecialChar ~
33328 \SpecialChar ~
33329 inc r0
33330 \layout Standard
33331
33332
33333 \size footnotesize 
33334 ; goto _whilecontinue_0($1)
33335 \layout Standard
33336
33337
33338 \size footnotesize 
33339 \SpecialChar ~
33340 \SpecialChar ~
33341 sjmp 00101$
33342 \layout Standard
33343
33344
33345 \size footnotesize 
33346 ; _whilebreak_0($3) :
33347 \layout Standard
33348
33349
33350 \size footnotesize 
33351 00103$:
33352 \layout Standard
33353
33354
33355 \size footnotesize 
33356 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
33357 \layout Standard
33358
33359
33360 \size footnotesize 
33361 \SpecialChar ~
33362 \SpecialChar ~
33363 mov r2,#0x00
33364 \layout Standard
33365
33366
33367 \size footnotesize 
33368 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
33369 \layout Standard
33370
33371
33372 \size footnotesize 
33373 \SpecialChar ~
33374 \SpecialChar ~
33375 mov r3,#0x00
33376 \layout Standard
33377
33378
33379 \size footnotesize 
33380 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
33381 \layout Standard
33382
33383
33384 \size footnotesize 
33385 \SpecialChar ~
33386 \SpecialChar ~
33387 mov r4,#0x00
33388 \layout Standard
33389
33390
33391 \size footnotesize 
33392 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
33393 \layout Standard
33394
33395
33396 \size footnotesize 
33397 \SpecialChar ~
33398 \SpecialChar ~
33399 mov r5,#0x0A
33400 \layout Standard
33401
33402
33403 \size footnotesize 
33404 \SpecialChar ~
33405 \SpecialChar ~
33406 mov r6,#0x00
33407 \layout Standard
33408
33409
33410 \size footnotesize 
33411 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
33412 \layout Standard
33413
33414
33415 \size footnotesize 
33416 \SpecialChar ~
33417 \SpecialChar ~
33418 mov r7,#0x1E
33419 \layout Standard
33420
33421
33422 \size footnotesize 
33423 \SpecialChar ~
33424 \SpecialChar ~
33425 mov r0,#0x00
33426 \layout Standard
33427
33428
33429 \size footnotesize 
33430 ; _forcond_0($4) :
33431 \layout Standard
33432
33433
33434 \size footnotesize 
33435 00104$:
33436 \layout Standard
33437
33438
33439 \size footnotesize 
33440 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
33441 \layout Standard
33442
33443
33444 \size footnotesize 
33445 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
33446 \layout Standard
33447
33448
33449 \size footnotesize 
33450 \SpecialChar ~
33451 \SpecialChar ~
33452 clr c
33453 \layout Standard
33454
33455
33456 \size footnotesize 
33457 \SpecialChar ~
33458 \SpecialChar ~
33459 mov a,r4
33460 \layout Standard
33461
33462
33463 \size footnotesize 
33464 \SpecialChar ~
33465 \SpecialChar ~
33466 xrl a,#0x80
33467 \layout Standard
33468
33469
33470 \size footnotesize 
33471 \SpecialChar ~
33472 \SpecialChar ~
33473 subb a,#0x8a
33474 \layout Standard
33475
33476
33477 \size footnotesize 
33478 \SpecialChar ~
33479 \SpecialChar ~
33480 jnc 00107$
33481 \layout Standard
33482
33483
33484 \size footnotesize 
33485 00115$:
33486 \layout Standard
33487
33488
33489 \size footnotesize 
33490 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
33491 \layout Standard
33492
33493
33494 \size footnotesize 
33495 ; iTemp21 [lr21:38]{short}[r4]
33496 \layout Standard
33497
33498
33499 \size footnotesize 
33500 \SpecialChar ~
33501 \SpecialChar ~
33502 mov a,r4
33503 \layout Standard
33504
33505
33506 \size footnotesize 
33507 \SpecialChar ~
33508 \SpecialChar ~
33509 add a,r2
33510 \layout Standard
33511
33512
33513 \size footnotesize 
33514 \SpecialChar ~
33515 \SpecialChar ~
33516 mov r2,a
33517 \layout Standard
33518
33519
33520 \size footnotesize 
33521 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
33522 \layout Standard
33523
33524
33525 \size footnotesize 
33526 \SpecialChar ~
33527 \SpecialChar ~
33528 mov b,#0x03
33529 \layout Standard
33530
33531
33532 \size footnotesize 
33533 \SpecialChar ~
33534 \SpecialChar ~
33535 mov a,r4
33536 \layout Standard
33537
33538
33539 \size footnotesize 
33540 \SpecialChar ~
33541 \SpecialChar ~
33542 mul ab
33543 \layout Standard
33544
33545
33546 \size footnotesize 
33547 \SpecialChar ~
33548 \SpecialChar ~
33549 mov r1,a
33550 \layout Standard
33551
33552
33553 \size footnotesize 
33554 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
33555 \layout Standard
33556
33557
33558 \size footnotesize 
33559 ; iTemp15 [lr29:30]{short}[r1]
33560 \layout Standard
33561
33562
33563 \size footnotesize 
33564 \SpecialChar ~
33565 \SpecialChar ~
33566 add a,r3
33567 \layout Standard
33568
33569
33570 \size footnotesize 
33571 \SpecialChar ~
33572 \SpecialChar ~
33573 mov r3,a
33574 \layout Standard
33575
33576
33577 \size footnotesize 
33578 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
33579 \layout Standard
33580
33581
33582 \size footnotesize 
33583 \SpecialChar ~
33584 \SpecialChar ~
33585 mov a,r7
33586 \layout Standard
33587
33588
33589 \size footnotesize 
33590 \SpecialChar ~
33591 \SpecialChar ~
33592 add a,#0xfd
33593 \layout Standard
33594
33595
33596 \size footnotesize 
33597 \SpecialChar ~
33598 \SpecialChar ~
33599 mov r7,a
33600 \layout Standard
33601
33602
33603 \size footnotesize 
33604 \SpecialChar ~
33605 \SpecialChar ~
33606 mov a,r0
33607 \layout Standard
33608
33609
33610 \size footnotesize 
33611 \SpecialChar ~
33612 \SpecialChar ~
33613 addc a,#0xff
33614 \layout Standard
33615
33616
33617 \size footnotesize 
33618 \SpecialChar ~
33619 \SpecialChar ~
33620 mov r0,a
33621 \layout Standard
33622
33623
33624 \size footnotesize 
33625 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
33626 \layout Standard
33627
33628
33629 \size footnotesize 
33630 \SpecialChar ~
33631 \SpecialChar ~
33632 mov a,r7
33633 \layout Standard
33634
33635
33636 \size footnotesize 
33637 \SpecialChar ~
33638 \SpecialChar ~
33639 add a,_gint
33640 \layout Standard
33641
33642
33643 \size footnotesize 
33644 \SpecialChar ~
33645 \SpecialChar ~
33646 mov _gint,a
33647 \layout Standard
33648
33649
33650 \size footnotesize 
33651 \SpecialChar ~
33652 \SpecialChar ~
33653 mov a,r0
33654 \layout Standard
33655
33656
33657 \size footnotesize 
33658 \SpecialChar ~
33659 \SpecialChar ~
33660 addc a,(_gint + 1)
33661 \layout Standard
33662
33663
33664 \size footnotesize 
33665 \SpecialChar ~
33666 \SpecialChar ~
33667 mov (_gint + 1),a
33668 \layout Standard
33669
33670
33671 \size footnotesize 
33672 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
33673 \layout Standard
33674
33675
33676 \size footnotesize 
33677 \SpecialChar ~
33678 \SpecialChar ~
33679 inc r4
33680 \layout Standard
33681
33682
33683 \size footnotesize 
33684 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
33685 \layout Standard
33686
33687
33688 \size footnotesize 
33689 \SpecialChar ~
33690 \SpecialChar ~
33691 dec r5
33692 \layout Standard
33693
33694
33695 \size footnotesize 
33696 \SpecialChar ~
33697 \SpecialChar ~
33698 cjne r5,#0xff,00104$
33699 \layout Standard
33700
33701
33702 \size footnotesize 
33703 \SpecialChar ~
33704 \SpecialChar ~
33705 dec r6
33706 \layout Standard
33707
33708
33709 \size footnotesize 
33710 ; goto _forcond_0($4)
33711 \layout Standard
33712
33713
33714 \size footnotesize 
33715 \SpecialChar ~
33716 \SpecialChar ~
33717 sjmp 00104$
33718 \layout Standard
33719
33720
33721 \size footnotesize 
33722 ; _forbreak_0($7) :
33723 \layout Standard
33724
33725
33726 \size footnotesize 
33727 00107$:
33728 \layout Standard
33729
33730
33731 \size footnotesize 
33732 ; ret iTemp24 [lr40:41]{short}
33733 \layout Standard
33734
33735
33736 \size footnotesize 
33737 \SpecialChar ~
33738 \SpecialChar ~
33739 mov a,r3
33740 \layout Standard
33741
33742
33743 \size footnotesize 
33744 \SpecialChar ~
33745 \SpecialChar ~
33746 add a,r2
33747 \layout Standard
33748
33749
33750 \size footnotesize 
33751 \SpecialChar ~
33752 \SpecialChar ~
33753 mov dpl,a
33754 \layout Standard
33755
33756
33757 \size footnotesize 
33758 ; _return($8) :
33759 \layout Standard
33760
33761
33762 \size footnotesize 
33763 00108$:
33764 \layout Standard
33765
33766
33767 \size footnotesize 
33768 \SpecialChar ~
33769 \SpecialChar ~
33770 ret
33771 \newline 
33772
33773 \layout Section
33774
33775 A few words about basic block successors, predecessors and dominators
33776 \layout Standard
33777
33778 Successors are basic blocks
33779 \begin_inset LatexCommand \index{Basic blocks}
33780
33781 \end_inset 
33782
33783  that might execute after this basic block.
33784 \newline 
33785 Predecessors are basic blocks that might execute before reaching this basic
33786  block.
33787 \newline 
33788 Dominators are basic blocks that WILL execute before reaching this basic
33789  block.
33790 \newline 
33791
33792 \layout Standard
33793
33794 [basic block 1]
33795 \layout Standard
33796
33797 if (something)
33798 \layout Standard
33799
33800 \SpecialChar ~
33801 \SpecialChar ~
33802 \SpecialChar ~
33803 \SpecialChar ~
33804 [basic block 2]
33805 \layout Standard
33806
33807 else
33808 \layout Standard
33809
33810 \SpecialChar ~
33811 \SpecialChar ~
33812 \SpecialChar ~
33813 \SpecialChar ~
33814 [basic block 3]
33815 \layout Standard
33816
33817 [basic block 4]
33818 \newline 
33819
33820 \layout Standard
33821
33822 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
33823 \layout Standard
33824
33825 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
33826 \layout Standard
33827
33828 c) domVect of [BB4] = BB1 ...
33829  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
33830  was executed.
33831 \layout Chapter
33832
33833 Acknowledgments
33834 \layout Standard
33835
33836
33837 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
33838
33839 \end_inset 
33840
33841
33842 \newline 
33843
33844 \newline 
33845
33846 \emph on 
33847 Thanks to all the other volunteer developers who have helped with coding,
33848  testing, web-page creation, distribution sets, etc.
33849  You know who you are :-)
33850 \emph default 
33851
33852 \newline 
33853
33854 \newline 
33855
33856 \emph on 
33857 Also thanks to Sourceforge 
33858 \begin_inset LatexCommand \url{http://www.sf.net}
33859
33860 \end_inset 
33861
33862  which has hosted the project since 1999 and donates significant download
33863  bandwidth and probably more than 
33864 \begin_inset ERT
33865 status Collapsed
33866
33867 \layout Standard
33868 $10^{13}$
33869 \end_inset 
33870
33871 CPU cycles per day.
33872 \newline 
33873  
33874 \begin_inset Note
33875 collapsed false
33876
33877 \layout Standard
33878
33879 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
33880  minutes for (configure+make+regression test), and there is (i386, amd64,
33881  alpha, ppc64, (mingw32), sparc, macosx).
33882  
33883 \end_inset 
33884
33885
33886 \layout Standard
33887
33888 This document was initially written by Sandeep Dutta
33889 \layout Standard
33890
33891 All product names mentioned herein may be trademarks
33892 \begin_inset LatexCommand \index{Trademarks}
33893
33894 \end_inset 
33895
33896  of their respective companies.
33897  
33898 \layout Section*
33899
33900 Alphabetical index
33901 \layout Standard
33902
33903 To avoid confusion, the installation and building options for SDCC itself
33904  (chapter 2) are not part of the index.
33905 \layout Standard
33906
33907
33908 \begin_inset LatexCommand \printindex{}
33909
33910 \end_inset 
33911
33912
33913 \the_end