* doc/sdccman.lyx: added the long missed iCode table "<where is figure II?>", added...
[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.2
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 \newline 
1063
1064 \layout List
1065 \labelwidthstring 00.00.0000
1066
1067 \SpecialChar ~
1068 \SpecialChar ~
1069 docdir environment variable, see table below
1070 \layout List
1071 \labelwidthstring 00.00.0000
1072
1073 \SpecialChar ~
1074 \SpecialChar ~
1075 include_dir_suffix environment variable, see table below
1076 \layout List
1077 \labelwidthstring 00.00.0000
1078
1079 \SpecialChar ~
1080 \SpecialChar ~
1081 lib_dir_suffix environment variable, see table below
1082 \layout List
1083 \labelwidthstring 00.00.0000
1084
1085 \SpecialChar ~
1086 \SpecialChar ~
1087 sdccconf_h_dir_separator environment variable, either / or 
1088 \backslash 
1089
1090 \backslash 
1091  makes sense here.
1092  This character will only be used in sdccconf.h; don't forget it's a C-header,
1093  therefore a double-backslash is needed there.
1094 \newline 
1095
1096 \layout List
1097 \labelwidthstring 00.00.0000
1098
1099 -
1100 \begin_inset ERT
1101 status Collapsed
1102
1103 \layout Standard
1104
1105 \backslash 
1106 /
1107 \end_inset 
1108
1109 -disable-mcs51-port Excludes the Intel mcs51 port
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-gbz80-port Excludes the Gameboy gbz80 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-z80-port Excludes the z80 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-avr-port Excludes the AVR 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-ds390-port Excludes the DS390 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-hc08-port Excludes the HC08 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-pic-port Excludes the PIC 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-xa51-port Excludes the XA51 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-ucsim Disables configuring and building of ucsim
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-device-lib Disables automatically building device libraries
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-packihx Disables building packihx
1250 \newline 
1251
1252 \layout List
1253 \labelwidthstring 00.00.0000
1254
1255 -
1256 \begin_inset ERT
1257 status Collapsed
1258
1259 \layout Standard
1260
1261 \backslash 
1262 /
1263 \end_inset 
1264
1265 -enable-doc Build pdf, html and txt files from the lyx sources
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-libgc Use the Bohem memory allocator.
1280  Lower runtime footprint.
1281 \layout Standard
1282
1283 Furthermore the environment variables CC, CFLAGS, ...
1284  the tools and their arguments can be influenced.
1285  Please see `configure -
1286 \begin_inset ERT
1287 status Collapsed
1288
1289 \layout Standard
1290
1291 \backslash 
1292 /
1293 \end_inset 
1294
1295 -help` and the man/info pages of `configure` for details.
1296 \newline 
1297
1298 \newline 
1299 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1300  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1301 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1302  At the moment it's not possible to change the default settings (it was
1303  simply never required).
1304 \newline 
1305
1306 \newline 
1307 These configure options are compiled into the binaries, and can only be
1308  changed by rerunning 'configure' and recompiling SDCC.
1309  The configure options are written in 
1310 \emph on 
1311 italics
1312 \emph default 
1313  to distinguish them from run time environment variables (see section search
1314  paths).
1315 \newline 
1316
1317 \newline 
1318 The settings for 
1319 \begin_inset Quotes sld
1320 \end_inset 
1321
1322 Win32 builds
1323 \begin_inset Quotes srd
1324 \end_inset 
1325
1326  are used by the SDCC team to build the official Win32 binaries.
1327  The SDCC team uses Mingw32 to build the official Windows binaries, because
1328  it's
1329 \layout Enumerate
1330
1331 open source, 
1332 \layout Enumerate
1333
1334 a gcc compiler and last but not least
1335 \layout Enumerate
1336
1337 the binaries can be built by cross compiling on Sourceforge's compile farm.
1338 \layout Standard
1339
1340 See the examples, how to pass the Win32 settings to 'configure'.
1341  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1342  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1343  for Win32.
1344 \newline 
1345
1346 \newline 
1347 These defaults are:
1348 \newline 
1349
1350 \layout Standard
1351 \align center 
1352
1353 \begin_inset  Tabular
1354 <lyxtabular version="3" rows="8" columns="3">
1355 <features>
1356 <column alignment="block" valignment="top" leftline="true" width="0in">
1357 <column alignment="block" valignment="top" leftline="true" width="0in">
1358 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1359 <row topline="true" bottomline="true">
1360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1361 \begin_inset Text
1362
1363 \layout Standard
1364
1365 Variable
1366 \end_inset 
1367 </cell>
1368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1369 \begin_inset Text
1370
1371 \layout Standard
1372
1373 default
1374 \end_inset 
1375 </cell>
1376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1377 \begin_inset Text
1378
1379 \layout Standard
1380
1381 Win32 builds
1382 \end_inset 
1383 </cell>
1384 </row>
1385 <row topline="true">
1386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1387 \begin_inset Text
1388
1389 \layout Standard
1390
1391
1392 \emph on 
1393 PREFIX
1394 \end_inset 
1395 </cell>
1396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1397 \begin_inset Text
1398
1399 \layout Standard
1400
1401 /usr/local
1402 \end_inset 
1403 </cell>
1404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1405 \begin_inset Text
1406
1407 \layout Standard
1408
1409
1410 \backslash 
1411 sdcc
1412 \end_inset 
1413 </cell>
1414 </row>
1415 <row topline="true">
1416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1417 \begin_inset Text
1418
1419 \layout Standard
1420
1421
1422 \emph on 
1423 EXEC_PREFIX
1424 \end_inset 
1425 </cell>
1426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1427 \begin_inset Text
1428
1429 \layout Standard
1430
1431
1432 \emph on 
1433 $PREFIX
1434 \end_inset 
1435 </cell>
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1437 \begin_inset Text
1438
1439 \layout Standard
1440
1441
1442 \emph on 
1443 $PREFIX
1444 \end_inset 
1445 </cell>
1446 </row>
1447 <row topline="true">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452
1453
1454 \emph on 
1455 BINDIR
1456 \end_inset 
1457 </cell>
1458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1459 \begin_inset Text
1460
1461 \layout Standard
1462
1463
1464 \emph on 
1465 $EXECPREFIX
1466 \emph default 
1467 /bin
1468 \end_inset 
1469 </cell>
1470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1471 \begin_inset Text
1472
1473 \layout Standard
1474
1475
1476 \emph on 
1477 $EXECPREFIX
1478 \emph default 
1479
1480 \backslash 
1481 bin
1482 \end_inset 
1483 </cell>
1484 </row>
1485 <row topline="true">
1486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1487 \begin_inset Text
1488
1489 \layout Standard
1490
1491
1492 \emph on 
1493 DATADIR
1494 \end_inset 
1495 </cell>
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501
1502 \emph on 
1503 $PREFIX
1504 \emph default 
1505 /share
1506 \end_inset 
1507 </cell>
1508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1509 \begin_inset Text
1510
1511 \layout Standard
1512
1513
1514 \emph on 
1515 $PREFIX
1516 \end_inset 
1517 </cell>
1518 </row>
1519 <row topline="true">
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1521 \begin_inset Text
1522
1523 \layout Standard
1524
1525
1526 \emph on 
1527 DOCDIR
1528 \end_inset 
1529 </cell>
1530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1531 \begin_inset Text
1532
1533 \layout Standard
1534
1535
1536 \emph on 
1537 $DATADIR
1538 \emph default 
1539 /sdcc/doc
1540 \end_inset 
1541 </cell>
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1543 \begin_inset Text
1544
1545 \layout Standard
1546
1547
1548 \emph on 
1549 $DATADIR
1550 \emph default 
1551
1552 \backslash 
1553 doc
1554 \end_inset 
1555 </cell>
1556 </row>
1557 <row topline="true">
1558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1559 \begin_inset Text
1560
1561 \layout Standard
1562
1563
1564 \emph on 
1565 INCLUDE_DIR_SUFFIX
1566 \end_inset 
1567 </cell>
1568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1569 \begin_inset Text
1570
1571 \layout Standard
1572
1573 sdcc/include
1574 \end_inset 
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581 include
1582 \end_inset 
1583 </cell>
1584 </row>
1585 <row topline="true" bottomline="true">
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1587 \begin_inset Text
1588
1589 \layout Standard
1590
1591
1592 \emph on 
1593 LIB_DIR_SUFFIX
1594 \end_inset 
1595 </cell>
1596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1597 \begin_inset Text
1598
1599 \layout Standard
1600
1601 sdcc/lib
1602 \end_inset 
1603 </cell>
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1605 \begin_inset Text
1606
1607 \layout Standard
1608
1609 lib
1610 \end_inset 
1611 </cell>
1612 </row>
1613 </lyxtabular>
1614
1615 \end_inset 
1616
1617
1618 \newline 
1619
1620 \layout Standard
1621 \noindent 
1622 'configure' also computes relative paths.
1623  This is needed for full relocatability of a binary package and to complete
1624  search paths (see section search paths below):
1625 \newline 
1626  
1627 \layout Standard
1628 \align center 
1629
1630 \begin_inset  Tabular
1631 <lyxtabular version="3" rows="4" columns="3">
1632 <features>
1633 <column alignment="block" valignment="top" leftline="true" width="0in">
1634 <column alignment="block" valignment="top" leftline="true" width="0in">
1635 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1636 <row topline="true" bottomline="true">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1638 \begin_inset Text
1639
1640 \layout Standard
1641
1642 Variable (computed)
1643 \end_inset 
1644 </cell>
1645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1646 \begin_inset Text
1647
1648 \layout Standard
1649
1650 default
1651 \end_inset 
1652 </cell>
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1654 \begin_inset Text
1655
1656 \layout Standard
1657
1658 Win32 builds
1659 \end_inset 
1660 </cell>
1661 </row>
1662 <row topline="true" bottomline="true">
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1664 \begin_inset Text
1665
1666 \layout Standard
1667
1668
1669 \emph on 
1670 BIN2DATA_DIR
1671 \end_inset 
1672 </cell>
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1674 \begin_inset Text
1675
1676 \layout Standard
1677
1678 ../share
1679 \end_inset 
1680 </cell>
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1682 \begin_inset Text
1683
1684 \layout Standard
1685
1686 ..
1687 \end_inset 
1688 </cell>
1689 </row>
1690 <row bottomline="true">
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 \begin_inset Text
1693
1694 \layout Standard
1695
1696
1697 \emph on 
1698 PREFIX2BIN_DIR
1699 \end_inset 
1700 </cell>
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \layout Standard
1705
1706 bin
1707 \end_inset 
1708 </cell>
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713
1714 bin
1715 \end_inset 
1716 </cell>
1717 </row>
1718 <row bottomline="true">
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_inset Text
1721
1722 \layout Standard
1723
1724
1725 \emph on 
1726 PREFIX2DATA_DIR
1727 \end_inset 
1728 </cell>
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1730 \begin_inset Text
1731
1732 \layout Standard
1733
1734 share/sdcc
1735 \end_inset 
1736 </cell>
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1738 \begin_inset Text
1739
1740 \layout Standard
1741
1742 \end_inset 
1743 </cell>
1744 </row>
1745 </lyxtabular>
1746
1747 \end_inset 
1748
1749
1750 \newline 
1751
1752 \layout Standard
1753 \noindent 
1754 Examples:
1755 \layout LyX-Code
1756
1757 ./configure
1758 \newline 
1759 ./configure -
1760 \begin_inset ERT
1761 status Collapsed
1762
1763 \layout Standard
1764
1765 \backslash 
1766 /
1767 \end_inset 
1768
1769 -prefix=
1770 \begin_inset Quotes srd
1771 \end_inset 
1772
1773 /usr/bin
1774 \begin_inset Quotes srd
1775 \end_inset 
1776
1777  -
1778 \begin_inset ERT
1779 status Collapsed
1780
1781 \layout Standard
1782
1783 \backslash 
1784 /
1785 \end_inset 
1786
1787 -datadir=
1788 \begin_inset Quotes srd
1789 \end_inset 
1790
1791 /usr/share
1792 \begin_inset Quotes srd
1793 \end_inset 
1794
1795
1796 \newline 
1797 ./configure -
1798 \begin_inset ERT
1799 status Collapsed
1800
1801 \layout Standard
1802
1803 \backslash 
1804 /
1805 \end_inset 
1806
1807 -disable-avr-port -
1808 \begin_inset ERT
1809 status Collapsed
1810
1811 \layout Standard
1812
1813 \backslash 
1814 /
1815 \end_inset 
1816
1817 -disable-xa51-port
1818 \layout Standard
1819
1820 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1821 32'):
1822 \layout LyX-Code
1823
1824 ./configure 
1825 \backslash 
1826
1827 \newline 
1828 CC=
1829 \begin_inset Quotes srd
1830 \end_inset 
1831
1832 i586-mingw32msvc-gcc
1833 \begin_inset Quotes srd
1834 \end_inset 
1835
1836  CXX=
1837 \begin_inset Quotes srd
1838 \end_inset 
1839
1840 i586-mingw32msvc-g++
1841 \begin_inset Quotes srd
1842 \end_inset 
1843
1844  
1845 \backslash 
1846  
1847 \newline 
1848 RANLIB=
1849 \begin_inset Quotes srd
1850 \end_inset 
1851
1852 i586-mingw32msvc-ranlib
1853 \begin_inset Quotes srd
1854 \end_inset 
1855
1856  
1857 \backslash 
1858
1859 \newline 
1860 STRIP=
1861 \begin_inset Quotes srd
1862 \end_inset 
1863
1864 i586-mingw32msvc-strip
1865 \begin_inset Quotes srd
1866 \end_inset 
1867
1868  
1869 \backslash 
1870
1871 \newline 
1872 -
1873 \begin_inset ERT
1874 status Collapsed
1875
1876 \layout Standard
1877
1878 \backslash 
1879 /
1880 \end_inset 
1881
1882 -prefix=
1883 \begin_inset Quotes srd
1884 \end_inset 
1885
1886 /sdcc
1887 \begin_inset Quotes srd
1888 \end_inset 
1889
1890  
1891 \backslash 
1892
1893 \newline 
1894 -
1895 \begin_inset ERT
1896 status Collapsed
1897
1898 \layout Standard
1899
1900 \backslash 
1901 /
1902 \end_inset 
1903
1904 -datadir=
1905 \begin_inset Quotes srd
1906 \end_inset 
1907
1908 /sdcc
1909 \begin_inset Quotes srd
1910 \end_inset 
1911
1912  
1913 \backslash 
1914
1915 \newline 
1916 docdir=
1917 \begin_inset Quotes srd
1918 \end_inset 
1919
1920 /sdcc/doc
1921 \begin_inset Quotes srd
1922 \end_inset 
1923
1924  
1925 \backslash 
1926
1927 \newline 
1928 include_dir_suffix=
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932 include
1933 \begin_inset Quotes srd
1934 \end_inset 
1935
1936  
1937 \backslash 
1938
1939 \newline 
1940 lib_dir_suffix=
1941 \begin_inset Quotes srd
1942 \end_inset 
1943
1944 lib
1945 \begin_inset Quotes srd
1946 \end_inset 
1947
1948  
1949 \backslash 
1950
1951 \newline 
1952 sdccconf_h_dir_separator=
1953 \begin_inset Quotes srd
1954 \end_inset 
1955
1956
1957 \backslash 
1958
1959 \backslash 
1960
1961 \backslash 
1962
1963 \backslash 
1964
1965 \begin_inset Quotes srd
1966 \end_inset 
1967
1968  
1969 \backslash 
1970
1971 \newline 
1972 -
1973 \begin_inset ERT
1974 status Collapsed
1975
1976 \layout Standard
1977
1978 \backslash 
1979 /
1980 \end_inset 
1981
1982 -disable-device-lib
1983 \backslash 
1984
1985 \newline 
1986 -
1987 \begin_inset ERT
1988 status Collapsed
1989
1990 \layout Standard
1991
1992 \backslash 
1993 /
1994 \end_inset 
1995
1996 -host=i586-mingw32msvc
1997 \backslash 
1998
1999 \newline 
2000 -
2001 \begin_inset ERT
2002 status Collapsed
2003
2004 \layout Standard
2005
2006 \backslash 
2007 /
2008 \end_inset 
2009
2010 -build=unknown-unknown-linux-gnu
2011 \layout Standard
2012
2013 To 
2014 \begin_inset Quotes sld
2015 \end_inset 
2016
2017 cross
2018 \begin_inset Quotes srd
2019 \end_inset 
2020
2021 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2022 ):
2023 \layout LyX-Code
2024
2025 ./configure -C 
2026 \backslash 
2027
2028 \newline 
2029 -
2030 \begin_inset ERT
2031 status Collapsed
2032
2033 \layout Standard
2034
2035 \backslash 
2036 /
2037 \end_inset 
2038
2039 -prefix=
2040 \begin_inset Quotes srd
2041 \end_inset 
2042
2043 /sdcc
2044 \begin_inset Quotes srd
2045 \end_inset 
2046
2047  
2048 \backslash 
2049
2050 \newline 
2051 -
2052 \begin_inset ERT
2053 status Collapsed
2054
2055 \layout Standard
2056
2057 \backslash 
2058 /
2059 \end_inset 
2060
2061 -datadir=
2062 \begin_inset Quotes srd
2063 \end_inset 
2064
2065 /sdcc
2066 \begin_inset Quotes srd
2067 \end_inset 
2068
2069  
2070 \backslash 
2071
2072 \newline 
2073 docdir=
2074 \begin_inset Quotes srd
2075 \end_inset 
2076
2077 /sdcc/doc
2078 \begin_inset Quotes srd
2079 \end_inset 
2080
2081  
2082 \backslash 
2083  
2084 \newline 
2085 include_dir_suffix=
2086 \begin_inset Quotes srd
2087 \end_inset 
2088
2089 include
2090 \begin_inset Quotes srd
2091 \end_inset 
2092
2093  
2094 \backslash 
2095
2096 \newline 
2097 lib_dir_suffix=
2098 \begin_inset Quotes srd
2099 \end_inset 
2100
2101 lib
2102 \begin_inset Quotes srd
2103 \end_inset 
2104
2105  
2106 \backslash 
2107
2108 \newline 
2109 sdccconf_h_dir_separator=
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113
2114 \backslash 
2115
2116 \backslash 
2117
2118 \backslash 
2119
2120 \backslash 
2121
2122 \begin_inset Quotes srd
2123 \end_inset 
2124
2125  
2126 \backslash 
2127
2128 \newline 
2129 CC=
2130 \begin_inset Quotes srd
2131 \end_inset 
2132
2133 gcc -mno-cygwin
2134 \begin_inset Quotes srd
2135 \end_inset 
2136
2137  
2138 \backslash 
2139
2140 \newline 
2141 CXX=
2142 \begin_inset Quotes srd
2143 \end_inset 
2144
2145 g++ -mno-cygwin
2146 \begin_inset Quotes srd
2147 \end_inset 
2148
2149  
2150 \layout Standard
2151
2152 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2153  The option '-
2154 \begin_inset ERT
2155 status Collapsed
2156
2157 \layout Standard
2158
2159 \backslash 
2160 /
2161 \end_inset 
2162
2163 -C' turns on caching, which gives a little bit extra speed.
2164  However if options are changed, it can be necessary to delete the config.cache
2165  file.
2166 \layout Section
2167
2168 Install paths
2169 \begin_inset LatexCommand \label{sub:Install-paths}
2170
2171 \end_inset 
2172
2173
2174 \begin_inset LatexCommand \index{Install paths}
2175
2176 \end_inset 
2177
2178
2179 \layout Standard
2180 \added_space_top medskip \align center 
2181
2182 \begin_inset  Tabular
2183 <lyxtabular version="3" rows="5" columns="4">
2184 <features>
2185 <column alignment="left" valignment="top" leftline="true" width="0">
2186 <column alignment="left" valignment="top" leftline="true" width="0">
2187 <column alignment="left" valignment="top" leftline="true" width="0">
2188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2189 <row topline="true" bottomline="true">
2190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2191 \begin_inset Text
2192
2193 \layout Standard
2194
2195
2196 \series bold 
2197 Description
2198 \end_inset 
2199 </cell>
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2201 \begin_inset Text
2202
2203 \layout Standard
2204
2205
2206 \series bold 
2207 Path
2208 \end_inset 
2209 </cell>
2210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2211 \begin_inset Text
2212
2213 \layout Standard
2214
2215
2216 \series bold 
2217 Default
2218 \end_inset 
2219 </cell>
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2221 \begin_inset Text
2222
2223 \layout Standard
2224
2225
2226 \series bold 
2227 Win32 builds
2228 \end_inset 
2229 </cell>
2230 </row>
2231 <row topline="true">
2232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2233 \begin_inset Text
2234
2235 \layout Standard
2236
2237 Binary files*
2238 \end_inset 
2239 </cell>
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2241 \begin_inset Text
2242
2243 \layout Standard
2244
2245
2246 \emph on 
2247 $EXEC_PREFIX
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 /usr/local/bin
2256 \end_inset 
2257 </cell>
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2259 \begin_inset Text
2260
2261 \layout Standard
2262
2263
2264 \backslash 
2265 sdcc
2266 \backslash 
2267 bin
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 Include files
2278 \end_inset 
2279 </cell>
2280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2281 \begin_inset Text
2282
2283 \layout Standard
2284
2285
2286 \emph on 
2287 $DATADIR/ $INCLUDE_DIR_SUFFIX
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 /usr/local/share/sdcc/include
2296 \end_inset 
2297 </cell>
2298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2299 \begin_inset Text
2300
2301 \layout Standard
2302
2303
2304 \backslash 
2305 sdcc
2306 \backslash 
2307 include
2308 \end_inset 
2309 </cell>
2310 </row>
2311 <row topline="true">
2312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2313 \begin_inset Text
2314
2315 \layout Standard
2316
2317 Library file**
2318 \end_inset 
2319 </cell>
2320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2321 \begin_inset Text
2322
2323 \layout Standard
2324
2325
2326 \emph on 
2327 $DATADIR/$LIB_DIR_SUFFIX
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 /usr/local/share/sdcc/lib
2336 \end_inset 
2337 </cell>
2338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2339 \begin_inset Text
2340
2341 \layout Standard
2342
2343
2344 \backslash 
2345 sdcc
2346 \backslash 
2347 lib
2348 \end_inset 
2349 </cell>
2350 </row>
2351 <row topline="true" bottomline="true">
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2353 \begin_inset Text
2354
2355 \layout Standard
2356
2357 Documentation
2358 \end_inset 
2359 </cell>
2360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2361 \begin_inset Text
2362
2363 \layout Standard
2364
2365
2366 \emph on 
2367 $DOCDIR
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 /usr/local/share/sdcc/doc
2376 \end_inset 
2377 </cell>
2378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2379 \begin_inset Text
2380
2381 \layout Standard
2382
2383
2384 \backslash 
2385 sdcc
2386 \backslash 
2387 doc
2388 \end_inset 
2389 </cell>
2390 </row>
2391 </lyxtabular>
2392
2393 \end_inset 
2394
2395
2396 \layout Verse
2397
2398
2399 \size footnotesize 
2400 *compiler, preprocessor, assembler, and linker
2401 \newline 
2402 **the 
2403 \shape italic 
2404 model
2405 \shape default 
2406  is auto-appended by the compiler, e.g.
2407  small, large, z80, ds390 etc
2408 \layout Standard
2409 \noindent 
2410 The install paths can still be changed during `make install` with e.g.:
2411 \layout LyX-Code
2412
2413 make install prefix=$(HOME)/local/sdcc
2414 \layout Standard
2415
2416 Of course this doesn't change the search paths compiled into the binaries.
2417 \newline 
2418
2419 \newline 
2420 Moreover the install path can be changed by defining DESTDIR
2421 \begin_inset LatexCommand \index{DESTDIR}
2422
2423 \end_inset 
2424
2425 :
2426 \layout LyX-Code
2427
2428 make install DESTDIR=$(HOME)/sdcc.rpm/
2429 \layout Standard
2430
2431 Please note that DESTDIR must have a trailing slash!
2432 \layout Section
2433
2434 Search Paths
2435 \begin_inset LatexCommand \label{sub:Search-Paths}
2436
2437 \end_inset 
2438
2439
2440 \begin_inset LatexCommand \index{Search path}
2441
2442 \end_inset 
2443
2444
2445 \layout Standard
2446
2447 Some search paths or parts of them are determined by configure variables
2448  (in 
2449 \emph on 
2450 italics
2451 \emph default 
2452 , see section above).
2453  Further search paths are determined by environment variables during runtime.
2454  
2455 \newline 
2456 The paths searched when running the compiler are as follows (the first catch
2457  wins):
2458 \newline 
2459
2460 \newline 
2461 1.
2462  Binary files (preprocessor, assembler and linker)
2463 \newline 
2464
2465 \layout Standard
2466 \align center 
2467
2468 \begin_inset  Tabular
2469 <lyxtabular version="3" rows="4" columns="3">
2470 <features>
2471 <column alignment="block" valignment="top" leftline="true" width="0in">
2472 <column alignment="block" valignment="top" leftline="true" width="0in">
2473 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2474 <row topline="true" bottomline="true">
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479
2480 Search path
2481 \end_inset 
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 default
2489 \end_inset 
2490 </cell>
2491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2492 \begin_inset Text
2493
2494 \layout Standard
2495
2496 Win32 builds
2497 \end_inset 
2498 </cell>
2499 </row>
2500 <row topline="true">
2501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2502 \begin_inset Text
2503
2504 \layout Standard
2505
2506 $SDCC_HOME/
2507 \emph on 
2508 $PPREFIX2BIN_DIR
2509 \end_inset 
2510 </cell>
2511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2512 \begin_inset Text
2513
2514 \layout Standard
2515
2516 $SDCC_HOME/bin
2517 \end_inset 
2518 </cell>
2519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2520 \begin_inset Text
2521
2522 \layout Standard
2523
2524 $SDCC_HOME
2525 \backslash 
2526 bin
2527 \end_inset 
2528 </cell>
2529 </row>
2530 <row topline="true">
2531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2532 \begin_inset Text
2533
2534 \layout Standard
2535
2536 Path of argv[0] (if available)
2537 \end_inset 
2538 </cell>
2539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2540 \begin_inset Text
2541
2542 \layout Standard
2543
2544 Path of argv[0]
2545 \end_inset 
2546 </cell>
2547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2548 \begin_inset Text
2549
2550 \layout Standard
2551
2552 Path of argv[0]
2553 \end_inset 
2554 </cell>
2555 </row>
2556 <row topline="true" bottomline="true">
2557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2558 \begin_inset Text
2559
2560 \layout Standard
2561
2562 $PATH
2563 \end_inset 
2564 </cell>
2565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2566 \begin_inset Text
2567
2568 \layout Standard
2569
2570 $PATH
2571 \end_inset 
2572 </cell>
2573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2574 \begin_inset Text
2575
2576 \layout Standard
2577
2578 $PATH
2579 \end_inset 
2580 </cell>
2581 </row>
2582 </lyxtabular>
2583
2584 \end_inset 
2585
2586  
2587 \newline 
2588
2589 \layout Standard
2590 \noindent 
2591 2.
2592  Include files
2593 \newline 
2594
2595 \layout Standard
2596 \align center 
2597
2598 \begin_inset  Tabular
2599 <lyxtabular version="3" rows="6" columns="3">
2600 <features>
2601 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2602 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2603 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2604 <row topline="true" bottomline="true">
2605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2606 \begin_inset Text
2607
2608 \layout Standard
2609
2610 Search path
2611 \end_inset 
2612 </cell>
2613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2614 \begin_inset Text
2615
2616 \layout Standard
2617
2618 default
2619 \end_inset 
2620 </cell>
2621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2622 \begin_inset Text
2623
2624 \layout Standard
2625
2626 Win32 builds
2627 \end_inset 
2628 </cell>
2629 </row>
2630 <row topline="true">
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2632 \begin_inset Text
2633
2634 \layout Standard
2635
2636 -
2637 \begin_inset ERT
2638 status Collapsed
2639
2640 \layout Standard
2641
2642 \backslash 
2643 /
2644 \end_inset 
2645
2646 -I dir
2647 \end_inset 
2648 </cell>
2649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_inset Text
2651
2652 \layout Standard
2653
2654 -
2655 \begin_inset ERT
2656 status Collapsed
2657
2658 \layout Standard
2659
2660 \backslash 
2661 /
2662 \end_inset 
2663
2664 -I dir
2665 \end_inset 
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \layout Standard
2671
2672 -
2673 \begin_inset ERT
2674 status Collapsed
2675
2676 \layout Standard
2677
2678 \backslash 
2679 /
2680 \end_inset 
2681
2682 -I dir
2683 \end_inset 
2684 </cell>
2685 </row>
2686 <row topline="true">
2687 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2688 \begin_inset Text
2689
2690 \layout Standard
2691
2692 $SDCC_INCLUDE
2693 \end_inset 
2694 </cell>
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2696 \begin_inset Text
2697
2698 \layout Standard
2699
2700 $SDCC_INCLUDE
2701 \end_inset 
2702 </cell>
2703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2704 \begin_inset Text
2705
2706 \layout Standard
2707
2708 $SDCC_INCLUDE
2709 \end_inset 
2710 </cell>
2711 </row>
2712 <row topline="true">
2713 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_inset Text
2715
2716 \layout Standard
2717
2718 $SDCC_HOME/
2719 \newline 
2720
2721 \emph on 
2722 $PREFIX2DATA_DIR/
2723 \newline 
2724 $INCLUDE_DIR_SUFFIX
2725 \end_inset 
2726 </cell>
2727 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2728 \begin_inset Text
2729
2730 \layout Standard
2731
2732 $SDCC_ HOME/
2733 \newline 
2734 share/sdcc/
2735 \newline 
2736 include
2737 \end_inset 
2738 </cell>
2739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2740 \begin_inset Text
2741
2742 \layout Standard
2743
2744 $SDCC_HOME
2745 \backslash 
2746 include
2747 \end_inset 
2748 </cell>
2749 </row>
2750 <row topline="true">
2751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_inset Text
2753
2754 \layout Standard
2755
2756 path(argv[0])/
2757 \newline 
2758
2759 \emph on 
2760 $BIN2DATADIR/
2761 \emph default 
2762
2763 \newline 
2764
2765 \emph on 
2766 $INCLUDE_DIR_SUFFIX
2767 \end_inset 
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \layout Standard
2773
2774 path(argv[0])/
2775 \newline 
2776 ../sdcc/include
2777 \newline 
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783 \SpecialChar ~
2784 \SpecialChar ~
2785 \SpecialChar ~
2786 \SpecialChar ~
2787 \SpecialChar ~
2788 \SpecialChar ~
2789 \SpecialChar ~
2790 \SpecialChar ~
2791 \SpecialChar ~
2792 \SpecialChar ~
2793 \SpecialChar ~
2794 \SpecialChar ~
2795 \SpecialChar ~
2796 \SpecialChar ~
2797 \SpecialChar ~
2798 \SpecialChar ~
2799 \SpecialChar ~
2800 \SpecialChar ~
2801 \SpecialChar ~
2802 \SpecialChar ~
2803 \SpecialChar ~
2804 \SpecialChar ~
2805 \SpecialChar ~
2806 \SpecialChar ~
2807 \SpecialChar ~
2808 \SpecialChar ~
2809 \SpecialChar ~
2810 \SpecialChar ~
2811 \SpecialChar ~
2812 \SpecialChar ~
2813 \SpecialChar ~
2814 \SpecialChar ~
2815 \SpecialChar ~
2816
2817 \end_inset 
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824 path(argv[0])
2825 \backslash 
2826 ..
2827 \backslash 
2828 include
2829 \end_inset 
2830 </cell>
2831 </row>
2832 <row topline="true" bottomline="true">
2833 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2834 \begin_inset Text
2835
2836 \layout Standard
2837
2838
2839 \emph on 
2840 $DATADIR/
2841 \emph default 
2842
2843 \newline 
2844
2845 \emph on 
2846 $INCLUDE_DIR_SUFFIX
2847 \end_inset 
2848 </cell>
2849 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2850 \begin_inset Text
2851
2852 \layout Standard
2853
2854 /usr/local/share/sdcc/
2855 \newline 
2856 include
2857 \end_inset 
2858 </cell>
2859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2860 \begin_inset Text
2861
2862 \layout Standard
2863
2864 (not on Win32)
2865 \end_inset 
2866 </cell>
2867 </row>
2868 </lyxtabular>
2869
2870 \end_inset 
2871
2872  
2873 \newline 
2874
2875 \layout Standard
2876 \noindent 
2877 The option -
2878 \begin_inset ERT
2879 status Collapsed
2880
2881 \layout Standard
2882
2883 \backslash 
2884 /
2885 \end_inset 
2886
2887 -nostdinc disables the last two search paths.
2888 \newline 
2889
2890 \newline 
2891 3.
2892  Library files 
2893 \newline 
2894
2895 \layout Standard
2896
2897 With the exception of 
2898 \begin_inset Quotes sld
2899 \end_inset 
2900
2901 -
2902 \begin_inset ERT
2903 status Collapsed
2904
2905 \layout Standard
2906
2907 \backslash 
2908 /
2909 \end_inset 
2910
2911 -L dir
2912 \begin_inset Quotes srd
2913 \end_inset 
2914
2915  the 
2916 \shape italic 
2917 model
2918 \shape default 
2919  is auto-appended by the compiler (e.g.
2920  small, large, z80, ds390 etc.).
2921  
2922 \newline 
2923
2924 \layout Standard
2925 \align center 
2926
2927 \begin_inset  Tabular
2928 <lyxtabular version="3" rows="6" columns="3">
2929 <features>
2930 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2931 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2932 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2933 <row topline="true" bottomline="true">
2934 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2935 \begin_inset Text
2936
2937 \layout Standard
2938
2939 Search path
2940 \end_inset 
2941 </cell>
2942 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \layout Standard
2946
2947 default
2948 \end_inset 
2949 </cell>
2950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2951 \begin_inset Text
2952
2953 \layout Standard
2954
2955 Win32 builds
2956 \end_inset 
2957 </cell>
2958 </row>
2959 <row topline="true">
2960 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_inset Text
2962
2963 \layout Standard
2964
2965 -
2966 \begin_inset ERT
2967 status Collapsed
2968
2969 \layout Standard
2970
2971 \backslash 
2972 /
2973 \end_inset 
2974
2975 -L dir
2976 \end_inset 
2977 </cell>
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2979 \begin_inset Text
2980
2981 \layout Standard
2982
2983 -
2984 \begin_inset ERT
2985 status Collapsed
2986
2987 \layout Standard
2988
2989 \backslash 
2990 /
2991 \end_inset 
2992
2993 -L dir
2994 \end_inset 
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \layout Standard
3000
3001 -
3002 \begin_inset ERT
3003 status Collapsed
3004
3005 \layout Standard
3006
3007 \backslash 
3008 /
3009 \end_inset 
3010
3011 -L dir
3012 \end_inset 
3013 </cell>
3014 </row>
3015 <row topline="true">
3016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_inset Text
3018
3019 \layout Standard
3020
3021 $SDCC_LIB/
3022 \newline 
3023
3024 \emph on 
3025 <model>
3026 \end_inset 
3027 </cell>
3028 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 $SDCC_LIB/
3034 \newline 
3035
3036 \emph on 
3037 <model>
3038 \end_inset 
3039 </cell>
3040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3041 \begin_inset Text
3042
3043 \layout Standard
3044
3045 $SDCC_LIB
3046 \backslash 
3047
3048 \newline 
3049
3050 \emph on 
3051 <model>
3052 \end_inset 
3053 </cell>
3054 </row>
3055 <row topline="true">
3056 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3057 \begin_inset Text
3058
3059 \layout Standard
3060
3061 $SDCC_HOME/
3062 \newline 
3063
3064 \emph on 
3065 $PREFIX2DATA_DIR/
3066 \newline 
3067 $LIB_DIR_SUFFIX/<model>
3068 \end_inset 
3069 </cell>
3070 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3071 \begin_inset Text
3072
3073 \layout Standard
3074
3075 $SDCC_HOME/
3076 \newline 
3077 share/sdcc/
3078 \newline 
3079 lib/
3080 \emph on 
3081 <model>
3082 \end_inset 
3083 </cell>
3084 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3085 \begin_inset Text
3086
3087 \layout Standard
3088
3089 $SDCC_HOME
3090 \backslash 
3091 lib
3092 \backslash 
3093
3094 \emph on 
3095
3096 \newline 
3097 <model>
3098 \end_inset 
3099 </cell>
3100 </row>
3101 <row topline="true">
3102 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_inset Text
3104
3105 \layout Standard
3106
3107 path(argv[0])/
3108 \newline 
3109
3110 \emph on 
3111 $BIN2DATADIR/
3112 \emph default 
3113
3114 \newline 
3115
3116 \emph on 
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 path(argv[0])/
3126 \newline 
3127 ../sdcc/lib/
3128 \emph on 
3129 <model>
3130 \newline 
3131 \SpecialChar ~
3132 \SpecialChar ~
3133 \SpecialChar ~
3134 \SpecialChar ~
3135 \SpecialChar ~
3136 \SpecialChar ~
3137 \SpecialChar ~
3138 \SpecialChar ~
3139 \SpecialChar ~
3140 \SpecialChar ~
3141 \SpecialChar ~
3142 \SpecialChar ~
3143 \SpecialChar ~
3144 \SpecialChar ~
3145 \SpecialChar ~
3146 \SpecialChar ~
3147 \SpecialChar ~
3148 \SpecialChar ~
3149 \SpecialChar ~
3150 \SpecialChar ~
3151 \SpecialChar ~
3152 \SpecialChar ~
3153 \SpecialChar ~
3154 \SpecialChar ~
3155 \SpecialChar ~
3156 \SpecialChar ~
3157 \SpecialChar ~
3158 \SpecialChar ~
3159 \SpecialChar ~
3160 \SpecialChar ~
3161 \SpecialChar ~
3162 \SpecialChar ~
3163 \SpecialChar ~
3164 \SpecialChar ~
3165 \SpecialChar ~
3166 \SpecialChar ~
3167 \SpecialChar ~
3168 \SpecialChar ~
3169 \SpecialChar ~
3170
3171 \end_inset 
3172 </cell>
3173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3174 \begin_inset Text
3175
3176 \layout Standard
3177
3178 path(argv[0])
3179 \backslash 
3180
3181 \newline 
3182 ..
3183 \backslash 
3184 lib
3185 \backslash 
3186
3187 \emph on 
3188 <model>
3189 \newline 
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 \SpecialChar ~
3221 \SpecialChar ~
3222 \SpecialChar ~
3223 \SpecialChar ~
3224 \SpecialChar ~
3225
3226 \end_inset 
3227 </cell>
3228 </row>
3229 <row topline="true" bottomline="true">
3230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3231 \begin_inset Text
3232
3233 \layout Standard
3234
3235
3236 \emph on 
3237 $DATADIR/
3238 \newline 
3239 $LIB_DIR_SUFFIX/<model>
3240 \end_inset 
3241 </cell>
3242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3243 \begin_inset Text
3244
3245 \layout Standard
3246
3247 /usr/local/share/sdcc/
3248 \newline 
3249 lib/
3250 \emph on 
3251 <model>
3252 \end_inset 
3253 </cell>
3254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3255 \begin_inset Text
3256
3257 \layout Standard
3258
3259 (not on Win32)
3260 \end_inset 
3261 </cell>
3262 </row>
3263 </lyxtabular>
3264
3265 \end_inset 
3266
3267
3268 \newline 
3269
3270 \layout Comment
3271
3272 Don't delete any of the stray spaces in the table above without checking
3273  the HTML output (last line)!
3274 \layout Standard
3275
3276 \SpecialChar ~
3277
3278 \newline 
3279 The option -
3280 \begin_inset ERT
3281 status Collapsed
3282
3283 \layout Standard
3284
3285 \backslash 
3286 /
3287 \end_inset 
3288
3289 -nostdlib disables the last two search paths.
3290 \layout Section
3291
3292 Building SDCC
3293 \begin_inset LatexCommand \index{Building SDCC}
3294
3295 \end_inset 
3296
3297
3298 \layout Subsection
3299
3300 Building SDCC on Linux
3301 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3302
3303 \end_inset 
3304
3305
3306 \layout Enumerate
3307
3308
3309 \series medium 
3310 Download the source package
3311 \series default 
3312  either from the SDCC Subversion repository or from the nightly snapshots
3313 \series medium 
3314 , it will be named something like sdcc
3315 \series default 
3316 .src
3317 \series medium 
3318 .t
3319 \series default 
3320 ar.
3321 \series medium 
3322 gz
3323 \series default 
3324  
3325 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3326
3327 \end_inset 
3328
3329 .
3330 \layout Enumerate
3331
3332
3333 \series medium 
3334 Bring up a command line terminal, such as xterm.
3335 \layout Enumerate
3336
3337
3338 \series medium 
3339 Unpack the file using a command like: 
3340 \family sans 
3341 \series bold 
3342 "tar -xvzf sdcc.src.tar.gz
3343 \family default 
3344 \series default 
3345 "
3346 \series medium 
3347 , this will create a sub-directory called sdcc with all of the sources.
3348 \layout Enumerate
3349
3350 Change directory into the main SDCC directory, for example type: 
3351 \family sans 
3352 \series bold 
3353 "cd sdcc
3354 \series default 
3355 ".
3356 \layout Enumerate
3357
3358
3359 \series medium 
3360 Type 
3361 \family sans 
3362 \series bold 
3363 "./configure
3364 \family default 
3365 \series default 
3366 ".
3367  This configures the package for compilation on your system.
3368 \layout Enumerate
3369
3370
3371 \series medium 
3372 Type 
3373 \family sans 
3374 \series bold 
3375 "make
3376 \family default 
3377 \series default 
3378 "
3379 \series medium 
3380 .
3381
3382 \series default 
3383  All of the source packages will compile, this can take a while.
3384 \layout Enumerate
3385
3386
3387 \series medium 
3388 Type 
3389 \family sans 
3390 \series bold 
3391 "make install"
3392 \family default 
3393 \series default 
3394  as root
3395 \series medium 
3396 .
3397
3398 \series default 
3399  This copies the binary executables, the include files, the libraries and
3400  the documentation to the install directories.
3401  Proceed with section 
3402 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3403
3404 \end_inset 
3405
3406 .
3407 \layout Subsection
3408
3409 Building SDCC on OSX 2.x
3410 \layout Standard
3411
3412 Follow the instruction for Linux.
3413 \newline 
3414
3415 \newline 
3416 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3417 )) fails to compile SDCC.
3418  Fortunately there's also gcc 2.9.x installed, which works fine.
3419  This compiler can be selected by running 'configure' with:
3420 \layout LyX-Code
3421
3422 ./configure CC=gcc2 CXX=g++2
3423 \layout Subsection
3424
3425 Cross compiling SDCC on Linux for Windows
3426 \layout Standard
3427
3428 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3429  See section 'Configure Options'.
3430 \layout Subsection
3431
3432 Building SDCC using Cygwin and Mingw32
3433 \layout Standard
3434
3435 For building and installing a Cygwin executable follow the instructions
3436  for Linux.
3437 \newline 
3438
3439 \newline 
3440 On Cygwin a 
3441 \begin_inset Quotes sld
3442 \end_inset 
3443
3444 native
3445 \begin_inset Quotes srd
3446 \end_inset 
3447
3448  Win32-binary can be built, which will not need the Cygwin-DLL.
3449  For the necessary 'configure' options see section 'configure options' or
3450  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3451 \newline 
3452
3453 \newline 
3454 In order to install Cygwin on Windows download setup.exe from 
3455 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3456
3457 \end_inset 
3458
3459 .
3460  Run it, set the 
3461 \begin_inset Quotes sld
3462 \end_inset 
3463
3464 default text file type
3465 \begin_inset Quotes srd
3466 \end_inset 
3467
3468  to 
3469 \begin_inset Quotes sld
3470 \end_inset 
3471
3472 unix
3473 \begin_inset Quotes srd
3474 \end_inset 
3475
3476  and download/install at least the following packages.
3477  Some packages are selected by default, others will be automatically selected
3478  because of dependencies with the manually selected packages.
3479  Never deselect these packages!
3480 \layout Itemize
3481
3482 flex
3483 \layout Itemize
3484
3485 bison
3486 \layout Itemize
3487
3488 gcc ; version 3.x is fine, no need to use the old 2.9x
3489 \layout Itemize
3490
3491 binutils ; selected with gcc
3492 \layout Itemize
3493
3494 make
3495 \layout Itemize
3496
3497 rxvt ; a nice console, which makes life much easier under windoze (see below)
3498 \layout Itemize
3499
3500 man ; not really needed for building SDCC, but you'll miss it sooner or
3501  later
3502 \layout Itemize
3503
3504 less ; not really needed for building SDCC, but you'll miss it sooner or
3505  later
3506 \layout Itemize
3507
3508 svn ; only if you use Subversion access
3509 \layout Standard
3510
3511 If you want to develop something you'll need:
3512 \layout Itemize
3513
3514 python ; for the regression tests
3515 \layout Itemize
3516
3517 gdb ; the gnu debugger, together with the nice GUI 
3518 \begin_inset Quotes sld
3519 \end_inset 
3520
3521 insight
3522 \begin_inset Quotes srd
3523 \end_inset 
3524
3525
3526 \layout Itemize
3527
3528 openssh ; to access the CF or commit changes
3529 \layout Itemize
3530
3531 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3532  use autoconf-stable!
3533 \layout Standard
3534
3535 rxvt is a nice console with history.
3536  Replace in your cygwin.bat the line
3537 \layout LyX-Code
3538
3539 bash -
3540 \begin_inset ERT
3541 status Collapsed
3542
3543 \layout Standard
3544
3545 \backslash 
3546 /
3547 \end_inset 
3548
3549 -login -i 
3550 \layout Standard
3551
3552 with (one line):
3553 \layout LyX-Code
3554
3555 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3556 \layout LyX-Code
3557
3558      -bg black -fg white -geometry 100x65 -e bash -
3559 \begin_inset ERT
3560 status Collapsed
3561
3562 \layout Standard
3563
3564 \backslash 
3565 /
3566 \end_inset 
3567
3568 -login
3569 \layout Standard
3570
3571 Text selected with the mouse is automatically copied to the clipboard, pasting
3572  works with shift-insert.
3573 \newline 
3574
3575 \newline 
3576 The other good tip is to make sure you have no //c/-style paths anywhere,
3577  use /cygdrive/c/ instead.
3578  Using // invokes a network lookup which is very slow.
3579  If you think 
3580 \begin_inset Quotes sld
3581 \end_inset 
3582
3583 cygdrive
3584 \begin_inset Quotes srd
3585 \end_inset 
3586
3587  is too long, you can change it with e.g.
3588 \layout LyX-Code
3589
3590 mount -s -u -c /mnt
3591 \layout Standard
3592
3593 SDCC sources use the unix line ending LF.
3594  Life is much easier, if you store the source tree on a drive which is mounted
3595  in binary mode.
3596  And use an editor which can handle LF-only line endings.
3597  Make sure not to commit files with windows line endings.
3598  The tabulator spacing
3599 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3600
3601 \end_inset 
3602
3603  used in the project is 8.
3604  Although a tabulator spacing of 8 is a sensible choice for programmers
3605  (it's a power of 2 and allows to display 8/16 bit signed variables without
3606  loosing columns) the plan is to move towards using only spaces in the source.
3607 \layout Subsection
3608
3609 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3610 \layout Standard
3611
3612
3613 \series medium 
3614 Download the source package
3615 \series default 
3616  either from the SDCC Subversion repository or from the 
3617 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3618
3619 \end_inset 
3620
3621
3622 \series medium 
3623 , it will be named something like sdcc
3624 \series default 
3625 .src
3626 \series medium 
3627 .tgz.
3628
3629 \series default 
3630  SDCC is distributed with all the projects, workspaces, and files you need
3631  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3632  The workspace name is 'sdcc.dsw'.
3633  Please note that as it is now, all the executables are created in a folder
3634  called sdcc
3635 \backslash 
3636 bin_vc.
3637  Once built you need to copy the executables from sdcc
3638 \backslash 
3639 bin_vc to sdcc
3640 \backslash 
3641 bin before running SDCC.
3642  
3643 \newline 
3644
3645 \newline 
3646 WARNING: Visual studio is very picky with line terminations; it expects
3647  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3648  When using the Subversion repository it's easiest to configure the svn
3649  client to convert automatically for you.
3650  If however you are getting a message such as "This makefile was not generated
3651  by Developer Studio etc.
3652  etc.
3653 \begin_inset Quotes srd
3654 \end_inset 
3655
3656  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3657  need to convert the Unix style line endings to DOS style line endings.
3658  To do so you can use the 
3659 \begin_inset Quotes sld
3660 \end_inset 
3661
3662 unix2dos
3663 \begin_inset Quotes srd
3664 \end_inset 
3665
3666  utility freely available on the internet.
3667  Doug Hawkins reported in the sdcc-user list that this works:
3668 \newline 
3669
3670 \newline 
3671 C:
3672 \backslash 
3673 Programming
3674 \backslash 
3675 SDCC> unix2dos sdcc.dsw
3676 \newline 
3677 C:
3678 \backslash 
3679 Programming
3680 \backslash 
3681 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3682 \newline 
3683
3684 \newline 
3685 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3686  flex.exe, and gawk.exe.
3687  One good place to get them is 
3688 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3689
3690 \end_inset 
3691
3692
3693 \newline 
3694
3695 \newline 
3696 Download the file UnxUtils
3697 \begin_inset LatexCommand \index{UnxUtils}
3698
3699 \end_inset 
3700
3701 .zip.
3702  Now you have to install the utilities and setup MSVC so it can locate the
3703  required programs.
3704  Here there are two alternatives (choose one!):
3705 \layout Enumerate
3706
3707 The easy way:
3708 \newline 
3709
3710 \newline 
3711 a) Extract UnxUtils.zip to your C:
3712 \backslash 
3713  hard disk PRESERVING the original paths, otherwise bison won't work.
3714  (If you are using WinZip make certain that 'Use folder names' is selected)
3715 \newline 
3716
3717 \newline 
3718 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3719  in 'Show directories for:' select 'Executable files', and in the directories
3720  window add a new path: 'C:
3721 \backslash 
3722 user
3723 \backslash 
3724 local
3725 \backslash 
3726 wbin', click ok.
3727 \newline 
3728
3729 \newline 
3730 (As a side effect, you get a bunch of Unix utilities that could be useful,
3731  such as diff and patch.)
3732 \layout Enumerate
3733
3734 A more compact way:
3735 \newline 
3736
3737 \newline 
3738 This one avoids extracting a bunch of files you may not use, but requires
3739  some extra work:
3740 \newline 
3741
3742 \newline 
3743 a) Create a directory were to put the tools needed, or use a directory already
3744  present.
3745  Say for example 'C:
3746 \backslash 
3747 util'.
3748 \newline 
3749
3750 \newline 
3751 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3752  to such directory WITHOUT preserving the original paths.
3753  (If you are using WinZip make certain that 'Use folder names' is not selected)
3754 \newline 
3755
3756 \newline 
3757 c) Rename bison.exe to '_bison.exe'.
3758 \newline 
3759
3760 \newline 
3761 d) Create a batch file 'bison.bat' in 'C:
3762 \backslash 
3763 util
3764 \backslash 
3765 ' and add these lines: 
3766 \newline 
3767 \SpecialChar ~
3768 \SpecialChar ~
3769 set BISON_SIMPLE=C:
3770 \backslash 
3771 util
3772 \backslash 
3773 bison.simple 
3774 \newline 
3775 \SpecialChar ~
3776 \SpecialChar ~
3777 set BISON_HAIRY=C:
3778 \backslash 
3779 util
3780 \backslash 
3781 bison.hairy
3782 \newline 
3783 \SpecialChar ~
3784 \SpecialChar ~
3785 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3786 \newline 
3787
3788 \newline 
3789 Steps 'c' and 'd' are needed because bison requires by default that the
3790  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3791  '/usr/local/share/' I think.
3792  So it is necessary to tell bison where those files are located if they
3793  are not in such directory.
3794  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3795 \newline 
3796
3797 \newline 
3798 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3799  in 'Show directories for:' select 'Executable files', and in the directories
3800  window add a new path: 'c:
3801 \backslash 
3802 util', click ok.
3803  Note that you can use any other path instead of 'c:
3804 \backslash 
3805 util', even the path where the Visual C++ tools are, probably: 'C:
3806 \backslash 
3807 Program Files
3808 \backslash 
3809 Microsoft Visual Studio
3810 \backslash 
3811 Common
3812 \backslash 
3813 Tools'.
3814  So you don't have to execute step 'e' :)
3815 \layout Standard
3816
3817 That is it.
3818  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3819  the executables from sdcc
3820 \backslash 
3821 bin_vc to sdcc
3822 \backslash 
3823 bin, and you can compile using SDCC.
3824 \layout Subsection
3825
3826 Building SDCC Using Borland
3827 \layout Enumerate
3828
3829 From the sdcc directory, run the command "make -f Makefile.bcc".
3830  This should regenerate all the .exe files in the bin directory except for
3831  SDCDB and ucSim.
3832 \layout Enumerate
3833
3834 If you modify any source files and need to rebuild, be aware that the dependenci
3835 es may not be correctly calculated.
3836  The safest option is to delete all .obj files and run the build again.
3837  From a Cygwin BASH prompt, this can easily be done with the command (be
3838  sure you are in the sdcc directory):
3839 \newline 
3840
3841 \newline 
3842
3843 \family sans 
3844 \series bold 
3845 find .
3846  
3847 \backslash 
3848 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3849 \backslash 
3850 ) -print -exec rm {} 
3851 \backslash 
3852 ;
3853 \family default 
3854 \series default 
3855
3856 \newline 
3857
3858 \newline 
3859 or on Windows NT/2000/XP from the command prompt with the command:
3860 \newline 
3861
3862 \family sans 
3863 \series bold 
3864
3865 \newline 
3866 del /s *.obj *.lib *.rul
3867 \family default 
3868 \series default 
3869  from the sdcc directory.
3870 \layout Subsection
3871
3872 Windows Install Using a ZIP Package
3873 \layout Enumerate
3874
3875 Download the binary zip package from 
3876 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3877
3878 \end_inset 
3879
3880  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3881  This should unpack to a group of sub-directories.
3882  An example directory structure after unpacking the mingw32 package is:
3883  c:
3884 \backslash 
3885 sdcc
3886 \backslash 
3887 bin for the executables, c:
3888 \backslash 
3889 sdcc
3890 \backslash 
3891 include and c:
3892 \backslash 
3893 sdcc
3894 \backslash 
3895 lib for the include and libraries.
3896 \layout Enumerate
3897
3898 Adjust your environment variable PATH to include the location of the bin
3899  directory or start sdcc using the full path.
3900 \layout Subsection
3901
3902 Windows Install Using the Setup Program
3903 \begin_inset LatexCommand \label{sub:Windows-Install}
3904
3905 \end_inset 
3906
3907
3908 \layout Standard
3909
3910 Download the setup program 
3911 \emph on 
3912 sdcc-x.y.z-setup.exe
3913 \emph default 
3914  for an official release from 
3915 \newline 
3916
3917 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3918
3919 \end_inset 
3920
3921  or a setup program for one of the snapshots 
3922 \emph on 
3923 sdcc-yyyymmdd-xxxx-setup.exe
3924 \emph default 
3925  from 
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3927
3928 \end_inset 
3929
3930  and execute it.
3931  A windows typical installer will guide you through the installation process.
3932 \layout Subsection
3933
3934 VPATH
3935 \begin_inset LatexCommand \index{VPATH}
3936
3937 \end_inset 
3938
3939  feature
3940 \layout Standard
3941
3942 SDCC supports the VPATH feature provided by configure and make.
3943  It allows to separate the source and build trees.
3944  Here's an example:
3945 \layout Standard
3946
3947
3948 \family typewriter 
3949 cd ~\SpecialChar ~
3950 \SpecialChar ~
3951 \SpecialChar ~
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 \SpecialChar ~
3955 \SpecialChar ~
3956 \SpecialChar ~
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 \SpecialChar ~
3961 \SpecialChar ~
3962 \SpecialChar ~
3963 \SpecialChar ~
3964 \SpecialChar ~
3965 \SpecialChar ~
3966 \SpecialChar ~
3967 \SpecialChar ~
3968 \SpecialChar ~
3969 \SpecialChar ~
3970 # cd $HOME
3971 \layout Standard
3972
3973
3974 \family typewriter 
3975 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3976 # extract source to directory sdcc
3977 \layout Standard
3978
3979
3980 \family typewriter 
3981 mkdir sdcc.build\SpecialChar ~
3982 \SpecialChar ~
3983 \SpecialChar ~
3984 \SpecialChar ~
3985 \SpecialChar ~
3986 \SpecialChar ~
3987 \SpecialChar ~
3988 \SpecialChar ~
3989 \SpecialChar ~
3990 # put output in sdcc.build
3991 \layout Standard
3992
3993
3994 \family typewriter 
3995 cd sdcc.build
3996 \layout Standard
3997
3998
3999 \family typewriter 
4000 ../sdcc/configure\SpecialChar ~
4001 \SpecialChar ~
4002 \SpecialChar ~
4003 \SpecialChar ~
4004 \SpecialChar ~
4005 \SpecialChar ~
4006 \SpecialChar ~
4007 \SpecialChar ~
4008 # configure is doing all the magic!
4009 \layout Standard
4010
4011
4012 \family typewriter 
4013 make
4014 \layout Standard
4015 \noindent 
4016 That's it! 
4017 \series bold 
4018 configure
4019 \series default 
4020  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4021  It automagically computes the variables srcdir, top_srcdir and top_buildir
4022  for each directory.
4023  After running 
4024 \series bold 
4025 make
4026 \series default 
4027  the generated files will be in ~/sdcc.build, while the source files stay
4028  in ~/sdcc.
4029 \newline 
4030 This is not only usefull for building different binaries, e.g.
4031  when cross compiling.
4032  It also gives you a much better overview in the source tree when all the
4033  generated files are not scattered between the source files.
4034  And the best thing is: if you want to change a file you can leave the original
4035  file untouched in the source directory.
4036  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4037  Makefile.dep` and `make`.
4038  
4039 \series bold 
4040 make
4041 \series default 
4042  will do the rest for you!
4043 \layout Section
4044
4045 Building the Documentation
4046 \layout Standard
4047
4048 Add -
4049 \begin_inset ERT
4050 status Collapsed
4051
4052 \layout Standard
4053
4054 \backslash 
4055 /
4056 \end_inset 
4057
4058 -enable-doc to the configure arguments to build the documentation together
4059  with all the other stuff.
4060  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4061  dvips and makeindex) to get the job done.
4062  Another possibility is to change to the doc directory and to type 
4063 \family sans 
4064 \series bold 
4065
4066 \begin_inset Quotes srd
4067 \end_inset 
4068
4069 make
4070 \begin_inset Quotes srd
4071 \end_inset 
4072
4073
4074 \family default 
4075 \series default 
4076  there.
4077  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4078 x).
4079  Using LyX 
4080 \begin_inset LatexCommand \url{http://www.lyx.org}
4081
4082 \end_inset 
4083
4084  as editor is straightforward.
4085  Prebuilt documentation in html and pdf format is available from 
4086 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4087
4088 \end_inset 
4089
4090 .
4091 \layout Section
4092
4093 Reading the Documentation
4094 \begin_inset LatexCommand \index{Documentation}
4095
4096 \end_inset 
4097
4098
4099 \layout Standard
4100
4101 Currently reading the document in pdf format is recommended, as for unknown
4102  reason the hyperlinks are working there whereas in the html version they
4103  are not
4104 \begin_inset Foot
4105 collapsed false
4106
4107 \layout Standard
4108
4109 If you should know why please drop us a note
4110 \end_inset 
4111
4112 .
4113  
4114 \newline 
4115 You'll find the pdf version
4116 \begin_inset LatexCommand \index{PDF version of this document}
4117
4118 \end_inset 
4119
4120  at 
4121 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4122
4123 \end_inset 
4124
4125 .
4126  
4127 \newline 
4128 A html version
4129 \begin_inset LatexCommand \index{HTML version of this document}
4130
4131 \end_inset 
4132
4133  should be online at 
4134 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4135
4136 \end_inset 
4137
4138 .
4139 \newline 
4140 This documentation is in some aspects different from a commercial documentation:
4141  
4142 \layout Itemize
4143
4144 It tries to document SDCC for several processor architectures in one document
4145  (commercially these probably would be separate documents/products).
4146  This document
4147 \begin_inset LatexCommand \index{Status of documentation}
4148
4149 \end_inset 
4150
4151  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4152 on about f.e.
4153  Z80, PIC14, PIC16 and HC08.
4154 \layout Itemize
4155
4156 There are many references pointing away from this documentation.
4157  Don't let this distract you.
4158  If there f.e.
4159  was a reference like 
4160 \begin_inset LatexCommand \url{http://www.opencores.org}
4161
4162 \end_inset 
4163
4164  together with a statement 
4165 \begin_inset Quotes sld
4166 \end_inset 
4167
4168 some processors which are targetted by SDCC can be implemented in a 
4169 \emph on 
4170 f
4171 \emph default 
4172 ield 
4173 \emph on 
4174 p
4175 \emph default 
4176 rogrammable 
4177 \emph on 
4178 g
4179 \emph default 
4180 ate 
4181 \emph on 
4182 a
4183 \emph default 
4184 rray
4185 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4186
4187 \end_inset 
4188
4189
4190 \begin_inset Quotes srd
4191 \end_inset 
4192
4193  or 
4194 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4195
4196 \end_inset 
4197
4198
4199 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4200
4201 \end_inset 
4202
4203  
4204 \begin_inset Quotes sld
4205 \end_inset 
4206
4207 have you ever heard of an open source compiler that compiles a subset of
4208  C for an FPGA?
4209 \begin_inset Quotes srd
4210 \end_inset 
4211
4212  we expect you to have a quick look there and come back.
4213  If you read this you are on the right track.
4214 \layout Itemize
4215
4216 Some sections attribute more space to problems, restrictions and warnings
4217  than to the solution.
4218 \layout Itemize
4219
4220 The installation section and the section about the debugger is intimidating.
4221 \layout Itemize
4222
4223 There are still lots of typos and there are more different writing styles
4224  than pictures.
4225 \layout Section
4226
4227 Testing the SDCC Compiler
4228 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4229
4230 \end_inset 
4231
4232
4233 \layout Standard
4234
4235 The first thing you should do after installing your SDCC compiler is to
4236  see if it runs.
4237  Type 
4238 \family sans 
4239 \series bold 
4240 "sdcc -
4241 \begin_inset ERT
4242 status Collapsed
4243
4244 \layout Standard
4245
4246 \backslash 
4247 /
4248 \end_inset 
4249
4250 -version"
4251 \begin_inset LatexCommand \index{version}
4252
4253 \end_inset 
4254
4255
4256 \family default 
4257 \series default 
4258  at the prompt, and the program should run and output its version like:
4259  
4260 \newline 
4261
4262 \family typewriter 
4263 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4264  (UNIX)
4265 \layout Standard
4266
4267 If it doesn't run, or gives a message about not finding sdcc program, then
4268  you need to check over your installation.
4269  Make sure that the sdcc bin directory is in your executable search path
4270  defined by the PATH environment setting (
4271 \series medium 
4272 see 
4273 \series default 
4274 section 
4275 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4276
4277 \end_inset 
4278
4279 \SpecialChar ~
4280
4281 \series medium 
4282 Install trouble-shooting for suggestions
4283 \series default 
4284 ).
4285  Make sure that the sdcc program is in the bin folder, if not perhaps something
4286  did not install correctly.
4287 \newline 
4288
4289 \newline 
4290
4291 \series medium 
4292 SDCC 
4293 \series default 
4294 is commonly installed as described in section 
4295 \begin_inset Quotes sld
4296 \end_inset 
4297
4298 Install and search paths
4299 \begin_inset Quotes srd
4300 \end_inset 
4301
4302 .
4303 \newline 
4304
4305 \newline 
4306
4307 \series medium 
4308 Make sure the compiler works on a very simple example.
4309  Type in the following test.c program using your favorite 
4310 \series default 
4311 ASCII 
4312 \series medium 
4313 editor:
4314 \layout Verse
4315
4316
4317 \family typewriter 
4318 char test;
4319 \newline 
4320
4321 \newline 
4322 void main(void) {
4323 \newline 
4324 \SpecialChar ~
4325 \SpecialChar ~
4326 \SpecialChar ~
4327 \SpecialChar ~
4328 test=0;
4329 \newline 
4330 }
4331 \layout Standard
4332
4333
4334 \series medium 
4335 Compile this using the following command: 
4336 \family sans 
4337 \series bold 
4338 "sdcc -c test.c".
4339
4340 \family default 
4341 \series default 
4342  
4343 \series medium 
4344 If all goes well, the compiler will generate a test.asm and test.rel file.
4345  Congratulations, you've just compiled your first program with SDCC.
4346  We used the -c option to tell SDCC not to link the generated code, just
4347  to keep things simple for this step.
4348 \series default 
4349
4350 \newline 
4351
4352 \newline 
4353
4354 \series medium 
4355 The next step is to try it with the linker.
4356  Type in 
4357 \family sans 
4358 \series bold 
4359 "sdcc test.c
4360 \family default 
4361 \series default 
4362 "
4363 \series medium 
4364 .
4365  If all goes well the compiler will link with the libraries and produce
4366  a test.ihx output file.
4367  If this step fails
4368 \series default 
4369  
4370 \series medium 
4371 (no test.ihx, and the linker generates warnings), then the problem is most
4372  likely that 
4373 \series default 
4374 SDCC
4375 \series medium 
4376  cannot find the 
4377 \series default 
4378 /
4379 \series medium 
4380 usr/local/share/sdcc/lib directory
4381 \series default 
4382  
4383 \series medium 
4384 (see 
4385 \series default 
4386 section 
4387 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4388
4389 \end_inset 
4390
4391 \SpecialChar ~
4392
4393 \series medium 
4394 Install trouble-shooting for suggestions).
4395 \series default 
4396
4397 \newline 
4398
4399 \newline 
4400
4401 \series medium 
4402 The final test is to ensure 
4403 \series default 
4404 SDCC
4405 \series medium 
4406  can use the 
4407 \series default 
4408 standard
4409 \series medium 
4410  header files and libraries.
4411  Edit test.c and change it to the following:
4412 \layout Verse
4413
4414
4415 \family typewriter 
4416 #include <string.h>
4417 \newline 
4418
4419 \newline 
4420 char str1[10];
4421 \newline 
4422
4423 \newline 
4424 void main(void) {
4425 \newline 
4426 \SpecialChar ~
4427 \SpecialChar ~
4428 strcpy(str1, "testing");
4429 \newline 
4430 }
4431 \layout Standard
4432
4433
4434 \series medium 
4435 Compile this by typing 
4436 \family sans 
4437 \series bold 
4438 "sdcc test.c"
4439 \family default 
4440 \series medium 
4441 .
4442  This should generate a test.ihx output file, and it should give no warnings
4443  such as not finding the string.h file.
4444  If it cannot find the string.h file, then the problem is that 
4445 \series default 
4446 SDCC
4447 \series medium 
4448  cannot find the /usr/local/share/sdcc/include directory
4449 \series default 
4450  
4451 \series medium 
4452 (see the 
4453 \series default 
4454 section 
4455 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4456
4457 \end_inset 
4458
4459 \SpecialChar ~
4460
4461 \series medium 
4462 Install trouble-shooting section for suggestions).
4463
4464 \series default 
4465  Use option 
4466 \series bold 
4467 -
4468 \begin_inset ERT
4469 status Collapsed
4470
4471 \layout Standard
4472
4473 \backslash 
4474 /
4475 \end_inset 
4476
4477 -print-search-dirs
4478 \series default 
4479
4480 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4481
4482 \end_inset 
4483
4484  to find exactly where SDCC is looking for the include and lib files.
4485 \layout Section
4486
4487 Install Trouble-shooting
4488 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4489
4490 \end_inset 
4491
4492
4493 \begin_inset LatexCommand \index{Install trouble-shooting}
4494
4495 \end_inset 
4496
4497
4498 \layout Subsection
4499
4500 If SDCC does not build correctly
4501 \layout Standard
4502
4503 A thing to try is starting from scratch by unpacking the .tgz source package
4504  again in an empty directory.
4505  Configure it like:
4506 \newline 
4507
4508 \newline 
4509
4510 \family sans 
4511 \series bold 
4512 ./configure 2>&1 | tee configure.log
4513 \family default 
4514 \series default 
4515
4516 \newline 
4517
4518 \newline 
4519 and build it like:
4520 \newline 
4521
4522 \newline 
4523
4524 \family sans 
4525 \series bold 
4526 make 2>&1 | tee make.log
4527 \family default 
4528 \series default 
4529
4530 \newline 
4531
4532 \newline 
4533 If anything goes wrong, you can review the log files to locate the problem.
4534  Or a relevant part of this can be attached to an email that could be helpful
4535  when requesting help from the mailing list.
4536 \layout Subsection
4537
4538 What the 
4539 \begin_inset Quotes sld
4540 \end_inset 
4541
4542 ./configure
4543 \begin_inset Quotes srd
4544 \end_inset 
4545
4546  does
4547 \layout Standard
4548
4549 The 
4550 \begin_inset Quotes sld
4551 \end_inset 
4552
4553 ./configure
4554 \begin_inset Quotes srd
4555 \end_inset 
4556
4557  command is a script that analyzes your system and performs some configuration
4558  to ensure the source package compiles on your system.
4559  It will take a few minutes to run, and will compile a few tests to determine
4560  what compiler features are installed.
4561 \layout Subsection
4562
4563 What the 
4564 \begin_inset Quotes sld
4565 \end_inset 
4566
4567 make
4568 \begin_inset Quotes srd
4569 \end_inset 
4570
4571  does
4572 \layout Standard
4573
4574 This runs the GNU make tool, which automatically compiles all the source
4575  packages into the final installed binary executables.
4576 \layout Subsection
4577
4578 What the 
4579 \begin_inset Quotes sld
4580 \end_inset 
4581
4582 make install
4583 \begin_inset Quotes erd
4584 \end_inset 
4585
4586  command does.
4587 \layout Standard
4588
4589 This will install the compiler, other executables libraries and include
4590  files into the appropriate directories.
4591  See sections 
4592 \begin_inset LatexCommand \ref{sub:Install-paths}
4593
4594 \end_inset 
4595
4596 ,\SpecialChar ~
4597
4598 \begin_inset LatexCommand \ref{sub:Search-Paths}
4599
4600 \end_inset 
4601
4602 \SpecialChar ~
4603 about install and search paths.
4604 \newline 
4605 On most systems you will need super-user privileges to do this.
4606 \layout Section
4607
4608 Components of SDCC
4609 \layout Standard
4610
4611 SDCC is not just a compiler, but a collection of tools by various developers.
4612  These include linkers, assemblers, simulators and other components.
4613  Here is a summary of some of the components.
4614  Note that the included simulator and assembler have separate documentation
4615  which you can find in the source package in their respective directories.
4616  As SDCC grows to include support for other processors, other packages from
4617  various developers are included and may have their own sets of documentation.
4618 \newline 
4619
4620 \newline 
4621 You might want to look at the files which are installed in <installdir>.
4622  At the time of this writing, we find the following programs for gcc-builds:
4623 \newline 
4624  
4625 \newline 
4626 In <installdir>/bin:
4627 \layout Itemize
4628
4629 sdcc - The compiler.
4630 \layout Itemize
4631
4632 sdcpp - The C preprocessor.
4633 \layout Itemize
4634
4635 asx8051 - The assembler for 8051 type processors.
4636 \layout Itemize
4637
4638 as-z80
4639 \series bold 
4640
4641 \series default 
4642 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4643 \layout Itemize
4644
4645 aslink -The linker for 8051 type processors.
4646 \layout Itemize
4647
4648 link-z80
4649 \series bold 
4650
4651 \series default 
4652 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4653 \layout Itemize
4654
4655 s51 - The ucSim 8051 simulator.
4656 \layout Itemize
4657
4658 sdcdb - The source debugger.
4659 \layout Itemize
4660
4661 packihx - A tool to pack (compress) Intel hex files.
4662 \layout Standard
4663
4664 In <installdir>/share/sdcc/include
4665 \layout Itemize
4666
4667 the include files
4668 \layout Standard
4669
4670 In <installdir>/share/sdcc/lib
4671 \layout Itemize
4672
4673 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4674  relocatables.
4675 \layout Standard
4676
4677 In <installdir>/share/sdcc/doc
4678 \layout Itemize
4679
4680 the documentation
4681 \layout Standard
4682
4683 As development for other processors proceeds, this list will expand to include
4684  executables to support processors like AVR, PIC, etc.
4685 \layout Subsection
4686
4687 sdcc - The Compiler
4688 \layout Standard
4689
4690 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4691  the assembler and linkage editor.
4692 \layout Subsection
4693
4694 sdcpp - The C-Preprocessor
4695 \layout Standard
4696
4697 The preprocessor
4698 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4699
4700 \end_inset 
4701
4702  is a modified version of the GNU cpp
4703 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4704
4705 \end_inset 
4706
4707  preprocessor 
4708 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4709
4710 \end_inset 
4711
4712 .
4713  The C preprocessor is used to pull in #include sources, process #ifdef
4714  statements, #defines and so on.
4715 \layout Subsection
4716
4717 as
4718 \emph on 
4719 xxxx
4720 \emph default 
4721 , aslink, link-
4722 \emph on 
4723 xxx
4724 \emph default 
4725  - The Assemblers and Linkage Editors
4726 \layout Standard
4727
4728 This is retargettable assembler & linkage editor, it was developed by Alan
4729  Baldwin.
4730  John Hartman created the version for 8051, and I (Sandeep) have made some
4731  enhancements and bug fixes for it to work properly with SDCC.
4732 \layout Subsection
4733
4734 s51 - The Simulator
4735 \layout Standard
4736
4737 S51
4738 \begin_inset LatexCommand \index{s51}
4739
4740 \end_inset 
4741
4742  is a freeware, opensource simulator developed by Daniel Drotos.
4743  The simulator is built as part of the build process.
4744  For more information visit Daniel's web site at: 
4745 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4746
4747 \end_inset 
4748
4749 .
4750  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4751  XA51 family.
4752 \layout Subsection
4753
4754 sdcdb - Source Level Debugger
4755 \layout Standard
4756
4757 SDCDB
4758 \begin_inset LatexCommand \index{SDCDB (debugger)}
4759
4760 \end_inset 
4761
4762  is the companion source level debugger.
4763  More about SDCDB in section 
4764 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4765
4766 \end_inset 
4767
4768 .
4769  The current version of the debugger uses Daniel's Simulator S51
4770 \begin_inset LatexCommand \index{s51}
4771
4772 \end_inset 
4773
4774 , but can be easily changed to use other simulators.
4775 \layout Chapter
4776
4777 Using SDCC
4778 \layout Section
4779
4780 Compiling
4781 \layout Subsection
4782
4783 Single Source File Projects
4784 \layout Standard
4785
4786 For single source file 8051 projects the process is very simple.
4787  Compile your programs with the following command 
4788 \family sans 
4789 \series bold 
4790 "sdcc sourcefile.c".
4791
4792 \family default 
4793 \series default 
4794  This will compile, assemble and link your source file.
4795  Output files are as follows:
4796 \layout Itemize
4797
4798 sourcefile.asm
4799 \begin_inset LatexCommand \index{<file>.asm}
4800
4801 \end_inset 
4802
4803  - Assembler source
4804 \begin_inset LatexCommand \index{Assembler source}
4805
4806 \end_inset 
4807
4808  file created by the compiler
4809 \layout Itemize
4810
4811 sourcefile.lst
4812 \begin_inset LatexCommand \index{<file>.lst}
4813
4814 \end_inset 
4815
4816  - Assembler listing
4817 \begin_inset LatexCommand \index{Assembler listing}
4818
4819 \end_inset 
4820
4821  file created by the Assembler
4822 \layout Itemize
4823
4824 sourcefile.rst
4825 \begin_inset LatexCommand \index{<file>.rst}
4826
4827 \end_inset 
4828
4829  - Assembler listing
4830 \begin_inset LatexCommand \index{Assembler listing}
4831
4832 \end_inset 
4833
4834  file updated with linkedit information, created by linkage editor
4835 \layout Itemize
4836
4837 sourcefile.sym
4838 \begin_inset LatexCommand \index{<file>.sym}
4839
4840 \end_inset 
4841
4842  - symbol listing
4843 \begin_inset LatexCommand \index{Symbol listing}
4844
4845 \end_inset 
4846
4847  for the sourcefile, created by the assembler
4848 \layout Itemize
4849
4850 sourcefile.rel
4851 \begin_inset LatexCommand \index{<file>.rel}
4852
4853 \end_inset 
4854
4855  or sourcefile.o
4856 \begin_inset LatexCommand \index{<file>.o}
4857
4858 \end_inset 
4859
4860  - Object file
4861 \begin_inset LatexCommand \index{Object file}
4862
4863 \end_inset 
4864
4865  created by the assembler, input to Linkage editor
4866 \layout Itemize
4867
4868 sourcefile.map
4869 \begin_inset LatexCommand \index{<file>.map}
4870
4871 \end_inset 
4872
4873  - The memory map
4874 \begin_inset LatexCommand \index{Memory map}
4875
4876 \end_inset 
4877
4878  for the load module, created by the Linker
4879 \layout Itemize
4880
4881 sourcefile.mem
4882 \begin_inset LatexCommand \index{<file>.mem}
4883
4884 \end_inset 
4885
4886  - A file with a summary of the memory usage
4887 \layout Itemize
4888
4889 sourcefile.ihx
4890 \begin_inset LatexCommand \index{<file>.ihx}
4891
4892 \end_inset 
4893
4894  - The load module in Intel hex format
4895 \begin_inset LatexCommand \index{Intel hex format}
4896
4897 \end_inset 
4898
4899  (you can select the Motorola S19 format
4900 \begin_inset LatexCommand \index{Motorola S19 format}
4901
4902 \end_inset 
4903
4904  with -
4905 \begin_inset ERT
4906 status Collapsed
4907
4908 \layout Standard
4909
4910 \backslash 
4911 /
4912 \end_inset 
4913
4914 -out-fmt-s19
4915 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4916
4917 \end_inset 
4918
4919 .
4920  If you need another format you might want to use 
4921 \family sans 
4922 \shape italic 
4923 objdump
4924 \family default 
4925 \shape default 
4926
4927 \begin_inset LatexCommand \index{objdump (tool)}
4928
4929 \end_inset 
4930
4931  or
4932 \family sans 
4933 \shape italic 
4934  srecord
4935 \family default 
4936 \shape default 
4937
4938 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4939
4940 \end_inset 
4941
4942 ).
4943  Both formats are documented in the documentation of srecord
4944 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4945
4946 \end_inset 
4947
4948
4949 \layout Itemize
4950
4951 sourcefile.adb
4952 \begin_inset LatexCommand \index{<file>.adb}
4953
4954 \end_inset 
4955
4956  - An intermediate file containing debug information needed to create the
4957  .cdb file (with -
4958 \begin_inset ERT
4959 status Collapsed
4960
4961 \layout Standard
4962
4963 \backslash 
4964 /
4965 \end_inset 
4966
4967 -debug
4968 \begin_inset LatexCommand \index{-\/-debug}
4969
4970 \end_inset 
4971
4972
4973 \layout Itemize
4974
4975 sourcefile.cdb
4976 \begin_inset LatexCommand \index{<file>.cdb}
4977
4978 \end_inset 
4979
4980  - An optional file (with -
4981 \begin_inset ERT
4982 status Collapsed
4983
4984 \layout Standard
4985
4986 \backslash 
4987 /
4988 \end_inset 
4989
4990 -debug) containing debug information.
4991  The format is documented in cdbfileformat.pdf
4992 \layout Itemize
4993
4994 sourcefile.
4995  - (no extension)
4996 \begin_inset LatexCommand \index{<file> (no extension)}
4997
4998 \end_inset 
4999
5000  An optional AOMF or AOMF51
5001 \begin_inset LatexCommand \index{AOMF, AOMF51}
5002
5003 \end_inset 
5004
5005  
5006 \begin_inset LatexCommand \label{OMF file}
5007
5008 \end_inset 
5009
5010 file containing debug information (generated with option -
5011 \begin_inset ERT
5012 status Collapsed
5013
5014 \layout Standard
5015
5016 \backslash 
5017 /
5018 \end_inset 
5019
5020 -debug).
5021  The (Intel)
5022 \emph on 
5023  a
5024 \emph default 
5025 bsolute 
5026 \emph on 
5027 o
5028 \emph default 
5029 bject 
5030 \emph on 
5031 m
5032 \emph default 
5033 odule 
5034 \emph on 
5035 f
5036 \emph default 
5037 ormat is commonly used by third party tools (debuggers
5038 \begin_inset LatexCommand \index{Debugger}
5039
5040 \end_inset 
5041
5042 , simulators, emulators)
5043 \layout Itemize
5044
5045 sourcefile.dump*
5046 \begin_inset LatexCommand \index{<file>.dump*}
5047
5048 \end_inset 
5049
5050  - Dump file to debug the compiler it self (generated with option -
5051 \begin_inset ERT
5052 status Collapsed
5053
5054 \layout Standard
5055
5056 \backslash 
5057 /
5058 \end_inset 
5059
5060 -dumpall) (see section 
5061 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5062
5063 \end_inset 
5064
5065 \SpecialChar ~
5066  and section 
5067 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5068
5069 \end_inset 
5070
5071 \SpecialChar ~
5072
5073 \begin_inset Quotes sld
5074 \end_inset 
5075
5076 Anatomy of the compiler
5077 \begin_inset Quotes srd
5078 \end_inset 
5079
5080 ).
5081 \layout Subsection
5082
5083 Postprocessing the Intel Hex
5084 \begin_inset LatexCommand \index{Intel hex format}
5085
5086 \end_inset 
5087
5088  file
5089 \layout Standard
5090
5091 In most cases this won't be needed but the Intel Hex file
5092 \begin_inset LatexCommand \index{<file>.ihx}
5093
5094 \end_inset 
5095
5096  which is generated by SDCC might include lines of varying length and the
5097  addresses within the file are not guaranteed to be strictly ascending.
5098  If your toolchain or a bootloader does not like this you can use the tool
5099  
5100 \family typewriter 
5101 packihx
5102 \family default 
5103
5104 \begin_inset LatexCommand \index{packihx (tool)}
5105
5106 \end_inset 
5107
5108  which is part of the SDCC distribution: 
5109 \newline 
5110
5111 \newline 
5112
5113 \family sans 
5114 \series bold 
5115  packihx sourcefile.ihx >sourcefile.hex
5116 \family default 
5117 \series default 
5118
5119 \newline 
5120
5121 \newline 
5122 The separately available
5123 \emph on 
5124  srecord
5125 \emph default 
5126
5127 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5128
5129 \end_inset 
5130
5131  package additionally allows to set undefined locations to a predefined
5132  value, to insert checksums
5133 \begin_inset LatexCommand \index{checksum}
5134
5135 \end_inset 
5136
5137  of various flavours (crc, add, xor) and to perform other manipulations
5138  (convert, split, crop, offset, ...).
5139  
5140 \newline 
5141
5142 \newline 
5143
5144 \family sans 
5145 \series bold 
5146 srec_cat\SpecialChar ~
5147 \SpecialChar ~
5148 sourcefile.ihx -intel\SpecialChar ~
5149 \SpecialChar ~
5150 -o sourcefile.hex -intel
5151 \newline 
5152
5153 \newline 
5154
5155 \family default 
5156 \series default 
5157 An example for a more complex command line
5158 \begin_inset Foot
5159 collapsed false
5160
5161 \layout Standard
5162
5163 the command backfills
5164 \begin_inset LatexCommand \index{backfill unused memory}
5165
5166 \end_inset 
5167
5168  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5169  block is zero.
5170  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5171  will be interpreted as an 
5172 \family typewriter 
5173 lcall
5174 \family default 
5175  to address 
5176 \family typewriter 
5177 0x1212
5178 \family default 
5179  (where an emergency routine could sit).
5180 \end_inset 
5181
5182  could look like:
5183 \newline 
5184
5185 \newline 
5186
5187 \family sans 
5188 \series bold 
5189 \size footnotesize 
5190 srec_cat\SpecialChar ~
5191 sourcefile.ihx -intel\SpecialChar ~
5192 \SpecialChar ~
5193 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5194 -little-endian-checksum-nega
5195 tive 0xfffe 0x02 0x02\SpecialChar ~
5196 \SpecialChar ~
5197 -o sourcefile.hex -intel
5198 \size default 
5199
5200 \newline 
5201
5202 \newline 
5203
5204 \family default 
5205 \series default 
5206 The srecord package is available at 
5207 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5208
5209 \end_inset 
5210
5211  .
5212 \layout Subsection
5213
5214 Projects with Multiple Source Files
5215 \layout Standard
5216
5217 SDCC can compile only ONE file at a time.
5218  Let us for example assume that you have a project containing the following
5219  files:
5220 \newline 
5221
5222 \newline 
5223 foo1.c (contains some functions)
5224 \newline 
5225 foo2.c (contains some more functions)
5226 \newline 
5227 foomain.c (contains more functions and the function main)
5228 \newline 
5229
5230 \size footnotesize 
5231
5232 \newline 
5233
5234 \size default 
5235 The first two files will need to be compiled separately with the commands:
5236 \size footnotesize 
5237  
5238 \size default 
5239
5240 \newline 
5241
5242 \newline 
5243
5244 \family sans 
5245 \series bold 
5246 sdcc\SpecialChar ~
5247 -c\SpecialChar ~
5248 foo1.c
5249 \family default 
5250 \series default 
5251 \size footnotesize 
5252
5253 \newline 
5254
5255 \family sans 
5256 \series bold 
5257 \size default 
5258 sdcc\SpecialChar ~
5259 -c\SpecialChar ~
5260 foo2.c
5261 \family default 
5262 \series default 
5263
5264 \newline 
5265
5266 \newline 
5267 Then compile the source file containing the 
5268 \emph on 
5269 main()
5270 \emph default 
5271  function and link
5272 \begin_inset LatexCommand \index{Linker}
5273
5274 \end_inset 
5275
5276  the files together with the following command: 
5277 \newline 
5278
5279 \newline 
5280
5281 \family sans 
5282 \series bold 
5283 sdcc\SpecialChar ~
5284 foomain.c\SpecialChar ~
5285 foo1.rel\SpecialChar ~
5286 foo2.rel
5287 \family default 
5288 \series default 
5289
5290 \begin_inset LatexCommand \index{<file>.rel}
5291
5292 \end_inset 
5293
5294
5295 \newline 
5296
5297 \newline 
5298 Alternatively, 
5299 \emph on 
5300 foomain.c 
5301 \emph default 
5302 can be separately compiled as well: 
5303 \family sans 
5304 \series bold 
5305
5306 \newline 
5307
5308 \newline 
5309 sdcc\SpecialChar ~
5310 -c\SpecialChar ~
5311 foomain.c
5312 \newline 
5313 sdcc foomain.rel foo1.rel foo2.rel
5314 \newline 
5315
5316 \newline 
5317
5318 \family default 
5319 \series default 
5320 The file containing the 
5321 \emph on 
5322 main()
5323 \emph default 
5324  function
5325 \emph on 
5326  
5327 \emph default 
5328 \noun on 
5329 must
5330 \noun default 
5331  be the 
5332 \noun on 
5333 first
5334 \noun default 
5335  file specified in the command line, since the linkage editor processes
5336  file in the order they are presented to it.
5337  The linker is invoked from SDCC using a script file with extension .lnk
5338 \begin_inset LatexCommand \index{<file>.lnk}
5339
5340 \end_inset 
5341
5342 .
5343  You can view this file to troubleshoot linking problems such as those arising
5344  from missing libraries.
5345 \layout Subsection
5346
5347 Projects with Additional Libraries
5348 \begin_inset LatexCommand \index{Libraries}
5349
5350 \end_inset 
5351
5352
5353 \layout Standard
5354
5355 Some reusable routines may be compiled into a library, see the documentation
5356  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5357  for how to create a 
5358 \emph on 
5359 .lib
5360 \begin_inset LatexCommand \index{<file>.lib}
5361
5362 \end_inset 
5363
5364
5365 \emph default 
5366  library file.
5367  Libraries created in this manner can be included in the command line.
5368  Make sure you include the -L <library-path> option to tell the linker where
5369  to look for these files if they are not in the current directory.
5370  Here is an example, assuming you have the source file 
5371 \emph on 
5372 foomain.c
5373 \emph default 
5374  and a library
5375 \emph on 
5376  foolib.lib
5377 \emph default 
5378  in the directory 
5379 \emph on 
5380 mylib
5381 \emph default 
5382  (if that is not the same as your current project):
5383 \newline 
5384
5385 \newline 
5386
5387 \family sans 
5388 \series bold 
5389 sdcc foomain.c foolib.lib -L mylib
5390 \newline 
5391
5392 \newline 
5393
5394 \family default 
5395 \series default 
5396 Note here that
5397 \emph on 
5398  mylib
5399 \emph default 
5400  must be an absolute path name.
5401 \newline 
5402
5403 \newline 
5404 The most efficient way to use libraries is to keep separate modules in separate
5405  source files.
5406  The lib file now should name all the modules.rel
5407 \begin_inset LatexCommand \index{<file>.rel}
5408
5409 \end_inset 
5410
5411  files.
5412  For an example see the standard library file 
5413 \emph on 
5414 libsdcc.lib
5415 \emph default 
5416  in the directory <installdir>/share/lib/small.
5417 \layout Subsection
5418
5419 Using sdcclib to Create and Manage Libraries
5420 \begin_inset LatexCommand \index{sdcclib}
5421
5422 \end_inset 
5423
5424
5425 \layout Standard
5426
5427 Alternatively, instead of having a .rel file for each entry on the library
5428  file as described in the preceding section, sdcclib can be used to embed
5429  all the modules belonging to such library in the library file itself.
5430  This results in a larger library file, but it greatly reduces the number
5431  of disk files accessed by the linker.
5432   Additionally, the packed library file contains an index of all include
5433  modules and symbols that significantly speeds up the linking process.
5434  To display a list of options supported by sdcclib type:
5435 \newline 
5436
5437 \layout Standard
5438
5439
5440 \family sans 
5441 \series bold 
5442 sdcclib -?
5443 \begin_inset LatexCommand \index{sdcclib}
5444
5445 \end_inset 
5446
5447
5448 \newline 
5449
5450 \newline 
5451
5452 \family default 
5453 \series default 
5454 To create a new library file, start by compiling all the required modules.
5455  For example:
5456 \newline 
5457
5458 \layout Standard
5459
5460
5461 \family sans 
5462 \series bold 
5463 sdcc -c _divsint.c
5464 \layout Standard
5465
5466
5467 \family sans 
5468 \series bold 
5469 sdcc -c _divuint.c
5470 \layout Standard
5471
5472
5473 \family sans 
5474 \series bold 
5475 sdcc -c _modsint.c
5476 \layout Standard
5477
5478
5479 \family sans 
5480 \series bold 
5481 sdcc -c _moduint.c
5482 \layout Standard
5483
5484
5485 \family sans 
5486 \series bold 
5487 sdcc -c _mulint.c
5488 \newline 
5489
5490 \layout Standard
5491
5492 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5493  and _mulint.rel.
5494  The next step is to add the .rel files to the library file:
5495 \newline 
5496
5497 \layout Standard
5498
5499
5500 \family sans 
5501 \series bold 
5502 sdcclib libint.lib _divsint.rel
5503 \family default 
5504
5505 \begin_inset LatexCommand \index{sdcclib}
5506
5507 \end_inset 
5508
5509
5510 \layout Standard
5511
5512
5513 \family sans 
5514 \series bold 
5515 sdcclib libint.lib _divuint.rel
5516 \layout Standard
5517
5518
5519 \family sans 
5520 \series bold 
5521 sdcclib libint.lib _modsint.rel
5522 \layout Standard
5523
5524
5525 \family sans 
5526 \series bold 
5527 sdcclib libint.lib _moduint.rel
5528 \layout Standard
5529
5530
5531 \family sans 
5532 \series bold 
5533 sdcclib libint.lib _mulint.rel
5534 \series default 
5535
5536 \newline 
5537
5538 \layout Standard
5539
5540 If the file already exists in the library, it will be replaced.
5541  To see what modules and symbols are included in the library, options -s
5542  and -m are available.
5543  For example:
5544 \newline 
5545
5546 \newline 
5547
5548 \family sans 
5549 \series bold 
5550 sdcclib -s libint.lib
5551 \family default 
5552
5553 \begin_inset LatexCommand \index{sdcclib}
5554
5555 \end_inset 
5556
5557
5558 \newline 
5559
5560 \family typewriter 
5561 \series default 
5562 _divsint.rel:
5563 \layout Standard
5564
5565
5566 \family typewriter 
5567 __divsint_a_1_1
5568 \layout Standard
5569
5570
5571 \family typewriter 
5572 __divsint_PARM_2
5573 \layout Standard
5574
5575
5576 \family typewriter 
5577 __divsint
5578 \newline 
5579 _divuint.rel:
5580 \layout Standard
5581
5582
5583 \family typewriter 
5584 __divuint_a_1_1
5585 \layout Standard
5586
5587
5588 \family typewriter 
5589 __divuint_PARM_2
5590 \layout Standard
5591
5592
5593 \family typewriter 
5594 __divuint_reste_1_1
5595 \layout Standard
5596
5597
5598 \family typewriter 
5599 __divuint_count_1_1
5600 \layout Standard
5601
5602
5603 \family typewriter 
5604 __divuint
5605 \newline 
5606 _modsint.rel:
5607 \layout Standard
5608
5609
5610 \family typewriter 
5611 __modsint_a_1_1
5612 \layout Standard
5613
5614
5615 \family typewriter 
5616 __modsint_PARM_2
5617 \layout Standard
5618
5619
5620 \family typewriter 
5621 __modsint
5622 \newline 
5623 _moduint.rel:
5624 \layout Standard
5625
5626
5627 \family typewriter 
5628 __moduint_a_1_1
5629 \layout Standard
5630
5631
5632 \family typewriter 
5633 __moduint_PARM_2
5634 \layout Standard
5635
5636
5637 \family typewriter 
5638 __moduint_count_1_1
5639 \layout Standard
5640
5641
5642 \family typewriter 
5643 __moduint
5644 \newline 
5645 _mulint.rel:
5646 \layout Standard
5647
5648
5649 \family typewriter 
5650 __mulint_PARM_2
5651 \layout Standard
5652
5653
5654 \family typewriter 
5655 __mulint
5656 \family default 
5657 \series bold 
5658
5659 \newline 
5660
5661 \layout Standard
5662 \added_space_bottom bigskip 
5663 If the source files are compiled using -
5664 \begin_inset ERT
5665 status Collapsed
5666
5667 \layout Standard
5668
5669 \backslash 
5670 /
5671 \end_inset 
5672
5673 -debug
5674 \begin_inset LatexCommand \index{-\/-debug}
5675
5676 \end_inset 
5677
5678 , the corresponding debug information file .adb will be include in the library
5679  file as well.
5680  The library files created with sdcclib are plain text files, so they can
5681  be viewed with a text editor.
5682  It is not recomended to modify a library file created with sdcclib using
5683  a text editor, as there are file indexes numbers located accross the file
5684  used by the linker to quickly locate the required module to link.
5685  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5686  it can be safely deleted, since all the information required for linking
5687  is embedded in the library file itself.
5688  Library files created using sdcclib are used as described in the preceding
5689  sections.
5690 \layout Section
5691
5692 Command Line Options
5693 \begin_inset LatexCommand \index{Command Line Options}
5694
5695 \end_inset 
5696
5697
5698 \layout Subsection
5699
5700 Processor Selection Options
5701 \begin_inset LatexCommand \index{Options processor selection}
5702
5703 \end_inset 
5704
5705
5706 \begin_inset LatexCommand \index{Processor selection options}
5707
5708 \end_inset 
5709
5710
5711 \layout List
5712 \labelwidthstring 00.00.0000
5713
5714
5715 \series bold 
5716 -mmcs51
5717 \begin_inset LatexCommand \index{-mmcs51}
5718
5719 \end_inset 
5720
5721
5722 \series default 
5723  Generate code for the Intel MCS51
5724 \begin_inset LatexCommand \index{MCS51}
5725
5726 \end_inset 
5727
5728  family of processors.
5729  This is the default processor target.
5730 \layout List
5731 \labelwidthstring 00.00.0000
5732
5733
5734 \series bold 
5735 -mds390
5736 \begin_inset LatexCommand \index{-mds390}
5737
5738 \end_inset 
5739
5740
5741 \series default 
5742  Generate code for the Dallas DS80C390
5743 \begin_inset LatexCommand \index{DS80C390}
5744
5745 \end_inset 
5746
5747  processor.
5748 \layout List
5749 \labelwidthstring 00.00.0000
5750
5751
5752 \series bold 
5753 -mds400
5754 \begin_inset LatexCommand \index{-mds400}
5755
5756 \end_inset 
5757
5758
5759 \series default 
5760  Generate code for the Dallas DS80C400
5761 \begin_inset LatexCommand \index{DS80C400}
5762
5763 \end_inset 
5764
5765  processor.
5766 \layout List
5767 \labelwidthstring 00.00.0000
5768
5769
5770 \series bold 
5771 -mhc08
5772 \begin_inset LatexCommand \index{-mhc08}
5773
5774 \end_inset 
5775
5776
5777 \series default 
5778  Generate code for the Freescale/Motorola HC08
5779 \begin_inset LatexCommand \index{HC08}
5780
5781 \end_inset 
5782
5783  family of processors.
5784 \layout List
5785 \labelwidthstring 00.00.0000
5786
5787
5788 \series bold 
5789 -mz80
5790 \begin_inset LatexCommand \index{-mz80}
5791
5792 \end_inset 
5793
5794
5795 \series default 
5796  Generate code for the Zilog Z80
5797 \begin_inset LatexCommand \index{Z80}
5798
5799 \end_inset 
5800
5801  family of processors.
5802 \layout List
5803 \labelwidthstring 00.00.0000
5804
5805
5806 \series bold 
5807 -mgbz80
5808 \begin_inset LatexCommand \index{-mgbz80}
5809
5810 \end_inset 
5811
5812
5813 \series default 
5814  Generate code for the GameBoy Z80
5815 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5816
5817 \end_inset 
5818
5819  processor (Not actively maintained).
5820 \layout List
5821 \labelwidthstring 00.00.0000
5822
5823
5824 \series bold 
5825 -mavr
5826 \begin_inset LatexCommand \index{-mavr}
5827
5828 \end_inset 
5829
5830
5831 \series default 
5832  Generate code for the Atmel AVR
5833 \begin_inset LatexCommand \index{AVR}
5834
5835 \end_inset 
5836
5837  processor (Not maintained, not complete).
5838  AVR users should probably have a look at winavr 
5839 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5840
5841 \end_inset 
5842
5843  or 
5844 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5845
5846 \end_inset 
5847
5848 .
5849 \layout Comment
5850
5851 I think it is fair to direct users there for now.
5852  Open source is also about avoiding unnecessary work .
5853  But I didn't find the 'official' link.
5854 \layout List
5855 \labelwidthstring 00.00.0000
5856
5857
5858 \series bold 
5859 -mpic14
5860 \begin_inset LatexCommand \index{-mpic14}
5861
5862 \end_inset 
5863
5864
5865 \series default 
5866  Generate code for the Microchip PIC 14
5867 \begin_inset LatexCommand \index{PIC14}
5868
5869 \end_inset 
5870
5871 -bit processors (p16f84 and variants.
5872  In development, not complete).
5873 \layout Comment
5874
5875 p16f627 p16f628 p16f84 p16f873 p16f877?
5876 \layout List
5877 \labelwidthstring 00.00.0000
5878
5879
5880 \series bold 
5881 -mpic16
5882 \begin_inset LatexCommand \index{-mpic16}
5883
5884 \end_inset 
5885
5886
5887 \series default 
5888  Generate code for the Microchip PIC 16
5889 \begin_inset LatexCommand \index{PIC16}
5890
5891 \end_inset 
5892
5893 -bit processors (p18f452 and variants.
5894  In development, not complete).
5895 \layout List
5896 \labelwidthstring 00.00.0000
5897
5898
5899 \series bold 
5900 -mtlcs900h
5901 \series default 
5902  Generate code for the Toshiba TLCS-900H
5903 \begin_inset LatexCommand \index{TLCS-900H}
5904
5905 \end_inset 
5906
5907  processor (Not maintained, not complete).
5908 \layout List
5909 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5910
5911
5912 \series bold 
5913 -mxa51
5914 \begin_inset LatexCommand \index{-mxa51}
5915
5916 \end_inset 
5917
5918
5919 \series default 
5920  Generate code for the Phillips XA51
5921 \begin_inset LatexCommand \index{XA51}
5922
5923 \end_inset 
5924
5925  processor (Not maintained, not complete).
5926 \layout Subsection
5927
5928 Preprocessor Options
5929 \begin_inset LatexCommand \index{Options preprocessor}
5930
5931 \end_inset 
5932
5933
5934 \begin_inset LatexCommand \index{Preprocessor options}
5935
5936 \end_inset 
5937
5938
5939 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5940
5941 \end_inset 
5942
5943
5944 \layout List
5945 \labelwidthstring 00.00.0000
5946
5947
5948 \series bold 
5949 -I<path>
5950 \begin_inset LatexCommand \index{-I<path>}
5951
5952 \end_inset 
5953
5954
5955 \series default 
5956  The additional location where the pre processor will look for <..h> or 
5957 \begin_inset Quotes eld
5958 \end_inset 
5959
5960 ..h
5961 \begin_inset Quotes erd
5962 \end_inset 
5963
5964  files.
5965 \layout List
5966 \labelwidthstring 00.00.0000
5967
5968
5969 \series bold 
5970 -D<macro[=value]>
5971 \begin_inset LatexCommand \index{-D<macro[=value]>}
5972
5973 \end_inset 
5974
5975
5976 \series default 
5977  Command line definition of macros.
5978  Passed to the preprocessor.
5979 \layout List
5980 \labelwidthstring 00.00.0000
5981
5982
5983 \series bold 
5984 -M
5985 \begin_inset LatexCommand \index{-M}
5986
5987 \end_inset 
5988
5989
5990 \series default 
5991  Tell the preprocessor to output a rule suitable for make describing the
5992  dependencies of each object file.
5993  For each source file, the preprocessor outputs one make-rule whose target
5994  is the object file name for that source file and whose dependencies are
5995  all the files `#include'd in it.
5996  This rule may be a single line or may be continued with `
5997 \backslash 
5998 '-newline if it is long.
5999  The list of rules is printed on standard output instead of the preprocessed
6000  C program.
6001  `-M' implies `-E
6002 \begin_inset LatexCommand \index{-E}
6003
6004 \end_inset 
6005
6006 '.
6007 \layout List
6008 \labelwidthstring 00.00.0000
6009
6010
6011 \series bold 
6012 -C
6013 \begin_inset LatexCommand \index{-C}
6014
6015 \end_inset 
6016
6017
6018 \series default 
6019  Tell the preprocessor not to discard comments.
6020  Used with the `-E' option.
6021 \layout List
6022 \labelwidthstring 00.00.0000
6023
6024
6025 \series bold 
6026 -MM
6027 \begin_inset LatexCommand \index{-MM}
6028
6029 \end_inset 
6030
6031
6032 \size large 
6033 \bar under 
6034  
6035 \series default 
6036 \size default 
6037 \bar default 
6038 Like `-M' but the output mentions only the user header files included with
6039  `#include 
6040 \begin_inset Quotes eld
6041 \end_inset 
6042
6043 file"'.
6044  System header files included with `#include <file>' are omitted.
6045 \layout List
6046 \labelwidthstring 00.00.0000
6047
6048
6049 \series bold 
6050 -Aquestion(answer)
6051 \begin_inset LatexCommand \index{-Aquestion(answer)}
6052
6053 \end_inset 
6054
6055
6056 \series default 
6057  Assert the answer answer for question, in case it is tested with a preprocessor
6058  conditional such as `#if #question(answer)'.
6059  `-A-' disables the standard assertions that normally describe the target
6060  machine.
6061 \layout List
6062 \labelwidthstring 00.00.0000
6063
6064
6065 \series bold 
6066 -Umacro
6067 \begin_inset LatexCommand \index{-Umacro}
6068
6069 \end_inset 
6070
6071
6072 \series default 
6073  Undefine macro macro.
6074  `-U' options are evaluated after all `-D' options, but before any `-include'
6075  and `-imacros' options.
6076 \layout List
6077 \labelwidthstring 00.00.0000
6078
6079
6080 \series bold 
6081 -dM
6082 \begin_inset LatexCommand \index{-dM}
6083
6084 \end_inset 
6085
6086
6087 \series default 
6088  Tell the preprocessor to output only a list of the macro definitions that
6089  are in effect at the end of preprocessing.
6090  Used with the `-E' option.
6091 \layout List
6092 \labelwidthstring 00.00.0000
6093
6094
6095 \series bold 
6096 -dD
6097 \begin_inset LatexCommand \index{-dD}
6098
6099 \end_inset 
6100
6101
6102 \series default 
6103  Tell the preprocessor to pass all macro definitions into the output, in
6104  their proper sequence in the rest of the output.
6105 \layout List
6106 \labelwidthstring 00.00.0000
6107
6108
6109 \series bold 
6110 -dN
6111 \begin_inset LatexCommand \index{-dN}
6112
6113 \end_inset 
6114
6115
6116 \size large 
6117 \bar under 
6118  
6119 \series default 
6120 \size default 
6121 \bar default 
6122 Like `-dD' except that the macro arguments and contents are omitted.
6123  Only `#define name' is included in the output.
6124 \layout List
6125 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6126
6127
6128 \series bold 
6129 -Wp\SpecialChar ~
6130 preprocessorOption[,preprocessorOption]
6131 \series default 
6132
6133 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6134
6135 \end_inset 
6136
6137 ...
6138  Pass the preprocessorOption to the preprocessor 
6139 \family typewriter 
6140 sdcpp
6141 \family default 
6142
6143 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6144
6145 \end_inset 
6146
6147 .
6148  SDCC uses an adapted version of the preprocessor 
6149 \emph on 
6150 cpp
6151 \emph default 
6152  of the GNU Compiler Collection
6153 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6154
6155 \end_inset 
6156
6157  (
6158 \emph on 
6159 gcc
6160 \emph default 
6161  
6162 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6163
6164 \end_inset 
6165
6166 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6167 3.3.6\SpecialChar ~
6168 CPP\SpecialChar ~
6169 Manual
6170  at 
6171 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6172
6173 \end_inset 
6174
6175 .
6176 \layout Subsection
6177
6178 Linker Options
6179 \begin_inset LatexCommand \index{Options linker}
6180
6181 \end_inset 
6182
6183
6184 \begin_inset LatexCommand \index{Linker options}
6185
6186 \end_inset 
6187
6188
6189 \layout List
6190 \labelwidthstring 00.00.0000
6191
6192
6193 \series bold 
6194 -L\SpecialChar ~
6195 -
6196 \series default 
6197
6198 \begin_inset ERT
6199 status Collapsed
6200
6201 \layout Standard
6202
6203 \backslash 
6204 /
6205 \end_inset 
6206
6207
6208 \series bold 
6209 -lib-path
6210 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6211
6212 \end_inset 
6213
6214
6215 \begin_inset LatexCommand \index{-L -\/-lib-path}
6216
6217 \end_inset 
6218
6219
6220 \series default 
6221 \SpecialChar ~
6222 <absolute path to additional libraries> This option is passed to the linkage
6223  editor's additional libraries
6224 \begin_inset LatexCommand \index{Libraries}
6225
6226 \end_inset 
6227
6228  search path.
6229  The path name must be absolute.
6230  Additional library files may be specified in the command line.
6231  See section Compiling programs for more details.
6232 \layout List
6233 \labelwidthstring 00.00.0000
6234
6235
6236 \series bold 
6237 -
6238 \begin_inset ERT
6239 status Collapsed
6240
6241 \layout Standard
6242
6243 \backslash 
6244 /
6245 \end_inset 
6246
6247 -xram-loc
6248 \series default 
6249
6250 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6251
6252 \end_inset 
6253
6254 \SpecialChar ~
6255 <Value> The start location of the external ram
6256 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6257
6258 \end_inset 
6259
6260 , default value is 0.
6261  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6262 \begin_inset ERT
6263 status Collapsed
6264
6265 \layout Standard
6266
6267 \backslash 
6268 /
6269 \end_inset 
6270
6271 -xram-loc 0x8000 or -
6272 \begin_inset ERT
6273 status Collapsed
6274
6275 \layout Standard
6276
6277 \backslash 
6278 /
6279 \end_inset 
6280
6281 -xram-loc 32768.
6282 \layout List
6283 \labelwidthstring 00.00.0000
6284
6285
6286 \series bold 
6287 -
6288 \begin_inset ERT
6289 status Collapsed
6290
6291 \layout Standard
6292
6293 \backslash 
6294 /
6295 \end_inset 
6296
6297 -code-loc
6298 \series default 
6299
6300 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6301
6302 \end_inset 
6303
6304 \SpecialChar ~
6305 <Value> The start location of the code
6306 \begin_inset LatexCommand \index{code}
6307
6308 \end_inset 
6309
6310  segment, default value 0.
6311  Note when this option is used the interrupt vector table
6312 \begin_inset LatexCommand \index{interrupt vector table}
6313
6314 \end_inset 
6315
6316  is also relocated to the given address.
6317  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6318 \begin_inset ERT
6319 status Collapsed
6320
6321 \layout Standard
6322
6323 \backslash 
6324 /
6325 \end_inset 
6326
6327 -code-loc 0x8000 or -
6328 \begin_inset ERT
6329 status Collapsed
6330
6331 \layout Standard
6332
6333 \backslash 
6334 /
6335 \end_inset 
6336
6337 -code-loc 32768.
6338 \layout List
6339 \labelwidthstring 00.00.0000
6340
6341
6342 \series bold 
6343 -
6344 \begin_inset ERT
6345 status Collapsed
6346
6347 \layout Standard
6348
6349 \backslash 
6350 /
6351 \end_inset 
6352
6353 -stack-loc
6354 \series default 
6355
6356 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6357
6358 \end_inset 
6359
6360 \SpecialChar ~
6361 <Value> By default the stack
6362 \begin_inset LatexCommand \index{stack}
6363
6364 \end_inset 
6365
6366  is placed after the data segment.
6367  Using this option the stack can be placed anywhere in the internal memory
6368  space of the 8051.
6369  The value entered can be in Hexadecimal or Decimal format, e.g.
6370  -
6371 \begin_inset ERT
6372 status Collapsed
6373
6374 \layout Standard
6375
6376 \backslash 
6377 /
6378 \end_inset 
6379
6380 -stack-loc 0x20 or -
6381 \begin_inset ERT
6382 status Collapsed
6383
6384 \layout Standard
6385
6386 \backslash 
6387 /
6388 \end_inset 
6389
6390 -stack-loc 32.
6391  Since the sp register is incremented before a push or call, the initial
6392  sp will be set to one byte prior the provided value.
6393  The provided value should not overlap any other memory areas such as used
6394  register banks or the data segment and with enough space for the current
6395  application.
6396  The 
6397 \series bold 
6398 -
6399 \begin_inset ERT
6400 status Collapsed
6401
6402 \layout Standard
6403
6404 \backslash 
6405 /
6406 \end_inset 
6407
6408 -pack-iram
6409 \series default 
6410 \SpecialChar ~
6411
6412 \begin_inset LatexCommand \index{-\/-pack-iram}
6413
6414 \end_inset 
6415
6416  option (which is now a default setting) will override this setting, so
6417  you should also specify the 
6418 \series bold 
6419 -
6420 \begin_inset ERT
6421 status Collapsed
6422
6423 \layout Standard
6424
6425 \backslash 
6426 /
6427 \end_inset 
6428
6429 -no-pack-iram
6430 \series default 
6431 \SpecialChar ~
6432
6433 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6434
6435 \end_inset 
6436
6437  option if you need to manually place the stack.
6438 \layout List
6439 \labelwidthstring 00.00.0000
6440
6441
6442 \series bold 
6443 -
6444 \begin_inset ERT
6445 status Collapsed
6446
6447 \layout Standard
6448
6449 \backslash 
6450 /
6451 \end_inset 
6452
6453 -xstack-loc
6454 \series default 
6455
6456 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6457
6458 \end_inset 
6459
6460 \SpecialChar ~
6461 <Value> By default the external stack
6462 \begin_inset LatexCommand \index{xstack}
6463
6464 \end_inset 
6465
6466  is placed after the pdata
6467 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6468
6469 \end_inset 
6470
6471  segment.
6472  Using this option the xstack can be placed anywhere in the external memory
6473  space of the 8051.
6474  The value entered can be in Hexadecimal or Decimal format, e.g.
6475  -
6476 \begin_inset ERT
6477 status Collapsed
6478
6479 \layout Standard
6480
6481 \backslash 
6482 /
6483 \end_inset 
6484
6485 -xstack-loc 0x8000 or -
6486 \begin_inset ERT
6487 status Collapsed
6488
6489 \layout Standard
6490
6491 \backslash 
6492 /
6493 \end_inset 
6494
6495 -stack-loc 32768.
6496  The provided value should not overlap any other memory areas such as the
6497  pdata or xdata segment and with enough space for the current application.
6498 \layout List
6499 \labelwidthstring 00.00.0000
6500
6501
6502 \series bold 
6503 -
6504 \begin_inset ERT
6505 status Collapsed
6506
6507 \layout Standard
6508
6509 \backslash 
6510 /
6511 \end_inset 
6512
6513 -data-loc
6514 \series default 
6515
6516 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6517
6518 \end_inset 
6519
6520 \SpecialChar ~
6521 <Value> The start location of the internal ram data
6522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6523
6524 \end_inset 
6525
6526  segment.
6527  The value entered can be in Hexadecimal or Decimal format, eg.
6528  -
6529 \begin_inset ERT
6530 status Collapsed
6531
6532 \layout Standard
6533
6534 \backslash 
6535 /
6536 \end_inset 
6537
6538 -data-loc 0x20 or -
6539 \begin_inset ERT
6540 status Collapsed
6541
6542 \layout Standard
6543
6544 \backslash 
6545 /
6546 \end_inset 
6547
6548 -data-loc 32.
6549  (By default, the start location of the internal ram data segment  is set
6550  as low as possible in memory, taking into account the used register banks
6551  and the bit segment at address 0x20.
6552  For example if register banks 0 and 1 are used without bit variables, the
6553  data segment will be set, if -
6554 \begin_inset ERT
6555 status Collapsed
6556
6557 \layout Standard
6558
6559 \backslash 
6560 /
6561 \end_inset 
6562
6563 -data-loc is not used, to location 0x10.)
6564 \layout List
6565 \labelwidthstring 00.00.0000
6566
6567
6568 \series bold 
6569 -
6570 \begin_inset ERT
6571 status Collapsed
6572
6573 \layout Standard
6574
6575 \backslash 
6576 /
6577 \end_inset 
6578
6579 -idata-loc
6580 \series default 
6581
6582 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6583
6584 \end_inset 
6585
6586 \SpecialChar ~
6587 <Value> The start location of the indirectly addressable internal ram
6588 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6589
6590 \end_inset 
6591
6592  of the 8051, default value is 0x80.
6593  The value entered can be in Hexadecimal or Decimal format, eg.
6594  -
6595 \begin_inset ERT
6596 status Collapsed
6597
6598 \layout Standard
6599
6600 \backslash 
6601 /
6602 \end_inset 
6603
6604 -idata-loc 0x88 or -
6605 \begin_inset ERT
6606 status Collapsed
6607
6608 \layout Standard
6609
6610 \backslash 
6611 /
6612 \end_inset 
6613
6614 -idata-loc 136.
6615 \layout List
6616 \labelwidthstring 00.00.0000
6617
6618
6619 \series bold 
6620 -
6621 \begin_inset ERT
6622 status Collapsed
6623
6624 \layout Standard
6625
6626 \backslash 
6627 /
6628 \end_inset 
6629
6630 -bit-loc
6631 \series default 
6632 \SpecialChar ~
6633 <Value> The start location of the bit
6634 \begin_inset LatexCommand \index{bit}
6635
6636 \end_inset 
6637
6638  addressable internal ram of the 8051.
6639  This is 
6640 \emph on 
6641 not
6642 \emph default 
6643  implemented yet.
6644  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6645 -bBSEG=<Value>.
6646 \layout List
6647 \labelwidthstring 00.00.0000
6648
6649
6650 \series bold 
6651 -
6652 \begin_inset ERT
6653 status Collapsed
6654
6655 \layout Standard
6656
6657 \backslash 
6658 /
6659 \end_inset 
6660
6661 -out-fmt-ihx
6662 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6663
6664 \end_inset 
6665
6666
6667 \bar under 
6668  
6669 \series default 
6670 \bar default 
6671 The linker output (final object code) is in Intel Hex format.
6672 \begin_inset LatexCommand \index{Intel hex format}
6673
6674 \end_inset 
6675
6676  This is the default option.
6677  The format itself is documented in the documentation of srecord
6678 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6679
6680 \end_inset 
6681
6682 .
6683 \layout List
6684 \labelwidthstring 00.00.0000
6685
6686
6687 \series bold 
6688 -
6689 \begin_inset ERT
6690 status Collapsed
6691
6692 \layout Standard
6693
6694 \backslash 
6695 /
6696 \end_inset 
6697
6698 -out-fmt-s19
6699 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6700
6701 \end_inset 
6702
6703
6704 \bar under 
6705  
6706 \series default 
6707 \bar default 
6708 The linker output (final object code) is in Motorola S19 format
6709 \begin_inset LatexCommand \index{Motorola S19 format}
6710
6711 \end_inset 
6712
6713 .
6714  The format itself is documented in the documentation of srecord.
6715 \layout List
6716 \labelwidthstring 00.00.0000
6717
6718
6719 \series bold 
6720 -
6721 \begin_inset ERT
6722 status Collapsed
6723
6724 \layout Standard
6725
6726 \backslash 
6727 /
6728 \end_inset 
6729
6730 -out-fmt-elf
6731 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6732
6733 \end_inset 
6734
6735
6736 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6737
6738 \end_inset 
6739
6740
6741 \bar under 
6742  
6743 \series default 
6744 \bar default 
6745 The linker output (final object code) is in ELF format
6746 \begin_inset LatexCommand \index{ELF format}
6747
6748 \end_inset 
6749
6750 .
6751  (Currently only supported for the HC08
6752 \begin_inset LatexCommand \index{HC08}
6753
6754 \end_inset 
6755
6756  processors)
6757 \layout List
6758 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6759
6760
6761 \series bold 
6762 -Wl\SpecialChar ~
6763 linkOption[,linkOption]
6764 \series default 
6765
6766 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6767
6768 \end_inset 
6769
6770 ...
6771  Pass the linkOption to the linker.
6772  If a bootloader is used an option like 
6773 \begin_inset Quotes sld
6774 \end_inset 
6775
6776 -Wl\SpecialChar ~
6777 -bCSEG=0x1000
6778 \begin_inset Quotes srd
6779 \end_inset 
6780
6781  would be typical to set the start of the code segment.
6782  See also #pragma constseg and #pragma codeseg in section 
6783 \begin_inset LatexCommand \ref{sec:Pragmas}
6784
6785 \end_inset 
6786
6787  .
6788  File sdcc/as/doc/asxhtm.html has more on linker options.
6789 \layout Subsection
6790
6791 MCS51 Options
6792 \begin_inset LatexCommand \index{Options MCS51}
6793
6794 \end_inset 
6795
6796
6797 \begin_inset LatexCommand \index{MCS51 options}
6798
6799 \end_inset 
6800
6801
6802 \layout List
6803 \labelwidthstring 00.00.0000
6804
6805
6806 \series bold 
6807 -
6808 \begin_inset ERT
6809 status Collapsed
6810
6811 \layout Standard
6812
6813 \backslash 
6814 /
6815 \end_inset 
6816
6817 -model-small
6818 \begin_inset LatexCommand \index{-\/-model-small}
6819
6820 \end_inset 
6821
6822
6823 \series default 
6824 \size large 
6825 \emph on 
6826  
6827 \size default 
6828 \emph default 
6829 Generate code for Small Model programs, see section Memory Models for more
6830  details.
6831  This is the default model.
6832 \layout List
6833 \labelwidthstring 00.00.0000
6834
6835
6836 \series bold 
6837 -
6838 \begin_inset ERT
6839 status Collapsed
6840
6841 \layout Standard
6842
6843 \backslash 
6844 /
6845 \end_inset 
6846
6847 -model-medium
6848 \begin_inset LatexCommand \index{-\/-model-medium}
6849
6850 \end_inset 
6851
6852
6853 \series default 
6854  Generate code for Medium model programs, see section Memory Models for
6855  more details.
6856  If this option is used all source files in the project have to be compiled
6857  with this option.
6858  It must also be used when invoking the linker.
6859 \layout List
6860 \labelwidthstring 00.00.0000
6861
6862
6863 \series bold 
6864 -
6865 \begin_inset ERT
6866 status Collapsed
6867
6868 \layout Standard
6869
6870 \backslash 
6871 /
6872 \end_inset 
6873
6874 -model-large
6875 \begin_inset LatexCommand \index{-\/-model-large}
6876
6877 \end_inset 
6878
6879
6880 \series default 
6881  Generate code for Large model programs, see section Memory Models for more
6882  details.
6883  If this option is used all source files in the project have to be compiled
6884  with this option.
6885  It must also be used when invoking the linker.
6886 \layout List
6887 \labelwidthstring 00.00.0000
6888
6889
6890 \series bold 
6891 -
6892 \begin_inset ERT
6893 status Collapsed
6894
6895 \layout Standard
6896
6897 \backslash 
6898 /
6899 \end_inset 
6900
6901 -xstack
6902 \begin_inset LatexCommand \index{-\/-xstack}
6903
6904 \end_inset 
6905
6906
6907 \series default 
6908  Uses a pseudo stack in the pdata
6909 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6910
6911 \end_inset 
6912
6913  area (usually the first 256 bytes in the external ram) for allocating variables
6914  and passing parameters.
6915  See section 
6916 \begin_inset LatexCommand \ref{sub:External-Stack}
6917
6918 \end_inset 
6919
6920 \SpecialChar ~
6921  External Stack for more details.
6922 \layout List
6923 \labelwidthstring 00.00.0000
6924
6925
6926 \series bold 
6927 -
6928 \begin_inset ERT
6929 status Collapsed
6930
6931 \layout Standard
6932
6933 \backslash 
6934 /
6935 \end_inset 
6936
6937 -iram-size
6938 \series default 
6939 \SpecialChar ~
6940 <Value>
6941 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6942
6943 \end_inset 
6944
6945  Causes the linker to check if the internal ram usage is within limits of
6946  the given value.
6947 \layout List
6948 \labelwidthstring 00.00.0000
6949
6950
6951 \series bold 
6952 -
6953 \begin_inset ERT
6954 status Collapsed
6955
6956 \layout Standard
6957
6958 \backslash 
6959 /
6960 \end_inset 
6961
6962 -xram-size
6963 \series default 
6964 \SpecialChar ~
6965 <Value>
6966 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6967
6968 \end_inset 
6969
6970  Causes the linker to check if the external ram usage is within limits of
6971  the given value.
6972 \layout List
6973 \labelwidthstring 00.00.0000
6974
6975
6976 \series bold 
6977 -
6978 \begin_inset ERT
6979 status Collapsed
6980
6981 \layout Standard
6982
6983 \backslash 
6984 /
6985 \end_inset 
6986
6987 -code-size
6988 \series default 
6989 \SpecialChar ~
6990 <Value>
6991 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6992
6993 \end_inset 
6994
6995  Causes the linker to check if the code memory usage is within limits of
6996  the given value.
6997 \layout List
6998 \labelwidthstring 00.00.0000
6999
7000
7001 \series bold 
7002 -
7003 \begin_inset ERT
7004 status Collapsed
7005
7006 \layout Standard
7007
7008 \backslash 
7009 /
7010 \end_inset 
7011
7012 -stack-size
7013 \series default 
7014 \SpecialChar ~
7015 <Value>
7016 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7017
7018 \end_inset 
7019
7020  Causes the linker to check if there is at minimum <Value> bytes for stack.
7021 \layout List
7022 \labelwidthstring 00.00.0000
7023
7024
7025 \series bold 
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032 \backslash 
7033 /
7034 \end_inset 
7035
7036 -pack-iram
7037 \series default 
7038 \SpecialChar ~
7039
7040 \begin_inset LatexCommand \index{-\/-pack-iram}
7041
7042 \end_inset 
7043
7044  Causes the linker to use unused register banks for data variables and pack
7045  data, idata and stack together.
7046  This is the default now.
7047 \layout List
7048 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7049
7050
7051 \series bold 
7052 -
7053 \begin_inset ERT
7054 status Collapsed
7055
7056 \layout Standard
7057
7058 \backslash 
7059 /
7060 \end_inset 
7061
7062 -no-pack-iram
7063 \series default 
7064 \SpecialChar ~
7065
7066 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7067
7068 \end_inset 
7069
7070  Causes the linker to use old style for allocating memory areas.
7071 \layout Subsection
7072
7073 DS390 / DS400 Options
7074 \begin_inset LatexCommand \index{Options DS390}
7075
7076 \end_inset 
7077
7078
7079 \begin_inset LatexCommand \index{DS390}
7080
7081 \end_inset 
7082
7083
7084 \layout List
7085 \labelwidthstring 00.00.0000
7086
7087
7088 \series bold 
7089 -
7090 \begin_inset ERT
7091 status Collapsed
7092
7093 \layout Standard
7094
7095 \backslash 
7096 /
7097 \end_inset 
7098
7099 -model-flat24
7100 \series default 
7101
7102 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7103
7104 \end_inset 
7105
7106
7107 \size large 
7108 \emph on 
7109  
7110 \size default 
7111 \emph default 
7112 Generate 24-bit flat mode code.
7113  This is the one and only that the ds390 code generator supports right now
7114  and is default when using 
7115 \emph on 
7116 -mds390
7117 \emph default 
7118 .
7119  See section Memory Models for more details.
7120 \layout List
7121 \labelwidthstring 00.00.0000
7122
7123
7124 \series bold 
7125 -
7126 \begin_inset ERT
7127 status Collapsed
7128
7129 \layout Standard
7130
7131 \backslash 
7132 /
7133 \end_inset 
7134
7135 -protect-sp-update
7136 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7137
7138 \end_inset 
7139
7140
7141 \series default 
7142  disable interrupts during ESP:SP updates.
7143 \layout List
7144 \labelwidthstring 00.00.0000
7145
7146
7147 \series bold 
7148 -
7149 \begin_inset ERT
7150 status Collapsed
7151
7152 \layout Standard
7153
7154 \backslash 
7155 /
7156 \end_inset 
7157
7158 -stack-10bit
7159 \series default 
7160
7161 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7162
7163 \end_inset 
7164
7165  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7166  This is the one and only that the ds390 code generator supports right now
7167  and is default when using 
7168 \emph on 
7169 -mds390
7170 \emph default 
7171 .
7172  In this mode, the stack is located in the lower 1K of the internal RAM,
7173  which is mapped to 0x400000.
7174  Note that the support is incomplete, since it still uses a single byte
7175  as the stack pointer.
7176  This means that only the lower 256 bytes of the potential 1K stack space
7177  will actually be used.
7178  However, this does allow you to reclaim the precious 256 bytes of low RAM
7179  for use for the DATA and IDATA segments.
7180  The compiler will not generate any code to put the processor into 10 bit
7181  stack mode.
7182  It is important to ensure that the processor is in this mode before calling
7183  any re-entrant functions compiled with this option.
7184  In principle, this should work with the 
7185 \emph on 
7186 -
7187 \begin_inset ERT
7188 status Collapsed
7189
7190 \layout Standard
7191
7192 \backslash 
7193 /
7194 \end_inset 
7195
7196 -stack-auto
7197 \begin_inset LatexCommand \index{-\/-stack-auto}
7198
7199 \end_inset 
7200
7201
7202 \emph default 
7203  option, but that has not been tested.
7204  It is incompatible with the 
7205 \emph on 
7206 -
7207 \begin_inset ERT
7208 status Collapsed
7209
7210 \layout Standard
7211
7212 \backslash 
7213 /
7214 \end_inset 
7215
7216 -xstack
7217 \begin_inset LatexCommand \index{-\/-xstack}
7218
7219 \end_inset 
7220
7221
7222 \emph default 
7223  option.
7224  It also only makes sense if the processor is in 24 bit contiguous addressing
7225  mode (see the 
7226 \emph on 
7227 -
7228 \begin_inset ERT
7229 status Collapsed
7230
7231 \layout Standard
7232
7233 \backslash 
7234 /
7235 \end_inset 
7236
7237 -model-flat24 option
7238 \emph default 
7239 ).
7240 \layout List
7241 \labelwidthstring 00.00.0000
7242
7243
7244 \series bold 
7245 -
7246 \begin_inset ERT
7247 status Collapsed
7248
7249 \layout Standard
7250
7251 \backslash 
7252 /
7253 \end_inset 
7254
7255 -stack-probe
7256 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7257
7258 \end_inset 
7259
7260
7261 \series default 
7262  insert call to function __stack_probe at each function prologue.
7263 \layout List
7264 \labelwidthstring 00.00.0000
7265
7266
7267 \series bold 
7268 -
7269 \begin_inset ERT
7270 status Collapsed
7271
7272 \layout Standard
7273
7274 \backslash 
7275 /
7276 \end_inset 
7277
7278 -tini-libid
7279 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7280
7281 \end_inset 
7282
7283
7284 \series default 
7285  <nnnn> LibraryID used in -mTININative.
7286  
7287 \layout List
7288 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7289
7290
7291 \series bold 
7292 -
7293 \begin_inset ERT
7294 status Collapsed
7295
7296 \layout Standard
7297
7298 \backslash 
7299 /
7300 \end_inset 
7301
7302 -use-accelerator
7303 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7304
7305 \end_inset 
7306
7307
7308 \series default 
7309  generate code for DS390 Arithmetic Accelerator.
7310  
7311 \layout Subsection
7312
7313 Z80 Options
7314 \begin_inset LatexCommand \index{Options Z80}
7315
7316 \end_inset 
7317
7318
7319 \begin_inset LatexCommand \index{Z80}
7320
7321 \end_inset 
7322
7323
7324 \layout List
7325 \labelwidthstring 00.00.0000
7326
7327
7328 \series bold 
7329 -
7330 \begin_inset ERT
7331 status Collapsed
7332
7333 \layout Standard
7334
7335 \backslash 
7336 /
7337 \end_inset 
7338
7339 -callee-saves-bc
7340 \series default 
7341
7342 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7343
7344 \end_inset 
7345
7346
7347 \size large 
7348 \emph on 
7349  
7350 \size default 
7351 \emph default 
7352 Force a called function to always save BC.
7353 \layout List
7354 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7355
7356
7357 \series bold 
7358 -
7359 \begin_inset ERT
7360 status Collapsed
7361
7362 \layout Standard
7363
7364 \backslash 
7365 /
7366 \end_inset 
7367
7368 -no-std-crt0
7369 \series default 
7370
7371 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7372
7373 \end_inset 
7374
7375  When linking, skip the standard crt0.o object file.
7376  You must provide your own crt0.o for your system when linking.
7377  
7378 \layout Subsection
7379
7380 Optimization Options
7381 \begin_inset LatexCommand \index{Options optimization}
7382
7383 \end_inset 
7384
7385
7386 \begin_inset LatexCommand \index{Optimization options}
7387
7388 \end_inset 
7389
7390
7391 \layout List
7392 \labelwidthstring 00.00.0000
7393
7394
7395 \series bold 
7396 -
7397 \begin_inset ERT
7398 status Collapsed
7399
7400 \layout Standard
7401
7402 \backslash 
7403 /
7404 \end_inset 
7405
7406 -nogcse
7407 \begin_inset LatexCommand \index{-\/-nogcse}
7408
7409 \end_inset 
7410
7411
7412 \series default 
7413  Will not do global subexpression elimination, this option may be used when
7414  the compiler creates undesirably large stack/data spaces to store compiler
7415  temporaries (
7416 \emph on 
7417 s
7418 \emph default 
7419 pill 
7420 \emph on 
7421 loc
7422 \emph default 
7423 ations, sloc
7424 \begin_inset LatexCommand \index{sloc (spill location)}
7425
7426 \end_inset 
7427
7428 ).
7429  A warning message will be generated when this happens and the compiler
7430  will indicate the number of extra bytes it allocated.
7431  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7432 nogcse
7433 \begin_inset LatexCommand \index{\#pragma nogcse}
7434
7435 \end_inset 
7436
7437  can be used to turn off global subexpression elimination
7438 \begin_inset LatexCommand \index{Subexpression elimination}
7439
7440 \end_inset 
7441
7442  for a given function only.
7443 \layout List
7444 \labelwidthstring 00.00.0000
7445
7446
7447 \series bold 
7448 -
7449 \begin_inset ERT
7450 status Collapsed
7451
7452 \layout Standard
7453
7454 \backslash 
7455 /
7456 \end_inset 
7457
7458 -noinvariant
7459 \begin_inset LatexCommand \index{-\/-noinvariant}
7460
7461 \end_inset 
7462
7463
7464 \series default 
7465  Will not do loop invariant optimizations, this may be turned off for reasons
7466  explained for the previous option.
7467  For more details of loop optimizations performed see Loop Invariants in
7468  section 
7469 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7470
7471 \end_inset 
7472
7473 .
7474  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7475 noinvariant
7476 \begin_inset LatexCommand \index{\#pragma noinvariant}
7477
7478 \end_inset 
7479
7480  can be used to turn off invariant optimizations for a given function only.
7481 \layout List
7482 \labelwidthstring 00.00.0000
7483
7484
7485 \series bold 
7486 -
7487 \begin_inset ERT
7488 status Collapsed
7489
7490 \layout Standard
7491
7492 \backslash 
7493 /
7494 \end_inset 
7495
7496 -noinduction
7497 \begin_inset LatexCommand \index{-\/-noinduction}
7498
7499 \end_inset 
7500
7501
7502 \series default 
7503  Will not do loop induction optimizations, see section strength reduction
7504  for more details.
7505  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7506 noinduction
7507 \begin_inset LatexCommand \index{\#pragma noinduction}
7508
7509 \end_inset 
7510
7511  can be used to turn off induction optimizations for a given function only.
7512 \layout List
7513 \labelwidthstring 00.00.0000
7514
7515
7516 \series bold 
7517 -
7518 \begin_inset ERT
7519 status Collapsed
7520
7521 \layout Standard
7522
7523 \backslash 
7524 /
7525 \end_inset 
7526
7527 -nojtbound
7528 \begin_inset LatexCommand \index{-\/-nojtbound}
7529
7530 \end_inset 
7531
7532
7533 \size large 
7534 \bar under 
7535  
7536 \series default 
7537 \size default 
7538 \bar default 
7539  Will not generate boundary condition check when switch statements
7540 \begin_inset LatexCommand \index{switch statement}
7541
7542 \end_inset 
7543
7544  are implemented using jump-tables.
7545  See section 
7546 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7547
7548 \end_inset 
7549
7550 \SpecialChar ~
7551 Switch Statements for more details.
7552  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7553 nojtbound
7554 \begin_inset LatexCommand \index{\#pragma nojtbound}
7555
7556 \end_inset 
7557
7558  can be used to turn off boundary checking for jump tables for a given function
7559  only.
7560 \layout List
7561 \labelwidthstring 00.00.0000
7562
7563
7564 \series bold 
7565 -
7566 \begin_inset ERT
7567 status Collapsed
7568
7569 \layout Standard
7570
7571 \backslash 
7572 /
7573 \end_inset 
7574
7575 -noloopreverse
7576 \begin_inset LatexCommand \index{-\/-noloopreverse}
7577
7578 \end_inset 
7579
7580
7581 \series default 
7582 \size large 
7583  
7584 \size default 
7585 Will not do loop reversal 
7586 \begin_inset LatexCommand \index{Loop reversing}
7587
7588 \end_inset 
7589
7590 optimization.
7591 \layout List
7592 \labelwidthstring 00.00.0000
7593
7594 -
7595 \begin_inset ERT
7596 status Collapsed
7597
7598 \layout Standard
7599
7600 \backslash 
7601 /
7602 \end_inset 
7603
7604 -
7605 \series bold 
7606 nolabelopt
7607 \series default 
7608  
7609 \begin_inset LatexCommand \index{-\/-nolabelopt }
7610
7611 \end_inset 
7612
7613 Will not optimize labels (makes the dumpfiles more readable).
7614 \layout List
7615 \labelwidthstring 00.00.0000
7616
7617
7618 \series bold 
7619 -
7620 \begin_inset ERT
7621 status Collapsed
7622
7623 \layout Standard
7624
7625 \backslash 
7626 /
7627 \end_inset 
7628
7629 -no-xinit-opt
7630 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7631
7632 \end_inset 
7633
7634
7635 \series default 
7636  Will not memcpy initialized data from code space into xdata space.
7637  This saves a few bytes in code space if you don't have initialized data
7638 \begin_inset LatexCommand \index{Variable initialization}
7639
7640 \end_inset 
7641
7642 .
7643 \layout List
7644 \labelwidthstring 00.00.0000
7645
7646
7647 \series bold 
7648 -
7649 \begin_inset ERT
7650 status Collapsed
7651
7652 \layout Standard
7653
7654 \backslash 
7655 /
7656 \end_inset 
7657
7658 -nooverlay
7659 \begin_inset LatexCommand \index{-\/-nooverlay}
7660
7661 \end_inset 
7662
7663
7664 \series default 
7665   The compiler will not overlay parameters and local variables of any function,
7666  see section Parameters and local variables for more details.
7667 \layout List
7668 \labelwidthstring 00.00.0000
7669
7670
7671 \series bold 
7672 -
7673 \begin_inset ERT
7674 status Collapsed
7675
7676 \layout Standard
7677
7678 \backslash 
7679 /
7680 \end_inset 
7681
7682 -no-peep
7683 \begin_inset LatexCommand \index{-\/-no-peep}
7684
7685 \end_inset 
7686
7687
7688 \series default 
7689  Disable peep-hole optimization with built-in rules.
7690 \layout List
7691 \labelwidthstring 00.00.0000
7692
7693
7694 \series bold 
7695 -
7696 \begin_inset ERT
7697 status Collapsed
7698
7699 \layout Standard
7700
7701 \backslash 
7702 /
7703 \end_inset 
7704
7705 -peep-file
7706 \series default 
7707
7708 \begin_inset LatexCommand \index{-\/-peep-file}
7709
7710 \end_inset 
7711
7712 \SpecialChar ~
7713 <filename> This option can be used to use additional rules to be used by
7714  the peep hole optimizer.
7715  See section 
7716 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7717
7718 \end_inset 
7719
7720 \SpecialChar ~
7721 Peep Hole optimizations for details on how to write these rules.
7722 \layout List
7723 \labelwidthstring 00.00.0000
7724
7725
7726 \series bold 
7727 -
7728 \begin_inset ERT
7729 status Collapsed
7730
7731 \layout Standard
7732
7733 \backslash 
7734 /
7735 \end_inset 
7736
7737 -peep-asm
7738 \begin_inset LatexCommand \index{-\/-peep-asm}
7739
7740 \end_inset 
7741
7742
7743 \series default 
7744  Pass the inline assembler code through the peep hole optimizer.
7745  This can cause unexpected changes to inline assembler code, please go through
7746  the peephole optimizer
7747 \begin_inset LatexCommand \index{Peephole optimizer}
7748
7749 \end_inset 
7750
7751  rules defined in the source file tree '<target>/peeph.def' before using
7752  this option.
7753 \layout List
7754 \labelwidthstring 00.00.0000
7755
7756
7757 \series bold 
7758 -
7759 \begin_inset ERT
7760 status Collapsed
7761
7762 \layout Standard
7763
7764 \backslash 
7765 /
7766 \end_inset 
7767
7768 -opt-code-speed
7769 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7770
7771 \end_inset 
7772
7773
7774 \series default 
7775  The compiler will optimize code generation towards fast code, possibly
7776  at the expense of code size.
7777 \layout List
7778 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7779
7780
7781 \series bold 
7782 -
7783 \begin_inset ERT
7784 status Collapsed
7785
7786 \layout Standard
7787
7788 \backslash 
7789 /
7790 \end_inset 
7791
7792 -opt-code-size
7793 \begin_inset LatexCommand \index{-\/-opt-code-size}
7794
7795 \end_inset 
7796
7797
7798 \series default 
7799  The compiler will optimize code generation towards compact code, possibly
7800  at the expense of code speed.
7801 \layout Subsection
7802
7803 Other Options
7804 \begin_inset LatexCommand \index{Options other}
7805
7806 \end_inset 
7807
7808
7809 \layout List
7810 \labelwidthstring 00.00.0000
7811
7812
7813 \series bold 
7814 -c\SpecialChar ~
7815 -
7816 \begin_inset ERT
7817 status Collapsed
7818
7819 \layout Standard
7820
7821 \backslash 
7822 /
7823 \end_inset 
7824
7825 -compile-only
7826 \begin_inset LatexCommand \index{-\/-compile-only}
7827
7828 \end_inset 
7829
7830
7831 \begin_inset LatexCommand \index{-c -\/-compile-only}
7832
7833 \end_inset 
7834
7835
7836 \series default 
7837  will compile and assemble the source, but will not call the linkage editor.
7838 \layout List
7839 \labelwidthstring 00.00.0000
7840
7841
7842 \series bold 
7843 -
7844 \series default 
7845
7846 \begin_inset ERT
7847 status Collapsed
7848
7849 \layout Standard
7850
7851 \backslash 
7852 /
7853 \end_inset 
7854
7855
7856 \series bold 
7857 -c1mode
7858 \begin_inset LatexCommand \index{-\/-c1mode}
7859
7860 \end_inset 
7861
7862
7863 \series default 
7864  reads the preprocessed source from standard input and compiles it.
7865  The file name for the assembler output must be specified using the -o option.
7866 \layout List
7867 \labelwidthstring 00.00.0000
7868
7869
7870 \series bold 
7871 -E
7872 \begin_inset LatexCommand \index{-E}
7873
7874 \end_inset 
7875
7876
7877 \series default 
7878  Run only the C preprocessor.
7879  Preprocess all the C source files specified and output the results to standard
7880  output.
7881 \layout List
7882 \labelwidthstring 00.00.0000
7883
7884
7885 \series bold 
7886 -o\SpecialChar ~
7887 <path/file>
7888 \begin_inset LatexCommand \index{-o <path/file>}
7889
7890 \end_inset 
7891
7892  
7893 \series default 
7894 The output path resp.
7895  file where everything will be placed.
7896  If the parameter is a path, it must have a trailing slash (or backslash
7897  for the Windows binaries) to be recognized as a path.
7898  
7899 \layout List
7900 \labelwidthstring 00.00.0000
7901
7902
7903 \series bold 
7904 -
7905 \begin_inset ERT
7906 status Collapsed
7907
7908 \layout Standard
7909
7910 \backslash 
7911 /
7912 \end_inset 
7913
7914 -stack-auto
7915 \begin_inset LatexCommand \index{-\/-stack-auto}
7916
7917 \end_inset 
7918
7919
7920 \series default 
7921 \size large 
7922 \emph on 
7923  
7924 \size default 
7925 \emph default 
7926 All functions in the source file will be compiled as 
7927 \emph on 
7928 reentrant
7929 \emph default 
7930
7931 \begin_inset LatexCommand \index{reentrant}
7932
7933 \end_inset 
7934
7935 , i.e.
7936  the parameters and local variables will be allocated on the stack
7937 \begin_inset LatexCommand \index{stack}
7938
7939 \end_inset 
7940
7941 .
7942  See section 
7943 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7944
7945 \end_inset 
7946
7947  Parameters and Local Variables for more details.
7948  If this option is used all source files in the project should be compiled
7949  with this option.
7950  It automatically implies --int-long-reent and --float-reent.
7951  
7952 \layout List
7953 \labelwidthstring 00.00.0000
7954
7955
7956 \series bold 
7957 -
7958 \begin_inset ERT
7959 status Collapsed
7960
7961 \layout Standard
7962
7963 \backslash 
7964 /
7965 \end_inset 
7966
7967 -callee-saves
7968 \begin_inset LatexCommand \index{-\/-callee-saves}
7969
7970 \end_inset 
7971
7972  function1[,function2][,function3]....
7973
7974 \series default 
7975  The compiler by default uses a caller saves convention for register saving
7976  across function calls, however this can cause unnecessary register pushing
7977  & popping when calling small functions from larger functions.
7978  This option can be used to switch the register saving convention for the
7979  function names specified.
7980  The compiler will not save registers when calling these functions, no extra
7981  code will be generated at the entry & exit (function prologue
7982 \series bold 
7983
7984 \begin_inset LatexCommand \index{function prologue}
7985
7986 \end_inset 
7987
7988
7989 \series default 
7990  & epilogue
7991 \series bold 
7992
7993 \begin_inset LatexCommand \index{function epilogue}
7994
7995 \end_inset 
7996
7997
7998 \series default 
7999 ) for these functions to save & restore the registers used by these functions,
8000  this can SUBSTANTIALLY reduce code & improve run time performance of the
8001  generated code.
8002  In the future the compiler (with inter procedural analysis) will be able
8003  to determine the appropriate scheme to use for each function call.
8004  DO NOT use this option for built-in functions such as _mulint..., if this
8005  option is used for a library function the appropriate library function
8006  needs to be recompiled with the same option.
8007  If the project consists of multiple source files then all the source file
8008  should be compiled with the same -
8009 \begin_inset ERT
8010 status Collapsed
8011
8012 \layout Standard
8013
8014 \backslash 
8015 /
8016 \end_inset 
8017
8018 -callee-saves option string.
8019  Also see #pragma\SpecialChar ~
8020 callee_saves
8021 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8022
8023 \end_inset 
8024
8025 .
8026 \layout List
8027 \labelwidthstring 00.00.0000
8028
8029
8030 \series bold 
8031 -
8032 \begin_inset ERT
8033 status Collapsed
8034
8035 \layout Standard
8036
8037 \backslash 
8038 /
8039 \end_inset 
8040
8041 -debug
8042 \begin_inset LatexCommand \index{-\/-debug}
8043
8044 \end_inset 
8045
8046
8047 \bar under 
8048  
8049 \series default 
8050 \bar default 
8051 When this option is used the compiler will generate debug information.
8052  The debug information collected in a file with .cdb extension can be used
8053  with the SDCDB.
8054  For more information see documentation for SDCDB.
8055  Another file with no extension contains debug information in AOMF or AOMF51
8056 \begin_inset LatexCommand \index{AOMF, AOMF51}
8057
8058 \end_inset 
8059
8060  format which is commonly used by third party tools.
8061 \layout List
8062 \labelwidthstring 00.00.0000
8063
8064
8065 \series bold 
8066 -S
8067 \begin_inset LatexCommand \index{-S}
8068
8069 \end_inset 
8070
8071
8072 \size large 
8073 \bar under 
8074  
8075 \series default 
8076 \size default 
8077 \bar default 
8078 Stop after the stage of compilation proper; do not assemble.
8079  The output is an assembler code file for the input file specified.
8080 \layout List
8081 \labelwidthstring 00.00.0000
8082
8083
8084 \series bold 
8085 -
8086 \begin_inset ERT
8087 status Collapsed
8088
8089 \layout Standard
8090
8091 \backslash 
8092 /
8093 \end_inset 
8094
8095 -int-long-reent
8096 \begin_inset LatexCommand \index{-\/-int-long-reent}
8097
8098 \end_inset 
8099
8100
8101 \series default 
8102  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8103  Note by default these libraries are compiled as non-reentrant.
8104  See section Installation for more details.
8105 \layout List
8106 \labelwidthstring 00.00.0000
8107
8108
8109 \series bold 
8110 -
8111 \begin_inset ERT
8112 status Collapsed
8113
8114 \layout Standard
8115
8116 \backslash 
8117 /
8118 \end_inset 
8119
8120 -cyclomatic
8121 \begin_inset LatexCommand \index{-\/-cyclomatic}
8122
8123 \end_inset 
8124
8125
8126 \bar under 
8127  
8128 \series default 
8129 \bar default 
8130 This option will cause the compiler to generate an information message for
8131  each function in the source file.
8132  The message contains some 
8133 \emph on 
8134 important
8135 \emph default 
8136  information about the function.
8137  The number of edges and nodes the compiler detected in the control flow
8138  graph of the function, and most importantly the 
8139 \emph on 
8140 cyclomatic complexity
8141 \begin_inset LatexCommand \index{Cyclomatic complexity}
8142
8143 \end_inset 
8144
8145
8146 \emph default 
8147  see section on Cyclomatic Complexity for more details.
8148 \layout List
8149 \labelwidthstring 00.00.0000
8150
8151
8152 \series bold 
8153 -
8154 \begin_inset ERT
8155 status Collapsed
8156
8157 \layout Standard
8158
8159 \backslash 
8160 /
8161 \end_inset 
8162
8163 -float-reent
8164 \begin_inset LatexCommand \index{-\/-float-reent}
8165
8166 \end_inset 
8167
8168
8169 \series default 
8170  Floating point library is compiled as reentrant
8171 \begin_inset LatexCommand \index{reentrant}
8172
8173 \end_inset 
8174
8175 .
8176  See section Installation for more details.
8177 \layout List
8178 \labelwidthstring 00.00.0000
8179
8180
8181 \series bold 
8182 -
8183 \begin_inset ERT
8184 status Collapsed
8185
8186 \layout Standard
8187
8188 \backslash 
8189 /
8190 \end_inset 
8191
8192 -main-return
8193 \begin_inset LatexCommand \index{-\/-main-return}
8194
8195 \end_inset 
8196
8197
8198 \series default 
8199  This option can be used if the code generated is called by a monitor program
8200  or if the main routine includes an endless loop.
8201  This option results in slightly smaller code and saves two bytes of stack
8202  space.
8203  The return from the 'main'
8204 \begin_inset LatexCommand \index{main return}
8205
8206 \end_inset 
8207
8208  function will return to the function calling main.
8209  The default setting is to lock up i.e.
8210  generate a '
8211 \family typewriter 
8212 sjmp .
8213 \family default 
8214 '.
8215 \layout List
8216 \labelwidthstring 00.00.0000
8217
8218
8219 \series bold 
8220 -
8221 \begin_inset ERT
8222 status Collapsed
8223
8224 \layout Standard
8225
8226 \backslash 
8227 /
8228 \end_inset 
8229
8230 -nostdinc
8231 \begin_inset LatexCommand \index{-\/-nostdinc}
8232
8233 \end_inset 
8234
8235
8236 \series default 
8237  This will prevent the compiler from passing on the default include path
8238  to the preprocessor.
8239 \layout List
8240 \labelwidthstring 00.00.0000
8241
8242
8243 \series bold 
8244 -
8245 \begin_inset ERT
8246 status Collapsed
8247
8248 \layout Standard
8249
8250 \backslash 
8251 /
8252 \end_inset 
8253
8254 -nostdlib
8255 \begin_inset LatexCommand \index{-\/-nostdlib}
8256
8257 \end_inset 
8258
8259
8260 \series default 
8261  This will prevent the compiler from passing on the default library
8262 \begin_inset LatexCommand \index{Libraries}
8263
8264 \end_inset 
8265
8266  path to the linker.
8267 \layout List
8268 \labelwidthstring 00.00.0000
8269
8270
8271 \series bold 
8272 -
8273 \begin_inset ERT
8274 status Collapsed
8275
8276 \layout Standard
8277
8278 \backslash 
8279 /
8280 \end_inset 
8281
8282 -verbose
8283 \begin_inset LatexCommand \index{-\/-verbose}
8284
8285 \end_inset 
8286
8287
8288 \series default 
8289  Shows the various actions the compiler is performing.
8290 \layout List
8291 \labelwidthstring 00.00.0000
8292
8293
8294 \series bold 
8295 -V
8296 \begin_inset LatexCommand \index{-V}
8297
8298 \end_inset 
8299
8300
8301 \series default 
8302  Shows the actual commands the compiler is executing.
8303 \layout List
8304 \labelwidthstring 00.00.0000
8305
8306
8307 \series bold 
8308 -
8309 \begin_inset ERT
8310 status Collapsed
8311
8312 \layout Standard
8313
8314 \backslash 
8315 /
8316 \end_inset 
8317
8318 -no-c-code-in-asm
8319 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8320
8321 \end_inset 
8322
8323
8324 \series default 
8325  Hides your ugly and inefficient c-code from the asm file, so you can always
8326  blame the compiler :)
8327 \layout List
8328 \labelwidthstring 00.00.0000
8329
8330
8331 \series bold 
8332 -
8333 \begin_inset ERT
8334 status Collapsed
8335
8336 \layout Standard
8337
8338 \backslash 
8339 /
8340 \end_inset 
8341
8342 -no-peep-comments
8343 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8344
8345 \end_inset 
8346
8347
8348 \series default 
8349  Will not include peep-hole comments in the generated files.
8350 \layout List
8351 \labelwidthstring 00.00.0000
8352
8353
8354 \series bold 
8355 -
8356 \begin_inset ERT
8357 status Collapsed
8358
8359 \layout Standard
8360
8361 \backslash 
8362 /
8363 \end_inset 
8364
8365 -i-code-in-asm
8366 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8367
8368 \end_inset 
8369
8370
8371 \series default 
8372  Include i-codes in the asm file.
8373  Sounds like noise but is most helpful for debugging the compiler itself.
8374 \layout List
8375 \labelwidthstring 00.00.0000
8376
8377
8378 \series bold 
8379 -
8380 \begin_inset ERT
8381 status Collapsed
8382
8383 \layout Standard
8384
8385 \backslash 
8386 /
8387 \end_inset 
8388
8389 -less-pedantic
8390 \begin_inset LatexCommand \index{-\/-less-pedantic}
8391
8392 \end_inset 
8393
8394
8395 \series default 
8396  Disable some of the more pedantic warnings
8397 \begin_inset LatexCommand \index{Warnings}
8398
8399 \end_inset 
8400
8401  (jwk burps: please be more specific here, please!).
8402 \layout List
8403 \labelwidthstring 00.00.0000
8404
8405
8406 \series bold 
8407 -
8408 \begin_inset ERT
8409 status Collapsed
8410
8411 \layout Standard
8412
8413 \backslash 
8414 /
8415 \end_inset 
8416
8417 -disable-warning\SpecialChar ~
8418 <nnnn>
8419 \begin_inset LatexCommand \index{-\/-disable-warning}
8420
8421 \end_inset 
8422
8423
8424 \series default 
8425  Disable specific warning with number <nnnn>.
8426 \layout List
8427 \labelwidthstring 00.00.0000
8428
8429
8430 \series bold 
8431 -
8432 \begin_inset ERT
8433 status Collapsed
8434
8435 \layout Standard
8436
8437 \backslash 
8438 /
8439 \end_inset 
8440
8441 -print-search-dirs
8442 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8443
8444 \end_inset 
8445
8446
8447 \series default 
8448  Display the directories in the compiler's search path
8449 \layout List
8450 \labelwidthstring 00.00.0000
8451
8452
8453 \series bold 
8454 -
8455 \begin_inset ERT
8456 status Collapsed
8457
8458 \layout Standard
8459
8460 \backslash 
8461 /
8462 \end_inset 
8463
8464 -vc
8465 \begin_inset LatexCommand \index{-\/-vc}
8466
8467 \end_inset 
8468
8469
8470 \series default 
8471  Display errors and warnings using MSVC style, so you can use SDCC with
8472  the visual studio IDE
8473 \begin_inset LatexCommand \index{IDE}
8474
8475 \end_inset 
8476
8477 .
8478  With SDCC both offering a GCC-like (the default) and a MSVC-like
8479 \begin_inset LatexCommand \index{MSVC output style}
8480
8481 \end_inset 
8482
8483  output style, integration into most programming editors should be straightforwa
8484 rd.
8485 \layout List
8486 \labelwidthstring 00.00.0000
8487
8488
8489 \series bold 
8490 -
8491 \begin_inset ERT
8492 status Collapsed
8493
8494 \layout Standard
8495
8496 \backslash 
8497 /
8498 \end_inset 
8499
8500 -use-stdout
8501 \begin_inset LatexCommand \index{-\/-use-stdout}
8502
8503 \end_inset 
8504
8505
8506 \series default 
8507  Send errors and warnings to stdout instead of stderr.
8508 \layout List
8509 \labelwidthstring 00.00.0000
8510
8511
8512 \series bold 
8513 -Wa\SpecialChar ~
8514 asmOption[,asmOption]
8515 \series default 
8516
8517 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8518
8519 \end_inset 
8520
8521 ...
8522  Pass the asmOption to the assembler
8523 \begin_inset LatexCommand \index{Options assembler}
8524
8525 \end_inset 
8526
8527
8528 \begin_inset LatexCommand \index{Assembler options}
8529
8530 \end_inset 
8531
8532 .
8533  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8534 \layout List
8535 \labelwidthstring 00.00.0000
8536
8537
8538 \series bold 
8539 -
8540 \begin_inset ERT
8541 status Collapsed
8542
8543 \layout Standard
8544
8545 \backslash 
8546 /
8547 \end_inset 
8548
8549 -std-sdcc89
8550 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8551
8552 \end_inset 
8553
8554
8555 \series default 
8556  Generally follow the C89 standard, but allow SDCC features that conflict
8557  with the standard (default).
8558 \layout List
8559 \labelwidthstring 00.00.0000
8560
8561
8562 \series bold 
8563 -
8564 \begin_inset ERT
8565 status Collapsed
8566
8567 \layout Standard
8568
8569 \backslash 
8570 /
8571 \end_inset 
8572
8573 -std-c89
8574 \begin_inset LatexCommand \index{-\/-std-c89}
8575
8576 \end_inset 
8577
8578
8579 \series default 
8580  Follow the C89 standard and disable SDCC features that conflict with the
8581  standard.
8582 \layout List
8583 \labelwidthstring 00.00.0000
8584
8585
8586 \series bold 
8587 -
8588 \begin_inset ERT
8589 status Collapsed
8590
8591 \layout Standard
8592
8593 \backslash 
8594 /
8595 \end_inset 
8596
8597 -std-sdcc99
8598 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8599
8600 \end_inset 
8601
8602
8603 \series default 
8604  Generally follow the C99 standard, but allow SDCC features that conflict
8605  with the standard (incomplete support).
8606 \layout List
8607 \labelwidthstring 00.00.0000
8608
8609
8610 \series bold 
8611 -
8612 \begin_inset ERT
8613 status Collapsed
8614
8615 \layout Standard
8616
8617 \backslash 
8618 /
8619 \end_inset 
8620
8621 -std-c99
8622 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8623
8624 \end_inset 
8625
8626
8627 \series default 
8628  Follow the C99 standard and disable SDCC features that conflict with the
8629  standard (incomplete support).
8630 \layout List
8631 \labelwidthstring 00.00.0000
8632
8633
8634 \series bold 
8635 -
8636 \begin_inset ERT
8637 status Collapsed
8638
8639 \layout Standard
8640
8641 \backslash 
8642 /
8643 \end_inset 
8644
8645 -codeseg
8646 \series default 
8647
8648 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8649
8650 \end_inset 
8651
8652 \SpecialChar ~
8653 <Name> The name to be used for the code
8654 \begin_inset LatexCommand \index{code}
8655
8656 \end_inset 
8657
8658  segment, default CSEG.
8659  This is useful if you need to tell the compiler to put the code in a special
8660  segment so you can later on tell the linker to put this segment in a special
8661  place in memory.
8662  Can be used for instance when using bank switching to put the code in a
8663  bank.
8664 \layout List
8665 \labelwidthstring 00.00.0000
8666
8667
8668 \series bold 
8669 -
8670 \begin_inset ERT
8671 status Collapsed
8672
8673 \layout Standard
8674
8675 \backslash 
8676 /
8677 \end_inset 
8678
8679 -constseg
8680 \series default 
8681
8682 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8683
8684 \end_inset 
8685
8686 \SpecialChar ~
8687 <Name> The name to be used for the const
8688 \begin_inset LatexCommand \index{code}
8689
8690 \end_inset 
8691
8692  segment, default CONST.
8693  This is useful if you need to tell the compiler to put the const data in
8694  a special segment so you can later on tell the linker to put this segment
8695  in a special place in memory.
8696  Can be used for instance when using bank switching to put the const data
8697  in a bank.
8698 \layout List
8699 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8700
8701
8702 \series bold 
8703 more-pedantic
8704 \series default 
8705  Actually this is 
8706 \series bold 
8707 \emph on 
8708 not
8709 \series default 
8710 \emph default 
8711  a SDCC compiler option but if you want 
8712 \emph on 
8713 more
8714 \emph default 
8715  warnings you can use a separate tool dedicated to syntax checking like
8716  splint
8717 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8718
8719 \end_inset 
8720
8721
8722 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8723
8724 \end_inset 
8725
8726  
8727 \begin_inset LatexCommand \url{http://www.splint.org}
8728
8729 \end_inset 
8730
8731 .
8732  To make your source files parseable by splint you will have to include
8733  
8734 \family sans 
8735 lint.h
8736 \family default 
8737
8738 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8739
8740 \end_inset 
8741
8742  in your source file and add brackets around extended keywords (like 
8743 \family sans 
8744
8745 \begin_inset Quotes sld
8746 \end_inset 
8747
8748 __at\SpecialChar ~
8749
8750 \series bold 
8751 (
8752 \series default 
8753 0xab
8754 \series bold 
8755 )
8756 \series default 
8757
8758 \begin_inset Quotes srd
8759 \end_inset 
8760
8761
8762 \family default 
8763  and 
8764 \family sans 
8765
8766 \begin_inset Quotes sld
8767 \end_inset 
8768
8769 __interrupt\SpecialChar ~
8770 (2)
8771 \begin_inset Quotes srd
8772 \end_inset 
8773
8774
8775 \family default 
8776 ).
8777  
8778 \newline 
8779 Splint has an excellent on line manual at 
8780 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8781
8782 \end_inset 
8783
8784  and it's capabilities go beyond pure syntax checking.
8785  You'll need to tell splint the location of SDCC's include files so a typical
8786  command line could look like this: 
8787 \newline 
8788
8789 \family sans 
8790 splint\SpecialChar ~
8791 -I\SpecialChar ~
8792 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8793 \SpecialChar ~
8794 myprogram.c
8795 \layout Subsection
8796
8797 Intermediate Dump Options
8798 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8799
8800 \end_inset 
8801
8802
8803 \begin_inset LatexCommand \index{Options intermediate dump}
8804
8805 \end_inset 
8806
8807
8808 \begin_inset LatexCommand \index{Intermediate dump options}
8809
8810 \end_inset 
8811
8812
8813 \layout Standard
8814
8815 The following options are provided for the purpose of retargetting and debugging
8816  the compiler.
8817  They provide a means to dump the intermediate code (iCode
8818 \begin_inset LatexCommand \index{iCode}
8819
8820 \end_inset 
8821
8822 ) generated by the compiler in human readable form at various stages of
8823  the compilation process.
8824  More on iCodes see chapter 
8825 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8826
8827 \end_inset 
8828
8829  
8830 \begin_inset Quotes srd
8831 \end_inset 
8832
8833 The anatomy of the compiler
8834 \begin_inset Quotes srd
8835 \end_inset 
8836
8837 .
8838 \layout List
8839 \labelwidthstring 00.00.0000
8840
8841
8842 \series bold 
8843 -
8844 \begin_inset ERT
8845 status Collapsed
8846
8847 \layout Standard
8848
8849 \backslash 
8850 /
8851 \end_inset 
8852
8853 -dumpraw
8854 \begin_inset LatexCommand \index{-\/-dumpraw}
8855
8856 \end_inset 
8857
8858
8859 \series default 
8860  This option will cause the compiler to dump the intermediate code into
8861  a file of named 
8862 \emph on 
8863 <source filename>.dumpraw
8864 \emph default 
8865  just after the intermediate code has been generated for a function, i.e.
8866  before any optimizations are done.
8867  The basic blocks
8868 \begin_inset LatexCommand \index{Basic blocks}
8869
8870 \end_inset 
8871
8872  at this stage ordered in the depth first number, so they may not be in
8873  sequence of execution.
8874 \layout List
8875 \labelwidthstring 00.00.0000
8876
8877
8878 \series bold 
8879 -
8880 \begin_inset ERT
8881 status Collapsed
8882
8883 \layout Standard
8884
8885 \backslash 
8886 /
8887 \end_inset 
8888
8889 -dumpgcse
8890 \begin_inset LatexCommand \index{-\/-dumpgcse}
8891
8892 \end_inset 
8893
8894
8895 \series default 
8896  Will create a dump of iCode's, after global subexpression elimination
8897 \begin_inset LatexCommand \index{Global subexpression elimination}
8898
8899 \end_inset 
8900
8901 , into a file named 
8902 \emph on 
8903 <source filename>.dumpgcse.
8904 \layout List
8905 \labelwidthstring 00.00.0000
8906
8907
8908 \series bold 
8909 -
8910 \begin_inset ERT
8911 status Collapsed
8912
8913 \layout Standard
8914
8915 \backslash 
8916 /
8917 \end_inset 
8918
8919 -dumpdeadcode
8920 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8921
8922 \end_inset 
8923
8924
8925 \series default 
8926  Will create a dump of iCode's, after deadcode elimination
8927 \begin_inset LatexCommand \index{Dead-code elimination}
8928
8929 \end_inset 
8930
8931 , into a file named 
8932 \emph on 
8933 <source filename>.dumpdeadcode.
8934 \layout List
8935 \labelwidthstring 00.00.0000
8936
8937
8938 \series bold 
8939 -
8940 \begin_inset ERT
8941 status Collapsed
8942
8943 \layout Standard
8944
8945 \backslash 
8946 /
8947 \end_inset 
8948
8949 -dumploop
8950 \begin_inset LatexCommand \index{-\/-dumploop}
8951
8952 \end_inset 
8953
8954
8955 \series default 
8956 \size large 
8957  
8958 \size default 
8959 Will create a dump of iCode's, after loop optimizations
8960 \begin_inset LatexCommand \index{Loop optimization}
8961
8962 \end_inset 
8963
8964 , into a file named 
8965 \emph on 
8966 <source filename>.dumploop.
8967 \layout List
8968 \labelwidthstring 00.00.0000
8969
8970
8971 \series bold 
8972 -
8973 \begin_inset ERT
8974 status Collapsed
8975
8976 \layout Standard
8977
8978 \backslash 
8979 /
8980 \end_inset 
8981
8982 -dumprange
8983 \begin_inset LatexCommand \index{-\/-dumprange}
8984
8985 \end_inset 
8986
8987
8988 \series default 
8989 \size large 
8990  
8991 \size default 
8992 Will create a dump of iCode's, after live range analysis
8993 \begin_inset LatexCommand \index{Live range analysis}
8994
8995 \end_inset 
8996
8997 , into a file named 
8998 \emph on 
8999 <source filename>.dumprange.
9000 \layout List
9001 \labelwidthstring 00.00.0000
9002
9003
9004 \series bold 
9005 -
9006 \begin_inset ERT
9007 status Collapsed
9008
9009 \layout Standard
9010
9011 \backslash 
9012 /
9013 \end_inset 
9014
9015 -dumlrange
9016 \begin_inset LatexCommand \index{-\/-dumlrange}
9017
9018 \end_inset 
9019
9020
9021 \series default 
9022  Will dump the life ranges
9023 \begin_inset LatexCommand \index{Live range analysis}
9024
9025 \end_inset 
9026
9027  for all symbols.
9028 \layout List
9029 \labelwidthstring 00.00.0000
9030
9031
9032 \series bold 
9033 -
9034 \begin_inset ERT
9035 status Collapsed
9036
9037 \layout Standard
9038
9039 \backslash 
9040 /
9041 \end_inset 
9042
9043 -dumpregassign
9044 \begin_inset LatexCommand \index{-\/-dumpregassign}
9045
9046 \end_inset 
9047
9048
9049 \bar under 
9050  
9051 \series default 
9052 \bar default 
9053 Will create a dump of iCode's, after register assignment
9054 \begin_inset LatexCommand \index{Register assignment}
9055
9056 \end_inset 
9057
9058 , into a file named 
9059 \emph on 
9060 <source filename>.dumprassgn.
9061 \layout List
9062 \labelwidthstring 00.00.0000
9063
9064
9065 \series bold 
9066 -
9067 \begin_inset ERT
9068 status Collapsed
9069
9070 \layout Standard
9071
9072 \backslash 
9073 /
9074 \end_inset 
9075
9076 -dumplrange
9077 \begin_inset LatexCommand \index{-\/-dumplrange}
9078
9079 \end_inset 
9080
9081
9082 \series default 
9083  Will create a dump of the live ranges of iTemp's
9084 \layout List
9085 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9086
9087
9088 \series bold 
9089 -
9090 \begin_inset ERT
9091 status Collapsed
9092
9093 \layout Standard
9094
9095 \backslash 
9096 /
9097 \end_inset 
9098
9099 -dumpall
9100 \begin_inset LatexCommand \index{-\/-dumpall}
9101
9102 \end_inset 
9103
9104
9105 \size large 
9106 \bar under 
9107  
9108 \series default 
9109 \size default 
9110 \bar default 
9111 Will cause all the above mentioned dumps to be created.
9112 \layout Subsection
9113
9114 Redirecting output on Windows Shells
9115 \layout Standard
9116 \added_space_bottom bigskip 
9117 By default SDCC writes it's error messages to 
9118 \begin_inset Quotes sld
9119 \end_inset 
9120
9121 standard error
9122 \begin_inset Quotes srd
9123 \end_inset 
9124
9125 .
9126  To force all messages to 
9127 \begin_inset Quotes sld
9128 \end_inset 
9129
9130 standard output
9131 \begin_inset Quotes srd
9132 \end_inset 
9133
9134  use 
9135 \series bold 
9136 -
9137 \series default 
9138 \emph on 
9139
9140 \begin_inset ERT
9141 status Collapsed
9142
9143 \layout Standard
9144
9145 \backslash 
9146 /
9147 \end_inset 
9148
9149
9150 \series bold 
9151 \emph default 
9152 -
9153 \series default 
9154 use-stdout
9155 \begin_inset LatexCommand \index{-\/-use-stdout}
9156
9157 \end_inset 
9158
9159 .
9160  Additionally, if you happen to have visual studio installed in your windows
9161  machine, you can use it to compile your sources using a custom build and
9162  the SDCC -
9163 \emph on 
9164
9165 \begin_inset ERT
9166 status Collapsed
9167
9168 \layout Standard
9169
9170 \backslash 
9171 /
9172 \end_inset 
9173
9174
9175 \emph default 
9176 -vc
9177 \begin_inset LatexCommand \index{-\/-vc}
9178
9179 \end_inset 
9180
9181  option.
9182  Something like this should work:
9183 \newline 
9184
9185 \newline 
9186
9187 \series bold 
9188 c:
9189 \backslash 
9190 sdcc
9191 \backslash 
9192 bin
9193 \backslash 
9194 sdcc.exe -
9195 \series default 
9196 \emph on 
9197
9198 \begin_inset ERT
9199 status Collapsed
9200
9201 \layout Standard
9202
9203 \backslash 
9204 /
9205 \end_inset 
9206
9207
9208 \series bold 
9209 \emph default 
9210 -vc -
9211 \series default 
9212 \emph on 
9213
9214 \begin_inset ERT
9215 status Collapsed
9216
9217 \layout Standard
9218
9219 \backslash 
9220 /
9221 \end_inset 
9222
9223
9224 \series bold 
9225 \emph default 
9226 -model-large -c $(InputPath)
9227 \layout Section
9228
9229 Environment variables
9230 \begin_inset LatexCommand \index{Environment variables}
9231
9232 \end_inset 
9233
9234
9235 \layout Standard
9236
9237 SDCC recognizes the following environment variables:
9238 \layout List
9239 \labelwidthstring 00.00.0000
9240
9241
9242 \series bold 
9243 SDCC_LEAVE_SIGNALS
9244 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9245
9246 \end_inset 
9247
9248
9249 \series default 
9250  SDCC installs a signal handler
9251 \begin_inset LatexCommand \index{signal handler}
9252
9253 \end_inset 
9254
9255  to be able to delete temporary files after an user break (^C) or an exception.
9256  If this environment variable is set, SDCC won't install the signal handler
9257  in order to be able to debug SDCC.
9258 \layout List
9259 \labelwidthstring 00.00.0000
9260
9261
9262 \series bold 
9263 TMP,\SpecialChar ~
9264 TEMP,\SpecialChar ~
9265 TMPDIR
9266 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9267
9268 \end_inset 
9269
9270
9271 \series default 
9272  Path, where temporary files will be created.
9273  The order of the variables is the search order.
9274  In a standard *nix environment these variables are not set, and there's
9275  no need to set them.
9276  On Windows it's recommended to set one of them.
9277 \layout List
9278 \labelwidthstring 00.00.0000
9279
9280
9281 \series bold 
9282 SDCC_HOME
9283 \begin_inset LatexCommand \index{SDCC\_HOME}
9284
9285 \end_inset 
9286
9287
9288 \series default 
9289  Path, see section 
9290 \begin_inset LatexCommand \ref{sub:Install-paths}
9291
9292 \end_inset 
9293
9294 \SpecialChar ~
9295
9296 \begin_inset Quotes sld
9297 \end_inset 
9298
9299  Install Paths
9300 \begin_inset Quotes srd
9301 \end_inset 
9302
9303 .
9304 \layout List
9305 \labelwidthstring 00.00.0000
9306
9307
9308 \series bold 
9309 SDCC_INCLUDE
9310 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9311
9312 \end_inset 
9313
9314
9315 \series default 
9316  Path, see section 
9317 \begin_inset LatexCommand \ref{sub:Search-Paths}
9318
9319 \end_inset 
9320
9321 \SpecialChar ~
9322
9323 \begin_inset Quotes sld
9324 \end_inset 
9325
9326 Search Paths
9327 \begin_inset Quotes srd
9328 \end_inset 
9329
9330 .
9331 \layout List
9332 \labelwidthstring 00.00.0000
9333
9334
9335 \series bold 
9336 SDCC_LIB
9337 \begin_inset LatexCommand \index{SDCC\_LIB}
9338
9339 \end_inset 
9340
9341
9342 \series default 
9343  Path, see section 
9344 \begin_inset LatexCommand \ref{sub:Search-Paths}
9345
9346 \end_inset 
9347
9348 \SpecialChar ~
9349
9350 \begin_inset Quotes sld
9351 \end_inset 
9352
9353 Search Paths
9354 \begin_inset Quotes srd
9355 \end_inset 
9356
9357 ..
9358 \layout Standard
9359 \added_space_bottom bigskip 
9360 There are some more environment variables recognized by SDCC, but these
9361  are solely used for debugging purposes.
9362  They can change or disappear very quickly, and will never be documented.
9363 \layout Section
9364
9365 Storage Class Language Extensions
9366 \layout Subsection
9367
9368 MCS51/DS390 Storage Class
9369 \begin_inset LatexCommand \index{Storage class}
9370
9371 \end_inset 
9372
9373  Language Extensions
9374 \layout Standard
9375
9376 In addition to the ANSI storage classes SDCC allows the following MCS51
9377  specific storage classes:
9378 \layout Subsubsection
9379
9380 data
9381 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9382
9383 \end_inset 
9384
9385
9386 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9387
9388 \end_inset 
9389
9390  / near
9391 \begin_inset LatexCommand \index{near (storage class)}
9392
9393 \end_inset 
9394
9395
9396 \begin_inset LatexCommand \index{\_\_near (storage class)}
9397
9398 \end_inset 
9399
9400
9401 \layout Standard
9402
9403 This is the 
9404 \series bold 
9405 default
9406 \series default 
9407  storage class for the Small Memory model (
9408 \emph on 
9409 data
9410 \emph default 
9411  and 
9412 \emph on 
9413 near
9414 \emph default 
9415  or the more ANSI-C compliant forms 
9416 \emph on 
9417 __data
9418 \emph default 
9419  and 
9420 \emph on 
9421 __near
9422 \emph default 
9423  can be used synonymously).
9424  Variables declared with this storage class will be allocated in the directly
9425  addressable portion of the internal RAM of a 8051, e.g.:
9426 \layout Verse
9427
9428
9429 \family typewriter 
9430 __data unsigned char test_data;
9431 \layout Standard
9432
9433 Writing 0x01 to this variable generates the assembly code:
9434 \layout Verse
9435
9436
9437 \family typewriter 
9438 75*00 01\SpecialChar ~
9439 \SpecialChar ~
9440 \SpecialChar ~
9441 mov\SpecialChar ~
9442 \SpecialChar ~
9443 _test_data,#0x01
9444 \layout Subsubsection
9445
9446 xdata
9447 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9448
9449 \end_inset 
9450
9451
9452 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9453
9454 \end_inset 
9455
9456  / far
9457 \begin_inset LatexCommand \index{far (storage class)}
9458
9459 \end_inset 
9460
9461
9462 \begin_inset LatexCommand \index{\_\_far (storage class)}
9463
9464 \end_inset 
9465
9466
9467 \layout Standard
9468
9469 Variables declared with this storage class will be placed in the external
9470  RAM.
9471  This is the 
9472 \series bold 
9473 default
9474 \series default 
9475  storage class for the Large Memory model, e.g.:
9476 \layout Verse
9477
9478
9479 \family typewriter 
9480 __xdata unsigned char test_xdata;
9481 \layout Standard
9482
9483 Writing 0x01 to this variable generates the assembly code:
9484 \layout Verse
9485
9486
9487 \family typewriter 
9488 90s00r00\SpecialChar ~
9489 \SpecialChar ~
9490 \SpecialChar ~
9491 mov\SpecialChar ~
9492 \SpecialChar ~
9493 dptr,#_test_xdata 
9494 \newline 
9495 74\SpecialChar ~
9496 01\SpecialChar ~
9497 \SpecialChar ~
9498 \SpecialChar ~
9499 \SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 mov\SpecialChar ~
9503 \SpecialChar ~
9504 a,#0x01 
9505 \newline 
9506 F0\SpecialChar ~
9507 \SpecialChar ~
9508 \SpecialChar ~
9509 \SpecialChar ~
9510 \SpecialChar ~
9511 \SpecialChar ~
9512 \SpecialChar ~
9513 \SpecialChar ~
9514 \SpecialChar ~
9515 movx\SpecialChar ~
9516 @dptr,a 
9517 \layout Subsubsection
9518
9519 idata
9520 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9521
9522 \end_inset 
9523
9524
9525 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9526
9527 \end_inset 
9528
9529
9530 \layout Standard
9531
9532 Variables declared with this storage class will be allocated into the indirectly
9533  addressable portion of the internal ram of a 8051, e.g.:
9534 \layout Verse
9535
9536
9537 \family typewriter 
9538 __idata unsigned char test_idata;
9539 \layout Standard
9540
9541 Writing 0x01 to this variable generates the assembly code:
9542 \layout Verse
9543
9544
9545 \family typewriter 
9546 78r00\SpecialChar ~
9547 \SpecialChar ~
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 \SpecialChar ~
9553 mov\SpecialChar ~
9554 \SpecialChar ~
9555 r0,#_test_idata
9556 \newline 
9557 76\SpecialChar ~
9558 01\SpecialChar ~
9559 \SpecialChar ~
9560 \SpecialChar ~
9561 \SpecialChar ~
9562 \SpecialChar ~
9563 \SpecialChar ~
9564 \SpecialChar ~
9565 mov\SpecialChar ~
9566 \SpecialChar ~
9567 @r0,#0x01
9568 \layout Standard
9569
9570 Please note, the first 128 byte of idata physically access the same RAM
9571  as the data memory.
9572  The original 8051 had 128 byte idata memory, nowadays most devices have
9573  256 byte idata memory.
9574  The stack
9575 \begin_inset LatexCommand \index{stack}
9576
9577 \end_inset 
9578
9579  is located in idata memory.
9580 \layout Subsubsection
9581
9582 pdata
9583 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9584
9585 \end_inset 
9586
9587
9588 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9589
9590 \end_inset 
9591
9592
9593 \layout Standard
9594
9595 Paged xdata access is just as straightforward as using the other addressing
9596  modes of a 8051.
9597  It is typically located at the start of xdata and has a maximum size of
9598  256 bytes.
9599  The following example writes 0x01 to the pdata variable.
9600  Please note, pdata access physically accesses xdata memory.
9601  The high byte of the address is determined by port P2 
9602 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9603
9604 \end_inset 
9605
9606 (or in case of some 8051 variants by a separate Special Function Register,
9607  see section 
9608 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9609
9610 \end_inset 
9611
9612 ).
9613  This is the 
9614 \series bold 
9615 default
9616 \series default 
9617  storage class for the Medium Memory model, e.g.:
9618 \layout Verse
9619
9620
9621 \family typewriter 
9622 __pdata unsigned char test_pdata;
9623 \layout Standard
9624
9625 Writing 0x01 to this variable generates the assembly code:
9626 \layout Verse
9627
9628
9629 \family typewriter 
9630 78r00\SpecialChar ~
9631 \SpecialChar ~
9632 \SpecialChar ~
9633 \SpecialChar ~
9634 \SpecialChar ~
9635 \SpecialChar ~
9636 mov r0,#_test_pdata
9637 \newline 
9638 74 01\SpecialChar ~
9639 \SpecialChar ~
9640 \SpecialChar ~
9641 \SpecialChar ~
9642 \SpecialChar ~
9643 \SpecialChar ~
9644 mov a,#0x01 
9645 \newline 
9646 F2\SpecialChar ~
9647 \SpecialChar ~
9648 \SpecialChar ~
9649 \SpecialChar ~
9650 \SpecialChar ~
9651 \SpecialChar ~
9652 \SpecialChar ~
9653 \SpecialChar ~
9654 \SpecialChar ~
9655 movx @r0,a
9656 \layout Standard
9657
9658 If the -
9659 \begin_inset ERT
9660 status Collapsed
9661
9662 \layout Standard
9663
9664 \backslash 
9665 /
9666 \end_inset 
9667
9668 -xstack
9669 \begin_inset LatexCommand \index{-\/-xstack}
9670
9671 \end_inset 
9672
9673  option is used the pdata memory area is followed by the xstack memory area
9674  and the sum of their sizes is limited to 256 bytes.
9675 \layout Subsubsection
9676
9677 code
9678 \begin_inset LatexCommand \index{code}
9679
9680 \end_inset 
9681
9682
9683 \begin_inset LatexCommand \index{\_\_code}
9684
9685 \end_inset 
9686
9687
9688 \layout Standard
9689
9690 'Variables' declared with this storage class will be placed in the code
9691  memory:
9692 \layout Verse
9693
9694
9695 \family typewriter 
9696 __code unsigned char test_code;
9697 \layout Standard
9698
9699 Read access to this variable generates the assembly code:
9700 \layout Verse
9701
9702
9703 \family typewriter 
9704 90s00r6F\SpecialChar ~
9705 \SpecialChar ~
9706 \SpecialChar ~
9707 mov dptr,#_test_code
9708 \newline 
9709 E4\SpecialChar ~
9710 \SpecialChar ~
9711 \SpecialChar ~
9712 \SpecialChar ~
9713 \SpecialChar ~
9714 \SpecialChar ~
9715 \SpecialChar ~
9716 \SpecialChar ~
9717 \SpecialChar ~
9718 clr a
9719 \newline 
9720 93\SpecialChar ~
9721 \SpecialChar ~
9722 \SpecialChar ~
9723 \SpecialChar ~
9724 \SpecialChar ~
9725 \SpecialChar ~
9726 \SpecialChar ~
9727 \SpecialChar ~
9728 \SpecialChar ~
9729 movc a,@a+dptr 
9730 \layout Standard
9731
9732
9733 \family typewriter 
9734 char
9735 \family default 
9736  indexed arrays of characters in code memory can be accessed efficiently:
9737 \layout Verse
9738
9739
9740 \family typewriter 
9741 __code char test_array[] = {'c','h','e','a','p'}; 
9742 \layout Standard
9743
9744 Read access to this array using an 8-bit unsigned index generates the assembly
9745  code:
9746 \layout Verse
9747
9748
9749 \family typewriter 
9750 E5*00\SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 \SpecialChar ~
9756 mov a,_index 
9757 \layout Verse
9758
9759
9760 \family typewriter 
9761 90s00r41\SpecialChar ~
9762 \SpecialChar ~
9763 \SpecialChar ~
9764 mov dptr,#_test_array
9765 \layout Verse
9766
9767
9768 \family typewriter 
9769 93\SpecialChar ~
9770 \SpecialChar ~
9771 \SpecialChar ~
9772 \SpecialChar ~
9773 \SpecialChar ~
9774 \SpecialChar ~
9775 \SpecialChar ~
9776 \SpecialChar ~
9777 \SpecialChar ~
9778 movc a,@a+dptr 
9779 \layout Subsubsection
9780
9781 bit
9782 \begin_inset LatexCommand \index{bit}
9783
9784 \end_inset 
9785
9786
9787 \begin_inset LatexCommand \index{\_\_bit}
9788
9789 \end_inset 
9790
9791
9792 \layout Standard
9793
9794 This is a data-type and a storage class specifier.
9795  When a variable is declared as a bit, it is allocated into the bit addressable
9796  memory of 8051, e.g.:
9797 \layout Verse
9798
9799
9800 \family typewriter 
9801 __bit test_bit;
9802 \layout Standard
9803
9804 Writing 1 to this variable generates the assembly code:
9805 \layout Verse
9806
9807
9808 \family typewriter 
9809 D2*00\SpecialChar ~
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 setb\SpecialChar ~
9817 _test_bit
9818 \layout Standard
9819
9820 The bit addressable memory consists of 128 bits which are located from 0x20
9821  to 0x2f in data memory.
9822  
9823 \newline 
9824 Apart from this 8051 specific storage class most architectures support ANSI-C
9825  bitfields
9826 \begin_inset LatexCommand \index{bitfields}
9827
9828 \end_inset 
9829
9830
9831 \begin_inset Foot
9832 collapsed false
9833
9834 \layout Standard
9835
9836 Not really meant as examples, but nevertheless showing what bitfields are
9837  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9838 \end_inset 
9839
9840 .
9841  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9842  signed modifier are implemented as unsigned.
9843 \layout Subsubsection
9844
9845 sfr
9846 \begin_inset LatexCommand \index{sfr}
9847
9848 \end_inset 
9849
9850
9851 \begin_inset LatexCommand \index{\_\_sfr}
9852
9853 \end_inset 
9854
9855  / sfr16
9856 \begin_inset LatexCommand \index{sfr16}
9857
9858 \end_inset 
9859
9860
9861 \begin_inset LatexCommand \index{\_\_sfr16}
9862
9863 \end_inset 
9864
9865  / sfr32
9866 \begin_inset LatexCommand \index{sfr32}
9867
9868 \end_inset 
9869
9870
9871 \begin_inset LatexCommand \index{\_\_sfr32}
9872
9873 \end_inset 
9874
9875  / sbit
9876 \begin_inset LatexCommand \index{\_\_sbit}
9877
9878 \end_inset 
9879
9880
9881 \begin_inset LatexCommand \index{sbit}
9882
9883 \end_inset 
9884
9885
9886 \layout Standard
9887
9888 Like the bit keyword, 
9889 \emph on 
9890 sfr / sfr16 / sfr32 / sbit 
9891 \emph default 
9892 signify both a data-type and storage class, they are used to describe the
9893  
9894 \emph on 
9895 s
9896 \emph default 
9897 pecial 
9898 \emph on 
9899 f
9900 \emph default 
9901 unction 
9902 \emph on 
9903 r
9904 \emph default 
9905 egisters and 
9906 \emph on 
9907 s
9908 \emph default 
9909 pecial 
9910 \emph on 
9911 bit
9912 \emph default 
9913  variables of a 8051, eg:
9914 \layout Verse
9915
9916
9917 \family typewriter 
9918 __sfr __at
9919 \begin_inset LatexCommand \index{at}
9920
9921 \end_inset 
9922
9923
9924 \begin_inset LatexCommand \index{\_\_at}
9925
9926 \end_inset 
9927
9928  (0x80) P0;\SpecialChar ~
9929  /* special function register P0 at location 0x80 */
9930 \newline 
9931
9932 \newline 
9933 /* 16 bit special function register combination for timer 0
9934 \newline 
9935 \SpecialChar ~
9936 \SpecialChar ~
9937  with the high byte at location 0x8C and the low byte at location 0x8A */
9938 \newline 
9939 __sfr16 __at (0x8C8A) TMR0;
9940 \newline 
9941
9942 \newline 
9943 __sbit __at
9944 \begin_inset LatexCommand \index{at}
9945
9946 \end_inset 
9947
9948
9949 \begin_inset LatexCommand \index{\_\_at}
9950
9951 \end_inset 
9952
9953  (0xd7) CY;\SpecialChar ~
9954  /* CY (Carry Flag
9955 \begin_inset LatexCommand \index{Flags}
9956
9957 \end_inset 
9958
9959
9960 \begin_inset LatexCommand \index{Carry flag}
9961
9962 \end_inset 
9963
9964 ) */
9965 \layout Standard
9966
9967 Special function registers which are located on an address dividable by
9968  8 are bit-addressable, an
9969 \emph on 
9970  sbit
9971 \emph default 
9972  addresses a specific bit within these sfr.
9973 \newline 
9974 16 Bit and 32 bit special function register combinations which require a
9975  certain access order are better not declared using 
9976 \emph on 
9977 sfr16
9978 \emph default 
9979  or 
9980 \emph on 
9981 sfr32.
9982
9983 \emph default 
9984  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9985  this is not guaranteed.
9986 \newline 
9987
9988 \layout Standard
9989
9990 Please note, if you use a header file which was written for another compiler
9991  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
9992  likely be 
9993 \emph on 
9994 not 
9995 \emph default 
9996 compatible.
9997  Specifically the syntax 
9998 \family typewriter 
9999 \SpecialChar ~
10000 sfr P0 = 0x80;\SpecialChar ~
10001
10002 \family default 
10003  is compiled 
10004 \emph on 
10005 without warning
10006 \emph default 
10007  by SDCC to an assignment of 0x80 to a variable called P0 
10008 \family typewriter 
10009
10010 \begin_inset Marginal
10011 collapsed true
10012
10013 \layout Standard
10014
10015
10016 \series bold 
10017 \SpecialChar ~
10018 !
10019 \end_inset 
10020
10021 .
10022  
10023 \family default 
10024 Nevertheless it is possible to write header files
10025 \begin_inset LatexCommand \index{Header files}
10026
10027 \end_inset 
10028
10029
10030 \begin_inset LatexCommand \index{Include files}
10031
10032 \end_inset 
10033
10034  which can be shared among different compilers (see section 
10035 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10036
10037 \end_inset 
10038
10039 ).
10040  
10041 \layout Subsubsection
10042
10043 Pointers
10044 \begin_inset LatexCommand \index{Pointer}
10045
10046 \end_inset 
10047
10048  to MCS51/DS390 specific memory spaces
10049 \layout Standard
10050
10051 SDCC allows (via language extensions) pointers to explicitly point to any
10052  of the memory spaces
10053 \begin_inset LatexCommand \index{Memory model}
10054
10055 \end_inset 
10056
10057  of the 8051.
10058  In addition to the explicit pointers, the compiler uses (by default) generic
10059  pointers which can be used to point to any of the memory spaces.
10060 \newline 
10061
10062 \newline 
10063 Pointer declaration examples:
10064 \layout Verse
10065
10066
10067 \family typewriter 
10068 /* pointer physically in internal ram pointing to object in external ram
10069  */ 
10070 \newline 
10071 __xdata unsigned char * __data p;
10072 \newline 
10073
10074 \newline 
10075 /* pointer physically in external ram pointing to object in internal ram
10076  */ 
10077 \newline 
10078 __data unsigned char * __xdata p;
10079 \newline 
10080
10081 \newline 
10082 /* pointer physically in code rom pointing to data in xdata space */ 
10083 \newline 
10084 __xdata unsigned char * __code p;
10085 \newline 
10086
10087 \newline 
10088 /* pointer physically in code space pointing to data in code space */ 
10089 \newline 
10090 __code unsigned char * __code p;
10091 \newline 
10092
10093 \newline 
10094 /* generic pointer physically located in xdata space */
10095 \newline 
10096 unsigned char * __xdata p;
10097 \newline 
10098
10099 \newline 
10100 /* generic pointer physically located in default memory space */
10101 \newline 
10102 unsigned char * p;
10103 \newline 
10104
10105 \newline 
10106 /* the following is a function pointer
10107 \begin_inset LatexCommand \index{function pointer}
10108
10109 \end_inset 
10110
10111  physically located in data space */
10112 \newline 
10113 char (* __data fp)(void);
10114 \layout Standard
10115
10116 Well you get the idea.
10117  
10118 \newline 
10119
10120 \newline 
10121 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10122 \emph on 
10123 generic
10124 \emph default 
10125  pointers.
10126  
10127 \size small 
10128
10129 \newline 
10130
10131 \newline 
10132
10133 \size default 
10134 The highest order byte of the 
10135 \emph on 
10136 generic
10137 \emph default 
10138  pointers contains the data space information.
10139  Assembler support routines are called whenever data is stored or retrieved
10140  using 
10141 \emph on 
10142 generic
10143 \emph default 
10144  pointers.
10145  These are useful for developing reusable library
10146 \begin_inset LatexCommand \index{Libraries}
10147
10148 \end_inset 
10149
10150  routines.
10151  Explicitly specifying the pointer
10152 \begin_inset LatexCommand \index{pointer}
10153
10154 \end_inset 
10155
10156  type will generate the most efficient code.
10157 \layout Subsubsection
10158
10159 Notes on MCS51 memory
10160 \begin_inset LatexCommand \index{MCS51 memory}
10161
10162 \end_inset 
10163
10164  layout
10165 \layout Standard
10166
10167 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10168  RAM memory which is structured as follows:
10169 \newline 
10170
10171 \newline 
10172 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10173  
10174 \newline 
10175 - Bytes 20-2F - 16 bytes to hold 128 bit
10176 \begin_inset LatexCommand \index{bit}
10177
10178 \end_inset 
10179
10180  variables and, 
10181 \newline 
10182 - Bytes 30-7F - 80 bytes for general purpose use.
10183 \newline 
10184
10185 \layout Standard
10186
10187 Additionally some members of the MCS51 family may have up to 128 bytes of
10188  additional, indirectly addressable, internal RAM memory (
10189 \emph on 
10190 idata
10191 \emph default 
10192
10193 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10194
10195 \end_inset 
10196
10197
10198 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10199
10200 \end_inset 
10201
10202 ).
10203  Furthermore, some chips may have some built in external memory (
10204 \emph on 
10205 xdata
10206 \emph default 
10207
10208 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10209
10210 \end_inset 
10211
10212
10213 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10214
10215 \end_inset 
10216
10217 ) which should not be confused with the internal, directly addressable RAM
10218  memory (
10219 \emph on 
10220 data
10221 \emph default 
10222
10223 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10224
10225 \end_inset 
10226
10227
10228 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10229
10230 \end_inset 
10231
10232 ).
10233  Sometimes this built in 
10234 \emph on 
10235 xdata
10236 \emph default 
10237  memory has to be activated before using it (you can probably find this
10238  information on the datasheet of the microcontroller your are using, see
10239  also section 
10240 \begin_inset LatexCommand \ref{sub:Startup-Code}
10241
10242 \end_inset 
10243
10244 \SpecialChar ~
10245 Startup-Code).
10246 \layout Standard
10247
10248 Normally SDCC will only use the first bank
10249 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10250
10251 \end_inset 
10252
10253  of registers (register bank 0), but it is possible to specify that other
10254  banks of registers (keyword 
10255 \emph on 
10256 using
10257 \emph default 
10258  
10259 \emph on 
10260
10261 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10262
10263 \end_inset 
10264
10265
10266 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10267
10268 \end_inset 
10269
10270
10271 \emph default 
10272 ) should be used in interrupt
10273 \begin_inset LatexCommand \index{interrupt}
10274
10275 \end_inset 
10276
10277
10278 \begin_inset LatexCommand \index{\_\_interrupt}
10279
10280 \end_inset 
10281
10282  routines.
10283  By default, the compiler will place the stack after the last byte of allocated
10284  memory for variables.
10285  For example, if the first 2 banks of registers are used, and only four
10286  bytes are used for 
10287 \emph on 
10288 data
10289 \emph default 
10290  variables, it will position the base of the internal stack at address 20
10291  (0x14).
10292  This implies that as the stack
10293 \begin_inset LatexCommand \index{stack}
10294
10295 \end_inset 
10296
10297  grows, it will use up the remaining register banks, and the 16 bytes used
10298  by the 128 bit variables, and 80 bytes for general purpose use.
10299  If any bit variables are used, the data variables will be placed in unused
10300  register banks and after the byte holding the last bit variable.
10301  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10302  (two bytes used), 
10303 \emph on 
10304 data
10305 \emph default 
10306  variables will be placed starting from address 0x10 to 0x20 and continue
10307  at address 0x22.
10308  You can also use -
10309 \begin_inset ERT
10310 status Collapsed
10311
10312 \layout Standard
10313
10314 \backslash 
10315 /
10316 \end_inset 
10317
10318 -data-loc
10319 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10320
10321 \end_inset 
10322
10323  to specify the start address of the 
10324 \emph on 
10325 data
10326 \emph default 
10327  and -
10328 \begin_inset ERT
10329 status Collapsed
10330
10331 \layout Standard
10332
10333 \backslash 
10334 /
10335 \end_inset 
10336
10337 -iram-size
10338 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10339
10340 \end_inset 
10341
10342  to specify the size of the total internal RAM (
10343 \emph on 
10344 data
10345 \emph default 
10346 +
10347 \emph on 
10348 idata
10349 \emph default 
10350 ).
10351  
10352 \newline 
10353
10354 \layout Standard
10355
10356 By default the 8051 linker will place the stack after the last byte of (i)data
10357  variables.
10358  Option -
10359 \begin_inset ERT
10360 status Collapsed
10361
10362 \layout Standard
10363
10364 \backslash 
10365 /
10366 \end_inset 
10367
10368 -stack-loc
10369 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10370
10371 \end_inset 
10372
10373  allows you to specify the start of the stack, i.e.
10374  you could start it after any data in the general purpose area.
10375  If your microcontroller has additional indirectly addressable internal
10376  RAM (
10377 \emph on 
10378 idata
10379 \emph default 
10380 ) you can place the stack on it.
10381  You may also need to use -
10382 \begin_inset ERT
10383 status Collapsed
10384
10385 \layout Standard
10386
10387 \backslash 
10388 /
10389 \end_inset 
10390
10391 -xdata-loc
10392 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10393
10394 \end_inset 
10395
10396  to set the start address of the external RAM (
10397 \emph on 
10398 xdata
10399 \emph default 
10400 ) and -
10401 \begin_inset ERT
10402 status Collapsed
10403
10404 \layout Standard
10405
10406 \backslash 
10407 /
10408 \end_inset 
10409
10410 -xram-size
10411 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10412
10413 \end_inset 
10414
10415  to specify its size.
10416  Same goes for the code memory, using -
10417 \begin_inset ERT
10418 status Collapsed
10419
10420 \layout Standard
10421
10422 \backslash 
10423 /
10424 \end_inset 
10425
10426 -code-loc
10427 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10428
10429 \end_inset 
10430
10431  and -
10432 \begin_inset ERT
10433 status Collapsed
10434
10435 \layout Standard
10436
10437 \backslash 
10438 /
10439 \end_inset 
10440
10441 -code-size
10442 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10443
10444 \end_inset 
10445
10446 .
10447  If in doubt, don't specify any options and see if the resulting memory
10448  layout is appropriate, then you can adjust it.
10449 \layout Standard
10450 \added_space_bottom bigskip 
10451 The linker generates two files with memory allocation information.
10452  The first, with extension .map
10453 \begin_inset LatexCommand \index{<file>.map}
10454
10455 \end_inset 
10456
10457  shows all the variables and segments.
10458  The second with extension .mem
10459 \begin_inset LatexCommand \index{<file>.mem}
10460
10461 \end_inset 
10462
10463  shows the final memory layout.
10464  The linker will complain either if memory segments overlap, there is not
10465  enough memory, or there is not enough space for stack.
10466  If you get any linking warnings and/or errors related to stack or segments
10467  allocation, take a look at either the .map or .mem files to find out what
10468  the problem is.
10469  The .mem file may even suggest a solution to the problem.
10470 \layout Subsection
10471
10472 Z80/Z180 Storage Class
10473 \begin_inset LatexCommand \index{Z80!Storage class}
10474
10475 \end_inset 
10476
10477  Language Extensions
10478 \layout Subsubsection
10479
10480 sfr
10481 \begin_inset LatexCommand \index{sfr}
10482
10483 \end_inset 
10484
10485
10486 \begin_inset LatexCommand \index{\_\_sfr}
10487
10488 \end_inset 
10489
10490  (in/out to 8-bit addresses)
10491 \layout Standard
10492
10493 The Z80
10494 \begin_inset LatexCommand \index{Z80}
10495
10496 \end_inset 
10497
10498  family has separate address spaces for memory and 
10499 \emph on 
10500 i
10501 \emph default 
10502 nput/
10503 \emph on 
10504 o
10505 \emph default 
10506 utput memory.
10507  I/O memory
10508 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10509
10510 \end_inset 
10511
10512
10513 \begin_inset LatexCommand \index{Z80!I/O memory}
10514
10515 \end_inset 
10516
10517
10518 \begin_inset LatexCommand \index{Z180!I/O memory}
10519
10520 \end_inset 
10521
10522  is accessed with special instructions, e.g.:
10523 \layout Verse
10524
10525
10526 \family typewriter 
10527 sfr at 0x78 IoPort;\SpecialChar ~
10528 \SpecialChar ~
10529 /* define a var in I/O space at 78h called IoPort */
10530  
10531 \layout Standard
10532
10533 Writing 0x01 to this variable generates the assembly code:
10534 \layout Verse
10535
10536
10537 \family typewriter 
10538 3E 01\SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 \SpecialChar ~
10542 \SpecialChar ~
10543 \SpecialChar ~
10544 ld a,#0x01
10545 \newline 
10546 D3 78\SpecialChar ~
10547 \SpecialChar ~
10548 \SpecialChar ~
10549 \SpecialChar ~
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 out (_IoPort),a 
10553 \layout Subsubsection
10554
10555 banked sfr
10556 \begin_inset LatexCommand \index{sfr}
10557
10558 \end_inset 
10559
10560
10561 \begin_inset LatexCommand \index{\_\_sfr}
10562
10563 \end_inset 
10564
10565  (in/out to 16-bit addresses)
10566 \layout Standard
10567
10568 The keyword 
10569 \emph on 
10570 banked
10571 \emph default 
10572  is used to support 16 bit addresses in I/O memory e.g.:
10573 \layout Verse
10574
10575
10576 \family typewriter 
10577 sfr banked at
10578 \begin_inset LatexCommand \index{at}
10579
10580 \end_inset 
10581
10582
10583 \begin_inset LatexCommand \index{\_\_at}
10584
10585 \end_inset 
10586
10587  0x123 IoPort; 
10588 \layout Standard
10589
10590 Writing 0x01 to this variable generates the assembly code:
10591 \layout Verse
10592
10593
10594 \family typewriter 
10595 01 23 01\SpecialChar ~
10596 \SpecialChar ~
10597 \SpecialChar ~
10598 ld bc,#_IoPort
10599 \newline 
10600 3E 01\SpecialChar ~
10601 \SpecialChar ~
10602 \SpecialChar ~
10603 \SpecialChar ~
10604 \SpecialChar ~
10605 \SpecialChar ~
10606 ld a,#0x01 
10607 \newline 
10608 ED 79\SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 \SpecialChar ~
10612 \SpecialChar ~
10613 \SpecialChar ~
10614 out (c),a 
10615 \layout Subsubsection
10616
10617 sfr
10618 \begin_inset LatexCommand \index{sfr}
10619
10620 \end_inset 
10621
10622
10623 \begin_inset LatexCommand \index{\_\_sfr}
10624
10625 \end_inset 
10626
10627  (in0/out0 to 8 bit addresses on Z180
10628 \begin_inset LatexCommand \index{Z180}
10629
10630 \end_inset 
10631
10632 /HD64180
10633 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10634
10635 \end_inset 
10636
10637 )
10638 \layout Standard
10639 \added_space_bottom bigskip 
10640 The compiler option -
10641 \begin_inset ERT
10642 status Collapsed
10643
10644 \layout Standard
10645
10646 \backslash 
10647 /
10648 \end_inset 
10649
10650 -portmode
10651 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10652
10653 \end_inset 
10654
10655 =180 (80) and a compiler #pragma\SpecialChar ~
10656 portmode
10657 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10658
10659 \end_inset 
10660
10661  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10662 ns 
10663 \family typewriter 
10664 in0/out0
10665 \family default 
10666  instead of 
10667 \family typewriter 
10668 in/out
10669 \family default 
10670 .
10671  If you include the file z180.h this will be set automatically.
10672 \layout Subsection
10673
10674 HC08 Storage Class
10675 \begin_inset LatexCommand \index{HC08!Storage class}
10676
10677 \end_inset 
10678
10679  Language Extensions
10680 \layout Subsubsection
10681
10682 data
10683 \begin_inset LatexCommand \index{data (hc08 storage class)}
10684
10685 \end_inset 
10686
10687
10688 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10689
10690 \end_inset 
10691
10692  
10693 \layout Standard
10694
10695 The data storage class declares a variable that resides in the first 256
10696  bytes of memory (the direct page).
10697  The HC08
10698 \begin_inset LatexCommand \index{HC08}
10699
10700 \end_inset 
10701
10702  is most efficient at accessing variables (especially pointers) stored here.
10703 \layout Subsubsection
10704
10705 xdata
10706 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10707
10708 \end_inset 
10709
10710
10711 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10712
10713 \end_inset 
10714
10715  
10716 \layout Standard
10717 \added_space_bottom bigskip 
10718 The xdata storage class declares a variable that can reside anywhere in
10719  memory.
10720  This is the default if no storage class is specified.
10721  
10722 \layout Section
10723
10724 Absolute Addressing
10725 \begin_inset LatexCommand \index{Absolute addressing}
10726
10727 \end_inset 
10728
10729
10730 \layout Standard
10731
10732 Data items can be assigned an absolute address with the 
10733 \emph on 
10734 at
10735 \begin_inset LatexCommand \index{at}
10736
10737 \end_inset 
10738
10739
10740 \begin_inset LatexCommand \index{\_\_at}
10741
10742 \end_inset 
10743
10744  <address>
10745 \emph default 
10746  keyword, in addition to a storage class, e.g.:
10747 \layout Verse
10748
10749
10750 \family typewriter 
10751 xdata
10752 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10753
10754 \end_inset 
10755
10756
10757 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10758
10759 \end_inset 
10760
10761  at
10762 \begin_inset LatexCommand \index{at}
10763
10764 \end_inset 
10765
10766
10767 \begin_inset LatexCommand \index{\_\_at}
10768
10769 \end_inset 
10770
10771  0x7ffe unsigned int chksum;
10772 \layout Standard
10773
10774 or, better conforming to ISO/IEC 9899 C:
10775 \layout Verse
10776
10777
10778 \family typewriter 
10779 __xdata __at (0x7ffe) unsigned int chksum;
10780 \layout Standard
10781
10782 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10783  of the external ram.
10784  The compiler does 
10785 \emph on 
10786 not
10787 \emph default 
10788  reserve any space for variables declared in this way
10789 \begin_inset Marginal
10790 collapsed true
10791
10792 \layout Standard
10793
10794
10795 \series bold 
10796 \SpecialChar ~
10797 !
10798 \end_inset 
10799
10800  (they are implemented with an equate in the assembler).
10801  Thus it is left to the programmer to make sure there are no overlaps with
10802  other variables that are declared without the absolute address.
10803  The assembler listing file (.lst
10804 \begin_inset LatexCommand \index{<file>.lst}
10805
10806 \end_inset 
10807
10808 ) and the linker output files (.rst
10809 \begin_inset LatexCommand \index{<file>.rst}
10810
10811 \end_inset 
10812
10813 ) and (.map
10814 \begin_inset LatexCommand \index{<file>.map}
10815
10816 \end_inset 
10817
10818 ) are good places to look for such overlaps.
10819  Variables with an absolute address are 
10820 \emph on 
10821 not
10822 \begin_inset Marginal
10823 collapsed true
10824
10825 \layout Standard
10826
10827
10828 \series bold 
10829 \SpecialChar ~
10830 !
10831 \end_inset 
10832
10833
10834 \emph default 
10835  initialized
10836 \begin_inset LatexCommand \index{Variable initialization}
10837
10838 \end_inset 
10839
10840 .
10841 \layout Standard
10842
10843 In case of memory mapped I/O devices the keyword 
10844 \emph on 
10845 volatile
10846 \emph default 
10847  has to be used to tell the compiler that accesses might not be removed:
10848 \layout Verse
10849
10850
10851 \family typewriter 
10852 volatile
10853 \begin_inset LatexCommand \index{volatile}
10854
10855 \end_inset 
10856
10857  __xdata
10858 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10859
10860 \end_inset 
10861
10862  __at
10863 \begin_inset LatexCommand \index{at}
10864
10865 \end_inset 
10866
10867  (0x8000) unsigned char PORTA_8255;
10868 \layout Standard
10869
10870 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10871 r) array
10872 \family typewriter 
10873 \size footnotesize 
10874
10875 \begin_inset LatexCommand \index{Aligned array}
10876
10877 \end_inset 
10878
10879
10880 \family default 
10881 \size default 
10882  starts at a block (256 byte) boundary
10883 \begin_inset LatexCommand \index{block boundary}
10884
10885 \end_inset 
10886
10887  (section 
10888 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10889
10890 \end_inset 
10891
10892  has an example).
10893 \newline 
10894 Absolute addresses can be specified for variables in all storage classes,
10895  e.g.:
10896 \layout Verse
10897
10898
10899 \family typewriter 
10900 __bit
10901 \begin_inset LatexCommand \index{bit}
10902
10903 \end_inset 
10904
10905  __at
10906 \begin_inset LatexCommand \index{at}
10907
10908 \end_inset 
10909
10910  (0x02) bvar;
10911 \layout Standard
10912
10913 The above example will allocate the variable at offset 0x02 in the bit-addressab
10914 le space.
10915  There is no real advantage to assigning absolute addresses to variables
10916  in this manner, unless you want strict control over all the variables allocated.
10917  One possible use would be to write hardware portable code.
10918  For example, if you have a routine that uses one or more of the microcontroller
10919  I/O pins, and such pins are different for two different hardwares, you
10920  can declare the I/O pins in your routine using:
10921 \layout Verse
10922
10923
10924 \family typewriter 
10925 extern volatile
10926 \begin_inset LatexCommand \index{volatile}
10927
10928 \end_inset 
10929
10930  __bit MOSI;\SpecialChar ~
10931 \SpecialChar ~
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 /* master out, slave in */
10935 \newline 
10936 extern volatile __bit MISO;\SpecialChar ~
10937 \SpecialChar ~
10938 \SpecialChar ~
10939 \SpecialChar ~
10940 /* master in, slave out */
10941 \newline 
10942 extern volatile __bit MCLK;\SpecialChar ~
10943 \SpecialChar ~
10944 \SpecialChar ~
10945 \SpecialChar ~
10946 /* master clock */
10947 \newline 
10948
10949 \newline 
10950 /* Input and Output of a byte on a 3-wire serial bus.
10951 \newline 
10952 \SpecialChar ~
10953 \SpecialChar ~
10954 \SpecialChar ~
10955 If needed adapt polarity of clock, polarity of data and bit order
10956 \newline 
10957 \SpecialChar ~
10958 */
10959 \newline 
10960 unsigned char spi_io(unsigned char out_byte) 
10961 \newline 
10962
10963 \newline 
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 \SpecialChar ~
10968 unsigned char i=8;
10969 \newline 
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 do { 
10975 \newline 
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 \SpecialChar ~
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 MOSI = out_byte & 0x80; 
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 \SpecialChar ~
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 out_byte <<= 1;
10995 \newline 
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 \SpecialChar ~
11001 \SpecialChar ~
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 MCLK = 1; 
11005 \newline 
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 /* _asm nop _endasm; */\SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 \SpecialChar ~
11022 /* for slow peripherals */
11023 \newline 
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 \SpecialChar ~
11032 if(MISO) 
11033 \newline 
11034 \SpecialChar ~
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 out_byte += 1; 
11047 \newline 
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 \SpecialChar ~
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 MCLK = 0; 
11057 \newline 
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 \SpecialChar ~
11062 } while(--i);
11063 \newline 
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 return out_byte; 
11069 \newline 
11070 }
11071 \layout Standard
11072
11073 Then, someplace in the code for the first hardware you would use
11074 \layout Verse
11075
11076
11077 \family typewriter 
11078 __bit __at
11079 \begin_inset LatexCommand \index{at}
11080
11081 \end_inset 
11082
11083
11084 \begin_inset LatexCommand \index{\_\_at}
11085
11086 \end_inset 
11087
11088  (0x80) MOSI;\SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 /* I/O port 0, bit 0 */
11093 \newline 
11094 __bit __at (0x81) MISO;\SpecialChar ~
11095 \SpecialChar ~
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 /* I/O port 0, bit 1 */
11099 \newline 
11100 __bit __at (0x82) MCLK;\SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 /* I/O port 0, bit 2 */
11105 \layout Standard
11106
11107 Similarly, for the second hardware you would use
11108 \layout Verse
11109
11110
11111 \family typewriter 
11112 __bit __at (0x83) MOSI;\SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 /* I/O port 0, bit 3 */
11117 \newline 
11118 __bit __at (0x91) MISO;\SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 /* I/O port 1, bit 1 */
11123 \newline 
11124 __bit
11125 \begin_inset LatexCommand \index{bit}
11126
11127 \end_inset 
11128
11129  __at (0x92) MCLK;\SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 /* I/O port 1, bit 2 */
11134 \layout Standard
11135 \added_space_bottom bigskip 
11136 and you can use the same hardware dependent routine without changes, as
11137  for example in a library.
11138  This is somehow similar to sbit, but only one absolute address has to be
11139  specified in the whole project.
11140 \layout Section
11141
11142 Parameters
11143 \begin_inset LatexCommand \index{Parameters}
11144
11145 \end_inset 
11146
11147
11148 \begin_inset LatexCommand \index{function parameter}
11149
11150 \end_inset 
11151
11152  & Local Variables
11153 \begin_inset LatexCommand \index{local variables}
11154
11155 \end_inset 
11156
11157
11158 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11159
11160 \end_inset 
11161
11162
11163 \layout Standard
11164
11165 Automatic (local) variables and parameters to functions can either be placed
11166  on the stack or in data-space.
11167  The default action of the compiler is to place these variables in the internal
11168  RAM (for small model) or external RAM (for large model).
11169  This in fact makes them similar to 
11170 \emph on 
11171 static
11172 \begin_inset LatexCommand \index{static}
11173
11174 \end_inset 
11175
11176
11177 \emph default 
11178  so by default functions are non-reentrant
11179 \begin_inset LatexCommand \index{reentrant}
11180
11181 \end_inset 
11182
11183 .
11184  
11185 \newline 
11186
11187 \newline 
11188 They can be placed on the stack
11189 \begin_inset LatexCommand \index{stack}
11190
11191 \end_inset 
11192
11193  by using the
11194 \emph on 
11195  -
11196 \begin_inset ERT
11197 status Collapsed
11198
11199 \layout Standard
11200
11201 \backslash 
11202 /
11203 \end_inset 
11204
11205 -stack-auto
11206 \begin_inset LatexCommand \index{-\/-stack-auto}
11207
11208 \end_inset 
11209
11210
11211 \emph default 
11212  option, by using 
11213 \emph on 
11214 #pragma\SpecialChar ~
11215 stackauto
11216 \emph default 
11217
11218 \begin_inset LatexCommand \index{\#pragma stackauto}
11219
11220 \end_inset 
11221
11222  or by using the 
11223 \emph on 
11224 reentrant
11225 \begin_inset LatexCommand \index{reentrant}
11226
11227 \end_inset 
11228
11229
11230 \emph default 
11231  keyword in the function declaration, e.g.:
11232 \layout Verse
11233
11234
11235 \family typewriter 
11236 unsigned char foo(char i) __reentrant 
11237 \newline 
11238
11239 \newline 
11240 \SpecialChar ~
11241 \SpecialChar ~
11242 \SpecialChar ~
11243 \SpecialChar ~
11244 ...
11245  
11246 \newline 
11247 }
11248 \layout Standard
11249
11250 Since stack space on 8051 is limited, the 
11251 \emph on 
11252 reentrant 
11253 \emph default 
11254 keyword or the
11255 \emph on 
11256  -
11257 \begin_inset ERT
11258 status Collapsed
11259
11260 \layout Standard
11261
11262 \backslash 
11263 /
11264 \end_inset 
11265
11266 -stack-auto
11267 \emph default 
11268  option should be used sparingly.
11269  Note that the reentrant keyword just means that the parameters & local
11270  variables will be allocated to the stack, it 
11271 \emph on 
11272 does not
11273 \emph default 
11274  mean that the function is register bank
11275 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11276
11277 \end_inset 
11278
11279  independent.
11280 \newline 
11281
11282 \newline 
11283 Local variables
11284 \begin_inset LatexCommand \index{local variables}
11285
11286 \end_inset 
11287
11288  can be assigned storage classes and absolute
11289 \begin_inset LatexCommand \index{Absolute addressing}
11290
11291 \end_inset 
11292
11293  addresses, e.g.: 
11294 \layout Verse
11295
11296
11297 \family typewriter 
11298 unsigned char foo() 
11299 \newline 
11300 {
11301 \newline 
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 __xdata unsigned char i;
11307 \newline 
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 \SpecialChar ~
11311 \SpecialChar ~
11312 __bit bvar;
11313 \newline 
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 __data __at
11319 \begin_inset LatexCommand \index{at}
11320
11321 \end_inset 
11322
11323  (0x31) unsigned char j;
11324 \newline 
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 \SpecialChar ~
11329 ...
11330  
11331 \newline 
11332 }
11333 \layout Standard
11334
11335 In the above example the variable 
11336 \emph on 
11337 i
11338 \emph default 
11339  will be allocated in the external ram, 
11340 \emph on 
11341 bvar
11342 \emph default 
11343  in bit addressable space and
11344 \emph on 
11345  j
11346 \emph default 
11347  in internal ram.
11348  When compiled with 
11349 \emph on 
11350 -
11351 \begin_inset ERT
11352 status Collapsed
11353
11354 \layout Standard
11355
11356 \backslash 
11357 /
11358 \end_inset 
11359
11360 -stack-auto
11361 \emph default 
11362  or when a function is declared as 
11363 \emph on 
11364 reentrant
11365 \emph default 
11366  this should only be done for static variables.
11367 \layout Standard
11368
11369 Parameters
11370 \begin_inset LatexCommand \index{function parameter}
11371
11372 \end_inset 
11373
11374  however are not allowed any storage class
11375 \begin_inset LatexCommand \index{Storage class}
11376
11377 \end_inset 
11378
11379 , (storage classes for parameters will be ignored), their allocation is
11380  governed by the memory model in use, and the reentrancy options.
11381 \layout Standard
11382
11383 It is however allowed to use bit parameters in reentrant functions and also
11384  non-static local bit variables are supported.
11385  Efficient use is limited to 8 semi-bitregisters in bit space.
11386  They are pushed and popped to stack
11387 \begin_inset LatexCommand \index{stack}
11388
11389 \end_inset 
11390
11391  as a single byte just like the normal registers.
11392 \layout Section
11393
11394 Overlaying
11395 \begin_inset LatexCommand \label{sub:Overlaying}
11396
11397 \end_inset 
11398
11399
11400 \begin_inset LatexCommand \index{Overlaying}
11401
11402 \end_inset 
11403
11404
11405 \layout Standard
11406
11407 For non-reentrant
11408 \begin_inset LatexCommand \index{reentrant}
11409
11410 \end_inset 
11411
11412  functions SDCC will try to reduce internal ram space usage by overlaying
11413  parameters and local variables of a function (if possible).
11414  Parameters and local variables
11415 \begin_inset LatexCommand \index{local variables}
11416
11417 \end_inset 
11418
11419  of a function will be allocated to an overlayable segment if the function
11420  has 
11421 \emph on 
11422 no other function calls and the function is non-reentrant and the memory
11423  model
11424 \begin_inset LatexCommand \index{Memory model}
11425
11426 \end_inset 
11427
11428  is small.
11429
11430 \emph default 
11431  If an explicit storage class
11432 \begin_inset LatexCommand \index{Storage class}
11433
11434 \end_inset 
11435
11436  is specified for a local variable, it will NOT be overlayed.
11437 \layout Standard
11438
11439 Note that the compiler (not the linkage editor) makes the decision for overlayin
11440 g the data items.
11441  Functions that are called from an interrupt service routine
11442 \begin_inset Marginal
11443 collapsed true
11444
11445 \layout Standard
11446
11447
11448 \series bold 
11449 !
11450 \end_inset 
11451
11452  should be preceded by a #pragma\SpecialChar ~
11453 nooverlay
11454 \begin_inset LatexCommand \index{\#pragma nooverlay}
11455
11456 \end_inset 
11457
11458  if they are not reentrant.
11459 \layout Standard
11460
11461 Also note that the compiler does not do any processing of inline assembler
11462  code, so the compiler might incorrectly assign local variables and parameters
11463  of a function into the overlay segment if the inline assembler code calls
11464  other c-functions that might use the overlay.
11465  In that case the #pragma\SpecialChar ~
11466 nooverlay should be used.
11467 \layout Standard
11468
11469 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11470 tion
11471 \begin_inset LatexCommand \index{Multiplication}
11472
11473 \end_inset 
11474
11475  or division
11476 \begin_inset LatexCommand \index{Division}
11477
11478 \end_inset 
11479
11480  will NOT be overlayed since these are implemented using external functions,
11481  e.g.:
11482 \layout Verse
11483
11484
11485 \family typewriter 
11486 #pragma save 
11487 \newline 
11488 #pragma nooverlay
11489 \begin_inset LatexCommand \index{\#pragma nooverlay}
11490
11491 \end_inset 
11492
11493  
11494 \newline 
11495 void set_error(unsigned char errcd) 
11496 \newline 
11497 {
11498 \newline 
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 P3 = errcd;
11504 \newline 
11505
11506 \newline 
11507 #pragma restore 
11508 \newline 
11509
11510 \newline 
11511 void some_isr () __interrupt
11512 \begin_inset LatexCommand \index{interrupt}
11513
11514 \end_inset 
11515
11516  (2)
11517 \newline 
11518 {
11519 \newline 
11520 \SpecialChar ~
11521 \SpecialChar ~
11522 \SpecialChar ~
11523 \SpecialChar ~
11524 ...
11525 \newline 
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 set_error(10);
11531 \newline 
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 \SpecialChar ~
11535 \SpecialChar ~
11536 ...
11537  
11538 \newline 
11539 }
11540 \layout Standard
11541 \added_space_bottom bigskip 
11542 In the above example the parameter 
11543 \emph on 
11544 errcd
11545 \emph default 
11546  for the function 
11547 \emph on 
11548 set_error
11549 \emph default 
11550  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11551 nooverlay was
11552  not present, this could cause unpredictable runtime behavior when called
11553  from an interrupt service routine.
11554  The #pragma\SpecialChar ~
11555 nooverlay ensures that the parameters and local variables for
11556  the function are NOT overlayed.
11557 \layout Section
11558
11559 Interrupt Service Routines
11560 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11561
11562 \end_inset 
11563
11564
11565 \layout Subsection
11566
11567 General Information
11568 \layout Standard
11569
11570 SDCC allows 
11571 \emph on 
11572 i
11573 \emph default 
11574 nterrupt 
11575 \emph on 
11576 s
11577 \emph default 
11578 ervice 
11579 \emph on 
11580 r
11581 \emph default 
11582 outines to be coded in C, with some extended keywords.
11583 \layout Verse
11584
11585
11586 \family typewriter 
11587 void timer_isr (void) __interrupt (1) __using (1) 
11588 \newline 
11589
11590 \newline 
11591 \SpecialChar ~
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 ...
11596  
11597 \newline 
11598 }
11599 \layout Standard
11600
11601 The optional number following the 
11602 \emph on 
11603 interrupt
11604 \begin_inset LatexCommand \index{interrupt}
11605
11606 \end_inset 
11607
11608
11609 \begin_inset LatexCommand \index{\_\_interrupt}
11610
11611 \end_inset 
11612
11613
11614 \emph default 
11615  keyword is the interrupt number this routine will service.
11616  When present, the compiler will insert a call to this routine in the interrupt
11617  vector table
11618 \begin_inset LatexCommand \index{interrupt vector table}
11619
11620 \end_inset 
11621
11622  for the interrupt number specified.
11623  If you have multiple source files in your project, interrupt service routines
11624  can be present in any of them, but a prototype of the isr MUST be present
11625  or included in the file that contains the function 
11626 \emph on 
11627 main
11628 \emph default 
11629 .
11630  The optional (8051 specific) keyword 
11631 \emph on 
11632 using
11633 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11634
11635 \end_inset 
11636
11637
11638 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11639
11640 \end_inset 
11641
11642
11643 \emph default 
11644  can be used to tell the compiler to use the specified register bank when
11645  generating code for this function.
11646  
11647 \newline 
11648 Interrupt service routines open the door for some very interesting bugs:
11649 \layout Subsubsection
11650
11651
11652 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11653
11654 \end_inset 
11655
11656 Common interrupt pitfall: variable not declared 
11657 \emph on 
11658 volatile
11659 \layout Standard
11660
11661 If an interrupt service routine changes variables which are accessed by
11662  other functions these variables have to be declared 
11663 \emph on 
11664 volatile
11665 \emph default 
11666
11667 \begin_inset LatexCommand \index{volatile}
11668
11669 \end_inset 
11670
11671 .
11672  See 
11673 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11674
11675 \end_inset 
11676
11677  .
11678 \layout Subsubsection
11679
11680
11681 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11682
11683 \end_inset 
11684
11685 Common interrupt pitfall: 
11686 \emph on 
11687 non-atomic access
11688 \layout Standard
11689
11690 If the access to these variables is not 
11691 \emph on 
11692 atomic
11693 \begin_inset LatexCommand \index{atomic}
11694
11695 \end_inset 
11696
11697
11698 \emph default 
11699  (i.e.
11700  the processor needs more than one instruction for the access and could
11701  be interrupted while accessing the variable) the interrupt must be disabled
11702  during the access to avoid inconsistent data.
11703  
11704 \newline 
11705 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11706  should be protected by disabling interrupts.
11707  You're not automatically on the safe side if you use 8 bit variables though.
11708  We need an example here: f.e.
11709  on the 8051 the harmless looking 
11710 \begin_inset Quotes srd
11711 \end_inset 
11712
11713
11714 \family typewriter 
11715 flags\SpecialChar ~
11716 |=\SpecialChar ~
11717 0x80;
11718 \family default 
11719
11720 \begin_inset Quotes sld
11721 \end_inset 
11722
11723  is not atomic if 
11724 \family typewriter 
11725 flags
11726 \family default 
11727  resides in xdata.
11728  Setting 
11729 \begin_inset Quotes srd
11730 \end_inset 
11731
11732
11733 \family typewriter 
11734 flags\SpecialChar ~
11735 |=\SpecialChar ~
11736 0x40;
11737 \family default 
11738
11739 \begin_inset Quotes sld
11740 \end_inset 
11741
11742  from within an interrupt routine might get lost if the interrupt occurs
11743  at the wrong time.
11744  
11745 \begin_inset Quotes sld
11746 \end_inset 
11747
11748
11749 \family typewriter 
11750 counter\SpecialChar ~
11751 +=\SpecialChar ~
11752 8;
11753 \family default 
11754
11755 \begin_inset Quotes srd
11756 \end_inset 
11757
11758  is not atomic on the 8051 even if 
11759 \family typewriter 
11760 counter
11761 \family default 
11762  is located in data memory.
11763 \newline 
11764 Bugs like these are hard to reproduce and can cause a lot of trouble.
11765  
11766 \layout Subsubsection
11767
11768
11769 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11770
11771 \end_inset 
11772
11773 Common interrupt pitfall: 
11774 \emph on 
11775 stack overflow
11776 \layout Standard
11777
11778 The return address and the registers used in the interrupt service routine
11779  are saved on the stack
11780 \begin_inset LatexCommand \index{stack}
11781
11782 \end_inset 
11783
11784  so there must be sufficient stack space.
11785  If there isn't variables or registers (or even the return address itself)
11786  will be corrupted.
11787  This 
11788 \emph on 
11789 stack overflow
11790 \emph default 
11791
11792 \begin_inset LatexCommand \index{stack overflow}
11793
11794 \end_inset 
11795
11796  is most likely to happen if the interrupt occurs during the 
11797 \begin_inset Quotes sld
11798 \end_inset 
11799
11800 deepest
11801 \begin_inset Quotes srd
11802 \end_inset 
11803
11804  subroutine when the stack is already in use for f.e.
11805  many return addresses.
11806 \layout Subsubsection
11807
11808
11809 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11810
11811 \end_inset 
11812
11813 Common interrupt pitfall: 
11814 \emph on 
11815 use of non-reentrant functions
11816 \layout Standard
11817
11818 A special note here, int (16 bit) and long (32 bit) integer division
11819 \begin_inset LatexCommand \index{Division}
11820
11821 \end_inset 
11822
11823 , multiplication
11824 \begin_inset LatexCommand \index{Multiplication}
11825
11826 \end_inset 
11827
11828  & modulus
11829 \begin_inset LatexCommand \index{Modulus}
11830
11831 \end_inset 
11832
11833  and floating-point
11834 \begin_inset LatexCommand \index{Floating point support}
11835
11836 \end_inset 
11837
11838  operations are implemented using external support routines.
11839  If an interrupt service routine needs to do any of these operations then
11840  the support routines (as mentioned in a following section) will have to
11841  be recompiled using the
11842 \emph on 
11843  -
11844 \begin_inset ERT
11845 status Collapsed
11846
11847 \layout Standard
11848
11849 \backslash 
11850 /
11851 \end_inset 
11852
11853 -stack-auto
11854 \begin_inset LatexCommand \index{-\/-stack-auto}
11855
11856 \end_inset 
11857
11858
11859 \emph default 
11860  option and the source file will need to be compiled using the 
11861 \emph on 
11862 -
11863 \begin_inset ERT
11864 status Collapsed
11865
11866 \layout Standard
11867
11868 \backslash 
11869 /
11870 \end_inset 
11871
11872 -int-long-reent
11873 \emph default 
11874
11875 \begin_inset LatexCommand \index{-\/-int-long-reent}
11876
11877 \end_inset 
11878
11879  compiler option.
11880  
11881 \newline 
11882 Note, the type promotion
11883 \begin_inset LatexCommand \index{type promotion}
11884
11885 \end_inset 
11886
11887  required by ANSI C can cause 16 bit routines to be used
11888 \begin_inset Marginal
11889 collapsed true
11890
11891 \layout Standard
11892
11893
11894 \series bold 
11895 \SpecialChar ~
11896 !
11897 \end_inset 
11898
11899  without the programmer being aware of it.
11900  See f.e.
11901  the cast 
11902 \family typewriter 
11903 (unsigned char)(tail-1)
11904 \family default 
11905  within the if clause in section 
11906 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11907
11908 \end_inset 
11909
11910 .
11911 \layout Standard
11912 \added_space_bottom bigskip 
11913 Calling other functions from an interrupt service routine is not recommended,
11914  avoid it if possible.
11915  Note that when some function is called from an interrupt service routine
11916  it should be preceded by a #pragma\SpecialChar ~
11917 nooverlay
11918 \begin_inset LatexCommand \index{\#pragma nooverlay}
11919
11920 \end_inset 
11921
11922  if it is not reentrant.
11923  Furthermore nonreentrant functions should not be called from the main program
11924  while the interrupt service routine might be active.
11925  They also must not be called from low priority interrupt service routines
11926  while a high priority interrupt service routine might be active.
11927  You could use semaphores or make the function
11928 \emph on 
11929  critical
11930 \emph default 
11931  if all parameters are passed in registers.
11932 \newline 
11933  Also see section 
11934 \begin_inset LatexCommand \ref{sub:Overlaying}
11935
11936 \end_inset 
11937
11938 \SpecialChar ~
11939 about Overlaying and section 
11940 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11941
11942 \end_inset 
11943
11944 \SpecialChar ~
11945 about Functions using private register banks.
11946 \layout Subsection
11947
11948 MCS51/DS390 Interrupt Service Routines
11949 \layout Standard
11950
11951 Interrupt
11952 \begin_inset LatexCommand \index{interrupt}
11953
11954 \end_inset 
11955
11956  numbers and the corresponding address & descriptions for the Standard 8051/8052
11957  are listed below.
11958  SDCC will automatically adjust the 
11959 \begin_inset LatexCommand \index{interrupt vector table}
11960
11961 \end_inset 
11962
11963  to the maximum interrupt number specified.
11964 \newline 
11965
11966 \layout Standard
11967 \align center 
11968
11969 \begin_inset  Tabular
11970 <lyxtabular version="3" rows="9" columns="3">
11971 <features>
11972 <column alignment="center" valignment="top" leftline="true" width="0in">
11973 <column alignment="left" valignment="top" leftline="true" width="0in">
11974 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11975 <row topline="true" bottomline="true">
11976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11977 \begin_inset Text
11978
11979 \layout Standard
11980
11981 Interrupt #
11982 \end_inset 
11983 </cell>
11984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11985 \begin_inset Text
11986
11987 \layout Standard
11988
11989 Description
11990 \end_inset 
11991 </cell>
11992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11993 \begin_inset Text
11994
11995 \layout Standard
11996
11997 Vector Address
11998 \end_inset 
11999 </cell>
12000 </row>
12001 <row topline="true">
12002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12003 \begin_inset Text
12004
12005 \layout Standard
12006
12007 0
12008 \end_inset 
12009 </cell>
12010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12011 \begin_inset Text
12012
12013 \layout Standard
12014
12015 External 0
12016 \end_inset 
12017 </cell>
12018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12019 \begin_inset Text
12020
12021 \layout Standard
12022
12023 0x0003
12024 \end_inset 
12025 </cell>
12026 </row>
12027 <row topline="true">
12028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12029 \begin_inset Text
12030
12031 \layout Standard
12032
12033 1
12034 \end_inset 
12035 </cell>
12036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12037 \begin_inset Text
12038
12039 \layout Standard
12040
12041 Timer 0
12042 \end_inset 
12043 </cell>
12044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12045 \begin_inset Text
12046
12047 \layout Standard
12048
12049 0x000b
12050 \end_inset 
12051 </cell>
12052 </row>
12053 <row topline="true">
12054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12055 \begin_inset Text
12056
12057 \layout Standard
12058
12059 2
12060 \end_inset 
12061 </cell>
12062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12063 \begin_inset Text
12064
12065 \layout Standard
12066
12067 External 1
12068 \end_inset 
12069 </cell>
12070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12071 \begin_inset Text
12072
12073 \layout Standard
12074
12075 0x0013
12076 \end_inset 
12077 </cell>
12078 </row>
12079 <row topline="true">
12080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12081 \begin_inset Text
12082
12083 \layout Standard
12084
12085 3
12086 \end_inset 
12087 </cell>
12088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12089 \begin_inset Text
12090
12091 \layout Standard
12092
12093 Timer 1
12094 \end_inset 
12095 </cell>
12096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12097 \begin_inset Text
12098
12099 \layout Standard
12100
12101 0x001b
12102 \end_inset 
12103 </cell>
12104 </row>
12105 <row topline="true">
12106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12107 \begin_inset Text
12108
12109 \layout Standard
12110
12111 4
12112 \end_inset 
12113 </cell>
12114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12115 \begin_inset Text
12116
12117 \layout Standard
12118
12119 Serial
12120 \end_inset 
12121 </cell>
12122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12123 \begin_inset Text
12124
12125 \layout Standard
12126
12127 0x0023
12128 \end_inset 
12129 </cell>
12130 </row>
12131 <row topline="true">
12132 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12133 \begin_inset Text
12134
12135 \layout Standard
12136
12137 5
12138 \end_inset 
12139 </cell>
12140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12141 \begin_inset Text
12142
12143 \layout Standard
12144
12145 Timer 2 (8052)
12146 \end_inset 
12147 </cell>
12148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12149 \begin_inset Text
12150
12151 \layout Standard
12152
12153 0x002b
12154 \end_inset 
12155 </cell>
12156 </row>
12157 <row topline="true">
12158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12159 \begin_inset Text
12160
12161 \layout Standard
12162
12163 ...
12164 \end_inset 
12165 </cell>
12166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12167 \begin_inset Text
12168
12169 \layout Standard
12170
12171 \end_inset 
12172 </cell>
12173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12174 \begin_inset Text
12175
12176 \layout Standard
12177
12178 ...
12179 \end_inset 
12180 </cell>
12181 </row>
12182 <row topline="true" bottomline="true">
12183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12184 \begin_inset Text
12185
12186 \layout Standard
12187
12188 n
12189 \end_inset 
12190 </cell>
12191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12192 \begin_inset Text
12193
12194 \layout Standard
12195
12196 \end_inset 
12197 </cell>
12198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12199 \begin_inset Text
12200
12201 \layout Standard
12202
12203 0x0003 + 8*n
12204 \end_inset 
12205 </cell>
12206 </row>
12207 </lyxtabular>
12208
12209 \end_inset 
12210
12211
12212 \newline 
12213
12214 \layout Standard
12215
12216 If the interrupt service routine is defined without 
12217 \emph on 
12218 using
12219 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12220
12221 \end_inset 
12222
12223
12224 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12225
12226 \end_inset 
12227
12228
12229 \emph default 
12230  a register bank or with register bank 0 (
12231 \emph on 
12232 using
12233 \emph default 
12234  0), the compiler will save the registers used by itself on the stack upon
12235  entry and restore them at exit, however if such an interrupt service routine
12236  calls another function then the entire register bank will be saved on the
12237  stack.
12238  This scheme may be advantageous for small interrupt service routines which
12239  have low register usage.
12240 \layout Standard
12241 \added_space_bottom bigskip 
12242 If the interrupt service routine is defined to be using a specific register
12243  bank then only 
12244 \emph on 
12245 a, b, dptr
12246 \emph default 
12247  & psw are saved and restored, if such an interrupt service routine calls
12248  another function (using another register bank) then the entire register
12249  bank of the called function will be saved on the stack
12250 \begin_inset LatexCommand \index{stack}
12251
12252 \end_inset 
12253
12254 .
12255  This scheme is recommended for larger interrupt service routines.
12256 \layout Subsection
12257
12258 HC08
12259 \begin_inset LatexCommand \index{HC08}
12260
12261 \end_inset 
12262
12263  Interrupt Service Routines
12264 \layout Standard
12265 \added_space_bottom bigskip 
12266 Since the number of interrupts
12267 \begin_inset LatexCommand \index{HC08!interrupt}
12268
12269 \end_inset 
12270
12271  available is chip specific and the interrupt vector table always ends at
12272  the last byte of memory, the interrupt numbers corresponds to the interrupt
12273  vectors in reverse order of address.
12274  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12275  2 will use the interrupt vector at 0xfffa, and so on.
12276  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12277  this way; instead see section 
12278 \begin_inset LatexCommand \ref{sub:Startup-Code}
12279
12280 \end_inset 
12281
12282  for details on customizing startup.
12283 \layout Subsection
12284
12285 Z80 Interrupt Service Routines
12286 \layout Standard
12287
12288 The Z80
12289 \begin_inset LatexCommand \index{Z80}
12290
12291 \end_inset 
12292
12293  uses several different methods for determining the correct interrupt
12294 \begin_inset LatexCommand \index{Z80!interrupt}
12295
12296 \end_inset 
12297
12298  vector depending on the hardware implementation.
12299  Therefore, SDCC ignores the optional interrupt number and does not attempt
12300  to generate an interrupt vector table.
12301 \layout Standard
12302
12303 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12304  instruction to return from the interrupt.
12305  To write an interrupt handler for the non-maskable interrupt, which needs
12306  a RETN instruction instead, add the 
12307 \emph on 
12308 critical
12309 \emph default 
12310  keyword:
12311 \layout Verse
12312
12313
12314 \family typewriter 
12315 void nmi_isr (void) critical interrupt
12316 \newline 
12317
12318 \newline 
12319 \SpecialChar ~
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 \SpecialChar ~
12323 ...
12324  
12325 \newline 
12326 }
12327 \layout Standard
12328 \added_space_bottom bigskip 
12329 However if you need to create a non-interruptable interrupt service routine
12330  you would also require the 
12331 \emph on 
12332 critical
12333 \emph default 
12334  keyword.
12335  To distinguish between this and an nmi_isr you must provide an interrupt
12336  number.
12337 \layout Section
12338
12339 Enabling and Disabling Interrupts
12340 \layout Subsection
12341
12342 Critical Functions and Critical Statements
12343 \layout Standard
12344
12345 A special keyword may be associated with a block or a function declaring
12346  it as 
12347 \emph on 
12348 critical
12349 \emph default 
12350 .
12351  SDCC will generate code to disable all interrupts
12352 \begin_inset LatexCommand \index{interrupt}
12353
12354 \end_inset 
12355
12356  upon entry to a critical function and restore the interrupt enable to the
12357  previous state before returning.
12358  Nesting critical functions will need one additional byte on the stack
12359 \begin_inset LatexCommand \index{stack}
12360
12361 \end_inset 
12362
12363  for each call.
12364 \layout Verse
12365
12366
12367 \family typewriter 
12368 int foo () __critical
12369 \begin_inset LatexCommand \index{critical}
12370
12371 \end_inset 
12372
12373
12374 \begin_inset LatexCommand \index{\_\_critical}
12375
12376 \end_inset 
12377
12378  
12379 \newline 
12380
12381 \newline 
12382 \SpecialChar ~
12383 \SpecialChar ~
12384 \SpecialChar ~
12385 \SpecialChar ~
12386 ...
12387  
12388 \newline 
12389 \SpecialChar ~
12390 \SpecialChar ~
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 ...
12394  
12395 \newline 
12396 }
12397 \layout Standard
12398
12399 The critical attribute maybe used with other attributes like 
12400 \emph on 
12401 reentrant.
12402 \emph default 
12403
12404 \newline 
12405 The keyword 
12406 \emph on 
12407 critical
12408 \emph default 
12409  may also be used to disable interrupts more locally:
12410 \layout Verse
12411
12412
12413 \family typewriter 
12414 __critical{ i++; }
12415 \layout Standard
12416
12417 More than one statement could have been included in the block.
12418 \layout Subsection
12419
12420 Enabling and Disabling Interrupts directly
12421 \layout Standard
12422
12423 Interrupts
12424 \begin_inset LatexCommand \index{interrupt}
12425
12426 \end_inset 
12427
12428  can also be disabled and enabled directly (8051):
12429 \layout Verse
12430
12431
12432 \family typewriter 
12433 EA = 0;\SpecialChar ~
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 \SpecialChar ~
12437 \SpecialChar ~
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 \SpecialChar ~
12442 \SpecialChar ~
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 or:\SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 \SpecialChar ~
12451 \SpecialChar ~
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 \SpecialChar ~
12456 EA_SAVE = EA;
12457 \layout Verse
12458
12459
12460 \family typewriter 
12461 ...\SpecialChar ~
12462 \SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 \SpecialChar ~
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 \SpecialChar ~
12480 \SpecialChar ~
12481 \SpecialChar ~
12482 \SpecialChar ~
12483 \SpecialChar ~
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 \SpecialChar ~
12487 \SpecialChar ~
12488 \SpecialChar ~
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 EA = 0;
12492 \layout Verse
12493
12494
12495 \family typewriter 
12496 EA = 1;\SpecialChar ~
12497 \SpecialChar ~
12498 \SpecialChar ~
12499 \SpecialChar ~
12500 \SpecialChar ~
12501 \SpecialChar ~
12502 \SpecialChar ~
12503 \SpecialChar ~
12504 \SpecialChar ~
12505 \SpecialChar ~
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 \SpecialChar ~
12509 \SpecialChar ~
12510 \SpecialChar ~
12511 \SpecialChar ~
12512 \SpecialChar ~
12513 \SpecialChar ~
12514 \SpecialChar ~
12515 \SpecialChar ~
12516 \SpecialChar ~
12517 \SpecialChar ~
12518 \SpecialChar ~
12519 \SpecialChar ~
12520 \SpecialChar ~
12521 \SpecialChar ~
12522 ...
12523 \layout Verse
12524
12525
12526 \family typewriter 
12527 \SpecialChar ~
12528 \SpecialChar ~
12529 \SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 \SpecialChar ~
12533 \SpecialChar ~
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 \SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 \SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 \SpecialChar ~
12560 EA = EA_SAVE;
12561 \layout Standard
12562
12563 On other architectures which have seperate opcodes for enabling and disabling
12564  interrupts you might want to make use of defines with inline assembly
12565 \begin_inset LatexCommand \index{Assembler routines}
12566
12567 \end_inset 
12568
12569  (HC08
12570 \begin_inset LatexCommand \index{HC08!interrupt}
12571
12572 \end_inset 
12573
12574 ):
12575 \layout Verse
12576
12577
12578 \family typewriter 
12579 #define CLI _asm
12580 \begin_inset LatexCommand \index{\_asm}
12581
12582 \end_inset 
12583
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 cli\SpecialChar ~
12587 \SpecialChar ~
12588 _endasm
12589 \begin_inset LatexCommand \index{\_endasm}
12590
12591 \end_inset 
12592
12593
12594 \layout Verse
12595
12596
12597 \family typewriter 
12598 #define SEI _asm\SpecialChar ~
12599 \SpecialChar ~
12600 sei\SpecialChar ~
12601 \SpecialChar ~
12602 _endasm; 
12603 \layout Verse
12604
12605
12606 \family typewriter 
12607 ...
12608 \layout Standard
12609
12610 Note: it is sometimes sufficient to disable only a specific interrupt source
12611  like f.e.
12612  a timer or serial interrupt by manipulating an 
12613 \emph on 
12614 interrupt mask
12615 \begin_inset LatexCommand \index{interrupt mask}
12616
12617 \end_inset 
12618
12619
12620 \emph default 
12621  register.
12622  
12623 \layout Standard
12624
12625 Usually the time during which interrupts are disabled should be kept as
12626  short as possible.
12627  This minimizes both 
12628 \emph on 
12629 interrupt latency
12630 \emph default 
12631
12632 \begin_inset LatexCommand \index{interrupt latency}
12633
12634 \end_inset 
12635
12636  (the time between the occurrence of the interrupt and the execution of
12637  the first code in the interrupt routine) and 
12638 \emph on 
12639 interrupt jitter
12640 \emph default 
12641
12642 \begin_inset LatexCommand \index{interrupt jitter}
12643
12644 \end_inset 
12645
12646  (the difference between the shortest and the longest interrupt latency).
12647  These really are something different, f.e.
12648  a serial interrupt has to be served before its buffer overruns so it cares
12649  for the maximum interrupt latency, whereas it does not care about jitter.
12650  On a loudspeaker driven via a digital to analog converter which is fed
12651  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12652  a much smaller jitter will be very audible.
12653 \layout Standard
12654
12655 You can reenable interrupts within an interrupt routine and on some architecture
12656 s you can make use of two (or more) levels of 
12657 \emph on 
12658 interrupt priorities
12659 \emph default 
12660
12661 \begin_inset LatexCommand \index{interrupt priority}
12662
12663 \end_inset 
12664
12665 .
12666  On some architectures which don't support interrupt priorities these can
12667  be implemented by manipulating the interrupt mask and reenabling interrupts
12668  within the interrupt routine.
12669  Check there is sufficient space on the stack
12670 \begin_inset LatexCommand \index{stack}
12671
12672 \end_inset 
12673
12674  and don't add complexity unless you have to.
12675  
12676 \layout Subsection
12677
12678 Semaphore
12679 \begin_inset LatexCommand \index{semaphore}
12680
12681 \end_inset 
12682
12683  locking (mcs51/ds390)
12684 \layout Standard
12685
12686 Some architectures (mcs51/ds390) have an atomic
12687 \begin_inset LatexCommand \index{atomic}
12688
12689 \end_inset 
12690
12691  bit test and
12692 \emph on 
12693  
12694 \emph default 
12695 clear
12696 \emph on 
12697  
12698 \emph default 
12699 instruction.
12700  These type of instructions are typically used in preemptive multitasking
12701  systems, where a routine f.e.
12702  claims the use of a data structure ('acquires a lock
12703 \begin_inset LatexCommand \index{lock}
12704
12705 \end_inset 
12706
12707  on it'), makes some modifications and then releases the lock when the data
12708  structure is consistent again.
12709  The instruction may also be used if interrupt and non-interrupt code have
12710  to compete for a resource.
12711  With the atomic bit test and clear instruction interrupts
12712 \begin_inset LatexCommand \index{interrupt}
12713
12714 \end_inset 
12715
12716  don't have to be disabled for the locking operation.
12717  
12718 \layout Standard
12719
12720 SDCC generates this instruction if the source follows this pattern:
12721 \layout Verse
12722
12723
12724 \family typewriter 
12725 volatile
12726 \begin_inset LatexCommand \index{volatile}
12727
12728 \end_inset 
12729
12730  bit resource_is_free; 
12731 \newline 
12732
12733 \newline 
12734 if (resource_is_free) 
12735 \newline 
12736 \SpecialChar ~
12737 \SpecialChar ~
12738
12739 \newline 
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 \SpecialChar ~
12743 \SpecialChar ~
12744 resource_is_free=0; 
12745 \newline 
12746 \SpecialChar ~
12747 \SpecialChar ~
12748 \SpecialChar ~
12749 \SpecialChar ~
12750 ...
12751  
12752 \newline 
12753 \SpecialChar ~
12754 \SpecialChar ~
12755 \SpecialChar ~
12756 \SpecialChar ~
12757 resource_is_free=1;
12758 \newline 
12759 \SpecialChar ~
12760 \SpecialChar ~
12761
12762 \layout Standard
12763
12764 Note, mcs51 and ds390 support only an atomic
12765 \begin_inset LatexCommand \index{atomic}
12766
12767 \end_inset 
12768
12769  bit test and 
12770 \emph on 
12771 clear
12772 \emph default 
12773  instruction (as opposed to atomic bit test and 
12774 \emph on 
12775 set).
12776 \layout Section
12777
12778 Functions using private register banks
12779 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12780
12781 \end_inset 
12782
12783  (mcs51/ds390)
12784 \layout Standard
12785
12786 Some architectures have support for quickly changing register sets.
12787  SDCC supports this feature with the 
12788 \emph on 
12789 using
12790 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12791
12792 \end_inset 
12793
12794
12795 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12796
12797 \end_inset 
12798
12799
12800 \emph default 
12801  attribute (which tells the compiler to use a register bank
12802 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12803
12804 \end_inset 
12805
12806  other than the default bank zero).
12807  It should only be applied to 
12808 \emph on 
12809 interrupt
12810 \begin_inset LatexCommand \index{interrupt}
12811
12812 \end_inset 
12813
12814
12815 \emph default 
12816  functions (see footnote below).
12817  This will in most circumstances make the generated ISR code more efficient
12818  since it will not have to save registers on the stack.
12819 \layout Standard
12820
12821 The 
12822 \emph on 
12823 using
12824 \emph default 
12825  attribute will have no effect on the generated code for a 
12826 \emph on 
12827 non-interrupt
12828 \emph default 
12829  function (but may occasionally be useful anyway
12830 \begin_inset Foot
12831 collapsed false
12832
12833 \layout Standard
12834
12835 possible exception: if a function is called ONLY from 'interrupt' functions
12836  using a particular bank, it can be declared with the same 'using' attribute
12837  as the calling 'interrupt' functions.
12838  For instance, if you have several ISRs using bank one, and all of them
12839  call memcpy(), it might make sense to create a specialized version of memcpy()
12840  'using 1', since this would prevent the ISR from having to save bank zero
12841  to the stack on entry and switch to bank zero before calling the function
12842 \end_inset 
12843
12844 ).
12845 \newline 
12846
12847 \emph on 
12848 (pending: Note, nowadays the 
12849 \emph default 
12850 using
12851 \emph on 
12852  attribute has an effect on
12853 \emph default 
12854  
12855 \emph on 
12856 the generated code for a 
12857 \emph default 
12858 non-interrupt
12859 \emph on 
12860  function
12861 \emph default 
12862 .
12863 \emph on 
12864 )
12865 \layout Standard
12866
12867 An 
12868 \emph on 
12869 interrupt
12870 \emph default 
12871  function using a non-zero bank will assume that it can trash that register
12872  bank, and will not save it.
12873  Since high-priority interrupts
12874 \begin_inset LatexCommand \index{interrupts}
12875
12876 \end_inset 
12877
12878
12879 \begin_inset LatexCommand \index{interrupt priority}
12880
12881 \end_inset 
12882
12883  can interrupt low-priority ones on the 8051 and friends, this means that
12884  if a high-priority ISR 
12885 \emph on 
12886 using
12887 \emph default 
12888  a particular bank occurs while processing a low-priority ISR 
12889 \emph on 
12890 using
12891 \emph default 
12892  the same bank, terrible and bad things can happen.
12893  To prevent this, no single register bank should be 
12894 \emph on 
12895 used
12896 \emph default 
12897  by both a high priority and a low priority ISR.
12898  This is probably most easily done by having all high priority ISRs use
12899  one bank and all low priority ISRs use another.
12900  If you have an ISR which can change priority at runtime, you're on your
12901  own: I suggest using the default bank zero and taking the small performance
12902  hit.
12903 \layout Standard
12904 \added_space_bottom bigskip 
12905 It is most efficient if your ISR calls no other functions.
12906  If your ISR must call other functions, it is most efficient if those functions
12907  use the same bank as the ISR (see note 1 below); the next best is if the
12908  called functions use bank zero.
12909  It is very inefficient to call a function using a different, non-zero bank
12910  from an ISR.
12911  
12912 \layout Section
12913
12914 Startup Code
12915 \begin_inset LatexCommand \label{sub:Startup-Code}
12916
12917 \end_inset 
12918
12919
12920 \begin_inset LatexCommand \index{Startup code}
12921
12922 \end_inset 
12923
12924
12925 \layout Subsection
12926
12927 MCS51/DS390 Startup Code
12928 \layout Standard
12929
12930 The compiler inserts a call to the C routine 
12931 \emph on 
12932 _sdcc_external_startup()
12933 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12934
12935 \end_inset 
12936
12937
12938 \series bold 
12939 \emph default 
12940  
12941 \series default 
12942 at the start of the CODE area.
12943  This routine is in the runtime library
12944 \begin_inset LatexCommand \index{Runtime library}
12945
12946 \end_inset 
12947
12948 .
12949  By default this routine returns 0, if this routine returns a non-zero value,
12950  the static & global variable initialization will be skipped and the function
12951  main will be invoked.
12952  Otherwise static & global variables will be initialized before the function
12953  main is invoked.
12954  You could add a 
12955 \emph on 
12956 _sdcc_external_startup()
12957 \emph default 
12958  routine to your program to override the default if you need to setup hardware
12959  or perform some other critical operation prior to static & global variable
12960  initialization
12961 \begin_inset LatexCommand \index{Variable initialization}
12962
12963 \end_inset 
12964
12965 .
12966  On some mcs51 variants xdata
12967 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12968
12969 \end_inset 
12970
12971  memory has to be explicitly enabled before it can be accessed or if the
12972  watchdog
12973 \begin_inset LatexCommand \index{watchdog}
12974
12975 \end_inset 
12976
12977  needs to be disabled, this is the place to do it.
12978  The startup code clears all internal data memory, 256 bytes by default,
12979  but from 0 to n-1 if 
12980 \emph on 
12981 -
12982 \begin_inset ERT
12983 status Collapsed
12984
12985 \layout Standard
12986
12987 \backslash 
12988 /
12989 \end_inset 
12990
12991 -iram-size
12992 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12993
12994 \end_inset 
12995
12996 n
12997 \emph default 
12998  is used.
12999  (recommended for Chipcon CC1010).
13000 \layout Standard
13001 \added_space_bottom bigskip 
13002 See also the compiler options 
13003 \emph on 
13004 -
13005 \begin_inset ERT
13006 status Collapsed
13007
13008 \layout Standard
13009
13010 \backslash 
13011 /
13012 \end_inset 
13013
13014 -no-xinit
13015 \emph default 
13016 -
13017 \emph on 
13018 opt
13019 \emph default 
13020
13021 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13022
13023 \end_inset 
13024
13025
13026 \emph on 
13027 -
13028 \begin_inset ERT
13029 status Collapsed
13030
13031 \layout Standard
13032
13033 \backslash 
13034 /
13035 \end_inset 
13036
13037 -main-return
13038 \emph default 
13039
13040 \begin_inset LatexCommand \index{-\/-main-return}
13041
13042 \end_inset 
13043
13044  and section 
13045 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13046
13047 \end_inset 
13048
13049  about MCS51-variants.
13050 \layout Subsection
13051
13052 HC08 Startup Code
13053 \layout Standard
13054 \added_space_bottom bigskip 
13055 The HC08
13056 \begin_inset LatexCommand \index{HC08}
13057
13058 \end_inset 
13059
13060  startup code follows the same scheme as the MCS51 startup code.
13061 \layout Subsection
13062
13063 Z80 Startup Code
13064 \layout Standard
13065 \added_space_bottom bigskip 
13066 On the Z80
13067 \begin_inset LatexCommand \index{Z80}
13068
13069 \end_inset 
13070
13071  the startup code is inserted by linking with crt0.o which is generated from
13072  sdcc/device/lib/z80/crt0.s.
13073  If you need a different startup code you can use the compiler option 
13074 \emph on 
13075 -
13076 \series bold 
13077 \emph default 
13078
13079 \begin_inset ERT
13080 status Collapsed
13081
13082 \layout Standard
13083
13084 \backslash 
13085 /
13086 \end_inset 
13087
13088
13089 \series default 
13090 \emph on 
13091 -no-std-crt0
13092 \emph default 
13093
13094 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13095
13096 \end_inset 
13097
13098  and provide your own crt0.o.
13099  
13100 \layout Section
13101
13102 Inline Assembler Code
13103 \begin_inset LatexCommand \index{Assembler routines}
13104
13105 \end_inset 
13106
13107
13108 \layout Subsection
13109
13110 A Step by Step Introduction
13111 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13112
13113 \end_inset 
13114
13115
13116 \layout Standard
13117
13118 Starting from a small snippet of c-code this example shows for the MCS51
13119  how to use inline assembly, access variables, a function parameter and
13120  an array in xdata memory.
13121  The example uses an MCS51 here but is easily adapted for other architectures.
13122  This is a buffer routine which should be optimized:
13123 \layout Verse
13124
13125
13126 \family typewriter 
13127 \size footnotesize 
13128 unsigned char __far
13129 \begin_inset LatexCommand \index{far (storage class)}
13130
13131 \end_inset 
13132
13133
13134 \begin_inset LatexCommand \index{\_\_far (storage class)}
13135
13136 \end_inset 
13137
13138  __at
13139 \begin_inset LatexCommand \index{at}
13140
13141 \end_inset 
13142
13143
13144 \begin_inset LatexCommand \index{\_\_at}
13145
13146 \end_inset 
13147
13148 (0x7f00) buf[0x100];
13149 \begin_inset LatexCommand \index{Aligned array}
13150
13151 \end_inset 
13152
13153
13154 \newline 
13155 unsigned char head, tail;\SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 \SpecialChar ~
13162 \SpecialChar ~
13163 \SpecialChar ~
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 \SpecialChar ~
13171 \SpecialChar ~
13172 /* if interrupts
13173 \begin_inset LatexCommand \index{interrupt}
13174
13175 \end_inset 
13176
13177  are involved see
13178 \newline 
13179 \SpecialChar ~
13180 \SpecialChar ~
13181 \SpecialChar ~
13182 \SpecialChar ~
13183 \SpecialChar ~
13184 \SpecialChar ~
13185 \SpecialChar ~
13186 \SpecialChar ~
13187 \SpecialChar ~
13188 \SpecialChar ~
13189 \SpecialChar ~
13190 \SpecialChar ~
13191 \SpecialChar ~
13192 \SpecialChar ~
13193 \SpecialChar ~
13194 \SpecialChar ~
13195 \SpecialChar ~
13196 \SpecialChar ~
13197 \SpecialChar ~
13198 \SpecialChar ~
13199 \SpecialChar ~
13200 \SpecialChar ~
13201 \SpecialChar ~
13202 \SpecialChar ~
13203 \SpecialChar ~
13204 \SpecialChar ~
13205 \SpecialChar ~
13206 \SpecialChar ~
13207 \SpecialChar ~
13208 \SpecialChar ~
13209 \SpecialChar ~
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 \SpecialChar ~
13214 \SpecialChar ~
13215 \SpecialChar ~
13216 \SpecialChar ~
13217 \SpecialChar ~
13218 \SpecialChar ~
13219 \SpecialChar ~
13220 \SpecialChar ~
13221 \SpecialChar ~
13222 \SpecialChar ~
13223 \SpecialChar ~
13224 section 
13225 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13226
13227 \end_inset 
13228
13229  about
13230 \series bold 
13231  volatile
13232 \series default 
13233  */
13234 \newline 
13235
13236 \newline 
13237 void to_buffer( unsigned char c ) 
13238 \newline 
13239 {
13240 \newline 
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13246 /* cast 
13247 \series bold 
13248 needed
13249 \series default 
13250  to avoid promotion
13251 \begin_inset LatexCommand \index{promotion to signed int}
13252
13253 \end_inset 
13254
13255
13256 \begin_inset LatexCommand \index{type promotion}
13257
13258 \end_inset 
13259
13260  to integer */
13261 \begin_inset Marginal
13262 collapsed true
13263
13264 \layout Standard
13265
13266
13267 \series bold 
13268 \SpecialChar ~
13269 !
13270 \end_inset 
13271
13272
13273 \newline 
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 buf[ head++ ] = c;\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 /* access to a 256 byte aligned array */
13299 \newline 
13300
13301 \layout Standard
13302
13303 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13304  then a corresponding buffer.asm file is generated.
13305  We define a new function 
13306 \family typewriter 
13307 to_buffer_asm()
13308 \family default 
13309  in file buffer.c in which we cut and paste the generated code, removing
13310  unwanted comments and some ':'.
13311  Then add 
13312 \begin_inset Quotes sld
13313 \end_inset 
13314
13315 _asm
13316 \begin_inset Quotes srd
13317 \end_inset 
13318
13319  and 
13320 \begin_inset Quotes sld
13321 \end_inset 
13322
13323 _endasm;
13324 \begin_inset Quotes srd
13325 \end_inset 
13326
13327  to the beginning and the end of the function body:
13328 \layout Verse
13329
13330
13331 \family typewriter 
13332 \size footnotesize 
13333 /* With a cut and paste from the .asm file, we have something to start with.
13334 \newline 
13335 \SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 The function is not yet OK! (registers aren't saved) */ 
13339 \newline 
13340 void to_buffer_asm( unsigned char c ) 
13341 \newline 
13342
13343 \newline 
13344 \SpecialChar ~
13345 \SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 _asm
13349 \begin_inset LatexCommand \index{\_asm}
13350
13351 \end_inset 
13352
13353
13354 \begin_inset LatexCommand \index{\_\_asm}
13355
13356 \end_inset 
13357
13358
13359 \newline 
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 \SpecialChar ~
13363 \SpecialChar ~
13364 mov\SpecialChar ~
13365 \SpecialChar ~
13366 r2,dpl 
13367 \newline 
13368 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13369 /* cast 
13370 \series bold 
13371 needed
13372 \series default 
13373  to avoid promotion
13374 \begin_inset LatexCommand \index{promotion to signed int}
13375
13376 \end_inset 
13377
13378
13379 \begin_inset LatexCommand \index{type promotion}
13380
13381 \end_inset 
13382
13383  to integer */
13384 \newline 
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 mov\SpecialChar ~
13390 \SpecialChar ~
13391 a,_tail 
13392 \newline 
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 dec\SpecialChar ~
13398 \SpecialChar ~
13399
13400 \newline 
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 mov\SpecialChar ~
13406 \SpecialChar ~
13407 r3,a 
13408 \newline 
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 \SpecialChar ~
13412 \SpecialChar ~
13413 mov\SpecialChar ~
13414 \SpecialChar ~
13415 a,_head 
13416 \newline 
13417 \SpecialChar ~
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 cjne a,ar3,00106$ 
13422 \newline 
13423 \SpecialChar ~
13424 \SpecialChar ~
13425 \SpecialChar ~
13426 \SpecialChar ~
13427 ret
13428 \newline 
13429 00106$: 
13430 \newline 
13431 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13432 \begin_inset LatexCommand \index{Aligned array}
13433
13434 \end_inset 
13435
13436
13437 \newline 
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 \SpecialChar ~
13442 mov\SpecialChar ~
13443 \SpecialChar ~
13444 r3,_head 
13445 \newline 
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 \SpecialChar ~
13449 \SpecialChar ~
13450 inc\SpecialChar ~
13451 \SpecialChar ~
13452 _head 
13453 \newline 
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 \SpecialChar ~
13457 \SpecialChar ~
13458 mov\SpecialChar ~
13459 \SpecialChar ~
13460 dpl,r3 
13461 \newline 
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 mov\SpecialChar ~
13467 \SpecialChar ~
13468 dph,#(_buf >> 8) 
13469 \newline 
13470 \SpecialChar ~
13471 \SpecialChar ~
13472 \SpecialChar ~
13473 \SpecialChar ~
13474 mov\SpecialChar ~
13475 \SpecialChar ~
13476 a,r2 
13477 \newline 
13478 \SpecialChar ~
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 movx @dptr,a 
13483 \newline 
13484 00103$: 
13485 \newline 
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 \SpecialChar ~
13490 ret
13491 \newline 
13492 \SpecialChar ~
13493 \SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 _endasm
13497 \begin_inset LatexCommand \index{\_endasm}
13498
13499 \end_inset 
13500
13501
13502 \begin_inset LatexCommand \index{\_\_endasm}
13503
13504 \end_inset 
13505
13506 ;
13507 \newline 
13508
13509 \layout Standard
13510
13511 The new file buffer.c should compile with only one warning about the unreferenced
13512  function argument 'c'.
13513  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13514  (1) and finally have:
13515 \layout Verse
13516
13517
13518 \family typewriter 
13519 \size footnotesize 
13520 unsigned char __far __at(0x7f00) buf[0x100];
13521 \newline 
13522 unsigned char head, tail;
13523 \newline 
13524 #define USE_ASSEMBLY (1)
13525 \newline 
13526
13527 \newline 
13528 #if !USE_ASSEMBLY
13529 \newline 
13530
13531 \newline 
13532 void to_buffer( unsigned char c )
13533 \newline 
13534 {
13535 \newline 
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 \SpecialChar ~
13539 \SpecialChar ~
13540 if( head != (unsigned char)(tail-1) )
13541 \newline 
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 \SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 buf[ head++ ] = c;
13551 \newline 
13552 }
13553 \newline 
13554
13555 \newline 
13556 #else
13557 \newline 
13558
13559 \newline 
13560 void to_buffer( unsigned char c )
13561 \newline 
13562 {
13563 \newline 
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 \SpecialChar ~
13568 c; // to avoid warning: unreferenced function argument
13569 \newline 
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 _asm
13575 \begin_inset LatexCommand \index{\_asm}
13576
13577 \end_inset 
13578
13579
13580 \begin_inset LatexCommand \index{\_\_asm}
13581
13582 \end_inset 
13583
13584
13585 \newline 
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 ; save used registers here.
13595  
13596 \newline 
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 \SpecialChar ~
13605 ; If we were still using r2,r3 we would have to push them here.
13606  
13607 \newline 
13608 ; if( head != (unsigned char)(tail-1) )
13609 \newline 
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 \SpecialChar ~
13613 \SpecialChar ~
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 mov\SpecialChar ~
13619  a,_tail
13620 \newline 
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 \SpecialChar ~
13629 dec\SpecialChar ~
13630  a
13631 \newline 
13632 \SpecialChar ~
13633 \SpecialChar ~
13634 \SpecialChar ~
13635 \SpecialChar ~
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 xrl\SpecialChar ~
13641  a,_head
13642 \newline 
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 \SpecialChar ~
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13652 \newline 
13653 \SpecialChar ~
13654 \SpecialChar ~
13655 \SpecialChar ~
13656 \SpecialChar ~
13657 \SpecialChar ~
13658 \SpecialChar ~
13659 \SpecialChar ~
13660 \SpecialChar ~
13661 jz\SpecialChar ~
13662 \SpecialChar ~
13663  t_b_end$
13664 \newline 
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 \SpecialChar ~
13668 \SpecialChar ~
13669 \SpecialChar ~
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 ;
13674 \newline 
13675 ; buf[ head++ ] = c;
13676 \newline 
13677 \SpecialChar ~
13678 \SpecialChar ~
13679 \SpecialChar ~
13680 \SpecialChar ~
13681 \SpecialChar ~
13682 \SpecialChar ~
13683 \SpecialChar ~
13684 \SpecialChar ~
13685 mov\SpecialChar ~
13686  a,dpl \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 ; dpl holds lower byte of function argument
13694 \newline 
13695 \SpecialChar ~
13696 \SpecialChar ~
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 mov\SpecialChar ~
13704  dpl,_head \SpecialChar ~
13705 \SpecialChar ~
13706 \SpecialChar ~
13707 ; buf is 0x100 byte aligned so head can be used directly
13708 \newline 
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 mov\SpecialChar ~
13718  dph,#(_buf>>8)
13719 \newline 
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 movx @dptr,a
13729 \newline 
13730 \SpecialChar ~
13731 \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 inc \SpecialChar ~
13739 _head
13740 \newline 
13741 \SpecialChar ~
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13750 \newline 
13751 t_b_end$:
13752 \newline 
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 ; restore used registers here 
13762 \newline 
13763 \SpecialChar ~
13764 \SpecialChar ~
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 _endasm
13768 \begin_inset LatexCommand \index{\_endasm}
13769
13770 \end_inset 
13771
13772
13773 \begin_inset LatexCommand \index{\_\_endasm}
13774
13775 \end_inset 
13776
13777 ;
13778 \newline 
13779 }
13780 \newline 
13781 #endif
13782 \layout Standard
13783
13784 The inline assembler code can contain any valid code understood by the assembler
13785 , this includes any assembler directives and comment lines.
13786  The assembler does not like some characters like ':' or ''' in comments.
13787  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13788 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13789
13790 \end_inset 
13791
13792
13793 \begin_inset LatexCommand \index{Assembler documentation}
13794
13795 \end_inset 
13796
13797  or online at 
13798 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13799
13800 \end_inset 
13801
13802 \SpecialChar ~
13803 .
13804 \layout Standard
13805
13806 The compiler does not do any validation of the code within the 
13807 \family typewriter 
13808 _asm
13809 \begin_inset LatexCommand \index{\_asm}
13810
13811 \end_inset 
13812
13813
13814 \begin_inset LatexCommand \index{\_\_asm}
13815
13816 \end_inset 
13817
13818  ...
13819  _endasm
13820 \size footnotesize 
13821
13822 \begin_inset LatexCommand \index{\_endasm}
13823
13824 \end_inset 
13825
13826
13827 \begin_inset LatexCommand \index{\_\_endasm}
13828
13829 \end_inset 
13830
13831
13832 \size default 
13833 ;
13834 \family default 
13835  keyword pair.
13836  Specifically it will not know which registers are used and thus register
13837  pushing/popping
13838 \begin_inset LatexCommand \index{push/pop}
13839
13840 \end_inset 
13841
13842  has to be done manually.
13843  
13844 \layout Standard
13845
13846 It is recommended that each assembly instruction (including labels) be placed
13847  in a separate line (as the example shows).
13848  When the -
13849 \begin_inset ERT
13850 status Collapsed
13851
13852 \layout Standard
13853
13854 \backslash 
13855 /
13856 \end_inset 
13857
13858 -
13859 \emph on 
13860 peep-asm
13861 \begin_inset LatexCommand \index{-\/-peep-asm}
13862
13863 \end_inset 
13864
13865
13866 \emph default 
13867  command line option is used, the inline assembler code will be passed through
13868  the peephole optimizer
13869 \begin_inset LatexCommand \index{Peephole optimizer}
13870
13871 \end_inset 
13872
13873 .
13874  There are only a few (if any) cases where this option makes sense, it might
13875  cause some unexpected changes in the inline assembler code.
13876  Please go through the peephole optimizer rules defined in file 
13877 \emph on 
13878 SDCCpeeph.def
13879 \emph default 
13880  before using this option.
13881 \layout Subsection
13882
13883 Naked Functions
13884 \begin_inset LatexCommand \label{sub:Naked-Functions}
13885
13886 \end_inset 
13887
13888
13889 \begin_inset LatexCommand \index{Naked functions}
13890
13891 \end_inset 
13892
13893
13894 \layout Standard
13895
13896 A special keyword may be associated with a function declaring it as 
13897 \emph on 
13898 _naked
13899 \begin_inset LatexCommand \index{\_naked}
13900
13901 \end_inset 
13902
13903
13904 \begin_inset LatexCommand \index{\_\_naked}
13905
13906 \end_inset 
13907
13908 .
13909  
13910 \emph default 
13911 The 
13912 \emph on 
13913 _naked
13914 \emph default 
13915  function modifier attribute prevents the compiler from generating prologue
13916 \begin_inset LatexCommand \index{function prologue}
13917
13918 \end_inset 
13919
13920  and epilogue
13921 \begin_inset LatexCommand \index{function epilogue}
13922
13923 \end_inset 
13924
13925  code for that function.
13926  This means that the user is entirely responsible for such things as saving
13927  any registers that may need to be preserved, selecting the proper register
13928  bank, generating the 
13929 \emph on 
13930 return
13931 \emph default 
13932  instruction at the end, etc.
13933  Practically, this means that the contents of the function must be written
13934  in inline assembler.
13935  This is particularly useful for interrupt functions, which can have a large
13936  (and often unnecessary) prologue/epilogue.
13937  For example, compare the code generated by these two functions:
13938 \layout Verse
13939
13940
13941 \family typewriter 
13942 volatile
13943 \begin_inset LatexCommand \index{volatile}
13944
13945 \end_inset 
13946
13947  data unsigned char counter;
13948 \newline 
13949
13950 \newline 
13951 void simpleInterrupt(void) __interrupt
13952 \begin_inset LatexCommand \index{interrupt}
13953
13954 \end_inset 
13955
13956
13957 \begin_inset LatexCommand \index{\_\_interrupt}
13958
13959 \end_inset 
13960
13961  (1)
13962 \newline 
13963 {
13964 \newline 
13965 \SpecialChar ~
13966 \SpecialChar ~
13967 \SpecialChar ~
13968 \SpecialChar ~
13969 counter++;
13970 \newline 
13971 }
13972 \newline 
13973
13974 \newline 
13975 void nakedInterrupt(void) __interrupt (2) __naked
13976 \newline 
13977 {
13978 \newline 
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 _asm
13984 \begin_inset LatexCommand \index{\_asm}
13985
13986 \end_inset 
13987
13988
13989 \begin_inset LatexCommand \index{\_\_asm}
13990
13991 \end_inset 
13992
13993
13994 \newline 
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 \SpecialChar ~
14000 \SpecialChar ~
14001 inc\SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 _counter ; does not change flags, no need to save psw
14007 \newline 
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 \SpecialChar ~
14011 \SpecialChar ~
14012 \SpecialChar ~
14013 \SpecialChar ~
14014 reti\SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 ; MUST explicitly include ret or reti in _naked function.
14019 \newline 
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 _endasm
14025 \begin_inset LatexCommand \index{\_endasm}
14026
14027 \end_inset 
14028
14029
14030 \begin_inset LatexCommand \index{\_\_endasm}
14031
14032 \end_inset 
14033
14034 ;
14035 \newline 
14036 }
14037 \layout Standard
14038
14039 For an 8051 target, the generated simpleInterrupt looks like:
14040 \layout Verse
14041
14042
14043 \family typewriter 
14044 Note, this is an 
14045 \emph on 
14046 outdated
14047 \emph default 
14048  example, recent versions of SDCC generate
14049 \newline 
14050 the 
14051 \emph on 
14052 same
14053 \emph default 
14054  code for simpleInterrupt() and nakedInterrupt()!
14055 \newline 
14056
14057 \newline 
14058 _simpleInterrupt:
14059 \newline 
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 \SpecialChar ~
14063 \SpecialChar ~
14064 push\SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 acc
14069 \newline 
14070 \SpecialChar ~
14071 \SpecialChar ~
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 push\SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 b
14079 \newline 
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 push\SpecialChar ~
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 dpl
14089 \newline 
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 push\SpecialChar ~
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 dph
14099 \newline 
14100 \SpecialChar ~
14101 \SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 push\SpecialChar ~
14105 \SpecialChar ~
14106 \SpecialChar ~
14107 \SpecialChar ~
14108 psw
14109 \newline 
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 mov\SpecialChar ~
14115 \SpecialChar ~
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 \SpecialChar ~
14119 psw,#0x00
14120 \newline 
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 inc\SpecialChar ~
14126 \SpecialChar ~
14127 \SpecialChar ~
14128 \SpecialChar ~
14129 \SpecialChar ~
14130 _counter
14131 \newline 
14132 \SpecialChar ~
14133 \SpecialChar ~
14134 \SpecialChar ~
14135 \SpecialChar ~
14136 pop\SpecialChar ~
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 psw
14142 \newline 
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 pop\SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 dph
14153 \newline 
14154 \SpecialChar ~
14155 \SpecialChar ~
14156 \SpecialChar ~
14157 \SpecialChar ~
14158 pop\SpecialChar ~
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 dpl
14164 \newline 
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 pop\SpecialChar ~
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 b
14175 \newline 
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 pop\SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 acc
14186 \newline 
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 reti
14192 \layout Standard
14193
14194 whereas nakedInterrupt looks like:
14195 \layout Verse
14196
14197
14198 \family typewriter 
14199 _nakedInterrupt:
14200 \newline 
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 inc\SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 \SpecialChar ~
14209 _counter ; does not change flags, no need to save psw
14210 \newline 
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 \SpecialChar ~
14215 reti\SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 \SpecialChar ~
14226 \SpecialChar ~
14227 ; MUST explicitly include ret or reti in _naked function
14228 \layout Standard
14229
14230 The related directive #pragma exclude
14231 \begin_inset LatexCommand \index{\#pragma exclude}
14232
14233 \end_inset 
14234
14235  allows a more fine grained control over pushing & popping
14236 \begin_inset LatexCommand \index{push/pop}
14237
14238 \end_inset 
14239
14240  the registers.
14241 \layout Standard
14242
14243 While there is nothing preventing you from writing C code inside a 
14244 \family typewriter 
14245 _naked
14246 \family default 
14247  function, there are many ways to shoot yourself in the foot doing this,
14248  and it is recommended that you stick to inline assembler.
14249 \layout Subsection
14250
14251 Use of Labels within Inline Assembler
14252 \layout Standard
14253
14254 SDCC allows the use of in-line assembler with a few restrictions regarding
14255  labels.
14256  In older versions of the compiler all labels defined within inline assembler
14257  code 
14258 \emph on 
14259 had to be
14260 \emph default 
14261  of the form 
14262 \emph on 
14263 nnnnn$
14264 \emph default 
14265  where nnnn is a number less than 100 (which implies a limit of utmost 100
14266  inline assembler labels 
14267 \emph on 
14268 per function
14269 \emph default 
14270 \noun on 
14271 )
14272 \noun default 
14273 .
14274  
14275 \layout Verse
14276
14277
14278 \family typewriter 
14279 _asm
14280 \begin_inset LatexCommand \index{\_asm}
14281
14282 \end_inset 
14283
14284
14285 \begin_inset LatexCommand \index{\_\_asm}
14286
14287 \end_inset 
14288
14289  
14290 \newline 
14291 \SpecialChar ~
14292 \SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 mov\SpecialChar ~
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 b,#10 
14301 \newline 
14302 00001$: 
14303 \newline 
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 djnz\SpecialChar ~
14309 \SpecialChar ~
14310 \SpecialChar ~
14311 \SpecialChar ~
14312 b,00001$ 
14313 \newline 
14314 _endasm
14315 \begin_inset LatexCommand \index{\_endasm}
14316
14317 \end_inset 
14318
14319
14320 \begin_inset LatexCommand \index{\_\_endasm}
14321
14322 \end_inset 
14323
14324  ;
14325 \layout Standard
14326
14327 Inline assembler code cannot reference any C-Labels, however it can reference
14328  labels
14329 \begin_inset LatexCommand \index{Labels}
14330
14331 \end_inset 
14332
14333  defined by the inline assembler, e.g.:
14334 \layout Verse
14335
14336
14337 \family typewriter 
14338 foo() { 
14339 \newline 
14340 \SpecialChar ~
14341 \SpecialChar ~
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 /* some c code */ 
14345 \newline 
14346 \SpecialChar ~
14347 \SpecialChar ~
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 _asm 
14351 \newline 
14352 \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 \SpecialChar ~
14356 \SpecialChar ~
14357 \SpecialChar ~
14358 ; some assembler code 
14359 \newline 
14360 \SpecialChar ~
14361 \SpecialChar ~
14362 \SpecialChar ~
14363 \SpecialChar ~
14364 \SpecialChar ~
14365 \SpecialChar ~
14366 ljmp $0003 
14367 \newline 
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 _endasm; 
14373 \newline 
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 \SpecialChar ~
14378 /* some more c code */ 
14379 \newline 
14380 clabel:\SpecialChar ~
14381 \SpecialChar ~
14382 /* inline assembler cannot reference this label */ 
14383 \newline 
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 _asm
14389 \newline 
14390 \SpecialChar ~
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 $0003: ;label (can be referenced by inline assembler only) 
14395 \newline 
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 _endasm
14401 \begin_inset LatexCommand \index{\_endasm}
14402
14403 \end_inset 
14404
14405
14406 \begin_inset LatexCommand \index{\_\_endasm}
14407
14408 \end_inset 
14409
14410  ; 
14411 \newline 
14412 \SpecialChar ~
14413 \SpecialChar ~
14414 \SpecialChar ~
14415 \SpecialChar ~
14416 /* some more c code */
14417 \newline 
14418 }
14419 \layout Standard
14420
14421 In other words inline assembly code can access labels defined in inline
14422  assembly within the scope of the function.
14423  The same goes the other way, i.e.
14424  labels defines in inline assembly can not be accessed by C statements.
14425 \layout Section
14426
14427 Interfacing with Assembler Code
14428 \begin_inset LatexCommand \index{Assembler routines}
14429
14430 \end_inset 
14431
14432
14433 \layout Subsection
14434
14435 Global Registers used for Parameter Passing
14436 \begin_inset LatexCommand \index{Parameter passing}
14437
14438 \end_inset 
14439
14440
14441 \layout Standard
14442
14443 The compiler always uses the global registers 
14444 \emph on 
14445 DPL, DPH
14446 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14447
14448 \end_inset 
14449
14450
14451 \begin_inset LatexCommand \index{DPTR}
14452
14453 \end_inset 
14454
14455 , B
14456 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14457
14458 \end_inset 
14459
14460  
14461 \emph default 
14462 and
14463 \emph on 
14464  ACC
14465 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14466
14467 \end_inset 
14468
14469
14470 \emph default 
14471  to pass the first parameter to a routine.
14472  The second parameter onwards is either allocated on the stack (for reentrant
14473  routines or if -
14474 \begin_inset ERT
14475 status Collapsed
14476
14477 \layout Standard
14478
14479 \backslash 
14480 /
14481 \end_inset 
14482
14483 -stack-auto is used) or in data / xdata memory (depending on the memory
14484  model).
14485  
14486 \layout Subsection
14487
14488 Assembler Routine (non-reentrant)
14489 \layout Standard
14490
14491 In the following example
14492 \begin_inset LatexCommand \index{reentrant}
14493
14494 \end_inset 
14495
14496
14497 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14498
14499 \end_inset 
14500
14501  the function c_func calls an assembler routine asm_func, which takes two
14502  parameters
14503 \begin_inset LatexCommand \index{function parameter}
14504
14505 \end_inset 
14506
14507 .
14508 \layout Verse
14509
14510
14511 \family typewriter 
14512 extern int asm_func(unsigned char, unsigned char);
14513 \newline 
14514
14515 \newline 
14516 int c_func (unsigned char i, unsigned char j)
14517 \newline 
14518 {
14519 \newline 
14520 \SpecialChar ~
14521 \SpecialChar ~
14522 \SpecialChar ~
14523 \SpecialChar ~
14524 return asm_func(i,j);
14525 \newline 
14526 }
14527 \newline 
14528
14529 \newline 
14530 int main()
14531 \newline 
14532 {
14533 \newline 
14534 \SpecialChar ~
14535 \SpecialChar ~
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 return c_func(10,9);
14539 \newline 
14540 }
14541 \layout Standard
14542
14543 The corresponding assembler function is:
14544 \layout Verse
14545
14546
14547 \family typewriter 
14548 .globl _asm_func_PARM_2 
14549 \newline 
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 \SpecialChar ~
14554 \SpecialChar ~
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 .globl _asm_func 
14559 \newline 
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 \SpecialChar ~
14564 \SpecialChar ~
14565 \SpecialChar ~
14566 \SpecialChar ~
14567 \SpecialChar ~
14568 .area OSEG 
14569 \newline 
14570 _asm_func_PARM_2:
14571 \newline 
14572 \SpecialChar ~
14573 \SpecialChar ~
14574 \SpecialChar ~
14575 \SpecialChar ~
14576 \SpecialChar ~
14577 \SpecialChar ~
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 .ds    1 
14581 \newline 
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 \SpecialChar ~
14585 \SpecialChar ~
14586 \SpecialChar ~
14587 \SpecialChar ~
14588 \SpecialChar ~
14589 \SpecialChar ~
14590 .area CSEG 
14591 \newline 
14592 _asm_func: 
14593 \newline 
14594 \SpecialChar ~
14595 \SpecialChar ~
14596 \SpecialChar ~
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 \SpecialChar ~
14600 \SpecialChar ~
14601 \SpecialChar ~
14602 mov\SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 a,dpl 
14607 \newline 
14608 \SpecialChar ~
14609 \SpecialChar ~
14610 \SpecialChar ~
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 \SpecialChar ~
14616 add\SpecialChar ~
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 \SpecialChar ~
14620 a,_asm_func_PARM_2 
14621 \newline 
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 \SpecialChar ~
14625 \SpecialChar ~
14626 \SpecialChar ~
14627 \SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 mov\SpecialChar ~
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 \SpecialChar ~
14634 dpl,a 
14635 \newline 
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 mov\SpecialChar ~
14645 \SpecialChar ~
14646 \SpecialChar ~
14647 \SpecialChar ~
14648 dph
14649 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14650
14651 \end_inset 
14652
14653 ,#0x00 
14654 \newline 
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 ret
14664 \layout Standard
14665
14666 Note here that the return values
14667 \begin_inset LatexCommand \index{return value}
14668
14669 \end_inset 
14670
14671  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14672  two byte values.
14673  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14674 b' & 'acc' for four byte values.
14675 \layout Standard
14676
14677 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14678  the parameter number starting from 1, and counting from the left.
14679  The first parameter is passed in 
14680 \begin_inset Quotes eld
14681 \end_inset 
14682
14683 dpl
14684 \begin_inset Quotes erd
14685 \end_inset 
14686
14687  for a one byte parameter, 
14688 \begin_inset Quotes eld
14689 \end_inset 
14690
14691 dptr
14692 \begin_inset Quotes erd
14693 \end_inset 
14694
14695  for two bytes, 
14696 \begin_inset Quotes eld
14697 \end_inset 
14698
14699 b,dptr
14700 \begin_inset Quotes erd
14701 \end_inset 
14702
14703  for three bytes and 
14704 \begin_inset Quotes eld
14705 \end_inset 
14706
14707 acc,b,dptr
14708 \begin_inset Quotes erd
14709 \end_inset 
14710
14711  for a four bytes parameter.
14712  The variable name for the second parameter will be _<function_name>_PARM_2.
14713 \newline 
14714
14715 \newline 
14716 Assemble the assembler routine with the following command:
14717 \newline 
14718
14719 \newline 
14720
14721 \family sans 
14722 \series bold 
14723 asx8051 -losg asmfunc.asm
14724 \newline 
14725
14726 \newline 
14727
14728 \family default 
14729 \series default 
14730 Then compile and link the assembler routine to the C source file with the
14731  following command:
14732 \newline 
14733
14734 \newline 
14735
14736 \family sans 
14737 \series bold 
14738 sdcc cfunc.c asmfunc.rel
14739 \layout Subsection
14740
14741 Assembler Routine (reentrant)
14742 \layout Standard
14743
14744 In this case
14745 \begin_inset LatexCommand \index{reentrant}
14746
14747 \end_inset 
14748
14749
14750 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14751
14752 \end_inset 
14753
14754  the second parameter
14755 \begin_inset LatexCommand \index{function parameter}
14756
14757 \end_inset 
14758
14759  onwards will be passed on the stack, the parameters are pushed from right
14760  to left i.e.
14761  after the call the leftmost parameter will be on the top of the stack.
14762  Here is an example:
14763 \layout Verse
14764
14765
14766 \family typewriter 
14767 extern int asm_func(unsigned char, unsigned char);
14768 \newline 
14769
14770 \newline 
14771 int c_func (unsigned char i, unsigned char j) reentrant 
14772 \newline 
14773
14774 \newline 
14775 \SpecialChar ~
14776 \SpecialChar ~
14777 \SpecialChar ~
14778 \SpecialChar ~
14779 return asm_func(i,j); 
14780 \newline 
14781
14782 \newline 
14783
14784 \newline 
14785 int main() 
14786 \newline 
14787
14788 \newline 
14789 \SpecialChar ~
14790 \SpecialChar ~
14791 \SpecialChar ~
14792 \SpecialChar ~
14793 return c_func(10,9); 
14794 \newline 
14795 }
14796 \layout Standard
14797
14798 The corresponding assembler routine is:
14799 \layout Verse
14800
14801
14802 \family typewriter 
14803 .globl _asm_func 
14804 \newline 
14805 _asm_func: 
14806 \newline 
14807 \SpecialChar ~
14808 \SpecialChar ~
14809 \SpecialChar ~
14810 \SpecialChar ~
14811 push  _bp 
14812 \newline 
14813 \SpecialChar ~
14814 \SpecialChar ~
14815 \SpecialChar ~
14816 \SpecialChar ~
14817 mov _bp,sp 
14818 \newline 
14819 \SpecialChar ~
14820 \SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 mov r2,dpl
14824 \newline 
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 \SpecialChar ~
14829 mov a,_bp 
14830 \newline 
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 \SpecialChar ~
14834 \SpecialChar ~
14835 add a,#0xfd 
14836 \newline 
14837 \SpecialChar ~
14838 \SpecialChar ~
14839 \SpecialChar ~
14840 \SpecialChar ~
14841 mov r0,a 
14842 \newline 
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 \SpecialChar ~
14846 \SpecialChar ~
14847 add  a,#0xfc ;?
14848 \newline 
14849 \SpecialChar ~
14850 \SpecialChar ~
14851 \SpecialChar ~
14852 \SpecialChar ~
14853 mov  r1,a 
14854 \newline 
14855 \SpecialChar ~
14856 \SpecialChar ~
14857 \SpecialChar ~
14858 \SpecialChar ~
14859 mov  a,@r0 
14860 \newline 
14861 \SpecialChar ~
14862 \SpecialChar ~
14863 \SpecialChar ~
14864 \SpecialChar ~
14865 add  a,r2 ;?
14866 \newline 
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 mov  dpl,a 
14872 \newline 
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 mov  dph,#0x00 
14878 \newline 
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 mov  sp,_bp 
14884 \newline 
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 \SpecialChar ~
14888 \SpecialChar ~
14889 pop  _bp 
14890 \newline 
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 ret
14896 \layout Standard
14897 \added_space_bottom bigskip 
14898 The compiling and linking procedure remains the same, however note the extra
14899  entry & exit linkage required for the assembler code, _bp is the stack
14900  frame pointer and is used to compute the offset into the stack for parameters
14901  and local variables.
14902 \layout Section
14903
14904 int (16 bit)
14905 \begin_inset LatexCommand \index{int (16 bit)}
14906
14907 \end_inset 
14908
14909  and long (32 bit)
14910 \begin_inset LatexCommand \index{long (32 bit)}
14911
14912 \end_inset 
14913
14914  Support
14915 \layout Standard
14916
14917 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14918  multiplication and modulus operations are implemented by support routines.
14919  These support routines are all developed in ANSI-C to facilitate porting
14920  to other MCUs, although some model specific assembler optimizations are
14921  used.
14922  The following files contain the described routines, all of them can be
14923  found in <installdir>/share/sdcc/lib.
14924 \newline 
14925
14926 \layout Standard
14927 \align center 
14928
14929 \begin_inset  Tabular
14930 <lyxtabular version="3" rows="11" columns="2">
14931 <features>
14932 <column alignment="left" valignment="top" leftline="true" width="0">
14933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14934 <row topline="true" bottomline="true">
14935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14936 \begin_inset Text
14937
14938 \layout Standard
14939
14940
14941 \series bold 
14942 Function
14943 \end_inset 
14944 </cell>
14945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14946 \begin_inset Text
14947
14948 \layout Standard
14949
14950
14951 \series bold 
14952 Description
14953 \end_inset 
14954 </cell>
14955 </row>
14956 <row topline="true">
14957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14958 \begin_inset Text
14959
14960 \layout Standard
14961
14962 _mulint.c 
14963 \end_inset 
14964 </cell>
14965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14966 \begin_inset Text
14967
14968 \layout Standard
14969
14970 16 bit multiplication
14971 \end_inset 
14972 </cell>
14973 </row>
14974 <row topline="true">
14975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14976 \begin_inset Text
14977
14978 \layout Standard
14979
14980 _divsint.c 
14981 \end_inset 
14982 </cell>
14983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14984 \begin_inset Text
14985
14986 \layout Standard
14987
14988  signed 16 bit division (calls _divuint)
14989 \end_inset 
14990 </cell>
14991 </row>
14992 <row topline="true">
14993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14994 \begin_inset Text
14995
14996 \layout Standard
14997
14998 _divuint.c 
14999 \end_inset 
15000 </cell>
15001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15002 \begin_inset Text
15003
15004 \layout Standard
15005
15006  unsigned 16 bit division
15007 \end_inset 
15008 </cell>
15009 </row>
15010 <row topline="true">
15011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15012 \begin_inset Text
15013
15014 \layout Standard
15015
15016 _modsint.c
15017 \end_inset 
15018 </cell>
15019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15020 \begin_inset Text
15021
15022 \layout Standard
15023
15024 signed 16 bit modulus (calls _moduint)
15025 \end_inset 
15026 </cell>
15027 </row>
15028 <row topline="true">
15029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15030 \begin_inset Text
15031
15032 \layout Standard
15033
15034 _moduint.c
15035 \end_inset 
15036 </cell>
15037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15038 \begin_inset Text
15039
15040 \layout Standard
15041
15042 unsigned 16 bit modulus
15043 \end_inset 
15044 </cell>
15045 </row>
15046 <row topline="true">
15047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15048 \begin_inset Text
15049
15050 \layout Standard
15051
15052 _mullong.c
15053 \end_inset 
15054 </cell>
15055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15056 \begin_inset Text
15057
15058 \layout Standard
15059
15060 32 bit multiplication
15061 \end_inset 
15062 </cell>
15063 </row>
15064 <row topline="true">
15065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15066 \begin_inset Text
15067
15068 \layout Standard
15069
15070 _divslong.c 
15071 \end_inset 
15072 </cell>
15073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15074 \begin_inset Text
15075
15076 \layout Standard
15077
15078  signed 32 division (calls _divulong)
15079 \end_inset 
15080 </cell>
15081 </row>
15082 <row topline="true">
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15084 \begin_inset Text
15085
15086 \layout Standard
15087
15088 _divulong.c 
15089 \end_inset 
15090 </cell>
15091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15092 \begin_inset Text
15093
15094 \layout Standard
15095
15096 unsigned 32 division
15097 \end_inset 
15098 </cell>
15099 </row>
15100 <row topline="true">
15101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15102 \begin_inset Text
15103
15104 \layout Standard
15105
15106 _modslong.c
15107 \end_inset 
15108 </cell>
15109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15110 \begin_inset Text
15111
15112 \layout Standard
15113
15114  signed 32 bit modulus (calls _modulong)
15115 \end_inset 
15116 </cell>
15117 </row>
15118 <row topline="true" bottomline="true">
15119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15120 \begin_inset Text
15121
15122 \layout Standard
15123
15124 _modulong.c
15125 \end_inset 
15126 </cell>
15127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15128 \begin_inset Text
15129
15130 \layout Standard
15131
15132 unsigned 32 bit modulus
15133 \end_inset 
15134 </cell>
15135 </row>
15136 </lyxtabular>
15137
15138 \end_inset 
15139
15140
15141 \newline 
15142
15143 \layout Standard
15144
15145 Since they are compiled as 
15146 \emph on 
15147 non-reentrant
15148 \emph default 
15149
15150 \begin_inset LatexCommand \index{reentrant}
15151
15152 \end_inset 
15153
15154 , interrupt
15155 \begin_inset LatexCommand \index{interrupt}
15156
15157 \end_inset 
15158
15159  service routines should not do any of the above operations.
15160  If this is unavoidable then the above routines will need to be compiled
15161  with the 
15162 \emph on 
15163 -
15164 \begin_inset ERT
15165 status Collapsed
15166
15167 \layout Standard
15168
15169 \backslash 
15170 /
15171 \end_inset 
15172
15173 -stack-auto
15174 \begin_inset LatexCommand \index{-\/-stack-auto}
15175
15176 \end_inset 
15177
15178
15179 \emph default 
15180  option, after which the source program will have to be compiled with 
15181 \emph on 
15182 -
15183 \begin_inset ERT
15184 status Collapsed
15185
15186 \layout Standard
15187
15188 \backslash 
15189 /
15190 \end_inset 
15191
15192 -int-long-reent
15193 \begin_inset LatexCommand \index{-\/-int-long-reent}
15194
15195 \end_inset 
15196
15197
15198 \emph default 
15199  option.
15200  Notice that you don't have to call these routines directly.
15201  The compiler will use them automatically every time an integer operation
15202  is required.
15203 \layout Section
15204
15205 Floating Point Support
15206 \begin_inset LatexCommand \index{Floating point support}
15207
15208 \end_inset 
15209
15210
15211 \layout Standard
15212
15213 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15214  The floating point support routines are derived from gcc's floatlib.c and
15215  consist of the following routines:
15216 \newline 
15217
15218 \layout Standard
15219 \align center 
15220
15221 \size footnotesize 
15222
15223 \begin_inset  Tabular
15224 <lyxtabular version="3" rows="17" columns="2">
15225 <features>
15226 <column alignment="left" valignment="top" leftline="true" width="0">
15227 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15228 <row topline="true" bottomline="true">
15229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15230 \begin_inset Text
15231
15232 \layout Standard
15233
15234
15235 \family roman 
15236 \series medium 
15237 \shape up 
15238 \size normal 
15239 \emph off 
15240 \bar no 
15241 \noun off 
15242 \color none
15243 Function 
15244 \end_inset 
15245 </cell>
15246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15247 \begin_inset Text
15248
15249 \layout Standard
15250
15251 Description
15252 \end_inset 
15253 </cell>
15254 </row>
15255 <row topline="true">
15256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15257 \begin_inset Text
15258
15259 \layout Standard
15260
15261
15262 \family roman 
15263 \series medium 
15264 \shape up 
15265 \size normal 
15266 \emph off 
15267 \bar no 
15268 \noun off 
15269 \color none
15270 _fsadd.c
15271 \end_inset 
15272 </cell>
15273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15274 \begin_inset Text
15275
15276 \layout Standard
15277
15278
15279 \family roman 
15280 \series medium 
15281 \shape up 
15282 \size normal 
15283 \emph off 
15284 \bar no 
15285 \noun off 
15286 \color none
15287 add floating point numbers
15288 \end_inset 
15289 </cell>
15290 </row>
15291 <row topline="true">
15292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15293 \begin_inset Text
15294
15295 \layout Standard
15296
15297
15298 \family roman 
15299 \series medium 
15300 \shape up 
15301 \size normal 
15302 \emph off 
15303 \bar no 
15304 \noun off 
15305 \color none
15306 _fssub.c 
15307 \end_inset 
15308 </cell>
15309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15310 \begin_inset Text
15311
15312 \layout Standard
15313
15314
15315 \family roman 
15316 \series medium 
15317 \shape up 
15318 \size normal 
15319 \emph off 
15320 \bar no 
15321 \noun off 
15322 \color none
15323 subtract floating point numbers 
15324 \end_inset 
15325 </cell>
15326 </row>
15327 <row topline="true">
15328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15329 \begin_inset Text
15330
15331 \layout Standard
15332
15333
15334 \family roman 
15335 \series medium 
15336 \shape up 
15337 \size normal 
15338 \emph off 
15339 \bar no 
15340 \noun off 
15341 \color none
15342 _fsdiv.c 
15343 \end_inset 
15344 </cell>
15345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15346 \begin_inset Text
15347
15348 \layout Standard
15349
15350
15351 \family roman 
15352 \series medium 
15353 \shape up 
15354 \size normal 
15355 \emph off 
15356 \bar no 
15357 \noun off 
15358 \color none
15359 divide floating point numbers 
15360 \end_inset 
15361 </cell>
15362 </row>
15363 <row topline="true">
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15365 \begin_inset Text
15366
15367 \layout Standard
15368
15369
15370 \family roman 
15371 \series medium 
15372 \shape up 
15373 \size normal 
15374 \emph off 
15375 \bar no 
15376 \noun off 
15377 \color none
15378 _fsmul.c 
15379 \end_inset 
15380 </cell>
15381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15382 \begin_inset Text
15383
15384 \layout Standard
15385
15386
15387 \family roman 
15388 \series medium 
15389 \shape up 
15390 \size normal 
15391 \emph off 
15392 \bar no 
15393 \noun off 
15394 \color none
15395 multiply floating point numbers 
15396 \end_inset 
15397 </cell>
15398 </row>
15399 <row topline="true">
15400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15401 \begin_inset Text
15402
15403 \layout Standard
15404
15405
15406 \family roman 
15407 \series medium 
15408 \shape up 
15409 \size normal 
15410 \emph off 
15411 \bar no 
15412 \noun off 
15413 \color none
15414 _fs2uchar.c
15415 \end_inset 
15416 </cell>
15417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15418 \begin_inset Text
15419
15420 \layout Standard
15421
15422
15423 \family roman 
15424 \series medium 
15425 \shape up 
15426 \size normal 
15427 \emph off 
15428 \bar no 
15429 \noun off 
15430 \color none
15431 convert floating point to unsigned char
15432 \end_inset 
15433 </cell>
15434 </row>
15435 <row topline="true">
15436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15437 \begin_inset Text
15438
15439 \layout Standard
15440
15441
15442 \family roman 
15443 \series medium 
15444 \shape up 
15445 \size normal 
15446 \emph off 
15447 \bar no 
15448 \noun off 
15449 \color none
15450 _fs2char.c
15451 \end_inset 
15452 </cell>
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15454 \begin_inset Text
15455
15456 \layout Standard
15457
15458
15459 \family roman 
15460 \series medium 
15461 \shape up 
15462 \size normal 
15463 \emph off 
15464 \bar no 
15465 \noun off 
15466 \color none
15467 convert floating point to signed char
15468 \end_inset 
15469 </cell>
15470 </row>
15471 <row topline="true">
15472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15473 \begin_inset Text
15474
15475 \layout Standard
15476
15477
15478 \family roman 
15479 \series medium 
15480 \shape up 
15481 \size normal 
15482 \emph off 
15483 \bar no 
15484 \noun off 
15485 \color none
15486 _fs2uint.c
15487 \end_inset 
15488 </cell>
15489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15490 \begin_inset Text
15491
15492 \layout Standard
15493
15494
15495 \family roman 
15496 \series medium 
15497 \shape up 
15498 \size normal 
15499 \emph off 
15500 \bar no 
15501 \noun off 
15502 \color none
15503 convert floating point to unsigned int
15504 \end_inset 
15505 </cell>
15506 </row>
15507 <row topline="true">
15508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15509 \begin_inset Text
15510
15511 \layout Standard
15512
15513
15514 \family roman 
15515 \series medium 
15516 \shape up 
15517 \size normal 
15518 \emph off 
15519 \bar no 
15520 \noun off 
15521 \color none
15522 _fs2int.c
15523 \end_inset 
15524 </cell>
15525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15526 \begin_inset Text
15527
15528 \layout Standard
15529
15530
15531 \family roman 
15532 \series medium 
15533 \shape up 
15534 \size normal 
15535 \emph off 
15536 \bar no 
15537 \noun off 
15538 \color none
15539 convert floating point to signed int
15540 \end_inset 
15541 </cell>
15542 </row>
15543 <row topline="true">
15544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15545 \begin_inset Text
15546
15547 \layout Standard
15548
15549
15550 \family roman 
15551 \series medium 
15552 \shape up 
15553 \size normal 
15554 \emph off 
15555 \bar no 
15556 \noun off 
15557 \color none
15558 _fs2ulong.
15559 \family default 
15560 \series default 
15561 \shape default 
15562 \size default 
15563 \emph default 
15564 \bar default 
15565 \noun default 
15566 \color default
15567 c
15568 \end_inset 
15569 </cell>
15570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15571 \begin_inset Text
15572
15573 \layout Standard
15574
15575
15576 \family roman 
15577 \series medium 
15578 \shape up 
15579 \size normal 
15580 \emph off 
15581 \bar no 
15582 \noun off 
15583 \color none
15584 convert floating point to unsigned long
15585 \end_inset 
15586 </cell>
15587 </row>
15588 <row topline="true">
15589 <cell alignment="center" valignment="top" topline="true" leftline="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 _fs2long.c
15604 \end_inset 
15605 </cell>
15606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15607 \begin_inset Text
15608
15609 \layout Standard
15610
15611
15612 \family roman 
15613 \series medium 
15614 \shape up 
15615 \size normal 
15616 \emph off 
15617 \bar no 
15618 \noun off 
15619 \color none
15620 convert floating point to signed long
15621 \end_inset 
15622 </cell>
15623 </row>
15624 <row topline="true">
15625 <cell alignment="center" valignment="top" topline="true" leftline="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 _uchar2fs.c
15640 \end_inset 
15641 </cell>
15642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15643 \begin_inset Text
15644
15645 \layout Standard
15646
15647
15648 \family roman 
15649 \series medium 
15650 \shape up 
15651 \size normal 
15652 \emph off 
15653 \bar no 
15654 \noun off 
15655 \color none
15656 convert unsigned char to floating point
15657 \end_inset 
15658 </cell>
15659 </row>
15660 <row topline="true">
15661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15662 \begin_inset Text
15663
15664 \layout Standard
15665
15666
15667 \family roman 
15668 \series medium 
15669 \shape up 
15670 \size normal 
15671 \emph off 
15672 \bar no 
15673 \noun off 
15674 \color none
15675 _char2fs.c
15676 \end_inset 
15677 </cell>
15678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15679 \begin_inset Text
15680
15681 \layout Standard
15682
15683
15684 \family roman 
15685 \series medium 
15686 \shape up 
15687 \size normal 
15688 \emph off 
15689 \bar no 
15690 \noun off 
15691 \color none
15692 convert char to floating point number
15693 \end_inset 
15694 </cell>
15695 </row>
15696 <row topline="true">
15697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15698 \begin_inset Text
15699
15700 \layout Standard
15701
15702
15703 \family roman 
15704 \series medium 
15705 \shape up 
15706 \size normal 
15707 \emph off 
15708 \bar no 
15709 \noun off 
15710 \color none
15711 _uint2fs.c
15712 \end_inset 
15713 </cell>
15714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15715 \begin_inset Text
15716
15717 \layout Standard
15718
15719
15720 \family roman 
15721 \series medium 
15722 \shape up 
15723 \size normal 
15724 \emph off 
15725 \bar no 
15726 \noun off 
15727 \color none
15728 convert unsigned int to floating point
15729 \end_inset 
15730 </cell>
15731 </row>
15732 <row topline="true">
15733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15734 \begin_inset Text
15735
15736 \layout Standard
15737
15738
15739 \family roman 
15740 \series medium 
15741 \shape up 
15742 \size normal 
15743 \emph off 
15744 \bar no 
15745 \noun off 
15746 \color none
15747 _int2fs.c
15748 \end_inset 
15749 </cell>
15750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15751 \begin_inset Text
15752
15753 \layout Standard
15754
15755
15756 \family roman 
15757 \series medium 
15758 \shape up 
15759 \size normal 
15760 \emph off 
15761 \bar no 
15762 \noun off 
15763 \color none
15764 convert int to floating point numbers
15765 \end_inset 
15766 </cell>
15767 </row>
15768 <row topline="true">
15769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15770 \begin_inset Text
15771
15772 \layout Standard
15773
15774
15775 \family roman 
15776 \series medium 
15777 \shape up 
15778 \size normal 
15779 \emph off 
15780 \bar no 
15781 \noun off 
15782 \color none
15783 _ulong2fs.c
15784 \end_inset 
15785 </cell>
15786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15787 \begin_inset Text
15788
15789 \layout Standard
15790
15791
15792 \family roman 
15793 \series medium 
15794 \shape up 
15795 \size normal 
15796 \emph off 
15797 \bar no 
15798 \noun off 
15799 \color none
15800 convert unsigned long to floating point number
15801 \end_inset 
15802 </cell>
15803 </row>
15804 <row topline="true" bottomline="true">
15805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15806 \begin_inset Text
15807
15808 \layout Standard
15809
15810
15811 \family roman 
15812 \series medium 
15813 \shape up 
15814 \size normal 
15815 \emph off 
15816 \bar no 
15817 \noun off 
15818 \color none
15819 _long2fs.c
15820 \end_inset 
15821 </cell>
15822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15823 \begin_inset Text
15824
15825 \layout Standard
15826
15827
15828 \family roman 
15829 \series medium 
15830 \shape up 
15831 \size normal 
15832 \emph off 
15833 \bar no 
15834 \noun off 
15835 \color none
15836 convert long to floating point number
15837 \end_inset 
15838 </cell>
15839 </row>
15840 </lyxtabular>
15841
15842 \end_inset 
15843
15844
15845 \newline 
15846
15847 \layout Standard
15848 \added_space_bottom bigskip 
15849 These support routines are developed in ANSI-C so there is room for space
15850  and speed improvement
15851 \begin_inset Foot
15852 collapsed false
15853
15854 \layout Standard
15855
15856 These floating point routines (
15857 \emph on 
15858 not
15859 \emph default 
15860  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15861  
15862 \end_inset 
15863
15864 .
15865  Note if all these routines are used simultaneously the data space might
15866  overflow.
15867  For serious floating point usage the large model might be needed.
15868  Also notice that you don't have to call this routines directly.
15869  The compiler will use them automatically every time a floating point operation
15870  is required.
15871 \layout Section
15872
15873 Library Routines
15874 \begin_inset LatexCommand \index{Libraries}
15875
15876 \end_inset 
15877
15878
15879 \layout Standard
15880
15881
15882 \emph on 
15883 <pending: this is messy and incomplete - a little more information is in
15884  sdcc/doc/libdoc.txt
15885 \emph default 
15886  >
15887 \layout Subsection
15888
15889 Compiler support routines (_gptrget, _mulint etc.)
15890 \layout Subsection
15891
15892 Stdclib functions (puts, printf, strcat etc.)
15893 \layout Subsubsection
15894
15895 <stdio.h>
15896 \layout Standard
15897
15898
15899 \begin_inset LatexCommand \index{<stdio.h>}
15900
15901 \end_inset 
15902
15903 As usual on embedded systems you have to provide your own 
15904 \family typewriter 
15905 getchar()
15906 \begin_inset LatexCommand \index{getchar()}
15907
15908 \end_inset 
15909
15910  
15911 \family default 
15912 and 
15913 \family typewriter 
15914 putchar()
15915 \begin_inset LatexCommand \index{putchar()}
15916
15917 \end_inset 
15918
15919
15920 \family default 
15921  routines.
15922  SDCC does not know whether the system connects to a serial line with or
15923  without handshake, LCD, keyboard or other device.
15924  And whether a 
15925 \family typewriter 
15926 lf
15927 \family default 
15928  to 
15929 \family typewriter 
15930 crlf
15931 \family default 
15932  conversion within 
15933 \family typewriter 
15934 putchar()
15935 \family default 
15936  is intended.
15937  You'll find examples for serial routines f.e.
15938  in sdcc/device/lib.
15939 \layout Standard
15940
15941 The default
15942 \family typewriter 
15943  printf()
15944 \begin_inset LatexCommand \index{printf()}
15945
15946 \end_inset 
15947
15948
15949 \family default 
15950 implementation in
15951 \family typewriter 
15952  printf_large.c
15953 \family default 
15954  does not support float (except on ds390).
15955  To enable this recompile it with the option 
15956 \emph on 
15957 -
15958 \begin_inset ERT
15959 status Collapsed
15960
15961 \layout Standard
15962
15963 \backslash 
15964 /
15965 \end_inset 
15966
15967 DUSE_FLOATS=1
15968 \begin_inset LatexCommand \index{USE\_FLOATS}
15969
15970 \end_inset 
15971
15972
15973 \emph default 
15974  on the command line.
15975  Use
15976 \emph on 
15977  -
15978 \begin_inset ERT
15979 status Collapsed
15980
15981 \layout Standard
15982
15983 \backslash 
15984 /
15985 \end_inset 
15986
15987 -model-large
15988 \begin_inset LatexCommand \index{-\/-model-large}
15989
15990 \end_inset 
15991
15992
15993 \emph default 
15994  for the mcs51 port, since this uses a lot of memory.
15995 \layout Standard
15996
15997 If you're short on memory you might want to use 
15998 \family typewriter 
15999 printf_small()
16000 \begin_inset LatexCommand \index{printf\_small()}
16001
16002 \end_inset 
16003
16004
16005 \family default 
16006  
16007 \emph on 
16008 instead
16009 \emph default 
16010  of
16011 \family typewriter 
16012  printf().
16013
16014 \family default 
16015  For the mcs51 there additionally are assembly versions 
16016 \family typewriter 
16017 printf_tiny()
16018 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16019
16020 \end_inset 
16021
16022
16023 \family default 
16024  (subset of printf using less than 270 bytes) and 
16025 \family typewriter 
16026 printf_fast()
16027 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16028
16029 \end_inset 
16030
16031  
16032 \family default 
16033 and
16034 \family typewriter 
16035  printf_fast_f()
16036 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16037
16038 \end_inset 
16039
16040
16041 \family default 
16042  (floating-point aware version of printf_fast) which should fit the requirements
16043  of many embedded systems (printf_fast() can be customized by unsetting
16044  #defines to 
16045 \emph on 
16046 not
16047 \emph default 
16048  support long variables and field widths).
16049 \layout Subsubsection
16050
16051 <malloc.h>
16052 \begin_inset LatexCommand \index{malloc.h}
16053
16054 \end_inset 
16055
16056
16057 \layout Standard
16058
16059 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16060  using dynamic memory allocation
16061 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16062
16063 \end_inset 
16064
16065  and a default heap
16066 \begin_inset LatexCommand \index{heap (malloc)}
16067
16068 \end_inset 
16069
16070  space of 1024 bytes is provided for malloc to allocate memory from.
16071  If you need a different heap size you need to recompile _heap.c with the
16072  required size defined in HEAP_SIZE.
16073  It is recommended to make a copy of this file into your project directory
16074  and compile it there with:
16075 \layout Verse
16076
16077
16078 \family typewriter 
16079 sdcc -c _heap.c -D HEAD_SIZE=2048
16080 \newline 
16081
16082 \family default 
16083 And then link it with:
16084 \layout Verse
16085
16086
16087 \family typewriter 
16088 sdcc main.rel _heap.rel
16089 \newline 
16090
16091 \layout Subsection
16092
16093 Math functions (sinf, powf, sqrtf etc.)
16094 \layout Subsubsection
16095
16096 <math.h>
16097 \layout Standard
16098
16099 See definitions in file <math.h>.
16100 \layout Subsection
16101
16102 Other libraries
16103 \layout Standard
16104
16105 Libraries
16106 \begin_inset LatexCommand \index{Libraries}
16107
16108 \end_inset 
16109
16110  included in SDCC should have a license at least as liberal as the GNU Lesser
16111  General Public License
16112 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16113
16114 \end_inset 
16115
16116  
16117 \emph on 
16118 LGPL
16119 \emph default 
16120 .
16121 \layout Comment
16122
16123 license statements for the libraries are missing.
16124  sdcc/device/lib/ser_ir.c
16125 \layout Comment
16126
16127 or _decdptr f.e.
16128  come with a GPL (as opposed to LGPL) License - this will not be liberal
16129  enough for many embedded programmers.
16130 \layout Standard
16131
16132 If you have ported some library or want to share experience about some code
16133  which f.e.
16134  falls into any of these categories Busses (I
16135 \begin_inset Formula $^{\textrm{2}}$
16136 \end_inset 
16137
16138 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16139  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16140  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16141 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16142
16143 \end_inset 
16144
16145 \SpecialChar ~
16146 would certainly like to hear about it.
16147 \layout Standard
16148 \added_space_bottom bigskip 
16149 Programmers coding for embedded systems are not especially famous for being
16150  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16151 e these references are very valuable.
16152  Let's help to create a climate where information is shared.
16153 \layout Section
16154
16155 Memory Models
16156 \layout Subsection
16157
16158 MCS51 Memory Models
16159 \begin_inset LatexCommand \index{Memory model}
16160
16161 \end_inset 
16162
16163
16164 \begin_inset LatexCommand \index{MCS51 memory model}
16165
16166 \end_inset 
16167
16168
16169 \layout Subsubsection
16170
16171 Small, Medium and Large
16172 \layout Standard
16173
16174 SDCC allows three memory models for MCS51 code, 
16175 \shape slanted 
16176 small, medium
16177 \shape default 
16178  and 
16179 \shape slanted 
16180 large
16181 \shape default 
16182 .
16183  Modules compiled with different memory models should 
16184 \emph on 
16185 never
16186 \emph default 
16187  be combined together or the results would be unpredictable.
16188  The library routines supplied with the compiler are compiled as small,
16189  medium and large.
16190  The compiled library modules are contained in separate directories as small,
16191  medium and large so that you can link to the appropriate set.
16192 \layout Standard
16193
16194 When the medium or large model is used all variables declared without a
16195  storage class will be allocated into the external ram, this includes all
16196  parameters and local variables (for non-reentrant
16197 \begin_inset LatexCommand \index{reentrant}
16198
16199 \end_inset 
16200
16201  functions).
16202  When the small model is used variables without storage class are allocated
16203  in the internal ram.
16204 \layout Standard
16205
16206 Judicious usage of the processor specific storage classes
16207 \begin_inset LatexCommand \index{Storage class}
16208
16209 \end_inset 
16210
16211  and the 'reentrant' function type will yield much more efficient code,
16212  than using the large model.
16213  Several optimizations are disabled when the program is compiled using the
16214  large model, it is therefore recommended that the small model be used unless
16215  absolutely required.
16216 \layout Subsubsection
16217
16218 External Stack
16219 \begin_inset LatexCommand \label{sub:External-Stack}
16220
16221 \end_inset 
16222
16223
16224 \begin_inset LatexCommand \index{stack}
16225
16226 \end_inset 
16227
16228
16229 \begin_inset LatexCommand \index{External stack (mcs51)}
16230
16231 \end_inset 
16232
16233
16234 \layout Standard
16235
16236 The external stack (-
16237 \begin_inset ERT
16238 status Collapsed
16239
16240 \layout Standard
16241
16242 \backslash 
16243 /
16244 \end_inset 
16245
16246 -xstack option
16247 \begin_inset LatexCommand \index{-\/-xstack}
16248
16249 \end_inset 
16250
16251 ) is located in pdata
16252 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16253
16254 \end_inset 
16255
16256  memory (usually at the start of the external ram segment) and uses all
16257  unused space in pdata (max.
16258  256 bytes).
16259  When -
16260 \begin_inset ERT
16261 status Collapsed
16262
16263 \layout Standard
16264
16265 \backslash 
16266 /
16267 \end_inset 
16268
16269 -xstack option is used to compile the program, the parameters and local
16270  variables
16271 \begin_inset LatexCommand \index{local variables}
16272
16273 \end_inset 
16274
16275  of all reentrant functions are allocated in this area.
16276  This option is provided for programs with large stack space requirements.
16277  When used with the -
16278 \begin_inset ERT
16279 status Collapsed
16280
16281 \layout Standard
16282
16283 \backslash 
16284 /
16285 \end_inset 
16286
16287 -stack-auto
16288 \begin_inset LatexCommand \index{-\/-stack-auto}
16289
16290 \end_inset 
16291
16292  option, all parameters and local variables are allocated on the external
16293  stack (note: support libraries will need to be recompiled with the same
16294  options.
16295  There is a predefined target in the library makefile).
16296 \layout Standard
16297
16298 The compiler outputs the higher order address byte of the external ram segment
16299  into port P2
16300 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16301
16302 \end_inset 
16303
16304  (see also section 
16305 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16306
16307 \end_inset 
16308
16309 ), therefore when using the External Stack option, this port 
16310 \emph on 
16311 may not
16312 \emph default 
16313  be used by the application program.
16314 \layout Subsection
16315
16316 DS390 Memory Model
16317 \begin_inset LatexCommand \index{Memory model}
16318
16319 \end_inset 
16320
16321
16322 \begin_inset LatexCommand \index{DS390 memory model}
16323
16324 \end_inset 
16325
16326
16327 \layout Standard
16328
16329 The only model supported is Flat 24
16330 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16331
16332 \end_inset 
16333
16334 .
16335  This generates code for the 24 bit contiguous addressing mode of the Dallas
16336  DS80C390 part.
16337  In this mode, up to four meg of external RAM or code space can be directly
16338  addressed.
16339  See the data sheets at www.dalsemi.com for further information on this part.
16340 \newline 
16341
16342 \newline 
16343 Note that the compiler does not generate any code to place the processor
16344  into 24 bitmode (although 
16345 \emph on 
16346 tinibios
16347 \emph default 
16348  in the ds390 libraries will do that for you).
16349  If you don't use 
16350 \emph on 
16351 tinibios
16352 \emph default 
16353
16354 \begin_inset LatexCommand \index{Tinibios (DS390)}
16355
16356 \end_inset 
16357
16358 , the boot loader or similar code must ensure that the processor is in 24
16359  bit contiguous addressing mode before calling the SDCC startup code.
16360 \newline 
16361
16362 \newline 
16363 Like the 
16364 \emph on 
16365 -
16366 \begin_inset ERT
16367 status Collapsed
16368
16369 \layout Standard
16370
16371 \backslash 
16372 /
16373 \end_inset 
16374
16375 -model-large
16376 \emph default 
16377  option, variables will by default be placed into the XDATA segment.
16378  
16379 \newline 
16380
16381 \newline 
16382 Segments may be placed anywhere in the 4 meg address space using the usual
16383  -
16384 \begin_inset ERT
16385 status Collapsed
16386
16387 \layout Standard
16388
16389 \backslash 
16390 /
16391 \end_inset 
16392
16393 -*-loc options.
16394  Note that if any segments are located above 64K, the -r flag must be passed
16395  to the linker to generate the proper segment relocations, and the Intel
16396  HEX output format must be used.
16397  The -r flag can be passed to the linker by using the option 
16398 \emph on 
16399 -Wl-r
16400 \emph default 
16401  on the SDCC command line.
16402  However, currently the linker can not handle code segments > 64k.
16403 \layout Section
16404
16405 Pragmas
16406 \begin_inset LatexCommand \label{sec:Pragmas}
16407
16408 \end_inset 
16409
16410
16411 \begin_inset LatexCommand \index{Pragmas}
16412
16413 \end_inset 
16414
16415
16416 \layout Standard
16417
16418 SDCC supports the following #pragma directives:
16419 \layout Itemize
16420
16421
16422 \series bold 
16423 save
16424 \series default 
16425
16426 \begin_inset LatexCommand \index{\#pragma save}
16427
16428 \end_inset 
16429
16430  - this will save most current options to the save/restore stack.
16431  See #pragma\SpecialChar ~
16432 restore.
16433 \layout Itemize
16434
16435
16436 \series bold 
16437 restore
16438 \series default 
16439
16440 \begin_inset LatexCommand \index{\#pragma restore}
16441
16442 \end_inset 
16443
16444  - will restore saved options from the last save.
16445  saves & restores can be nested.
16446  SDCC uses a save/restore stack: save pushes current options to the stack,
16447  restore pulls current options from the stack.
16448  See #pragma\SpecialChar ~
16449 save.
16450 \newline 
16451
16452 \layout Itemize
16453
16454
16455 \series bold 
16456 callee_saves
16457 \series default 
16458
16459 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16460
16461 \end_inset 
16462
16463
16464 \begin_inset LatexCommand \index{function prologue}
16465
16466 \end_inset 
16467
16468  function1[,function2[,function3...]] - The compiler by default uses a caller
16469  saves convention for register saving across function calls, however this
16470  can cause unnecessary register pushing & popping
16471 \begin_inset LatexCommand \index{push/pop}
16472
16473 \end_inset 
16474
16475  when calling small functions from larger functions.
16476  This option can be used to switch off the register saving convention for
16477  the function names specified.
16478  The compiler will not save registers when calling these functions, extra
16479  code need to be manually inserted at the entry & exit for these functions
16480  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16481  reduce code & improve run time performance of the generated code.
16482  In the future the compiler (with inter procedural analysis) may be able
16483  to determine the appropriate scheme to use for each function call.
16484  If -
16485 \begin_inset ERT
16486 status Collapsed
16487
16488 \layout Standard
16489
16490 \backslash 
16491 /
16492 \end_inset 
16493
16494 -callee-saves command line option is used, the function names specified
16495  in #pragma\SpecialChar ~
16496 callee_saves
16497 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16498
16499 \end_inset 
16500
16501  is appended to the list of functions specified in the command line.
16502 \layout Itemize
16503
16504
16505 \series bold 
16506 exclude
16507 \series default 
16508
16509 \begin_inset LatexCommand \index{\#pragma exclude}
16510
16511 \end_inset 
16512
16513  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16514  of pairs of push/pop
16515 \begin_inset LatexCommand \index{push/pop}
16516
16517 \end_inset 
16518
16519  instructions in 
16520 \emph on 
16521 I
16522 \emph default 
16523 nterrupt
16524 \begin_inset LatexCommand \index{interrupt}
16525
16526 \end_inset 
16527
16528  
16529 \emph on 
16530 S
16531 \emph default 
16532 ervice 
16533 \emph on 
16534 R
16535 \emph default 
16536 outines.
16537  The directive should be placed immediately before the ISR function definition
16538  and it affects ALL ISR functions following it.
16539  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16540 exclude\SpecialChar ~
16541 none
16542 \begin_inset LatexCommand \index{\#pragma exclude}
16543
16544 \end_inset 
16545
16546 .
16547  See also the related keyword _naked
16548 \begin_inset LatexCommand \index{\_naked}
16549
16550 \end_inset 
16551
16552
16553 \begin_inset LatexCommand \index{\_\_naked}
16554
16555 \end_inset 
16556
16557 .
16558 \layout Itemize
16559
16560
16561 \series bold 
16562 less_pedantic
16563 \series default 
16564
16565 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16566
16567 \end_inset 
16568
16569  - the compiler will not warn you anymore for obvious mistakes, you'r on
16570  your own now ;-(
16571 \layout Itemize
16572
16573
16574 \series bold 
16575 disable_warning
16576 \series default 
16577  <nnnn>
16578 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16579
16580 \end_inset 
16581
16582  - the compiler will not warn you anymore about warning number <nnnn>.
16583 \layout Itemize
16584
16585
16586 \series bold 
16587 nogcse
16588 \series default 
16589
16590 \begin_inset LatexCommand \index{\#pragma nogcse}
16591
16592 \end_inset 
16593
16594  - will stop global common subexpression elimination.
16595 \layout Itemize
16596
16597
16598 \series bold 
16599 noinduction
16600 \series default 
16601
16602 \begin_inset LatexCommand \index{\#pragma noinduction}
16603
16604 \end_inset 
16605
16606  - will stop loop induction optimizations.
16607 \layout Itemize
16608
16609
16610 \series bold 
16611 noinvariant
16612 \series default 
16613
16614 \begin_inset LatexCommand \index{\#pragma noinvariant}
16615
16616 \end_inset 
16617
16618  - will not do loop invariant optimizations.
16619  For more details see Loop Invariants in section
16620 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16621
16622 \end_inset 
16623
16624 .
16625 \layout Itemize
16626
16627
16628 \series bold 
16629 noiv
16630 \series default 
16631
16632 \begin_inset LatexCommand \index{\#pragma noiv}
16633
16634 \end_inset 
16635
16636  - Do not generate interrupt
16637 \begin_inset LatexCommand \index{interrupt}
16638
16639 \end_inset 
16640
16641  vector table
16642 \begin_inset LatexCommand \index{interrupt vector table}
16643
16644 \end_inset 
16645
16646  entries for all ISR functions defined after the pragma.
16647  This is useful in cases where the interrupt vector table must be defined
16648  manually, or when there is a secondary, manually defined interrupt vector
16649  table (e.g.
16650  for the autovector feature of the Cypress EZ-USB FX2).
16651  More elegantly this can be achieved by obmitting the optional interrupt
16652  number after the interrupt keyword, see section 
16653 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16654
16655 \end_inset 
16656
16657 \SpecialChar ~
16658 about interrupts.
16659 \layout Itemize
16660
16661
16662 \series bold 
16663 nojtbound
16664 \series default 
16665
16666 \begin_inset LatexCommand \index{\#pragma nojtbound}
16667
16668 \end_inset 
16669
16670  - will not generate code for boundary value checking, when switch statements
16671  are turned into jump-tables (dangerous).
16672  For more details see section 
16673 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16674
16675 \end_inset 
16676
16677 .
16678 \layout Itemize
16679
16680
16681 \series bold 
16682 noloopreverse
16683 \series default 
16684
16685 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16686
16687 \end_inset 
16688
16689  - Will not do loop reversal optimization
16690 \layout Itemize
16691
16692
16693 \series bold 
16694 nooverlay
16695 \series default 
16696
16697 \begin_inset LatexCommand \index{\#pragma nooverlay}
16698
16699 \end_inset 
16700
16701  - the compiler will not overlay the parameters and local variables of a
16702  function.
16703 \layout Itemize
16704
16705
16706 \series bold 
16707 stackauto
16708 \series default 
16709
16710 \begin_inset LatexCommand \index{\#pragma stackauto}
16711
16712 \end_inset 
16713
16714 - See option -
16715 \begin_inset ERT
16716 status Collapsed
16717
16718 \layout Standard
16719
16720 \backslash 
16721 /
16722 \end_inset 
16723
16724 -stack-auto
16725 \begin_inset LatexCommand \index{-\/-stack-auto}
16726
16727 \end_inset 
16728
16729  and section 
16730 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16731
16732 \end_inset 
16733
16734  Parameters and Local Variables.
16735 \layout Itemize
16736
16737
16738 \series bold 
16739 opt_code_speed
16740 \series default 
16741  
16742 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16743
16744 \end_inset 
16745
16746 - The compiler will optimize code generation towards fast code, possibly
16747  at the expense of code size.
16748  Currently this has little effect.
16749 \layout Itemize
16750
16751
16752 \series bold 
16753 opt_code_size
16754 \series default 
16755  
16756 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16757
16758 \end_inset 
16759
16760 - The compiler will optimize code generation towards compact code, possibly
16761  at the expense of code speed.
16762  Currently this has little effect.
16763 \layout Itemize
16764
16765
16766 \series bold 
16767 opt_code_balanced
16768 \series default 
16769  
16770 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16771
16772 \end_inset 
16773
16774 - The compiler will attempt to generate code that is both compact and fast,
16775  as long as meeting one goal is not a detriment to the other (this is the
16776  default).
16777  
16778 \layout Itemize
16779
16780
16781 \series bold 
16782 std_sdcc89
16783 \series default 
16784  
16785 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16786
16787 \end_inset 
16788
16789 - Generally follow the C89 standard, but allow SDCC features that conflict
16790  with the standard (default).
16791 \layout Itemize
16792
16793
16794 \series bold 
16795 std_c89
16796 \series default 
16797  
16798 \begin_inset LatexCommand \index{\#pragma std\_c89}
16799
16800 \end_inset 
16801
16802 - Follow the C89 standard and disable SDCC features that conflict with the
16803  standard.
16804 \layout Itemize
16805
16806
16807 \series bold 
16808 std_sdcc99
16809 \series default 
16810  
16811 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16812
16813 \end_inset 
16814
16815 - Generally follow the C99 standard, but allow SDCC features that conflict
16816  with the standard (incomplete support).
16817 \layout Itemize
16818
16819
16820 \series bold 
16821 std_c99
16822 \series default 
16823  
16824 \begin_inset LatexCommand \index{\#pragma std\_c99}
16825
16826 \end_inset 
16827
16828 - Follow the C99 standard and disable SDCC features that conflict with the
16829  standard (incomplete support).
16830 \layout Itemize
16831
16832
16833 \series bold 
16834 codeseg
16835 \series default 
16836  <name>
16837 \begin_inset LatexCommand \index{\#pragma codeseg}
16838
16839 \end_inset 
16840
16841 - Use this name (max.
16842  8 characters) for the code segment.
16843  See option -
16844 \begin_inset ERT
16845 status Collapsed
16846
16847 \layout Standard
16848
16849 \backslash 
16850 /
16851 \end_inset 
16852
16853 -codeseg.
16854 \layout Itemize
16855
16856
16857 \series bold 
16858 constseg
16859 \series default 
16860  <name>
16861 \begin_inset LatexCommand \index{\#pragma constseg}
16862
16863 \end_inset 
16864
16865 - Use this name (max.
16866  8 characters) for the const segment.
16867  See option -
16868 \begin_inset ERT
16869 status Collapsed
16870
16871 \layout Standard
16872
16873 \backslash 
16874 /
16875 \end_inset 
16876
16877 -constseg.
16878 \layout Standard
16879
16880 The preprocessor SDCPP
16881 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16882
16883 \end_inset 
16884
16885  supports the following #pragma directives:
16886 \layout Itemize
16887
16888
16889 \series bold 
16890 preproc_asm
16891 \series default 
16892
16893 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16894
16895 \end_inset 
16896
16897  (+ | -) - switch _asm _endasm block preprocessing on / off.
16898  Default is on.
16899  You use this prama to define multilines of assembly code.
16900  This will prevent the preprocessor from changing the formating required
16901  by assembly code.
16902  Below is an example on how to use this pragma.
16903 \layout Verse
16904
16905
16906 \family typewriter 
16907 #pragma preproc_asm -
16908 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16909
16910 \end_inset 
16911
16912
16913 \newline 
16914 #define MYDELAY _asm
16915 \newline 
16916 \SpecialChar ~
16917 \SpecialChar ~
16918 \SpecialChar ~
16919 nop ;my assembly comment...
16920 \newline 
16921 \SpecialChar ~
16922 \SpecialChar ~
16923 \SpecialChar ~
16924 nop
16925 \newline 
16926 \SpecialChar ~
16927 \SpecialChar ~
16928 \SpecialChar ~
16929 nop
16930 \newline 
16931 _endasm
16932 \newline 
16933 #pragma preproc_asm +
16934 \newline 
16935
16936 \newline 
16937 void foo (void) 
16938 \newline 
16939
16940 \newline 
16941 \SpecialChar ~
16942 \SpecialChar ~
16943 \SpecialChar ~
16944  ...
16945  
16946 \newline 
16947 \SpecialChar ~
16948 \SpecialChar ~
16949 \SpecialChar ~
16950  MYDELAY;
16951 \newline 
16952 \SpecialChar ~
16953 \SpecialChar ~
16954 \SpecialChar ~
16955  ...
16956  
16957 \newline 
16958
16959 \newline 
16960
16961 \layout Standard
16962
16963 The pragma's are intended to be used to turn-on or off certain optimizations
16964  which might cause the compiler to generate extra stack / data space to
16965  store compiler generated temporary variables.
16966  This usually happens in large functions.
16967  Pragma directives should be used as shown in the following example, they
16968  are used to control options & optimizations for a given function; pragmas
16969  should be placed before and/or after a function, placing pragma's inside
16970  a function body could have unpredictable results.
16971 \layout Verse
16972
16973
16974 \family typewriter 
16975 #pragma save
16976 \begin_inset LatexCommand \index{\#pragma save}
16977
16978 \end_inset 
16979
16980  \SpecialChar ~
16981 \SpecialChar ~
16982 \SpecialChar ~
16983 \SpecialChar ~
16984 \SpecialChar ~
16985 \SpecialChar ~
16986 \SpecialChar ~
16987 /* save the current settings */ 
16988 \newline 
16989 #pragma nogcse
16990 \begin_inset LatexCommand \index{\#pragma nogcse}
16991
16992 \end_inset 
16993
16994  \SpecialChar ~
16995 \SpecialChar ~
16996 \SpecialChar ~
16997 \SpecialChar ~
16998 \SpecialChar ~
16999 /* turnoff global subexpression elimination */ 
17000 \newline 
17001 #pragma noinduction
17002 \begin_inset LatexCommand \index{\#pragma noinduction}
17003
17004 \end_inset 
17005
17006  /* turn off induction optimizations */ 
17007 \newline 
17008 int foo () 
17009 \newline 
17010
17011 \newline 
17012 \SpecialChar ~
17013  \SpecialChar ~
17014  ...
17015  
17016 \newline 
17017 \SpecialChar ~
17018  \SpecialChar ~
17019  /* large code */ 
17020 \newline 
17021 \SpecialChar ~
17022  \SpecialChar ~
17023  ...
17024  
17025 \newline 
17026
17027 \newline 
17028 #pragma restore
17029 \begin_inset LatexCommand \index{\#pragma restore}
17030
17031 \end_inset 
17032
17033  /* turn the optimizations back on */
17034 \layout Standard
17035
17036 The compiler will generate a warning message when extra space is allocated.
17037  It is strongly recommended that the save and restore pragma's be used when
17038  changing options for a function.
17039 \newline 
17040
17041 \newline 
17042
17043 \newline 
17044
17045 \layout Section
17046
17047 Defines Created by the Compiler
17048 \layout Standard
17049
17050 The compiler creates the following #defines
17051 \begin_inset LatexCommand \index{\#defines}
17052
17053 \end_inset 
17054
17055
17056 \begin_inset LatexCommand \index{Defines created by the compiler}
17057
17058 \end_inset 
17059
17060 :
17061 \newline 
17062
17063 \layout Standard
17064
17065
17066 \begin_inset  Tabular
17067 <lyxtabular version="3" rows="11" columns="2">
17068 <features>
17069 <column alignment="left" valignment="top" leftline="true" width="3in">
17070 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17071 <row topline="true" bottomline="true">
17072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17073 \begin_inset Text
17074
17075 \layout Standard
17076
17077
17078 \series bold 
17079 #define
17080 \end_inset 
17081 </cell>
17082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17083 \begin_inset Text
17084
17085 \layout Standard
17086
17087
17088 \series bold 
17089 Description
17090 \end_inset 
17091 </cell>
17092 </row>
17093 <row topline="true">
17094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17095 \begin_inset Text
17096
17097 \layout Standard
17098
17099 SDCC
17100 \begin_inset LatexCommand \index{SDCC}
17101
17102 \end_inset 
17103
17104  
17105 \end_inset 
17106 </cell>
17107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17108 \begin_inset Text
17109
17110 \layout Standard
17111
17112 Always defined.
17113  Since version 2.5.6 the version number as an int (ex.
17114  256)
17115 \end_inset 
17116 </cell>
17117 </row>
17118 <row topline="true">
17119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17120 \begin_inset Text
17121
17122 \layout Standard
17123
17124 SDCC_mcs51
17125 \begin_inset LatexCommand \index{SDCC\_mcs51}
17126
17127 \end_inset 
17128
17129  or SDCC_ds390
17130 \begin_inset LatexCommand \index{SDCC\_ds390}
17131
17132 \end_inset 
17133
17134  or SDCC_z80
17135 \begin_inset LatexCommand \index{SDCC\_z80}
17136
17137 \end_inset 
17138
17139 , etc.
17140 \end_inset 
17141 </cell>
17142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17143 \begin_inset Text
17144
17145 \layout Standard
17146
17147 depending on the model used (e.g.: -mds390)
17148 \end_inset 
17149 </cell>
17150 </row>
17151 <row topline="true">
17152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17153 \begin_inset Text
17154
17155 \layout Standard
17156
17157 __mcs51
17158 \begin_inset LatexCommand \index{\_\_mcs51}
17159
17160 \end_inset 
17161
17162 , __ds390
17163 \begin_inset LatexCommand \index{\_\_ds390}
17164
17165 \end_inset 
17166
17167 , __hc08
17168 \begin_inset LatexCommand \index{\_\_hc08}
17169
17170 \end_inset 
17171
17172 , __z80
17173 \begin_inset LatexCommand \index{\_\_z80}
17174
17175 \end_inset 
17176
17177 , etc
17178 \end_inset 
17179 </cell>
17180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17181 \begin_inset Text
17182
17183 \layout Standard
17184
17185 depending on the model used (e.g.
17186  -mz80)
17187 \end_inset 
17188 </cell>
17189 </row>
17190 <row topline="true">
17191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17192 \begin_inset Text
17193
17194 \layout Standard
17195
17196 SDCC_STACK_AUTO
17197 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17198
17199 \end_inset 
17200
17201
17202 \end_inset 
17203 </cell>
17204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17205 \begin_inset Text
17206
17207 \layout Standard
17208
17209 when 
17210 \emph on 
17211 -
17212 \begin_inset ERT
17213 status Collapsed
17214
17215 \layout Standard
17216
17217 \backslash 
17218 /
17219 \end_inset 
17220
17221 -stack-auto
17222 \emph default 
17223  option is used
17224 \end_inset 
17225 </cell>
17226 </row>
17227 <row topline="true">
17228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17229 \begin_inset Text
17230
17231 \layout Standard
17232
17233 SDCC_MODEL_SMALL
17234 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17235
17236 \end_inset 
17237
17238
17239 \end_inset 
17240 </cell>
17241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17242 \begin_inset Text
17243
17244 \layout Standard
17245
17246 when 
17247 \emph on 
17248 -
17249 \begin_inset ERT
17250 status Collapsed
17251
17252 \layout Standard
17253
17254 \backslash 
17255 /
17256 \end_inset 
17257
17258 -model-small
17259 \emph default 
17260  is used
17261 \end_inset 
17262 </cell>
17263 </row>
17264 <row topline="true">
17265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17266 \begin_inset Text
17267
17268 \layout Standard
17269
17270 SDCC_MODEL_MEDIUM
17271 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17272
17273 \end_inset 
17274
17275
17276 \end_inset 
17277 </cell>
17278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17279 \begin_inset Text
17280
17281 \layout Standard
17282
17283 when 
17284 \emph on 
17285 -
17286 \begin_inset ERT
17287 status Collapsed
17288
17289 \layout Standard
17290
17291 \backslash 
17292 /
17293 \end_inset 
17294
17295 -model-medium
17296 \emph default 
17297  is used
17298 \end_inset 
17299 </cell>
17300 </row>
17301 <row topline="true">
17302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17303 \begin_inset Text
17304
17305 \layout Standard
17306
17307 SDCC_MODEL_LARGE
17308 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17309
17310 \end_inset 
17311
17312
17313 \end_inset 
17314 </cell>
17315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17316 \begin_inset Text
17317
17318 \layout Standard
17319
17320 when 
17321 \emph on 
17322 -
17323 \begin_inset ERT
17324 status Collapsed
17325
17326 \layout Standard
17327
17328 \backslash 
17329 /
17330 \end_inset 
17331
17332 -model-large
17333 \emph default 
17334  is used
17335 \end_inset 
17336 </cell>
17337 </row>
17338 <row topline="true">
17339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17340 \begin_inset Text
17341
17342 \layout Standard
17343
17344 SDCC_USE_XSTACK
17345 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17346
17347 \end_inset 
17348
17349
17350 \end_inset 
17351 </cell>
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17353 \begin_inset Text
17354
17355 \layout Standard
17356
17357 when 
17358 \emph on 
17359 -
17360 \begin_inset ERT
17361 status Collapsed
17362
17363 \layout Standard
17364
17365 \backslash 
17366 /
17367 \end_inset 
17368
17369 -xstack
17370 \emph default 
17371  option is used
17372 \end_inset 
17373 </cell>
17374 </row>
17375 <row topline="true">
17376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17377 \begin_inset Text
17378
17379 \layout Standard
17380
17381 SDCC_STACK_TENBIT
17382 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17383
17384 \end_inset 
17385
17386  
17387 \end_inset 
17388 </cell>
17389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17390 \begin_inset Text
17391
17392 \layout Standard
17393
17394 when 
17395 \emph on 
17396 -mds390
17397 \emph default 
17398  is used
17399 \end_inset 
17400 </cell>
17401 </row>
17402 <row topline="true" bottomline="true">
17403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17404 \begin_inset Text
17405
17406 \layout Standard
17407
17408 SDCC_MODEL_FLAT24
17409 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17410
17411 \end_inset 
17412
17413
17414 \end_inset 
17415 </cell>
17416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17417 \begin_inset Text
17418
17419 \layout Standard
17420
17421 when 
17422 \emph on 
17423 -mds390
17424 \emph default 
17425  is used
17426 \end_inset 
17427 </cell>
17428 </row>
17429 </lyxtabular>
17430
17431 \end_inset 
17432
17433
17434 \layout Chapter
17435
17436 Notes on supported Processors
17437 \layout Section
17438
17439 MCS51 variants
17440 \begin_inset LatexCommand \label{sub:MCS51-variants}
17441
17442 \end_inset 
17443
17444
17445 \begin_inset LatexCommand \index{MCS51 variants}
17446
17447 \end_inset 
17448
17449
17450 \layout Standard
17451
17452 MCS51 processors are available from many vendors and come in many different
17453  flavours.
17454  While they might differ considerably in respect to Special Function Registers
17455  the core MCS51 is usually not modified or is kept compatible.
17456  
17457 \layout Subsection
17458
17459 pdata access by SFR 
17460 \layout Standard
17461
17462 With the upcome of devices with internal xdata and flash memory devices
17463  using port P2
17464 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17465
17466 \end_inset 
17467
17468  as dedicated I/O port is becoming more popular.
17469  Switching the high byte for pdata
17470 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17471
17472 \end_inset 
17473
17474  access which was formerly done by port P2 is then achieved by a Special
17475  Function Register
17476 \begin_inset LatexCommand \index{sfr}
17477
17478 \end_inset 
17479
17480 .
17481  In well-established MCS51 tradition the address of this 
17482 \emph on 
17483 sfr
17484 \emph default 
17485  is where the chip designers decided to put it.
17486  Needless to say that they didn't agree on a common name either.
17487  So that the startup code can correctly initialize xdata variables, you
17488  should define an sfr with the name _XPAGE
17489 \family typewriter 
17490
17491 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17492
17493 \end_inset 
17494
17495
17496 \family default 
17497  at the appropriate location if the default, port P2, is not used for this.
17498  Some examples are:
17499 \layout Verse
17500
17501
17502 \family typewriter 
17503 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17504 \layout Verse
17505
17506
17507 \family typewriter 
17508 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17509 \layout Verse
17510
17511
17512 \family typewriter 
17513 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17514 \layout Standard
17515
17516 For more exotic implementations further customizations may be needed.
17517  See section 
17518 \begin_inset LatexCommand \ref{sub:Startup-Code}
17519
17520 \end_inset 
17521
17522  for other possibilities.
17523 \layout Subsection
17524
17525 Other Features available by SFR
17526 \layout Standard
17527 \added_space_bottom bigskip 
17528 Some MCS51 variants offer features like Double DPTR
17529 \begin_inset LatexCommand \index{DPTR}
17530
17531 \end_inset 
17532
17533 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17534  These are currently not used for the MCS51 port.
17535  If you absolutely need them you can fall back to inline assembly or submit
17536  a patch to SDCC.
17537 \layout Section
17538
17539 DS400 port
17540 \layout Standard
17541 \added_space_bottom bigskip 
17542 The DS80C400
17543 \begin_inset LatexCommand \index{DS80C400}
17544
17545 \end_inset 
17546
17547
17548 \begin_inset LatexCommand \index{DS400}
17549
17550 \end_inset 
17551
17552  microcontroller has a rich set of peripherals.
17553  In its built-in ROM library it includes functions to access some of the
17554  features, among them is a TCP stack with IP4 and IP6 support.
17555  Library headers (currently in beta status) and other files are provided
17556  at 
17557 \size footnotesize 
17558
17559 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17560
17561 \end_inset 
17562
17563 .
17564  
17565 \layout Section
17566
17567 The Z80 and gbz80 port
17568 \layout Standard
17569
17570 SDCC can target both the Zilog Z80
17571 \begin_inset LatexCommand \index{Z80}
17572
17573 \end_inset 
17574
17575  and the Nintendo Gameboy's Z80-like gbz80
17576 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17577
17578 \end_inset 
17579
17580 .
17581  The Z80 port is passed through the same 
17582 \emph on 
17583 regressions tests
17584 \begin_inset LatexCommand \index{Regression test}
17585
17586 \end_inset 
17587
17588
17589 \emph default 
17590  (see section 
17591 \begin_inset LatexCommand \ref{sec:Quality-control}
17592
17593 \end_inset 
17594
17595 ) as the MCS51 and DS390 ports, so floating point support, support for long
17596  variables and bitfield support is fine.
17597  See mailing lists and forums about interrupt routines.
17598 \layout Standard
17599 \added_space_bottom bigskip 
17600 As always, the code is the authoritative reference - see z80/ralloc.c and
17601  z80/gen.c.
17602  The stack
17603 \begin_inset LatexCommand \index{Z80!stack}
17604
17605 \end_inset 
17606
17607  frame is similar to that generated by the IAR Z80 compiler.
17608  IX is used as the base pointer, HL and IY are used as a temporary registers,
17609  and BC and DE are available for holding variables.
17610  Return values
17611 \begin_inset LatexCommand \index{Z80!return value}
17612
17613 \end_inset 
17614
17615  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17616  bytes).
17617  The gbz80 port use the same set of registers for the return values, but
17618  in a different order of significance: E (one byte), DE (two bytes), or
17619  HLDE (four bytes).
17620 \layout Section
17621
17622 The HC08 port
17623 \layout Standard
17624
17625 The port to the Freescale/Motorola HC08
17626 \begin_inset LatexCommand \index{HC08}
17627
17628 \end_inset 
17629
17630  family has been added in October 2003, and is still undergoing some basic
17631  development.
17632  The code generator is complete, but the register allocation is still quite
17633  unoptimized.
17634  Some of the SDCC's standard C library functions have embedded non-HC08
17635  inline assembly and so are not yet usable.
17636 \layout Standard
17637 \added_space_bottom bigskip 
17638 The HC08 port passes the regression test suite (see section 
17639 \begin_inset LatexCommand \ref{sec:Quality-control}
17640
17641 \end_inset 
17642
17643 ).
17644 \layout Section
17645 \pagebreak_top 
17646 The PIC14 port
17647 \layout Standard
17648
17649 The 14bit PIC
17650 \begin_inset LatexCommand \index{PIC14}
17651
17652 \end_inset 
17653
17654  port still requires a major effort from the development community.
17655  However it can work for simple code.
17656  It passes its (smaller set of) regression tests
17657 \begin_inset LatexCommand \index{Regression test (PIC14)}
17658
17659 \end_inset 
17660
17661  in the directory 
17662 \shape italic 
17663 sdcc/src/regression
17664 \shape default 
17665 .
17666 \layout Subsection
17667
17668 C code and 14bit PIC code page
17669 \begin_inset LatexCommand \index{code page (pic14)}
17670
17671 \end_inset 
17672
17673  and RAM banks
17674 \begin_inset LatexCommand \index{RAM bank (pic14)}
17675
17676 \end_inset 
17677
17678
17679 \layout Standard
17680
17681 The linker organizes allocation for the code page and RAM banks.
17682  It does not have intimate knowledge of the code flow.
17683  It will put all the code section of a single asm file into a single code
17684  page.
17685  In order to make use of multiple code pages, separate asm files must be
17686  used.
17687  The compiler treats all functions of a single C file as being in the same
17688  code page unless it is non static.
17689  The compiler treats all local variables of a single C file as being in
17690  the same RAM bank unless it is an extern.
17691 \newline 
17692
17693 \newline 
17694 To get the best follow these guide lines:
17695 \layout Enumerate
17696
17697 make local functions static, as non static functions require code page selection
17698  overhead.
17699 \layout Enumerate
17700
17701 Make local variables static as extern variables require RAM bank selection
17702  overhead.
17703 \layout Enumerate
17704
17705 For devices that have multiple code pages it is more efficient to use the
17706  same number of files as pages, i.e.
17707  for the 16F877 use 4 separate files and i.e.
17708  for the 16F874 use 2 separate files.
17709  This way the linker can put the code for each file into different code
17710  pages and the compiler can allocate reusable variables more efficiently
17711  and there's less page selection overhead.
17712  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17713  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17714 \layout Subsection
17715
17716 Creating a device include file 
17717 \layout Standard
17718
17719 For generating a device include file
17720 \begin_inset LatexCommand \index{PIC14!Header files}
17721
17722 \end_inset 
17723
17724  use the support perl script inc2h.pl kept in directory support/script.
17725 \layout Subsection
17726
17727 Interrupt code
17728 \layout Standard
17729
17730 For the interrupt function, use the keyword 'interrupt'
17731 \begin_inset LatexCommand \index{PIC14!interrupt}
17732
17733 \end_inset 
17734
17735  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17736  there to avoid a syntax error - it ought to be fixed).
17737  E.g.:
17738 \layout Verse
17739
17740
17741 \family typewriter 
17742 void Intr(void) interrupt 0
17743 \newline 
17744 {
17745 \newline 
17746 \SpecialChar ~
17747 \SpecialChar ~
17748 T0IF = 0; /* Clear timer interrupt */
17749 \newline 
17750 }
17751 \layout Subsection
17752
17753 Linking and assembling
17754 \layout Standard
17755
17756 For assembling you can use either GPUTILS'
17757 \begin_inset LatexCommand \index{gputils (pic tools)}
17758
17759 \end_inset 
17760
17761  gpasm.exe or MPLAB's mpasmwin.exe.
17762  GPUTILS is available from 
17763 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17764
17765 \end_inset 
17766
17767 .
17768  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17769  If you use MPLAB and an interrupt function then the linker script file
17770  vectors section will need to be enlarged to link with mplink.
17771 \newline 
17772
17773 \newline 
17774 Here is a 
17775 \family typewriter 
17776 Makefile
17777 \family default 
17778  using GPUTILS:
17779 \layout Verse
17780
17781
17782 \family typewriter 
17783 .c.o:
17784 \newline 
17785 \SpecialChar ~
17786 \SpecialChar ~
17787 \SpecialChar ~
17788 \SpecialChar ~
17789 \SpecialChar ~
17790 \SpecialChar ~
17791 \SpecialChar ~
17792 \SpecialChar ~
17793 sdcc -S -V -mpic14 -p16F877 $< 
17794 \newline 
17795 \SpecialChar ~
17796 \SpecialChar ~
17797 \SpecialChar ~
17798 \SpecialChar ~
17799 \SpecialChar ~
17800 \SpecialChar ~
17801 \SpecialChar ~
17802 \SpecialChar ~
17803 gpasm -c $*.asm
17804 \newline 
17805
17806 \newline 
17807 $(PRJ).hex: $(OBJS) 
17808 \newline 
17809 \SpecialChar ~
17810 \SpecialChar ~
17811 \SpecialChar ~
17812 \SpecialChar ~
17813 \SpecialChar ~
17814 \SpecialChar ~
17815 \SpecialChar ~
17816 \SpecialChar ~
17817 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17818 \layout Standard
17819
17820 Here is a 
17821 \family typewriter 
17822 Makefile
17823 \family default 
17824  using MPLAB:
17825 \layout Verse
17826
17827
17828 \family typewriter 
17829 .c.o: 
17830 \newline 
17831 \SpecialChar ~
17832 \SpecialChar ~
17833 \SpecialChar ~
17834 \SpecialChar ~
17835 \SpecialChar ~
17836 \SpecialChar ~
17837 \SpecialChar ~
17838 \SpecialChar ~
17839 sdcc -S -V -mpic14 -p16F877 $< 
17840 \newline 
17841 \SpecialChar ~
17842 \SpecialChar ~
17843 \SpecialChar ~
17844 \SpecialChar ~
17845 \SpecialChar ~
17846 \SpecialChar ~
17847 \SpecialChar ~
17848 \SpecialChar ~
17849 mpasmwin /q /o $*.asm
17850 \newline 
17851
17852 \newline 
17853 $(PRJ).hex: $(OBJS) 
17854 \newline 
17855 \SpecialChar ~
17856 \SpecialChar ~
17857 \SpecialChar ~
17858 \SpecialChar ~
17859 \SpecialChar ~
17860 \SpecialChar ~
17861 \SpecialChar ~
17862 \SpecialChar ~
17863 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17864 \layout Standard
17865
17866 Please note that indentations within a
17867 \family typewriter 
17868  Makefile
17869 \family default 
17870  have to be done with a tabulator character.
17871 \layout Subsection
17872
17873 Command-line options
17874 \layout Standard
17875
17876 Besides the switches common to all SDCC backends, the PIC14 port accepts
17877  the following options (for an updated list see sdcc -
17878 \begin_inset ERT
17879 status Collapsed
17880
17881 \layout Standard
17882
17883 \backslash 
17884 /
17885 \end_inset 
17886
17887 -help):
17888 \layout List
17889 \labelwidthstring 00.00.0000
17890
17891 -
17892 \begin_inset ERT
17893 status Collapsed
17894
17895 \layout Standard
17896
17897 \backslash 
17898 /
17899 \end_inset 
17900
17901 -debug-extra
17902 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
17903
17904 \end_inset 
17905
17906  emit debug info in assembly output
17907 \layout List
17908 \labelwidthstring 00.00.0000
17909
17910 -
17911 \begin_inset ERT
17912 status Collapsed
17913
17914 \layout Standard
17915
17916 \backslash 
17917 /
17918 \end_inset 
17919
17920 -no-pcode-opt
17921 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
17922
17923 \end_inset 
17924
17925  disable (slightly faulty) optimization on pCode
17926 \layout Subsection
17927
17928 The library
17929 \layout Subsubsection
17930
17931 error: missing definition for symbol 
17932 \begin_inset Quotes sld
17933 \end_inset 
17934
17935 __gptrget1
17936 \begin_inset Quotes srd
17937 \end_inset 
17938
17939
17940 \layout Standard
17941
17942 The PIC14 port uses library routines to provide more complex operations
17943  like multiplication, division/modulus and (generic) pointer dereferencing.
17944  In order to add these routines to your project, you must link with PIC14's
17945  
17946 \family typewriter 
17947 libsdcc.lib
17948 \family default 
17949 .
17950  For single source file projects this is done automatically, more complex
17951  projects must add 
17952 \family typewriter 
17953 libsdcc.lib
17954 \family default 
17955  to the linker's arguments.
17956  Make sure you also add an include path for the library (using the -I switch
17957  to the linker)!
17958 \layout Subsubsection
17959
17960 Processor mismatch in file 
17961 \begin_inset Quotes sld
17962 \end_inset 
17963
17964 XXX
17965 \begin_inset Quotes srd
17966 \end_inset 
17967
17968 .
17969 \layout Standard
17970
17971 This warning can usually be ignored due to the very good compatibility amongst
17972  14 bit PIC
17973 \begin_inset LatexCommand \index{PIC14}
17974
17975 \end_inset 
17976
17977  devices.
17978 \layout Standard
17979
17980 You might also consider recompiling the library for your specific device
17981  by changing the ARCH=p16f877 (default target) entry in 
17982 \family typewriter 
17983 device/lib/pic/Makefile.in
17984 \family default 
17985  and 
17986 \family typewriter 
17987 device/lib/pic/Makefile
17988 \family default 
17989  to reflect your device.
17990  This might even improve performance for smaller devices as unneccesary
17991  BANKSELs migth be removed.
17992 \layout Subsection
17993
17994 Known bugs
17995 \layout Subsubsection
17996
17997 initialized data
17998 \layout Standard
17999
18000 Currently, data can only be initialized if it resides in the source file
18001  together with 
18002 \emph on 
18003 main()
18004 \emph default 
18005 .
18006  Data in other source files will silently 
18007 \series bold 
18008 not
18009 \series default 
18010  be initialized.
18011 \family typewriter 
18012 \size footnotesize 
18013
18014 \begin_inset Marginal
18015 collapsed true
18016
18017 \layout Standard
18018
18019
18020 \series bold 
18021 \SpecialChar ~
18022 !
18023 \end_inset 
18024
18025
18026 \layout Section
18027 \pagebreak_top 
18028 The PIC16
18029 \begin_inset LatexCommand \index{PIC16}
18030
18031 \end_inset 
18032
18033  port
18034 \layout Standard
18035
18036 The PIC16
18037 \begin_inset LatexCommand \index{PIC16}
18038
18039 \end_inset 
18040
18041  port is the portion of SDCC that is responsible to produce code for the
18042  Microchip
18043 \begin_inset LatexCommand \index{Microchip}
18044
18045 \end_inset 
18046
18047 (TM) microcontrollers with 16 bit core.
18048  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18049  Currently supported devices are:
18050 \layout Standard
18051 \align center 
18052
18053 \begin_inset  Tabular
18054 <lyxtabular version="3" rows="4" columns="6">
18055 <features>
18056 <column alignment="center" valignment="top" leftline="true" width="0">
18057 <column alignment="center" valignment="top" leftline="true" width="0">
18058 <column alignment="center" valignment="top" leftline="true" width="0">
18059 <column alignment="center" valignment="top" leftline="true" width="0">
18060 <column alignment="center" valignment="top" leftline="true" width="0">
18061 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18062 <row topline="true">
18063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18064 \begin_inset Text
18065
18066 \layout Standard
18067
18068 18F242
18069 \end_inset 
18070 </cell>
18071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18072 \begin_inset Text
18073
18074 \layout Standard
18075
18076 18F248
18077 \end_inset 
18078 </cell>
18079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18080 \begin_inset Text
18081
18082 \layout Standard
18083
18084 18F252
18085 \end_inset 
18086 </cell>
18087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18088 \begin_inset Text
18089
18090 \layout Standard
18091
18092 18F258
18093 \end_inset 
18094 </cell>
18095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18096 \begin_inset Text
18097
18098 \layout Standard
18099
18100 18F442
18101 \end_inset 
18102 </cell>
18103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18104 \begin_inset Text
18105
18106 \layout Standard
18107
18108 18F448
18109 \end_inset 
18110 </cell>
18111 </row>
18112 <row topline="true">
18113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18114 \begin_inset Text
18115
18116 \layout Standard
18117
18118 18F452
18119 \end_inset 
18120 </cell>
18121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18122 \begin_inset Text
18123
18124 \layout Standard
18125
18126 18F458
18127 \end_inset 
18128 </cell>
18129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18130 \begin_inset Text
18131
18132 \layout Standard
18133
18134 18F1220
18135 \end_inset 
18136 </cell>
18137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18138 \begin_inset Text
18139
18140 \layout Standard
18141
18142 18F2220
18143 \end_inset 
18144 </cell>
18145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18146 \begin_inset Text
18147
18148 \layout Standard
18149
18150 18F2550
18151 \end_inset 
18152 </cell>
18153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18154 \begin_inset Text
18155
18156 \layout Standard
18157
18158 18F4331
18159 \end_inset 
18160 </cell>
18161 </row>
18162 <row topline="true">
18163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18164 \begin_inset Text
18165
18166 \layout Standard
18167
18168 18F4455
18169 \end_inset 
18170 </cell>
18171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18172 \begin_inset Text
18173
18174 \layout Standard
18175
18176 18F6520
18177 \end_inset 
18178 </cell>
18179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18180 \begin_inset Text
18181
18182 \layout Standard
18183
18184 18F6620
18185 \end_inset 
18186 </cell>
18187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18188 \begin_inset Text
18189
18190 \layout Standard
18191
18192 18F6680
18193 \end_inset 
18194 </cell>
18195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18196 \begin_inset Text
18197
18198 \layout Standard
18199
18200 18F6720
18201 \end_inset 
18202 </cell>
18203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18204 \begin_inset Text
18205
18206 \layout Standard
18207
18208 18F8520
18209 \end_inset 
18210 </cell>
18211 </row>
18212 <row topline="true" bottomline="true">
18213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18214 \begin_inset Text
18215
18216 \layout Standard
18217
18218 18F8620
18219 \end_inset 
18220 </cell>
18221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18222 \begin_inset Text
18223
18224 \layout Standard
18225
18226 18F8680
18227 \end_inset 
18228 </cell>
18229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18230 \begin_inset Text
18231
18232 \layout Standard
18233
18234 18F8720
18235 \end_inset 
18236 </cell>
18237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18238 \begin_inset Text
18239
18240 \layout Standard
18241
18242 \end_inset 
18243 </cell>
18244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18245 \begin_inset Text
18246
18247 \layout Standard
18248
18249 \end_inset 
18250 </cell>
18251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18252 \begin_inset Text
18253
18254 \layout Standard
18255
18256 \end_inset 
18257 </cell>
18258 </row>
18259 </lyxtabular>
18260
18261 \end_inset 
18262
18263
18264 \layout Subsection
18265
18266 Global Options
18267 \layout Standard
18268
18269 PIC16 port supports the standard command line arguments as supposed, with
18270  the exception of certain cases that will be mentioned in the following
18271  list:
18272 \layout List
18273 \labelwidthstring 00.00.0000
18274
18275 -
18276 \begin_inset ERT
18277 status Collapsed
18278
18279 \layout Standard
18280
18281 \backslash 
18282 /
18283 \end_inset 
18284
18285 -callee-saves
18286 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18287
18288 \end_inset 
18289
18290  See -
18291 \begin_inset ERT
18292 status Collapsed
18293
18294 \layout Standard
18295
18296 \backslash 
18297 /
18298 \end_inset 
18299
18300 -all-callee-saves
18301 \layout List
18302 \labelwidthstring 00.00.0000
18303
18304 -
18305 \begin_inset ERT
18306 status Collapsed
18307
18308 \layout Standard
18309
18310 \backslash 
18311 /
18312 \end_inset 
18313
18314 -all-callee-saves
18315 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18316
18317 \end_inset 
18318
18319  All function arguments are passed on stack by default.
18320  
18321 \emph on 
18322 There is no need to specify this in the command line.
18323 \layout List
18324 \labelwidthstring 00.00.0000
18325
18326 -
18327 \begin_inset ERT
18328 status Collapsed
18329
18330 \layout Standard
18331
18332 \backslash 
18333 /
18334 \end_inset 
18335
18336 -fommit-frame-pointer
18337 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18338
18339 \end_inset 
18340
18341  Frame pointer will be omitted when the function uses no local variables.
18342 \layout Subsection
18343
18344 Port Specific Options
18345 \begin_inset LatexCommand \index{Options PIC16}
18346
18347 \end_inset 
18348
18349
18350 \layout Standard
18351
18352 The port specific options appear after the global options in the sdcc --help
18353  output.
18354 \layout Subsubsection
18355
18356 General Options
18357 \layout Standard
18358
18359 General options enable certain port features and optimizations.
18360 \layout List
18361 \labelwidthstring 00.00.0000
18362
18363 -
18364 \begin_inset ERT
18365 status Collapsed
18366
18367 \layout Standard
18368
18369 \backslash 
18370 /
18371 \end_inset 
18372
18373 -stack-model=[model] Used in conjuction with the command above.
18374  Defines the stack model to be used, valid stack models are : 
18375 \begin_deeper 
18376 \layout List
18377 \labelwidthstring 00.00.0000
18378
18379
18380 \emph on 
18381 small
18382 \emph default 
18383  Selects small stack model.
18384  8 bit stack and frame pointers.
18385  Supports 256 bytes stack size.
18386 \layout List
18387 \labelwidthstring 00.00.0000
18388
18389
18390 \emph on 
18391 large
18392 \emph default 
18393  Selects large stack model.
18394  16 bit stack and frame pointers.
18395  Supports 65536 bytes stack size.
18396 \end_deeper 
18397 \layout List
18398 \labelwidthstring 00.00.0000
18399
18400 -
18401 \begin_inset ERT
18402 status Collapsed
18403
18404 \layout Standard
18405
18406 \backslash 
18407 /
18408 \end_inset 
18409
18410 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18411  unitialized data variables with [kword].
18412  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18413 \layout List
18414 \labelwidthstring 00.00.0000
18415
18416 -
18417 \begin_inset ERT
18418 status Collapsed
18419
18420 \layout Standard
18421
18422 \backslash 
18423 /
18424 \end_inset 
18425
18426 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18427  Useful for bootloaders.
18428 \layout List
18429 \labelwidthstring 00.00.0000
18430
18431 -
18432 \begin_inset ERT
18433 status Collapsed
18434
18435 \layout Standard
18436
18437 \backslash 
18438 /
18439 \end_inset 
18440
18441 -asm= sets the full path and name of an external assembler to call.
18442 \layout List
18443 \labelwidthstring 00.00.0000
18444
18445 -
18446 \begin_inset ERT
18447 status Collapsed
18448
18449 \layout Standard
18450
18451 \backslash 
18452 /
18453 \end_inset 
18454
18455 -link= sets the full path and name of an external linker to call.
18456 \layout List
18457 \labelwidthstring 00.00.0000
18458
18459 -
18460 \begin_inset ERT
18461 status Collapsed
18462
18463 \layout Standard
18464
18465 \backslash 
18466 /
18467 \end_inset 
18468
18469 -mplab-comp MPLAB
18470 \begin_inset LatexCommand \index{PIC16!MPLAB}
18471
18472 \end_inset 
18473
18474  compatibility option.
18475  Currently only suppresses special gpasm directives.
18476 \layout Subsubsection
18477
18478 Optimization Options
18479 \layout List
18480 \labelwidthstring 00.00.0000
18481
18482 -
18483 \begin_inset ERT
18484 status Collapsed
18485
18486 \layout Standard
18487
18488 \backslash 
18489 /
18490 \end_inset 
18491
18492 -optimize-goto Try to use (conditional) BRA instead of GOTO
18493 \layout List
18494 \labelwidthstring 00.00.0000
18495
18496 -
18497 \begin_inset ERT
18498 status Collapsed
18499
18500 \layout Standard
18501
18502 \backslash 
18503 /
18504 \end_inset 
18505
18506 -optimize-cmp Try to optimize some compares.
18507 \layout List
18508 \labelwidthstring 00.00.0000
18509
18510 -
18511 \begin_inset ERT
18512 status Collapsed
18513
18514 \layout Standard
18515
18516 \backslash 
18517 /
18518 \end_inset 
18519
18520 -optimize-df Analyze the dataflow of the generated code and improve it.
18521 \layout List
18522 \labelwidthstring 00.00.0000
18523
18524 -
18525 \begin_inset ERT
18526 status Collapsed
18527
18528 \layout Standard
18529
18530 \backslash 
18531 /
18532 \end_inset 
18533
18534 -obanksel=nn Set optimization level for inserting BANKSELs.
18535 \newline 
18536
18537 \begin_deeper 
18538 \layout List
18539 \labelwidthstring 00.00.0000
18540
18541 0 no optimization
18542 \layout List
18543 \labelwidthstring 00.00.0000
18544
18545 1 checks previous used register and if it is the same then does not emit
18546  BANKSEL, accounts only for labels.
18547 \layout List
18548 \labelwidthstring 00.00.0000
18549
18550 2 tries to check the location of (even different) symbols and removes BANKSELs
18551  if they are in the same bank.
18552  
18553 \newline 
18554
18555 \emph on 
18556 Important: There might be problems if the linker script has data sections
18557  across bank borders!
18558 \end_deeper 
18559 \layout Subsubsection
18560
18561 Linking Options
18562 \layout List
18563 \labelwidthstring 00.00.0000
18564
18565 -
18566 \begin_inset ERT
18567 status Collapsed
18568
18569 \layout Standard
18570
18571 \backslash 
18572 /
18573 \end_inset 
18574
18575 -nodefaultlibs do not link default libraries when linking
18576 \layout List
18577 \labelwidthstring 00.00.0000
18578
18579 -
18580 \begin_inset ERT
18581 status Collapsed
18582
18583 \layout Standard
18584
18585 \backslash 
18586 /
18587 \end_inset 
18588
18589 -no-crt Don't link the default run-time modules
18590 \layout List
18591 \labelwidthstring 00.00.0000
18592
18593 -
18594 \begin_inset ERT
18595 status Collapsed
18596
18597 \layout Standard
18598
18599 \backslash 
18600 /
18601 \end_inset 
18602
18603 -use-crt= Use a custom run-time module instead of the defaults.
18604 \layout Subsubsection
18605
18606 Debugging Options
18607 \layout Standard
18608
18609 Debugging options enable extra debugging information in the output files.
18610 \layout List
18611 \labelwidthstring 00.00.0000
18612
18613 -
18614 \begin_inset ERT
18615 status Collapsed
18616
18617 \layout Standard
18618
18619 \backslash 
18620 /
18621 \end_inset 
18622
18623 -debug-xtra Similar to -
18624 \begin_inset ERT
18625 status Collapsed
18626
18627 \layout Standard
18628
18629 \backslash 
18630 /
18631 \end_inset 
18632
18633 -debug
18634 \begin_inset LatexCommand \index{-\/-debug}
18635
18636 \end_inset 
18637
18638 , but dumps more information.
18639 \layout List
18640 \labelwidthstring 00.00.0000
18641
18642 -
18643 \begin_inset ERT
18644 status Collapsed
18645
18646 \layout Standard
18647
18648 \backslash 
18649 /
18650 \end_inset 
18651
18652 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18653  information.
18654  <source> is the name of the file compiled.
18655 \layout List
18656 \labelwidthstring 00.00.0000
18657
18658 -
18659 \begin_inset ERT
18660 status Collapsed
18661
18662 \layout Standard
18663
18664 \backslash 
18665 /
18666 \end_inset 
18667
18668 -pcode-verbose Enable pcode debugging information in translation.
18669 \layout List
18670 \labelwidthstring 00.00.0000
18671
18672 -
18673 \begin_inset ERT
18674 status Collapsed
18675
18676 \layout Standard
18677
18678 \backslash 
18679 /
18680 \end_inset 
18681
18682 -denable-peeps Force the usage of peepholes.
18683  Use with care.
18684 \layout List
18685 \labelwidthstring 00.00.0000
18686
18687 -
18688 \begin_inset ERT
18689 status Collapsed
18690
18691 \layout Standard
18692
18693 \backslash 
18694 /
18695 \end_inset 
18696
18697 -gstack Trace push/pops for stack pointer overflow
18698 \layout List
18699 \labelwidthstring 00.00.0000
18700
18701 -
18702 \begin_inset ERT
18703 status Collapsed
18704
18705 \layout Standard
18706
18707 \backslash 
18708 /
18709 \end_inset 
18710
18711 -call-tree dump call tree in .calltree file
18712 \layout Subsection
18713
18714 Enviromental Variables
18715 \layout Standard
18716
18717 There is a number of enviromental variables that can be used when running
18718  SDCC to enable certain optimizations or force a specific program behaviour.
18719  these variables are primarily for debugging purposes so they can be enabled/dis
18720 abled at will.
18721 \layout Standard
18722
18723 Currently there is only two such variables available:
18724 \layout List
18725 \labelwidthstring 00.00.0000
18726
18727 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18728  bitfields is optimized by directly loading FSR0 with the address of the
18729  bitfield structure.
18730  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18731  then load FSR0.
18732  This step saves data ram and code space for functions that perform heavy
18733  use of bitfields.
18734  (ie.
18735  80 bytes of code space are saved when compiling malloc.c with this option).
18736  
18737 \layout List
18738 \labelwidthstring 00.00.0000
18739
18740 NO_REG_OPT do not perform pCode registers optimization.
18741  This should be used for debugging purposes.
18742  In some where bugs in the pcode optimizer are found, users can benefit
18743  from temporarily disabling the optimizer until the bug is fixed.
18744 \layout Subsection
18745
18746 Preprocessor Macros
18747 \layout Standard
18748
18749 PIC16
18750 \begin_inset LatexCommand \index{PIC16}
18751
18752 \end_inset 
18753
18754  port defines the following preprocessor macros while translating a source.
18755 \layout Standard
18756 \align center 
18757
18758 \begin_inset  Tabular
18759 <lyxtabular version="3" rows="6" columns="2">
18760 <features>
18761 <column alignment="center" valignment="top" leftline="true" width="0">
18762 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18763 <row topline="true" bottomline="true">
18764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18765 \begin_inset Text
18766
18767 \layout Standard
18768
18769 Macro
18770 \end_inset 
18771 </cell>
18772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18773 \begin_inset Text
18774
18775 \layout Standard
18776
18777 Description
18778 \end_inset 
18779 </cell>
18780 </row>
18781 <row topline="true">
18782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18783 \begin_inset Text
18784
18785 \layout Standard
18786
18787 SDCC_pic16
18788 \end_inset 
18789 </cell>
18790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18791 \begin_inset Text
18792
18793 \layout Standard
18794
18795 Port identification
18796 \end_inset 
18797 </cell>
18798 </row>
18799 <row topline="true">
18800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18801 \begin_inset Text
18802
18803 \layout Standard
18804
18805 _
18806 \begin_inset ERT
18807 status Collapsed
18808
18809 \layout Standard
18810
18811 \backslash 
18812 /
18813 \end_inset 
18814
18815 _pic16
18816 \end_inset 
18817 </cell>
18818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18819 \begin_inset Text
18820
18821 \layout Standard
18822
18823 Port identification (same as above)
18824 \end_inset 
18825 </cell>
18826 </row>
18827 <row topline="true">
18828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18829 \begin_inset Text
18830
18831 \layout Standard
18832
18833 pic18fxxxx
18834 \end_inset 
18835 </cell>
18836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18837 \begin_inset Text
18838
18839 \layout Standard
18840
18841 MCU Identification.
18842  
18843 \emph on 
18844 xxxx
18845 \emph default 
18846  is the microcontrol identification number, i.e.
18847  452, 6620, etc
18848 \end_inset 
18849 </cell>
18850 </row>
18851 <row topline="true">
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18853 \begin_inset Text
18854
18855 \layout Standard
18856
18857 _
18858 \begin_inset ERT
18859 status Collapsed
18860
18861 \layout Standard
18862
18863 \backslash 
18864 /
18865 \end_inset 
18866
18867 _18Fxxxx
18868 \end_inset 
18869 </cell>
18870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18871 \begin_inset Text
18872
18873 \layout Standard
18874
18875 MCU Identification (same as above)
18876 \end_inset 
18877 </cell>
18878 </row>
18879 <row topline="true" bottomline="true">
18880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18881 \begin_inset Text
18882
18883 \layout Standard
18884
18885 STACK_MODEL_nnn
18886 \end_inset 
18887 </cell>
18888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18889 \begin_inset Text
18890
18891 \layout Standard
18892
18893 nnn = SMALL or LARGE respectively according to the stack model used
18894 \end_inset 
18895 </cell>
18896 </row>
18897 </lyxtabular>
18898
18899 \end_inset 
18900
18901
18902 \layout Standard
18903
18904 In addition the following macros are defined when calling assembler:
18905 \layout Standard
18906 \align center 
18907
18908 \begin_inset  Tabular
18909 <lyxtabular version="3" rows="4" columns="2">
18910 <features>
18911 <column alignment="center" valignment="top" leftline="true" width="0">
18912 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18913 <row topline="true" bottomline="true">
18914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18915 \begin_inset Text
18916
18917 \layout Standard
18918
18919 Macro
18920 \end_inset 
18921 </cell>
18922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18923 \begin_inset Text
18924
18925 \layout Standard
18926
18927 Description
18928 \end_inset 
18929 </cell>
18930 </row>
18931 <row topline="true">
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18933 \begin_inset Text
18934
18935 \layout Standard
18936
18937 __18Fxxxx
18938 \end_inset 
18939 </cell>
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18941 \begin_inset Text
18942
18943 \layout Standard
18944
18945 MCU Identification.
18946  
18947 \emph on 
18948 xxxx
18949 \emph default 
18950  is the microcontrol identification number, i.e.
18951  452, 6620, etc
18952 \end_inset 
18953 </cell>
18954 </row>
18955 <row topline="true">
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18957 \begin_inset Text
18958
18959 \layout Standard
18960
18961 SDCC_MODEL_nnn
18962 \end_inset 
18963 </cell>
18964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18965 \begin_inset Text
18966
18967 \layout Standard
18968
18969 nnn = SMALL or LARGE respectively according to the memory model used for
18970  SDCC
18971 \end_inset 
18972 </cell>
18973 </row>
18974 <row topline="true" bottomline="true">
18975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18976 \begin_inset Text
18977
18978 \layout Standard
18979
18980 STACK_MODEL_nnn
18981 \end_inset 
18982 </cell>
18983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18984 \begin_inset Text
18985
18986 \layout Standard
18987
18988 nnn = SMALL or LARGE respectively according to the stack model used
18989 \end_inset 
18990 </cell>
18991 </row>
18992 </lyxtabular>
18993
18994 \end_inset 
18995
18996
18997 \layout Subsection
18998
18999 Directories
19000 \layout Standard
19001
19002 PIC16
19003 \begin_inset LatexCommand \index{PIC16}
19004
19005 \end_inset 
19006
19007  port uses the following directories for searching header files and libraries.
19008 \layout Standard
19009 \align center 
19010
19011 \begin_inset  Tabular
19012 <lyxtabular version="3" rows="3" columns="4">
19013 <features>
19014 <column alignment="center" valignment="top" leftline="true" width="0">
19015 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19016 <column alignment="center" valignment="top" width="0">
19017 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19018 <row topline="true" bottomline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19020 \begin_inset Text
19021
19022 \layout Standard
19023
19024 Directory
19025 \end_inset 
19026 </cell>
19027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19028 \begin_inset Text
19029
19030 \layout Standard
19031
19032 Description
19033 \end_inset 
19034 </cell>
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19036 \begin_inset Text
19037
19038 \layout Standard
19039
19040 Target
19041 \end_inset 
19042 </cell>
19043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19044 \begin_inset Text
19045
19046 \layout Standard
19047
19048 Command prefix
19049 \end_inset 
19050 </cell>
19051 </row>
19052 <row topline="true">
19053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19054 \begin_inset Text
19055
19056 \layout Standard
19057
19058 PREFIX/sdcc/include/pic16
19059 \end_inset 
19060 </cell>
19061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19062 \begin_inset Text
19063
19064 \layout Standard
19065
19066 PIC16 specific headers
19067 \end_inset 
19068 </cell>
19069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19070 \begin_inset Text
19071
19072 \layout Standard
19073
19074 Compiler
19075 \end_inset 
19076 </cell>
19077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19078 \begin_inset Text
19079
19080 \layout Standard
19081
19082 -I
19083 \end_inset 
19084 </cell>
19085 </row>
19086 <row topline="true" bottomline="true">
19087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19088 \begin_inset Text
19089
19090 \layout Standard
19091
19092 PREFIX/sdcc/lib/pic16
19093 \end_inset 
19094 </cell>
19095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19096 \begin_inset Text
19097
19098 \layout Standard
19099
19100 PIC16 specific libraries
19101 \end_inset 
19102 </cell>
19103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19104 \begin_inset Text
19105
19106 \layout Standard
19107
19108 Linker
19109 \end_inset 
19110 </cell>
19111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19112 \begin_inset Text
19113
19114 \layout Standard
19115
19116 -L
19117 \end_inset 
19118 </cell>
19119 </row>
19120 </lyxtabular>
19121
19122 \end_inset 
19123
19124
19125 \layout Subsection
19126
19127 Pragmas
19128 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19129
19130 \end_inset 
19131
19132
19133 \layout Standard
19134
19135 PIC16
19136 \begin_inset LatexCommand \index{PIC16}
19137
19138 \end_inset 
19139
19140  port currently supports the following pragmas:
19141 \layout List
19142 \labelwidthstring 00.00.0000
19143
19144 stack
19145 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19146
19147 \end_inset 
19148
19149  pragma stack
19150 \begin_inset LatexCommand \index{PIC16!stack}
19151
19152 \end_inset 
19153
19154  forces the code generator to initialize the stack & frame pointers at a
19155  specific address.
19156  This is an adhoc solution for cases where no STACK directive is available
19157  in the linker script or gplink is not instructed to create a stack section.
19158 \newline 
19159 The stack pragma should be used only once in a project.
19160  Multiple pragmas may result in indeterminate behaviour of the program.
19161 \begin_inset Foot
19162 collapsed false
19163
19164 \layout Standard
19165
19166 The old format (ie.
19167  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19168  cross page boundaries (or even exceed the available data RAM) and crash
19169  the program.
19170  Make sure that stack does not cross page boundaries when using the SMALL
19171  stack model.
19172 \end_inset 
19173
19174
19175 \newline 
19176 The format is as follows:
19177 \layout LyX-Code
19178
19179 #pragma stack bottom_address [stack_size]
19180 \layout Standard
19181
19182
19183 \emph on 
19184 bottom_address
19185 \emph default 
19186  is the lower bound of the stack section.
19187  The stack pointer initially will point at address (bottom_address+stack_size-1).
19188 \layout LyX-Code
19189
19190 Example:
19191 \layout LyX-Code
19192
19193 \layout LyX-Code
19194
19195 /* initializes stack of 100 bytes at RAM address 0x200 */
19196 \layout LyX-Code
19197
19198 #pragma stack 0x200 100
19199 \layout Standard
19200
19201 If the stack_size field is omitted then a stack is created with the default
19202  size of 64.
19203  This size might be enough for most programs, but its not enough for operations
19204  with deep function nesting or excessive stack usage.
19205 \layout List
19206 \labelwidthstring 00.00.0000
19207
19208 code
19209 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19210
19211 \end_inset 
19212
19213  place a function symbol at static FLASH address
19214 \layout LyX-Code
19215
19216 Example:
19217 \layout LyX-Code
19218
19219 \layout LyX-Code
19220
19221 /* place function test_func at 0x4000 */
19222 \layout LyX-Code
19223
19224 #pragma code test_func 0x4000
19225 \layout LyX-Code
19226
19227 \layout List
19228 \labelwidthstring 00.00.0000
19229
19230 library instructs the linker to use a library module.
19231 \newline 
19232 Usage:
19233 \layout LyX-Code
19234
19235 #pragma library module_name
19236 \layout Standard
19237
19238
19239 \emph on 
19240 module_name
19241 \emph default 
19242  can be any library or object file (including its path).
19243  Note that there are four reserved keywords which have special meaning.
19244  These are:
19245 \layout Standard
19246 \align center 
19247
19248 \begin_inset  Tabular
19249 <lyxtabular version="3" rows="6" columns="3">
19250 <features>
19251 <column alignment="center" valignment="top" leftline="true" width="0">
19252 <column alignment="block" valignment="top" leftline="true" width="20page%">
19253 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19254 <row topline="true" bottomline="true">
19255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19256 \begin_inset Text
19257
19258 \layout Standard
19259
19260 Keyword
19261 \end_inset 
19262 </cell>
19263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19264 \begin_inset Text
19265
19266 \layout Standard
19267
19268 Description
19269 \end_inset 
19270 </cell>
19271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19272 \begin_inset Text
19273
19274 \layout Standard
19275
19276 Module to link
19277 \end_inset 
19278 </cell>
19279 </row>
19280 <row topline="true">
19281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19282 \begin_inset Text
19283
19284 \layout Standard
19285
19286
19287 \series bold 
19288 ignore
19289 \end_inset 
19290 </cell>
19291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19292 \begin_inset Text
19293
19294 \layout Standard
19295
19296 ignore all library pragmas
19297 \end_inset 
19298 </cell>
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19300 \begin_inset Text
19301
19302 \layout Standard
19303
19304
19305 \emph on 
19306 (none)
19307 \end_inset 
19308 </cell>
19309 </row>
19310 <row topline="true">
19311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19312 \begin_inset Text
19313
19314 \layout Standard
19315
19316
19317 \series bold 
19318 c
19319 \end_inset 
19320 </cell>
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19322 \begin_inset Text
19323
19324 \layout Standard
19325
19326 link the C library
19327 \end_inset 
19328 </cell>
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19330 \begin_inset Text
19331
19332 \layout Standard
19333
19334
19335 \emph on 
19336 libc18f
19337 \emph default 
19338 .lib
19339 \end_inset 
19340 </cell>
19341 </row>
19342 <row topline="true">
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19344 \begin_inset Text
19345
19346 \layout Standard
19347
19348
19349 \series bold 
19350 math
19351 \end_inset 
19352 </cell>
19353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19354 \begin_inset Text
19355
19356 \layout Standard
19357
19358 link the Math libarary
19359 \end_inset 
19360 </cell>
19361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19362 \begin_inset Text
19363
19364 \layout Standard
19365
19366
19367 \emph on 
19368 libm18f
19369 \emph default 
19370 .lib
19371 \end_inset 
19372 </cell>
19373 </row>
19374 <row topline="true">
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19376 \begin_inset Text
19377
19378 \layout Standard
19379
19380
19381 \series bold 
19382 io
19383 \end_inset 
19384 </cell>
19385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19386 \begin_inset Text
19387
19388 \layout Standard
19389
19390 link the I/O library
19391 \end_inset 
19392 </cell>
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19394 \begin_inset Text
19395
19396 \layout Standard
19397
19398
19399 \emph on 
19400 libio18f*
19401 \emph default 
19402 .lib
19403 \end_inset 
19404 </cell>
19405 </row>
19406 <row topline="true" bottomline="true">
19407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19408 \begin_inset Text
19409
19410 \layout Standard
19411
19412
19413 \series bold 
19414 debug
19415 \end_inset 
19416 </cell>
19417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19418 \begin_inset Text
19419
19420 \layout Standard
19421
19422 link the debug library
19423 \end_inset 
19424 </cell>
19425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19426 \begin_inset Text
19427
19428 \layout Standard
19429
19430
19431 \emph on 
19432 libdebug
19433 \emph default 
19434 .lib
19435 \end_inset 
19436 </cell>
19437 </row>
19438 </lyxtabular>
19439
19440 \end_inset 
19441
19442
19443 \newline 
19444 * is the device number, i.e.
19445  452 for PIC18F452 MCU.
19446 \layout Standard
19447
19448 This feature allows for linking with specific libraries withoug having to
19449  explicit name them in the command line.
19450  Note that the 
19451 \noun on 
19452 ignore
19453 \noun default 
19454  keyword will reject all modules specified by the library pragma.
19455 \layout List
19456 \labelwidthstring 00.00.0000
19457
19458 udata pragma udata instructs the compiler to emit code so that linker will
19459  place a variable at a specific memory bank
19460 \layout LyX-Code
19461
19462 Example:
19463 \layout LyX-Code
19464
19465 \layout LyX-Code
19466
19467 /* places variable foo at bank2 */
19468 \layout LyX-Code
19469
19470 #pragma udata bank2 foo
19471 \layout LyX-Code
19472
19473 char foo;
19474 \layout Standard
19475
19476 In order for this pragma to work extra SECTION directives should be added
19477  in the .lkr script.
19478  In the following example a sample .lkr file is shown:
19479 \layout LyX-Code
19480
19481 \layout LyX-Code
19482
19483 // Sample linker script for the PIC18F452 processor
19484 \layout LyX-Code
19485
19486 LIBPATH .
19487 \layout LyX-Code
19488
19489 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19490 \layout LyX-Code
19491
19492 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19493 \layout LyX-Code
19494
19495 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19496 \layout LyX-Code
19497
19498 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19499 \layout LyX-Code
19500
19501 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19502 \layout LyX-Code
19503
19504 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19505 \layout LyX-Code
19506
19507 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19508 \layout LyX-Code
19509
19510 \layout LyX-Code
19511
19512 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19513 \layout LyX-Code
19514
19515 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19516 \layout LyX-Code
19517
19518 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19519 \layout LyX-Code
19520
19521 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19522 \layout LyX-Code
19523
19524 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19525 \layout LyX-Code
19526
19527 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19528 \layout LyX-Code
19529
19530 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19531 \layout LyX-Code
19532
19533 \layout LyX-Code
19534
19535 SECTION    NAME=CONFIG     ROM=config
19536 \layout LyX-Code
19537
19538 \layout LyX-Code
19539
19540 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19541 \layout LyX-Code
19542
19543 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19544 \layout LyX-Code
19545
19546 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19547 \layout LyX-Code
19548
19549 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19550 \layout LyX-Code
19551
19552 SECTION    NAME=bank4      RAM=gpr4
19553 \layout LyX-Code
19554
19555 SECTION    NAME=bank5      RAM=gpr5
19556 \layout Standard
19557
19558 The linker will recognise the section name set in the pragma statement and
19559  will position the variable at the memory bank set with the RAM field at
19560  the SECTION line in the linker script file.
19561 \layout Subsection
19562
19563 Header Files
19564 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19565
19566 \end_inset 
19567
19568
19569 \layout Standard
19570
19571 There is one main header file
19572 \begin_inset LatexCommand \index{PIC16!Header files}
19573
19574 \end_inset 
19575
19576  that can be included to the source files using the pic16
19577 \begin_inset LatexCommand \index{PIC16}
19578
19579 \end_inset 
19580
19581  port.
19582  That file is the 
19583 \series bold 
19584 pic18fregs.h
19585 \series default 
19586 .
19587  This header file contains the definitions for the processor special registers,
19588  so it is necessary if the source accesses them.
19589  It can be included by adding the following line in the beginning of the
19590  file:
19591 \layout LyX-Code
19592
19593 #include <pic18fregs.h>
19594 \layout Standard
19595
19596 The specific microcontroller is selected within the pic18fregs.h automatically,
19597  so the same source can be used with a variety of devices.
19598 \layout Subsection
19599
19600 Libraries
19601 \layout Standard
19602
19603 The libraries
19604 \begin_inset LatexCommand \index{PIC16!Libraries}
19605
19606 \end_inset 
19607
19608  that PIC16
19609 \begin_inset LatexCommand \index{PIC16}
19610
19611 \end_inset 
19612
19613  port depends on are the microcontroller device libraries which contain
19614  the symbol definitions for the microcontroller special function registers.
19615  These libraries have the format pic18fxxxx.lib, where 
19616 \emph on 
19617 xxxx
19618 \emph default 
19619  is the microcontroller identification number.
19620  The specific library is selected automatically by the compiler at link
19621  stage according to the selected device.
19622 \layout Standard
19623
19624 Libraries are created with gplib which is part of the gputils package 
19625 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19626
19627 \end_inset 
19628
19629 .
19630 \layout Subsubsection*
19631
19632 Building the libraries
19633 \layout Standard
19634
19635 Before using SDCC/pic16 there are some libraries that need to be compiled.
19636  This process is not done automatically by SDCC since not all users use
19637  SDCC for pic16 projects.
19638  So each user should compile the libraries separately.
19639 \layout Standard
19640
19641 The steps to compile the pic16 libraries under Linux are:
19642 \layout LyX-Code
19643
19644 cd device/lib/pic16
19645 \layout LyX-Code
19646
19647 ./configure
19648 \layout LyX-Code
19649
19650 make
19651 \layout LyX-Code
19652
19653 cd ..
19654 \layout LyX-Code
19655
19656 make model-pic16
19657 \layout LyX-Code
19658
19659 su -c 'make install'     # install the libraries, you need the root password
19660 \layout Standard
19661
19662 If you need to install the headers too, do:
19663 \layout LyX-Code
19664
19665 cd device/include
19666 \layout LyX-Code
19667
19668 su -c 'make install'     # install the headers, you need the root password
19669 \layout Standard
19670
19671 There exist a special target to build the I/O libraries.
19672  This target is not automatically build because it will build the I/O library
19673  for 
19674 \emph on 
19675 every
19676 \emph default 
19677  supported device.
19678  This way building will take quite a lot of time.
19679  Users are advised to edit the 
19680 \series bold 
19681 device/lib/pic16/pics.build
19682 \series default 
19683  file and then execute:
19684 \layout LyX-Code
19685
19686 make lib-io
19687 \layout Subsection
19688
19689 Memory Models
19690 \layout Standard
19691
19692 The following memory models are supported by the PIC16 port:
19693 \layout Itemize
19694
19695 small model
19696 \layout Itemize
19697
19698 large model
19699 \layout Standard
19700
19701 Memory model affects the default size of pointers within the source.
19702  The sizes are shown in the next table:
19703 \layout Standard
19704 \align center 
19705
19706 \begin_inset  Tabular
19707 <lyxtabular version="3" rows="3" columns="3">
19708 <features>
19709 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19710 <column alignment="center" valignment="top" leftline="true" width="0">
19711 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19712 <row topline="true" bottomline="true">
19713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19714 \begin_inset Text
19715
19716 \layout Standard
19717
19718 Pointer sizes according to memory model
19719 \end_inset 
19720 </cell>
19721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19722 \begin_inset Text
19723
19724 \layout Standard
19725
19726 small model
19727 \end_inset 
19728 </cell>
19729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19730 \begin_inset Text
19731
19732 \layout Standard
19733
19734 large model
19735 \end_inset 
19736 </cell>
19737 </row>
19738 <row topline="true" bottomline="true">
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19740 \begin_inset Text
19741
19742 \layout Standard
19743
19744 code pointers
19745 \end_inset 
19746 </cell>
19747 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19748 \begin_inset Text
19749
19750 \layout Standard
19751
19752 16-bits
19753 \end_inset 
19754 </cell>
19755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19756 \begin_inset Text
19757
19758 \layout Standard
19759
19760 24-bits
19761 \end_inset 
19762 </cell>
19763 </row>
19764 <row topline="true" bottomline="true">
19765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19766 \begin_inset Text
19767
19768 \layout Standard
19769
19770 data pointers
19771 \end_inset 
19772 </cell>
19773 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19774 \begin_inset Text
19775
19776 \layout Standard
19777
19778 16-bits
19779 \end_inset 
19780 </cell>
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19782 \begin_inset Text
19783
19784 \layout Standard
19785
19786 16-bits
19787 \end_inset 
19788 </cell>
19789 </row>
19790 </lyxtabular>
19791
19792 \end_inset 
19793
19794
19795 \layout Standard
19796
19797 It is advisable that all sources within a project are compiled with the
19798  same memory model.
19799  If one wants to override the default memory model, this can be done by
19800  declaring a pointer as 
19801 \series bold 
19802 far
19803 \series default 
19804  or 
19805 \series bold 
19806 near
19807 \series default 
19808 .
19809  Far selects large memory model's pointers, while near selects small memory
19810  model's pointers.
19811 \layout Standard
19812
19813 The standard device libraries (see 
19814 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19815
19816 \end_inset 
19817
19818 ) contain no reference to pointers, so they can be used with both memory
19819  models.
19820 \layout Subsection
19821
19822 Stack
19823 \layout Standard
19824
19825 The stack
19826 \begin_inset LatexCommand \index{PIC16!stack}
19827
19828 \end_inset 
19829
19830  implementation for the PIC16 port uses two indirect registers, FSR1 and
19831  FSR2.
19832 \layout List
19833 \labelwidthstring 00.00.0000
19834
19835 FSR1 is assigned as stack pointer
19836 \layout List
19837 \labelwidthstring 00.00.0000
19838
19839 FSR2 is assigned as frame pointer
19840 \layout Standard
19841
19842 The following stack models are supported by the PIC16 port
19843 \layout Itemize
19844
19845
19846 \noun on 
19847 small
19848 \noun default 
19849  model
19850 \layout Itemize
19851
19852
19853 \noun on 
19854 large
19855 \noun default 
19856  model
19857 \layout Standard
19858
19859
19860 \noun on 
19861 Small
19862 \noun default 
19863  model means that only the FSRxL byte is used to access stack and frame,
19864  while 
19865 \emph on 
19866 \noun on 
19867 large
19868 \emph default 
19869 \noun default 
19870  uses both FSRxL and FSRxH registers.
19871  The following table shows the stack/frame pointers sizes according to stack
19872  model and the maximum space they can address:
19873 \layout Standard
19874 \align center 
19875
19876 \begin_inset  Tabular
19877 <lyxtabular version="3" rows="3" columns="3">
19878 <features>
19879 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19880 <column alignment="center" valignment="top" leftline="true" width="0">
19881 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19882 <row topline="true" bottomline="true">
19883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19884 \begin_inset Text
19885
19886 \layout Standard
19887
19888 Stack & Frame pointer sizes according to stack model
19889 \end_inset 
19890 </cell>
19891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19892 \begin_inset Text
19893
19894 \layout Standard
19895
19896 small
19897 \end_inset 
19898 </cell>
19899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19900 \begin_inset Text
19901
19902 \layout Standard
19903
19904 large
19905 \end_inset 
19906 </cell>
19907 </row>
19908 <row topline="true">
19909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19910 \begin_inset Text
19911
19912 \layout Standard
19913
19914 Stack pointer FSR1
19915 \end_inset 
19916 </cell>
19917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19918 \begin_inset Text
19919
19920 \layout Standard
19921
19922 8-bits
19923 \end_inset 
19924 </cell>
19925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19926 \begin_inset Text
19927
19928 \layout Standard
19929
19930 16-bits
19931 \end_inset 
19932 </cell>
19933 </row>
19934 <row topline="true" bottomline="true">
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19936 \begin_inset Text
19937
19938 \layout Standard
19939
19940 Frame pointer FSR2
19941 \end_inset 
19942 </cell>
19943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19944 \begin_inset Text
19945
19946 \layout Standard
19947
19948 8-bits
19949 \end_inset 
19950 </cell>
19951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19952 \begin_inset Text
19953
19954 \layout Standard
19955
19956 16-bits
19957 \end_inset 
19958 </cell>
19959 </row>
19960 </lyxtabular>
19961
19962 \end_inset 
19963
19964
19965 \layout Standard
19966
19967
19968 \noun on 
19969 Large 
19970 \noun default 
19971 stack model is currently not working properly throughout the code generator.
19972  So its use is not advised.
19973  Also there are some other points that need special care:
19974 \newline 
19975
19976 \layout Enumerate
19977
19978 Do not create stack sections with size more than one physical bank (that
19979  is 256 bytes)
19980 \layout Enumerate
19981
19982 Stack sections should no cross physical bank limits (i.e.
19983  #pragma stack 0x50 0x100)
19984 \layout Standard
19985
19986 These limitations are caused by the fact that only FSRxL is modified when
19987  using SMALL stack model, so no more than 256 bytes of stack can be used.
19988  This problem will disappear after LARGE model is fully implemented.
19989 \layout Subsection
19990
19991 Functions
19992 \layout Standard
19993
19994 In addition to the standard SDCC function keywords, PIC16
19995 \begin_inset LatexCommand \index{PIC16}
19996
19997 \end_inset 
19998
19999  port makes available two more:
20000 \layout List
20001 \labelwidthstring 00.00.0000
20002
20003 wparam
20004 \begin_inset LatexCommand \index{PIC16!wparam}
20005
20006 \end_inset 
20007
20008  Use the WREG to pass one byte of the first function argument.
20009  This improves speed but you may not use this for functions with arguments
20010  that are called via function pointers, otherwise the first byte of the
20011  first parameter will get lost.
20012  Usage:
20013 \layout LyX-Code
20014
20015 void func_wparam(int a) wparam
20016 \layout LyX-Code
20017
20018 {
20019 \layout LyX-Code
20020
20021     /* WREG hold the lower part of a */
20022 \layout LyX-Code
20023
20024     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20025  */
20026 \layout LyX-Code
20027
20028 ...
20029 \layout LyX-Code
20030
20031 }
20032 \layout List
20033 \labelwidthstring 00.00.0000
20034
20035 shadowregs
20036 \begin_inset LatexCommand \index{PIC16!shadowregs}
20037
20038 \end_inset 
20039
20040  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20041  hardware shadow registers which hold the values of WREG, STATUS and BSR
20042  registers.
20043  This can be done by adding the keyword 
20044 \emph on 
20045 shadowregs
20046 \emph default 
20047  before the 
20048 \emph on 
20049 interrupt
20050 \emph default 
20051  keyword in the function's header.
20052 \layout LyX-Code
20053
20054 void isr_shadow(void) shadowregs interrupt 1
20055 \layout LyX-Code
20056
20057 {
20058 \layout LyX-Code
20059
20060 ...
20061 \layout LyX-Code
20062
20063 }
20064 \layout Standard
20065
20066
20067 \emph on 
20068 shadowregs
20069 \emph default 
20070  instructs the code generator not to store/restore WREG, STATUS, BSR when
20071  entering/exiting the ISR.
20072 \layout Subsection
20073
20074 Function return values
20075 \layout Standard
20076
20077 Return values from functions are placed to the appropriate registers following
20078  a modified Microchip policy optimized for SDCC.
20079  The following table shows these registers:
20080 \layout Standard
20081 \align center 
20082
20083 \begin_inset  Tabular
20084 <lyxtabular version="3" rows="6" columns="2">
20085 <features>
20086 <column alignment="center" valignment="top" leftline="true" width="0">
20087 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20088 <row topline="true" bottomline="true">
20089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20090 \begin_inset Text
20091
20092 \layout Standard
20093
20094 size
20095 \end_inset 
20096 </cell>
20097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20098 \begin_inset Text
20099
20100 \layout Standard
20101
20102 destination register
20103 \end_inset 
20104 </cell>
20105 </row>
20106 <row topline="true">
20107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20108 \begin_inset Text
20109
20110 \layout Standard
20111
20112 8 bits
20113 \end_inset 
20114 </cell>
20115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20116 \begin_inset Text
20117
20118 \layout Standard
20119
20120 WREG
20121 \end_inset 
20122 </cell>
20123 </row>
20124 <row topline="true">
20125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20126 \begin_inset Text
20127
20128 \layout Standard
20129
20130 16 bits
20131 \end_inset 
20132 </cell>
20133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20134 \begin_inset Text
20135
20136 \layout Standard
20137
20138 PRODL:WREG
20139 \end_inset 
20140 </cell>
20141 </row>
20142 <row topline="true">
20143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20144 \begin_inset Text
20145
20146 \layout Standard
20147
20148 24 bits
20149 \end_inset 
20150 </cell>
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20152 \begin_inset Text
20153
20154 \layout Standard
20155
20156 PRODH:PRODL:WREG
20157 \end_inset 
20158 </cell>
20159 </row>
20160 <row topline="true">
20161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20162 \begin_inset Text
20163
20164 \layout Standard
20165
20166 32 bits
20167 \end_inset 
20168 </cell>
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20170 \begin_inset Text
20171
20172 \layout Standard
20173
20174 FSR0L:PRODH:PRODL:WREG
20175 \end_inset 
20176 </cell>
20177 </row>
20178 <row topline="true" bottomline="true">
20179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20180 \begin_inset Text
20181
20182 \layout Standard
20183
20184 >32 bits
20185 \end_inset 
20186 </cell>
20187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20188 \begin_inset Text
20189
20190 \layout Standard
20191
20192 on stack, FSR0 points to the beginning
20193 \end_inset 
20194 </cell>
20195 </row>
20196 </lyxtabular>
20197
20198 \end_inset 
20199
20200
20201 \layout Subsection
20202
20203 Interrupts
20204 \layout Standard
20205
20206 An interrupt
20207 \begin_inset LatexCommand \index{PIC16!interrupt}
20208
20209 \end_inset 
20210
20211  service routine (ISR) is declared using the 
20212 \emph on 
20213 interrupt
20214 \emph default 
20215  keyword.
20216 \layout LyX-Code
20217
20218 void isr(void) interrupt 
20219 \emph on 
20220 n
20221 \layout LyX-Code
20222
20223 {
20224 \layout LyX-Code
20225
20226 ...
20227 \layout LyX-Code
20228
20229 }
20230 \layout Standard
20231
20232
20233 \emph on 
20234 n
20235 \emph default 
20236  is the interrupt number, which for PIC18F devices can be:
20237 \layout Standard
20238 \align center 
20239
20240 \begin_inset  Tabular
20241 <lyxtabular version="3" rows="4" columns="3">
20242 <features>
20243 <column alignment="center" valignment="top" leftline="true" width="0">
20244 <column alignment="center" valignment="top" leftline="true" width="0">
20245 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20246 <row topline="true" bottomline="true">
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20248 \begin_inset Text
20249
20250 \layout Standard
20251
20252
20253 \emph on 
20254 n
20255 \end_inset 
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \layout Standard
20261
20262 Interrupt Vector
20263 \end_inset 
20264 </cell>
20265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20266 \begin_inset Text
20267
20268 \layout Standard
20269
20270 Interrupt Vector Address
20271 \end_inset 
20272 </cell>
20273 </row>
20274 <row topline="true">
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \layout Standard
20279
20280 0
20281 \end_inset 
20282 </cell>
20283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20284 \begin_inset Text
20285
20286 \layout Standard
20287
20288 RESET vector
20289 \end_inset 
20290 </cell>
20291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20292 \begin_inset Text
20293
20294 \layout Standard
20295
20296 0x000000
20297 \end_inset 
20298 </cell>
20299 </row>
20300 <row topline="true">
20301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20302 \begin_inset Text
20303
20304 \layout Standard
20305
20306
20307 \family roman 
20308 \series medium 
20309 \shape up 
20310 \size normal 
20311 \emph off 
20312 \bar no 
20313 \noun off 
20314 \color none
20315 1
20316 \end_inset 
20317 </cell>
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \layout Standard
20322
20323
20324 \family roman 
20325 \series medium 
20326 \shape up 
20327 \size normal 
20328 \emph off 
20329 \bar no 
20330 \noun off 
20331 \color none
20332 HIGH priority interrupts
20333 \end_inset 
20334 </cell>
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20336 \begin_inset Text
20337
20338 \layout Standard
20339
20340 0x000008
20341 \end_inset 
20342 </cell>
20343 </row>
20344 <row topline="true" bottomline="true">
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20346 \begin_inset Text
20347
20348 \layout Standard
20349
20350 2
20351 \end_inset 
20352 </cell>
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20354 \begin_inset Text
20355
20356 \layout Standard
20357
20358 LOW priority interrupts
20359 \end_inset 
20360 </cell>
20361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20362 \begin_inset Text
20363
20364 \layout Standard
20365
20366 0x000018
20367 \end_inset 
20368 </cell>
20369 </row>
20370 </lyxtabular>
20371
20372 \end_inset 
20373
20374
20375 \layout Standard
20376
20377 When generating assembly code for ISR the code generator places a 
20378 \noun on 
20379 goto 
20380 \noun default 
20381 instruction at the 
20382 \emph on 
20383 Interrupt Vector Address
20384 \emph default 
20385  which points at the genetated ISR.
20386  This single GOTO instruction is part of an automatically generated 
20387 \emph on 
20388 interrupt entry point
20389 \emph default 
20390  function.
20391  The actuall ISR code is placed as normally would in the code space.
20392  Upon interrupt request, the GOTO instruction is executed which jumps to
20393  the ISR code.
20394  When declaring interrupt functions as _naked this GOTO instruction is 
20395 \series bold 
20396 not
20397 \series default 
20398  generated.
20399  The whole interrupt functions is therefore placed at the Interrupt Vector
20400  Address of the specific interrupt.
20401  This is not a problem for the LOW priority interrupts, but it is a problem
20402  for the RESET and the HIGH priority interrupts because code may be written
20403  at the next interrupt´s vector address and cause undeterminate program
20404  behaviour if that interrupt is raised.
20405 \begin_inset Foot
20406 collapsed false
20407
20408 \layout Standard
20409
20410 This is not a problem when
20411 \layout Enumerate
20412
20413 this is a HIGH interrupt ISR and LOW interrupts are 
20414 \emph on 
20415 disabled
20416 \emph default 
20417  or not used.
20418 \layout Enumerate
20419
20420 when the ISR is small enough not to reach the next interrupt´s vector address.
20421 \end_inset 
20422
20423
20424 \layout Standard
20425
20426
20427 \emph on 
20428 n
20429 \emph default 
20430  is possible to be omitted.
20431  This way a function is generated similar to an ISR, but it is not assigned
20432  to any interrupt.
20433 \layout Standard
20434
20435 When entering an interrupt, currently the PIC16
20436 \begin_inset LatexCommand \index{PIC16}
20437
20438 \end_inset 
20439
20440  port automatically saves the following registers:
20441 \layout Itemize
20442
20443 WREG
20444 \layout Itemize
20445
20446 STATUS
20447 \layout Itemize
20448
20449 BSR
20450 \layout Itemize
20451
20452 PROD (PRODL and PRODH)
20453 \layout Itemize
20454
20455 FSR0 (FSR0L and FSR0H)
20456 \layout Standard
20457
20458 These registers are restored upon return from the interrupt routine.
20459 \begin_inset Foot
20460 collapsed false
20461
20462 \layout Standard
20463
20464 NOTE that when the _naked attribute is specified for an interrupt routine,
20465  then NO registers are stored or restored.
20466 \end_inset 
20467
20468
20469 \layout Subsection
20470
20471 Generic Pointers
20472 \layout Standard
20473
20474 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20475  There are 3 types of generic pointers currently implemented data, code
20476  and eeprom pointers.
20477  They are differentiated by the value of the 7th and 6th bits of the upper
20478  byte:
20479 \layout Standard
20480 \align center 
20481
20482 \begin_inset  Tabular
20483 <lyxtabular version="3" rows="5" columns="5">
20484 <features>
20485 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20486 <column alignment="center" valignment="top" width="0">
20487 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20488 <column alignment="center" valignment="top" width="0">
20489 <column alignment="left" valignment="top" rightline="true" width="0">
20490 <row topline="true" bottomline="true">
20491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_inset Text
20493
20494 \layout Standard
20495
20496 pointer type
20497 \end_inset 
20498 </cell>
20499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20500 \begin_inset Text
20501
20502 \layout Standard
20503
20504 7th bit
20505 \end_inset 
20506 </cell>
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \layout Standard
20511
20512 6th bit
20513 \end_inset 
20514 </cell>
20515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20516 \begin_inset Text
20517
20518 \layout Standard
20519
20520 rest of the pointer
20521 \end_inset 
20522 </cell>
20523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20524 \begin_inset Text
20525
20526 \layout Standard
20527
20528 description
20529 \end_inset 
20530 </cell>
20531 </row>
20532 <row topline="true" bottomline="true">
20533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20534 \begin_inset Text
20535
20536 \layout Standard
20537
20538 data 
20539 \end_inset 
20540 </cell>
20541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20542 \begin_inset Text
20543
20544 \layout Standard
20545
20546 1
20547 \end_inset 
20548 </cell>
20549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20550 \begin_inset Text
20551
20552 \layout Standard
20553
20554 0
20555 \end_inset 
20556 </cell>
20557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20558 \begin_inset Text
20559
20560 \layout Standard
20561
20562
20563 \family typewriter 
20564 \shape slanted 
20565 \emph on 
20566 uuuuuu uuuuxxxx xxxxxxxx
20567 \end_inset 
20568 </cell>
20569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20570 \begin_inset Text
20571
20572 \layout Standard
20573
20574 a 12-bit data pointer in data RAM memory
20575 \end_inset 
20576 </cell>
20577 </row>
20578 <row bottomline="true">
20579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20580 \begin_inset Text
20581
20582 \layout Standard
20583
20584 code
20585 \end_inset 
20586 </cell>
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20588 \begin_inset Text
20589
20590 \layout Standard
20591
20592 0
20593 \end_inset 
20594 </cell>
20595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20596 \begin_inset Text
20597
20598 \layout Standard
20599
20600 0
20601 \end_inset 
20602 </cell>
20603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20604 \begin_inset Text
20605
20606 \layout Standard
20607
20608
20609 \family typewriter 
20610 \shape slanted 
20611 \emph on 
20612 uxxxxx xxxxxxxx xxxxxxxx
20613 \end_inset 
20614 </cell>
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20616 \begin_inset Text
20617
20618 \layout Standard
20619
20620 a 21-bit code pointer in FLASH memory
20621 \end_inset 
20622 </cell>
20623 </row>
20624 <row bottomline="true">
20625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20626 \begin_inset Text
20627
20628 \layout Standard
20629
20630 eeprom
20631 \end_inset 
20632 </cell>
20633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20634 \begin_inset Text
20635
20636 \layout Standard
20637
20638 0
20639 \end_inset 
20640 </cell>
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20642 \begin_inset Text
20643
20644 \layout Standard
20645
20646 1
20647 \end_inset 
20648 </cell>
20649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20650 \begin_inset Text
20651
20652 \layout Standard
20653
20654
20655 \family typewriter 
20656 \shape slanted 
20657 \emph on 
20658 uuuuuu uuuuuuxx xxxxxxxx
20659 \end_inset 
20660 </cell>
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20662 \begin_inset Text
20663
20664 \layout Standard
20665
20666 a 10-bit eeprom pointer in EEPROM memory
20667 \end_inset 
20668 </cell>
20669 </row>
20670 <row bottomline="true">
20671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_inset Text
20673
20674 \layout Standard
20675
20676 (unimplemented)
20677 \end_inset 
20678 </cell>
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20680 \begin_inset Text
20681
20682 \layout Standard
20683
20684 1
20685 \end_inset 
20686 </cell>
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20688 \begin_inset Text
20689
20690 \layout Standard
20691
20692 1
20693 \end_inset 
20694 </cell>
20695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20696 \begin_inset Text
20697
20698 \layout Standard
20699
20700
20701 \family typewriter 
20702 \shape slanted 
20703 \emph on 
20704 xxxxxx xxxxxxxx xxxxxxxx
20705 \end_inset 
20706 </cell>
20707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20708 \begin_inset Text
20709
20710 \layout Standard
20711
20712 unimplemented pointer type
20713 \end_inset 
20714 </cell>
20715 </row>
20716 </lyxtabular>
20717
20718 \end_inset 
20719
20720
20721 \layout Standard
20722
20723 Generic pointer are read and written with a set of library functions which
20724  read/write 1, 2, 3, 4 bytes.
20725 \layout Subsection
20726
20727 PIC16 C Libraries
20728 \layout Subsubsection
20729
20730 Standard I/O Streams
20731 \layout Standard
20732
20733 In the 
20734 \emph on 
20735 stdio.h
20736 \emph default 
20737  the type FILE is defined as:
20738 \layout LyX-Code
20739
20740 typedef char * FILE;
20741 \layout Standard
20742
20743 This type is the stream type implemented I/O in the PIC18F devices.
20744  Also the standard input and output streams are declared in stdio.h:
20745 \layout LyX-Code
20746
20747 extern FILE * stdin;
20748 \layout LyX-Code
20749
20750 extern FILE * stdout;
20751 \layout Standard
20752
20753 The FILE type is actually a generic pointer which defines one more type
20754  of generic pointers, the 
20755 \emph on 
20756 stream 
20757 \emph default 
20758 pointer.
20759  This new type has the format:
20760 \layout Standard
20761 \align center 
20762
20763 \begin_inset  Tabular
20764 <lyxtabular version="3" rows="2" columns="7">
20765 <features>
20766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20767 <column alignment="center" valignment="top" width="0">
20768 <column alignment="center" valignment="top" leftline="true" width="0">
20769 <column alignment="center" valignment="top" leftline="true" width="0">
20770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20771 <column alignment="center" valignment="top" width="0">
20772 <column alignment="left" valignment="top" rightline="true" width="0">
20773 <row topline="true" bottomline="true">
20774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20775 \begin_inset Text
20776
20777 \layout Standard
20778
20779 pointer type
20780 \end_inset 
20781 </cell>
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20783 \begin_inset Text
20784
20785 \layout Standard
20786
20787 <7:6>
20788 \end_inset 
20789 </cell>
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20791 \begin_inset Text
20792
20793 \layout Standard
20794
20795 <5>
20796 \end_inset 
20797 </cell>
20798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20799 \begin_inset Text
20800
20801 \layout Standard
20802
20803 <4>
20804 \end_inset 
20805 </cell>
20806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20807 \begin_inset Text
20808
20809 \layout Standard
20810
20811 <3:0>
20812 \end_inset 
20813 </cell>
20814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20815 \begin_inset Text
20816
20817 \layout Standard
20818
20819 rest of the pointer
20820 \end_inset 
20821 </cell>
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20823 \begin_inset Text
20824
20825 \layout Standard
20826
20827 descrption
20828 \end_inset 
20829 </cell>
20830 </row>
20831 <row topline="true" bottomline="true">
20832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20833 \begin_inset Text
20834
20835 \layout Standard
20836
20837 stream
20838 \end_inset 
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \layout Standard
20844
20845 00
20846 \end_inset 
20847 </cell>
20848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20849 \begin_inset Text
20850
20851 \layout Standard
20852
20853 1
20854 \end_inset 
20855 </cell>
20856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20857 \begin_inset Text
20858
20859 \layout Standard
20860
20861 0
20862 \end_inset 
20863 </cell>
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20865 \begin_inset Text
20866
20867 \layout Standard
20868
20869 nnnn
20870 \end_inset 
20871 </cell>
20872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20873 \begin_inset Text
20874
20875 \layout Standard
20876
20877
20878 \family typewriter 
20879 \shape slanted 
20880 \emph on 
20881 uuuuuuuu uuuuuuuu
20882 \end_inset 
20883 </cell>
20884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20885 \begin_inset Text
20886
20887 \layout Standard
20888
20889 upper byte high nubble is 0x2n, the rest are zeroes
20890 \end_inset 
20891 </cell>
20892 </row>
20893 </lyxtabular>
20894
20895 \end_inset 
20896
20897
20898 \layout Standard
20899
20900 Currently implemented there are 3 types of streams defined:
20901 \layout Standard
20902 \align center 
20903
20904 \begin_inset  Tabular
20905 <lyxtabular version="3" rows="4" columns="4">
20906 <features>
20907 <column alignment="center" valignment="top" leftline="true" width="0">
20908 <column alignment="center" valignment="top" leftline="true" width="0">
20909 <column alignment="center" valignment="top" leftline="true" width="0">
20910 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20911 <row topline="true" bottomline="true">
20912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20913 \begin_inset Text
20914
20915 \layout Standard
20916
20917 stream type
20918 \end_inset 
20919 </cell>
20920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20921 \begin_inset Text
20922
20923 \layout Standard
20924
20925 value
20926 \end_inset 
20927 </cell>
20928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20929 \begin_inset Text
20930
20931 \layout Standard
20932
20933 module
20934 \end_inset 
20935 </cell>
20936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20937 \begin_inset Text
20938
20939 \layout Standard
20940
20941 description
20942 \end_inset 
20943 </cell>
20944 </row>
20945 <row topline="true">
20946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20947 \begin_inset Text
20948
20949 \layout Standard
20950
20951 STREAM_USART
20952 \end_inset 
20953 </cell>
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20955 \begin_inset Text
20956
20957 \layout Standard
20958
20959
20960 \family typewriter 
20961 0x200000UL
20962 \end_inset 
20963 </cell>
20964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20965 \begin_inset Text
20966
20967 \layout Standard
20968
20969 USART
20970 \end_inset 
20971 </cell>
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \layout Standard
20976
20977 Writes/Reads characters via the USART peripheral
20978 \end_inset 
20979 </cell>
20980 </row>
20981 <row topline="true">
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20983 \begin_inset Text
20984
20985 \layout Standard
20986
20987 STREAM_MSSP
20988 \end_inset 
20989 </cell>
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \layout Standard
20994
20995
20996 \family typewriter 
20997 0x210000UL
20998 \end_inset 
20999 </cell>
21000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21001 \begin_inset Text
21002
21003 \layout Standard
21004
21005 MSSP
21006 \end_inset 
21007 </cell>
21008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21009 \begin_inset Text
21010
21011 \layout Standard
21012
21013 Writes/Reads characters via the MSSP peripheral
21014 \end_inset 
21015 </cell>
21016 </row>
21017 <row topline="true" bottomline="true">
21018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21019 \begin_inset Text
21020
21021 \layout Standard
21022
21023 STREAM_USER
21024 \end_inset 
21025 </cell>
21026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21027 \begin_inset Text
21028
21029 \layout Standard
21030
21031
21032 \family typewriter 
21033 0x2f0000UL
21034 \end_inset 
21035 </cell>
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21037 \begin_inset Text
21038
21039 \layout Standard
21040
21041 (none)
21042 \end_inset 
21043 </cell>
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21045 \begin_inset Text
21046
21047 \layout Standard
21048
21049 Writes/Reads characters via used defined functions
21050 \end_inset 
21051 </cell>
21052 </row>
21053 </lyxtabular>
21054
21055 \end_inset 
21056
21057
21058 \layout Standard
21059
21060 The stream identifiers are declared as macros in the stdio.h header.
21061 \layout Standard
21062
21063 In the libc library there exist the functions that are used to write to
21064  each of the above streams.
21065  These are
21066 \layout List
21067 \labelwidthstring 00.00.0000
21068
21069 _
21070 \begin_inset ERT
21071 status Collapsed
21072
21073 \layout Standard
21074
21075 \backslash 
21076 /
21077 \end_inset 
21078
21079 _stream_usart_putchar writes a character at the USART stream
21080 \layout List
21081 \labelwidthstring 00.00.0000
21082
21083 _
21084 \begin_inset ERT
21085 status Collapsed
21086
21087 \layout Standard
21088
21089 \backslash 
21090 /
21091 \end_inset 
21092
21093 _stream_mssp_putchar writes a character at the MSSP stream
21094 \layout List
21095 \labelwidthstring 00.00.0000
21096
21097 putchar dummy function.
21098  This writes a character to a user specified manner.
21099 \layout Standard
21100
21101 In order to increase performance 
21102 \emph on 
21103 putchar 
21104 \emph default 
21105 is declared in stdio.h as having its parameter in WREG (it has the wparam
21106  keyword).
21107  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21108  in a user-friendly way.
21109  
21110 \emph on 
21111 arg
21112 \emph default 
21113  is the name of the variable that holds the character to print.
21114  An example follows:
21115 \layout LyX-Code
21116
21117 #include <pic18fregs.h>
21118 \newline 
21119 #include <stdio.h>
21120 \newline 
21121
21122 \newline 
21123 PUTCHAR( c )
21124 \layout LyX-Code
21125
21126 {
21127 \layout LyX-Code
21128
21129     PORTA = c;    /* dump character c to PORTA */
21130 \layout LyX-Code
21131
21132
21133 \newline 
21134
21135 \newline 
21136 void main(void)
21137 \layout LyX-Code
21138
21139 {
21140 \layout LyX-Code
21141
21142     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21143 \layout LyX-Code
21144
21145                               * by default to STREAM_USER */
21146 \layout LyX-Code
21147
21148     printf (¨This is a printf test
21149 \backslash 
21150 n¨);
21151 \layout LyX-Code
21152
21153 }
21154 \layout LyX-Code
21155
21156 \layout Subsubsection
21157
21158 Printing functions
21159 \layout Standard
21160
21161 PIC16 contains an implementation of the printf-family of functions.
21162  There exist the following functions:
21163 \layout LyX-Code
21164
21165 extern unsigned int sprintf(char *buf, char *fmt, ...);
21166 \layout LyX-Code
21167
21168 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21169 \layout LyX-Code
21170
21171 \layout LyX-Code
21172
21173 extern unsigned int printf(char *fmt, ...);
21174 \layout LyX-Code
21175
21176 extern unsigned int vprintf(char *fmt, va_lista ap);
21177 \layout LyX-Code
21178
21179 \layout LyX-Code
21180
21181 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21182 \layout LyX-Code
21183
21184 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21185 \layout Standard
21186
21187 For sprintf and vsprintf 
21188 \emph on 
21189 buf 
21190 \emph default 
21191 should normally be a data pointer where the resulting string will be placed.
21192  No range checking is done so the user should allocate the necessery buffer.
21193  For fprintf and vfprintf 
21194 \emph on 
21195 fp
21196 \emph default 
21197  should be a stream pointer (i.e.
21198  stdout, STREAM_MSSP, etc...).
21199 \layout Subsubsection
21200
21201 Signals
21202 \layout Standard
21203
21204 The PIC18F family of microcontrollers supports a number of interrupt sources.
21205  A list of these interrupts is shown in the following table:
21206 \layout Standard
21207 \align center 
21208
21209 \begin_inset  Tabular
21210 <lyxtabular version="3" rows="11" columns="4">
21211 <features>
21212 <column alignment="left" valignment="top" leftline="true" width="0">
21213 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21214 <column alignment="left" valignment="top" leftline="true" width="0">
21215 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21216 <row topline="true" bottomline="true">
21217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21218 \begin_inset Text
21219
21220 \layout Standard
21221
21222 signal name
21223 \end_inset 
21224 </cell>
21225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21226 \begin_inset Text
21227
21228 \layout Standard
21229
21230 description
21231 \end_inset 
21232 </cell>
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21234 \begin_inset Text
21235
21236 \layout Standard
21237
21238 signal name
21239 \end_inset 
21240 </cell>
21241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21242 \begin_inset Text
21243
21244 \layout Standard
21245
21246 descritpion
21247 \end_inset 
21248 </cell>
21249 </row>
21250 <row topline="true">
21251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21252 \begin_inset Text
21253
21254 \layout Standard
21255
21256 SIG_RB
21257 \end_inset 
21258 </cell>
21259 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21260 \begin_inset Text
21261
21262 \layout Standard
21263
21264 PORTB change interrupt
21265 \end_inset 
21266 </cell>
21267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21268 \begin_inset Text
21269
21270 \layout Standard
21271
21272 SIG_EE
21273 \end_inset 
21274 </cell>
21275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21276 \begin_inset Text
21277
21278 \layout Standard
21279
21280 EEPROM/FLASH write complete interrupt
21281 \end_inset 
21282 </cell>
21283 </row>
21284 <row topline="true">
21285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21286 \begin_inset Text
21287
21288 \layout Standard
21289
21290 SIG_INT0
21291 \end_inset 
21292 </cell>
21293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21294 \begin_inset Text
21295
21296 \layout Standard
21297
21298 INT0 external interrupt
21299 \end_inset 
21300 </cell>
21301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21302 \begin_inset Text
21303
21304 \layout Standard
21305
21306 SIG_BCOL
21307 \end_inset 
21308 </cell>
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21310 \begin_inset Text
21311
21312 \layout Standard
21313
21314 Bus collision interrupt
21315 \end_inset 
21316 </cell>
21317 </row>
21318 <row topline="true">
21319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21320 \begin_inset Text
21321
21322 \layout Standard
21323
21324 SIG_INT1
21325 \end_inset 
21326 </cell>
21327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21328 \begin_inset Text
21329
21330 \layout Standard
21331
21332 INT1 external interrupt
21333 \end_inset 
21334 </cell>
21335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21336 \begin_inset Text
21337
21338 \layout Standard
21339
21340 SIG_LVD
21341 \end_inset 
21342 </cell>
21343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21344 \begin_inset Text
21345
21346 \layout Standard
21347
21348 Low voltage detect interrupt
21349 \end_inset 
21350 </cell>
21351 </row>
21352 <row topline="true">
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21354 \begin_inset Text
21355
21356 \layout Standard
21357
21358 SIG_INT2
21359 \end_inset 
21360 </cell>
21361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21362 \begin_inset Text
21363
21364 \layout Standard
21365
21366 INT2 external interrupt
21367 \end_inset 
21368 </cell>
21369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21370 \begin_inset Text
21371
21372 \layout Standard
21373
21374 SIG_PSP
21375 \end_inset 
21376 </cell>
21377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21378 \begin_inset Text
21379
21380 \layout Standard
21381
21382 Parallel slave port interrupt
21383 \end_inset 
21384 </cell>
21385 </row>
21386 <row topline="true">
21387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21388 \begin_inset Text
21389
21390 \layout Standard
21391
21392 SIG_CCP1
21393 \end_inset 
21394 </cell>
21395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21396 \begin_inset Text
21397
21398 \layout Standard
21399
21400 CCP1 module interrupt
21401 \end_inset 
21402 </cell>
21403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21404 \begin_inset Text
21405
21406 \layout Standard
21407
21408 SIG_AD
21409 \end_inset 
21410 </cell>
21411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21412 \begin_inset Text
21413
21414 \layout Standard
21415
21416 AD convertion complete interrupt
21417 \end_inset 
21418 </cell>
21419 </row>
21420 <row topline="true">
21421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21422 \begin_inset Text
21423
21424 \layout Standard
21425
21426 SIG_CCP2
21427 \end_inset 
21428 </cell>
21429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21430 \begin_inset Text
21431
21432 \layout Standard
21433
21434 CCP2 module interrupt
21435 \end_inset 
21436 </cell>
21437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21438 \begin_inset Text
21439
21440 \layout Standard
21441
21442 SIG_RC
21443 \end_inset 
21444 </cell>
21445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21446 \begin_inset Text
21447
21448 \layout Standard
21449
21450 USART receive interrupt
21451 \end_inset 
21452 </cell>
21453 </row>
21454 <row topline="true">
21455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21456 \begin_inset Text
21457
21458 \layout Standard
21459
21460 SIG_TMR0
21461 \end_inset 
21462 </cell>
21463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21464 \begin_inset Text
21465
21466 \layout Standard
21467
21468 TMR0 overflow interrupt
21469 \end_inset 
21470 </cell>
21471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21472 \begin_inset Text
21473
21474 \layout Standard
21475
21476 SIG_TX
21477 \end_inset 
21478 </cell>
21479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21480 \begin_inset Text
21481
21482 \layout Standard
21483
21484 USART transmit interrupt
21485 \end_inset 
21486 </cell>
21487 </row>
21488 <row topline="true">
21489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21490 \begin_inset Text
21491
21492 \layout Standard
21493
21494 SIG_TMR1
21495 \end_inset 
21496 </cell>
21497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21498 \begin_inset Text
21499
21500 \layout Standard
21501
21502 TMR1 overflow interrupt
21503 \end_inset 
21504 </cell>
21505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21506 \begin_inset Text
21507
21508 \layout Standard
21509
21510 SIG_MSSP
21511 \end_inset 
21512 </cell>
21513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21514 \begin_inset Text
21515
21516 \layout Standard
21517
21518 SSP receive/transmit interrupt
21519 \end_inset 
21520 </cell>
21521 </row>
21522 <row topline="true">
21523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21524 \begin_inset Text
21525
21526 \layout Standard
21527
21528 SIG_TMR2
21529 \end_inset 
21530 </cell>
21531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21532 \begin_inset Text
21533
21534 \layout Standard
21535
21536 TMR2 matches PR2 interrupt
21537 \end_inset 
21538 </cell>
21539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21540 \begin_inset Text
21541
21542 \layout Standard
21543
21544 \end_inset 
21545 </cell>
21546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21547 \begin_inset Text
21548
21549 \layout Standard
21550
21551 \end_inset 
21552 </cell>
21553 </row>
21554 <row topline="true" bottomline="true">
21555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21556 \begin_inset Text
21557
21558 \layout Standard
21559
21560 SIG_TMR3
21561 \end_inset 
21562 </cell>
21563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21564 \begin_inset Text
21565
21566 \layout Standard
21567
21568 TMR3 overflow interrupt
21569 \end_inset 
21570 </cell>
21571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21572 \begin_inset Text
21573
21574 \layout Standard
21575
21576 \end_inset 
21577 </cell>
21578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21579 \begin_inset Text
21580
21581 \layout Standard
21582
21583 \end_inset 
21584 </cell>
21585 </row>
21586 </lyxtabular>
21587
21588 \end_inset 
21589
21590
21591 \layout Standard
21592
21593 The prototypes for these names are defined in the header file 
21594 \emph on 
21595 signal.h
21596 \emph default 
21597  .
21598 \layout Standard
21599
21600 In order to simplify signal handling, a number of macros is provided:
21601 \layout List
21602 \labelwidthstring 00.00.0000
21603
21604 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21605  high priority interrupts.
21606  
21607 \emph on 
21608 name
21609 \emph default 
21610  is the function name to use.
21611 \layout List
21612 \labelwidthstring 00.00.0000
21613
21614 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21615  low priority interrupt.
21616  
21617 \emph on 
21618 name
21619 \emph default 
21620  is the function name to use.
21621 \layout List
21622 \labelwidthstring 00.00.0000
21623
21624 DEF_HANDLER(sig,handler) define a handler for signal 
21625 \emph on 
21626 sig.
21627 \layout List
21628 \labelwidthstring 00.00.0000
21629
21630 END_DEF end the declaration of the dispatch table.
21631 \layout Standard
21632
21633 Additionally there are two more macros to simplify the declaration of the
21634  signal handler:
21635 \layout List
21636 \labelwidthstring 00.00.0000
21637
21638
21639 \series medium 
21640 SIGHANDLER(handler) 
21641 \series default 
21642 this declares the function prototype for the 
21643 \emph on 
21644 handler
21645 \emph default 
21646  function.
21647 \layout List
21648 \labelwidthstring 00.00.0000
21649
21650 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21651 \layout Standard
21652
21653 An example of using the macros above is shown below:
21654 \layout LyX-Code
21655
21656 #include <pic18fregs.h>
21657 \layout LyX-Code
21658
21659 #include <signal.h>
21660 \newline 
21661
21662 \newline 
21663 DEF_INTHIGH(high_int)
21664 \layout LyX-Code
21665
21666 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21667 \layout LyX-Code
21668
21669 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21670 \layout LyX-Code
21671
21672 END_DEF
21673 \newline 
21674
21675 \newline 
21676 SIGHANDLER(_tmr0_handler)
21677 \layout LyX-Code
21678
21679 {
21680 \layout LyX-Code
21681
21682   /* action to be taken when timer 0 overflows */
21683 \layout LyX-Code
21684
21685 }
21686 \newline 
21687
21688 \newline 
21689 SIGHANDLERNAKED(_bcol_handler)
21690 \layout LyX-Code
21691
21692 {
21693 \layout LyX-Code
21694
21695   _asm
21696 \layout LyX-Code
21697
21698     /* action to be taken when bus collision occurs */
21699 \layout LyX-Code
21700
21701     retfie
21702 \layout LyX-Code
21703
21704  _endasm;
21705 \layout LyX-Code
21706
21707 }
21708 \layout Standard
21709
21710
21711 \series bold 
21712 NOTES:
21713 \series default 
21714  Special care should be taken when using the above scheme:
21715 \layout Itemize
21716
21717 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21718 \layout Itemize
21719
21720 when declaring SIGHANDLERNAKED handler never forget to use 
21721 \emph on 
21722 retfie
21723 \emph default 
21724  for proper returning.
21725 \layout Subsection
21726
21727 PIC16 Port -- Tips
21728 \layout Standard
21729
21730 Here you can find some general tips for compiling programs with SDCC/pic16.
21731 \layout Subsubsection
21732
21733 Stack size
21734 \layout Standard
21735
21736 The default stack
21737 \begin_inset LatexCommand \index{PIC16!stack}
21738
21739 \end_inset 
21740
21741  size (that is 64 bytes) probably is enough for many programs.
21742  One must take care that when there are many levels of function nesting,
21743  or there is excessive usage of stack, its size should be extended.
21744  An example of such a case is the printf/sprintf family of functions.
21745  If you encounter problems like not being able to print integers, then you
21746  need to set the stack size around the maximum (256 for small stack model).
21747  The following diagram shows what happens when calling printf to print an
21748  integer:
21749 \layout LyX-Code
21750
21751 printf () --> ltoa () --> ultoa () --> divschar ()
21752 \layout Standard
21753
21754 It is should be understood that stack is easily consumed when calling complicate
21755 d functions.
21756  Using command line arguments like -
21757 \begin_inset ERT
21758 status Collapsed
21759
21760 \layout Standard
21761
21762 \backslash 
21763 /
21764 \end_inset 
21765
21766 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21767  stack frames.
21768  Other ways to reduce stack usage may exist.
21769 \layout Subsection
21770
21771 Known bugs
21772 \layout Standard
21773
21774 The PIC16 Port currently does not pass SDCC's regression test
21775 \begin_inset LatexCommand \index{Regression test (PIC16)}
21776
21777 \end_inset 
21778
21779  suite (see section 
21780 \begin_inset LatexCommand \ref{sec:Quality-control}
21781
21782 \end_inset 
21783
21784 ) and thus the nightly regression tests for the PIC16 target are currently
21785  disabled for all hosts except for 
21786 \emph on 
21787 Linux on Opteron.
21788
21789 \emph default 
21790  This means you can see the result of the PIC16 regression tests f.e.
21791  by checking the log files in 
21792 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
21793
21794 \end_inset 
21795
21796  (pick the most up to date file there, scroll down, lend a hand).
21797 \layout Chapter
21798
21799 Debugging
21800 \layout Standard
21801
21802 There are several approaches to debugging your code.
21803  This chapter is meant to show your options and to give detail on some of
21804  them:
21805 \newline 
21806
21807 \newline 
21808 When writing your code:
21809 \layout Itemize
21810
21811 write your code with debugging in mind (avoid duplicating code, put conceptually
21812  similar variables into structs, use structured code, have strategic points
21813  within your code where all variables are consistent, ...)
21814 \layout Itemize
21815
21816 run a syntax-checking tool like splint
21817 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21818
21819 \end_inset 
21820
21821
21822 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21823
21824 \end_inset 
21825
21826  (see -
21827 \begin_inset ERT
21828 status Collapsed
21829
21830 \layout Standard
21831
21832 \backslash 
21833 /
21834 \end_inset 
21835
21836 -more-pedantic 
21837 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21838
21839 \end_inset 
21840
21841 ) over the code.
21842 \layout Itemize
21843
21844 for the high level code use a C-compiler (like f.e.
21845  GCC) to compile run and debug the code on your host.
21846  See (see -
21847 \begin_inset ERT
21848 status Collapsed
21849
21850 \layout Standard
21851
21852 \backslash 
21853 /
21854 \end_inset 
21855
21856 -more-pedantic 
21857 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21858
21859 \end_inset 
21860
21861  ) on howto handle syntax extensions like __xdata, __at(), ...
21862  
21863 \layout Itemize
21864
21865 use another C-compiler to compile code for your target.
21866  Always an option but not recommended:) And not very likely to help you.
21867  If you seriously consider walking this path you should at least occasionally
21868  check portability of your code.
21869  Most commercial compiler vendors will offer an evaluation version so you
21870  can test compile your code or snippets of your code.
21871 \layout Standard
21872
21873 Debugging on a simulator:
21874 \layout Itemize
21875
21876 there is a separate section about SDCDB (section 
21877 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21878
21879 \end_inset 
21880
21881 ) below.
21882 \layout Itemize
21883
21884 or (8051 specific) use a freeware/commercial simulator which interfaces
21885  to the AOMF
21886 \begin_inset LatexCommand \index{AOMF, AOMF51}
21887
21888 \end_inset 
21889
21890  file (see 
21891 \begin_inset LatexCommand \ref{OMF file}
21892
21893 \end_inset 
21894
21895 ) optionally generated by SDCC.
21896 \layout Standard
21897
21898 Debugging On-target: 
21899 \layout Itemize
21900
21901 use a MCU port pin to serially output debug data to the RS232 port of your
21902  host.
21903  You'll probably want some level shifting device typically involving a MAX232
21904  or similar IC.
21905  If the hardware serial port of the MCU is not available search for 'Software
21906  UART' in your favourite search machine.
21907 \layout Itemize
21908
21909 use an on-target monitor.
21910  In this context a monitor is a small program which usually accepts commands
21911  via a serial line and allows to set program counter, to single step through
21912  a program and read/write memory locations.
21913  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21914  
21915 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21916
21917 \end_inset 
21918
21919 ).
21920 \layout Itemize
21921
21922 toggle MCU port pins at strategic points within your code and use an oscilloscop
21923 e.
21924  A 
21925 \emph on 
21926 digital oscilloscope
21927 \emph default 
21928
21929 \begin_inset LatexCommand \index{Oscilloscope}
21930
21931 \end_inset 
21932
21933  with deep trace memory is really helpful especially if you have to debug
21934  a realtime application.
21935  If you need to monitor more pins than your oscilloscope provides you can
21936  sometimes get away with a small R-2R network.
21937  On a single channel oscilloscope you could f.e.
21938  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21939 k
21940 \begin_inset Formula $\Omega$
21941 \end_inset 
21942
21943  resistor and the other one by a 5\SpecialChar ~
21944 k
21945 \begin_inset Formula $\Omega$
21946 \end_inset 
21947
21948  resistor to the oscilloscope probe (check output drive capability of the
21949  pins you want to monitor).
21950  If you need to monitor many more pins a 
21951 \emph on 
21952 logic analyzer
21953 \emph default 
21954  will be handy.
21955 \layout Itemize
21956
21957 use an ICE (
21958 \emph on 
21959 i
21960 \emph default 
21961
21962 \emph on 
21963 c
21964 \emph default 
21965 ircuit 
21966 \emph on 
21967 e
21968 \emph default 
21969 mulator
21970 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21971
21972 \end_inset 
21973
21974 ).
21975  Usually very expensive.
21976  And very nice to have too.
21977  And usually locks you (for years...) to the devices the ICE can emulate.
21978  
21979 \layout Itemize
21980
21981 use a remote debugger.
21982  In most 8-bit systems the symbol information is not available on the target,
21983  and a complete debugger is too bulky for the target system.
21984  Therefore usually a debugger on the host system connects to an on-target
21985  debugging stub which accepts only primitive commands.
21986  
21987 \newline 
21988 Terms to enter into your favourite search engine could be 'remote debugging',
21989  'gdb stub' or 'inferior debugger'.
21990  (is there one?)
21991 \layout Itemize
21992
21993 use an on target hardware debugger.
21994  Some of the more modern MCUs include hardware support for setting break
21995  points and monitoring/changing variables by using dedicated hardware pins.
21996  This facility doesn't require additional code to run on the target and
21997  
21998 \emph on 
21999 usually
22000 \emph default 
22001  doesn't affect runtime behaviour until a breakpoint is hit.
22002  For the mcs51 most hardware debuggers use the AOMF
22003 \begin_inset LatexCommand \index{AOMF, AOMF51}
22004
22005 \end_inset 
22006
22007  file (see 
22008 \begin_inset LatexCommand \ref{OMF file}
22009
22010 \end_inset 
22011
22012 ) as input file.
22013  
22014 \layout Standard
22015
22016 Last not least:
22017 \layout Itemize
22018
22019 if you are not familiar with any of the following terms you're likely to
22020  run into problems rather sooner than later: 
22021 \emph on 
22022 volatile
22023 \emph default 
22024
22025 \emph on 
22026 atomic
22027 \emph default 
22028
22029 \emph on 
22030 memory map
22031 \emph default 
22032
22033 \emph on 
22034 overlay
22035 \emph default 
22036 .
22037  As an embedded programmer you 
22038 \emph on 
22039 have
22040 \emph default 
22041  to know them so why not look them up 
22042 \emph on 
22043 before
22044 \emph default 
22045  you have problems?)
22046 \layout Itemize
22047
22048 tell someone else about your problem (actually this is a surprisingly effective
22049  means to hunt down the bug even if the listener is not familiar with your
22050  environment).
22051  As 'failure to communicate' is probably one of the job-induced deformations
22052  of an embedded programmer this is highly encouraged.
22053 \layout Section
22054
22055 Debugging with SDCDB
22056 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22057
22058 \end_inset 
22059
22060
22061 \begin_inset LatexCommand \index{SDCDB (debugger)}
22062
22063 \end_inset 
22064
22065  
22066 \layout Standard
22067
22068 SDCC is distributed with a source level debugger
22069 \begin_inset LatexCommand \index{Debugger}
22070
22071 \end_inset 
22072
22073 .
22074  The debugger uses a command line interface, the command repertoire of the
22075  debugger has been kept as close to gdb
22076 \begin_inset LatexCommand \index{gdb}
22077
22078 \end_inset 
22079
22080  (the GNU debugger) as possible.
22081  The configuration and build process is part of the standard compiler installati
22082 on, which also builds and installs the debugger in the target directory
22083  specified during configuration.
22084  The debugger allows you debug BOTH at the C source and at the ASM source
22085  level.
22086 \layout Subsection
22087
22088 Compiling for Debugging
22089 \layout Standard
22090
22091 The -
22092 \begin_inset ERT
22093 status Collapsed
22094
22095 \layout Standard
22096
22097 \backslash 
22098 /
22099 \end_inset 
22100
22101 -debug
22102 \begin_inset LatexCommand \index{-\/-debug}
22103
22104 \end_inset 
22105
22106  option must be specified for all files for which debug information is to
22107  be generated.
22108  The compiler generates a .adb file for each of these files.
22109  The linker creates the .cdb
22110 \begin_inset LatexCommand \index{<file>.cdb}
22111
22112 \end_inset 
22113
22114  file from the .adb
22115 \begin_inset LatexCommand \index{<file>.adb}
22116
22117 \end_inset 
22118
22119  files and the address information.
22120  This .cdb is used by the debugger.
22121 \layout Subsection
22122
22123 How the Debugger Works
22124 \layout Standard
22125
22126 When the -
22127 \begin_inset ERT
22128 status Collapsed
22129
22130 \layout Standard
22131
22132 \backslash 
22133 /
22134 \end_inset 
22135
22136 -debug option is specified the compiler generates extra symbol information
22137  some of which are put into the assembler source and some are put into the
22138  .adb file.
22139  Then the linker creates the .cdb file from the individual .adb files with
22140  the address information for the symbols.
22141  The debugger reads the symbolic information generated by the compiler &
22142  the address information generated by the linker.
22143  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22144  execution is controlled by the debugger.
22145  When a command is issued for the debugger, it translates it into appropriate
22146  commands for the simulator.
22147  (Currently SDCDM only connects to the simulator but 
22148 \emph on 
22149 newcdb
22150 \emph default 
22151  at 
22152 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22153
22154 \end_inset 
22155
22156  is an effort to connect directly to the hardware.) 
22157 \layout Subsection
22158
22159 Starting the Debugger SDCDB
22160 \layout Standard
22161
22162 The debugger can be started using the following command line.
22163  (Assume the file you are debugging has the file name foo).
22164 \newline 
22165
22166 \newline 
22167
22168 \family sans 
22169 \series bold 
22170 sdcdb foo
22171 \newline 
22172
22173 \family default 
22174 \series default 
22175
22176 \newline 
22177 The debugger will look for the following files.
22178 \layout Itemize
22179
22180 foo.c - the source file.
22181 \layout Itemize
22182
22183 foo.cdb - the debugger symbol information file.
22184 \layout Itemize
22185
22186 foo.ihx - the Intel hex format
22187 \begin_inset LatexCommand \index{Intel hex format}
22188
22189 \end_inset 
22190
22191  object file.
22192 \layout Subsection
22193
22194 SDCDB Command Line Options
22195 \layout Itemize
22196
22197 -
22198 \begin_inset ERT
22199 status Collapsed
22200
22201 \layout Standard
22202
22203 \backslash 
22204 /
22205 \end_inset 
22206
22207 -directory=<source file directory> this option can used to specify the directory
22208  search list.
22209  The debugger will look into the directory list specified for source, cdb
22210  & ihx files.
22211  The items in the directory list must be separated by ':', e.g.
22212  if the source files can be in the directories /home/src1 and /home/src2,
22213  the -
22214 \begin_inset ERT
22215 status Collapsed
22216
22217 \layout Standard
22218
22219 \backslash 
22220 /
22221 \end_inset 
22222
22223 -directory option should be -
22224 \begin_inset ERT
22225 status Collapsed
22226
22227 \layout Standard
22228
22229 \backslash 
22230 /
22231 \end_inset 
22232
22233 -directory=/home/src1:/home/src2.
22234  Note there can be no spaces in the option.
22235  
22236 \layout Itemize
22237
22238 -cd <directory> - change to the <directory>.
22239 \layout Itemize
22240
22241 -fullname - used by GUI front ends.
22242 \layout Itemize
22243
22244 -cpu <cpu-type> - this argument is passed to the simulator please see the
22245  simulator docs for details.
22246 \layout Itemize
22247
22248 -X <Clock frequency > this options is passed to the simulator please see
22249  the simulator docs for details.
22250 \layout Itemize
22251
22252 -s <serial port file> passed to simulator see the simulator docs for details.
22253 \layout Itemize
22254
22255 -S <serial in,out> passed to simulator see the simulator docs for details.
22256 \layout Itemize
22257
22258 -k <port number> passed to simulator see the simulator docs for details.
22259 \layout Subsection
22260
22261 SDCDB Debugger Commands
22262 \layout Standard
22263
22264 As mentioned earlier the command interface for the debugger has been deliberatel
22265 y kept as close the GNU debugger gdb, as possible.
22266  This will help the integration with existing graphical user interfaces
22267  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22268  If you use a graphical user interface for the debugger you can skip this
22269  section.
22270 \layout Subsubsection*
22271
22272 break [line | file:line | function | file:function]
22273 \layout Standard
22274
22275 Set breakpoint at specified line or function:
22276 \newline 
22277
22278 \newline 
22279
22280 \family sans 
22281 \series bold 
22282 sdcdb>break 100 
22283 \newline 
22284 sdcdb>break foo.c:100
22285 \newline 
22286 sdcdb>break funcfoo
22287 \newline 
22288 sdcdb>break foo.c:funcfoo
22289 \layout Subsubsection*
22290
22291 clear [line | file:line | function | file:function ]
22292 \layout Standard
22293
22294 Clear breakpoint at specified line or function:
22295 \newline 
22296
22297 \newline 
22298
22299 \family sans 
22300 \series bold 
22301 sdcdb>clear 100
22302 \newline 
22303 sdcdb>clear foo.c:100
22304 \newline 
22305 sdcdb>clear funcfoo
22306 \newline 
22307 sdcdb>clear foo.c:funcfoo
22308 \layout Subsubsection*
22309
22310 continue
22311 \layout Standard
22312
22313 Continue program being debugged, after breakpoint.
22314 \layout Subsubsection*
22315
22316 finish
22317 \layout Standard
22318
22319 Execute till the end of the current function.
22320 \layout Subsubsection*
22321
22322 delete [n]
22323 \layout Standard
22324
22325 Delete breakpoint number 'n'.
22326  If used without any option clear ALL user defined break points.
22327 \layout Subsubsection*
22328
22329 info [break | stack | frame | registers ]
22330 \layout Itemize
22331
22332 info break - list all breakpoints
22333 \layout Itemize
22334
22335 info stack - show the function call stack.
22336 \layout Itemize
22337
22338 info frame - show information about the current execution frame.
22339 \layout Itemize
22340
22341 info registers - show content of all registers.
22342 \layout Subsubsection*
22343
22344 step
22345 \layout Standard
22346
22347 Step program until it reaches a different source line.
22348  Note: pressing <return> repeats the last command.
22349 \layout Subsubsection*
22350
22351 next
22352 \layout Standard
22353
22354 Step program, proceeding through subroutine calls.
22355 \layout Subsubsection*
22356
22357 run
22358 \layout Standard
22359
22360 Start debugged program.
22361 \layout Subsubsection*
22362
22363 ptype variable 
22364 \layout Standard
22365
22366 Print type information of the variable.
22367 \layout Subsubsection*
22368
22369 print variable
22370 \layout Standard
22371
22372 print value of variable.
22373 \layout Subsubsection*
22374
22375 file filename
22376 \layout Standard
22377
22378 load the given file name.
22379  Note this is an alternate method of loading file for debugging.
22380 \layout Subsubsection*
22381
22382 frame
22383 \layout Standard
22384
22385 print information about current frame.
22386 \layout Subsubsection*
22387
22388 set srcmode
22389 \layout Standard
22390
22391 Toggle between C source & assembly source.
22392 \layout Subsubsection*
22393
22394 ! simulator command
22395 \layout Standard
22396
22397 Send the string following '!' to the simulator, the simulator response is
22398  displayed.
22399  Note the debugger does not interpret the command being sent to the simulator,
22400  so if a command like 'go' is sent the debugger can loose its execution
22401  context and may display incorrect values.
22402 \layout Subsubsection*
22403
22404 quit
22405 \layout Standard
22406
22407 "Watch me now.
22408  Iam going Down.
22409  My name is Bobby Brown"
22410 \layout Subsection
22411
22412 Interfacing SDCDB with DDD
22413 \layout Comment
22414
22415 The screenshot was converted from png to eps with: 
22416 \begin_inset Quotes sld
22417 \end_inset 
22418
22419 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22420 \begin_inset Quotes srd
22421 \end_inset 
22422
22423  which produces a pretty compact eps file which is free from compression
22424  artifacts.
22425 \layout Comment
22426
22427 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22428  as this broke the build system on Sourceforge (pdf-file was broken.
22429  pdflatex does not accept eps files).
22430 \layout Standard
22431
22432 The 
22433 \emph on 
22434 p
22435 \emph default 
22436 ortable 
22437 \emph on 
22438 n
22439 \emph default 
22440 etwork 
22441 \emph on 
22442 g
22443 \emph default 
22444 raphics File 
22445 \size footnotesize 
22446
22447 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22448
22449 \end_inset 
22450
22451
22452 \size default 
22453  shows a screenshot of a debugging session with DDD
22454 \begin_inset LatexCommand \index{DDD (debugger)}
22455
22456 \end_inset 
22457
22458  (Unix only) on a simulated 8032.
22459  The debugging session might not run as smoothly as the screenshot suggests.
22460  The debugger allows setting of breakpoints, displaying and changing variables,
22461  single stepping through C and assembler code.
22462  
22463 \newline 
22464 The source was compiled with 
22465 \family sans 
22466 \series bold 
22467
22468 \newline 
22469
22470 \newline 
22471 sdcc -
22472 \family default 
22473 \series default 
22474
22475 \begin_inset ERT
22476 status Collapsed
22477
22478 \layout Standard
22479
22480 \backslash 
22481 /
22482 \end_inset 
22483
22484
22485 \family sans 
22486 \series bold 
22487 -debug ddd_example.c
22488 \family default 
22489 \series default 
22490  
22491 \family sans 
22492 \series bold 
22493
22494 \newline 
22495
22496 \family default 
22497 \series default 
22498
22499 \newline 
22500 and DDD was invoked with 
22501 \family sans 
22502 \series bold 
22503
22504 \newline 
22505
22506 \newline 
22507 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22508 \layout Subsection
22509
22510 Interfacing SDCDB with XEmacs
22511 \begin_inset LatexCommand \index{XEmacs}
22512
22513 \end_inset 
22514
22515
22516 \begin_inset LatexCommand \index{Emacs}
22517
22518 \end_inset 
22519
22520
22521 \layout Standard
22522
22523 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22524  sdcdb.el and sdcdbsrc.el.
22525  These two files can be found in the $(prefix)/bin directory after the installat
22526 ion is complete.
22527  These files need to be loaded into XEmacs for the interface to work.
22528  This can be done at XEmacs startup time by inserting the following into
22529  your '.xemacs' file (which can be found in your HOME directory): 
22530 \newline 
22531
22532 \newline 
22533
22534 \family typewriter 
22535 (load-file sdcdbsrc.el) 
22536 \family default 
22537
22538 \newline 
22539
22540 \newline 
22541 .xemacs is a lisp file so the () around the command is REQUIRED.
22542  The files can also be loaded dynamically while XEmacs is running, set the
22543  environment variable 'EMACSLOADPATH' to the installation bin directory
22544  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22545  To start the interface enter the following command: 
22546 \newline 
22547
22548 \newline 
22549
22550 \family sans 
22551 \series bold 
22552 ESC-x sdcdbsrc
22553 \family default 
22554 \series default 
22555
22556 \newline 
22557
22558 \newline 
22559 You will prompted to enter the file name to be debugged.
22560  
22561 \newline 
22562
22563 \newline 
22564 The command line options that are passed to the simulator directly are bound
22565  to default values in the file sdcdbsrc.el.
22566  The variables are listed below, these values maybe changed as required.
22567 \layout Itemize
22568
22569 sdcdbsrc-cpu-type '51
22570 \layout Itemize
22571
22572 sdcdbsrc-frequency '11059200
22573 \layout Itemize
22574
22575 sdcdbsrc-serial nil
22576 \layout Standard
22577
22578 The following is a list of key mapping for the debugger interface.
22579 \layout Standard
22580
22581 \SpecialChar ~
22582
22583 \family typewriter 
22584
22585 \newline 
22586 ;;\SpecialChar ~
22587 Current Listing :: 
22588 \newline 
22589 ;;key\SpecialChar ~
22590 \SpecialChar ~
22591 \SpecialChar ~
22592 \SpecialChar ~
22593 \SpecialChar ~
22594 \SpecialChar ~
22595 \SpecialChar ~
22596 \SpecialChar ~
22597 \SpecialChar ~
22598 \SpecialChar ~
22599 \SpecialChar ~
22600 \SpecialChar ~
22601 \SpecialChar ~
22602 \SpecialChar ~
22603 binding\SpecialChar ~
22604 \SpecialChar ~
22605 \SpecialChar ~
22606 \SpecialChar ~
22607 \SpecialChar ~
22608 \SpecialChar ~
22609 \SpecialChar ~
22610 \SpecialChar ~
22611 \SpecialChar ~
22612 \SpecialChar ~
22613 \SpecialChar ~
22614 \SpecialChar ~
22615 \SpecialChar ~
22616 \SpecialChar ~
22617 \SpecialChar ~
22618 \SpecialChar ~
22619 \SpecialChar ~
22620 \SpecialChar ~
22621 \SpecialChar ~
22622 \SpecialChar ~
22623 \SpecialChar ~
22624 \SpecialChar ~
22625 Comment 
22626 \newline 
22627 ;;---\SpecialChar ~
22628 \SpecialChar ~
22629 \SpecialChar ~
22630 \SpecialChar ~
22631 \SpecialChar ~
22632 \SpecialChar ~
22633 \SpecialChar ~
22634 \SpecialChar ~
22635 \SpecialChar ~
22636 \SpecialChar ~
22637 \SpecialChar ~
22638 \SpecialChar ~
22639 \SpecialChar ~
22640 \SpecialChar ~
22641 -------\SpecialChar ~
22642 \SpecialChar ~
22643 \SpecialChar ~
22644 \SpecialChar ~
22645 \SpecialChar ~
22646 \SpecialChar ~
22647 \SpecialChar ~
22648 \SpecialChar ~
22649 \SpecialChar ~
22650 \SpecialChar ~
22651 \SpecialChar ~
22652 \SpecialChar ~
22653 \SpecialChar ~
22654 \SpecialChar ~
22655 \SpecialChar ~
22656 \SpecialChar ~
22657 \SpecialChar ~
22658 \SpecialChar ~
22659 \SpecialChar ~
22660 \SpecialChar ~
22661 \SpecialChar ~
22662 \SpecialChar ~
22663 -------
22664 \newline 
22665 ;; 
22666 \newline 
22667 ;;\SpecialChar ~
22668 n\SpecialChar ~
22669 \SpecialChar ~
22670 \SpecialChar ~
22671 \SpecialChar ~
22672 \SpecialChar ~
22673 \SpecialChar ~
22674 \SpecialChar ~
22675 \SpecialChar ~
22676 \SpecialChar ~
22677 \SpecialChar ~
22678 \SpecialChar ~
22679 \SpecialChar ~
22680 \SpecialChar ~
22681 \SpecialChar ~
22682 \SpecialChar ~
22683 sdcdb-next-from-src\SpecialChar ~
22684 \SpecialChar ~
22685 \SpecialChar ~
22686 \SpecialChar ~
22687 \SpecialChar ~
22688 \SpecialChar ~
22689 \SpecialChar ~
22690 \SpecialChar ~
22691 \SpecialChar ~
22692 \SpecialChar ~
22693 SDCDB next command 
22694 \newline 
22695 ;;\SpecialChar ~
22696 b\SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 \SpecialChar ~
22702 \SpecialChar ~
22703 \SpecialChar ~
22704 \SpecialChar ~
22705 \SpecialChar ~
22706 \SpecialChar ~
22707 \SpecialChar ~
22708 \SpecialChar ~
22709 \SpecialChar ~
22710 \SpecialChar ~
22711 sdcdb-back-from-src\SpecialChar ~
22712 \SpecialChar ~
22713 \SpecialChar ~
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 \SpecialChar ~
22717 \SpecialChar ~
22718 \SpecialChar ~
22719 \SpecialChar ~
22720 \SpecialChar ~
22721 SDCDB back command 
22722 \newline 
22723 ;;\SpecialChar ~
22724 c\SpecialChar ~
22725 \SpecialChar ~
22726 \SpecialChar ~
22727 \SpecialChar ~
22728 \SpecialChar ~
22729 \SpecialChar ~
22730 \SpecialChar ~
22731 \SpecialChar ~
22732 \SpecialChar ~
22733 \SpecialChar ~
22734 \SpecialChar ~
22735 \SpecialChar ~
22736 \SpecialChar ~
22737 \SpecialChar ~
22738 \SpecialChar ~
22739 sdcdb-cont-from-src\SpecialChar ~
22740 \SpecialChar ~
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 \SpecialChar ~
22746 \SpecialChar ~
22747 \SpecialChar ~
22748 \SpecialChar ~
22749 SDCDB continue command
22750 \newline 
22751 ;;\SpecialChar ~
22752 s\SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 \SpecialChar ~
22761 \SpecialChar ~
22762 \SpecialChar ~
22763 \SpecialChar ~
22764 \SpecialChar ~
22765 \SpecialChar ~
22766 \SpecialChar ~
22767 sdcdb-step-from-src\SpecialChar ~
22768 \SpecialChar ~
22769 \SpecialChar ~
22770 \SpecialChar ~
22771 \SpecialChar ~
22772 \SpecialChar ~
22773 \SpecialChar ~
22774 \SpecialChar ~
22775 \SpecialChar ~
22776 \SpecialChar ~
22777 SDCDB step command 
22778 \newline 
22779 ;;\SpecialChar ~
22780 ?\SpecialChar ~
22781 \SpecialChar ~
22782 \SpecialChar ~
22783 \SpecialChar ~
22784 \SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 \SpecialChar ~
22789 \SpecialChar ~
22790 \SpecialChar ~
22791 \SpecialChar ~
22792 \SpecialChar ~
22793 \SpecialChar ~
22794 \SpecialChar ~
22795 sdcdb-whatis-c-sexp\SpecialChar ~
22796 \SpecialChar ~
22797 \SpecialChar ~
22798 \SpecialChar ~
22799 \SpecialChar ~
22800 \SpecialChar ~
22801 \SpecialChar ~
22802 \SpecialChar ~
22803 \SpecialChar ~
22804 \SpecialChar ~
22805 SDCDB ptypecommand for data at 
22806 \newline 
22807 ;;\SpecialChar ~
22808 \SpecialChar ~
22809 \SpecialChar ~
22810 \SpecialChar ~
22811 \SpecialChar ~
22812 \SpecialChar ~
22813 \SpecialChar ~
22814 \SpecialChar ~
22815 \SpecialChar ~
22816 \SpecialChar ~
22817 \SpecialChar ~
22818 \SpecialChar ~
22819 \SpecialChar ~
22820 \SpecialChar ~
22821 \SpecialChar ~
22822 \SpecialChar ~
22823 \SpecialChar ~
22824 \SpecialChar ~
22825 \SpecialChar ~
22826 \SpecialChar ~
22827 \SpecialChar ~
22828 \SpecialChar ~
22829 \SpecialChar ~
22830 \SpecialChar ~
22831 \SpecialChar ~
22832 \SpecialChar ~
22833 \SpecialChar ~
22834 \SpecialChar ~
22835 \SpecialChar ~
22836 \SpecialChar ~
22837 \SpecialChar ~
22838 \SpecialChar ~
22839 \SpecialChar ~
22840 \SpecialChar ~
22841 \SpecialChar ~
22842 \SpecialChar ~
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 \SpecialChar ~
22846 \SpecialChar ~
22847 \SpecialChar ~
22848 \SpecialChar ~
22849 \SpecialChar ~
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 \SpecialChar ~
22853 \SpecialChar ~
22854 buffer point 
22855 \newline 
22856 ;;\SpecialChar ~
22857 x\SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 \SpecialChar ~
22862 \SpecialChar ~
22863 \SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 \SpecialChar ~
22872 sdcdbsrc-delete\SpecialChar ~
22873 \SpecialChar ~
22874 \SpecialChar ~
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 \SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 \SpecialChar ~
22886 SDCDB Delete all breakpoints if no arg 
22887 \newline 
22888 ;;\SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 \SpecialChar ~
22902 \SpecialChar ~
22903 \SpecialChar ~
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 \SpecialChar ~
22907 \SpecialChar ~
22908 \SpecialChar ~
22909 \SpecialChar ~
22910 \SpecialChar ~
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 \SpecialChar ~
22914 \SpecialChar ~
22915 \SpecialChar ~
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 \SpecialChar ~
22920 \SpecialChar ~
22921 \SpecialChar ~
22922 \SpecialChar ~
22923 \SpecialChar ~
22924 \SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 \SpecialChar ~
22935 given or delete arg (C-u arg x) 
22936 \newline 
22937 ;;\SpecialChar ~
22938 m\SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 \SpecialChar ~
22943 \SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 \SpecialChar ~
22953 sdcdbsrc-frame\SpecialChar ~
22954 \SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 \SpecialChar ~
22960 \SpecialChar ~
22961 \SpecialChar ~
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 \SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 SDCDB Display current frame if no arg, 
22969 \newline 
22970 ;;\SpecialChar ~
22971 \SpecialChar ~
22972 \SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 \SpecialChar ~
22977 \SpecialChar ~
22978 \SpecialChar ~
22979 \SpecialChar ~
22980 \SpecialChar ~
22981 \SpecialChar ~
22982 \SpecialChar ~
22983 \SpecialChar ~
22984 \SpecialChar ~
22985 \SpecialChar ~
22986 \SpecialChar ~
22987 \SpecialChar ~
22988 \SpecialChar ~
22989 \SpecialChar ~
22990 \SpecialChar ~
22991 \SpecialChar ~
22992 \SpecialChar ~
22993 \SpecialChar ~
22994 \SpecialChar ~
22995 \SpecialChar ~
22996 \SpecialChar ~
22997 \SpecialChar ~
22998 \SpecialChar ~
22999 \SpecialChar ~
23000 \SpecialChar ~
23001 \SpecialChar ~
23002 \SpecialChar ~
23003 \SpecialChar ~
23004 \SpecialChar ~
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 \SpecialChar ~
23008 \SpecialChar ~
23009 \SpecialChar ~
23010 \SpecialChar ~
23011 \SpecialChar ~
23012 \SpecialChar ~
23013 \SpecialChar ~
23014 \SpecialChar ~
23015 \SpecialChar ~
23016 \SpecialChar ~
23017 given or display frame arg 
23018 \newline 
23019 ;;\SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 \SpecialChar ~
23025 \SpecialChar ~
23026 \SpecialChar ~
23027 \SpecialChar ~
23028 \SpecialChar ~
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 \SpecialChar ~
23032 \SpecialChar ~
23033 \SpecialChar ~
23034 \SpecialChar ~
23035 \SpecialChar ~
23036 \SpecialChar ~
23037 \SpecialChar ~
23038 \SpecialChar ~
23039 \SpecialChar ~
23040 \SpecialChar ~
23041 \SpecialChar ~
23042 \SpecialChar ~
23043 \SpecialChar ~
23044 \SpecialChar ~
23045 \SpecialChar ~
23046 \SpecialChar ~
23047 \SpecialChar ~
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 \SpecialChar ~
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 \SpecialChar ~
23056 \SpecialChar ~
23057 \SpecialChar ~
23058 \SpecialChar ~
23059 \SpecialChar ~
23060 \SpecialChar ~
23061 \SpecialChar ~
23062 \SpecialChar ~
23063 \SpecialChar ~
23064 \SpecialChar ~
23065 \SpecialChar ~
23066 buffer point 
23067 \newline 
23068 ;;\SpecialChar ~
23069 !\SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 \SpecialChar ~
23073 \SpecialChar ~
23074 \SpecialChar ~
23075 \SpecialChar ~
23076 \SpecialChar ~
23077 \SpecialChar ~
23078 \SpecialChar ~
23079 \SpecialChar ~
23080 \SpecialChar ~
23081 \SpecialChar ~
23082 \SpecialChar ~
23083 \SpecialChar ~
23084 sdcdbsrc-goto-sdcdb\SpecialChar ~
23085 \SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 \SpecialChar ~
23092 \SpecialChar ~
23093 \SpecialChar ~
23094 Goto the SDCDB output buffer 
23095 \newline 
23096 ;;\SpecialChar ~
23097 p\SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 \SpecialChar ~
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 sdcdb-print-c-sexp\SpecialChar ~
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 SDCDB print command for data at 
23124 \newline 
23125 ;;\SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 \SpecialChar ~
23133 \SpecialChar ~
23134 \SpecialChar ~
23135 \SpecialChar ~
23136 \SpecialChar ~
23137 \SpecialChar ~
23138 \SpecialChar ~
23139 \SpecialChar ~
23140 \SpecialChar ~
23141 \SpecialChar ~
23142 \SpecialChar ~
23143 \SpecialChar ~
23144 \SpecialChar ~
23145 \SpecialChar ~
23146 \SpecialChar ~
23147 \SpecialChar ~
23148 \SpecialChar ~
23149 \SpecialChar ~
23150 \SpecialChar ~
23151 \SpecialChar ~
23152 \SpecialChar ~
23153 \SpecialChar ~
23154 \SpecialChar ~
23155 \SpecialChar ~
23156 \SpecialChar ~
23157 \SpecialChar ~
23158 \SpecialChar ~
23159 \SpecialChar ~
23160 \SpecialChar ~
23161 \SpecialChar ~
23162 \SpecialChar ~
23163 \SpecialChar ~
23164 \SpecialChar ~
23165 \SpecialChar ~
23166 \SpecialChar ~
23167 \SpecialChar ~
23168 \SpecialChar ~
23169 \SpecialChar ~
23170 \SpecialChar ~
23171 \SpecialChar ~
23172 buffer point 
23173 \newline 
23174 ;;\SpecialChar ~
23175 g\SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 \SpecialChar ~
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 \SpecialChar ~
23186 \SpecialChar ~
23187 \SpecialChar ~
23188 \SpecialChar ~
23189 \SpecialChar ~
23190 sdcdbsrc-goto-sdcdb\SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 \SpecialChar ~
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 \SpecialChar ~
23199 \SpecialChar ~
23200 Goto the SDCDB output buffer 
23201 \newline 
23202 ;;\SpecialChar ~
23203 t\SpecialChar ~
23204 \SpecialChar ~
23205 \SpecialChar ~
23206 \SpecialChar ~
23207 \SpecialChar ~
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 \SpecialChar ~
23211 \SpecialChar ~
23212 \SpecialChar ~
23213 \SpecialChar ~
23214 \SpecialChar ~
23215 \SpecialChar ~
23216 \SpecialChar ~
23217 \SpecialChar ~
23218 sdcdbsrc-mode\SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226 \SpecialChar ~
23227 \SpecialChar ~
23228 \SpecialChar ~
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 Toggles Sdcdbsrc mode (turns it off) 
23235 \newline 
23236 ;; 
23237 \newline 
23238 ;;\SpecialChar ~
23239 C-c\SpecialChar ~
23240 C-f\SpecialChar ~
23241 \SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249 sdcdb-finish-from-src\SpecialChar ~
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 \SpecialChar ~
23253 \SpecialChar ~
23254 \SpecialChar ~
23255 \SpecialChar ~
23256 \SpecialChar ~
23257 SDCDB finish command 
23258 \newline 
23259 ;; 
23260 \newline 
23261 ;;\SpecialChar ~
23262 C-x\SpecialChar ~
23263 SPC\SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 \SpecialChar ~
23267 \SpecialChar ~
23268 \SpecialChar ~
23269 \SpecialChar ~
23270 \SpecialChar ~
23271 \SpecialChar ~
23272 sdcdb-break\SpecialChar ~
23273 \SpecialChar ~
23274 \SpecialChar ~
23275 \SpecialChar ~
23276 \SpecialChar ~
23277 \SpecialChar ~
23278 \SpecialChar ~
23279 \SpecialChar ~
23280 \SpecialChar ~
23281 \SpecialChar ~
23282 \SpecialChar ~
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 \SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 \SpecialChar ~
23290 Set break for line with point 
23291 \newline 
23292 ;;\SpecialChar ~
23293 ESC\SpecialChar ~
23294 t\SpecialChar ~
23295 \SpecialChar ~
23296 \SpecialChar ~
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 \SpecialChar ~
23301 \SpecialChar ~
23302 \SpecialChar ~
23303 \SpecialChar ~
23304 \SpecialChar ~
23305 sdcdbsrc-mode\SpecialChar ~
23306 \SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 Toggle Sdcdbsrc mode 
23322 \newline 
23323 ;;\SpecialChar ~
23324 ESC\SpecialChar ~
23325 m\SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 \SpecialChar ~
23329 \SpecialChar ~
23330 \SpecialChar ~
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 \SpecialChar ~
23334 \SpecialChar ~
23335 \SpecialChar ~
23336 sdcdbsrc-srcmode\SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 Toggle list mode 
23350 \newline 
23351 ;; 
23352 \newline 
23353
23354 \layout Chapter
23355 \pagebreak_top 
23356 TIPS
23357 \layout Standard
23358
23359 Here are a few guidelines that will help the compiler generate more efficient
23360  code, some of the tips are specific to this compiler others are generally
23361  good programming practice.
23362 \layout Itemize
23363
23364 Use the smallest data type to represent your data-value.
23365  If it is known in advance that the value is going to be less than 256 then
23366  use an 'unsigned char' instead of a 'short' or 'int'.
23367  Please note, that ANSI C requires both signed and unsigned chars to be
23368  promoted to 'signed int'
23369 \begin_inset LatexCommand \index{promotion to signed int}
23370
23371 \end_inset 
23372
23373
23374 \begin_inset Marginal
23375 collapsed true
23376
23377 \layout Standard
23378
23379
23380 \series bold 
23381 \SpecialChar ~
23382 !
23383 \end_inset 
23384
23385  before doing any operation.
23386  This promotion
23387 \begin_inset LatexCommand \index{type promotion}
23388
23389 \end_inset 
23390
23391
23392 \begin_inset LatexCommand \label{type promotion}
23393
23394 \end_inset 
23395
23396  can be omitted, if the result is the same.
23397  The effect of the promotion rules together with the sign-extension is often
23398  surprising:
23399 \begin_deeper 
23400 \layout Verse
23401
23402
23403 \family typewriter 
23404 unsigned char uc = 0xfe;
23405 \newline 
23406 if (uc * uc < 0) /* this is true! */
23407 \newline 
23408 {
23409 \newline 
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 \SpecialChar ~
23414 ....
23415 \newline 
23416 }
23417 \layout Standard
23418
23419
23420 \family typewriter 
23421 uc * uc
23422 \family default 
23423  is evaluated as 
23424 \family typewriter 
23425 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23426 \family default 
23427 .
23428  
23429 \newline 
23430 Another one:
23431 \layout Verse
23432
23433
23434 \family typewriter 
23435 (unsigned char) -12 / (signed char) -3 = ...
23436 \layout Standard
23437
23438 No, the result is not 4:
23439 \layout Verse
23440
23441
23442 \family typewriter 
23443 (int) (unsigned char) -12 / (int) (signed char) -3 =
23444 \newline 
23445 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23446 \newline 
23447 (int) 0x00f4 / (int) 0xfffd =
23448 \newline 
23449 (int) 0x00f4 / (int) 0xfffd =
23450 \newline 
23451 (int) 244 / (int) -3 =
23452 \newline 
23453 (int) -81 = (int) 0xffaf;
23454 \layout Standard
23455
23456 Don't complain, that gcc gives you a different result.
23457  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23458  Therefore the results are different.
23459 \newline 
23460 From 
23461 \begin_inset Quotes sld
23462 \end_inset 
23463
23464 comp.lang.c FAQ
23465 \begin_inset Quotes srd
23466 \end_inset 
23467
23468 :
23469 \layout Quote
23470
23471
23472 \emph on 
23473 If well-defined overflow characteristics are important and negative values
23474  are not, or if you want to steer clear of sign-extension problems when
23475  manipulating bits or bytes, use one of the corresponding unsigned types.
23476  (Beware when mixing signed and unsigned values in expressions, though.)
23477 \newline 
23478 Although character types (especially unsigned char) can be used as "tiny"
23479  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23480 ble sign extension and increased code size.
23481 \end_deeper 
23482 \layout Itemize
23483
23484 Use unsigned when it is known in advance that the value is not going to
23485  be negative.
23486  This helps especially if you are doing division or multiplication, bit-shifting
23487  or are using an array index.
23488 \layout Itemize
23489
23490 NEVER jump into a LOOP.
23491 \layout Itemize
23492
23493 Declare the variables to be local
23494 \begin_inset LatexCommand \index{local variables}
23495
23496 \end_inset 
23497
23498  whenever possible, especially loop control variables (induction).
23499 \layout Itemize
23500
23501 Since the compiler does not always do implicit integral promotion, the programme
23502 r should do an explicit cast when integral promotion is required.
23503 \layout Itemize
23504
23505 Reducing the size of division, multiplication & modulus operations can reduce
23506  code size substantially.
23507  Take the following code for example.
23508 \begin_deeper 
23509 \layout Verse
23510
23511
23512 \family typewriter 
23513 foobar(unsigned int p1, unsigned char ch)
23514 \newline 
23515 {
23516 \newline 
23517 \SpecialChar ~
23518 \SpecialChar ~
23519 \SpecialChar ~
23520 \SpecialChar ~
23521 unsigned char ch1 = p1 % ch ;
23522 \newline 
23523 \SpecialChar ~
23524 \SpecialChar ~
23525 \SpecialChar ~
23526 \SpecialChar ~
23527 ....
23528 \newline 
23529 }
23530 \layout Standard
23531
23532 For the modulus operation the variable ch will be promoted to unsigned int
23533  first then the modulus operation will be performed (this will lead to a
23534  call to support routine _moduint()), and the result will be casted to a
23535  char.
23536  If the code is changed to 
23537 \layout Verse
23538
23539
23540 \family typewriter 
23541 foobar(unsigned int p1, unsigned char ch)
23542 \newline 
23543 {
23544 \newline 
23545 \SpecialChar ~
23546 \SpecialChar ~
23547 \SpecialChar ~
23548 \SpecialChar ~
23549 unsigned char ch1 = (unsigned char)p1 % ch ;
23550 \newline 
23551 \SpecialChar ~
23552 \SpecialChar ~
23553 \SpecialChar ~
23554 \SpecialChar ~
23555 ....
23556 \newline 
23557 }
23558 \layout Standard
23559
23560 It would substantially reduce the code generated (future versions of the
23561  compiler will be smart enough to detect such optimization opportunities).
23562 \end_deeper 
23563 \layout Itemize
23564
23565 Have a look at the assembly listing to get a 
23566 \begin_inset Quotes sld
23567 \end_inset 
23568
23569 feeling
23570 \begin_inset Quotes srd
23571 \end_inset 
23572
23573  for the code generation.
23574 \layout Section
23575
23576 Porting code from or to other compilers
23577 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23578
23579 \end_inset 
23580
23581
23582 \layout Itemize
23583
23584 check whether endianness of the compilers differs and adapt where needed.
23585 \layout Itemize
23586
23587 check the device specific header files
23588 \begin_inset LatexCommand \index{Header files}
23589
23590 \end_inset 
23591
23592
23593 \begin_inset LatexCommand \index{Include files}
23594
23595 \end_inset 
23596
23597  for compiler specific syntax.
23598  Eventually include the file <compiler.h
23599 \begin_inset LatexCommand \index{compiler.h (include file)}
23600
23601 \end_inset 
23602
23603
23604 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23605
23606 \end_inset 
23607
23608  to allow using common header files.
23609  (see f.e.
23610  cc2510fx.h 
23611 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23612
23613 \end_inset 
23614
23615 ).
23616 \layout Itemize
23617
23618 check whether the startup code contains the correct initialization (watchdog,
23619  peripherals).
23620 \layout Itemize
23621
23622 check whether the sizes of short, int, long match.
23623 \layout Itemize
23624
23625 check if some 16 or 32 bit hardware registers require a specific addressing
23626  order (least significant or most significant byte first) and adapt if needed
23627  (
23628 \emph on 
23629 first
23630 \emph default 
23631  and 
23632 \emph on 
23633 last
23634 \emph default 
23635  relate to time and not to lower/upper memory location here, so this is
23636  
23637 \emph on 
23638 not
23639 \emph default 
23640  the same as endianness).
23641 \layout Itemize
23642
23643 check whether the keyword 
23644 \emph on 
23645 volatile
23646 \emph default 
23647  is used where needed.
23648  The compilers might differ in their optimization characteristics (as different
23649  versions of the same compiler might also use more clever optimizations
23650  this is good idea anyway).
23651  See section 
23652 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23653
23654 \end_inset 
23655
23656 .
23657 \layout Itemize
23658
23659 check that the compilers are not told to supress warnings.
23660 \layout Itemize
23661
23662 check and convert compiler specific extensions (interrupts, memory areas,
23663  pragmas etc.).
23664 \layout Itemize
23665
23666 check for differences in type promotion.
23667  Especially check for math operations on 
23668 \family typewriter 
23669 char
23670 \family default 
23671  or 
23672 \family typewriter 
23673 unsigned char
23674 \family default 
23675  variables.
23676  For the sake of C99 compatibility SDCC will probably promote these to 
23677 \family typewriter 
23678 int
23679 \family default 
23680  more often than other compilers.
23681  Eventually insert explicit casts to 
23682 \family typewriter 
23683 (char) 
23684 \family default 
23685 or
23686 \family typewriter 
23687  (unsigned char)
23688 \family default 
23689 .
23690  Also check that the ~\SpecialChar ~
23691 operator
23692 \begin_inset LatexCommand \index{\~\/ Operator}
23693
23694 \end_inset 
23695
23696  is not used on 
23697 \family typewriter 
23698 bit
23699 \begin_inset LatexCommand \index{bit}
23700
23701 \end_inset 
23702
23703
23704 \family default 
23705  variables, use the !\SpecialChar ~
23706 operator instead.
23707  See sections 
23708 \begin_inset LatexCommand \ref{type promotion}
23709
23710 \end_inset 
23711
23712  and 
23713 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23714
23715 \end_inset 
23716
23717 .
23718 \layout Itemize
23719
23720 check the assembly code generated for interrupt routines (f.e.
23721  for calls to possibly non-reentrant library functions).
23722 \layout Itemize
23723
23724 check whether timing loops result in proper timing (or preferably consider
23725  a rewrite of the code with timer based delays instead).
23726 \layout Itemize
23727
23728 check for differences in printf parameters (some compilers push (va_arg
23729 \begin_inset LatexCommand \index{vararg, va\_arg}
23730
23731 \end_inset 
23732
23733 ) char variables as 
23734 \family typewriter 
23735 int
23736 \family default 
23737  others push them as 
23738 \family typewriter 
23739 char
23740 \family default 
23741 .
23742  See section 
23743 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23744
23745 \end_inset 
23746
23747 ).
23748 \layout Itemize
23749
23750 check the resulting memory map
23751 \begin_inset LatexCommand \index{Memory map}
23752
23753 \end_inset 
23754
23755 .
23756  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23757 ly idata, pdata, xdata).
23758  Eventually check if unexpected library functions are included.
23759 \layout Section
23760
23761 Tools
23762 \begin_inset LatexCommand \index{Tools}
23763
23764 \end_inset 
23765
23766  included in the distribution
23767 \layout Standard
23768 \align left 
23769
23770 \begin_inset  Tabular
23771 <lyxtabular version="3" rows="12" columns="3">
23772 <features>
23773 <column alignment="left" valignment="top" leftline="true" width="0pt">
23774 <column alignment="left" valignment="top" leftline="true" width="0pt">
23775 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23776 <row topline="true" bottomline="true">
23777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23778 \begin_inset Text
23779
23780 \layout Standard
23781
23782 Name
23783 \end_inset 
23784 </cell>
23785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23786 \begin_inset Text
23787
23788 \layout Standard
23789
23790 Purpose
23791 \end_inset 
23792 </cell>
23793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23794 \begin_inset Text
23795
23796 \layout Standard
23797
23798 Directory
23799 \end_inset 
23800 </cell>
23801 </row>
23802 <row topline="true">
23803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23804 \begin_inset Text
23805
23806 \layout Standard
23807
23808 ucSsim
23809 \end_inset 
23810 </cell>
23811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23812 \begin_inset Text
23813
23814 \layout Standard
23815
23816 Simulator for various architectures
23817 \end_inset 
23818 </cell>
23819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23820 \begin_inset Text
23821
23822 \layout Standard
23823
23824 sdcc/sim/ucsim
23825 \end_inset 
23826 </cell>
23827 </row>
23828 <row topline="true">
23829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23830 \begin_inset Text
23831
23832 \layout Standard
23833
23834 keil2sdcc.pl
23835 \end_inset 
23836 </cell>
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23838 \begin_inset Text
23839
23840 \layout Standard
23841
23842 header file
23843 \begin_inset LatexCommand \index{Header files}
23844
23845 \end_inset 
23846
23847
23848 \begin_inset LatexCommand \index{Include files}
23849
23850 \end_inset 
23851
23852  conversion
23853 \end_inset 
23854 </cell>
23855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23856 \begin_inset Text
23857
23858 \layout Standard
23859
23860 sdcc/support/scripts
23861 \end_inset 
23862 </cell>
23863 </row>
23864 <row topline="true">
23865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23866 \begin_inset Text
23867
23868 \layout Standard
23869
23870 mh2h.c
23871 \end_inset 
23872 </cell>
23873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23874 \begin_inset Text
23875
23876 \layout Standard
23877
23878 header file conversion
23879 \end_inset 
23880 </cell>
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23882 \begin_inset Text
23883
23884 \layout Standard
23885
23886 sdcc/support/scripts
23887 \end_inset 
23888 </cell>
23889 </row>
23890 <row topline="true">
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23892 \begin_inset Text
23893
23894 \layout Standard
23895
23896 as-gbz80
23897 \end_inset 
23898 </cell>
23899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23900 \begin_inset Text
23901
23902 \layout Standard
23903
23904 Assembler
23905 \end_inset 
23906 </cell>
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23908 \begin_inset Text
23909
23910 \layout Standard
23911
23912
23913 \family roman 
23914 \series medium 
23915 \shape up 
23916 \size normal 
23917 \emph off 
23918 \bar no 
23919 \noun off 
23920 \color none
23921 sdcc/bin
23922 \end_inset 
23923 </cell>
23924 </row>
23925 <row topline="true">
23926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23927 \begin_inset Text
23928
23929 \layout Standard
23930
23931 as-z80
23932 \end_inset 
23933 </cell>
23934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23935 \begin_inset Text
23936
23937 \layout Standard
23938
23939 Assembler
23940 \end_inset 
23941 </cell>
23942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23943 \begin_inset Text
23944
23945 \layout Standard
23946
23947
23948 \family roman 
23949 \series medium 
23950 \shape up 
23951 \size normal 
23952 \emph off 
23953 \bar no 
23954 \noun off 
23955 \color none
23956 sdcc/bin
23957 \end_inset 
23958 </cell>
23959 </row>
23960 <row topline="true">
23961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23962 \begin_inset Text
23963
23964 \layout Standard
23965
23966 asx8051
23967 \end_inset 
23968 </cell>
23969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23970 \begin_inset Text
23971
23972 \layout Standard
23973
23974 Assembler
23975 \end_inset 
23976 </cell>
23977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23978 \begin_inset Text
23979
23980 \layout Standard
23981
23982
23983 \family roman 
23984 \series medium 
23985 \shape up 
23986 \size normal 
23987 \emph off 
23988 \bar no 
23989 \noun off 
23990 \color none
23991 sdcc/bin
23992 \end_inset 
23993 </cell>
23994 </row>
23995 <row topline="true">
23996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23997 \begin_inset Text
23998
23999 \layout Standard
24000
24001 SDCDB
24002 \end_inset 
24003 </cell>
24004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24005 \begin_inset Text
24006
24007 \layout Standard
24008
24009 Simulator
24010 \end_inset 
24011 </cell>
24012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24013 \begin_inset Text
24014
24015 \layout Standard
24016
24017
24018 \family roman 
24019 \series medium 
24020 \shape up 
24021 \size normal 
24022 \emph off 
24023 \bar no 
24024 \noun off 
24025 \color none
24026 sdcc/bin
24027 \end_inset 
24028 </cell>
24029 </row>
24030 <row topline="true">
24031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24032 \begin_inset Text
24033
24034 \layout Standard
24035
24036 aslink
24037 \end_inset 
24038 </cell>
24039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24040 \begin_inset Text
24041
24042 \layout Standard
24043
24044 Linker
24045 \end_inset 
24046 </cell>
24047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24048 \begin_inset Text
24049
24050 \layout Standard
24051
24052
24053 \family roman 
24054 \series medium 
24055 \shape up 
24056 \size normal 
24057 \emph off 
24058 \bar no 
24059 \noun off 
24060 \color none
24061 sdcc/bin
24062 \end_inset 
24063 </cell>
24064 </row>
24065 <row topline="true">
24066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24067 \begin_inset Text
24068
24069 \layout Standard
24070
24071 link-z80
24072 \end_inset 
24073 </cell>
24074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24075 \begin_inset Text
24076
24077 \layout Standard
24078
24079 Linker
24080 \end_inset 
24081 </cell>
24082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24083 \begin_inset Text
24084
24085 \layout Standard
24086
24087
24088 \family roman 
24089 \series medium 
24090 \shape up 
24091 \size normal 
24092 \emph off 
24093 \bar no 
24094 \noun off 
24095 \color none
24096 sdcc/bin
24097 \end_inset 
24098 </cell>
24099 </row>
24100 <row topline="true">
24101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24102 \begin_inset Text
24103
24104 \layout Standard
24105
24106 link-gbz80
24107 \end_inset 
24108 </cell>
24109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24110 \begin_inset Text
24111
24112 \layout Standard
24113
24114 Linker
24115 \end_inset 
24116 </cell>
24117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24118 \begin_inset Text
24119
24120 \layout Standard
24121
24122
24123 \family roman 
24124 \series medium 
24125 \shape up 
24126 \size normal 
24127 \emph off 
24128 \bar no 
24129 \noun off 
24130 \color none
24131 sdcc/bin
24132 \end_inset 
24133 </cell>
24134 </row>
24135 <row topline="true" bottomline="true">
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24137 \begin_inset Text
24138
24139 \layout Standard
24140
24141 packihx
24142 \end_inset 
24143 </cell>
24144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24145 \begin_inset Text
24146
24147 \layout Standard
24148
24149 Intel Hex packer 
24150 \begin_inset LatexCommand \index{packihx (tool)}
24151
24152 \end_inset 
24153
24154
24155 \end_inset 
24156 </cell>
24157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24158 \begin_inset Text
24159
24160 \layout Standard
24161
24162
24163 \family roman 
24164 \series medium 
24165 \shape up 
24166 \size normal 
24167 \emph off 
24168 \bar no 
24169 \noun off 
24170 \color none
24171 sdcc/bin
24172 \end_inset 
24173 </cell>
24174 </row>
24175 </lyxtabular>
24176
24177 \end_inset 
24178
24179
24180 \newline 
24181
24182 \layout Section
24183
24184 Documentation
24185 \begin_inset LatexCommand \index{Documentation}
24186
24187 \end_inset 
24188
24189  included in the distribution
24190 \layout Standard
24191 \align left 
24192
24193 \begin_inset  Tabular
24194 <lyxtabular version="3" rows="10" columns="2">
24195 <features>
24196 <column alignment="left" valignment="top" leftline="true" width="0">
24197 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24198 <row topline="true" bottomline="true">
24199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24200 \begin_inset Text
24201
24202 \layout Standard
24203
24204 Subject / Title
24205 \end_inset 
24206 </cell>
24207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24208 \begin_inset Text
24209
24210 \layout Standard
24211
24212 Where to get / filename
24213 \end_inset 
24214 </cell>
24215 </row>
24216 <row topline="true">
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24218 \begin_inset Text
24219
24220 \layout Standard
24221
24222 SDCC Compiler User Guide
24223 \end_inset 
24224 </cell>
24225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24226 \begin_inset Text
24227
24228 \layout Standard
24229
24230 You're reading it right now
24231 \end_inset 
24232 </cell>
24233 </row>
24234 <row topline="true">
24235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24236 \begin_inset Text
24237
24238 \layout Standard
24239
24240 Changelog of SDCC
24241 \end_inset 
24242 </cell>
24243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24244 \begin_inset Text
24245
24246 \layout Standard
24247
24248 sdcc/Changelog
24249 \end_inset 
24250 </cell>
24251 </row>
24252 <row topline="true">
24253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24254 \begin_inset Text
24255
24256 \layout Standard
24257
24258 ASXXXX
24259 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24260
24261 \end_inset 
24262
24263
24264 \begin_inset LatexCommand \index{Assembler documentation}
24265
24266 \end_inset 
24267
24268  Assemblers and ASLINK
24269 \begin_inset LatexCommand \index{aslink}
24270
24271 \end_inset 
24272
24273
24274 \begin_inset LatexCommand \index{Linker documentation}
24275
24276 \end_inset 
24277
24278  Relocating Linker
24279 \end_inset 
24280 </cell>
24281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24282 \begin_inset Text
24283
24284 \layout Standard
24285
24286 sdcc/as/doc/asxhtm.html
24287 \end_inset 
24288 </cell>
24289 </row>
24290 <row topline="true">
24291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24292 \begin_inset Text
24293
24294 \layout Standard
24295
24296 SDCC regression test
24297 \begin_inset LatexCommand \index{Regression test}
24298
24299 \end_inset 
24300
24301
24302 \end_inset 
24303 </cell>
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24305 \begin_inset Text
24306
24307 \layout Standard
24308
24309 sdcc/doc/test_suite_spec.pdf
24310 \end_inset 
24311 </cell>
24312 </row>
24313 <row topline="true">
24314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24315 \begin_inset Text
24316
24317 \layout Standard
24318
24319 Various notes
24320 \end_inset 
24321 </cell>
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24323 \begin_inset Text
24324
24325 \layout Standard
24326
24327 sdcc/doc/*
24328 \end_inset 
24329 </cell>
24330 </row>
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24333 \begin_inset Text
24334
24335 \layout Standard
24336
24337 Notes on debugging with SDCDB
24338 \begin_inset LatexCommand \index{SDCDB (debugger)}
24339
24340 \end_inset 
24341
24342
24343 \end_inset 
24344 </cell>
24345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24346 \begin_inset Text
24347
24348 \layout Standard
24349
24350 sdcc/debugger/README
24351 \end_inset 
24352 </cell>
24353 </row>
24354 <row topline="true">
24355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24356 \begin_inset Text
24357
24358 \layout Standard
24359
24360 Software simulator for microcontrollers
24361 \end_inset 
24362 </cell>
24363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24364 \begin_inset Text
24365
24366 \layout Standard
24367
24368
24369 \family roman 
24370 \series medium 
24371 \shape up 
24372 \size normal 
24373 \emph off 
24374 \bar no 
24375 \noun off 
24376 \color none
24377 sdcc/sim/ucsim/doc
24378 \family default 
24379 \series default 
24380 \shape default 
24381 \size default 
24382 \emph default 
24383 \bar default 
24384 \noun default 
24385 \color default
24386 /index.html
24387 \end_inset 
24388 </cell>
24389 </row>
24390 <row topline="true">
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24392 \begin_inset Text
24393
24394 \layout Standard
24395
24396 Temporary notes on the pic16
24397 \begin_inset LatexCommand \index{PIC16}
24398
24399 \end_inset 
24400
24401  port
24402 \end_inset 
24403 </cell>
24404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24405 \begin_inset Text
24406
24407 \layout Standard
24408
24409 sdcc/src/pic16/NOTES
24410 \end_inset 
24411 </cell>
24412 </row>
24413 <row topline="true" bottomline="true">
24414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24415 \begin_inset Text
24416
24417 \layout Standard
24418
24419 SDCC internal documentation (debugging file format)
24420 \end_inset 
24421 </cell>
24422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24423 \begin_inset Text
24424
24425 \layout Standard
24426
24427 sdcc/doc/
24428 \family roman 
24429 \series medium 
24430 \shape up 
24431 \size normal 
24432 \emph off 
24433 \bar no 
24434 \noun off 
24435 \color none
24436 cdbfileformat.pd
24437 \family default 
24438 \series default 
24439 \shape default 
24440 \size default 
24441 \emph default 
24442 \bar default 
24443 \noun default 
24444 \color default
24445 f
24446 \end_inset 
24447 </cell>
24448 </row>
24449 </lyxtabular>
24450
24451 \end_inset 
24452
24453
24454 \newline 
24455
24456 \layout Section
24457
24458 Related open source tools
24459 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24460
24461 \end_inset 
24462
24463
24464 \begin_inset LatexCommand \index{Related tools}
24465
24466 \end_inset 
24467
24468
24469 \layout Standard
24470 \align left 
24471
24472 \begin_inset  Tabular
24473 <lyxtabular version="3" rows="14" columns="3">
24474 <features>
24475 <column alignment="left" valignment="top" leftline="true" width="0pt">
24476 <column alignment="block" valignment="top" leftline="true" width="30line%">
24477 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24478 <row topline="true" bottomline="true">
24479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24480 \begin_inset Text
24481
24482 \layout Standard
24483
24484 Name
24485 \end_inset 
24486 </cell>
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24488 \begin_inset Text
24489
24490 \layout Standard
24491
24492 Purpose
24493 \end_inset 
24494 </cell>
24495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24496 \begin_inset Text
24497
24498 \layout Standard
24499
24500 Where to get
24501 \end_inset 
24502 </cell>
24503 </row>
24504 <row topline="true">
24505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24506 \begin_inset Text
24507
24508 \layout Standard
24509
24510 gpsim
24511 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24512
24513 \end_inset 
24514
24515
24516 \end_inset 
24517 </cell>
24518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24519 \begin_inset Text
24520
24521 \layout Standard
24522
24523 PIC simulator
24524 \end_inset 
24525 </cell>
24526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24527 \begin_inset Text
24528
24529 \layout Standard
24530
24531
24532 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24533
24534 \end_inset 
24535
24536
24537 \end_inset 
24538 </cell>
24539 </row>
24540 <row topline="true">
24541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24542 \begin_inset Text
24543
24544 \layout Standard
24545
24546 gputils
24547 \begin_inset LatexCommand \index{gputils (pic tools)}
24548
24549 \end_inset 
24550
24551
24552 \end_inset 
24553 </cell>
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24555 \begin_inset Text
24556
24557 \layout Standard
24558
24559 GNU PIC utilities
24560 \end_inset 
24561 </cell>
24562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24563 \begin_inset Text
24564
24565 \layout Standard
24566
24567
24568 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24569
24570 \end_inset 
24571
24572
24573 \end_inset 
24574 </cell>
24575 </row>
24576 <row topline="true">
24577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24578 \begin_inset Text
24579
24580 \layout Standard
24581
24582 flP5
24583 \end_inset 
24584 </cell>
24585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24586 \begin_inset Text
24587
24588 \layout Standard
24589
24590 PIC programmer
24591 \end_inset 
24592 </cell>
24593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24594 \begin_inset Text
24595
24596 \layout Standard
24597
24598
24599 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24600
24601 \end_inset 
24602
24603
24604 \end_inset 
24605 </cell>
24606 </row>
24607 <row topline="true">
24608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24609 \begin_inset Text
24610
24611 \layout Standard
24612
24613 ec2drv/newcdb
24614 \end_inset 
24615 </cell>
24616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24617 \begin_inset Text
24618
24619 \layout Standard
24620
24621 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24622  (Unix only)
24623 \end_inset 
24624 </cell>
24625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24626 \begin_inset Text
24627
24628 \layout Standard
24629
24630
24631 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24632
24633 \end_inset 
24634
24635
24636 \end_inset 
24637 </cell>
24638 </row>
24639 <row topline="true">
24640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24641 \begin_inset Text
24642
24643 \layout Standard
24644
24645 indent
24646 \begin_inset LatexCommand \index{indent (source formatting tool)}
24647
24648 \end_inset 
24649
24650
24651 \end_inset 
24652 </cell>
24653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24654 \begin_inset Text
24655
24656 \layout Standard
24657
24658 Formats C source - Master of the white spaces
24659 \end_inset 
24660 </cell>
24661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24662 \begin_inset Text
24663
24664 \layout Standard
24665
24666
24667 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24668
24669 \end_inset 
24670
24671
24672 \end_inset 
24673 </cell>
24674 </row>
24675 <row topline="true">
24676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24677 \begin_inset Text
24678
24679 \layout Standard
24680
24681 srecord
24682 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24683
24684 \end_inset 
24685
24686
24687 \end_inset 
24688 </cell>
24689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24690 \begin_inset Text
24691
24692 \layout Standard
24693
24694 Object file conversion, checksumming, ...
24695 \end_inset 
24696 </cell>
24697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24698 \begin_inset Text
24699
24700 \layout Standard
24701
24702
24703 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24704
24705 \end_inset 
24706
24707
24708 \end_inset 
24709 </cell>
24710 </row>
24711 <row topline="true">
24712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24713 \begin_inset Text
24714
24715 \layout Standard
24716
24717 objdump
24718 \begin_inset LatexCommand \index{objdump (tool)}
24719
24720 \end_inset 
24721
24722
24723 \end_inset 
24724 </cell>
24725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24726 \begin_inset Text
24727
24728 \layout Standard
24729
24730 Object file conversion, ...
24731 \end_inset 
24732 </cell>
24733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24734 \begin_inset Text
24735
24736 \layout Standard
24737
24738 Part of binutils (should be there anyway)
24739 \end_inset 
24740 </cell>
24741 </row>
24742 <row topline="true">
24743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24744 \begin_inset Text
24745
24746 \layout Standard
24747
24748 cmon51
24749 \end_inset 
24750 </cell>
24751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24752 \begin_inset Text
24753
24754 \layout Standard
24755
24756 8051 monitor (hex up-/download, single step, disassemble)
24757 \end_inset 
24758 </cell>
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24760 \begin_inset Text
24761
24762 \layout Standard
24763
24764
24765 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24766
24767 \end_inset 
24768
24769
24770 \end_inset 
24771 </cell>
24772 </row>
24773 <row topline="true">
24774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24775 \begin_inset Text
24776
24777 \layout Standard
24778
24779 doxygen
24780 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24781
24782 \end_inset 
24783
24784
24785 \end_inset 
24786 </cell>
24787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24788 \begin_inset Text
24789
24790 \layout Standard
24791
24792 Source code documentation system
24793 \end_inset 
24794 </cell>
24795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24796 \begin_inset Text
24797
24798 \layout Standard
24799
24800
24801 \begin_inset LatexCommand \url{http://www.doxygen.org}
24802
24803 \end_inset 
24804
24805
24806 \end_inset 
24807 </cell>
24808 </row>
24809 <row topline="true">
24810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24811 \begin_inset Text
24812
24813 \layout Standard
24814
24815 kdevelop
24816 \end_inset 
24817 </cell>
24818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24819 \begin_inset Text
24820
24821 \layout Standard
24822
24823 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24824 \end_inset 
24825 </cell>
24826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24827 \begin_inset Text
24828
24829 \layout Standard
24830
24831
24832 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24833
24834 \end_inset 
24835
24836
24837 \end_inset 
24838 </cell>
24839 </row>
24840 <row topline="true">
24841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24842 \begin_inset Text
24843
24844 \layout Standard
24845
24846 paulmon
24847 \end_inset 
24848 </cell>
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24850 \begin_inset Text
24851
24852 \layout Standard
24853
24854 8051 monitor (hex up-/download, single step, disassemble)
24855 \end_inset 
24856 </cell>
24857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24858 \begin_inset Text
24859
24860 \layout Standard
24861
24862
24863 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24864
24865 \end_inset 
24866
24867
24868 \end_inset 
24869 </cell>
24870 </row>
24871 <row topline="true">
24872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24873 \begin_inset Text
24874
24875 \layout Standard
24876
24877 splint
24878 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24879
24880 \end_inset 
24881
24882
24883 \end_inset 
24884 </cell>
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24886 \begin_inset Text
24887
24888 \layout Standard
24889
24890 Statically checks c sources (see 
24891 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24892
24893 \end_inset 
24894
24895 )
24896 \end_inset 
24897 </cell>
24898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24899 \begin_inset Text
24900
24901 \layout Standard
24902
24903
24904 \begin_inset LatexCommand \url{http://www.splint.org}
24905
24906 \end_inset 
24907
24908
24909 \end_inset 
24910 </cell>
24911 </row>
24912 <row topline="true" bottomline="true">
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24914 \begin_inset Text
24915
24916 \layout Standard
24917
24918 ddd
24919 \begin_inset LatexCommand \index{DDD (debugger)}
24920
24921 \end_inset 
24922
24923
24924 \end_inset 
24925 </cell>
24926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24927 \begin_inset Text
24928
24929 \layout Standard
24930
24931 Debugger, serves nicely as GUI to SDCDB
24932 \begin_inset LatexCommand \index{SDCDB (debugger)}
24933
24934 \end_inset 
24935
24936  (Unix only)
24937 \end_inset 
24938 </cell>
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24940 \begin_inset Text
24941
24942 \layout Standard
24943
24944
24945 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
24946
24947 \end_inset 
24948
24949
24950 \end_inset 
24951 </cell>
24952 </row>
24953 </lyxtabular>
24954
24955 \end_inset 
24956
24957
24958 \newline 
24959
24960 \layout Section
24961
24962 Related documentation / recommended reading
24963 \layout Standard
24964 \align left 
24965
24966 \begin_inset  Tabular
24967 <lyxtabular version="3" rows="7" columns="3">
24968 <features>
24969 <column alignment="left" valignment="top" leftline="true" width="0pt">
24970 <column alignment="center" valignment="top" leftline="true" width="0">
24971 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24972 <row topline="true" bottomline="true">
24973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24974 \begin_inset Text
24975
24976 \layout Standard
24977
24978 Name
24979 \end_inset 
24980 </cell>
24981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24982 \begin_inset Text
24983
24984 \layout Standard
24985
24986 Subject / Title
24987 \end_inset 
24988 </cell>
24989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24990 \begin_inset Text
24991
24992 \layout Standard
24993
24994 Where to get
24995 \end_inset 
24996 </cell>
24997 </row>
24998 <row topline="true">
24999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25000 \begin_inset Text
25001
25002 \layout Standard
25003
25004
25005 \family roman 
25006 \series medium 
25007 \shape up 
25008 \size normal 
25009 \emph off 
25010 \bar no 
25011 \noun off 
25012 \color none
25013 c-refcard.pdf
25014 \end_inset 
25015 </cell>
25016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25017 \begin_inset Text
25018
25019 \layout Standard
25020
25021 C Reference Card
25022 \begin_inset LatexCommand \index{C Reference card}
25023
25024 \end_inset 
25025
25026 , 2 pages
25027 \end_inset 
25028 </cell>
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25030 \begin_inset Text
25031
25032 \layout Standard
25033
25034
25035 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25036
25037 \end_inset 
25038
25039
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 c-faq
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 C-FAQ
25058 \begin_inset LatexCommand \index{C FAQ}
25059
25060 \end_inset 
25061
25062
25063 \end_inset 
25064 </cell>
25065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25066 \begin_inset Text
25067
25068 \layout Standard
25069
25070
25071 \begin_inset LatexCommand \url{http://www.c-faq.com}
25072
25073 \end_inset 
25074
25075
25076 \end_inset 
25077 </cell>
25078 </row>
25079 <row topline="true">
25080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25081 \begin_inset Text
25082
25083 \layout Standard
25084
25085 ISO/IEC 9899:TC2
25086 \end_inset 
25087 </cell>
25088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25089 \begin_inset Text
25090
25091 \layout Standard
25092
25093
25094 \begin_inset Quotes sld
25095 \end_inset 
25096
25097 C-Standard
25098 \begin_inset Quotes srd
25099 \end_inset 
25100
25101
25102 \end_inset 
25103 </cell>
25104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25105 \begin_inset Text
25106
25107 \layout Standard
25108
25109
25110 \size footnotesize 
25111
25112 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25113
25114 \end_inset 
25115
25116
25117 \end_inset 
25118 </cell>
25119 </row>
25120 <row topline="true">
25121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25122 \begin_inset Text
25123
25124 \layout Standard
25125
25126 ISO/IEC DTR 18037
25127 \end_inset 
25128 </cell>
25129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25130 \begin_inset Text
25131
25132 \layout Standard
25133
25134
25135 \begin_inset Quotes sld
25136 \end_inset 
25137
25138 Extensions for Embedded C
25139 \begin_inset Quotes srd
25140 \end_inset 
25141
25142
25143 \end_inset 
25144 </cell>
25145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25146 \begin_inset Text
25147
25148 \layout Standard
25149
25150
25151 \size footnotesize 
25152
25153 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25154
25155 \end_inset 
25156
25157
25158 \end_inset 
25159 </cell>
25160 </row>
25161 <row topline="true">
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25163 \begin_inset Text
25164
25165 \layout Standard
25166
25167 \end_inset 
25168 </cell>
25169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25170 \begin_inset Text
25171
25172 \layout Standard
25173
25174 Latest datasheet of target CPU
25175 \end_inset 
25176 </cell>
25177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25178 \begin_inset Text
25179
25180 \layout Standard
25181
25182 vendor
25183 \end_inset 
25184 </cell>
25185 </row>
25186 <row topline="true" bottomline="true">
25187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25188 \begin_inset Text
25189
25190 \layout Standard
25191
25192 \end_inset 
25193 </cell>
25194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25195 \begin_inset Text
25196
25197 \layout Standard
25198
25199 Revision history of datasheet
25200 \end_inset 
25201 </cell>
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25203 \begin_inset Text
25204
25205 \layout Standard
25206
25207 vendor
25208 \end_inset 
25209 </cell>
25210 </row>
25211 </lyxtabular>
25212
25213 \end_inset 
25214
25215
25216 \newline 
25217
25218 \layout Section
25219
25220 Application notes specifically for SDCC
25221 \layout Standard
25222
25223 SDCC makes no claims about the completeness of this list and about up-to-datenes
25224 s or correctness of the application notes
25225 \begin_inset LatexCommand \index{Application notes}
25226
25227 \end_inset 
25228
25229 .
25230 \layout Standard
25231 \align left 
25232
25233 \size footnotesize 
25234
25235 \begin_inset  Tabular
25236 <lyxtabular version="3" rows="7" columns="3">
25237 <features>
25238 <column alignment="block" valignment="top" leftline="true" width="17col%">
25239 <column alignment="block" valignment="top" leftline="true" width="27col%">
25240 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25241 <row topline="true" bottomline="true">
25242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25243 \begin_inset Text
25244
25245 \layout Standard
25246
25247
25248 \size footnotesize 
25249 Vendor
25250 \end_inset 
25251 </cell>
25252 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25253 \begin_inset Text
25254
25255 \layout Standard
25256
25257
25258 \size footnotesize 
25259 Subject / Title
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
25268 \size footnotesize 
25269 Where to get
25270 \end_inset 
25271 </cell>
25272 </row>
25273 <row topline="true">
25274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25275 \begin_inset Text
25276
25277 \layout Standard
25278
25279
25280 \size footnotesize 
25281 Maxim / Dallas
25282 \end_inset 
25283 </cell>
25284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25285 \begin_inset Text
25286
25287 \layout Standard
25288
25289
25290 \size footnotesize 
25291 Using the SDCC Compiler for the DS80C400
25292 \begin_inset LatexCommand \index{DS80C400}
25293
25294 \end_inset 
25295
25296
25297 \end_inset 
25298 </cell>
25299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25300 \begin_inset Text
25301
25302 \layout Standard
25303
25304
25305 \size footnotesize 
25306
25307 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25308
25309 \end_inset 
25310
25311
25312 \end_inset 
25313 </cell>
25314 </row>
25315 <row topline="true">
25316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25317 \begin_inset Text
25318
25319 \layout Standard
25320
25321
25322 \size footnotesize 
25323 Maxim / Dallas
25324 \end_inset 
25325 </cell>
25326 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25327 \begin_inset Text
25328
25329 \layout Standard
25330
25331
25332 \size footnotesize 
25333 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25334 \begin_inset LatexCommand \index{DS89C4x0}
25335
25336 \end_inset 
25337
25338  Family of Microcontrollers
25339 \end_inset 
25340 </cell>
25341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25342 \begin_inset Text
25343
25344 \layout Standard
25345
25346
25347 \size footnotesize 
25348
25349 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25350
25351 \end_inset 
25352
25353
25354 \end_inset 
25355 </cell>
25356 </row>
25357 <row topline="true">
25358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25359 \begin_inset Text
25360
25361 \layout Standard
25362
25363
25364 \size footnotesize 
25365 Silicon Laboratories / Cygnal
25366 \end_inset 
25367 </cell>
25368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25369 \begin_inset Text
25370
25371 \layout Standard
25372
25373
25374 \size footnotesize 
25375 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25376 \begin_inset LatexCommand \index{IDE}
25377
25378 \end_inset 
25379
25380
25381 \end_inset 
25382 </cell>
25383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25384 \begin_inset Text
25385
25386 \layout Standard
25387
25388
25389 \size footnotesize 
25390
25391 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
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
25406 \size footnotesize 
25407 Ramtron / Goal Semiconductor
25408 \end_inset 
25409 </cell>
25410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25411 \begin_inset Text
25412
25413 \layout Standard
25414
25415
25416 \size footnotesize 
25417 Interfacing SDCC to Syn and Textpad
25418 \end_inset 
25419 </cell>
25420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25421 \begin_inset Text
25422
25423 \layout Standard
25424
25425
25426 \size footnotesize 
25427
25428 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25429
25430 \end_inset 
25431
25432
25433 \end_inset 
25434 </cell>
25435 </row>
25436 <row topline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25438 \begin_inset Text
25439
25440 \layout Standard
25441
25442
25443 \size footnotesize 
25444 Ramtron / Goal Semiconductor
25445 \end_inset 
25446 </cell>
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25448 \begin_inset Text
25449
25450 \layout Standard
25451
25452
25453 \size footnotesize 
25454 Installing and Configuring SDCC and Crimson Editor 
25455 \end_inset 
25456 </cell>
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \layout Standard
25461
25462
25463 \size footnotesize 
25464
25465 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25466
25467 \end_inset 
25468
25469
25470 \end_inset 
25471 </cell>
25472 </row>
25473 <row topline="true" bottomline="true">
25474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25475 \begin_inset Text
25476
25477 \layout Standard
25478
25479
25480 \size footnotesize 
25481 Texas Instruments
25482 \end_inset 
25483 </cell>
25484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25485 \begin_inset Text
25486
25487 \layout Standard
25488
25489
25490 \size footnotesize 
25491 MSC12xx Programming with SDCC
25492 \end_inset 
25493 </cell>
25494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25495 \begin_inset Text
25496
25497 \layout Standard
25498
25499
25500 \size footnotesize 
25501
25502 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25503
25504 \end_inset 
25505
25506
25507 \end_inset 
25508 </cell>
25509 </row>
25510 </lyxtabular>
25511
25512 \end_inset 
25513
25514
25515 \layout Section
25516
25517 Some Questions
25518 \layout Standard
25519
25520 Some questions answered, some pointers given - it might be time to in turn
25521  ask 
25522 \emph on 
25523 you
25524 \emph default 
25525  some questions: 
25526 \layout Itemize
25527
25528 can you solve your project with the selected microcontroller? Would you
25529  find out early or rather late that your target is too small/slow/whatever?
25530  Can you switch to a slightly better device if it doesn't fit?
25531 \layout Itemize
25532
25533 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25534  and/or another programming language be more adequate? Would an operating
25535  system on the target device help?
25536 \layout Itemize
25537
25538 if you solved the problem, will the marketing department be happy?
25539 \layout Itemize
25540
25541 if the marketing department is happy, will customers be happy?
25542 \layout Itemize
25543
25544 if you're the project manager, marketing department and maybe even the customer
25545  in one person, have you tried to see the project from the outside?
25546 \layout Itemize
25547
25548 is the project done if you think it is done? Or is just that other interface/pro
25549 tocol/feature/configuration/option missing? How about website, manual(s),
25550  internationali(z|s)ation, packaging, labels, 2nd source for components,
25551  electromagnetic compatability/interference, documentation for production,
25552  production test software, update mechanism, patent issues?
25553 \layout Itemize
25554
25555 is your project adequately positioned in that magic triangle: fame, fortune,
25556  fun?
25557 \layout Standard
25558
25559 Maybe not all answers to these questions are known and some answers may
25560  even be 
25561 \emph on 
25562 no
25563 \emph default 
25564 , nevertheless knowing these questions may help you to avoid burnout
25565 \begin_inset Foot
25566 collapsed false
25567
25568 \layout Standard
25569
25570 burnout is bad for electronic devices, programmers and motorcycle tyres
25571 \end_inset 
25572
25573 .
25574  Chances are you didn't want to hear some of them...
25575 \layout Chapter
25576
25577 Support
25578 \begin_inset LatexCommand \index{Support}
25579
25580 \end_inset 
25581
25582
25583 \layout Standard
25584
25585 SDCC has grown to be a large project.
25586  The compiler alone (without the preprocessor, assembler and linker) is
25587  well over 150,000 lines of code (blank stripped).
25588  The open source nature of this project is a key to its continued growth
25589  and support.
25590  You gain the benefit and support of many active software developers and
25591  end users.
25592  Is SDCC perfect? No, that's why we need your help.
25593  The developers take pride in fixing reported bugs.
25594  You can help by reporting the bugs and helping other SDCC users.
25595  There are lots of ways to contribute, and we encourage you to take part
25596  in making SDCC a great software package.
25597  
25598 \layout Standard
25599
25600 The SDCC project is hosted on the SDCC sourceforge site at 
25601 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25602
25603 \end_inset 
25604
25605 .
25606  You'll find the complete set of mailing lists
25607 \begin_inset LatexCommand \index{Mailing list(s)}
25608
25609 \end_inset 
25610
25611 , forums, bug reporting system, patch submission
25612 \begin_inset LatexCommand \index{Patch submission}
25613
25614 \end_inset 
25615
25616  system, download
25617 \begin_inset LatexCommand \index{download}
25618
25619 \end_inset 
25620
25621  area and Subversion code repository
25622 \begin_inset LatexCommand \index{Subversion code repository}
25623
25624 \end_inset 
25625
25626  there.
25627 \layout Section
25628
25629 Reporting Bugs
25630 \begin_inset LatexCommand \index{Bug reporting}
25631
25632 \end_inset 
25633
25634
25635 \begin_inset LatexCommand \index{Reporting bugs}
25636
25637 \end_inset 
25638
25639
25640 \layout Standard
25641
25642 The recommended way of reporting bugs is using the infrastructure of the
25643  sourceforge site.
25644  You can follow the status of bug reports there and have an overview about
25645  the known bugs.
25646 \layout Standard
25647
25648 Bug reports are automatically forwarded to the developer mailing list and
25649  will be fixed ASAP.
25650  When reporting a bug, it is very useful to include a small test program
25651  (the smaller the better) which reproduces the problem.
25652  If you can isolate the problem by looking at the generated assembly code,
25653  this can be very helpful.
25654  Compiling your program with the -
25655 \begin_inset ERT
25656 status Collapsed
25657
25658 \layout Standard
25659
25660 \backslash 
25661 /
25662 \end_inset 
25663
25664 -dumpall
25665 \begin_inset LatexCommand \index{-\/-dumpall}
25666
25667 \end_inset 
25668
25669  option can sometimes be useful in locating optimization problems.
25670  When reporting a bug please make sure you:
25671 \layout Enumerate
25672
25673 Attach the code you are compiling with SDCC.
25674  
25675 \layout Enumerate
25676
25677 Specify the exact command you use to run SDCC, or attach your Makefile.
25678  
25679 \layout Enumerate
25680
25681 Specify the SDCC version (type "
25682 \family sans 
25683 \series bold 
25684 sdcc -v
25685 \family default 
25686 \series default 
25687 "), your platform, and operating system.
25688  
25689 \layout Enumerate
25690
25691 Provide an exact copy of any error message or incorrect output.
25692  
25693 \layout Enumerate
25694
25695 Put something meaningful in the subject of your message.
25696 \layout Standard
25697
25698 Please attempt to include these 5 important parts, as applicable, in all
25699  requests for support or when reporting any problems or bugs with SDCC.
25700  Though this will make your message lengthy, it will greatly improve your
25701  chance that SDCC users and developers will be able to help you.
25702  Some SDCC developers are frustrated by bug reports without code provided
25703  that they can use to reproduce and ultimately fix the problem, so please
25704  be sure to provide sample code if you are reporting a bug! 
25705 \layout Standard
25706
25707 Please have a short check that you are using a recent version of SDCC and
25708  the bug is not yet known.
25709  This is the link for reporting bugs: 
25710 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25711
25712 \end_inset 
25713
25714 .
25715  With SDCC on average having more than 200 downloads
25716 \begin_inset LatexCommand \index{download}
25717
25718 \end_inset 
25719
25720  on sourceforge per day
25721 \begin_inset Foot
25722 collapsed false
25723
25724 \layout Standard
25725
25726 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25727  between 2002 and 2005.
25728  This does not include other methods of distribution.
25729 \end_inset 
25730
25731  there must be some users.
25732  So it's not exactly easy to find a new bug.
25733  If you find one we need it: 
25734 \emph on 
25735 reporting bugs is good
25736 \emph default 
25737 .
25738 \layout Section
25739
25740 Requesting Features
25741 \begin_inset LatexCommand \label{sub:Requesting-Features}
25742
25743 \end_inset 
25744
25745
25746 \begin_inset LatexCommand \index{Feature request}
25747
25748 \end_inset 
25749
25750
25751 \begin_inset LatexCommand \index{Requesting features}
25752
25753 \end_inset 
25754
25755
25756 \layout Standard
25757
25758 Like bug reports feature requests are forwarded to the developer mailing
25759  list.
25760  This is the link for requesting features: 
25761 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25762
25763 \end_inset 
25764
25765 .
25766 \layout Section
25767
25768 Submitting patches
25769 \layout Standard
25770
25771 Like bug reports contributed patches are forwarded to the developer mailing
25772  list.
25773  This is the link for submitting patches
25774 \begin_inset LatexCommand \index{Patch submission}
25775
25776 \end_inset 
25777
25778
25779 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25780
25781 \end_inset 
25782
25783 .
25784 \layout Standard
25785
25786 You need to specify some parameters to the 
25787 \family typewriter 
25788 diff
25789 \family default 
25790  command for the patches to be useful.
25791  If you modified more than one file a patch created f.e.
25792  with 
25793 \family sans 
25794 \series bold 
25795
25796 \begin_inset Quotes sld
25797 \end_inset 
25798
25799 diff -Naur unmodified_directory modified_directory >my_changes.patch
25800 \begin_inset Quotes srd
25801 \end_inset 
25802
25803
25804 \family default 
25805 \series default 
25806  will be fine, otherwise 
25807 \family sans 
25808 \series bold 
25809
25810 \begin_inset Quotes sld
25811 \end_inset 
25812
25813 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25814 \begin_inset Quotes srd
25815 \end_inset 
25816
25817
25818 \series default 
25819  
25820 \family default 
25821 will do.
25822 \layout Section
25823
25824 Getting Help
25825 \layout Standard
25826
25827 These links should take you directly to the 
25828 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25829
25830 \end_inset 
25831
25832
25833 \begin_inset Foot
25834 collapsed false
25835
25836 \layout Standard
25837
25838 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25839  automated messages (mid 2003)
25840 \end_inset 
25841
25842  and the 
25843 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25844
25845 \end_inset 
25846
25847 , lists
25848 \begin_inset LatexCommand \index{Mailing list(s)}
25849
25850 \end_inset 
25851
25852  and forums are archived and searchable so if you are lucky someone already
25853  had a similar problem.
25854  While mails to the lists themselves are delivered promptly their web front
25855  end on sourceforge sometimes shows a severe time lag (up to several weeks),
25856  if you're seriously using SDCC please consider subscribing to the lists.
25857 \layout Section
25858
25859 ChangeLog
25860 \layout Standard
25861
25862 You can follow the status of the Subversion version
25863 \begin_inset LatexCommand \index{version}
25864
25865 \end_inset 
25866
25867  of SDCC by watching the Changelog
25868 \begin_inset LatexCommand \index{Changelog}
25869
25870 \end_inset 
25871
25872  in the Subversion repository
25873 \size footnotesize 
25874  
25875 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25876
25877 \end_inset 
25878
25879 .
25880 \layout Section
25881
25882 Subversion Source Code Repository
25883 \layout Standard
25884
25885 The output of 
25886 \family sans 
25887 \series bold 
25888 sdcc --version
25889 \family default 
25890 \series default 
25891  or the filenames of the snapshot versions of SDCC include date and its
25892  Subversion
25893 \begin_inset LatexCommand \index{Subversion code repository}
25894
25895 \end_inset 
25896
25897  number.
25898  Subversion allows to download the source of recent or previous versions
25899  
25900 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25901
25902 \end_inset 
25903
25904  (by number or by date).
25905  An on-line source code browser and detailled instructions are also available
25906  there.
25907  SDCC versions starting from 1999 up to now are available (currently the
25908  versions prior to the conversion from cvs
25909 \begin_inset LatexCommand \index{cvs|see{Subversion}}
25910
25911 \end_inset 
25912
25913  to Subversion (April 2006) are either by accessible by Subversion or by
25914  cvs).
25915 \layout Section
25916
25917 Release policy
25918 \begin_inset LatexCommand \index{Release policy}
25919
25920 \end_inset 
25921
25922
25923 \layout Standard
25924
25925 Historically there often were long delays between official releases and
25926  the sourceforge download area tends to get not updated at all.
25927  Excuses in the past might have referred to problems with live range analysis,
25928  but as this was fixed a while ago, the current problem is that another
25929  excuse has to be found.
25930  Kidding aside, we have to get better there! On the other hand there are
25931  daily snapshots available at 
25932 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
25933
25934 \end_inset 
25935
25936 , and you can always build the very last version (hopefully with many bugs
25937  fixed, and features added) from the source code available at 
25938 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
25939
25940 \end_inset 
25941
25942 .
25943  A release wiki
25944 \begin_inset LatexCommand \index{wiki}
25945
25946 \end_inset 
25947
25948
25949 \begin_inset LatexCommand \index{Release wiki}
25950
25951 \end_inset 
25952
25953  at 
25954 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
25955
25956 \end_inset 
25957
25958  also holds some information about past and future releases.
25959 \layout Section
25960
25961 Examples
25962 \begin_inset LatexCommand \index{Examples}
25963
25964 \end_inset 
25965
25966
25967 \layout Standard
25968
25969 You'll find some small examples in the directory 
25970 \emph on 
25971 sdcc/device/examples/.
25972  
25973 \emph default 
25974 More examples and libraries are available at
25975 \emph on 
25976  The SDCC Open Knowledge Resource 
25977 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
25978
25979 \end_inset 
25980
25981  
25982 \emph default 
25983 web site or at 
25984 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
25985
25986 \end_inset 
25987
25988 .
25989 \layout Comment
25990
25991 I did insert a reference to Paul's web site here although it seems rather
25992  dedicated to a specific 8032 board (I think it's okay because it f.e.
25993  shows LCD/Harddisc interface and has a free 8051 monitor.
25994  Independent 8032 board vendors face hard competition of heavily subsidized
25995  development boards anyway).
25996 \layout Comment
25997
25998 Maybe we should include some links to real world applications.
25999  Preferably pointer to pointers (one for each architecture) so this stays
26000  manageable here?
26001 \layout Section
26002
26003 Quality control
26004 \begin_inset LatexCommand \label{sec:Quality-control}
26005
26006 \end_inset 
26007
26008
26009 \begin_inset LatexCommand \index{Quality control}
26010
26011 \end_inset 
26012
26013
26014 \layout Standard
26015
26016 The compiler is passed through nightly compile and build checks.
26017  The so called 
26018 \shape italic 
26019 regression tests
26020 \shape default 
26021
26022 \begin_inset LatexCommand \index{Regression test}
26023
26024 \end_inset 
26025
26026  check that SDCC itself compiles flawlessly on several host platforms (i386,
26027  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26028  the quality of the code generated by SDCC by running the code for several
26029  target platforms through simulators.
26030  The regression test suite comprises more than 100 files which expand to
26031  more than 500 test cases which include more than 4500 tests.
26032  The results of these tests are published daily on SDCC's snapshot page
26033  (click on the red or green symbols on the right side of 
26034 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26035
26036 \end_inset 
26037
26038 ).
26039 \layout Standard
26040
26041 There is a separate document 
26042 \shape italic 
26043 test_suite.pdf 
26044 \begin_inset LatexCommand \index{Test suite}
26045
26046 \end_inset 
26047
26048
26049 \shape default 
26050  
26051 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26052
26053 \end_inset 
26054
26055  about the regression test suite.
26056 \layout Standard
26057
26058 You'll find the test code in the directory 
26059 \shape italic 
26060 sdcc/support/regression
26061 \shape default 
26062 .
26063  You can run these tests manually by running 
26064 \family sans 
26065 make
26066 \family default 
26067  in this directory (or f.e.
26068  
26069 \family sans 
26070 \series bold 
26071
26072 \begin_inset Quotes sld
26073 \end_inset 
26074
26075 make test-mcs51
26076 \begin_inset Quotes srd
26077 \end_inset 
26078
26079
26080 \family default 
26081 \series default 
26082  if you don't want to run the complete tests).
26083  The test code might also be interesting if you want to look for examples
26084 \begin_inset LatexCommand \index{Examples}
26085
26086 \end_inset 
26087
26088  checking corner cases of SDCC or if you plan to submit patches
26089 \begin_inset LatexCommand \index{Patch submission}
26090
26091 \end_inset 
26092
26093 .
26094 \layout Standard
26095
26096 The 14bit pic port uses a different set of regression tests 
26097 \begin_inset LatexCommand \index{Regression test (PIC14)}
26098
26099 \end_inset 
26100
26101 , you'll find them in the directory 
26102 \shape italic 
26103 sdcc/src/regression
26104 \shape default 
26105 .
26106 \layout Section
26107
26108 Use of SDCC in Education
26109 \layout Standard
26110
26111 In short: 
26112 \emph on 
26113 highly
26114 \emph default 
26115  encouraged
26116 \begin_inset Foot
26117 collapsed false
26118
26119 \layout Standard
26120
26121 the phrase "use in education" might evoke the association "
26122 \emph on 
26123 only
26124 \emph default 
26125  fit for use in education".
26126  This connotation is not intended but nevertheless risked as the licensing
26127  of SDCC makes it difficult to offer educational discounts
26128 \end_inset 
26129
26130 .
26131  If your rationales are to:
26132 \layout Enumerate
26133
26134 give students a chance to understand the 
26135 \emph on 
26136 complete
26137 \emph default 
26138  steps of code generation
26139 \layout Enumerate
26140
26141 have a curriculum that can be extended for years.
26142  Then you could use an fpga board as target and your curriculum will seamlessly
26143  extend from logic synthesis (
26144 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26145
26146 \end_inset 
26147
26148
26149 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26150
26151 \end_inset 
26152
26153 ), over assembly programming, to C to FPGA compilers (
26154 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26155
26156 \end_inset 
26157
26158 ) and to C.
26159 \layout Enumerate
26160
26161 be able to insert excursions about skills like using a revision control
26162  system, submitting/applying patches, using a type-setting (as opposed to
26163  word-processing) engine LyX/LaTeX, using 
26164 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26165
26166 \end_inset 
26167
26168 , following some 
26169 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26170
26171 \end_inset 
26172
26173 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26174  Source Software, CPU simulation, compiler regression tests
26175 \begin_inset LatexCommand \index{Regression test}
26176
26177 \end_inset 
26178
26179 .
26180  
26181 \newline 
26182 And if there should be a shortage of ideas then you can always point students
26183  to the ever-growing feature request list 
26184 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26185
26186 \end_inset 
26187
26188 .
26189 \layout Enumerate
26190
26191 not tie students to a specific host platform and instead allow them to use
26192  a host platform of 
26193 \emph on 
26194 their
26195 \emph default 
26196  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26197  eventually 
26198 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26199
26200 \end_inset 
26201
26202 )
26203 \layout Enumerate
26204
26205 not encourage students to use illegal copies of educational software
26206 \layout Enumerate
26207
26208 be immune to licensing/availability/price changes of the chosen tool chain
26209 \layout Enumerate
26210
26211 be able to change to a new target platform without having to adopt a new
26212  tool chain
26213 \layout Enumerate
26214
26215 have complete control over and insight into the tool chain
26216 \layout Enumerate
26217
26218 make your students aware about the pros and cons of open source software
26219  development
26220 \layout Enumerate
26221
26222 give back to the public as you are probably at least partially publically
26223  funded
26224 \layout Enumerate
26225
26226 give students a chance to publically prove their skills and to possibly
26227  see a world wide impact
26228 \layout Standard
26229
26230 then SDCC is probably among the first choices.
26231  Well, probably SDCC might be the only choice.
26232 \layout Chapter
26233 \pagebreak_top 
26234 SDCC Technical Data
26235 \layout Section
26236
26237 Optimizations
26238 \begin_inset LatexCommand \index{Optimizations}
26239
26240 \end_inset 
26241
26242
26243 \layout Standard
26244
26245 SDCC performs a host of standard optimizations in addition to some MCU specific
26246  optimizations.
26247  
26248 \layout Subsection
26249
26250 Sub-expression Elimination
26251 \begin_inset LatexCommand \index{Subexpression elimination}
26252
26253 \end_inset 
26254
26255
26256 \layout Standard
26257
26258 The compiler does local and 
26259 \emph on 
26260 g
26261 \emph default 
26262 lobal 
26263 \emph on 
26264 c
26265 \emph default 
26266 ommon 
26267 \emph on 
26268 s
26269 \emph default 
26270 ubexpression 
26271 \emph on 
26272 e
26273 \emph default 
26274 limination, e.g.: 
26275 \layout Verse
26276
26277
26278 \family typewriter 
26279 i = x + y + 1; 
26280 \newline 
26281 j = x + y;
26282 \layout Standard
26283
26284 will be translated to
26285 \layout Verse
26286
26287
26288 \family typewriter 
26289 iTemp = x + y; 
26290 \newline 
26291 i = iTemp + 1; 
26292 \newline 
26293 j = iTemp;
26294 \layout Standard
26295
26296 Some subexpressions are not as obvious as the above example, e.g.:
26297 \layout Verse
26298
26299
26300 \family typewriter 
26301 a->b[i].c = 10; 
26302 \newline 
26303 a->b[i].d = 11;
26304 \layout Standard
26305
26306 In this case the address arithmetic a->b[i] will be computed only once;
26307  the equivalent code in C would be.
26308 \layout Verse
26309
26310
26311 \family typewriter 
26312 iTemp = a->b[i]; 
26313 \newline 
26314 iTemp.c = 10; 
26315 \newline 
26316 iTemp.d = 11;
26317 \layout Standard
26318
26319 The compiler will try to keep these temporary variables in registers.
26320 \layout Subsection
26321
26322 Dead-Code Elimination
26323 \begin_inset LatexCommand \index{Dead-code elimination}
26324
26325 \end_inset 
26326
26327
26328 \layout Verse
26329
26330
26331 \family typewriter 
26332 int global;
26333 \newline 
26334
26335 \newline 
26336 void f () { 
26337 \newline 
26338 \SpecialChar ~
26339 \SpecialChar ~
26340 int i; 
26341 \newline 
26342 \SpecialChar ~
26343 \SpecialChar ~
26344 i = 1; \SpecialChar ~
26345 \SpecialChar ~
26346 \SpecialChar ~
26347 \SpecialChar ~
26348 \SpecialChar ~
26349 /* dead store */ 
26350 \newline 
26351 \SpecialChar ~
26352 \SpecialChar ~
26353 global = 1;\SpecialChar ~
26354 /* dead store */ 
26355 \newline 
26356 \SpecialChar ~
26357 \SpecialChar ~
26358 global = 2; 
26359 \newline 
26360 \SpecialChar ~
26361 \SpecialChar ~
26362 return; 
26363 \newline 
26364 \SpecialChar ~
26365 \SpecialChar ~
26366 global = 3;\SpecialChar ~
26367 /* unreachable */ 
26368 \newline 
26369 }
26370 \layout Standard
26371
26372 will be changed to
26373 \layout Verse
26374
26375
26376 \family typewriter 
26377 int global;
26378 \newline 
26379
26380 \newline 
26381 void f () {
26382 \newline 
26383 \SpecialChar ~
26384 \SpecialChar ~
26385 global = 2; 
26386 \newline 
26387 }
26388 \layout Subsection
26389
26390 Copy-Propagation
26391 \begin_inset LatexCommand \index{Copy propagation}
26392
26393 \end_inset 
26394
26395
26396 \layout Verse
26397
26398
26399 \family typewriter 
26400 int f() { 
26401 \newline 
26402 \SpecialChar ~
26403 \SpecialChar ~
26404 int i, j; 
26405 \newline 
26406 \SpecialChar ~
26407 \SpecialChar ~
26408 i = 10; 
26409 \newline 
26410 \SpecialChar ~
26411 \SpecialChar ~
26412 j = i; 
26413 \newline 
26414 \SpecialChar ~
26415 \SpecialChar ~
26416 return j; 
26417 \newline 
26418 }
26419 \layout Standard
26420
26421 will be changed to 
26422 \layout Verse
26423
26424
26425 \family typewriter 
26426 int f() { 
26427 \newline 
26428 \SpecialChar ~
26429 \SpecialChar ~
26430 int i, j; 
26431 \newline 
26432 \SpecialChar ~
26433 \SpecialChar ~
26434 i = 10; 
26435 \newline 
26436 \SpecialChar ~
26437 \SpecialChar ~
26438 j = 10; 
26439 \newline 
26440 \SpecialChar ~
26441 \SpecialChar ~
26442 return 10; 
26443 \newline 
26444 }
26445 \layout Standard
26446
26447 Note: the dead stores created by this copy propagation will be eliminated
26448  by dead-code elimination.
26449 \layout Subsection
26450
26451 Loop Optimizations
26452 \begin_inset LatexCommand \index{Loop optimization}
26453
26454 \end_inset 
26455
26456
26457 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26458
26459 \end_inset 
26460
26461
26462 \layout Standard
26463
26464 Two types of loop optimizations are done by SDCC 
26465 \emph on 
26466 loop invariant
26467 \emph default 
26468  lifting and
26469 \emph on 
26470  strength reduction
26471 \emph default 
26472  of loop induction variables.
26473  In addition to the strength reduction the optimizer marks the induction
26474  variables and the register allocator tries to keep the induction variables
26475  in registers for the duration of the loop.
26476  Because of this preference of the register allocator
26477 \begin_inset LatexCommand \index{Register allocation}
26478
26479 \end_inset 
26480
26481 , loop induction optimization causes an increase in register pressure, which
26482  may cause unwanted spilling of other temporary variables into the stack
26483 \begin_inset LatexCommand \index{stack}
26484
26485 \end_inset 
26486
26487  / data space.
26488  The compiler will generate a warning message when it is forced to allocate
26489  extra space either on the stack or data space.
26490  If this extra space allocation is undesirable then induction optimization
26491  can be eliminated either for the entire source file (with -
26492 \begin_inset ERT
26493 status Collapsed
26494
26495 \layout Standard
26496
26497 \backslash 
26498 /
26499 \end_inset 
26500
26501 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26502 noinduction
26503 \begin_inset LatexCommand \index{\#pragma noinduction}
26504
26505 \end_inset 
26506
26507 .
26508 \newline 
26509
26510 \newline 
26511 Loop Invariant:
26512 \layout Verse
26513
26514
26515 \family typewriter 
26516 for (i = 0 ; i < 100 ; i ++) 
26517 \newline 
26518 \SpecialChar ~
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 \SpecialChar ~
26522 f += k + l;
26523 \layout Standard
26524
26525 changed to
26526 \layout Verse
26527
26528
26529 \family typewriter 
26530 itemp = k + l; 
26531 \newline 
26532 for (i = 0; i < 100; i++) 
26533 \newline 
26534 \SpecialChar ~
26535 \SpecialChar ~
26536 \SpecialChar ~
26537 \SpecialChar ~
26538 f += itemp;
26539 \layout Standard
26540
26541 As mentioned previously some loop invariants are not as apparent, all static
26542  address computations are also moved out of the loop.
26543 \newline 
26544
26545 \newline 
26546 Strength Reduction
26547 \begin_inset LatexCommand \index{Strength reduction}
26548
26549 \end_inset 
26550
26551 , this optimization substitutes an expression by a cheaper expression:
26552 \layout Verse
26553
26554
26555 \family typewriter 
26556 for (i=0;i < 100; i++)
26557 \newline 
26558 \SpecialChar ~
26559 \SpecialChar ~
26560 \SpecialChar ~
26561 \SpecialChar ~
26562 ar[i*5] = i*3;
26563 \layout Standard
26564
26565 changed to
26566 \layout Verse
26567
26568
26569 \family typewriter 
26570 itemp1 = 0; 
26571 \newline 
26572 itemp2 = 0; 
26573 \newline 
26574 for (i=0;i< 100;i++) { 
26575 \newline 
26576 \SpecialChar ~
26577 \SpecialChar ~
26578 \SpecialChar ~
26579 \SpecialChar ~
26580 ar[itemp1] = itemp2; 
26581 \newline 
26582 \SpecialChar ~
26583 \SpecialChar ~
26584 \SpecialChar ~
26585 \SpecialChar ~
26586 itemp1 += 5; 
26587 \newline 
26588 \SpecialChar ~
26589 \SpecialChar ~
26590 \SpecialChar ~
26591 \SpecialChar ~
26592 itemp2 += 3; 
26593 \newline 
26594 }
26595 \layout Standard
26596
26597 The more expensive multiplication
26598 \begin_inset LatexCommand \index{Multiplication}
26599
26600 \end_inset 
26601
26602  is changed to a less expensive addition.
26603 \layout Subsection
26604
26605 Loop Reversing
26606 \begin_inset LatexCommand \index{Loop reversing}
26607
26608 \end_inset 
26609
26610
26611 \layout Standard
26612
26613 This optimization is done to reduce the overhead of checking loop boundaries
26614  for every iteration.
26615  Some simple loops can be reversed and implemented using a 
26616 \begin_inset Quotes eld
26617 \end_inset 
26618
26619 decrement and jump if not zero
26620 \begin_inset Quotes erd
26621 \end_inset 
26622
26623  instruction.
26624  SDCC checks for the following criterion to determine if a loop is reversible
26625  (note: more sophisticated compilers use data-dependency analysis to make
26626  this determination, SDCC uses a more simple minded analysis).
26627 \layout Itemize
26628
26629 The 'for' loop is of the form 
26630 \newline 
26631
26632 \newline 
26633
26634 \family typewriter 
26635 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26636  += 1])
26637 \newline 
26638 \SpecialChar ~
26639 \SpecialChar ~
26640 \SpecialChar ~
26641 \SpecialChar ~
26642 <for body>
26643 \layout Itemize
26644
26645 The <for body> does not contain 
26646 \begin_inset Quotes eld
26647 \end_inset 
26648
26649 continue
26650 \begin_inset Quotes erd
26651 \end_inset 
26652
26653  or 'break
26654 \begin_inset Quotes erd
26655 \end_inset 
26656
26657 .
26658 \layout Itemize
26659
26660 All goto's are contained within the loop.
26661 \layout Itemize
26662
26663 No function calls within the loop.
26664 \layout Itemize
26665
26666 The loop control variable <sym> is not assigned any value within the loop
26667 \layout Itemize
26668
26669 The loop control variable does NOT participate in any arithmetic operation
26670  within the loop.
26671 \layout Itemize
26672
26673 There are NO switch statements in the loop.
26674 \layout Subsection
26675
26676 Algebraic Simplifications
26677 \layout Standard
26678
26679 SDCC does numerous algebraic simplifications, the following is a small sub-set
26680  of these optimizations.
26681 \layout Verse
26682
26683
26684 \family typewriter 
26685 i = j + 0;\SpecialChar ~
26686 \SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689  /* changed to: */\SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692 \SpecialChar ~
26693  i = j; 
26694 \newline 
26695 i /= 2;\SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699 \SpecialChar ~
26700 \SpecialChar ~
26701 \SpecialChar ~
26702  /* changed to: */\SpecialChar ~
26703 \SpecialChar ~
26704 \SpecialChar ~
26705 \SpecialChar ~
26706  i >>= 1; 
26707 \newline 
26708 i = j - j;\SpecialChar ~
26709 \SpecialChar ~
26710 \SpecialChar ~
26711 \SpecialChar ~
26712  /* changed to: */\SpecialChar ~
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716  i = 0; 
26717 \newline 
26718 i = j / 1;\SpecialChar ~
26719 \SpecialChar ~
26720 \SpecialChar ~
26721 \SpecialChar ~
26722  /* changed to: */\SpecialChar ~
26723 \SpecialChar ~
26724 \SpecialChar ~
26725 \SpecialChar ~
26726  i = j;
26727 \layout Standard
26728
26729 Note the subexpressions
26730 \begin_inset LatexCommand \index{Subexpression}
26731
26732 \end_inset 
26733
26734  given above are generally introduced by macro expansions or as a result
26735  of copy/constant propagation.
26736 \layout Subsection
26737
26738 'switch' Statements
26739 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26740
26741 \end_inset 
26742
26743
26744 \begin_inset LatexCommand \index{switch statement}
26745
26746 \end_inset 
26747
26748
26749 \layout Standard
26750
26751 SDCC can optimize switch statements to jump tables
26752 \begin_inset LatexCommand \index{jump tables}
26753
26754 \end_inset 
26755
26756 .
26757  It makes the decision based on an estimate of the generated code size.
26758  SDCC is quite liberal in the requirements for jump table generation: 
26759 \layout Itemize
26760
26761 The labels need not be in order, and the starting number need not be one
26762  or zero, the case labels are in numerical sequence or not too many case
26763  labels are missing.
26764 \begin_deeper 
26765 \layout Verse
26766
26767
26768 \family typewriter 
26769 switch(i) {\SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776 \SpecialChar ~
26777 \SpecialChar ~
26778 \SpecialChar ~
26779 \SpecialChar ~
26780 \SpecialChar ~
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 \SpecialChar ~
26784 \SpecialChar ~
26785 \SpecialChar ~
26786 \SpecialChar ~
26787 \SpecialChar ~
26788 \SpecialChar ~
26789 \SpecialChar ~
26790 \SpecialChar ~
26791 \SpecialChar ~
26792 \SpecialChar ~
26793 \SpecialChar ~
26794 \SpecialChar ~
26795 switch (i) { 
26796 \newline 
26797 \SpecialChar ~
26798 \SpecialChar ~
26799 \SpecialChar ~
26800 case 4: ...\SpecialChar ~
26801 \SpecialChar ~
26802 \SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 \SpecialChar ~
26806 \SpecialChar ~
26807 \SpecialChar ~
26808 \SpecialChar ~
26809 \SpecialChar ~
26810 \SpecialChar ~
26811 \SpecialChar ~
26812 \SpecialChar ~
26813 \SpecialChar ~
26814 \SpecialChar ~
26815 \SpecialChar ~
26816 \SpecialChar ~
26817 \SpecialChar ~
26818 \SpecialChar ~
26819 \SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 \SpecialChar ~
26823 \SpecialChar ~
26824 \SpecialChar ~
26825 \SpecialChar ~
26826 case 0: ...
26827  
26828 \newline 
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832 case 5: ...\SpecialChar ~
26833 \SpecialChar ~
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840 \SpecialChar ~
26841 \SpecialChar ~
26842 \SpecialChar ~
26843 \SpecialChar ~
26844 \SpecialChar ~
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 \SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850 \SpecialChar ~
26851 \SpecialChar ~
26852 \SpecialChar ~
26853 \SpecialChar ~
26854 \SpecialChar ~
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 case 1: ...
26859  
26860 \newline 
26861 \SpecialChar ~
26862 \SpecialChar ~
26863 \SpecialChar ~
26864 case 3: ...\SpecialChar ~
26865 \SpecialChar ~
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 \SpecialChar ~
26869 \SpecialChar ~
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 \SpecialChar ~
26873 \SpecialChar ~
26874 \SpecialChar ~
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878 \SpecialChar ~
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 \SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890
26891 \newline 
26892 \SpecialChar ~
26893 \SpecialChar ~
26894 \SpecialChar ~
26895 case 6: ...\SpecialChar ~
26896 \SpecialChar ~
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 \SpecialChar ~
26906 \SpecialChar ~
26907 \SpecialChar ~
26908 \SpecialChar ~
26909 \SpecialChar ~
26910 \SpecialChar ~
26911 \SpecialChar ~
26912 \SpecialChar ~
26913 \SpecialChar ~
26914 \SpecialChar ~
26915 \SpecialChar ~
26916 \SpecialChar ~
26917 \SpecialChar ~
26918 \SpecialChar ~
26919 \SpecialChar ~
26920 \SpecialChar ~
26921 case 3: ...
26922  
26923 \newline 
26924 \SpecialChar ~
26925 \SpecialChar ~
26926 \SpecialChar ~
26927 case 7: ...\SpecialChar ~
26928 \SpecialChar ~
26929 \SpecialChar ~
26930 \SpecialChar ~
26931 \SpecialChar ~
26932 \SpecialChar ~
26933 \SpecialChar ~
26934 \SpecialChar ~
26935 \SpecialChar ~
26936 \SpecialChar ~
26937 \SpecialChar ~
26938 \SpecialChar ~
26939 \SpecialChar ~
26940 \SpecialChar ~
26941 \SpecialChar ~
26942 \SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 \SpecialChar ~
26948 \SpecialChar ~
26949 \SpecialChar ~
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953 case 4: ...
26954  
26955 \newline 
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 case 8: ...\SpecialChar ~
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 \SpecialChar ~
26963 \SpecialChar ~
26964 \SpecialChar ~
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 \SpecialChar ~
26968 \SpecialChar ~
26969 \SpecialChar ~
26970 \SpecialChar ~
26971 \SpecialChar ~
26972 \SpecialChar ~
26973 \SpecialChar ~
26974 \SpecialChar ~
26975 \SpecialChar ~
26976 \SpecialChar ~
26977 \SpecialChar ~
26978 \SpecialChar ~
26979 \SpecialChar ~
26980 \SpecialChar ~
26981 \SpecialChar ~
26982 \SpecialChar ~
26983 \SpecialChar ~
26984 \SpecialChar ~
26985 case 5: ...
26986  
26987 \newline 
26988 \SpecialChar ~
26989 \SpecialChar ~
26990 \SpecialChar ~
26991 case 9: ...\SpecialChar ~
26992 \SpecialChar ~
26993 \SpecialChar ~
26994 \SpecialChar ~
26995 \SpecialChar ~
26996 \SpecialChar ~
26997 \SpecialChar ~
26998 \SpecialChar ~
26999 \SpecialChar ~
27000 \SpecialChar ~
27001 \SpecialChar ~
27002 \SpecialChar ~
27003 \SpecialChar ~
27004 \SpecialChar ~
27005 \SpecialChar ~
27006 \SpecialChar ~
27007 \SpecialChar ~
27008 \SpecialChar ~
27009 \SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 \SpecialChar ~
27013 \SpecialChar ~
27014 \SpecialChar ~
27015 \SpecialChar ~
27016 \SpecialChar ~
27017 case 6: ...
27018  
27019 \newline 
27020 \SpecialChar ~
27021 \SpecialChar ~
27022 \SpecialChar ~
27023 case 10: ...\SpecialChar ~
27024 \SpecialChar ~
27025 \SpecialChar ~
27026 \SpecialChar ~
27027 \SpecialChar ~
27028 \SpecialChar ~
27029 \SpecialChar ~
27030 \SpecialChar ~
27031 \SpecialChar ~
27032 \SpecialChar ~
27033 \SpecialChar ~
27034 \SpecialChar ~
27035 \SpecialChar ~
27036 \SpecialChar ~
27037 \SpecialChar ~
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 \SpecialChar ~
27041 \SpecialChar ~
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 \SpecialChar ~
27046 \SpecialChar ~
27047 \SpecialChar ~
27048 case 7: ...
27049  
27050 \newline 
27051 \SpecialChar ~
27052 \SpecialChar ~
27053 \SpecialChar ~
27054 case 11: ...\SpecialChar ~
27055 \SpecialChar ~
27056 \SpecialChar ~
27057 \SpecialChar ~
27058 \SpecialChar ~
27059 \SpecialChar ~
27060 \SpecialChar ~
27061 \SpecialChar ~
27062 \SpecialChar ~
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 \SpecialChar ~
27066 \SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069 \SpecialChar ~
27070 \SpecialChar ~
27071 \SpecialChar ~
27072 \SpecialChar ~
27073 \SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076 \SpecialChar ~
27077 \SpecialChar ~
27078 \SpecialChar ~
27079 case 8: ...
27080  
27081 \newline 
27082 }\SpecialChar ~
27083 \SpecialChar ~
27084 \SpecialChar ~
27085 \SpecialChar ~
27086 \SpecialChar ~
27087 \SpecialChar ~
27088 \SpecialChar ~
27089 \SpecialChar ~
27090 \SpecialChar ~
27091 \SpecialChar ~
27092 \SpecialChar ~
27093 \SpecialChar ~
27094 \SpecialChar ~
27095 \SpecialChar ~
27096 \SpecialChar ~
27097 \SpecialChar ~
27098 \SpecialChar ~
27099 \SpecialChar ~
27100 \SpecialChar ~
27101 \SpecialChar ~
27102 \SpecialChar ~
27103 \SpecialChar ~
27104 \SpecialChar ~
27105 \SpecialChar ~
27106 \SpecialChar ~
27107 \SpecialChar ~
27108 \SpecialChar ~
27109 \SpecialChar ~
27110 \SpecialChar ~
27111 \SpecialChar ~
27112 \SpecialChar ~
27113 \SpecialChar ~
27114 \SpecialChar ~
27115 \SpecialChar ~
27116 \SpecialChar ~
27117 \SpecialChar ~
27118 }
27119 \layout Standard
27120
27121 Both the above switch statements will be implemented using a jump-table.
27122  The example to the right side is slightly more efficient as the check for
27123  the lower boundary of the jump-table is not needed.
27124 \end_deeper 
27125 \layout Itemize
27126
27127 The number of case labels is not larger than supported by the target architectur
27128 e.
27129 \layout Itemize
27130
27131 If the case labels are not in numerical sequence ('gaps' between cases)
27132  SDCC checks whether a jump table with additionally inserted dummy cases
27133  is still attractive.
27134  
27135 \layout Itemize
27136
27137 If the starting number is not zero and a check for the lower boundary of
27138  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27139  ...
27140  .
27141 \layout Standard
27142
27143 Switch statements which have large gaps in the numeric sequence or those
27144  that have too many case labels can be split into more than one switch statement
27145  for efficient code generation, e.g.:
27146 \layout Verse
27147
27148
27149 \family typewriter 
27150 switch (i) { 
27151 \newline 
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 case 1: ...
27155  
27156 \newline 
27157 \SpecialChar ~
27158 \SpecialChar ~
27159 case 2: ...
27160  
27161 \newline 
27162 \SpecialChar ~
27163 \SpecialChar ~
27164 case 3: ...
27165  
27166 \newline 
27167 \SpecialChar ~
27168 \SpecialChar ~
27169 case 4: ...
27170  
27171 \newline 
27172 \SpecialChar ~
27173 \SpecialChar ~
27174 case 5: ...
27175  
27176 \newline 
27177 \SpecialChar ~
27178 \SpecialChar ~
27179 case 6: ...
27180  
27181 \newline 
27182 \SpecialChar ~
27183 \SpecialChar ~
27184 case 7: ...
27185  
27186 \newline 
27187 \SpecialChar ~
27188 \SpecialChar ~
27189 case 101: ...
27190  
27191 \newline 
27192 \SpecialChar ~
27193 \SpecialChar ~
27194 case 102: ...
27195  
27196 \newline 
27197 \SpecialChar ~
27198 \SpecialChar ~
27199 case 103: ...
27200  
27201 \newline 
27202 \SpecialChar ~
27203 \SpecialChar ~
27204 case 104: ...
27205  
27206 \newline 
27207 \SpecialChar ~
27208 \SpecialChar ~
27209 case 105: ...
27210  
27211 \newline 
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 case 106: ...
27215  
27216 \newline 
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 case 107: ...
27220  
27221 \newline 
27222 }
27223 \layout Standard
27224
27225 If the above switch statement is broken down into two switch statements
27226 \layout Verse
27227
27228
27229 \family typewriter 
27230 switch (i) { 
27231 \newline 
27232 \SpecialChar ~
27233 \SpecialChar ~
27234 case 1: ...
27235  
27236 \newline 
27237 \SpecialChar ~
27238 \SpecialChar ~
27239 case 2: ...
27240  
27241 \newline 
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 case 3: ...
27245  
27246 \newline 
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 case 4: ...
27250  
27251 \newline 
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 case 5: ...
27255  
27256 \newline 
27257 \SpecialChar ~
27258 \SpecialChar ~
27259 case 6: ...
27260  
27261 \newline 
27262 \SpecialChar ~
27263 \SpecialChar ~
27264 case 7: ...
27265  
27266 \newline 
27267 }
27268 \layout Standard
27269
27270 and
27271 \layout Verse
27272
27273
27274 \family typewriter 
27275 switch (i) { 
27276 \newline 
27277 \SpecialChar ~
27278 \SpecialChar ~
27279 case 101: ...
27280  
27281 \newline 
27282 \SpecialChar ~
27283 \SpecialChar ~
27284 case 102: ...
27285  
27286 \newline 
27287 \SpecialChar ~
27288 \SpecialChar ~
27289 case 103: ...
27290  
27291 \newline 
27292 \SpecialChar ~
27293 \SpecialChar ~
27294 case 104: ...
27295  
27296 \newline 
27297 \SpecialChar ~
27298 \SpecialChar ~
27299 case 105: ...
27300  
27301 \newline 
27302 \SpecialChar ~
27303 \SpecialChar ~
27304 case 106: ...
27305  
27306 \newline 
27307 \SpecialChar ~
27308 \SpecialChar ~
27309 case 107: ...
27310  
27311 \newline 
27312 }
27313 \layout Standard
27314
27315 then both the switch statements will be implemented using jump-tables whereas
27316  the unmodified switch statement will not be.
27317 \layout Comment
27318
27319 There might be reasons which SDCC cannot know about to either favour or
27320  not favour jump tables.
27321  If the target system has to be as quick for the last switch case as for
27322  the first (pro jump table), or if the switch argument is known to be zero
27323  in the majority of the cases (contra jump table).
27324 \layout Standard
27325
27326 The pragma nojtbound
27327 \begin_inset LatexCommand \index{\#pragma nojtbound}
27328
27329 \end_inset 
27330
27331  can be used to turn off checking the 
27332 \emph on 
27333 j
27334 \emph default 
27335 ump 
27336 \emph on 
27337 t
27338 \emph default 
27339 able 
27340 \emph on 
27341 bound
27342 \emph default 
27343 aries.
27344  It has no effect if a default label is supplied.
27345  Use of this pragma is dangerous: if the switch
27346 \begin_inset LatexCommand \index{switch statement}
27347
27348 \end_inset 
27349
27350  argument is not matched by a case statement the processor will happily
27351  jump into Nirvana.
27352 \layout Subsection
27353
27354 Bit-shifting Operations
27355 \begin_inset LatexCommand \index{Bit shifting}
27356
27357 \end_inset 
27358
27359 .
27360 \layout Standard
27361
27362 Bit shifting is one of the most frequently used operation in embedded programmin
27363 g.
27364  SDCC tries to implement bit-shift operations in the most efficient way
27365  possible, e.g.:
27366 \layout Verse
27367
27368
27369 \family typewriter 
27370 unsigned char i;
27371 \newline 
27372 ...
27373  
27374 \newline 
27375 i >>= 4; 
27376 \newline 
27377 ...
27378 \layout Standard
27379
27380 generates the following code:
27381 \layout Verse
27382
27383
27384 \family typewriter 
27385 mov\SpecialChar ~
27386  a,_i 
27387 \newline 
27388 swap a 
27389 \newline 
27390 anl\SpecialChar ~
27391  a,#0x0f 
27392 \newline 
27393 mov\SpecialChar ~
27394  _i,a
27395 \layout Standard
27396
27397 In general SDCC will never setup a loop if the shift count is known.
27398  Another example:
27399 \layout Verse
27400
27401
27402 \family typewriter 
27403 unsigned int i; 
27404 \newline 
27405 ...
27406  
27407 \newline 
27408 i >>= 9; 
27409 \newline 
27410 ...
27411 \layout Standard
27412
27413 will generate:
27414 \layout Verse
27415
27416
27417 \family typewriter 
27418 mov\SpecialChar ~
27419 \SpecialChar ~
27420 a,(_i + 1) 
27421 \newline 
27422 mov\SpecialChar ~
27423 \SpecialChar ~
27424 (_i + 1),#0x00 
27425 \newline 
27426 clr\SpecialChar ~
27427 \SpecialChar ~
27428
27429 \newline 
27430 rrc\SpecialChar ~
27431 \SpecialChar ~
27432
27433 \newline 
27434 mov\SpecialChar ~
27435 \SpecialChar ~
27436 _i,a
27437 \layout Subsection
27438
27439 Bit-rotation
27440 \begin_inset LatexCommand \index{Bit rotation}
27441
27442 \end_inset 
27443
27444
27445 \layout Standard
27446
27447 A special case of the bit-shift operation is bit rotation
27448 \begin_inset LatexCommand \index{rotating bits}
27449
27450 \end_inset 
27451
27452 , SDCC recognizes the following expression to be a left bit-rotation:
27453 \layout Verse
27454
27455
27456 \family typewriter 
27457 \series bold 
27458 unsigned
27459 \series default 
27460 \SpecialChar ~
27461 \SpecialChar ~
27462 char i;\SpecialChar ~
27463 \SpecialChar ~
27464 \SpecialChar ~
27465 \SpecialChar ~
27466 \SpecialChar ~
27467 \SpecialChar ~
27468 \SpecialChar ~
27469 \SpecialChar ~
27470 \SpecialChar ~
27471 \SpecialChar ~
27472 \SpecialChar ~
27473 /* unsigned is needed for rotation */ 
27474 \newline 
27475 ...
27476  
27477 \newline 
27478 i = ((i << 1) | (i >> 7)); 
27479 \family default 
27480
27481 \newline 
27482
27483 \family typewriter 
27484 ...
27485 \layout Standard
27486
27487 will generate the following code:
27488 \layout Verse
27489
27490
27491 \family typewriter 
27492 mov\SpecialChar ~
27493 \SpecialChar ~
27494 a,_i 
27495 \newline 
27496 rl\SpecialChar ~
27497 \SpecialChar ~
27498 \SpecialChar ~
27499
27500 \newline 
27501 mov\SpecialChar ~
27502 \SpecialChar ~
27503 _i,a
27504 \layout Standard
27505
27506 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27507 ns of this case will also be recognized as bit-rotation, i.e.: 
27508 \layout Verse
27509
27510
27511 \family typewriter 
27512 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27513 \layout Subsection
27514
27515 Nibble and Byte Swapping
27516 \layout Standard
27517
27518 Other special cases of the bit-shift operations are nibble or byte swapping
27519 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27520
27521 \end_inset 
27522
27523 , SDCC recognizes the following expressions:
27524 \layout Verse
27525
27526
27527 \family typewriter 
27528 \series bold 
27529 unsigned
27530 \series default 
27531 \SpecialChar ~
27532 \SpecialChar ~
27533 char i; 
27534 \newline 
27535
27536 \series bold 
27537 unsigned
27538 \series default 
27539 \SpecialChar ~
27540 \SpecialChar ~
27541 int j; 
27542 \newline 
27543 ...
27544  
27545 \newline 
27546 i = ((i << 4) | (i >> 4)); 
27547 \family default 
27548
27549 \newline 
27550
27551 \family typewriter 
27552 j = ((j << 8) | (j >> 8)); 
27553 \layout Standard
27554
27555 and generates a swap instruction for the nibble swapping
27556 \begin_inset LatexCommand \index{Nibble swapping}
27557
27558 \end_inset 
27559
27560  or move instructions for the byte swapping
27561 \begin_inset LatexCommand \index{Byte swapping}
27562
27563 \end_inset 
27564
27565 .
27566  The 
27567 \begin_inset Quotes sld
27568 \end_inset 
27569
27570 j
27571 \begin_inset Quotes srd
27572 \end_inset 
27573
27574  example can be used to convert from little to big-endian or vice versa.
27575  If you want to change the endianness of a 
27576 \emph on 
27577 signed
27578 \emph default 
27579  integer you have to cast to 
27580 \family typewriter 
27581 (unsigned int)
27582 \family default 
27583  first.
27584 \layout Standard
27585
27586 Note that SDCC stores numbers in little-endian
27587 \begin_inset Foot
27588 collapsed false
27589
27590 \layout Standard
27591
27592 Usually 8-bit processors don't care much about endianness.
27593  This is not the case for the standard 8051 which only has an instruction
27594  to increment its 
27595 \emph on 
27596 dptr
27597 \emph default 
27598
27599 \begin_inset LatexCommand \index{DPTR}
27600
27601 \end_inset 
27602
27603 -datapointer
27604 \emph on 
27605  
27606 \emph default 
27607 so little-endian is the more efficient byte order.
27608 \end_inset 
27609
27610
27611 \begin_inset LatexCommand \index{little-endian}
27612
27613 \end_inset 
27614
27615
27616 \begin_inset LatexCommand \index{Endianness}
27617
27618 \end_inset 
27619
27620  format (i.e.
27621  lowest order first).
27622 \layout Subsection
27623
27624 Highest Order Bit
27625 \begin_inset LatexCommand \index{Highest Order Bit}
27626
27627 \end_inset 
27628
27629  / Any Order Bit
27630 \begin_inset LatexCommand \index{Any Order Bit}
27631
27632 \end_inset 
27633
27634
27635 \layout Standard
27636
27637 It is frequently required to obtain the highest order bit of an integral
27638  type (long, int, short or char types).
27639  Also obtaining any other order bit is not uncommon.
27640  SDCC recognizes the following expressions to yield the highest order bit
27641  and generates optimized code for it, e.g.:
27642 \layout Verse
27643
27644
27645 \family typewriter 
27646 unsigned int gint; 
27647 \newline 
27648
27649 \newline 
27650 foo () { 
27651 \newline 
27652 \SpecialChar ~
27653 \SpecialChar ~
27654 unsigned char hob1, aob1; 
27655 \newline 
27656 \SpecialChar ~
27657 \SpecialChar ~
27658 bit hob2, hob3, aob2, aob3; 
27659 \newline 
27660 \SpecialChar ~
27661 \SpecialChar ~
27662 ...
27663  
27664 \newline 
27665 \SpecialChar ~
27666 \SpecialChar ~
27667 hob1 = (gint >> 15) & 1; 
27668 \newline 
27669 \SpecialChar ~
27670 \SpecialChar ~
27671 hob2 = (gint >> 15) & 1; 
27672 \newline 
27673 \SpecialChar ~
27674 \SpecialChar ~
27675 hob3 = gint & 0x8000; 
27676 \newline 
27677 \SpecialChar ~
27678 \SpecialChar ~
27679 aob1 = (gint >> 9) & 1; 
27680 \newline 
27681 \SpecialChar ~
27682 \SpecialChar ~
27683 aob2 = (gint >> 8) & 1; 
27684 \newline 
27685 \SpecialChar ~
27686 \SpecialChar ~
27687 aob3 = gint & 0x0800; 
27688 \newline 
27689 \SpecialChar ~
27690 \SpecialChar ~
27691 ..
27692  
27693 \newline 
27694 }
27695 \layout Standard
27696
27697 will generate the following code:
27698 \layout Verse
27699
27700
27701 \family typewriter 
27702 \SpecialChar ~
27703 \SpecialChar ~
27704 \SpecialChar ~
27705 \SpecialChar ~
27706 \SpecialChar ~
27707 \SpecialChar ~
27708 \SpecialChar ~
27709 \SpecialChar ~
27710 \SpecialChar ~
27711 \SpecialChar ~
27712 \SpecialChar ~
27713 \SpecialChar ~
27714 \SpecialChar ~
27715 \SpecialChar ~
27716 \SpecialChar ~
27717 \SpecialChar ~
27718 \SpecialChar ~
27719 \SpecialChar ~
27720 \SpecialChar ~
27721 \SpecialChar ~
27722 \SpecialChar ~
27723 \SpecialChar ~
27724 \SpecialChar ~
27725 \SpecialChar ~
27726 \SpecialChar ~
27727  61 ;\SpecialChar ~
27728  hob.c 7 
27729 \newline 
27730 000A E5*01\SpecialChar ~
27731 \SpecialChar ~
27732 \SpecialChar ~
27733 \SpecialChar ~
27734 \SpecialChar ~
27735 \SpecialChar ~
27736 \SpecialChar ~
27737 \SpecialChar ~
27738 \SpecialChar ~
27739 \SpecialChar ~
27740 \SpecialChar ~
27741 \SpecialChar ~
27742 \SpecialChar ~
27743 \SpecialChar ~
27744 \SpecialChar ~
27745  62\SpecialChar ~
27746 \SpecialChar ~
27747 \SpecialChar ~
27748 \SpecialChar ~
27749 \SpecialChar ~
27750 \SpecialChar ~
27751 \SpecialChar ~
27752 \SpecialChar ~
27753  mov\SpecialChar ~
27754 \SpecialChar ~
27755  a,(_gint + 1) 
27756 \newline 
27757 000C 23\SpecialChar ~
27758 \SpecialChar ~
27759 \SpecialChar ~
27760 \SpecialChar ~
27761 \SpecialChar ~
27762 \SpecialChar ~
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 \SpecialChar ~
27766 \SpecialChar ~
27767 \SpecialChar ~
27768 \SpecialChar ~
27769 \SpecialChar ~
27770 \SpecialChar ~
27771 \SpecialChar ~
27772 \SpecialChar ~
27773 \SpecialChar ~
27774 \SpecialChar ~
27775  63\SpecialChar ~
27776 \SpecialChar ~
27777 \SpecialChar ~
27778 \SpecialChar ~
27779 \SpecialChar ~
27780 \SpecialChar ~
27781 \SpecialChar ~
27782 \SpecialChar ~
27783  rl\SpecialChar ~
27784 \SpecialChar ~
27785 \SpecialChar ~
27786  a 
27787 \newline 
27788 000D 54 01\SpecialChar ~
27789 \SpecialChar ~
27790 \SpecialChar ~
27791 \SpecialChar ~
27792 \SpecialChar ~
27793 \SpecialChar ~
27794 \SpecialChar ~
27795 \SpecialChar ~
27796 \SpecialChar ~
27797 \SpecialChar ~
27798 \SpecialChar ~
27799 \SpecialChar ~
27800 \SpecialChar ~
27801 \SpecialChar ~
27802 \SpecialChar ~
27803  64\SpecialChar ~
27804 \SpecialChar ~
27805 \SpecialChar ~
27806 \SpecialChar ~
27807 \SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811  anl\SpecialChar ~
27812 \SpecialChar ~
27813  a,#0x01 
27814 \newline 
27815 000F F5*02\SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818 \SpecialChar ~
27819 \SpecialChar ~
27820 \SpecialChar ~
27821 \SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825 \SpecialChar ~
27826 \SpecialChar ~
27827 \SpecialChar ~
27828 \SpecialChar ~
27829 \SpecialChar ~
27830  65\SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835 \SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838  mov\SpecialChar ~
27839 \SpecialChar ~
27840  _foo_hob1_1_1,a 
27841 \newline 
27842 \SpecialChar ~
27843 \SpecialChar ~
27844 \SpecialChar ~
27845 \SpecialChar ~
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 \SpecialChar ~
27849 \SpecialChar ~
27850 \SpecialChar ~
27851 \SpecialChar ~
27852 \SpecialChar ~
27853 \SpecialChar ~
27854 \SpecialChar ~
27855 \SpecialChar ~
27856 \SpecialChar ~
27857 \SpecialChar ~
27858 \SpecialChar ~
27859 \SpecialChar ~
27860 \SpecialChar ~
27861 \SpecialChar ~
27862 \SpecialChar ~
27863 \SpecialChar ~
27864 \SpecialChar ~
27865 \SpecialChar ~
27866 \SpecialChar ~
27867  66 ;\SpecialChar ~
27868  hob.c 8 
27869 \newline 
27870 0011 E5*01\SpecialChar ~
27871 \SpecialChar ~
27872 \SpecialChar ~
27873 \SpecialChar ~
27874 \SpecialChar ~
27875 \SpecialChar ~
27876 \SpecialChar ~
27877 \SpecialChar ~
27878 \SpecialChar ~
27879 \SpecialChar ~
27880 \SpecialChar ~
27881 \SpecialChar ~
27882 \SpecialChar ~
27883 \SpecialChar ~
27884 \SpecialChar ~
27885  67\SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 \SpecialChar ~
27893  mov\SpecialChar ~
27894 \SpecialChar ~
27895  a,(_gint + 1) 
27896 \newline 
27897 0013 33\SpecialChar ~
27898 \SpecialChar ~
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 \SpecialChar ~
27909 \SpecialChar ~
27910 \SpecialChar ~
27911 \SpecialChar ~
27912 \SpecialChar ~
27913 \SpecialChar ~
27914 \SpecialChar ~
27915  68\SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920 \SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923  rlc\SpecialChar ~
27924 \SpecialChar ~
27925  a 
27926 \newline 
27927 0014 92*00\SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935 \SpecialChar ~
27936 \SpecialChar ~
27937 \SpecialChar ~
27938 \SpecialChar ~
27939 \SpecialChar ~
27940 \SpecialChar ~
27941 \SpecialChar ~
27942  69\SpecialChar ~
27943 \SpecialChar ~
27944 \SpecialChar ~
27945 \SpecialChar ~
27946 \SpecialChar ~
27947 \SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950  mov\SpecialChar ~
27951 \SpecialChar ~
27952  _foo_hob2_1_1,c 
27953 \newline 
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 \SpecialChar ~
27972 \SpecialChar ~
27973 \SpecialChar ~
27974 \SpecialChar ~
27975 \SpecialChar ~
27976 \SpecialChar ~
27977 \SpecialChar ~
27978 \SpecialChar ~
27979  66 ;\SpecialChar ~
27980  hob.c 9 
27981 \newline 
27982 0016 E5*01\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  67\SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 \SpecialChar ~
28003 \SpecialChar ~
28004 \SpecialChar ~
28005  mov\SpecialChar ~
28006 \SpecialChar ~
28007  a,(_gint + 1) 
28008 \newline 
28009 0018 33\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  68\SpecialChar ~
28028 \SpecialChar ~
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 \SpecialChar ~
28035  rlc\SpecialChar ~
28036 \SpecialChar ~
28037  a 
28038 \newline 
28039 0019 92*01\SpecialChar ~
28040 \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  69\SpecialChar ~
28055 \SpecialChar ~
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062  mov\SpecialChar ~
28063 \SpecialChar ~
28064  _foo_hob3_1_1,c 
28065 \newline 
28066 \SpecialChar ~
28067 \SpecialChar ~
28068 \SpecialChar ~
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072 \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  70 ;\SpecialChar ~
28092  hob.c 10 
28093 \newline 
28094 001B E5*01\SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 \SpecialChar ~
28099 \SpecialChar ~
28100 \SpecialChar ~
28101 \SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104 \SpecialChar ~
28105 \SpecialChar ~
28106 \SpecialChar ~
28107 \SpecialChar ~
28108 \SpecialChar ~
28109  71\SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 \SpecialChar ~
28114 \SpecialChar ~
28115 \SpecialChar ~
28116 \SpecialChar ~
28117  mov\SpecialChar ~
28118 \SpecialChar ~
28119  a,(_gint + 1) 
28120 \newline 
28121 001D 03\SpecialChar ~
28122 \SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130 \SpecialChar ~
28131 \SpecialChar ~
28132 \SpecialChar ~
28133 \SpecialChar ~
28134 \SpecialChar ~
28135 \SpecialChar ~
28136 \SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139  72\SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147  rr\SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150  a 
28151 \newline 
28152 001E 54 01\SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 \SpecialChar ~
28160 \SpecialChar ~
28161 \SpecialChar ~
28162 \SpecialChar ~
28163 \SpecialChar ~
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167  73\SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175  anl\SpecialChar ~
28176 \SpecialChar ~
28177  a,#0x01 
28178 \newline 
28179 0020 F5*03\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 \SpecialChar ~
28193 \SpecialChar ~
28194  74\SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202  mov\SpecialChar ~
28203 \SpecialChar ~
28204  _foo_aob1_1_1,a 
28205 \newline 
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  75 ;\SpecialChar ~
28232  hob.c 11 
28233 \newline 
28234 0022 E5*01\SpecialChar ~
28235 \SpecialChar ~
28236 \SpecialChar ~
28237 \SpecialChar ~
28238 \SpecialChar ~
28239 \SpecialChar ~
28240 \SpecialChar ~
28241 \SpecialChar ~
28242 \SpecialChar ~
28243 \SpecialChar ~
28244 \SpecialChar ~
28245 \SpecialChar ~
28246 \SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249  76\SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252 \SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257  mov\SpecialChar ~
28258 \SpecialChar ~
28259  a,(_gint + 1) 
28260 \newline 
28261 0024 13\SpecialChar ~
28262 \SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274 \SpecialChar ~
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 \SpecialChar ~
28278 \SpecialChar ~
28279  77\SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 \SpecialChar ~
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 \SpecialChar ~
28286 \SpecialChar ~
28287  rrc\SpecialChar ~
28288 \SpecialChar ~
28289  a 
28290 \newline 
28291 0025 92*02\SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294 \SpecialChar ~
28295 \SpecialChar ~
28296 \SpecialChar ~
28297 \SpecialChar ~
28298 \SpecialChar ~
28299 \SpecialChar ~
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 \SpecialChar ~
28303 \SpecialChar ~
28304 \SpecialChar ~
28305 \SpecialChar ~
28306  78\SpecialChar ~
28307 \SpecialChar ~
28308 \SpecialChar ~
28309 \SpecialChar ~
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 \SpecialChar ~
28313 \SpecialChar ~
28314  mov\SpecialChar ~
28315 \SpecialChar ~
28316  _foo_aob2_1_1,c 
28317 \newline 
28318 \SpecialChar ~
28319 \SpecialChar ~
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 \SpecialChar ~
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329 \SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 \SpecialChar ~
28338 \SpecialChar ~
28339 \SpecialChar ~
28340 \SpecialChar ~
28341 \SpecialChar ~
28342 \SpecialChar ~
28343  79 ;\SpecialChar ~
28344  hob.c 12 
28345 \newline 
28346 0027 E5*01\SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 \SpecialChar ~
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 \SpecialChar ~
28353 \SpecialChar ~
28354 \SpecialChar ~
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361  80\SpecialChar ~
28362 \SpecialChar ~
28363 \SpecialChar ~
28364 \SpecialChar ~
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369  mov\SpecialChar ~
28370 \SpecialChar ~
28371  a,(_gint + 1) 
28372 \newline 
28373 0029 A2 E3\SpecialChar ~
28374 \SpecialChar ~
28375 \SpecialChar ~
28376 \SpecialChar ~
28377 \SpecialChar ~
28378 \SpecialChar ~
28379 \SpecialChar ~
28380 \SpecialChar ~
28381 \SpecialChar ~
28382 \SpecialChar ~
28383 \SpecialChar ~
28384 \SpecialChar ~
28385 \SpecialChar ~
28386 \SpecialChar ~
28387 \SpecialChar ~
28388  81\SpecialChar ~
28389 \SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 \SpecialChar ~
28396  mov\SpecialChar ~
28397 \SpecialChar ~
28398  c,acc[3] 
28399 \newline 
28400 002B 92*03\SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410 \SpecialChar ~
28411 \SpecialChar ~
28412 \SpecialChar ~
28413 \SpecialChar ~
28414 \SpecialChar ~
28415  82\SpecialChar ~
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 \SpecialChar ~
28419 \SpecialChar ~
28420 \SpecialChar ~
28421 \SpecialChar ~
28422 \SpecialChar ~
28423  mov\SpecialChar ~
28424 \SpecialChar ~
28425  _foo_aob3_1_1,c 
28426 \layout Standard
28427
28428 Other variations of these cases however will 
28429 \emph on 
28430 not
28431 \emph default 
28432  be recognized.
28433  They are standard C expressions, so I heartily recommend these be the only
28434  way to get the highest order bit, (it is portable).
28435  Of course it will be recognized even if it is embedded in other expressions,
28436  e.g.:
28437 \layout Verse
28438
28439
28440 \family typewriter 
28441 xyz = gint + ((gint >> 15) & 1);
28442 \layout Standard
28443
28444 will still be recognized.
28445 \layout Subsection
28446
28447 Higher Order Byte
28448 \begin_inset LatexCommand \index{Higher Order Byte}
28449
28450 \end_inset 
28451
28452  / Higher Order Word
28453 \begin_inset LatexCommand \index{Higher Order Word}
28454
28455 \end_inset 
28456
28457
28458 \layout Standard
28459
28460 It is also frequently required to obtain a higher order byte or word of
28461  a larger integral type (long, int or short types).
28462  SDCC recognizes the following expressions to yield the higher order byte
28463  or word and generates optimized code for it, e.g.:
28464 \layout Verse
28465
28466
28467 \family typewriter 
28468 unsigned int gint; 
28469 \newline 
28470 unsigned long int glong; 
28471 \newline 
28472
28473 \newline 
28474 foo () { 
28475 \newline 
28476 \SpecialChar ~
28477 \SpecialChar ~
28478 unsigned char hob1, hob2; 
28479 \newline 
28480 \SpecialChar ~
28481 \SpecialChar ~
28482 unsigned int how1, how2; 
28483 \newline 
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 ...
28487  
28488 \newline 
28489 \SpecialChar ~
28490 \SpecialChar ~
28491 hob1 = (gint >> 8) & 0xFF; 
28492 \newline 
28493 \SpecialChar ~
28494 \SpecialChar ~
28495 hob2 = glong >> 24; 
28496 \newline 
28497 \SpecialChar ~
28498 \SpecialChar ~
28499 how1 = (glong >> 16) & 0xFFFF; 
28500 \newline 
28501 \SpecialChar ~
28502 \SpecialChar ~
28503 how2 = glong >> 8; 
28504 \newline 
28505 \SpecialChar ~
28506 \SpecialChar ~
28507 ..
28508  
28509 \newline 
28510 }
28511 \layout Standard
28512
28513 will generate the following code:
28514 \layout Verse
28515
28516
28517 \family typewriter 
28518 \SpecialChar ~
28519 \SpecialChar ~
28520 \SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526 \SpecialChar ~
28527 \SpecialChar ~
28528 \SpecialChar ~
28529 \SpecialChar ~
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 \SpecialChar ~
28533 \SpecialChar ~
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 \SpecialChar ~
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 \SpecialChar ~
28540 \SpecialChar ~
28541 \SpecialChar ~
28542 \SpecialChar ~
28543  91 ;\SpecialChar ~
28544  hob.c 15 
28545 \newline 
28546 0037 85*01*06\SpecialChar ~
28547 \SpecialChar ~
28548 \SpecialChar ~
28549 \SpecialChar ~
28550 \SpecialChar ~
28551 \SpecialChar ~
28552 \SpecialChar ~
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 \SpecialChar ~
28556 \SpecialChar ~
28557 \SpecialChar ~
28558  92\SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 \SpecialChar ~
28562 \SpecialChar ~
28563 \SpecialChar ~
28564 \SpecialChar ~
28565 \SpecialChar ~
28566  mov\SpecialChar ~
28567 \SpecialChar ~
28568  _foo_hob1_1_1,(_gint + 1) 
28569 \newline 
28570 \SpecialChar ~
28571 \SpecialChar ~
28572 \SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580 \SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 \SpecialChar ~
28591 \SpecialChar ~
28592 \SpecialChar ~
28593 \SpecialChar ~
28594 \SpecialChar ~
28595  93 ;\SpecialChar ~
28596  hob.c 16 
28597 \newline 
28598 003A 85*05*07\SpecialChar ~
28599 \SpecialChar ~
28600 \SpecialChar ~
28601 \SpecialChar ~
28602 \SpecialChar ~
28603 \SpecialChar ~
28604 \SpecialChar ~
28605 \SpecialChar ~
28606 \SpecialChar ~
28607 \SpecialChar ~
28608 \SpecialChar ~
28609 \SpecialChar ~
28610  94\SpecialChar ~
28611 \SpecialChar ~
28612 \SpecialChar ~
28613 \SpecialChar ~
28614 \SpecialChar ~
28615 \SpecialChar ~
28616 \SpecialChar ~
28617 \SpecialChar ~
28618  mov\SpecialChar ~
28619 \SpecialChar ~
28620  _foo_hob2_1_1,(_glong + 3) 
28621 \newline 
28622 \SpecialChar ~
28623 \SpecialChar ~
28624 \SpecialChar ~
28625 \SpecialChar ~
28626 \SpecialChar ~
28627 \SpecialChar ~
28628 \SpecialChar ~
28629 \SpecialChar ~
28630 \SpecialChar ~
28631 \SpecialChar ~
28632 \SpecialChar ~
28633 \SpecialChar ~
28634 \SpecialChar ~
28635 \SpecialChar ~
28636 \SpecialChar ~
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 \SpecialChar ~
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 \SpecialChar ~
28644 \SpecialChar ~
28645 \SpecialChar ~
28646 \SpecialChar ~
28647  95 ;\SpecialChar ~
28648  hob.c 17 
28649 \newline 
28650 003D 85*04*08\SpecialChar ~
28651 \SpecialChar ~
28652 \SpecialChar ~
28653 \SpecialChar ~
28654 \SpecialChar ~
28655 \SpecialChar ~
28656 \SpecialChar ~
28657 \SpecialChar ~
28658 \SpecialChar ~
28659 \SpecialChar ~
28660 \SpecialChar ~
28661 \SpecialChar ~
28662  96\SpecialChar ~
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 \SpecialChar ~
28667 \SpecialChar ~
28668 \SpecialChar ~
28669 \SpecialChar ~
28670  mov\SpecialChar ~
28671 \SpecialChar ~
28672  _foo_how1_1_1,(_glong + 2) 
28673 \newline 
28674 0040 85*05*09\SpecialChar ~
28675 \SpecialChar ~
28676 \SpecialChar ~
28677 \SpecialChar ~
28678 \SpecialChar ~
28679 \SpecialChar ~
28680 \SpecialChar ~
28681 \SpecialChar ~
28682 \SpecialChar ~
28683 \SpecialChar ~
28684 \SpecialChar ~
28685 \SpecialChar ~
28686  97\SpecialChar ~
28687 \SpecialChar ~
28688 \SpecialChar ~
28689 \SpecialChar ~
28690 \SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693 \SpecialChar ~
28694  mov\SpecialChar ~
28695 \SpecialChar ~
28696  (_foo_how1_1_1 + 1),(_glong + 3) 
28697 \newline 
28698 0043 85*03*0A\SpecialChar ~
28699 \SpecialChar ~
28700 \SpecialChar ~
28701 \SpecialChar ~
28702 \SpecialChar ~
28703 \SpecialChar ~
28704 \SpecialChar ~
28705 \SpecialChar ~
28706 \SpecialChar ~
28707 \SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710  98\SpecialChar ~
28711 \SpecialChar ~
28712 \SpecialChar ~
28713 \SpecialChar ~
28714 \SpecialChar ~
28715 \SpecialChar ~
28716 \SpecialChar ~
28717 \SpecialChar ~
28718  mov\SpecialChar ~
28719 \SpecialChar ~
28720  _foo_how2_1_1,(_glong + 1) 
28721 \newline 
28722 0046 85*04*0B\SpecialChar ~
28723 \SpecialChar ~
28724 \SpecialChar ~
28725 \SpecialChar ~
28726 \SpecialChar ~
28727 \SpecialChar ~
28728 \SpecialChar ~
28729 \SpecialChar ~
28730 \SpecialChar ~
28731 \SpecialChar ~
28732 \SpecialChar ~
28733 \SpecialChar ~
28734  99\SpecialChar ~
28735 \SpecialChar ~
28736 \SpecialChar ~
28737 \SpecialChar ~
28738 \SpecialChar ~
28739 \SpecialChar ~
28740 \SpecialChar ~
28741 \SpecialChar ~
28742  mov\SpecialChar ~
28743 \SpecialChar ~
28744  (_foo_how2_1_1 + 1),(_glong + 2) 
28745 \layout Standard
28746
28747 Again, variations of these cases may 
28748 \emph on 
28749 not
28750 \emph default 
28751  be recognized.
28752  They are standard C expressions, so I heartily recommend these be the only
28753  way to get the higher order byte/word, (it is portable).
28754  Of course it will be recognized even if it is embedded in other expressions,
28755  e.g.:
28756 \layout Verse
28757
28758
28759 \family typewriter 
28760 xyz = gint + ((gint >> 8) & 0xFF);
28761 \layout Standard
28762
28763 will still be recognized.
28764 \layout Subsection
28765
28766 Peephole Optimizer
28767 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28768
28769 \end_inset 
28770
28771
28772 \begin_inset LatexCommand \index{Peephole optimizer}
28773
28774 \end_inset 
28775
28776
28777 \layout Standard
28778
28779 The compiler uses a rule based, pattern matching and re-writing mechanism
28780  for peep-hole optimization.
28781  It is inspired by 
28782 \emph on 
28783 copt
28784 \emph default 
28785  a peep-hole optimizer by Christopher W.
28786  Fraser (cwfraser\SpecialChar ~
28787 @\SpecialChar ~
28788 microsoft.com).
28789  A default set of rules are compiled into the compiler, additional rules
28790  may be added with the 
28791 \emph on 
28792 -
28793 \begin_inset ERT
28794 status Collapsed
28795
28796 \layout Standard
28797
28798 \backslash 
28799 /
28800 \end_inset 
28801
28802 -peep-file
28803 \begin_inset LatexCommand \index{-\/-peep-file}
28804
28805 \end_inset 
28806
28807  <filename>
28808 \emph default 
28809  option.
28810  The rule language is best illustrated with examples.
28811 \layout Verse
28812
28813
28814 \family typewriter 
28815 replace { 
28816 \newline 
28817 \SpecialChar ~
28818 \SpecialChar ~
28819 mov %1,a 
28820 \newline 
28821 \SpecialChar ~
28822 \SpecialChar ~
28823 mov a,%1
28824 \newline 
28825 } by {
28826 \newline 
28827 \SpecialChar ~
28828 \SpecialChar ~
28829 mov %1,a
28830 \newline 
28831 }
28832 \layout Standard
28833
28834 The above rule will change the following assembly
28835 \begin_inset LatexCommand \index{Assembler routines}
28836
28837 \end_inset 
28838
28839  sequence:
28840 \layout Verse
28841
28842
28843 \family typewriter 
28844 mov r1,a 
28845 \newline 
28846 mov a,r1
28847 \layout Standard
28848
28849 to
28850 \layout Verse
28851
28852
28853 \family typewriter 
28854 mov r1,a
28855 \layout Standard
28856
28857 Note: All occurrences of a 
28858 \emph on 
28859 %n
28860 \emph default 
28861  (pattern variable) must denote the same string.
28862  With the above rule, the assembly sequence:
28863 \layout Verse
28864
28865
28866 \family typewriter 
28867 mov r1,a 
28868 \newline 
28869 mov a,r2
28870 \layout Standard
28871
28872 will remain unmodified.
28873 \newline 
28874
28875 \newline 
28876 Other special case optimizations may be added by the user (via 
28877 \emph on 
28878 -
28879 \begin_inset ERT
28880 status Collapsed
28881
28882 \layout Standard
28883
28884 \backslash 
28885 /
28886 \end_inset 
28887
28888 -peep-file option
28889 \emph default 
28890 ).
28891  E.g.
28892  some variants of the 8051 MCU
28893 \begin_inset LatexCommand \index{MCS51 variants}
28894
28895 \end_inset 
28896
28897  allow only 
28898 \family typewriter 
28899 ajmp
28900 \family default 
28901  and 
28902 \family typewriter 
28903 acall
28904 \family default 
28905 .
28906  The following two rules will change all 
28907 \family typewriter 
28908 ljmp
28909 \family default 
28910  and 
28911 \family typewriter 
28912 lcall
28913 \family default 
28914  to 
28915 \family typewriter 
28916 ajmp
28917 \family default 
28918  and 
28919 \family typewriter 
28920 acall
28921 \layout Verse
28922
28923
28924 \family typewriter 
28925 replace { lcall %1 } by { acall %1 } 
28926 \newline 
28927 replace { ljmp %1 } by { ajmp %1 }
28928 \layout Standard
28929
28930 The 
28931 \emph on 
28932 inline-assembler code
28933 \emph default 
28934  is also passed through the peep hole optimizer, thus the peephole optimizer
28935  can also be used as an assembly level macro expander.
28936  The rules themselves are MCU dependent whereas the rule language infra-structur
28937 e is MCU independent.
28938  Peephole optimization rules for other MCU can be easily programmed using
28939  the rule language.
28940 \newline 
28941
28942 \newline 
28943 The syntax for a rule is as follows:
28944 \layout Verse
28945
28946
28947 \family typewriter 
28948 rule := replace [ restart ] '{' <assembly sequence> '
28949 \backslash 
28950 n' 
28951 \newline 
28952 \SpecialChar ~
28953  \SpecialChar ~
28954  \SpecialChar ~
28955  \SpecialChar ~
28956  \SpecialChar ~
28957  \SpecialChar ~
28958  \SpecialChar ~
28959  \SpecialChar ~
28960  \SpecialChar ~
28961  \SpecialChar ~
28962  \SpecialChar ~
28963  \SpecialChar ~
28964  \SpecialChar ~
28965  \SpecialChar ~
28966  '}' by '{' '
28967 \backslash 
28968 n' 
28969 \newline 
28970 \SpecialChar ~
28971  \SpecialChar ~
28972  \SpecialChar ~
28973  \SpecialChar ~
28974  \SpecialChar ~
28975  \SpecialChar ~
28976  \SpecialChar ~
28977  \SpecialChar ~
28978  \SpecialChar ~
28979  \SpecialChar ~
28980  \SpecialChar ~
28981  \SpecialChar ~
28982  \SpecialChar ~
28983  \SpecialChar ~
28984  \SpecialChar ~
28985  \SpecialChar ~
28986  <assembly sequence> '
28987 \backslash 
28988 n' 
28989 \newline 
28990 \SpecialChar ~
28991  \SpecialChar ~
28992  \SpecialChar ~
28993  \SpecialChar ~
28994  \SpecialChar ~
28995  \SpecialChar ~
28996  \SpecialChar ~
28997  \SpecialChar ~
28998  \SpecialChar ~
28999  \SpecialChar ~
29000  \SpecialChar ~
29001  \SpecialChar ~
29002  \SpecialChar ~
29003  \SpecialChar ~
29004  '}' [if <functionName> ] '
29005 \backslash 
29006 n' 
29007 \layout Standard
29008
29009 <assembly sequence> := assembly instruction (each instruction including
29010  labels must be on a separate line).
29011 \newline 
29012
29013 \newline 
29014 The optimizer will apply to the rules one by one from the top in the sequence
29015  of their appearance, it will terminate when all rules are exhausted.
29016  If the 'restart' option is specified, then the optimizer will start matching
29017  the rules again from the top, this option for a rule is expensive (performance)
29018 , it is intended to be used in situations where a transformation will trigger
29019  the same rule again.
29020  An example of this (not a good one, it has side effects) is the following
29021  rule:
29022 \layout Verse
29023
29024
29025 \family typewriter 
29026 replace restart { 
29027 \newline 
29028 \SpecialChar ~
29029 \SpecialChar ~
29030 pop %1 
29031 \newline 
29032 \SpecialChar ~
29033 \SpecialChar ~
29034 push %1 } by { 
29035 \newline 
29036 \SpecialChar ~
29037 \SpecialChar ~
29038 ; nop 
29039 \newline 
29040 }
29041 \layout Standard
29042
29043 Note that the replace pattern cannot be a blank, but can be a comment line.
29044  Without the 'restart' option only the innermost 'pop' 'push' pair would
29045  be eliminated, i.e.:
29046 \layout Verse
29047
29048
29049 \family typewriter 
29050 pop ar1 
29051 \newline 
29052 pop ar2 
29053 \newline 
29054 push ar2 
29055 \newline 
29056 push ar1
29057 \layout Standard
29058
29059 would result in:
29060 \layout Verse
29061
29062
29063 \family typewriter 
29064 pop ar1 
29065 \newline 
29066 ; nop 
29067 \newline 
29068 push ar1
29069 \layout Standard
29070
29071
29072 \emph on 
29073 with
29074 \emph default 
29075  the restart option the rule will be applied again to the resulting code
29076  and then all the pop-push pairs will be eliminated to yield:
29077 \layout Verse
29078
29079
29080 \family typewriter 
29081 ; nop 
29082 \newline 
29083 ; nop
29084 \layout Standard
29085
29086 A conditional function can be attached to a rule.
29087  Attaching rules are somewhat more involved, let me illustrate this with
29088  an example.
29089 \layout Verse
29090
29091
29092 \family typewriter 
29093 replace { 
29094 \newline 
29095 \SpecialChar ~
29096  \SpecialChar ~
29097  \SpecialChar ~
29098 ljmp %5 
29099 \newline 
29100 %2:
29101 \newline 
29102 } by { 
29103 \newline 
29104 \SpecialChar ~
29105  \SpecialChar ~
29106  \SpecialChar ~
29107 sjmp %5 
29108 \newline 
29109 %2:
29110 \newline 
29111 } if labelInRange
29112 \layout Standard
29113
29114 The optimizer does a look-up of a function name table defined in function
29115  
29116 \emph on 
29117 callFuncByName
29118 \emph default 
29119  in the source file SDCCpeeph.c, with the name 
29120 \emph on 
29121 labelInRange
29122 \emph default 
29123 .
29124  If it finds a corresponding entry the function is called.
29125  Note there can be no parameters specified for these functions, in this
29126  case the use of 
29127 \emph on 
29128 %5
29129 \emph default 
29130  is crucial, since the function 
29131 \emph on 
29132 labelInRange
29133 \emph default 
29134  expects to find the label in that particular variable (the hash table containin
29135 g the variable bindings is passed as a parameter).
29136  If you want to code more such functions, take a close look at the function
29137  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29138  Currently implemented are 
29139 \emph on 
29140 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29141  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29142 \emph default 
29143 and
29144 \emph on 
29145  notVolatile
29146 \emph default 
29147 .
29148 \layout Standard
29149
29150 I know this whole thing is a little kludgey, but maybe some day we will
29151  have some better means.
29152  If you are looking at this file, you will see the default rules that are
29153  compiled into the compiler, you can add your own rules in the default set
29154  there if you get tired of specifying the -
29155 \begin_inset ERT
29156 status Collapsed
29157
29158 \layout Standard
29159
29160 \backslash 
29161 /
29162 \end_inset 
29163
29164 -peep-file option.
29165 \layout Section
29166
29167 ANSI-Compliance
29168 \begin_inset LatexCommand \index{ANSI-compliance}
29169
29170 \end_inset 
29171
29172
29173 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29174
29175 \end_inset 
29176
29177
29178 \layout Standard
29179
29180 The latest publically available version of the standard 
29181 \emph on 
29182 ISO/IEC 9899 - Programming languages - C
29183 \emph default 
29184  should be available at: 
29185 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29186
29187 \end_inset 
29188
29189 .
29190 \newline 
29191
29192 \layout Standard
29193
29194 Deviations from the compliance:
29195 \layout Itemize
29196
29197 functions are not reentrant
29198 \begin_inset LatexCommand \index{reentrant}
29199
29200 \end_inset 
29201
29202  unless explicitly declared as such or the 
29203 \series bold 
29204 -
29205 \begin_inset ERT
29206 status Collapsed
29207
29208 \layout Standard
29209
29210 \backslash 
29211 /
29212 \end_inset 
29213
29214 -stack-auto
29215 \begin_inset LatexCommand \index{-\/-stack-auto}
29216
29217 \end_inset 
29218
29219
29220 \series default 
29221  command line option is specified.
29222 \layout Itemize
29223
29224 structures
29225 \begin_inset LatexCommand \index{struct}
29226
29227 \end_inset 
29228
29229  and unions
29230 \begin_inset LatexCommand \index{union}
29231
29232 \end_inset 
29233
29234  cannot be assigned values directly, cannot be passed as function parameters
29235  or assigned to each other and cannot be a return value
29236 \begin_inset LatexCommand \index{return value}
29237
29238 \end_inset 
29239
29240  from a function, e.g.:
29241 \begin_deeper 
29242 \layout Verse
29243
29244
29245 \family typewriter 
29246 struct s { ...
29247  }; 
29248 \newline 
29249 struct s s1, s2; 
29250 \newline 
29251 foo() 
29252 \newline 
29253
29254 \newline 
29255 \SpecialChar ~
29256 \SpecialChar ~
29257 \SpecialChar ~
29258 \SpecialChar ~
29259 ...
29260  
29261 \newline 
29262 \SpecialChar ~
29263 \SpecialChar ~
29264 \SpecialChar ~
29265 \SpecialChar ~
29266 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29267 \newline 
29268 \SpecialChar ~
29269 \SpecialChar ~
29270 \SpecialChar ~
29271 \SpecialChar ~
29272 ...
29273  
29274 \newline 
29275 }
29276 \newline 
29277
29278 \series bold 
29279 struct
29280 \series default 
29281  s foo1 (
29282 \series bold 
29283 struct
29284 \series default 
29285  s parms) /* invalid in SDCC although allowed in ANSI */
29286 \newline 
29287
29288 \newline 
29289 \SpecialChar ~
29290 \SpecialChar ~
29291 \SpecialChar ~
29292 \SpecialChar ~
29293 struct s rets; 
29294 \newline 
29295 \SpecialChar ~
29296 \SpecialChar ~
29297 \SpecialChar ~
29298 \SpecialChar ~
29299 ...
29300  
29301 \newline 
29302 \SpecialChar ~
29303 \SpecialChar ~
29304 \SpecialChar ~
29305 \SpecialChar ~
29306 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29307 \newline 
29308 }
29309 \end_deeper 
29310 \layout Itemize
29311
29312 initialization of structure arrays must be fully braced.
29313 \begin_deeper 
29314 \layout Verse
29315
29316
29317 \family typewriter 
29318 struct s { char x } a[] = {1, 2};\SpecialChar ~
29319 \SpecialChar ~
29320 \SpecialChar ~
29321 \SpecialChar ~
29322 \SpecialChar ~
29323 /* invalid in SDCC */
29324 \newline 
29325 struct s { char x } a[] = {{1}, {2}}; /* OK */
29326 \end_deeper 
29327 \layout Itemize
29328
29329 'long long
29330 \begin_inset LatexCommand \index{long long (not supported)}
29331
29332 \end_inset 
29333
29334 ' (64 bit integers
29335 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29336
29337 \end_inset 
29338
29339 ) not supported.
29340 \layout Itemize
29341
29342 'double
29343 \begin_inset LatexCommand \index{double (not supported)}
29344
29345 \end_inset 
29346
29347 ' precision floating point 
29348 \begin_inset LatexCommand \index{Floating point support}
29349
29350 \end_inset 
29351
29352 not supported.
29353 \layout Itemize
29354
29355 Old K&R style
29356 \begin_inset LatexCommand \index{K\&R style}
29357
29358 \end_inset 
29359
29360  function declarations are NOT allowed.
29361 \begin_deeper 
29362 \layout Verse
29363
29364
29365 \family typewriter 
29366 foo(i,j) /* this old style of function declarations */ 
29367 \newline 
29368 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29369 \newline 
29370
29371 \newline 
29372 \SpecialChar ~
29373 \SpecialChar ~
29374 \SpecialChar ~
29375 \SpecialChar ~
29376 ...
29377  
29378 \newline 
29379 }
29380 \end_deeper 
29381 \layout Itemize
29382
29383 Most enhancements in C99 are not supported, f.e.:
29384 \begin_deeper 
29385 \layout Verse
29386
29387
29388 \family typewriter 
29389 \series bold 
29390 inline
29391 \begin_inset LatexCommand \index{inline (not supported)}
29392
29393 \end_inset 
29394
29395
29396 \series default 
29397  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29398  in C99.
29399  An empty define 
29400 \emph on 
29401 #define inline
29402 \emph default 
29403  can be used as a work around */
29404 \newline 
29405
29406 \newline 
29407 for (
29408 \series bold 
29409 int
29410 \series default 
29411  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29412 \end_deeper 
29413 \layout Itemize
29414
29415 Certain words that are valid identifiers in the standard may be reserved
29416  words in SDCC unless the 
29417 \series bold 
29418 -
29419 \begin_inset ERT
29420 status Collapsed
29421
29422 \layout Standard
29423
29424 \backslash 
29425 /
29426 \end_inset 
29427
29428 -std-c89
29429 \begin_inset LatexCommand \index{-\/-std-c89}
29430
29431 \end_inset 
29432
29433  or -
29434 \begin_inset ERT
29435 status Collapsed
29436
29437 \layout Standard
29438
29439 \backslash 
29440 /
29441 \end_inset 
29442
29443 -std-c99
29444 \begin_inset LatexCommand \index{-\/-std-c99}
29445
29446 \end_inset 
29447
29448
29449 \series default 
29450  command line options are used.
29451  These may include (depending on the selected processor): 'at', 'banked',
29452  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29453 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29454  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29455  '_naked'.
29456  Compliant equivalents of these keywords are always available in a form
29457  that begin with two underscores
29458 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29459
29460 \end_inset 
29461
29462 , f.e.
29463  '__data' instead of 'data'.
29464 \layout Section
29465
29466 Cyclomatic Complexity
29467 \begin_inset LatexCommand \index{Cyclomatic complexity}
29468
29469 \end_inset 
29470
29471
29472 \layout Standard
29473
29474 Cyclomatic complexity of a function is defined as the number of independent
29475  paths the program can take during execution of the function.
29476  This is an important number since it defines the number test cases you
29477  have to generate to validate the function.
29478  The accepted industry standard for complexity number is 10, if the cyclomatic
29479  complexity reported by SDCC exceeds 10 you should think about simplification
29480  of the function logic.
29481  Note that the complexity level is not related to the number of lines of
29482  code in a function.
29483  Large functions can have low complexity, and small functions can have large
29484  complexity levels.
29485  
29486 \newline 
29487
29488 \newline 
29489 SDCC uses the following formula to compute the complexity:
29490 \newline 
29491
29492 \layout Standard
29493
29494 complexity = (number of edges in control flow graph) - (number of nodes
29495  in control flow graph) + 2;
29496 \newline 
29497
29498 \newline 
29499 Having said that the industry standard is 10, you should be aware that in
29500  some cases it be may unavoidable to have a complexity level of less than
29501  10.
29502  For example if you have switch statement with more than 10 case labels,
29503  each case label adds one to the complexity level.
29504  The complexity level is by no means an absolute measure of the algorithmic
29505  complexity of the function, it does however provide a good starting point
29506  for which functions you might look at for further optimization.
29507 \layout Section
29508
29509 Retargetting for other Processors
29510 \layout Standard
29511
29512 The issues for retargetting the compiler are far too numerous to be covered
29513  by this document.
29514  What follows is a brief description of each of the seven phases of the
29515  compiler and its MCU dependency.
29516 \layout Itemize
29517
29518 Parsing the source and building the annotated parse tree.
29519  This phase is largely MCU independent (except for the language extensions).
29520  Syntax & semantic checks are also done in this phase, along with some initial
29521  optimizations like back patching labels and the pattern matching optimizations
29522  like bit-rotation etc.
29523 \layout Itemize
29524
29525 The second phase involves generating an intermediate code which can be easy
29526  manipulated during the later phases.
29527  This phase is entirely MCU independent.
29528  The intermediate code generation assumes the target machine has unlimited
29529  number of registers, and designates them with the name iTemp.
29530  The compiler can be made to dump a human readable form of the code generated
29531  by using the -
29532 \begin_inset ERT
29533 status Collapsed
29534
29535 \layout Standard
29536
29537 \backslash 
29538 /
29539 \end_inset 
29540
29541 -dumpraw option.
29542 \layout Itemize
29543
29544 This phase does the bulk of the standard optimizations and is also MCU independe
29545 nt.
29546  This phase can be broken down into several sub-phases:
29547 \newline 
29548
29549 \newline 
29550 Break down intermediate code (iCode) into basic blocks.
29551 \newline 
29552 Do control flow & data flow analysis on the basic blocks.
29553 \newline 
29554 Do local common subexpression elimination, then global subexpression elimination
29555 \newline 
29556 Dead code elimination
29557 \newline 
29558 Loop optimizations
29559 \newline 
29560 If loop optimizations caused any changes then do 'global subexpression eliminati
29561 on' and 'dead code elimination' again.
29562 \layout Itemize
29563
29564 This phase determines the live-ranges; by live range I mean those iTemp
29565  variables defined by the compiler that still survive after all the optimization
29566 s.
29567  Live range analysis
29568 \begin_inset LatexCommand \index{Live range analysis}
29569
29570 \end_inset 
29571
29572  is essential for register allocation, since these computation determines
29573  which of these iTemps will be assigned to registers, and for how long.
29574 \layout Itemize
29575
29576 Phase five is register allocation.
29577  There are two parts to this process.
29578 \newline 
29579
29580 \newline 
29581 The first part I call 'register packing' (for lack of a better term).
29582  In this case several MCU specific expression folding is done to reduce
29583  register pressure.
29584 \newline 
29585
29586 \newline 
29587 The second part is more MCU independent and deals with allocating registers
29588  to the remaining live ranges.
29589  A lot of MCU specific code does creep into this phase because of the limited
29590  number of index registers available in the 8051.
29591 \layout Itemize
29592
29593 The Code generation phase is (unhappily), entirely MCU dependent and very
29594  little (if any at all) of this code can be reused for other MCU.
29595  However the scheme for allocating a homogenized assembler operand for each
29596  iCode operand may be reused.
29597 \layout Itemize
29598
29599 As mentioned in the optimization section the peep-hole optimizer is rule
29600  based system, which can reprogrammed for other MCUs.
29601 \layout Standard
29602
29603 More information is available in a wiki
29604 \begin_inset LatexCommand \index{wiki}
29605
29606 \end_inset 
29607
29608  (preliminary link 
29609 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
29610
29611 \end_inset 
29612
29613 ) and in the thread 
29614 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
29615
29616 \end_inset 
29617
29618  .
29619 \layout Chapter
29620
29621 Compiler internals
29622 \begin_inset LatexCommand \index{Compiler internals}
29623
29624 \end_inset 
29625
29626
29627 \layout Section
29628
29629 The anatomy of the compiler
29630 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29631
29632 \end_inset 
29633
29634
29635 \layout Standard
29636
29637
29638 \shape italic 
29639 This is an excerpt from an article published in Circuit Cellar Magazine
29640  in 
29641 \series bold 
29642 August 2000
29643 \series default 
29644 .
29645  It's a little outdated (the compiler is much more efficient now and user/develo
29646 per friendly), but pretty well exposes the guts of it all.
29647 \shape default 
29648
29649 \newline 
29650
29651 \newline 
29652 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29653  It is fairly easy to retarget for other 8-bit MCU.
29654  Here we take a look at some of the internals of the compiler.
29655  
29656 \layout Paragraph*
29657
29658 Parsing
29659 \begin_inset LatexCommand \index{Parsing}
29660
29661 \end_inset 
29662
29663  
29664 \layout Standard
29665
29666 Parsing the input source file and creating an AST (Annotated Syntax Tree
29667 \begin_inset LatexCommand \index{Annotated syntax tree}
29668
29669 \end_inset 
29670
29671 ).
29672  This phase also involves propagating types (annotating each node of the
29673  parse tree with type information) and semantic analysis.
29674  There are some MCU specific parsing rules.
29675  For example the storage classes, the extended storage classes are MCU specific
29676  while there may be a xdata storage class for 8051 there is no such storage
29677  class for z80 or Atmel AVR.
29678  SDCC allows MCU specific storage class extensions, i.e.
29679  xdata will be treated as a storage class specifier when parsing 8051 C
29680  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29681  C code.
29682 \layout Paragraph*
29683
29684 Generating iCode
29685 \begin_inset LatexCommand \index{iCode}
29686
29687 \end_inset 
29688
29689
29690 \layout Standard
29691
29692 Intermediate code generation.
29693  In this phase the AST is broken down into three-operand form (iCode).
29694  These three operand forms are represented as doubly linked lists.
29695  ICode is the term given to the intermediate form generated by the compiler.
29696  ICode example section shows some examples of iCode generated for some simple
29697  C source functions.
29698 \layout Paragraph*
29699
29700 Optimizations
29701 \begin_inset LatexCommand \index{Optimizations}
29702
29703 \end_inset 
29704
29705 .
29706 \layout Standard
29707
29708 Bulk of the target independent optimizations is performed in this phase.
29709  The optimizations include constant propagation, common sub-expression eliminati
29710 on, loop invariant code movement, strength reduction of loop induction variables
29711  and dead-code elimination.
29712 \layout Paragraph*
29713
29714 Live range analysis
29715 \begin_inset LatexCommand \index{Live range analysis}
29716
29717 \end_inset 
29718
29719
29720 \layout Standard
29721
29722 During intermediate code generation phase, the compiler assumes the target
29723  machine has infinite number of registers and generates a lot of temporary
29724  variables.
29725  The live range computation determines the lifetime of each of these compiler-ge
29726 nerated temporaries.
29727  A picture speaks a thousand words.
29728  ICode example sections show the live range annotations for each of the
29729  operand.
29730  It is important to note here, each iCode is assigned a number in the order
29731  of its execution in the function.
29732  The live ranges are computed in terms of these numbers.
29733  The from number is the number of the iCode which first defines the operand
29734  and the to number signifies the iCode which uses this operand last.
29735 \layout Paragraph*
29736
29737 Register Allocation
29738 \begin_inset LatexCommand \index{Register allocation}
29739
29740 \end_inset 
29741
29742
29743 \layout Standard
29744
29745 The register allocation determines the type and number of registers needed
29746  by each operand.
29747  In most MCUs only a few registers can be used for indirect addressing.
29748  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29749  address the internal ram and DPTR to indirectly address the external ram.
29750  The compiler will try to allocate the appropriate register to pointer variables
29751  if it can.
29752  ICode example section shows the operands annotated with the registers assigned
29753  to them.
29754  The compiler will try to keep operands in registers as much as possible;
29755  there are several schemes the compiler uses to do achieve this.
29756  When the compiler runs out of registers the compiler will check to see
29757  if there are any live operands which is not used or defined in the current
29758  basic block being processed, if there are any found then it will push that
29759  operand and use the registers in this block, the operand will then be popped
29760  at the end of the basic block.
29761  
29762 \layout Standard
29763
29764 There are other MCU specific considerations in this phase.
29765  Some MCUs have an accumulator; very short-lived operands could be assigned
29766  to the accumulator instead of a general-purpose register.
29767 \layout Paragraph*
29768
29769 Code generation
29770 \layout Standard
29771
29772 Figure II gives a table of iCode
29773 \begin_inset LatexCommand \index{iCode}
29774
29775 \end_inset 
29776
29777  operations supported by the compiler.
29778  The code generation involves translating these operations into corresponding
29779  assembly code for the processor.
29780  This sounds overly simple but that is the essence of code generation.
29781  Some of the iCode operations are generated on a MCU specific manner for
29782  example, the z80 port does not use registers to pass parameters so the
29783  SEND and RECV iCode operations will not be generated, and it also does
29784  not support JUMPTABLES.
29785  
29786 \newline 
29787
29788 \layout Standard
29789
29790
29791 \size footnotesize 
29792 Figure II 
29793 \begin_inset  Tabular
29794 <lyxtabular version="3" rows="39" columns="4">
29795 <features islongtable="true" headBottomDL="true">
29796 <column alignment="block" valignment="top" leftline="true" width="13col%">
29797 <column alignment="left" valignment="top" leftline="true" width="13col%">
29798 <column alignment="block" valignment="top" leftline="true" width="22col%">
29799 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
29800 <row topline="true" bottomline="true" endhead="true">
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29802 \begin_inset Text
29803
29804 \layout Standard
29805
29806
29807 \series bold 
29808 iCode
29809 \series default 
29810
29811 \begin_inset LatexCommand \index{iCode}
29812
29813 \end_inset 
29814
29815
29816 \end_inset 
29817 </cell>
29818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29819 \begin_inset Text
29820
29821 \layout Standard
29822
29823
29824 \series bold 
29825 Operands
29826 \end_inset 
29827 </cell>
29828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29829 \begin_inset Text
29830
29831 \layout Standard
29832
29833
29834 \series bold 
29835 Description
29836 \end_inset 
29837 </cell>
29838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29839 \begin_inset Text
29840
29841 \layout Standard
29842
29843
29844 \series bold 
29845 C Equivalent
29846 \end_inset 
29847 </cell>
29848 </row>
29849 <row topline="true">
29850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29851 \begin_inset Text
29852
29853 \layout Standard
29854
29855
29856 \size footnotesize 
29857 '!'
29858 \end_inset 
29859 </cell>
29860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29861 \begin_inset Text
29862
29863 \layout Standard
29864
29865
29866 \size footnotesize 
29867 IC_LEFT() IC_RESULT()
29868 \end_inset 
29869 </cell>
29870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29871 \begin_inset Text
29872
29873 \layout Standard
29874
29875
29876 \size footnotesize 
29877 NOT operation 
29878 \end_inset 
29879 </cell>
29880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29881 \begin_inset Text
29882
29883 \layout Standard
29884
29885
29886 \size footnotesize 
29887 IC_RESULT = ! IC_LEFT;
29888 \end_inset 
29889 </cell>
29890 </row>
29891 <row topline="true">
29892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29893 \begin_inset Text
29894
29895 \layout Standard
29896
29897
29898 \size footnotesize 
29899 '~'
29900 \end_inset 
29901 </cell>
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29903 \begin_inset Text
29904
29905 \layout Standard
29906
29907
29908 \size footnotesize 
29909 IC_LEFT() IC_RESULT()
29910 \end_inset 
29911 </cell>
29912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29913 \begin_inset Text
29914
29915 \layout Standard
29916
29917
29918 \size footnotesize 
29919 Bitwise complement of 
29920 \end_inset 
29921 </cell>
29922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29923 \begin_inset Text
29924
29925 \layout Standard
29926
29927
29928 \size footnotesize 
29929 IC_RESULT = ~IC_LEFT;
29930 \end_inset 
29931 </cell>
29932 </row>
29933 <row topline="true">
29934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29935 \begin_inset Text
29936
29937 \layout Standard
29938
29939
29940 \size footnotesize 
29941 RRC
29942 \end_inset 
29943 </cell>
29944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29945 \begin_inset Text
29946
29947 \layout Standard
29948
29949
29950 \size footnotesize 
29951 IC_LEFT() IC_RESULT()
29952 \end_inset 
29953 </cell>
29954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29955 \begin_inset Text
29956
29957 \layout Standard
29958
29959
29960 \size footnotesize 
29961 Rotate right with carry
29962 \end_inset 
29963 </cell>
29964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29965 \begin_inset Text
29966
29967 \layout Standard
29968
29969
29970 \size footnotesize 
29971 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
29972 \end_inset 
29973 </cell>
29974 </row>
29975 <row topline="true">
29976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29977 \begin_inset Text
29978
29979 \layout Standard
29980
29981
29982 \size footnotesize 
29983 RLC
29984 \end_inset 
29985 </cell>
29986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29987 \begin_inset Text
29988
29989 \layout Standard
29990
29991
29992 \size footnotesize 
29993 IC_LEFT() IC_RESULT()
29994 \end_inset 
29995 </cell>
29996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29997 \begin_inset Text
29998
29999 \layout Standard
30000
30001
30002 \size footnotesize 
30003 Rotate left with carry
30004 \end_inset 
30005 </cell>
30006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30007 \begin_inset Text
30008
30009 \layout Standard
30010
30011
30012 \size footnotesize 
30013 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
30014 \end_inset 
30015 </cell>
30016 </row>
30017 <row topline="true">
30018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30019 \begin_inset Text
30020
30021 \layout Standard
30022
30023
30024 \size footnotesize 
30025 GETHBIT
30026 \end_inset 
30027 </cell>
30028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30029 \begin_inset Text
30030
30031 \layout Standard
30032
30033
30034 \size footnotesize 
30035 IC_LEFT() IC_RESULT()
30036 \end_inset 
30037 </cell>
30038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30039 \begin_inset Text
30040
30041 \layout Standard
30042
30043
30044 \size footnotesize 
30045 Get the highest order bit of IC_LEFT
30046 \end_inset 
30047 </cell>
30048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30049 \begin_inset Text
30050
30051 \layout Standard
30052
30053
30054 \size footnotesize 
30055 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
30056 \end_inset 
30057 </cell>
30058 </row>
30059 <row topline="true">
30060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30061 \begin_inset Text
30062
30063 \layout Standard
30064
30065
30066 \size footnotesize 
30067 UNARYMINUS
30068 \end_inset 
30069 </cell>
30070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30071 \begin_inset Text
30072
30073 \layout Standard
30074
30075
30076 \size footnotesize 
30077 IC_LEFT() IC_RESULT()
30078 \end_inset 
30079 </cell>
30080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30081 \begin_inset Text
30082
30083 \layout Standard
30084
30085
30086 \size footnotesize 
30087 Unary minus
30088 \end_inset 
30089 </cell>
30090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30091 \begin_inset Text
30092
30093 \layout Standard
30094
30095
30096 \size footnotesize 
30097 IC_RESULT = - IC_LEFT;
30098 \end_inset 
30099 </cell>
30100 </row>
30101 <row topline="true">
30102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30103 \begin_inset Text
30104
30105 \layout Standard
30106
30107
30108 \size footnotesize 
30109 IPUSH
30110 \end_inset 
30111 </cell>
30112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30113 \begin_inset Text
30114
30115 \layout Standard
30116
30117
30118 \size footnotesize 
30119 IC_LEFT()
30120 \end_inset 
30121 </cell>
30122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30123 \begin_inset Text
30124
30125 \layout Standard
30126
30127
30128 \size footnotesize 
30129 Push the operand into stack
30130 \end_inset 
30131 </cell>
30132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30133 \begin_inset Text
30134
30135 \layout Standard
30136
30137
30138 \size footnotesize 
30139 NONE
30140 \end_inset 
30141 </cell>
30142 </row>
30143 <row topline="true">
30144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30145 \begin_inset Text
30146
30147 \layout Standard
30148
30149
30150 \size footnotesize 
30151 IPOP
30152 \end_inset 
30153 </cell>
30154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30155 \begin_inset Text
30156
30157 \layout Standard
30158
30159
30160 \size footnotesize 
30161 IC_LEFT()
30162 \end_inset 
30163 </cell>
30164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30165 \begin_inset Text
30166
30167 \layout Standard
30168
30169
30170 \size footnotesize 
30171 Pop the operand from the stack 
30172 \end_inset 
30173 </cell>
30174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30175 \begin_inset Text
30176
30177 \layout Standard
30178
30179
30180 \size footnotesize 
30181 NONE
30182 \end_inset 
30183 </cell>
30184 </row>
30185 <row topline="true">
30186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30187 \begin_inset Text
30188
30189 \layout Standard
30190
30191
30192 \size footnotesize 
30193 CALL
30194 \end_inset 
30195 </cell>
30196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30197 \begin_inset Text
30198
30199 \layout Standard
30200
30201
30202 \size footnotesize 
30203 IC_LEFT() IC_RESULT()
30204 \end_inset 
30205 </cell>
30206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30207 \begin_inset Text
30208
30209 \layout Standard
30210
30211
30212 \size footnotesize 
30213 Call the function represented by IC_LEFT 
30214 \end_inset 
30215 </cell>
30216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30217 \begin_inset Text
30218
30219 \layout Standard
30220
30221
30222 \size footnotesize 
30223 IC_RESULT = IC_LEFT();
30224 \end_inset 
30225 </cell>
30226 </row>
30227 <row topline="true">
30228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30229 \begin_inset Text
30230
30231 \layout Standard
30232
30233
30234 \size footnotesize 
30235 PCALL
30236 \end_inset 
30237 </cell>
30238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30239 \begin_inset Text
30240
30241 \layout Standard
30242
30243
30244 \size footnotesize 
30245 IC_LEFT() IC_RESULT()
30246 \end_inset 
30247 </cell>
30248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30249 \begin_inset Text
30250
30251 \layout Standard
30252
30253
30254 \size footnotesize 
30255 Call via function pointer
30256 \end_inset 
30257 </cell>
30258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30259 \begin_inset Text
30260
30261 \layout Standard
30262
30263
30264 \size footnotesize 
30265 IC_RESULT = (*IC_LEFT)();
30266 \end_inset 
30267 </cell>
30268 </row>
30269 <row topline="true">
30270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30271 \begin_inset Text
30272
30273 \layout Standard
30274
30275
30276 \size footnotesize 
30277 RETURN
30278 \end_inset 
30279 </cell>
30280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30281 \begin_inset Text
30282
30283 \layout Standard
30284
30285
30286 \size footnotesize 
30287 IC_LEFT()
30288 \end_inset 
30289 </cell>
30290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30291 \begin_inset Text
30292
30293 \layout Standard
30294
30295
30296 \size footnotesize 
30297 Return the value in operand IC_LEFT 
30298 \end_inset 
30299 </cell>
30300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30301 \begin_inset Text
30302
30303 \layout Standard
30304
30305
30306 \size footnotesize 
30307 return IC_LEFT;
30308 \end_inset 
30309 </cell>
30310 </row>
30311 <row topline="true">
30312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30313 \begin_inset Text
30314
30315 \layout Standard
30316
30317
30318 \size footnotesize 
30319 LABEL
30320 \end_inset 
30321 </cell>
30322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30323 \begin_inset Text
30324
30325 \layout Standard
30326
30327
30328 \size footnotesize 
30329 IC_LABEL() 
30330 \end_inset 
30331 </cell>
30332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30333 \begin_inset Text
30334
30335 \layout Standard
30336
30337
30338 \size footnotesize 
30339 Label
30340 \end_inset 
30341 </cell>
30342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30343 \begin_inset Text
30344
30345 \layout Standard
30346
30347
30348 \size footnotesize 
30349 IC_LABEL:
30350 \end_inset 
30351 </cell>
30352 </row>
30353 <row topline="true">
30354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30355 \begin_inset Text
30356
30357 \layout Standard
30358
30359
30360 \size footnotesize 
30361 GOTO
30362 \end_inset 
30363 </cell>
30364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30365 \begin_inset Text
30366
30367 \layout Standard
30368
30369
30370 \size footnotesize 
30371 IC_LABEL() 
30372 \end_inset 
30373 </cell>
30374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30375 \begin_inset Text
30376
30377 \layout Standard
30378
30379
30380 \size footnotesize 
30381 Goto label
30382 \end_inset 
30383 </cell>
30384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30385 \begin_inset Text
30386
30387 \layout Standard
30388
30389
30390 \size footnotesize 
30391 goto IC_LABEL();
30392 \end_inset 
30393 </cell>
30394 </row>
30395 <row topline="true">
30396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30397 \begin_inset Text
30398
30399 \layout Standard
30400
30401
30402 \size footnotesize 
30403 '+'
30404 \end_inset 
30405 </cell>
30406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30407 \begin_inset Text
30408
30409 \layout Standard
30410
30411
30412 \size footnotesize 
30413 IC_LEFT() IC_RIGHT() IC_RESULT()
30414 \end_inset 
30415 </cell>
30416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30417 \begin_inset Text
30418
30419 \layout Standard
30420
30421
30422 \size footnotesize 
30423 Addition
30424 \end_inset 
30425 </cell>
30426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30427 \begin_inset Text
30428
30429 \layout Standard
30430
30431
30432 \size footnotesize 
30433 IC_RESULT = IC_LEFT + IC_RIGHT
30434 \end_inset 
30435 </cell>
30436 </row>
30437 <row topline="true">
30438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30439 \begin_inset Text
30440
30441 \layout Standard
30442
30443
30444 \size footnotesize 
30445 '-'
30446 \end_inset 
30447 </cell>
30448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30449 \begin_inset Text
30450
30451 \layout Standard
30452
30453
30454 \size footnotesize 
30455 IC_LEFT() IC_RIGHT() IC_RESULT()
30456 \end_inset 
30457 </cell>
30458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30459 \begin_inset Text
30460
30461 \layout Standard
30462
30463
30464 \size footnotesize 
30465 Subtraction
30466 \end_inset 
30467 </cell>
30468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30469 \begin_inset Text
30470
30471 \layout Standard
30472
30473
30474 \size footnotesize 
30475 IC_RESULT = IC_LEFT - IC_RIGHT 
30476 \end_inset 
30477 </cell>
30478 </row>
30479 <row topline="true">
30480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30481 \begin_inset Text
30482
30483 \layout Standard
30484
30485
30486 \size footnotesize 
30487 '*'
30488 \end_inset 
30489 </cell>
30490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30491 \begin_inset Text
30492
30493 \layout Standard
30494
30495
30496 \size footnotesize 
30497 IC_LEFT() IC_RIGHT() IC_RESULT()
30498 \end_inset 
30499 </cell>
30500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30501 \begin_inset Text
30502
30503 \layout Standard
30504
30505
30506 \size footnotesize 
30507 Multiplication 
30508 \end_inset 
30509 </cell>
30510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30511 \begin_inset Text
30512
30513 \layout Standard
30514
30515
30516 \size footnotesize 
30517 IC_RESULT = IC_LEFT * IC_RIGHT;
30518 \end_inset 
30519 </cell>
30520 </row>
30521 <row topline="true">
30522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30523 \begin_inset Text
30524
30525 \layout Standard
30526
30527
30528 \size footnotesize 
30529 '/'
30530 \end_inset 
30531 </cell>
30532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30533 \begin_inset Text
30534
30535 \layout Standard
30536
30537
30538 \size footnotesize 
30539 IC_LEFT() IC_RIGHT() IC_RESULT()
30540 \end_inset 
30541 </cell>
30542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30543 \begin_inset Text
30544
30545 \layout Standard
30546
30547
30548 \size footnotesize 
30549 Division
30550 \end_inset 
30551 </cell>
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30553 \begin_inset Text
30554
30555 \layout Standard
30556
30557
30558 \size footnotesize 
30559 IC_RESULT = IC_LEFT / IC_RIGHT;
30560 \end_inset 
30561 </cell>
30562 </row>
30563 <row topline="true">
30564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30565 \begin_inset Text
30566
30567 \layout Standard
30568
30569
30570 \size footnotesize 
30571 '%'
30572 \end_inset 
30573 </cell>
30574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30575 \begin_inset Text
30576
30577 \layout Standard
30578
30579
30580 \size footnotesize 
30581 IC_LEFT() IC_RIGHT() IC_RESULT()
30582 \end_inset 
30583 </cell>
30584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30585 \begin_inset Text
30586
30587 \layout Standard
30588
30589
30590 \size footnotesize 
30591 Modulus
30592 \end_inset 
30593 </cell>
30594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30595 \begin_inset Text
30596
30597 \layout Standard
30598
30599
30600 \size footnotesize 
30601 IC_RESULT = IC_LEFT % IC_RIGHT;
30602 \end_inset 
30603 </cell>
30604 </row>
30605 <row topline="true">
30606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30607 \begin_inset Text
30608
30609 \layout Standard
30610
30611
30612 \size footnotesize 
30613 '<'
30614 \end_inset 
30615 </cell>
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30617 \begin_inset Text
30618
30619 \layout Standard
30620
30621
30622 \size footnotesize 
30623 IC_LEFT() IC_RIGHT() IC_RESULT()
30624 \end_inset 
30625 </cell>
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30627 \begin_inset Text
30628
30629 \layout Standard
30630
30631
30632 \size footnotesize 
30633 Less than
30634 \end_inset 
30635 </cell>
30636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30637 \begin_inset Text
30638
30639 \layout Standard
30640
30641
30642 \size footnotesize 
30643 IC_RESULT = IC_LEFT < IC_RIGHT;
30644 \end_inset 
30645 </cell>
30646 </row>
30647 <row topline="true">
30648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30649 \begin_inset Text
30650
30651 \layout Standard
30652
30653
30654 \size footnotesize 
30655 '>'
30656 \end_inset 
30657 </cell>
30658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30659 \begin_inset Text
30660
30661 \layout Standard
30662
30663
30664 \size footnotesize 
30665 IC_LEFT() IC_RIGHT() IC_RESULT()
30666 \end_inset 
30667 </cell>
30668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30669 \begin_inset Text
30670
30671 \layout Standard
30672
30673
30674 \size footnotesize 
30675 Greater than 
30676 \end_inset 
30677 </cell>
30678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30679 \begin_inset Text
30680
30681 \layout Standard
30682
30683
30684 \size footnotesize 
30685 IC_RESULT = IC_LEFT > IC_RIGHT;
30686 \end_inset 
30687 </cell>
30688 </row>
30689 <row topline="true">
30690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30691 \begin_inset Text
30692
30693 \layout Standard
30694
30695
30696 \size footnotesize 
30697 EQ_OP
30698 \end_inset 
30699 </cell>
30700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30701 \begin_inset Text
30702
30703 \layout Standard
30704
30705
30706 \size footnotesize 
30707 IC_LEFT() IC_RIGHT() IC_RESULT()
30708 \end_inset 
30709 </cell>
30710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30711 \begin_inset Text
30712
30713 \layout Standard
30714
30715
30716 \size footnotesize 
30717 Equal to 
30718 \end_inset 
30719 </cell>
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30721 \begin_inset Text
30722
30723 \layout Standard
30724
30725
30726 \size footnotesize 
30727 IC_RESULT = IC_LEFT == IC_RIGHT;
30728 \end_inset 
30729 </cell>
30730 </row>
30731 <row topline="true">
30732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30733 \begin_inset Text
30734
30735 \layout Standard
30736
30737
30738 \size footnotesize 
30739 AND_OP
30740 \end_inset 
30741 </cell>
30742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30743 \begin_inset Text
30744
30745 \layout Standard
30746
30747
30748 \size footnotesize 
30749 IC_LEFT() IC_RIGHT() IC_RESULT() 
30750 \end_inset 
30751 </cell>
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30753 \begin_inset Text
30754
30755 \layout Standard
30756
30757
30758 \size footnotesize 
30759 Logical and operation
30760 \end_inset 
30761 </cell>
30762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30763 \begin_inset Text
30764
30765 \layout Standard
30766
30767
30768 \size footnotesize 
30769 IC_RESULT = IC_LEFT && IC_RIGHT; 
30770 \end_inset 
30771 </cell>
30772 </row>
30773 <row topline="true">
30774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30775 \begin_inset Text
30776
30777 \layout Standard
30778
30779
30780 \size footnotesize 
30781 OR_OP
30782 \end_inset 
30783 </cell>
30784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30785 \begin_inset Text
30786
30787 \layout Standard
30788
30789
30790 \size footnotesize 
30791 IC_LEFT() IC_RIGHT() IC_RESULT() 
30792 \end_inset 
30793 </cell>
30794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30795 \begin_inset Text
30796
30797 \layout Standard
30798
30799
30800 \size footnotesize 
30801 Logical or operation 
30802 \end_inset 
30803 </cell>
30804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30805 \begin_inset Text
30806
30807 \layout Standard
30808
30809
30810 \size footnotesize 
30811 IC_RESULT = IC_LEFT || IC_RIGHT; 
30812 \end_inset 
30813 </cell>
30814 </row>
30815 <row topline="true">
30816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30817 \begin_inset Text
30818
30819 \layout Standard
30820
30821
30822 \size footnotesize 
30823 '^'
30824 \end_inset 
30825 </cell>
30826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30827 \begin_inset Text
30828
30829 \layout Standard
30830
30831
30832 \size footnotesize 
30833 IC_LEFT() IC_RIGHT() IC_RESULT() 
30834 \end_inset 
30835 </cell>
30836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30837 \begin_inset Text
30838
30839 \layout Standard
30840
30841
30842 \size footnotesize 
30843 Exclusive OR
30844 \end_inset 
30845 </cell>
30846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30847 \begin_inset Text
30848
30849 \layout Standard
30850
30851
30852 \size footnotesize 
30853 IC_RESULT = IC_LEFT ^ IC_RIGHT;
30854 \end_inset 
30855 </cell>
30856 </row>
30857 <row topline="true">
30858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30859 \begin_inset Text
30860
30861 \layout Standard
30862
30863
30864 \size footnotesize 
30865 '|'
30866 \end_inset 
30867 </cell>
30868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30869 \begin_inset Text
30870
30871 \layout Standard
30872
30873
30874 \size footnotesize 
30875 IC_LEFT() IC_RIGHT() IC_RESULT() 
30876 \end_inset 
30877 </cell>
30878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30879 \begin_inset Text
30880
30881 \layout Standard
30882
30883
30884 \size footnotesize 
30885 Bitwise OR 
30886 \end_inset 
30887 </cell>
30888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30889 \begin_inset Text
30890
30891 \layout Standard
30892
30893
30894 \size footnotesize 
30895 IC_RESULT = IC_LEFT | IC_RIGHT;
30896 \end_inset 
30897 </cell>
30898 </row>
30899 <row topline="true">
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30901 \begin_inset Text
30902
30903 \layout Standard
30904
30905
30906 \size footnotesize 
30907 BITWISEAND
30908 \end_inset 
30909 </cell>
30910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30911 \begin_inset Text
30912
30913 \layout Standard
30914
30915
30916 \size footnotesize 
30917 IC_LEFT() IC_RIGHT() IC_RESULT()
30918 \end_inset 
30919 </cell>
30920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30921 \begin_inset Text
30922
30923 \layout Standard
30924
30925
30926 \size footnotesize 
30927 Bitwise AND 
30928 \end_inset 
30929 </cell>
30930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30931 \begin_inset Text
30932
30933 \layout Standard
30934
30935
30936 \size footnotesize 
30937 IC_RESULT = IC_LEFT & IC_RIGHT;
30938 \end_inset 
30939 </cell>
30940 </row>
30941 <row topline="true">
30942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30943 \begin_inset Text
30944
30945 \layout Standard
30946
30947
30948 \size footnotesize 
30949 LEFT_OP
30950 \end_inset 
30951 </cell>
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30953 \begin_inset Text
30954
30955 \layout Standard
30956
30957
30958 \size footnotesize 
30959 IC_LEFT() IC_RIGHT() IC_RESULT()
30960 \end_inset 
30961 </cell>
30962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30963 \begin_inset Text
30964
30965 \layout Standard
30966
30967
30968 \size footnotesize 
30969 Left shift 
30970 \end_inset 
30971 </cell>
30972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30973 \begin_inset Text
30974
30975 \layout Standard
30976
30977
30978 \size footnotesize 
30979 IC_RESULT = IC_LEFT << IC_RIGHT 
30980 \end_inset 
30981 </cell>
30982 </row>
30983 <row topline="true">
30984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30985 \begin_inset Text
30986
30987 \layout Standard
30988
30989
30990 \size footnotesize 
30991 RIGHT_OP
30992 \end_inset 
30993 </cell>
30994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30995 \begin_inset Text
30996
30997 \layout Standard
30998
30999
31000 \size footnotesize 
31001 IC_LEFT() IC_RIGHT() IC_RESULT()
31002 \end_inset 
31003 </cell>
31004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31005 \begin_inset Text
31006
31007 \layout Standard
31008
31009
31010 \size footnotesize 
31011 Right shift
31012 \end_inset 
31013 </cell>
31014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31015 \begin_inset Text
31016
31017 \layout Standard
31018
31019
31020 \size footnotesize 
31021 IC_RESULT = IC_LEFT >> IC_RIGHT 
31022 \end_inset 
31023 </cell>
31024 </row>
31025 <row topline="true">
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31027 \begin_inset Text
31028
31029 \layout Standard
31030
31031
31032 \size footnotesize 
31033 GET_VALUE_
31034 \newline 
31035 AT_ ADDRESS
31036 \end_inset 
31037 </cell>
31038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31039 \begin_inset Text
31040
31041 \layout Standard
31042
31043
31044 \size footnotesize 
31045 IC_LEFT() IC_RESULT()
31046 \end_inset 
31047 </cell>
31048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31049 \begin_inset Text
31050
31051 \layout Standard
31052
31053
31054 \size footnotesize 
31055 Indirect fetch 
31056 \end_inset 
31057 </cell>
31058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31059 \begin_inset Text
31060
31061 \layout Standard
31062
31063
31064 \size footnotesize 
31065 IC_RESULT = (*IC_LEFT);
31066 \end_inset 
31067 </cell>
31068 </row>
31069 <row topline="true">
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31071 \begin_inset Text
31072
31073 \layout Standard
31074
31075
31076 \size footnotesize 
31077 POINTER_SET
31078 \end_inset 
31079 </cell>
31080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31081 \begin_inset Text
31082
31083 \layout Standard
31084
31085
31086 \size footnotesize 
31087 IC_RIGHT() IC_RESULT() 
31088 \end_inset 
31089 </cell>
31090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31091 \begin_inset Text
31092
31093 \layout Standard
31094
31095
31096 \size footnotesize 
31097 Indirect set
31098 \end_inset 
31099 </cell>
31100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31101 \begin_inset Text
31102
31103 \layout Standard
31104
31105
31106 \size footnotesize 
31107 (*IC_RESULT) = IC_RIGHT;
31108 \end_inset 
31109 </cell>
31110 </row>
31111 <row topline="true">
31112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31113 \begin_inset Text
31114
31115 \layout Standard
31116
31117
31118 \size footnotesize 
31119 '='
31120 \end_inset 
31121 </cell>
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31123 \begin_inset Text
31124
31125 \layout Standard
31126
31127
31128 \size footnotesize 
31129 IC_RIGHT() IC_RESULT()
31130 \end_inset 
31131 </cell>
31132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31133 \begin_inset Text
31134
31135 \layout Standard
31136
31137
31138 \size footnotesize 
31139 Assignment
31140 \end_inset 
31141 </cell>
31142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31143 \begin_inset Text
31144
31145 \layout Standard
31146
31147
31148 \size footnotesize 
31149 IC_RESULT = IC_RIGHT;
31150 \end_inset 
31151 </cell>
31152 </row>
31153 <row topline="true">
31154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31155 \begin_inset Text
31156
31157 \layout Standard
31158
31159
31160 \size footnotesize 
31161 IFX
31162 \end_inset 
31163 </cell>
31164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31165 \begin_inset Text
31166
31167 \layout Standard
31168
31169
31170 \size footnotesize 
31171 IC_COND IC_TRUE IC_LABEL
31172 \end_inset 
31173 </cell>
31174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31175 \begin_inset Text
31176
31177 \layout Standard
31178
31179
31180 \size footnotesize 
31181 Conditional jump.
31182  If true label is present then jump to true label if condition is true else
31183  jump to false label if condition is false 
31184 \end_inset 
31185 </cell>
31186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31187 \begin_inset Text
31188
31189 \layout Standard
31190
31191
31192 \size footnotesize 
31193 if (IC_COND) goto IC_TRUE; 
31194 \newline 
31195 \SpecialChar ~
31196 \SpecialChar ~
31197 Or 
31198 \newline 
31199 If (!IC_COND) goto IC_FALSE;
31200 \end_inset 
31201 </cell>
31202 </row>
31203 <row topline="true">
31204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31205 \begin_inset Text
31206
31207 \layout Standard
31208
31209
31210 \size footnotesize 
31211 ADDRESS_OF
31212 \end_inset 
31213 </cell>
31214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31215 \begin_inset Text
31216
31217 \layout Standard
31218
31219
31220 \size footnotesize 
31221 IC_LEFT() IC_RESULT()
31222 \end_inset 
31223 </cell>
31224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31225 \begin_inset Text
31226
31227 \layout Standard
31228
31229
31230 \size footnotesize 
31231 Address of 
31232 \end_inset 
31233 </cell>
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31235 \begin_inset Text
31236
31237 \layout Standard
31238
31239
31240 \size footnotesize 
31241 IC_RESULT = &IC_LEFT();
31242 \end_inset 
31243 </cell>
31244 </row>
31245 <row topline="true">
31246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31247 \begin_inset Text
31248
31249 \layout Standard
31250
31251
31252 \size footnotesize 
31253 JUMPTABLE
31254 \end_inset 
31255 </cell>
31256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31257 \begin_inset Text
31258
31259 \layout Standard
31260
31261
31262 \size footnotesize 
31263 IC_JTCOND IC_JTLABELS
31264 \end_inset 
31265 </cell>
31266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31267 \begin_inset Text
31268
31269 \layout Standard
31270
31271
31272 \size footnotesize 
31273 Jump to list of labels depending on the value of JTCOND
31274 \end_inset 
31275 </cell>
31276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31277 \begin_inset Text
31278
31279 \layout Standard
31280
31281
31282 \size footnotesize 
31283 Switch statement
31284 \end_inset 
31285 </cell>
31286 </row>
31287 <row topline="true">
31288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31289 \begin_inset Text
31290
31291 \layout Standard
31292
31293
31294 \size footnotesize 
31295 CAST
31296 \end_inset 
31297 </cell>
31298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31299 \begin_inset Text
31300
31301 \layout Standard
31302
31303
31304 \size footnotesize 
31305 IC_RIGHT() IC_LEFT() IC_RESULT()
31306 \end_inset 
31307 </cell>
31308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31309 \begin_inset Text
31310
31311 \layout Standard
31312
31313
31314 \size footnotesize 
31315 Cast types 
31316 \end_inset 
31317 </cell>
31318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31319 \begin_inset Text
31320
31321 \layout Standard
31322
31323
31324 \size footnotesize 
31325 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
31326 \end_inset 
31327 </cell>
31328 </row>
31329 <row topline="true">
31330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31331 \begin_inset Text
31332
31333 \layout Standard
31334
31335
31336 \size footnotesize 
31337 SEND
31338 \end_inset 
31339 </cell>
31340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31341 \begin_inset Text
31342
31343 \layout Standard
31344
31345
31346 \size footnotesize 
31347 IC_LEFT()
31348 \end_inset 
31349 </cell>
31350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31351 \begin_inset Text
31352
31353 \layout Standard
31354
31355
31356 \size footnotesize 
31357 This is used for passing parameters in registers; 
31358 \newline 
31359 move IC_LEFT to the next available parameter register.
31360 \end_inset 
31361 </cell>
31362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31363 \begin_inset Text
31364
31365 \layout Standard
31366
31367
31368 \size footnotesize 
31369 None
31370 \end_inset 
31371 </cell>
31372 </row>
31373 <row topline="true">
31374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31375 \begin_inset Text
31376
31377 \layout Standard
31378
31379
31380 \size footnotesize 
31381 RECV
31382 \end_inset 
31383 </cell>
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31385 \begin_inset Text
31386
31387 \layout Standard
31388
31389
31390 \size footnotesize 
31391 IC_RESULT()
31392 \end_inset 
31393 </cell>
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31395 \begin_inset Text
31396
31397 \layout Standard
31398
31399
31400 \size footnotesize 
31401 This is used for receiving parameters passed in registers;
31402 \newline 
31403 Move the values in the next parameter register to IC_RESULT 
31404 \end_inset 
31405 </cell>
31406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31407 \begin_inset Text
31408
31409 \layout Standard
31410
31411
31412 \size footnotesize 
31413 None
31414 \end_inset 
31415 </cell>
31416 </row>
31417 <row topline="true" bottomline="true">
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31419 \begin_inset Text
31420
31421 \layout Standard
31422
31423
31424 \shape slanted 
31425 \size footnotesize 
31426 (some more have been added)
31427 \end_inset 
31428 </cell>
31429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31430 \begin_inset Text
31431
31432 \layout Standard
31433
31434 \end_inset 
31435 </cell>
31436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31437 \begin_inset Text
31438
31439 \layout Standard
31440
31441 \end_inset 
31442 </cell>
31443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31444 \begin_inset Text
31445
31446 \layout Standard
31447
31448
31449 \shape slanted 
31450 \size footnotesize 
31451 see f.e.
31452  
31453 \family typewriter 
31454 gen51Code()
31455 \family default 
31456  in 
31457 \family typewriter 
31458 src/mcs51/gen.c
31459 \end_inset 
31460 </cell>
31461 </row>
31462 </lyxtabular>
31463
31464 \end_inset 
31465
31466
31467 \layout Comment
31468
31469 In the original article Figure II was announced to be downloadable on 
31470 \shape italic 
31471 Circuit Cellar
31472 \shape default 
31473 's web site.
31474  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
31475 \layout Paragraph*
31476
31477 ICode Example
31478 \begin_inset LatexCommand \index{iCode}
31479
31480 \end_inset 
31481
31482
31483 \layout Standard
31484
31485 This section shows some details of iCode.
31486  The example C code does not do anything useful; it is used as an example
31487  to illustrate the intermediate code generated by the compiler.
31488 \layout Verse
31489
31490
31491 \family typewriter 
31492 1.\SpecialChar ~
31493 xdata int * p;
31494 \newline 
31495 2.\SpecialChar ~
31496 int gint;
31497 \newline 
31498 3.\SpecialChar ~
31499 /* This function does nothing useful.
31500  It is used
31501 \newline 
31502 4.\SpecialChar ~
31503 \SpecialChar ~
31504 \SpecialChar ~
31505 \SpecialChar ~
31506 for the purpose of explaining iCode */
31507 \newline 
31508 5.\SpecialChar ~
31509 short function (data int *x)
31510 \newline 
31511 6.\SpecialChar ~
31512 {
31513 \newline 
31514 7.\SpecialChar ~
31515 \SpecialChar ~
31516 \SpecialChar ~
31517 short i=10; \SpecialChar ~
31518 \SpecialChar ~
31519 /* dead initialization eliminated */
31520 \newline 
31521 8.\SpecialChar ~
31522 \SpecialChar ~
31523 \SpecialChar ~
31524 short sum=10; /* dead initialization eliminated */
31525 \newline 
31526 9.\SpecialChar ~
31527 \SpecialChar ~
31528 \SpecialChar ~
31529 short mul;
31530 \newline 
31531 10.\SpecialChar ~
31532 \SpecialChar ~
31533 int j ;
31534 \newline 
31535 11.\SpecialChar ~
31536 \SpecialChar ~
31537 while (*x) *x++ = *p++; 
31538 \newline 
31539 12.\SpecialChar ~
31540 \SpecialChar ~
31541 \SpecialChar ~
31542 \SpecialChar ~
31543 sum = 0 ; 
31544 \newline 
31545 13.\SpecialChar ~
31546 \SpecialChar ~
31547 mul = 0;
31548 \newline 
31549 14.\SpecialChar ~
31550 \SpecialChar ~
31551 /* compiler detects i,j to be induction variables */
31552 \newline 
31553 15.\SpecialChar ~
31554 \SpecialChar ~
31555 for (i = 0, j = 10 ; i < 10 ; i++, j
31556 \family default 
31557 -
31558 \begin_inset ERT
31559 status Collapsed
31560
31561 \layout Standard
31562
31563 \backslash 
31564 /
31565 \end_inset 
31566
31567 -
31568 \family typewriter 
31569 ) {
31570 \newline 
31571 16.\SpecialChar ~
31572 \SpecialChar ~
31573 \SpecialChar ~
31574 \SpecialChar ~
31575 sum += i;
31576 \newline 
31577 17.\SpecialChar ~
31578 \SpecialChar ~
31579 \SpecialChar ~
31580 \SpecialChar ~
31581 mul += i * 3; \SpecialChar ~
31582 \SpecialChar ~
31583 /* this multiplication remains */
31584 \newline 
31585 18.\SpecialChar ~
31586 \SpecialChar ~
31587 \SpecialChar ~
31588 \SpecialChar ~
31589 gint += j * 3;\SpecialChar ~
31590 \SpecialChar ~
31591 /* this multiplication changed to addition */
31592 \newline 
31593 19.\SpecialChar ~
31594 \SpecialChar ~
31595 }
31596 \newline 
31597 20.\SpecialChar ~
31598 \SpecialChar ~
31599 return sum+mul;
31600 \newline 
31601 21.\SpecialChar ~
31602 }
31603 \layout Standard
31604
31605 In addition to the operands each iCode contains information about the filename
31606  and line it corresponds to in the source file.
31607  The first field in the listing should be interpreted as follows:
31608 \newline 
31609
31610 \shape italic 
31611 \size footnotesize 
31612 Filename(linenumber: iCode Execution sequence number : ICode hash table
31613  key : loop depth of the iCode).
31614 \shape default 
31615 \size default 
31616
31617 \newline 
31618 Then follows the human readable form of the ICode operation.
31619  Each operand of this triplet form can be of three basic types a) compiler
31620  generated temporary b) user defined variable c) a constant value.
31621  Note that local variables and parameters are replaced by compiler generated
31622  temporaries.
31623  Live ranges
31624 \begin_inset LatexCommand \index{Live range analysis}
31625
31626 \end_inset 
31627
31628  are computed only for temporaries (i.e.
31629  live ranges are not computed for global variables).
31630  Registers
31631 \begin_inset LatexCommand \index{Register allocation}
31632
31633 \end_inset 
31634
31635  are allocated for temporaries only.
31636  Operands are formatted in the following manner:
31637 \newline 
31638
31639 \shape italic 
31640 \size footnotesize 
31641 Operand Name [lr live-from : live-to ] { type information } [ registers
31642  allocated ].
31643 \shape default 
31644 \size default 
31645
31646 \newline 
31647 As mentioned earlier the live ranges are computed in terms of the execution
31648  sequence number of the iCodes, for example 
31649 \newline 
31650 the iTemp0 is live from (i.e.
31651  first defined in iCode with execution sequence number 3, and is last used
31652  in the iCode with sequence number 5).
31653  For induction variables such as iTemp21 the live range computation extends
31654  the lifetime from the start to the end of the loop.
31655 \newline 
31656 The register allocator used the live range information to allocate registers,
31657  the same registers may be used for different temporaries if their live
31658  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
31659  iTemp17 since their live ranges do not overlap.
31660  In addition the allocator also takes into consideration the type and usage
31661  of a temporary, for example itemp6 is a pointer to near space and is used
31662  as to fetch data from (i.e.
31663  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
31664  Some short lived temporaries are allocated to special registers which have
31665  meaning to the code generator e.g.
31666  iTemp13 is allocated to a pseudo register CC which tells the back end that
31667  the temporary is used only for a conditional jump the code generation makes
31668  use of this information to optimize a compare and jump ICode.
31669 \newline 
31670 There are several loop optimizations
31671 \begin_inset LatexCommand \index{Loop optimization}
31672
31673 \end_inset 
31674
31675  performed by the compiler.
31676  It can detect induction variables iTemp21(i) and iTemp23(j).
31677  Also note the compiler does selective strength reduction
31678 \begin_inset LatexCommand \index{Strength reduction}
31679
31680 \end_inset 
31681
31682 , i.e.
31683  the multiplication of an induction variable in line 18 (gint = j * 3) is
31684  changed to addition, a new temporary iTemp17 is allocated and assigned
31685  a initial value, a constant 3 is then added for each iteration of the loop.
31686  The compiler does not change the multiplication
31687 \begin_inset LatexCommand \index{Multiplication}
31688
31689 \end_inset 
31690
31691  in line 17 however since the processor does support an 8 * 8 bit multiplication.
31692 \newline 
31693 Note the dead code elimination
31694 \begin_inset LatexCommand \index{Dead-code elimination}
31695
31696 \end_inset 
31697
31698  optimization eliminated the dead assignments in line 7 & 8 to I and sum
31699  respectively.
31700 \newline 
31701
31702 \layout Standard
31703
31704
31705 \size footnotesize 
31706 Sample.c (5:1:0:0) _entry($9) :
31707 \layout Standard
31708
31709
31710 \size footnotesize 
31711 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
31712 \layout Standard
31713
31714
31715 \size footnotesize 
31716 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
31717 \layout Standard
31718
31719
31720 \size footnotesize 
31721 Sample.c(11:4:53:0) preHeaderLbl0($11) :
31722 \layout Standard
31723
31724
31725 \size footnotesize 
31726 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
31727  * int}[r2]
31728 \layout Standard
31729
31730
31731 \size footnotesize 
31732 Sample.c(11:6:5:1) _whilecontinue_0($1) :
31733 \layout Standard
31734
31735
31736 \size footnotesize 
31737 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
31738  int}[r0]]
31739 \layout Standard
31740
31741
31742 \size footnotesize 
31743 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
31744 \layout Standard
31745
31746
31747 \size footnotesize 
31748 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
31749  * int}
31750 \layout Standard
31751
31752
31753 \size footnotesize 
31754 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
31755  {short}
31756 \layout Standard
31757
31758
31759 \size footnotesize 
31760 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
31761  * int}[DPTR]]
31762 \layout Standard
31763
31764
31765 \size footnotesize 
31766 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
31767 }[r2 r3]
31768 \layout Standard
31769
31770
31771 \size footnotesize 
31772 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
31773  * int}[r0] + 0x2 {short}
31774 \layout Standard
31775
31776
31777 \size footnotesize 
31778 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
31779 \layout Standard
31780
31781
31782 \size footnotesize 
31783 Sample.c(11:17:21:0)_whilebreak_0($3) :
31784 \layout Standard
31785
31786
31787 \size footnotesize 
31788 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
31789 \layout Standard
31790
31791
31792 \size footnotesize 
31793 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
31794 \layout Standard
31795
31796
31797 \size footnotesize 
31798 Sample.c(15:20:54:0)preHeaderLbl1($13) :
31799 \layout Standard
31800
31801
31802 \size footnotesize 
31803 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
31804 \layout Standard
31805
31806
31807 \size footnotesize 
31808 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
31809 \layout Standard
31810
31811
31812 \size footnotesize 
31813 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
31814 \layout Standard
31815
31816
31817 \size footnotesize 
31818 Sample.c(15:24:26:1)_forcond_0($4) :
31819 \layout Standard
31820
31821
31822 \size footnotesize 
31823 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
31824  < 0xa {short}
31825 \layout Standard
31826
31827
31828 \size footnotesize 
31829 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
31830 \layout Standard
31831
31832
31833 \size footnotesize 
31834 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
31835  + ITemp21 [lr21:38]{short}[r4]
31836 \layout Standard
31837
31838
31839 \size footnotesize 
31840 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
31841  * 0x3 {short}
31842 \layout Standard
31843
31844
31845 \size footnotesize 
31846 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
31847  + iTemp15 [lr29:30]{short}[r1]
31848 \layout Standard
31849
31850
31851 \size footnotesize 
31852 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
31853  r0]- 0x3 {short}
31854 \layout Standard
31855
31856
31857 \size footnotesize 
31858 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
31859 int}[r7 r0]
31860 \layout Standard
31861
31862
31863 \size footnotesize 
31864 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
31865  + 0x1 {short}
31866 \layout Standard
31867
31868
31869 \size footnotesize 
31870 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
31871  r6]- 0x1 {short}
31872 \layout Standard
31873
31874
31875 \size footnotesize 
31876 Sample.c(19:38:47:1) goto _forcond_0($4)
31877 \layout Standard
31878
31879
31880 \size footnotesize 
31881 Sample.c(19:39:48:0)_forbreak_0($7) :
31882 \layout Standard
31883
31884
31885 \size footnotesize 
31886 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
31887  + ITemp11 [lr19:40]{short}[r3]
31888 \layout Standard
31889
31890
31891 \size footnotesize 
31892 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
31893 \layout Standard
31894
31895
31896 \size footnotesize 
31897 Sample.c(20:42:51:0)_return($8) :
31898 \layout Standard
31899
31900
31901 \size footnotesize 
31902 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
31903 \size default 
31904
31905 \newline 
31906
31907 \newline 
31908 Finally the code generated for this function:
31909 \newline 
31910
31911 \layout Standard
31912
31913
31914 \size footnotesize 
31915 .area DSEG (DATA)
31916 \layout Standard
31917
31918
31919 \size footnotesize 
31920 _p::
31921 \layout Standard
31922
31923
31924 \size footnotesize 
31925 \SpecialChar ~
31926 \SpecialChar ~
31927 .ds 2
31928 \layout Standard
31929
31930
31931 \size footnotesize 
31932 _gint::
31933 \layout Standard
31934
31935
31936 \size footnotesize 
31937 \SpecialChar ~
31938 \SpecialChar ~
31939 .ds 2
31940 \layout Standard
31941
31942
31943 \size footnotesize 
31944 ; sample.c 5
31945 \layout Standard
31946
31947
31948 \size footnotesize 
31949 ; ----------------------------------------------
31950 \layout Standard
31951
31952
31953 \size footnotesize 
31954 ; function function
31955 \layout Standard
31956
31957
31958 \size footnotesize 
31959 ; ----------------------------------------------
31960 \layout Standard
31961
31962
31963 \size footnotesize 
31964 _function:
31965 \layout Standard
31966
31967
31968 \size footnotesize 
31969 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
31970 \layout Standard
31971
31972
31973 \size footnotesize 
31974 \SpecialChar ~
31975 \SpecialChar ~
31976 mov r2,dpl
31977 \layout Standard
31978
31979
31980 \size footnotesize 
31981 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
31982 \layout Standard
31983
31984
31985 \size footnotesize 
31986 \SpecialChar ~
31987 \SpecialChar ~
31988 mov ar0,r2
31989 \layout Standard
31990
31991
31992 \size footnotesize 
31993 ;_whilecontinue_0($1) :
31994 \layout Standard
31995
31996
31997 \size footnotesize 
31998 00101$:
31999 \layout Standard
32000
32001
32002 \size footnotesize 
32003 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
32004 \layout Standard
32005
32006
32007 \size footnotesize 
32008 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32009 \layout Standard
32010
32011
32012 \size footnotesize 
32013 \SpecialChar ~
32014 \SpecialChar ~
32015 mov ar2,@r0
32016 \layout Standard
32017
32018
32019 \size footnotesize 
32020 \SpecialChar ~
32021 \SpecialChar ~
32022 inc r0
32023 \layout Standard
32024
32025
32026 \size footnotesize 
32027 \SpecialChar ~
32028 \SpecialChar ~
32029 mov ar3,@r0
32030 \layout Standard
32031
32032
32033 \size footnotesize 
32034 \SpecialChar ~
32035 \SpecialChar ~
32036 dec r0
32037 \layout Standard
32038
32039
32040 \size footnotesize 
32041 \SpecialChar ~
32042 \SpecialChar ~
32043 mov a,r2
32044 \layout Standard
32045
32046
32047 \size footnotesize 
32048 \SpecialChar ~
32049 \SpecialChar ~
32050 orl a,r3
32051 \layout Standard
32052
32053
32054 \size footnotesize 
32055 \SpecialChar ~
32056 \SpecialChar ~
32057 jz 00103$
32058 \layout Standard
32059
32060
32061 \size footnotesize 
32062 00114$:
32063 \layout Standard
32064
32065
32066 \size footnotesize 
32067 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
32068 \layout Standard
32069
32070
32071 \size footnotesize 
32072 \SpecialChar ~
32073 \SpecialChar ~
32074 mov dpl,_p
32075 \layout Standard
32076
32077
32078 \size footnotesize 
32079 \SpecialChar ~
32080 \SpecialChar ~
32081 mov dph,(_p + 1)
32082 \layout Standard
32083
32084
32085 \size footnotesize 
32086 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
32087 \layout Standard
32088
32089
32090 \size footnotesize 
32091 \SpecialChar ~
32092 \SpecialChar ~
32093 mov a,#0x02
32094 \layout Standard
32095
32096
32097 \size footnotesize 
32098 \SpecialChar ~
32099 \SpecialChar ~
32100 add a,_p
32101 \layout Standard
32102
32103
32104 \size footnotesize 
32105 \SpecialChar ~
32106 \SpecialChar ~
32107 mov _p,a
32108 \layout Standard
32109
32110
32111 \size footnotesize 
32112 \SpecialChar ~
32113 \SpecialChar ~
32114 clr a
32115 \layout Standard
32116
32117
32118 \size footnotesize 
32119 \SpecialChar ~
32120 \SpecialChar ~
32121 addc a,(_p + 1)
32122 \layout Standard
32123
32124
32125 \size footnotesize 
32126 \SpecialChar ~
32127 \SpecialChar ~
32128 mov (_p + 1),a
32129 \layout Standard
32130
32131
32132 \size footnotesize 
32133 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
32134 \layout Standard
32135
32136
32137 \size footnotesize 
32138 \SpecialChar ~
32139 \SpecialChar ~
32140 movx a,@dptr
32141 \layout Standard
32142
32143
32144 \size footnotesize 
32145 \SpecialChar ~
32146 \SpecialChar ~
32147 mov r2,a
32148 \layout Standard
32149
32150
32151 \size footnotesize 
32152 \SpecialChar ~
32153 \SpecialChar ~
32154 inc dptr
32155 \layout Standard
32156
32157
32158 \size footnotesize 
32159 \SpecialChar ~
32160 \SpecialChar ~
32161 movx a,@dptr
32162 \layout Standard
32163
32164
32165 \size footnotesize 
32166 \SpecialChar ~
32167 \SpecialChar ~
32168 mov r3,a
32169 \layout Standard
32170
32171
32172 \size footnotesize 
32173 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
32174 \layout Standard
32175
32176
32177 \size footnotesize 
32178 \SpecialChar ~
32179 \SpecialChar ~
32180 mov @r0,ar2
32181 \layout Standard
32182
32183
32184 \size footnotesize 
32185 \SpecialChar ~
32186 \SpecialChar ~
32187 inc r0
32188 \layout Standard
32189
32190
32191 \size footnotesize 
32192 \SpecialChar ~
32193 \SpecialChar ~
32194 mov @r0,ar3
32195 \layout Standard
32196
32197
32198 \size footnotesize 
32199 ; iTemp6 [lr5:16]{_near * int}[r0] = 
32200 \layout Standard
32201
32202
32203 \size footnotesize 
32204 ; iTemp6 [lr5:16]{_near * int}[r0] + 
32205 \layout Standard
32206
32207
32208 \size footnotesize 
32209 ; 0x2 {short}
32210 \layout Standard
32211
32212
32213 \size footnotesize 
32214 \SpecialChar ~
32215 \SpecialChar ~
32216 inc r0
32217 \layout Standard
32218
32219
32220 \size footnotesize 
32221 ; goto _whilecontinue_0($1)
32222 \layout Standard
32223
32224
32225 \size footnotesize 
32226 \SpecialChar ~
32227 \SpecialChar ~
32228 sjmp 00101$
32229 \layout Standard
32230
32231
32232 \size footnotesize 
32233 ; _whilebreak_0($3) :
32234 \layout Standard
32235
32236
32237 \size footnotesize 
32238 00103$:
32239 \layout Standard
32240
32241
32242 \size footnotesize 
32243 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32244 \layout Standard
32245
32246
32247 \size footnotesize 
32248 \SpecialChar ~
32249 \SpecialChar ~
32250 mov r2,#0x00
32251 \layout Standard
32252
32253
32254 \size footnotesize 
32255 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32256 \layout Standard
32257
32258
32259 \size footnotesize 
32260 \SpecialChar ~
32261 \SpecialChar ~
32262 mov r3,#0x00
32263 \layout Standard
32264
32265
32266 \size footnotesize 
32267 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32268 \layout Standard
32269
32270
32271 \size footnotesize 
32272 \SpecialChar ~
32273 \SpecialChar ~
32274 mov r4,#0x00
32275 \layout Standard
32276
32277
32278 \size footnotesize 
32279 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32280 \layout Standard
32281
32282
32283 \size footnotesize 
32284 \SpecialChar ~
32285 \SpecialChar ~
32286 mov r5,#0x0A
32287 \layout Standard
32288
32289
32290 \size footnotesize 
32291 \SpecialChar ~
32292 \SpecialChar ~
32293 mov r6,#0x00
32294 \layout Standard
32295
32296
32297 \size footnotesize 
32298 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32299 \layout Standard
32300
32301
32302 \size footnotesize 
32303 \SpecialChar ~
32304 \SpecialChar ~
32305 mov r7,#0x1E
32306 \layout Standard
32307
32308
32309 \size footnotesize 
32310 \SpecialChar ~
32311 \SpecialChar ~
32312 mov r0,#0x00
32313 \layout Standard
32314
32315
32316 \size footnotesize 
32317 ; _forcond_0($4) :
32318 \layout Standard
32319
32320
32321 \size footnotesize 
32322 00104$:
32323 \layout Standard
32324
32325
32326 \size footnotesize 
32327 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
32328 \layout Standard
32329
32330
32331 \size footnotesize 
32332 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32333 \layout Standard
32334
32335
32336 \size footnotesize 
32337 \SpecialChar ~
32338 \SpecialChar ~
32339 clr c
32340 \layout Standard
32341
32342
32343 \size footnotesize 
32344 \SpecialChar ~
32345 \SpecialChar ~
32346 mov a,r4
32347 \layout Standard
32348
32349
32350 \size footnotesize 
32351 \SpecialChar ~
32352 \SpecialChar ~
32353 xrl a,#0x80
32354 \layout Standard
32355
32356
32357 \size footnotesize 
32358 \SpecialChar ~
32359 \SpecialChar ~
32360 subb a,#0x8a
32361 \layout Standard
32362
32363
32364 \size footnotesize 
32365 \SpecialChar ~
32366 \SpecialChar ~
32367 jnc 00107$
32368 \layout Standard
32369
32370
32371 \size footnotesize 
32372 00115$:
32373 \layout Standard
32374
32375
32376 \size footnotesize 
32377 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
32378 \layout Standard
32379
32380
32381 \size footnotesize 
32382 ; iTemp21 [lr21:38]{short}[r4]
32383 \layout Standard
32384
32385
32386 \size footnotesize 
32387 \SpecialChar ~
32388 \SpecialChar ~
32389 mov a,r4
32390 \layout Standard
32391
32392
32393 \size footnotesize 
32394 \SpecialChar ~
32395 \SpecialChar ~
32396 add a,r2
32397 \layout Standard
32398
32399
32400 \size footnotesize 
32401 \SpecialChar ~
32402 \SpecialChar ~
32403 mov r2,a
32404 \layout Standard
32405
32406
32407 \size footnotesize 
32408 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
32409 \layout Standard
32410
32411
32412 \size footnotesize 
32413 \SpecialChar ~
32414 \SpecialChar ~
32415 mov b,#0x03
32416 \layout Standard
32417
32418
32419 \size footnotesize 
32420 \SpecialChar ~
32421 \SpecialChar ~
32422 mov a,r4
32423 \layout Standard
32424
32425
32426 \size footnotesize 
32427 \SpecialChar ~
32428 \SpecialChar ~
32429 mul ab
32430 \layout Standard
32431
32432
32433 \size footnotesize 
32434 \SpecialChar ~
32435 \SpecialChar ~
32436 mov r1,a
32437 \layout Standard
32438
32439
32440 \size footnotesize 
32441 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
32442 \layout Standard
32443
32444
32445 \size footnotesize 
32446 ; iTemp15 [lr29:30]{short}[r1]
32447 \layout Standard
32448
32449
32450 \size footnotesize 
32451 \SpecialChar ~
32452 \SpecialChar ~
32453 add a,r3
32454 \layout Standard
32455
32456
32457 \size footnotesize 
32458 \SpecialChar ~
32459 \SpecialChar ~
32460 mov r3,a
32461 \layout Standard
32462
32463
32464 \size footnotesize 
32465 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
32466 \layout Standard
32467
32468
32469 \size footnotesize 
32470 \SpecialChar ~
32471 \SpecialChar ~
32472 mov a,r7
32473 \layout Standard
32474
32475
32476 \size footnotesize 
32477 \SpecialChar ~
32478 \SpecialChar ~
32479 add a,#0xfd
32480 \layout Standard
32481
32482
32483 \size footnotesize 
32484 \SpecialChar ~
32485 \SpecialChar ~
32486 mov r7,a
32487 \layout Standard
32488
32489
32490 \size footnotesize 
32491 \SpecialChar ~
32492 \SpecialChar ~
32493 mov a,r0
32494 \layout Standard
32495
32496
32497 \size footnotesize 
32498 \SpecialChar ~
32499 \SpecialChar ~
32500 addc a,#0xff
32501 \layout Standard
32502
32503
32504 \size footnotesize 
32505 \SpecialChar ~
32506 \SpecialChar ~
32507 mov r0,a
32508 \layout Standard
32509
32510
32511 \size footnotesize 
32512 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
32513 \layout Standard
32514
32515
32516 \size footnotesize 
32517 \SpecialChar ~
32518 \SpecialChar ~
32519 mov a,r7
32520 \layout Standard
32521
32522
32523 \size footnotesize 
32524 \SpecialChar ~
32525 \SpecialChar ~
32526 add a,_gint
32527 \layout Standard
32528
32529
32530 \size footnotesize 
32531 \SpecialChar ~
32532 \SpecialChar ~
32533 mov _gint,a
32534 \layout Standard
32535
32536
32537 \size footnotesize 
32538 \SpecialChar ~
32539 \SpecialChar ~
32540 mov a,r0
32541 \layout Standard
32542
32543
32544 \size footnotesize 
32545 \SpecialChar ~
32546 \SpecialChar ~
32547 addc a,(_gint + 1)
32548 \layout Standard
32549
32550
32551 \size footnotesize 
32552 \SpecialChar ~
32553 \SpecialChar ~
32554 mov (_gint + 1),a
32555 \layout Standard
32556
32557
32558 \size footnotesize 
32559 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
32560 \layout Standard
32561
32562
32563 \size footnotesize 
32564 \SpecialChar ~
32565 \SpecialChar ~
32566 inc r4
32567 \layout Standard
32568
32569
32570 \size footnotesize 
32571 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
32572 \layout Standard
32573
32574
32575 \size footnotesize 
32576 \SpecialChar ~
32577 \SpecialChar ~
32578 dec r5
32579 \layout Standard
32580
32581
32582 \size footnotesize 
32583 \SpecialChar ~
32584 \SpecialChar ~
32585 cjne r5,#0xff,00104$
32586 \layout Standard
32587
32588
32589 \size footnotesize 
32590 \SpecialChar ~
32591 \SpecialChar ~
32592 dec r6
32593 \layout Standard
32594
32595
32596 \size footnotesize 
32597 ; goto _forcond_0($4)
32598 \layout Standard
32599
32600
32601 \size footnotesize 
32602 \SpecialChar ~
32603 \SpecialChar ~
32604 sjmp 00104$
32605 \layout Standard
32606
32607
32608 \size footnotesize 
32609 ; _forbreak_0($7) :
32610 \layout Standard
32611
32612
32613 \size footnotesize 
32614 00107$:
32615 \layout Standard
32616
32617
32618 \size footnotesize 
32619 ; ret iTemp24 [lr40:41]{short}
32620 \layout Standard
32621
32622
32623 \size footnotesize 
32624 \SpecialChar ~
32625 \SpecialChar ~
32626 mov a,r3
32627 \layout Standard
32628
32629
32630 \size footnotesize 
32631 \SpecialChar ~
32632 \SpecialChar ~
32633 add a,r2
32634 \layout Standard
32635
32636
32637 \size footnotesize 
32638 \SpecialChar ~
32639 \SpecialChar ~
32640 mov dpl,a
32641 \layout Standard
32642
32643
32644 \size footnotesize 
32645 ; _return($8) :
32646 \layout Standard
32647
32648
32649 \size footnotesize 
32650 00108$:
32651 \layout Standard
32652
32653
32654 \size footnotesize 
32655 \SpecialChar ~
32656 \SpecialChar ~
32657 ret
32658 \newline 
32659
32660 \layout Section
32661
32662 A few words about basic block successors, predecessors and dominators
32663 \layout Standard
32664
32665 Successors are basic blocks
32666 \begin_inset LatexCommand \index{Basic blocks}
32667
32668 \end_inset 
32669
32670  that might execute after this basic block.
32671 \newline 
32672 Predecessors are basic blocks that might execute before reaching this basic
32673  block.
32674 \newline 
32675 Dominators are basic blocks that WILL execute before reaching this basic
32676  block.
32677 \newline 
32678
32679 \layout Standard
32680
32681 [basic block 1]
32682 \layout Standard
32683
32684 if (something)
32685 \layout Standard
32686
32687 \SpecialChar ~
32688 \SpecialChar ~
32689 \SpecialChar ~
32690 \SpecialChar ~
32691 [basic block 2]
32692 \layout Standard
32693
32694 else
32695 \layout Standard
32696
32697 \SpecialChar ~
32698 \SpecialChar ~
32699 \SpecialChar ~
32700 \SpecialChar ~
32701 [basic block 3]
32702 \layout Standard
32703
32704 [basic block 4]
32705 \newline 
32706
32707 \layout Standard
32708
32709 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
32710 \layout Standard
32711
32712 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
32713 \layout Standard
32714
32715 c) domVect of [BB4] = BB1 ...
32716  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
32717  was executed.
32718 \layout Chapter
32719
32720 Acknowledgments
32721 \layout Standard
32722
32723
32724 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
32725
32726 \end_inset 
32727
32728
32729 \newline 
32730
32731 \newline 
32732
32733 \emph on 
32734 Thanks to all the other volunteer developers who have helped with coding,
32735  testing, web-page creation, distribution sets, etc.
32736  You know who you are :-)
32737 \emph default 
32738
32739 \newline 
32740
32741 \newline 
32742
32743 \emph on 
32744 Also thanks to Sourceforge 
32745 \begin_inset LatexCommand \url{http://www.sf.net}
32746
32747 \end_inset 
32748
32749  which has hosted the project since 1999 and donates significant download
32750  bandwidth and probably more than 
32751 \begin_inset ERT
32752 status Collapsed
32753
32754 \layout Standard
32755 $10^{13}$
32756 \end_inset 
32757
32758 CPU cycles per day.
32759 \newline 
32760  
32761 \begin_inset Note
32762 collapsed false
32763
32764 \layout Standard
32765
32766 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
32767  minutes for (configure+make+regression test), and there is (i386, amd64,
32768  alpha, ppc64, (mingw32), sparc, macosx).
32769  
32770 \end_inset 
32771
32772
32773 \layout Standard
32774
32775 This document was initially written by Sandeep Dutta
32776 \layout Standard
32777
32778 All product names mentioned herein may be trademarks
32779 \begin_inset LatexCommand \index{Trademarks}
32780
32781 \end_inset 
32782
32783  of their respective companies.
32784  
32785 \layout Section*
32786
32787 Alphabetical index
32788 \layout Standard
32789
32790 To avoid confusion, the installation and building options for SDCC itself
32791  (chapter 2) are not part of the index.
32792 \layout Standard
32793
32794
32795 \begin_inset LatexCommand \printindex{}
32796
32797 \end_inset 
32798
32799
32800 \the_end