* doc/sdccman.lyx: fixed format errors
[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 \labelwidthstring 00.00.0000
6126
6127
6128 \series bold 
6129 -pedantic-parse-number
6130 \begin_inset LatexCommand \index{-pedantic-parse-number}
6131
6132 \end_inset 
6133
6134
6135 \size large 
6136 \bar under 
6137  
6138 \series default 
6139 \size default 
6140 \bar default 
6141 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6142  and the macro LO_B(3) gets expanded.
6143  See also #pragma pedantic_parse_number in section
6144 \begin_inset LatexCommand \ref{sec:Pragmas}
6145
6146 \end_inset 
6147
6148  
6149 \emph on 
6150 Note: this functionality is not in conformance with standard!
6151 \layout List
6152 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6153
6154
6155 \series bold 
6156 -Wp\SpecialChar ~
6157 preprocessorOption[,preprocessorOption]
6158 \series default 
6159
6160 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6161
6162 \end_inset 
6163
6164 ...
6165  Pass the preprocessorOption to the preprocessor 
6166 \family typewriter 
6167 sdcpp
6168 \family default 
6169
6170 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6171
6172 \end_inset 
6173
6174 .
6175  SDCC uses an adapted version of the preprocessor 
6176 \emph on 
6177 cpp
6178 \emph default 
6179  of the GNU Compiler Collection
6180 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6181
6182 \end_inset 
6183
6184  (
6185 \emph on 
6186 gcc
6187 \emph default 
6188  
6189 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6190
6191 \end_inset 
6192
6193 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6194 4.1.1\SpecialChar ~
6195 CPP\SpecialChar ~
6196 Manual
6197  at 
6198 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6199
6200 \end_inset 
6201
6202 .
6203 \layout Subsection
6204
6205 Linker Options
6206 \begin_inset LatexCommand \index{Options linker}
6207
6208 \end_inset 
6209
6210
6211 \begin_inset LatexCommand \index{Linker options}
6212
6213 \end_inset 
6214
6215
6216 \layout List
6217 \labelwidthstring 00.00.0000
6218
6219
6220 \series bold 
6221 -L\SpecialChar ~
6222 -
6223 \series default 
6224
6225 \begin_inset ERT
6226 status Collapsed
6227
6228 \layout Standard
6229
6230 \backslash 
6231 /
6232 \end_inset 
6233
6234
6235 \series bold 
6236 -lib-path
6237 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6238
6239 \end_inset 
6240
6241
6242 \begin_inset LatexCommand \index{-L -\/-lib-path}
6243
6244 \end_inset 
6245
6246
6247 \series default 
6248 \SpecialChar ~
6249 <absolute path to additional libraries> This option is passed to the linkage
6250  editor's additional libraries
6251 \begin_inset LatexCommand \index{Libraries}
6252
6253 \end_inset 
6254
6255  search path.
6256  The path name must be absolute.
6257  Additional library files may be specified in the command line.
6258  See section Compiling programs for more details.
6259 \layout List
6260 \labelwidthstring 00.00.0000
6261
6262
6263 \series bold 
6264 -
6265 \begin_inset ERT
6266 status Collapsed
6267
6268 \layout Standard
6269
6270 \backslash 
6271 /
6272 \end_inset 
6273
6274 -xram-loc
6275 \series default 
6276
6277 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6278
6279 \end_inset 
6280
6281 \SpecialChar ~
6282 <Value> The start location of the external ram
6283 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6284
6285 \end_inset 
6286
6287 , default value is 0.
6288  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6289 \begin_inset ERT
6290 status Collapsed
6291
6292 \layout Standard
6293
6294 \backslash 
6295 /
6296 \end_inset 
6297
6298 -xram-loc 0x8000 or -
6299 \begin_inset ERT
6300 status Collapsed
6301
6302 \layout Standard
6303
6304 \backslash 
6305 /
6306 \end_inset 
6307
6308 -xram-loc 32768.
6309 \layout List
6310 \labelwidthstring 00.00.0000
6311
6312
6313 \series bold 
6314 -
6315 \begin_inset ERT
6316 status Collapsed
6317
6318 \layout Standard
6319
6320 \backslash 
6321 /
6322 \end_inset 
6323
6324 -code-loc
6325 \series default 
6326
6327 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6328
6329 \end_inset 
6330
6331 \SpecialChar ~
6332 <Value> The start location of the code
6333 \begin_inset LatexCommand \index{code}
6334
6335 \end_inset 
6336
6337  segment, default value 0.
6338  Note when this option is used the interrupt vector table
6339 \begin_inset LatexCommand \index{interrupt vector table}
6340
6341 \end_inset 
6342
6343  is also relocated to the given address.
6344  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6345 \begin_inset ERT
6346 status Collapsed
6347
6348 \layout Standard
6349
6350 \backslash 
6351 /
6352 \end_inset 
6353
6354 -code-loc 0x8000 or -
6355 \begin_inset ERT
6356 status Collapsed
6357
6358 \layout Standard
6359
6360 \backslash 
6361 /
6362 \end_inset 
6363
6364 -code-loc 32768.
6365 \layout List
6366 \labelwidthstring 00.00.0000
6367
6368
6369 \series bold 
6370 -
6371 \begin_inset ERT
6372 status Collapsed
6373
6374 \layout Standard
6375
6376 \backslash 
6377 /
6378 \end_inset 
6379
6380 -stack-loc
6381 \series default 
6382
6383 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6384
6385 \end_inset 
6386
6387 \SpecialChar ~
6388 <Value> By default the stack
6389 \begin_inset LatexCommand \index{stack}
6390
6391 \end_inset 
6392
6393  is placed after the data segment.
6394  Using this option the stack can be placed anywhere in the internal memory
6395  space of the 8051.
6396  The value entered can be in Hexadecimal or Decimal format, e.g.
6397  -
6398 \begin_inset ERT
6399 status Collapsed
6400
6401 \layout Standard
6402
6403 \backslash 
6404 /
6405 \end_inset 
6406
6407 -stack-loc 0x20 or -
6408 \begin_inset ERT
6409 status Collapsed
6410
6411 \layout Standard
6412
6413 \backslash 
6414 /
6415 \end_inset 
6416
6417 -stack-loc 32.
6418  Since the sp register is incremented before a push or call, the initial
6419  sp will be set to one byte prior the provided value.
6420  The provided value should not overlap any other memory areas such as used
6421  register banks or the data segment and with enough space for the current
6422  application.
6423  The 
6424 \series bold 
6425 -
6426 \begin_inset ERT
6427 status Collapsed
6428
6429 \layout Standard
6430
6431 \backslash 
6432 /
6433 \end_inset 
6434
6435 -pack-iram
6436 \series default 
6437 \SpecialChar ~
6438
6439 \begin_inset LatexCommand \index{-\/-pack-iram}
6440
6441 \end_inset 
6442
6443  option (which is now a default setting) will override this setting, so
6444  you should also specify the 
6445 \series bold 
6446 -
6447 \begin_inset ERT
6448 status Collapsed
6449
6450 \layout Standard
6451
6452 \backslash 
6453 /
6454 \end_inset 
6455
6456 -no-pack-iram
6457 \series default 
6458 \SpecialChar ~
6459
6460 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6461
6462 \end_inset 
6463
6464  option if you need to manually place the stack.
6465 \layout List
6466 \labelwidthstring 00.00.0000
6467
6468
6469 \series bold 
6470 -
6471 \begin_inset ERT
6472 status Collapsed
6473
6474 \layout Standard
6475
6476 \backslash 
6477 /
6478 \end_inset 
6479
6480 -xstack-loc
6481 \series default 
6482
6483 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6484
6485 \end_inset 
6486
6487 \SpecialChar ~
6488 <Value> By default the external stack
6489 \begin_inset LatexCommand \index{xstack}
6490
6491 \end_inset 
6492
6493  is placed after the pdata
6494 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6495
6496 \end_inset 
6497
6498  segment.
6499  Using this option the xstack can be placed anywhere in the external memory
6500  space of the 8051.
6501  The value entered can be in Hexadecimal or Decimal format, e.g.
6502  -
6503 \begin_inset ERT
6504 status Collapsed
6505
6506 \layout Standard
6507
6508 \backslash 
6509 /
6510 \end_inset 
6511
6512 -xstack-loc 0x8000 or -
6513 \begin_inset ERT
6514 status Collapsed
6515
6516 \layout Standard
6517
6518 \backslash 
6519 /
6520 \end_inset 
6521
6522 -stack-loc 32768.
6523  The provided value should not overlap any other memory areas such as the
6524  pdata or xdata segment and with enough space for the current application.
6525 \layout List
6526 \labelwidthstring 00.00.0000
6527
6528
6529 \series bold 
6530 -
6531 \begin_inset ERT
6532 status Collapsed
6533
6534 \layout Standard
6535
6536 \backslash 
6537 /
6538 \end_inset 
6539
6540 -data-loc
6541 \series default 
6542
6543 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6544
6545 \end_inset 
6546
6547 \SpecialChar ~
6548 <Value> The start location of the internal ram data
6549 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6550
6551 \end_inset 
6552
6553  segment.
6554  The value entered can be in Hexadecimal or Decimal format, eg.
6555  -
6556 \begin_inset ERT
6557 status Collapsed
6558
6559 \layout Standard
6560
6561 \backslash 
6562 /
6563 \end_inset 
6564
6565 -data-loc 0x20 or -
6566 \begin_inset ERT
6567 status Collapsed
6568
6569 \layout Standard
6570
6571 \backslash 
6572 /
6573 \end_inset 
6574
6575 -data-loc 32.
6576  (By default, the start location of the internal ram data segment  is set
6577  as low as possible in memory, taking into account the used register banks
6578  and the bit segment at address 0x20.
6579  For example if register banks 0 and 1 are used without bit variables, the
6580  data segment will be set, if -
6581 \begin_inset ERT
6582 status Collapsed
6583
6584 \layout Standard
6585
6586 \backslash 
6587 /
6588 \end_inset 
6589
6590 -data-loc is not used, to location 0x10.)
6591 \layout List
6592 \labelwidthstring 00.00.0000
6593
6594
6595 \series bold 
6596 -
6597 \begin_inset ERT
6598 status Collapsed
6599
6600 \layout Standard
6601
6602 \backslash 
6603 /
6604 \end_inset 
6605
6606 -idata-loc
6607 \series default 
6608
6609 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6610
6611 \end_inset 
6612
6613 \SpecialChar ~
6614 <Value> The start location of the indirectly addressable internal ram
6615 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6616
6617 \end_inset 
6618
6619  of the 8051, default value is 0x80.
6620  The value entered can be in Hexadecimal or Decimal format, eg.
6621  -
6622 \begin_inset ERT
6623 status Collapsed
6624
6625 \layout Standard
6626
6627 \backslash 
6628 /
6629 \end_inset 
6630
6631 -idata-loc 0x88 or -
6632 \begin_inset ERT
6633 status Collapsed
6634
6635 \layout Standard
6636
6637 \backslash 
6638 /
6639 \end_inset 
6640
6641 -idata-loc 136.
6642 \layout List
6643 \labelwidthstring 00.00.0000
6644
6645
6646 \series bold 
6647 -
6648 \begin_inset ERT
6649 status Collapsed
6650
6651 \layout Standard
6652
6653 \backslash 
6654 /
6655 \end_inset 
6656
6657 -bit-loc
6658 \series default 
6659 \SpecialChar ~
6660 <Value> The start location of the bit
6661 \begin_inset LatexCommand \index{bit}
6662
6663 \end_inset 
6664
6665  addressable internal ram of the 8051.
6666  This is 
6667 \emph on 
6668 not
6669 \emph default 
6670  implemented yet.
6671  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6672 -bBSEG=<Value>.
6673 \layout List
6674 \labelwidthstring 00.00.0000
6675
6676
6677 \series bold 
6678 -
6679 \begin_inset ERT
6680 status Collapsed
6681
6682 \layout Standard
6683
6684 \backslash 
6685 /
6686 \end_inset 
6687
6688 -out-fmt-ihx
6689 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6690
6691 \end_inset 
6692
6693
6694 \bar under 
6695  
6696 \series default 
6697 \bar default 
6698 The linker output (final object code) is in Intel Hex format.
6699 \begin_inset LatexCommand \index{Intel hex format}
6700
6701 \end_inset 
6702
6703  This is the default option.
6704  The format itself is documented in the documentation of srecord
6705 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6706
6707 \end_inset 
6708
6709 .
6710 \layout List
6711 \labelwidthstring 00.00.0000
6712
6713
6714 \series bold 
6715 -
6716 \begin_inset ERT
6717 status Collapsed
6718
6719 \layout Standard
6720
6721 \backslash 
6722 /
6723 \end_inset 
6724
6725 -out-fmt-s19
6726 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6727
6728 \end_inset 
6729
6730
6731 \bar under 
6732  
6733 \series default 
6734 \bar default 
6735 The linker output (final object code) is in Motorola S19 format
6736 \begin_inset LatexCommand \index{Motorola S19 format}
6737
6738 \end_inset 
6739
6740 .
6741  The format itself is documented in the documentation of srecord.
6742 \layout List
6743 \labelwidthstring 00.00.0000
6744
6745
6746 \series bold 
6747 -
6748 \begin_inset ERT
6749 status Collapsed
6750
6751 \layout Standard
6752
6753 \backslash 
6754 /
6755 \end_inset 
6756
6757 -out-fmt-elf
6758 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6759
6760 \end_inset 
6761
6762
6763 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6764
6765 \end_inset 
6766
6767
6768 \bar under 
6769  
6770 \series default 
6771 \bar default 
6772 The linker output (final object code) is in ELF format
6773 \begin_inset LatexCommand \index{ELF format}
6774
6775 \end_inset 
6776
6777 .
6778  (Currently only supported for the HC08
6779 \begin_inset LatexCommand \index{HC08}
6780
6781 \end_inset 
6782
6783  processors)
6784 \layout List
6785 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6786
6787
6788 \series bold 
6789 -Wl\SpecialChar ~
6790 linkOption[,linkOption]
6791 \series default 
6792
6793 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6794
6795 \end_inset 
6796
6797 ...
6798  Pass the linkOption to the linker.
6799  If a bootloader is used an option like 
6800 \begin_inset Quotes sld
6801 \end_inset 
6802
6803 -Wl\SpecialChar ~
6804 -bCSEG=0x1000
6805 \begin_inset Quotes srd
6806 \end_inset 
6807
6808  would be typical to set the start of the code segment.
6809  See also #pragma constseg and #pragma codeseg in section 
6810 \begin_inset LatexCommand \ref{sec:Pragmas}
6811
6812 \end_inset 
6813
6814  .
6815  File sdcc/as/doc/asxhtm.html has more on linker options.
6816 \layout Subsection
6817
6818 MCS51 Options
6819 \begin_inset LatexCommand \index{Options MCS51}
6820
6821 \end_inset 
6822
6823
6824 \begin_inset LatexCommand \index{MCS51 options}
6825
6826 \end_inset 
6827
6828
6829 \layout List
6830 \labelwidthstring 00.00.0000
6831
6832
6833 \series bold 
6834 -
6835 \begin_inset ERT
6836 status Collapsed
6837
6838 \layout Standard
6839
6840 \backslash 
6841 /
6842 \end_inset 
6843
6844 -model-small
6845 \begin_inset LatexCommand \index{-\/-model-small}
6846
6847 \end_inset 
6848
6849
6850 \series default 
6851 \size large 
6852 \emph on 
6853  
6854 \size default 
6855 \emph default 
6856 Generate code for Small Model programs, see section Memory Models for more
6857  details.
6858  This is the default model.
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-medium
6875 \begin_inset LatexCommand \index{-\/-model-medium}
6876
6877 \end_inset 
6878
6879
6880 \series default 
6881  Generate code for Medium model programs, see section Memory Models for
6882  more 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 -model-large
6902 \begin_inset LatexCommand \index{-\/-model-large}
6903
6904 \end_inset 
6905
6906
6907 \series default 
6908  Generate code for Large model programs, see section Memory Models for more
6909  details.
6910  If this option is used all source files in the project have to be compiled
6911  with this option.
6912  It must also be used when invoking the linker.
6913 \layout List
6914 \labelwidthstring 00.00.0000
6915
6916
6917 \series bold 
6918 -
6919 \begin_inset ERT
6920 status Collapsed
6921
6922 \layout Standard
6923
6924 \backslash 
6925 /
6926 \end_inset 
6927
6928 -xstack
6929 \begin_inset LatexCommand \index{-\/-xstack}
6930
6931 \end_inset 
6932
6933
6934 \series default 
6935  Uses a pseudo stack in the pdata
6936 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6937
6938 \end_inset 
6939
6940  area (usually the first 256 bytes in the external ram) for allocating variables
6941  and passing parameters.
6942  See section 
6943 \begin_inset LatexCommand \ref{sub:External-Stack}
6944
6945 \end_inset 
6946
6947 \SpecialChar ~
6948  External Stack for more details.
6949 \layout List
6950 \labelwidthstring 00.00.0000
6951
6952
6953 \series bold 
6954 -
6955 \begin_inset ERT
6956 status Collapsed
6957
6958 \layout Standard
6959
6960 \backslash 
6961 /
6962 \end_inset 
6963
6964 -iram-size
6965 \series default 
6966 \SpecialChar ~
6967 <Value>
6968 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6969
6970 \end_inset 
6971
6972  Causes the linker to check if the internal ram usage is within limits of
6973  the given value.
6974 \layout List
6975 \labelwidthstring 00.00.0000
6976
6977
6978 \series bold 
6979 -
6980 \begin_inset ERT
6981 status Collapsed
6982
6983 \layout Standard
6984
6985 \backslash 
6986 /
6987 \end_inset 
6988
6989 -xram-size
6990 \series default 
6991 \SpecialChar ~
6992 <Value>
6993 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6994
6995 \end_inset 
6996
6997  Causes the linker to check if the external ram usage is within limits of
6998  the given value.
6999 \layout List
7000 \labelwidthstring 00.00.0000
7001
7002
7003 \series bold 
7004 -
7005 \begin_inset ERT
7006 status Collapsed
7007
7008 \layout Standard
7009
7010 \backslash 
7011 /
7012 \end_inset 
7013
7014 -code-size
7015 \series default 
7016 \SpecialChar ~
7017 <Value>
7018 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7019
7020 \end_inset 
7021
7022  Causes the linker to check if the code memory usage is within limits of
7023  the given value.
7024 \layout List
7025 \labelwidthstring 00.00.0000
7026
7027
7028 \series bold 
7029 -
7030 \begin_inset ERT
7031 status Collapsed
7032
7033 \layout Standard
7034
7035 \backslash 
7036 /
7037 \end_inset 
7038
7039 -stack-size
7040 \series default 
7041 \SpecialChar ~
7042 <Value>
7043 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7044
7045 \end_inset 
7046
7047  Causes the linker to check if there is at minimum <Value> bytes for stack.
7048 \layout List
7049 \labelwidthstring 00.00.0000
7050
7051
7052 \series bold 
7053 -
7054 \begin_inset ERT
7055 status Collapsed
7056
7057 \layout Standard
7058
7059 \backslash 
7060 /
7061 \end_inset 
7062
7063 -pack-iram
7064 \series default 
7065 \SpecialChar ~
7066
7067 \begin_inset LatexCommand \index{-\/-pack-iram}
7068
7069 \end_inset 
7070
7071  Causes the linker to use unused register banks for data variables and pack
7072  data, idata and stack together.
7073  This is the default now.
7074 \layout List
7075 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7076
7077
7078 \series bold 
7079 -
7080 \begin_inset ERT
7081 status Collapsed
7082
7083 \layout Standard
7084
7085 \backslash 
7086 /
7087 \end_inset 
7088
7089 -no-pack-iram
7090 \series default 
7091 \SpecialChar ~
7092
7093 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7094
7095 \end_inset 
7096
7097  Causes the linker to use old style for allocating memory areas.
7098 \layout Subsection
7099
7100 DS390 / DS400 Options
7101 \begin_inset LatexCommand \index{Options DS390}
7102
7103 \end_inset 
7104
7105
7106 \begin_inset LatexCommand \index{DS390}
7107
7108 \end_inset 
7109
7110
7111 \layout List
7112 \labelwidthstring 00.00.0000
7113
7114
7115 \series bold 
7116 -
7117 \begin_inset ERT
7118 status Collapsed
7119
7120 \layout Standard
7121
7122 \backslash 
7123 /
7124 \end_inset 
7125
7126 -model-flat24
7127 \series default 
7128
7129 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7130
7131 \end_inset 
7132
7133
7134 \size large 
7135 \emph on 
7136  
7137 \size default 
7138 \emph default 
7139 Generate 24-bit flat mode code.
7140  This is the one and only that the ds390 code generator supports right now
7141  and is default when using 
7142 \emph on 
7143 -mds390
7144 \emph default 
7145 .
7146  See section Memory Models for more details.
7147 \layout List
7148 \labelwidthstring 00.00.0000
7149
7150
7151 \series bold 
7152 -
7153 \begin_inset ERT
7154 status Collapsed
7155
7156 \layout Standard
7157
7158 \backslash 
7159 /
7160 \end_inset 
7161
7162 -protect-sp-update
7163 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7164
7165 \end_inset 
7166
7167
7168 \series default 
7169  disable interrupts during ESP:SP updates.
7170 \layout List
7171 \labelwidthstring 00.00.0000
7172
7173
7174 \series bold 
7175 -
7176 \begin_inset ERT
7177 status Collapsed
7178
7179 \layout Standard
7180
7181 \backslash 
7182 /
7183 \end_inset 
7184
7185 -stack-10bit
7186 \series default 
7187
7188 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7189
7190 \end_inset 
7191
7192  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7193  This is the one and only that the ds390 code generator supports right now
7194  and is default when using 
7195 \emph on 
7196 -mds390
7197 \emph default 
7198 .
7199  In this mode, the stack is located in the lower 1K of the internal RAM,
7200  which is mapped to 0x400000.
7201  Note that the support is incomplete, since it still uses a single byte
7202  as the stack pointer.
7203  This means that only the lower 256 bytes of the potential 1K stack space
7204  will actually be used.
7205  However, this does allow you to reclaim the precious 256 bytes of low RAM
7206  for use for the DATA and IDATA segments.
7207  The compiler will not generate any code to put the processor into 10 bit
7208  stack mode.
7209  It is important to ensure that the processor is in this mode before calling
7210  any re-entrant functions compiled with this option.
7211  In principle, this should work with the 
7212 \emph on 
7213 -
7214 \begin_inset ERT
7215 status Collapsed
7216
7217 \layout Standard
7218
7219 \backslash 
7220 /
7221 \end_inset 
7222
7223 -stack-auto
7224 \begin_inset LatexCommand \index{-\/-stack-auto}
7225
7226 \end_inset 
7227
7228
7229 \emph default 
7230  option, but that has not been tested.
7231  It is incompatible with the 
7232 \emph on 
7233 -
7234 \begin_inset ERT
7235 status Collapsed
7236
7237 \layout Standard
7238
7239 \backslash 
7240 /
7241 \end_inset 
7242
7243 -xstack
7244 \begin_inset LatexCommand \index{-\/-xstack}
7245
7246 \end_inset 
7247
7248
7249 \emph default 
7250  option.
7251  It also only makes sense if the processor is in 24 bit contiguous addressing
7252  mode (see the 
7253 \emph on 
7254 -
7255 \begin_inset ERT
7256 status Collapsed
7257
7258 \layout Standard
7259
7260 \backslash 
7261 /
7262 \end_inset 
7263
7264 -model-flat24 option
7265 \emph default 
7266 ).
7267 \layout List
7268 \labelwidthstring 00.00.0000
7269
7270
7271 \series bold 
7272 -
7273 \begin_inset ERT
7274 status Collapsed
7275
7276 \layout Standard
7277
7278 \backslash 
7279 /
7280 \end_inset 
7281
7282 -stack-probe
7283 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7284
7285 \end_inset 
7286
7287
7288 \series default 
7289  insert call to function __stack_probe at each function prologue.
7290 \layout List
7291 \labelwidthstring 00.00.0000
7292
7293
7294 \series bold 
7295 -
7296 \begin_inset ERT
7297 status Collapsed
7298
7299 \layout Standard
7300
7301 \backslash 
7302 /
7303 \end_inset 
7304
7305 -tini-libid
7306 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7307
7308 \end_inset 
7309
7310
7311 \series default 
7312  <nnnn> LibraryID used in -mTININative.
7313  
7314 \layout List
7315 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7316
7317
7318 \series bold 
7319 -
7320 \begin_inset ERT
7321 status Collapsed
7322
7323 \layout Standard
7324
7325 \backslash 
7326 /
7327 \end_inset 
7328
7329 -use-accelerator
7330 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7331
7332 \end_inset 
7333
7334
7335 \series default 
7336  generate code for DS390 Arithmetic Accelerator.
7337  
7338 \layout Subsection
7339
7340 Z80 Options
7341 \begin_inset LatexCommand \index{Options Z80}
7342
7343 \end_inset 
7344
7345
7346 \begin_inset LatexCommand \index{Z80}
7347
7348 \end_inset 
7349
7350
7351 \layout List
7352 \labelwidthstring 00.00.0000
7353
7354
7355 \series bold 
7356 -
7357 \begin_inset ERT
7358 status Collapsed
7359
7360 \layout Standard
7361
7362 \backslash 
7363 /
7364 \end_inset 
7365
7366 -callee-saves-bc
7367 \series default 
7368
7369 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7370
7371 \end_inset 
7372
7373
7374 \size large 
7375 \emph on 
7376  
7377 \size default 
7378 \emph default 
7379 Force a called function to always save BC.
7380 \layout List
7381 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7382
7383
7384 \series bold 
7385 -
7386 \begin_inset ERT
7387 status Collapsed
7388
7389 \layout Standard
7390
7391 \backslash 
7392 /
7393 \end_inset 
7394
7395 -no-std-crt0
7396 \series default 
7397
7398 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7399
7400 \end_inset 
7401
7402  When linking, skip the standard crt0.o object file.
7403  You must provide your own crt0.o for your system when linking.
7404  
7405 \layout Subsection
7406
7407 Optimization Options
7408 \begin_inset LatexCommand \index{Options optimization}
7409
7410 \end_inset 
7411
7412
7413 \begin_inset LatexCommand \index{Optimization options}
7414
7415 \end_inset 
7416
7417
7418 \layout List
7419 \labelwidthstring 00.00.0000
7420
7421
7422 \series bold 
7423 -
7424 \begin_inset ERT
7425 status Collapsed
7426
7427 \layout Standard
7428
7429 \backslash 
7430 /
7431 \end_inset 
7432
7433 -nogcse
7434 \begin_inset LatexCommand \index{-\/-nogcse}
7435
7436 \end_inset 
7437
7438
7439 \series default 
7440  Will not do global subexpression elimination, this option may be used when
7441  the compiler creates undesirably large stack/data spaces to store compiler
7442  temporaries (
7443 \emph on 
7444 s
7445 \emph default 
7446 pill 
7447 \emph on 
7448 loc
7449 \emph default 
7450 ations, sloc
7451 \begin_inset LatexCommand \index{sloc (spill location)}
7452
7453 \end_inset 
7454
7455 ).
7456  A warning message will be generated when this happens and the compiler
7457  will indicate the number of extra bytes it allocated.
7458  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7459 nogcse
7460 \begin_inset LatexCommand \index{\#pragma nogcse}
7461
7462 \end_inset 
7463
7464  can be used to turn off global subexpression elimination
7465 \begin_inset LatexCommand \index{Subexpression elimination}
7466
7467 \end_inset 
7468
7469  for a given function only.
7470 \layout List
7471 \labelwidthstring 00.00.0000
7472
7473
7474 \series bold 
7475 -
7476 \begin_inset ERT
7477 status Collapsed
7478
7479 \layout Standard
7480
7481 \backslash 
7482 /
7483 \end_inset 
7484
7485 -noinvariant
7486 \begin_inset LatexCommand \index{-\/-noinvariant}
7487
7488 \end_inset 
7489
7490
7491 \series default 
7492  Will not do loop invariant optimizations, this may be turned off for reasons
7493  explained for the previous option.
7494  For more details of loop optimizations performed see Loop Invariants in
7495  section 
7496 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7497
7498 \end_inset 
7499
7500 .
7501  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7502 noinvariant
7503 \begin_inset LatexCommand \index{\#pragma noinvariant}
7504
7505 \end_inset 
7506
7507  can be used to turn off invariant optimizations for a given function only.
7508 \layout List
7509 \labelwidthstring 00.00.0000
7510
7511
7512 \series bold 
7513 -
7514 \begin_inset ERT
7515 status Collapsed
7516
7517 \layout Standard
7518
7519 \backslash 
7520 /
7521 \end_inset 
7522
7523 -noinduction
7524 \begin_inset LatexCommand \index{-\/-noinduction}
7525
7526 \end_inset 
7527
7528
7529 \series default 
7530  Will not do loop induction optimizations, see section strength reduction
7531  for more details.
7532  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7533 noinduction
7534 \begin_inset LatexCommand \index{\#pragma noinduction}
7535
7536 \end_inset 
7537
7538  can be used to turn off induction optimizations for a given function only.
7539 \layout List
7540 \labelwidthstring 00.00.0000
7541
7542
7543 \series bold 
7544 -
7545 \begin_inset ERT
7546 status Collapsed
7547
7548 \layout Standard
7549
7550 \backslash 
7551 /
7552 \end_inset 
7553
7554 -nojtbound
7555 \begin_inset LatexCommand \index{-\/-nojtbound}
7556
7557 \end_inset 
7558
7559
7560 \size large 
7561 \bar under 
7562  
7563 \series default 
7564 \size default 
7565 \bar default 
7566  Will not generate boundary condition check when switch statements
7567 \begin_inset LatexCommand \index{switch statement}
7568
7569 \end_inset 
7570
7571  are implemented using jump-tables.
7572  See section 
7573 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7574
7575 \end_inset 
7576
7577 \SpecialChar ~
7578 Switch Statements for more details.
7579  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7580 nojtbound
7581 \begin_inset LatexCommand \index{\#pragma nojtbound}
7582
7583 \end_inset 
7584
7585  can be used to turn off boundary checking for jump tables for a given function
7586  only.
7587 \layout List
7588 \labelwidthstring 00.00.0000
7589
7590
7591 \series bold 
7592 -
7593 \begin_inset ERT
7594 status Collapsed
7595
7596 \layout Standard
7597
7598 \backslash 
7599 /
7600 \end_inset 
7601
7602 -noloopreverse
7603 \begin_inset LatexCommand \index{-\/-noloopreverse}
7604
7605 \end_inset 
7606
7607
7608 \series default 
7609 \size large 
7610  
7611 \size default 
7612 Will not do loop reversal 
7613 \begin_inset LatexCommand \index{Loop reversing}
7614
7615 \end_inset 
7616
7617 optimization.
7618 \layout List
7619 \labelwidthstring 00.00.0000
7620
7621 -
7622 \begin_inset ERT
7623 status Collapsed
7624
7625 \layout Standard
7626
7627 \backslash 
7628 /
7629 \end_inset 
7630
7631 -
7632 \series bold 
7633 nolabelopt
7634 \series default 
7635  
7636 \begin_inset LatexCommand \index{-\/-nolabelopt }
7637
7638 \end_inset 
7639
7640 Will not optimize labels (makes the dumpfiles more readable).
7641 \layout List
7642 \labelwidthstring 00.00.0000
7643
7644
7645 \series bold 
7646 -
7647 \begin_inset ERT
7648 status Collapsed
7649
7650 \layout Standard
7651
7652 \backslash 
7653 /
7654 \end_inset 
7655
7656 -no-xinit-opt
7657 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7658
7659 \end_inset 
7660
7661
7662 \series default 
7663  Will not memcpy initialized data from code space into xdata space.
7664  This saves a few bytes in code space if you don't have initialized data
7665 \begin_inset LatexCommand \index{Variable initialization}
7666
7667 \end_inset 
7668
7669 .
7670 \layout List
7671 \labelwidthstring 00.00.0000
7672
7673
7674 \series bold 
7675 -
7676 \begin_inset ERT
7677 status Collapsed
7678
7679 \layout Standard
7680
7681 \backslash 
7682 /
7683 \end_inset 
7684
7685 -nooverlay
7686 \begin_inset LatexCommand \index{-\/-nooverlay}
7687
7688 \end_inset 
7689
7690
7691 \series default 
7692   The compiler will not overlay parameters and local variables of any function,
7693  see section Parameters and local variables for more details.
7694 \layout List
7695 \labelwidthstring 00.00.0000
7696
7697
7698 \series bold 
7699 -
7700 \begin_inset ERT
7701 status Collapsed
7702
7703 \layout Standard
7704
7705 \backslash 
7706 /
7707 \end_inset 
7708
7709 -no-peep
7710 \begin_inset LatexCommand \index{-\/-no-peep}
7711
7712 \end_inset 
7713
7714
7715 \series default 
7716  Disable peep-hole optimization with built-in rules.
7717 \layout List
7718 \labelwidthstring 00.00.0000
7719
7720
7721 \series bold 
7722 -
7723 \begin_inset ERT
7724 status Collapsed
7725
7726 \layout Standard
7727
7728 \backslash 
7729 /
7730 \end_inset 
7731
7732 -peep-file
7733 \series default 
7734
7735 \begin_inset LatexCommand \index{-\/-peep-file}
7736
7737 \end_inset 
7738
7739 \SpecialChar ~
7740 <filename> This option can be used to use additional rules to be used by
7741  the peep hole optimizer.
7742  See section 
7743 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7744
7745 \end_inset 
7746
7747 \SpecialChar ~
7748 Peep Hole optimizations for details on how to write these rules.
7749 \layout List
7750 \labelwidthstring 00.00.0000
7751
7752
7753 \series bold 
7754 -
7755 \begin_inset ERT
7756 status Collapsed
7757
7758 \layout Standard
7759
7760 \backslash 
7761 /
7762 \end_inset 
7763
7764 -peep-asm
7765 \begin_inset LatexCommand \index{-\/-peep-asm}
7766
7767 \end_inset 
7768
7769
7770 \series default 
7771  Pass the inline assembler code through the peep hole optimizer.
7772  This can cause unexpected changes to inline assembler code, please go through
7773  the peephole optimizer
7774 \begin_inset LatexCommand \index{Peephole optimizer}
7775
7776 \end_inset 
7777
7778  rules defined in the source file tree '<target>/peeph.def' before using
7779  this option.
7780 \layout List
7781 \labelwidthstring 00.00.0000
7782
7783
7784 \series bold 
7785 -
7786 \begin_inset ERT
7787 status Collapsed
7788
7789 \layout Standard
7790
7791 \backslash 
7792 /
7793 \end_inset 
7794
7795 -opt-code-speed
7796 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7797
7798 \end_inset 
7799
7800
7801 \series default 
7802  The compiler will optimize code generation towards fast code, possibly
7803  at the expense of code size.
7804 \layout List
7805 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7806
7807
7808 \series bold 
7809 -
7810 \begin_inset ERT
7811 status Collapsed
7812
7813 \layout Standard
7814
7815 \backslash 
7816 /
7817 \end_inset 
7818
7819 -opt-code-size
7820 \begin_inset LatexCommand \index{-\/-opt-code-size}
7821
7822 \end_inset 
7823
7824
7825 \series default 
7826  The compiler will optimize code generation towards compact code, possibly
7827  at the expense of code speed.
7828 \layout Subsection
7829
7830 Other Options
7831 \begin_inset LatexCommand \index{Options other}
7832
7833 \end_inset 
7834
7835
7836 \layout List
7837 \labelwidthstring 00.00.0000
7838
7839
7840 \series bold 
7841 -c\SpecialChar ~
7842 -
7843 \begin_inset ERT
7844 status Collapsed
7845
7846 \layout Standard
7847
7848 \backslash 
7849 /
7850 \end_inset 
7851
7852 -compile-only
7853 \begin_inset LatexCommand \index{-\/-compile-only}
7854
7855 \end_inset 
7856
7857
7858 \begin_inset LatexCommand \index{-c -\/-compile-only}
7859
7860 \end_inset 
7861
7862
7863 \series default 
7864  will compile and assemble the source, but will not call the linkage editor.
7865 \layout List
7866 \labelwidthstring 00.00.0000
7867
7868
7869 \series bold 
7870 -
7871 \series default 
7872
7873 \begin_inset ERT
7874 status Collapsed
7875
7876 \layout Standard
7877
7878 \backslash 
7879 /
7880 \end_inset 
7881
7882
7883 \series bold 
7884 -c1mode
7885 \begin_inset LatexCommand \index{-\/-c1mode}
7886
7887 \end_inset 
7888
7889
7890 \series default 
7891  reads the preprocessed source from standard input and compiles it.
7892  The file name for the assembler output must be specified using the -o option.
7893 \layout List
7894 \labelwidthstring 00.00.0000
7895
7896
7897 \series bold 
7898 -E
7899 \begin_inset LatexCommand \index{-E}
7900
7901 \end_inset 
7902
7903
7904 \series default 
7905  Run only the C preprocessor.
7906  Preprocess all the C source files specified and output the results to standard
7907  output.
7908 \layout List
7909 \labelwidthstring 00.00.0000
7910
7911
7912 \series bold 
7913 -o\SpecialChar ~
7914 <path/file>
7915 \begin_inset LatexCommand \index{-o <path/file>}
7916
7917 \end_inset 
7918
7919  
7920 \series default 
7921 The output path resp.
7922  file where everything will be placed.
7923  If the parameter is a path, it must have a trailing slash (or backslash
7924  for the Windows binaries) to be recognized as a path.
7925  
7926 \layout List
7927 \labelwidthstring 00.00.0000
7928
7929
7930 \series bold 
7931 -
7932 \begin_inset ERT
7933 status Collapsed
7934
7935 \layout Standard
7936
7937 \backslash 
7938 /
7939 \end_inset 
7940
7941 -stack-auto
7942 \begin_inset LatexCommand \index{-\/-stack-auto}
7943
7944 \end_inset 
7945
7946
7947 \series default 
7948 \size large 
7949 \emph on 
7950  
7951 \size default 
7952 \emph default 
7953 All functions in the source file will be compiled as 
7954 \emph on 
7955 reentrant
7956 \emph default 
7957
7958 \begin_inset LatexCommand \index{reentrant}
7959
7960 \end_inset 
7961
7962 , i.e.
7963  the parameters and local variables will be allocated on the stack
7964 \begin_inset LatexCommand \index{stack}
7965
7966 \end_inset 
7967
7968 .
7969  See section 
7970 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7971
7972 \end_inset 
7973
7974  Parameters and Local Variables for more details.
7975  If this option is used all source files in the project should be compiled
7976  with this option.
7977  It automatically implies --int-long-reent and --float-reent.
7978  
7979 \layout List
7980 \labelwidthstring 00.00.0000
7981
7982
7983 \series bold 
7984 -
7985 \begin_inset ERT
7986 status Collapsed
7987
7988 \layout Standard
7989
7990 \backslash 
7991 /
7992 \end_inset 
7993
7994 -callee-saves
7995 \begin_inset LatexCommand \index{-\/-callee-saves}
7996
7997 \end_inset 
7998
7999  function1[,function2][,function3]....
8000
8001 \series default 
8002  The compiler by default uses a caller saves convention for register saving
8003  across function calls, however this can cause unnecessary register pushing
8004  & popping when calling small functions from larger functions.
8005  This option can be used to switch the register saving convention for the
8006  function names specified.
8007  The compiler will not save registers when calling these functions, no extra
8008  code will be generated at the entry & exit (function prologue
8009 \series bold 
8010
8011 \begin_inset LatexCommand \index{function prologue}
8012
8013 \end_inset 
8014
8015
8016 \series default 
8017  & epilogue
8018 \series bold 
8019
8020 \begin_inset LatexCommand \index{function epilogue}
8021
8022 \end_inset 
8023
8024
8025 \series default 
8026 ) for these functions to save & restore the registers used by these functions,
8027  this can SUBSTANTIALLY reduce code & improve run time performance of the
8028  generated code.
8029  In the future the compiler (with inter procedural analysis) will be able
8030  to determine the appropriate scheme to use for each function call.
8031  DO NOT use this option for built-in functions such as _mulint..., if this
8032  option is used for a library function the appropriate library function
8033  needs to be recompiled with the same option.
8034  If the project consists of multiple source files then all the source file
8035  should be compiled with the same -
8036 \begin_inset ERT
8037 status Collapsed
8038
8039 \layout Standard
8040
8041 \backslash 
8042 /
8043 \end_inset 
8044
8045 -callee-saves option string.
8046  Also see #pragma\SpecialChar ~
8047 callee_saves
8048 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8049
8050 \end_inset 
8051
8052 .
8053 \layout List
8054 \labelwidthstring 00.00.0000
8055
8056
8057 \series bold 
8058 -
8059 \begin_inset ERT
8060 status Collapsed
8061
8062 \layout Standard
8063
8064 \backslash 
8065 /
8066 \end_inset 
8067
8068 -debug
8069 \begin_inset LatexCommand \index{-\/-debug}
8070
8071 \end_inset 
8072
8073
8074 \bar under 
8075  
8076 \series default 
8077 \bar default 
8078 When this option is used the compiler will generate debug information.
8079  The debug information collected in a file with .cdb extension can be used
8080  with the SDCDB.
8081  For more information see documentation for SDCDB.
8082  Another file with no extension contains debug information in AOMF or AOMF51
8083 \begin_inset LatexCommand \index{AOMF, AOMF51}
8084
8085 \end_inset 
8086
8087  format which is commonly used by third party tools.
8088 \layout List
8089 \labelwidthstring 00.00.0000
8090
8091
8092 \series bold 
8093 -S
8094 \begin_inset LatexCommand \index{-S}
8095
8096 \end_inset 
8097
8098
8099 \size large 
8100 \bar under 
8101  
8102 \series default 
8103 \size default 
8104 \bar default 
8105 Stop after the stage of compilation proper; do not assemble.
8106  The output is an assembler code file for the input file specified.
8107 \layout List
8108 \labelwidthstring 00.00.0000
8109
8110
8111 \series bold 
8112 -
8113 \begin_inset ERT
8114 status Collapsed
8115
8116 \layout Standard
8117
8118 \backslash 
8119 /
8120 \end_inset 
8121
8122 -int-long-reent
8123 \begin_inset LatexCommand \index{-\/-int-long-reent}
8124
8125 \end_inset 
8126
8127
8128 \series default 
8129  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8130  Note by default these libraries are compiled as non-reentrant.
8131  See section Installation for more details.
8132 \layout List
8133 \labelwidthstring 00.00.0000
8134
8135
8136 \series bold 
8137 -
8138 \begin_inset ERT
8139 status Collapsed
8140
8141 \layout Standard
8142
8143 \backslash 
8144 /
8145 \end_inset 
8146
8147 -cyclomatic
8148 \begin_inset LatexCommand \index{-\/-cyclomatic}
8149
8150 \end_inset 
8151
8152
8153 \bar under 
8154  
8155 \series default 
8156 \bar default 
8157 This option will cause the compiler to generate an information message for
8158  each function in the source file.
8159  The message contains some 
8160 \emph on 
8161 important
8162 \emph default 
8163  information about the function.
8164  The number of edges and nodes the compiler detected in the control flow
8165  graph of the function, and most importantly the 
8166 \emph on 
8167 cyclomatic complexity
8168 \begin_inset LatexCommand \index{Cyclomatic complexity}
8169
8170 \end_inset 
8171
8172
8173 \emph default 
8174  see section on Cyclomatic Complexity for more details.
8175 \layout List
8176 \labelwidthstring 00.00.0000
8177
8178
8179 \series bold 
8180 -
8181 \begin_inset ERT
8182 status Collapsed
8183
8184 \layout Standard
8185
8186 \backslash 
8187 /
8188 \end_inset 
8189
8190 -float-reent
8191 \begin_inset LatexCommand \index{-\/-float-reent}
8192
8193 \end_inset 
8194
8195
8196 \series default 
8197  Floating point library is compiled as reentrant
8198 \begin_inset LatexCommand \index{reentrant}
8199
8200 \end_inset 
8201
8202 .
8203  See section Installation for more details.
8204 \layout List
8205 \labelwidthstring 00.00.0000
8206
8207
8208 \series bold 
8209 -
8210 \begin_inset ERT
8211 status Collapsed
8212
8213 \layout Standard
8214
8215 \backslash 
8216 /
8217 \end_inset 
8218
8219 -main-return
8220 \begin_inset LatexCommand \index{-\/-main-return}
8221
8222 \end_inset 
8223
8224
8225 \series default 
8226  This option can be used if the code generated is called by a monitor program
8227  or if the main routine includes an endless loop.
8228  This option results in slightly smaller code and saves two bytes of stack
8229  space.
8230  The return from the 'main'
8231 \begin_inset LatexCommand \index{main return}
8232
8233 \end_inset 
8234
8235  function will return to the function calling main.
8236  The default setting is to lock up i.e.
8237  generate a '
8238 \family typewriter 
8239 sjmp .
8240 \family default 
8241 '.
8242 \layout List
8243 \labelwidthstring 00.00.0000
8244
8245
8246 \series bold 
8247 -
8248 \begin_inset ERT
8249 status Collapsed
8250
8251 \layout Standard
8252
8253 \backslash 
8254 /
8255 \end_inset 
8256
8257 -nostdinc
8258 \begin_inset LatexCommand \index{-\/-nostdinc}
8259
8260 \end_inset 
8261
8262
8263 \series default 
8264  This will prevent the compiler from passing on the default include path
8265  to the preprocessor.
8266 \layout List
8267 \labelwidthstring 00.00.0000
8268
8269
8270 \series bold 
8271 -
8272 \begin_inset ERT
8273 status Collapsed
8274
8275 \layout Standard
8276
8277 \backslash 
8278 /
8279 \end_inset 
8280
8281 -nostdlib
8282 \begin_inset LatexCommand \index{-\/-nostdlib}
8283
8284 \end_inset 
8285
8286
8287 \series default 
8288  This will prevent the compiler from passing on the default library
8289 \begin_inset LatexCommand \index{Libraries}
8290
8291 \end_inset 
8292
8293  path to the linker.
8294 \layout List
8295 \labelwidthstring 00.00.0000
8296
8297
8298 \series bold 
8299 -
8300 \begin_inset ERT
8301 status Collapsed
8302
8303 \layout Standard
8304
8305 \backslash 
8306 /
8307 \end_inset 
8308
8309 -verbose
8310 \begin_inset LatexCommand \index{-\/-verbose}
8311
8312 \end_inset 
8313
8314
8315 \series default 
8316  Shows the various actions the compiler is performing.
8317 \layout List
8318 \labelwidthstring 00.00.0000
8319
8320
8321 \series bold 
8322 -V
8323 \begin_inset LatexCommand \index{-V}
8324
8325 \end_inset 
8326
8327
8328 \series default 
8329  Shows the actual commands the compiler is executing.
8330 \layout List
8331 \labelwidthstring 00.00.0000
8332
8333
8334 \series bold 
8335 -
8336 \begin_inset ERT
8337 status Collapsed
8338
8339 \layout Standard
8340
8341 \backslash 
8342 /
8343 \end_inset 
8344
8345 -no-c-code-in-asm
8346 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8347
8348 \end_inset 
8349
8350
8351 \series default 
8352  Hides your ugly and inefficient c-code from the asm file, so you can always
8353  blame the compiler :)
8354 \layout List
8355 \labelwidthstring 00.00.0000
8356
8357
8358 \series bold 
8359 -
8360 \begin_inset ERT
8361 status Collapsed
8362
8363 \layout Standard
8364
8365 \backslash 
8366 /
8367 \end_inset 
8368
8369 -no-peep-comments
8370 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8371
8372 \end_inset 
8373
8374
8375 \series default 
8376  Will not include peep-hole comments in the generated files.
8377 \layout List
8378 \labelwidthstring 00.00.0000
8379
8380
8381 \series bold 
8382 -
8383 \begin_inset ERT
8384 status Collapsed
8385
8386 \layout Standard
8387
8388 \backslash 
8389 /
8390 \end_inset 
8391
8392 -i-code-in-asm
8393 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8394
8395 \end_inset 
8396
8397
8398 \series default 
8399  Include i-codes in the asm file.
8400  Sounds like noise but is most helpful for debugging the compiler itself.
8401 \layout List
8402 \labelwidthstring 00.00.0000
8403
8404
8405 \series bold 
8406 -
8407 \begin_inset ERT
8408 status Collapsed
8409
8410 \layout Standard
8411
8412 \backslash 
8413 /
8414 \end_inset 
8415
8416 -less-pedantic
8417 \begin_inset LatexCommand \index{-\/-less-pedantic}
8418
8419 \end_inset 
8420
8421
8422 \series default 
8423  Disable some of the more pedantic warnings
8424 \begin_inset LatexCommand \index{Warnings}
8425
8426 \end_inset 
8427
8428  (jwk burps: please be more specific here, please!).
8429 \layout List
8430 \labelwidthstring 00.00.0000
8431
8432
8433 \series bold 
8434 -
8435 \begin_inset ERT
8436 status Collapsed
8437
8438 \layout Standard
8439
8440 \backslash 
8441 /
8442 \end_inset 
8443
8444 -disable-warning\SpecialChar ~
8445 <nnnn>
8446 \begin_inset LatexCommand \index{-\/-disable-warning}
8447
8448 \end_inset 
8449
8450
8451 \series default 
8452  Disable specific warning with number <nnnn>.
8453 \layout List
8454 \labelwidthstring 00.00.0000
8455
8456
8457 \series bold 
8458 -
8459 \begin_inset ERT
8460 status Collapsed
8461
8462 \layout Standard
8463
8464 \backslash 
8465 /
8466 \end_inset 
8467
8468 -print-search-dirs
8469 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8470
8471 \end_inset 
8472
8473
8474 \series default 
8475  Display the directories in the compiler's search path
8476 \layout List
8477 \labelwidthstring 00.00.0000
8478
8479
8480 \series bold 
8481 -
8482 \begin_inset ERT
8483 status Collapsed
8484
8485 \layout Standard
8486
8487 \backslash 
8488 /
8489 \end_inset 
8490
8491 -vc
8492 \begin_inset LatexCommand \index{-\/-vc}
8493
8494 \end_inset 
8495
8496
8497 \series default 
8498  Display errors and warnings using MSVC style, so you can use SDCC with
8499  the visual studio IDE
8500 \begin_inset LatexCommand \index{IDE}
8501
8502 \end_inset 
8503
8504 .
8505  With SDCC both offering a GCC-like (the default) and a MSVC-like
8506 \begin_inset LatexCommand \index{MSVC output style}
8507
8508 \end_inset 
8509
8510  output style, integration into most programming editors should be straightforwa
8511 rd.
8512 \layout List
8513 \labelwidthstring 00.00.0000
8514
8515
8516 \series bold 
8517 -
8518 \begin_inset ERT
8519 status Collapsed
8520
8521 \layout Standard
8522
8523 \backslash 
8524 /
8525 \end_inset 
8526
8527 -use-stdout
8528 \begin_inset LatexCommand \index{-\/-use-stdout}
8529
8530 \end_inset 
8531
8532
8533 \series default 
8534  Send errors and warnings to stdout instead of stderr.
8535 \layout List
8536 \labelwidthstring 00.00.0000
8537
8538
8539 \series bold 
8540 -Wa\SpecialChar ~
8541 asmOption[,asmOption]
8542 \series default 
8543
8544 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8545
8546 \end_inset 
8547
8548 ...
8549  Pass the asmOption to the assembler
8550 \begin_inset LatexCommand \index{Options assembler}
8551
8552 \end_inset 
8553
8554
8555 \begin_inset LatexCommand \index{Assembler options}
8556
8557 \end_inset 
8558
8559 .
8560  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8561 \layout List
8562 \labelwidthstring 00.00.0000
8563
8564
8565 \series bold 
8566 -
8567 \begin_inset ERT
8568 status Collapsed
8569
8570 \layout Standard
8571
8572 \backslash 
8573 /
8574 \end_inset 
8575
8576 -std-sdcc89
8577 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8578
8579 \end_inset 
8580
8581
8582 \series default 
8583  Generally follow the C89 standard, but allow SDCC features that conflict
8584  with the standard (default).
8585 \layout List
8586 \labelwidthstring 00.00.0000
8587
8588
8589 \series bold 
8590 -
8591 \begin_inset ERT
8592 status Collapsed
8593
8594 \layout Standard
8595
8596 \backslash 
8597 /
8598 \end_inset 
8599
8600 -std-c89
8601 \begin_inset LatexCommand \index{-\/-std-c89}
8602
8603 \end_inset 
8604
8605
8606 \series default 
8607  Follow the C89 standard and disable SDCC features that conflict with the
8608  standard.
8609 \layout List
8610 \labelwidthstring 00.00.0000
8611
8612
8613 \series bold 
8614 -
8615 \begin_inset ERT
8616 status Collapsed
8617
8618 \layout Standard
8619
8620 \backslash 
8621 /
8622 \end_inset 
8623
8624 -std-sdcc99
8625 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8626
8627 \end_inset 
8628
8629
8630 \series default 
8631  Generally follow the C99 standard, but allow SDCC features that conflict
8632  with the standard (incomplete support).
8633 \layout List
8634 \labelwidthstring 00.00.0000
8635
8636
8637 \series bold 
8638 -
8639 \begin_inset ERT
8640 status Collapsed
8641
8642 \layout Standard
8643
8644 \backslash 
8645 /
8646 \end_inset 
8647
8648 -std-c99
8649 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8650
8651 \end_inset 
8652
8653
8654 \series default 
8655  Follow the C99 standard and disable SDCC features that conflict with the
8656  standard (incomplete support).
8657 \layout List
8658 \labelwidthstring 00.00.0000
8659
8660
8661 \series bold 
8662 -
8663 \begin_inset ERT
8664 status Collapsed
8665
8666 \layout Standard
8667
8668 \backslash 
8669 /
8670 \end_inset 
8671
8672 -codeseg
8673 \series default 
8674
8675 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8676
8677 \end_inset 
8678
8679 \SpecialChar ~
8680 <Name> The name to be used for the code
8681 \begin_inset LatexCommand \index{code}
8682
8683 \end_inset 
8684
8685  segment, default CSEG.
8686  This is useful if you need to tell the compiler to put the code in a special
8687  segment so you can later on tell the linker to put this segment in a special
8688  place in memory.
8689  Can be used for instance when using bank switching to put the code in a
8690  bank.
8691 \layout List
8692 \labelwidthstring 00.00.0000
8693
8694
8695 \series bold 
8696 -
8697 \begin_inset ERT
8698 status Collapsed
8699
8700 \layout Standard
8701
8702 \backslash 
8703 /
8704 \end_inset 
8705
8706 -constseg
8707 \series default 
8708
8709 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8710
8711 \end_inset 
8712
8713 \SpecialChar ~
8714 <Name> The name to be used for the const
8715 \begin_inset LatexCommand \index{code}
8716
8717 \end_inset 
8718
8719  segment, default CONST.
8720  This is useful if you need to tell the compiler to put the const data in
8721  a special segment so you can later on tell the linker to put this segment
8722  in a special place in memory.
8723  Can be used for instance when using bank switching to put the const data
8724  in a bank.
8725 \layout List
8726 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8727
8728
8729 \series bold 
8730 more-pedantic
8731 \series default 
8732  Actually this is 
8733 \series bold 
8734 \emph on 
8735 not
8736 \series default 
8737 \emph default 
8738  a SDCC compiler option but if you want 
8739 \emph on 
8740 more
8741 \emph default 
8742  warnings you can use a separate tool dedicated to syntax checking like
8743  splint
8744 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8745
8746 \end_inset 
8747
8748
8749 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8750
8751 \end_inset 
8752
8753  
8754 \begin_inset LatexCommand \url{http://www.splint.org}
8755
8756 \end_inset 
8757
8758 .
8759  To make your source files parseable by splint you will have to include
8760  
8761 \family sans 
8762 lint.h
8763 \family default 
8764
8765 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8766
8767 \end_inset 
8768
8769  in your source file and add brackets around extended keywords (like 
8770 \family sans 
8771
8772 \begin_inset Quotes sld
8773 \end_inset 
8774
8775 __at\SpecialChar ~
8776
8777 \series bold 
8778 (
8779 \series default 
8780 0xab
8781 \series bold 
8782 )
8783 \series default 
8784
8785 \begin_inset Quotes srd
8786 \end_inset 
8787
8788
8789 \family default 
8790  and 
8791 \family sans 
8792
8793 \begin_inset Quotes sld
8794 \end_inset 
8795
8796 __interrupt\SpecialChar ~
8797 (2)
8798 \begin_inset Quotes srd
8799 \end_inset 
8800
8801
8802 \family default 
8803 ).
8804  
8805 \newline 
8806 Splint has an excellent on line manual at 
8807 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8808
8809 \end_inset 
8810
8811  and it's capabilities go beyond pure syntax checking.
8812  You'll need to tell splint the location of SDCC's include files so a typical
8813  command line could look like this: 
8814 \newline 
8815
8816 \family sans 
8817 splint\SpecialChar ~
8818 -I\SpecialChar ~
8819 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8820 \SpecialChar ~
8821 myprogram.c
8822 \layout Subsection
8823
8824 Intermediate Dump Options
8825 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8826
8827 \end_inset 
8828
8829
8830 \begin_inset LatexCommand \index{Options intermediate dump}
8831
8832 \end_inset 
8833
8834
8835 \begin_inset LatexCommand \index{Intermediate dump options}
8836
8837 \end_inset 
8838
8839
8840 \layout Standard
8841
8842 The following options are provided for the purpose of retargetting and debugging
8843  the compiler.
8844  They provide a means to dump the intermediate code (iCode
8845 \begin_inset LatexCommand \index{iCode}
8846
8847 \end_inset 
8848
8849 ) generated by the compiler in human readable form at various stages of
8850  the compilation process.
8851  More on iCodes see chapter 
8852 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8853
8854 \end_inset 
8855
8856  
8857 \begin_inset Quotes srd
8858 \end_inset 
8859
8860 The anatomy of the compiler
8861 \begin_inset Quotes srd
8862 \end_inset 
8863
8864 .
8865 \layout List
8866 \labelwidthstring 00.00.0000
8867
8868
8869 \series bold 
8870 -
8871 \begin_inset ERT
8872 status Collapsed
8873
8874 \layout Standard
8875
8876 \backslash 
8877 /
8878 \end_inset 
8879
8880 -dumpraw
8881 \begin_inset LatexCommand \index{-\/-dumpraw}
8882
8883 \end_inset 
8884
8885
8886 \series default 
8887  This option will cause the compiler to dump the intermediate code into
8888  a file of named 
8889 \emph on 
8890 <source filename>.dumpraw
8891 \emph default 
8892  just after the intermediate code has been generated for a function, i.e.
8893  before any optimizations are done.
8894  The basic blocks
8895 \begin_inset LatexCommand \index{Basic blocks}
8896
8897 \end_inset 
8898
8899  at this stage ordered in the depth first number, so they may not be in
8900  sequence of execution.
8901 \layout List
8902 \labelwidthstring 00.00.0000
8903
8904
8905 \series bold 
8906 -
8907 \begin_inset ERT
8908 status Collapsed
8909
8910 \layout Standard
8911
8912 \backslash 
8913 /
8914 \end_inset 
8915
8916 -dumpgcse
8917 \begin_inset LatexCommand \index{-\/-dumpgcse}
8918
8919 \end_inset 
8920
8921
8922 \series default 
8923  Will create a dump of iCode's, after global subexpression elimination
8924 \begin_inset LatexCommand \index{Global subexpression elimination}
8925
8926 \end_inset 
8927
8928 , into a file named 
8929 \emph on 
8930 <source filename>.dumpgcse.
8931 \layout List
8932 \labelwidthstring 00.00.0000
8933
8934
8935 \series bold 
8936 -
8937 \begin_inset ERT
8938 status Collapsed
8939
8940 \layout Standard
8941
8942 \backslash 
8943 /
8944 \end_inset 
8945
8946 -dumpdeadcode
8947 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8948
8949 \end_inset 
8950
8951
8952 \series default 
8953  Will create a dump of iCode's, after deadcode elimination
8954 \begin_inset LatexCommand \index{Dead-code elimination}
8955
8956 \end_inset 
8957
8958 , into a file named 
8959 \emph on 
8960 <source filename>.dumpdeadcode.
8961 \layout List
8962 \labelwidthstring 00.00.0000
8963
8964
8965 \series bold 
8966 -
8967 \begin_inset ERT
8968 status Collapsed
8969
8970 \layout Standard
8971
8972 \backslash 
8973 /
8974 \end_inset 
8975
8976 -dumploop
8977 \begin_inset LatexCommand \index{-\/-dumploop}
8978
8979 \end_inset 
8980
8981
8982 \series default 
8983 \size large 
8984  
8985 \size default 
8986 Will create a dump of iCode's, after loop optimizations
8987 \begin_inset LatexCommand \index{Loop optimization}
8988
8989 \end_inset 
8990
8991 , into a file named 
8992 \emph on 
8993 <source filename>.dumploop.
8994 \layout List
8995 \labelwidthstring 00.00.0000
8996
8997
8998 \series bold 
8999 -
9000 \begin_inset ERT
9001 status Collapsed
9002
9003 \layout Standard
9004
9005 \backslash 
9006 /
9007 \end_inset 
9008
9009 -dumprange
9010 \begin_inset LatexCommand \index{-\/-dumprange}
9011
9012 \end_inset 
9013
9014
9015 \series default 
9016 \size large 
9017  
9018 \size default 
9019 Will create a dump of iCode's, after live range analysis
9020 \begin_inset LatexCommand \index{Live range analysis}
9021
9022 \end_inset 
9023
9024 , into a file named 
9025 \emph on 
9026 <source filename>.dumprange.
9027 \layout List
9028 \labelwidthstring 00.00.0000
9029
9030
9031 \series bold 
9032 -
9033 \begin_inset ERT
9034 status Collapsed
9035
9036 \layout Standard
9037
9038 \backslash 
9039 /
9040 \end_inset 
9041
9042 -dumlrange
9043 \begin_inset LatexCommand \index{-\/-dumlrange}
9044
9045 \end_inset 
9046
9047
9048 \series default 
9049  Will dump the life ranges
9050 \begin_inset LatexCommand \index{Live range analysis}
9051
9052 \end_inset 
9053
9054  for all symbols.
9055 \layout List
9056 \labelwidthstring 00.00.0000
9057
9058
9059 \series bold 
9060 -
9061 \begin_inset ERT
9062 status Collapsed
9063
9064 \layout Standard
9065
9066 \backslash 
9067 /
9068 \end_inset 
9069
9070 -dumpregassign
9071 \begin_inset LatexCommand \index{-\/-dumpregassign}
9072
9073 \end_inset 
9074
9075
9076 \bar under 
9077  
9078 \series default 
9079 \bar default 
9080 Will create a dump of iCode's, after register assignment
9081 \begin_inset LatexCommand \index{Register assignment}
9082
9083 \end_inset 
9084
9085 , into a file named 
9086 \emph on 
9087 <source filename>.dumprassgn.
9088 \layout List
9089 \labelwidthstring 00.00.0000
9090
9091
9092 \series bold 
9093 -
9094 \begin_inset ERT
9095 status Collapsed
9096
9097 \layout Standard
9098
9099 \backslash 
9100 /
9101 \end_inset 
9102
9103 -dumplrange
9104 \begin_inset LatexCommand \index{-\/-dumplrange}
9105
9106 \end_inset 
9107
9108
9109 \series default 
9110  Will create a dump of the live ranges of iTemp's
9111 \layout List
9112 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9113
9114
9115 \series bold 
9116 -
9117 \begin_inset ERT
9118 status Collapsed
9119
9120 \layout Standard
9121
9122 \backslash 
9123 /
9124 \end_inset 
9125
9126 -dumpall
9127 \begin_inset LatexCommand \index{-\/-dumpall}
9128
9129 \end_inset 
9130
9131
9132 \size large 
9133 \bar under 
9134  
9135 \series default 
9136 \size default 
9137 \bar default 
9138 Will cause all the above mentioned dumps to be created.
9139 \layout Subsection
9140
9141 Redirecting output on Windows Shells
9142 \layout Standard
9143 \added_space_bottom bigskip 
9144 By default SDCC writes it's error messages to 
9145 \begin_inset Quotes sld
9146 \end_inset 
9147
9148 standard error
9149 \begin_inset Quotes srd
9150 \end_inset 
9151
9152 .
9153  To force all messages to 
9154 \begin_inset Quotes sld
9155 \end_inset 
9156
9157 standard output
9158 \begin_inset Quotes srd
9159 \end_inset 
9160
9161  use 
9162 \series bold 
9163 -
9164 \series default 
9165 \emph on 
9166
9167 \begin_inset ERT
9168 status Collapsed
9169
9170 \layout Standard
9171
9172 \backslash 
9173 /
9174 \end_inset 
9175
9176
9177 \series bold 
9178 \emph default 
9179 -
9180 \series default 
9181 use-stdout
9182 \begin_inset LatexCommand \index{-\/-use-stdout}
9183
9184 \end_inset 
9185
9186 .
9187  Additionally, if you happen to have visual studio installed in your windows
9188  machine, you can use it to compile your sources using a custom build and
9189  the SDCC -
9190 \emph on 
9191
9192 \begin_inset ERT
9193 status Collapsed
9194
9195 \layout Standard
9196
9197 \backslash 
9198 /
9199 \end_inset 
9200
9201
9202 \emph default 
9203 -vc
9204 \begin_inset LatexCommand \index{-\/-vc}
9205
9206 \end_inset 
9207
9208  option.
9209  Something like this should work:
9210 \newline 
9211
9212 \newline 
9213
9214 \series bold 
9215 c:
9216 \backslash 
9217 sdcc
9218 \backslash 
9219 bin
9220 \backslash 
9221 sdcc.exe -
9222 \series default 
9223 \emph on 
9224
9225 \begin_inset ERT
9226 status Collapsed
9227
9228 \layout Standard
9229
9230 \backslash 
9231 /
9232 \end_inset 
9233
9234
9235 \series bold 
9236 \emph default 
9237 -vc -
9238 \series default 
9239 \emph on 
9240
9241 \begin_inset ERT
9242 status Collapsed
9243
9244 \layout Standard
9245
9246 \backslash 
9247 /
9248 \end_inset 
9249
9250
9251 \series bold 
9252 \emph default 
9253 -model-large -c $(InputPath)
9254 \layout Section
9255
9256 Environment variables
9257 \begin_inset LatexCommand \index{Environment variables}
9258
9259 \end_inset 
9260
9261
9262 \layout Standard
9263
9264 SDCC recognizes the following environment variables:
9265 \layout List
9266 \labelwidthstring 00.00.0000
9267
9268
9269 \series bold 
9270 SDCC_LEAVE_SIGNALS
9271 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9272
9273 \end_inset 
9274
9275
9276 \series default 
9277  SDCC installs a signal handler
9278 \begin_inset LatexCommand \index{signal handler}
9279
9280 \end_inset 
9281
9282  to be able to delete temporary files after an user break (^C) or an exception.
9283  If this environment variable is set, SDCC won't install the signal handler
9284  in order to be able to debug SDCC.
9285 \layout List
9286 \labelwidthstring 00.00.0000
9287
9288
9289 \series bold 
9290 TMP,\SpecialChar ~
9291 TEMP,\SpecialChar ~
9292 TMPDIR
9293 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9294
9295 \end_inset 
9296
9297
9298 \series default 
9299  Path, where temporary files will be created.
9300  The order of the variables is the search order.
9301  In a standard *nix environment these variables are not set, and there's
9302  no need to set them.
9303  On Windows it's recommended to set one of them.
9304 \layout List
9305 \labelwidthstring 00.00.0000
9306
9307
9308 \series bold 
9309 SDCC_HOME
9310 \begin_inset LatexCommand \index{SDCC\_HOME}
9311
9312 \end_inset 
9313
9314
9315 \series default 
9316  Path, see section 
9317 \begin_inset LatexCommand \ref{sub:Install-paths}
9318
9319 \end_inset 
9320
9321 \SpecialChar ~
9322
9323 \begin_inset Quotes sld
9324 \end_inset 
9325
9326  Install 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_INCLUDE
9337 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
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 List
9359 \labelwidthstring 00.00.0000
9360
9361
9362 \series bold 
9363 SDCC_LIB
9364 \begin_inset LatexCommand \index{SDCC\_LIB}
9365
9366 \end_inset 
9367
9368
9369 \series default 
9370  Path, see section 
9371 \begin_inset LatexCommand \ref{sub:Search-Paths}
9372
9373 \end_inset 
9374
9375 \SpecialChar ~
9376
9377 \begin_inset Quotes sld
9378 \end_inset 
9379
9380 Search Paths
9381 \begin_inset Quotes srd
9382 \end_inset 
9383
9384 ..
9385 \layout Standard
9386 \added_space_bottom bigskip 
9387 There are some more environment variables recognized by SDCC, but these
9388  are solely used for debugging purposes.
9389  They can change or disappear very quickly, and will never be documented.
9390 \layout Section
9391
9392 Storage Class Language Extensions
9393 \layout Subsection
9394
9395 MCS51/DS390 Storage Class
9396 \begin_inset LatexCommand \index{Storage class}
9397
9398 \end_inset 
9399
9400  Language Extensions
9401 \layout Standard
9402
9403 In addition to the ANSI storage classes SDCC allows the following MCS51
9404  specific storage classes:
9405 \layout Subsubsection
9406
9407 data
9408 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9409
9410 \end_inset 
9411
9412
9413 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9414
9415 \end_inset 
9416
9417  / near
9418 \begin_inset LatexCommand \index{near (storage class)}
9419
9420 \end_inset 
9421
9422
9423 \begin_inset LatexCommand \index{\_\_near (storage class)}
9424
9425 \end_inset 
9426
9427
9428 \layout Standard
9429
9430 This is the 
9431 \series bold 
9432 default
9433 \series default 
9434  storage class for the Small Memory model (
9435 \emph on 
9436 data
9437 \emph default 
9438  and 
9439 \emph on 
9440 near
9441 \emph default 
9442  or the more ANSI-C compliant forms 
9443 \emph on 
9444 __data
9445 \emph default 
9446  and 
9447 \emph on 
9448 __near
9449 \emph default 
9450  can be used synonymously).
9451  Variables declared with this storage class will be allocated in the directly
9452  addressable portion of the internal RAM of a 8051, e.g.:
9453 \layout Verse
9454
9455
9456 \family typewriter 
9457 __data unsigned char test_data;
9458 \layout Standard
9459
9460 Writing 0x01 to this variable generates the assembly code:
9461 \layout Verse
9462
9463
9464 \family typewriter 
9465 75*00 01\SpecialChar ~
9466 \SpecialChar ~
9467 \SpecialChar ~
9468 mov\SpecialChar ~
9469 \SpecialChar ~
9470 _test_data,#0x01
9471 \layout Subsubsection
9472
9473 xdata
9474 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9475
9476 \end_inset 
9477
9478
9479 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9480
9481 \end_inset 
9482
9483  / far
9484 \begin_inset LatexCommand \index{far (storage class)}
9485
9486 \end_inset 
9487
9488
9489 \begin_inset LatexCommand \index{\_\_far (storage class)}
9490
9491 \end_inset 
9492
9493
9494 \layout Standard
9495
9496 Variables declared with this storage class will be placed in the external
9497  RAM.
9498  This is the 
9499 \series bold 
9500 default
9501 \series default 
9502  storage class for the Large Memory model, e.g.:
9503 \layout Verse
9504
9505
9506 \family typewriter 
9507 __xdata unsigned char test_xdata;
9508 \layout Standard
9509
9510 Writing 0x01 to this variable generates the assembly code:
9511 \layout Verse
9512
9513
9514 \family typewriter 
9515 90s00r00\SpecialChar ~
9516 \SpecialChar ~
9517 \SpecialChar ~
9518 mov\SpecialChar ~
9519 \SpecialChar ~
9520 dptr,#_test_xdata 
9521 \newline 
9522 74\SpecialChar ~
9523 01\SpecialChar ~
9524 \SpecialChar ~
9525 \SpecialChar ~
9526 \SpecialChar ~
9527 \SpecialChar ~
9528 \SpecialChar ~
9529 mov\SpecialChar ~
9530 \SpecialChar ~
9531 a,#0x01 
9532 \newline 
9533 F0\SpecialChar ~
9534 \SpecialChar ~
9535 \SpecialChar ~
9536 \SpecialChar ~
9537 \SpecialChar ~
9538 \SpecialChar ~
9539 \SpecialChar ~
9540 \SpecialChar ~
9541 \SpecialChar ~
9542 movx\SpecialChar ~
9543 @dptr,a 
9544 \layout Subsubsection
9545
9546 idata
9547 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9548
9549 \end_inset 
9550
9551
9552 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9553
9554 \end_inset 
9555
9556
9557 \layout Standard
9558
9559 Variables declared with this storage class will be allocated into the indirectly
9560  addressable portion of the internal ram of a 8051, e.g.:
9561 \layout Verse
9562
9563
9564 \family typewriter 
9565 __idata unsigned char test_idata;
9566 \layout Standard
9567
9568 Writing 0x01 to this variable generates the assembly code:
9569 \layout Verse
9570
9571
9572 \family typewriter 
9573 78r00\SpecialChar ~
9574 \SpecialChar ~
9575 \SpecialChar ~
9576 \SpecialChar ~
9577 \SpecialChar ~
9578 \SpecialChar ~
9579 \SpecialChar ~
9580 mov\SpecialChar ~
9581 \SpecialChar ~
9582 r0,#_test_idata
9583 \newline 
9584 76\SpecialChar ~
9585 01\SpecialChar ~
9586 \SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 \SpecialChar ~
9592 mov\SpecialChar ~
9593 \SpecialChar ~
9594 @r0,#0x01
9595 \layout Standard
9596
9597 Please note, the first 128 byte of idata physically access the same RAM
9598  as the data memory.
9599  The original 8051 had 128 byte idata memory, nowadays most devices have
9600  256 byte idata memory.
9601  The stack
9602 \begin_inset LatexCommand \index{stack}
9603
9604 \end_inset 
9605
9606  is located in idata memory.
9607 \layout Subsubsection
9608
9609 pdata
9610 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9611
9612 \end_inset 
9613
9614
9615 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9616
9617 \end_inset 
9618
9619
9620 \layout Standard
9621
9622 Paged xdata access is just as straightforward as using the other addressing
9623  modes of a 8051.
9624  It is typically located at the start of xdata and has a maximum size of
9625  256 bytes.
9626  The following example writes 0x01 to the pdata variable.
9627  Please note, pdata access physically accesses xdata memory.
9628  The high byte of the address is determined by port P2 
9629 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9630
9631 \end_inset 
9632
9633 (or in case of some 8051 variants by a separate Special Function Register,
9634  see section 
9635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9636
9637 \end_inset 
9638
9639 ).
9640  This is the 
9641 \series bold 
9642 default
9643 \series default 
9644  storage class for the Medium Memory model, e.g.:
9645 \layout Verse
9646
9647
9648 \family typewriter 
9649 __pdata unsigned char test_pdata;
9650 \layout Standard
9651
9652 Writing 0x01 to this variable generates the assembly code:
9653 \layout Verse
9654
9655
9656 \family typewriter 
9657 78r00\SpecialChar ~
9658 \SpecialChar ~
9659 \SpecialChar ~
9660 \SpecialChar ~
9661 \SpecialChar ~
9662 \SpecialChar ~
9663 mov r0,#_test_pdata
9664 \newline 
9665 74 01\SpecialChar ~
9666 \SpecialChar ~
9667 \SpecialChar ~
9668 \SpecialChar ~
9669 \SpecialChar ~
9670 \SpecialChar ~
9671 mov a,#0x01 
9672 \newline 
9673 F2\SpecialChar ~
9674 \SpecialChar ~
9675 \SpecialChar ~
9676 \SpecialChar ~
9677 \SpecialChar ~
9678 \SpecialChar ~
9679 \SpecialChar ~
9680 \SpecialChar ~
9681 \SpecialChar ~
9682 movx @r0,a
9683 \layout Standard
9684
9685 If the -
9686 \begin_inset ERT
9687 status Collapsed
9688
9689 \layout Standard
9690
9691 \backslash 
9692 /
9693 \end_inset 
9694
9695 -xstack
9696 \begin_inset LatexCommand \index{-\/-xstack}
9697
9698 \end_inset 
9699
9700  option is used the pdata memory area is followed by the xstack memory area
9701  and the sum of their sizes is limited to 256 bytes.
9702 \layout Subsubsection
9703
9704 code
9705 \begin_inset LatexCommand \index{code}
9706
9707 \end_inset 
9708
9709
9710 \begin_inset LatexCommand \index{\_\_code}
9711
9712 \end_inset 
9713
9714
9715 \layout Standard
9716
9717 'Variables' declared with this storage class will be placed in the code
9718  memory:
9719 \layout Verse
9720
9721
9722 \family typewriter 
9723 __code unsigned char test_code;
9724 \layout Standard
9725
9726 Read access to this variable generates the assembly code:
9727 \layout Verse
9728
9729
9730 \family typewriter 
9731 90s00r6F\SpecialChar ~
9732 \SpecialChar ~
9733 \SpecialChar ~
9734 mov dptr,#_test_code
9735 \newline 
9736 E4\SpecialChar ~
9737 \SpecialChar ~
9738 \SpecialChar ~
9739 \SpecialChar ~
9740 \SpecialChar ~
9741 \SpecialChar ~
9742 \SpecialChar ~
9743 \SpecialChar ~
9744 \SpecialChar ~
9745 clr a
9746 \newline 
9747 93\SpecialChar ~
9748 \SpecialChar ~
9749 \SpecialChar ~
9750 \SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 \SpecialChar ~
9756 movc a,@a+dptr 
9757 \layout Standard
9758
9759
9760 \family typewriter 
9761 char
9762 \family default 
9763  indexed arrays of characters in code memory can be accessed efficiently:
9764 \layout Verse
9765
9766
9767 \family typewriter 
9768 __code char test_array[] = {'c','h','e','a','p'}; 
9769 \layout Standard
9770
9771 Read access to this array using an 8-bit unsigned index generates the assembly
9772  code:
9773 \layout Verse
9774
9775
9776 \family typewriter 
9777 E5*00\SpecialChar ~
9778 \SpecialChar ~
9779 \SpecialChar ~
9780 \SpecialChar ~
9781 \SpecialChar ~
9782 \SpecialChar ~
9783 mov a,_index 
9784 \layout Verse
9785
9786
9787 \family typewriter 
9788 90s00r41\SpecialChar ~
9789 \SpecialChar ~
9790 \SpecialChar ~
9791 mov dptr,#_test_array
9792 \layout Verse
9793
9794
9795 \family typewriter 
9796 93\SpecialChar ~
9797 \SpecialChar ~
9798 \SpecialChar ~
9799 \SpecialChar ~
9800 \SpecialChar ~
9801 \SpecialChar ~
9802 \SpecialChar ~
9803 \SpecialChar ~
9804 \SpecialChar ~
9805 movc a,@a+dptr 
9806 \layout Subsubsection
9807
9808 bit
9809 \begin_inset LatexCommand \index{bit}
9810
9811 \end_inset 
9812
9813
9814 \begin_inset LatexCommand \index{\_\_bit}
9815
9816 \end_inset 
9817
9818
9819 \layout Standard
9820
9821 This is a data-type and a storage class specifier.
9822  When a variable is declared as a bit, it is allocated into the bit addressable
9823  memory of 8051, e.g.:
9824 \layout Verse
9825
9826
9827 \family typewriter 
9828 __bit test_bit;
9829 \layout Standard
9830
9831 Writing 1 to this variable generates the assembly code:
9832 \layout Verse
9833
9834
9835 \family typewriter 
9836 D2*00\SpecialChar ~
9837 \SpecialChar ~
9838 \SpecialChar ~
9839 \SpecialChar ~
9840 \SpecialChar ~
9841 \SpecialChar ~
9842 \SpecialChar ~
9843 setb\SpecialChar ~
9844 _test_bit
9845 \layout Standard
9846
9847 The bit addressable memory consists of 128 bits which are located from 0x20
9848  to 0x2f in data memory.
9849  
9850 \newline 
9851 Apart from this 8051 specific storage class most architectures support ANSI-C
9852  bitfields
9853 \begin_inset LatexCommand \index{bitfields}
9854
9855 \end_inset 
9856
9857
9858 \begin_inset Foot
9859 collapsed false
9860
9861 \layout Standard
9862
9863 Not really meant as examples, but nevertheless showing what bitfields are
9864  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9865 \end_inset 
9866
9867 .
9868  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9869  signed modifier are implemented as unsigned.
9870 \layout Subsubsection
9871
9872 sfr
9873 \begin_inset LatexCommand \index{sfr}
9874
9875 \end_inset 
9876
9877
9878 \begin_inset LatexCommand \index{\_\_sfr}
9879
9880 \end_inset 
9881
9882  / sfr16
9883 \begin_inset LatexCommand \index{sfr16}
9884
9885 \end_inset 
9886
9887
9888 \begin_inset LatexCommand \index{\_\_sfr16}
9889
9890 \end_inset 
9891
9892  / sfr32
9893 \begin_inset LatexCommand \index{sfr32}
9894
9895 \end_inset 
9896
9897
9898 \begin_inset LatexCommand \index{\_\_sfr32}
9899
9900 \end_inset 
9901
9902  / sbit
9903 \begin_inset LatexCommand \index{\_\_sbit}
9904
9905 \end_inset 
9906
9907
9908 \begin_inset LatexCommand \index{sbit}
9909
9910 \end_inset 
9911
9912
9913 \layout Standard
9914
9915 Like the bit keyword, 
9916 \emph on 
9917 sfr / sfr16 / sfr32 / sbit 
9918 \emph default 
9919 signify both a data-type and storage class, they are used to describe the
9920  
9921 \emph on 
9922 s
9923 \emph default 
9924 pecial 
9925 \emph on 
9926 f
9927 \emph default 
9928 unction 
9929 \emph on 
9930 r
9931 \emph default 
9932 egisters and 
9933 \emph on 
9934 s
9935 \emph default 
9936 pecial 
9937 \emph on 
9938 bit
9939 \emph default 
9940  variables of a 8051, eg:
9941 \layout Verse
9942
9943
9944 \family typewriter 
9945 __sfr __at
9946 \begin_inset LatexCommand \index{at}
9947
9948 \end_inset 
9949
9950
9951 \begin_inset LatexCommand \index{\_\_at}
9952
9953 \end_inset 
9954
9955  (0x80) P0;\SpecialChar ~
9956  /* special function register P0 at location 0x80 */
9957 \newline 
9958
9959 \newline 
9960 /* 16 bit special function register combination for timer 0
9961 \newline 
9962 \SpecialChar ~
9963 \SpecialChar ~
9964  with the high byte at location 0x8C and the low byte at location 0x8A */
9965 \newline 
9966 __sfr16 __at (0x8C8A) TMR0;
9967 \newline 
9968
9969 \newline 
9970 __sbit __at
9971 \begin_inset LatexCommand \index{at}
9972
9973 \end_inset 
9974
9975
9976 \begin_inset LatexCommand \index{\_\_at}
9977
9978 \end_inset 
9979
9980  (0xd7) CY;\SpecialChar ~
9981  /* CY (Carry Flag
9982 \begin_inset LatexCommand \index{Flags}
9983
9984 \end_inset 
9985
9986
9987 \begin_inset LatexCommand \index{Carry flag}
9988
9989 \end_inset 
9990
9991 ) */
9992 \layout Standard
9993
9994 Special function registers which are located on an address dividable by
9995  8 are bit-addressable, an
9996 \emph on 
9997  sbit
9998 \emph default 
9999  addresses a specific bit within these sfr.
10000 \newline 
10001 16 Bit and 32 bit special function register combinations which require a
10002  certain access order are better not declared using 
10003 \emph on 
10004 sfr16
10005 \emph default 
10006  or 
10007 \emph on 
10008 sfr32.
10009
10010 \emph default 
10011  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10012  this is not guaranteed.
10013 \newline 
10014
10015 \layout Standard
10016
10017 Please note, if you use a header file which was written for another compiler
10018  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10019  likely be 
10020 \emph on 
10021 not 
10022 \emph default 
10023 compatible.
10024  Specifically the syntax 
10025 \family typewriter 
10026 \SpecialChar ~
10027 sfr P0 = 0x80;\SpecialChar ~
10028
10029 \family default 
10030  is compiled 
10031 \emph on 
10032 without warning
10033 \emph default 
10034  by SDCC to an assignment of 0x80 to a variable called P0 
10035 \family typewriter 
10036
10037 \begin_inset Marginal
10038 collapsed true
10039
10040 \layout Standard
10041
10042
10043 \series bold 
10044 \SpecialChar ~
10045 !
10046 \end_inset 
10047
10048 .
10049  
10050 \family default 
10051 Nevertheless it is possible to write header files
10052 \begin_inset LatexCommand \index{Header files}
10053
10054 \end_inset 
10055
10056
10057 \begin_inset LatexCommand \index{Include files}
10058
10059 \end_inset 
10060
10061  which can be shared among different compilers (see section 
10062 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10063
10064 \end_inset 
10065
10066 ).
10067  
10068 \layout Subsubsection
10069
10070 Pointers
10071 \begin_inset LatexCommand \index{Pointer}
10072
10073 \end_inset 
10074
10075  to MCS51/DS390 specific memory spaces
10076 \layout Standard
10077
10078 SDCC allows (via language extensions) pointers to explicitly point to any
10079  of the memory spaces
10080 \begin_inset LatexCommand \index{Memory model}
10081
10082 \end_inset 
10083
10084  of the 8051.
10085  In addition to the explicit pointers, the compiler uses (by default) generic
10086  pointers which can be used to point to any of the memory spaces.
10087 \newline 
10088
10089 \newline 
10090 Pointer declaration examples:
10091 \layout Verse
10092
10093
10094 \family typewriter 
10095 /* pointer physically in internal ram pointing to object in external ram
10096  */ 
10097 \newline 
10098 __xdata unsigned char * __data p;
10099 \newline 
10100
10101 \newline 
10102 /* pointer physically in external ram pointing to object in internal ram
10103  */ 
10104 \newline 
10105 __data unsigned char * __xdata p;
10106 \newline 
10107
10108 \newline 
10109 /* pointer physically in code rom pointing to data in xdata space */ 
10110 \newline 
10111 __xdata unsigned char * __code p;
10112 \newline 
10113
10114 \newline 
10115 /* pointer physically in code space pointing to data in code space */ 
10116 \newline 
10117 __code unsigned char * __code p;
10118 \newline 
10119
10120 \newline 
10121 /* generic pointer physically located in xdata space */
10122 \newline 
10123 unsigned char * __xdata p;
10124 \newline 
10125
10126 \newline 
10127 /* generic pointer physically located in default memory space */
10128 \newline 
10129 unsigned char * p;
10130 \newline 
10131
10132 \newline 
10133 /* the following is a function pointer
10134 \begin_inset LatexCommand \index{function pointer}
10135
10136 \end_inset 
10137
10138  physically located in data space */
10139 \newline 
10140 char (* __data fp)(void);
10141 \layout Standard
10142
10143 Well you get the idea.
10144  
10145 \newline 
10146
10147 \newline 
10148 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10149 \emph on 
10150 generic
10151 \emph default 
10152  pointers.
10153  
10154 \size small 
10155
10156 \newline 
10157
10158 \newline 
10159
10160 \size default 
10161 The highest order byte of the 
10162 \emph on 
10163 generic
10164 \emph default 
10165  pointers contains the data space information.
10166  Assembler support routines are called whenever data is stored or retrieved
10167  using 
10168 \emph on 
10169 generic
10170 \emph default 
10171  pointers.
10172  These are useful for developing reusable library
10173 \begin_inset LatexCommand \index{Libraries}
10174
10175 \end_inset 
10176
10177  routines.
10178  Explicitly specifying the pointer
10179 \begin_inset LatexCommand \index{pointer}
10180
10181 \end_inset 
10182
10183  type will generate the most efficient code.
10184 \layout Subsubsection
10185
10186 Notes on MCS51 memory
10187 \begin_inset LatexCommand \index{MCS51 memory}
10188
10189 \end_inset 
10190
10191  layout
10192 \layout Standard
10193
10194 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10195  RAM memory which is structured as follows:
10196 \newline 
10197
10198 \newline 
10199 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10200  
10201 \newline 
10202 - Bytes 20-2F - 16 bytes to hold 128 bit
10203 \begin_inset LatexCommand \index{bit}
10204
10205 \end_inset 
10206
10207  variables and, 
10208 \newline 
10209 - Bytes 30-7F - 80 bytes for general purpose use.
10210 \newline 
10211
10212 \layout Standard
10213
10214 Additionally some members of the MCS51 family may have up to 128 bytes of
10215  additional, indirectly addressable, internal RAM memory (
10216 \emph on 
10217 idata
10218 \emph default 
10219
10220 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10221
10222 \end_inset 
10223
10224
10225 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10226
10227 \end_inset 
10228
10229 ).
10230  Furthermore, some chips may have some built in external memory (
10231 \emph on 
10232 xdata
10233 \emph default 
10234
10235 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10236
10237 \end_inset 
10238
10239
10240 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10241
10242 \end_inset 
10243
10244 ) which should not be confused with the internal, directly addressable RAM
10245  memory (
10246 \emph on 
10247 data
10248 \emph default 
10249
10250 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10251
10252 \end_inset 
10253
10254
10255 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10256
10257 \end_inset 
10258
10259 ).
10260  Sometimes this built in 
10261 \emph on 
10262 xdata
10263 \emph default 
10264  memory has to be activated before using it (you can probably find this
10265  information on the datasheet of the microcontroller your are using, see
10266  also section 
10267 \begin_inset LatexCommand \ref{sub:Startup-Code}
10268
10269 \end_inset 
10270
10271 \SpecialChar ~
10272 Startup-Code).
10273 \layout Standard
10274
10275 Normally SDCC will only use the first bank
10276 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10277
10278 \end_inset 
10279
10280  of registers (register bank 0), but it is possible to specify that other
10281  banks of registers (keyword 
10282 \emph on 
10283 using
10284 \emph default 
10285  
10286 \emph on 
10287
10288 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10289
10290 \end_inset 
10291
10292
10293 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10294
10295 \end_inset 
10296
10297
10298 \emph default 
10299 ) should be used in interrupt
10300 \begin_inset LatexCommand \index{interrupt}
10301
10302 \end_inset 
10303
10304
10305 \begin_inset LatexCommand \index{\_\_interrupt}
10306
10307 \end_inset 
10308
10309  routines.
10310  By default, the compiler will place the stack after the last byte of allocated
10311  memory for variables.
10312  For example, if the first 2 banks of registers are used, and only four
10313  bytes are used for 
10314 \emph on 
10315 data
10316 \emph default 
10317  variables, it will position the base of the internal stack at address 20
10318  (0x14).
10319  This implies that as the stack
10320 \begin_inset LatexCommand \index{stack}
10321
10322 \end_inset 
10323
10324  grows, it will use up the remaining register banks, and the 16 bytes used
10325  by the 128 bit variables, and 80 bytes for general purpose use.
10326  If any bit variables are used, the data variables will be placed in unused
10327  register banks and after the byte holding the last bit variable.
10328  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10329  (two bytes used), 
10330 \emph on 
10331 data
10332 \emph default 
10333  variables will be placed starting from address 0x10 to 0x20 and continue
10334  at address 0x22.
10335  You can also use -
10336 \begin_inset ERT
10337 status Collapsed
10338
10339 \layout Standard
10340
10341 \backslash 
10342 /
10343 \end_inset 
10344
10345 -data-loc
10346 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10347
10348 \end_inset 
10349
10350  to specify the start address of the 
10351 \emph on 
10352 data
10353 \emph default 
10354  and -
10355 \begin_inset ERT
10356 status Collapsed
10357
10358 \layout Standard
10359
10360 \backslash 
10361 /
10362 \end_inset 
10363
10364 -iram-size
10365 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10366
10367 \end_inset 
10368
10369  to specify the size of the total internal RAM (
10370 \emph on 
10371 data
10372 \emph default 
10373 +
10374 \emph on 
10375 idata
10376 \emph default 
10377 ).
10378  
10379 \newline 
10380
10381 \layout Standard
10382
10383 By default the 8051 linker will place the stack after the last byte of (i)data
10384  variables.
10385  Option -
10386 \begin_inset ERT
10387 status Collapsed
10388
10389 \layout Standard
10390
10391 \backslash 
10392 /
10393 \end_inset 
10394
10395 -stack-loc
10396 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10397
10398 \end_inset 
10399
10400  allows you to specify the start of the stack, i.e.
10401  you could start it after any data in the general purpose area.
10402  If your microcontroller has additional indirectly addressable internal
10403  RAM (
10404 \emph on 
10405 idata
10406 \emph default 
10407 ) you can place the stack on it.
10408  You may also need to use -
10409 \begin_inset ERT
10410 status Collapsed
10411
10412 \layout Standard
10413
10414 \backslash 
10415 /
10416 \end_inset 
10417
10418 -xdata-loc
10419 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10420
10421 \end_inset 
10422
10423  to set the start address of the external RAM (
10424 \emph on 
10425 xdata
10426 \emph default 
10427 ) and -
10428 \begin_inset ERT
10429 status Collapsed
10430
10431 \layout Standard
10432
10433 \backslash 
10434 /
10435 \end_inset 
10436
10437 -xram-size
10438 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10439
10440 \end_inset 
10441
10442  to specify its size.
10443  Same goes for the code memory, using -
10444 \begin_inset ERT
10445 status Collapsed
10446
10447 \layout Standard
10448
10449 \backslash 
10450 /
10451 \end_inset 
10452
10453 -code-loc
10454 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10455
10456 \end_inset 
10457
10458  and -
10459 \begin_inset ERT
10460 status Collapsed
10461
10462 \layout Standard
10463
10464 \backslash 
10465 /
10466 \end_inset 
10467
10468 -code-size
10469 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10470
10471 \end_inset 
10472
10473 .
10474  If in doubt, don't specify any options and see if the resulting memory
10475  layout is appropriate, then you can adjust it.
10476 \layout Standard
10477 \added_space_bottom bigskip 
10478 The linker generates two files with memory allocation information.
10479  The first, with extension .map
10480 \begin_inset LatexCommand \index{<file>.map}
10481
10482 \end_inset 
10483
10484  shows all the variables and segments.
10485  The second with extension .mem
10486 \begin_inset LatexCommand \index{<file>.mem}
10487
10488 \end_inset 
10489
10490  shows the final memory layout.
10491  The linker will complain either if memory segments overlap, there is not
10492  enough memory, or there is not enough space for stack.
10493  If you get any linking warnings and/or errors related to stack or segments
10494  allocation, take a look at either the .map or .mem files to find out what
10495  the problem is.
10496  The .mem file may even suggest a solution to the problem.
10497 \layout Subsection
10498
10499 Z80/Z180 Storage Class
10500 \begin_inset LatexCommand \index{Z80!Storage class}
10501
10502 \end_inset 
10503
10504  Language Extensions
10505 \layout Subsubsection
10506
10507 sfr
10508 \begin_inset LatexCommand \index{sfr}
10509
10510 \end_inset 
10511
10512
10513 \begin_inset LatexCommand \index{\_\_sfr}
10514
10515 \end_inset 
10516
10517  (in/out to 8-bit addresses)
10518 \layout Standard
10519
10520 The Z80
10521 \begin_inset LatexCommand \index{Z80}
10522
10523 \end_inset 
10524
10525  family has separate address spaces for memory and 
10526 \emph on 
10527 i
10528 \emph default 
10529 nput/
10530 \emph on 
10531 o
10532 \emph default 
10533 utput memory.
10534  I/O memory
10535 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10536
10537 \end_inset 
10538
10539
10540 \begin_inset LatexCommand \index{Z80!I/O memory}
10541
10542 \end_inset 
10543
10544
10545 \begin_inset LatexCommand \index{Z180!I/O memory}
10546
10547 \end_inset 
10548
10549  is accessed with special instructions, e.g.:
10550 \layout Verse
10551
10552
10553 \family typewriter 
10554 sfr at 0x78 IoPort;\SpecialChar ~
10555 \SpecialChar ~
10556 /* define a var in I/O space at 78h called IoPort */
10557  
10558 \layout Standard
10559
10560 Writing 0x01 to this variable generates the assembly code:
10561 \layout Verse
10562
10563
10564 \family typewriter 
10565 3E 01\SpecialChar ~
10566 \SpecialChar ~
10567 \SpecialChar ~
10568 \SpecialChar ~
10569 \SpecialChar ~
10570 \SpecialChar ~
10571 ld a,#0x01
10572 \newline 
10573 D3 78\SpecialChar ~
10574 \SpecialChar ~
10575 \SpecialChar ~
10576 \SpecialChar ~
10577 \SpecialChar ~
10578 \SpecialChar ~
10579 out (_IoPort),a 
10580 \layout Subsubsection
10581
10582 banked sfr
10583 \begin_inset LatexCommand \index{sfr}
10584
10585 \end_inset 
10586
10587
10588 \begin_inset LatexCommand \index{\_\_sfr}
10589
10590 \end_inset 
10591
10592  (in/out to 16-bit addresses)
10593 \layout Standard
10594
10595 The keyword 
10596 \emph on 
10597 banked
10598 \emph default 
10599  is used to support 16 bit addresses in I/O memory e.g.:
10600 \layout Verse
10601
10602
10603 \family typewriter 
10604 sfr banked at
10605 \begin_inset LatexCommand \index{at}
10606
10607 \end_inset 
10608
10609
10610 \begin_inset LatexCommand \index{\_\_at}
10611
10612 \end_inset 
10613
10614  0x123 IoPort; 
10615 \layout Standard
10616
10617 Writing 0x01 to this variable generates the assembly code:
10618 \layout Verse
10619
10620
10621 \family typewriter 
10622 01 23 01\SpecialChar ~
10623 \SpecialChar ~
10624 \SpecialChar ~
10625 ld bc,#_IoPort
10626 \newline 
10627 3E 01\SpecialChar ~
10628 \SpecialChar ~
10629 \SpecialChar ~
10630 \SpecialChar ~
10631 \SpecialChar ~
10632 \SpecialChar ~
10633 ld a,#0x01 
10634 \newline 
10635 ED 79\SpecialChar ~
10636 \SpecialChar ~
10637 \SpecialChar ~
10638 \SpecialChar ~
10639 \SpecialChar ~
10640 \SpecialChar ~
10641 out (c),a 
10642 \layout Subsubsection
10643
10644 sfr
10645 \begin_inset LatexCommand \index{sfr}
10646
10647 \end_inset 
10648
10649
10650 \begin_inset LatexCommand \index{\_\_sfr}
10651
10652 \end_inset 
10653
10654  (in0/out0 to 8 bit addresses on Z180
10655 \begin_inset LatexCommand \index{Z180}
10656
10657 \end_inset 
10658
10659 /HD64180
10660 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10661
10662 \end_inset 
10663
10664 )
10665 \layout Standard
10666 \added_space_bottom bigskip 
10667 The compiler option -
10668 \begin_inset ERT
10669 status Collapsed
10670
10671 \layout Standard
10672
10673 \backslash 
10674 /
10675 \end_inset 
10676
10677 -portmode
10678 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10679
10680 \end_inset 
10681
10682 =180 (80) and a compiler #pragma\SpecialChar ~
10683 portmode
10684 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10685
10686 \end_inset 
10687
10688  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10689 ns 
10690 \family typewriter 
10691 in0/out0
10692 \family default 
10693  instead of 
10694 \family typewriter 
10695 in/out
10696 \family default 
10697 .
10698  If you include the file z180.h this will be set automatically.
10699 \layout Subsection
10700
10701 HC08 Storage Class
10702 \begin_inset LatexCommand \index{HC08!Storage class}
10703
10704 \end_inset 
10705
10706  Language Extensions
10707 \layout Subsubsection
10708
10709 data
10710 \begin_inset LatexCommand \index{data (hc08 storage class)}
10711
10712 \end_inset 
10713
10714
10715 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10716
10717 \end_inset 
10718
10719  
10720 \layout Standard
10721
10722 The data storage class declares a variable that resides in the first 256
10723  bytes of memory (the direct page).
10724  The HC08
10725 \begin_inset LatexCommand \index{HC08}
10726
10727 \end_inset 
10728
10729  is most efficient at accessing variables (especially pointers) stored here.
10730 \layout Subsubsection
10731
10732 xdata
10733 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10734
10735 \end_inset 
10736
10737
10738 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10739
10740 \end_inset 
10741
10742  
10743 \layout Standard
10744 \added_space_bottom bigskip 
10745 The xdata storage class declares a variable that can reside anywhere in
10746  memory.
10747  This is the default if no storage class is specified.
10748  
10749 \layout Section
10750
10751 Absolute Addressing
10752 \begin_inset LatexCommand \index{Absolute addressing}
10753
10754 \end_inset 
10755
10756
10757 \layout Standard
10758
10759 Data items can be assigned an absolute address with the 
10760 \emph on 
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  <address>
10772 \emph default 
10773  keyword, in addition to a storage class, e.g.:
10774 \layout Verse
10775
10776
10777 \family typewriter 
10778 xdata
10779 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10780
10781 \end_inset 
10782
10783
10784 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10785
10786 \end_inset 
10787
10788  at
10789 \begin_inset LatexCommand \index{at}
10790
10791 \end_inset 
10792
10793
10794 \begin_inset LatexCommand \index{\_\_at}
10795
10796 \end_inset 
10797
10798  0x7ffe unsigned int chksum;
10799 \layout Standard
10800
10801 or, better conforming to ISO/IEC 9899 C:
10802 \layout Verse
10803
10804
10805 \family typewriter 
10806 __xdata __at (0x7ffe) unsigned int chksum;
10807 \layout Standard
10808
10809 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10810  of the external ram.
10811  The compiler does 
10812 \emph on 
10813 not
10814 \emph default 
10815  reserve any space for variables declared in this way
10816 \begin_inset Marginal
10817 collapsed true
10818
10819 \layout Standard
10820
10821
10822 \series bold 
10823 \SpecialChar ~
10824 !
10825 \end_inset 
10826
10827  (they are implemented with an equate in the assembler).
10828  Thus it is left to the programmer to make sure there are no overlaps with
10829  other variables that are declared without the absolute address.
10830  The assembler listing file (.lst
10831 \begin_inset LatexCommand \index{<file>.lst}
10832
10833 \end_inset 
10834
10835 ) and the linker output files (.rst
10836 \begin_inset LatexCommand \index{<file>.rst}
10837
10838 \end_inset 
10839
10840 ) and (.map
10841 \begin_inset LatexCommand \index{<file>.map}
10842
10843 \end_inset 
10844
10845 ) are good places to look for such overlaps.
10846  Variables with an absolute address are 
10847 \emph on 
10848 not
10849 \begin_inset Marginal
10850 collapsed true
10851
10852 \layout Standard
10853
10854
10855 \series bold 
10856 \SpecialChar ~
10857 !
10858 \end_inset 
10859
10860
10861 \emph default 
10862  initialized
10863 \begin_inset LatexCommand \index{Variable initialization}
10864
10865 \end_inset 
10866
10867 .
10868 \layout Standard
10869
10870 In case of memory mapped I/O devices the keyword 
10871 \emph on 
10872 volatile
10873 \emph default 
10874  has to be used to tell the compiler that accesses might not be removed:
10875 \layout Verse
10876
10877
10878 \family typewriter 
10879 volatile
10880 \begin_inset LatexCommand \index{volatile}
10881
10882 \end_inset 
10883
10884  __xdata
10885 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10886
10887 \end_inset 
10888
10889  __at
10890 \begin_inset LatexCommand \index{at}
10891
10892 \end_inset 
10893
10894  (0x8000) unsigned char PORTA_8255;
10895 \layout Standard
10896
10897 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10898 r) array
10899 \family typewriter 
10900 \size footnotesize 
10901
10902 \begin_inset LatexCommand \index{Aligned array}
10903
10904 \end_inset 
10905
10906
10907 \family default 
10908 \size default 
10909  starts at a block (256 byte) boundary
10910 \begin_inset LatexCommand \index{block boundary}
10911
10912 \end_inset 
10913
10914  (section 
10915 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10916
10917 \end_inset 
10918
10919  has an example).
10920 \newline 
10921 Absolute addresses can be specified for variables in all storage classes,
10922  e.g.:
10923 \layout Verse
10924
10925
10926 \family typewriter 
10927 __bit
10928 \begin_inset LatexCommand \index{bit}
10929
10930 \end_inset 
10931
10932  __at
10933 \begin_inset LatexCommand \index{at}
10934
10935 \end_inset 
10936
10937  (0x02) bvar;
10938 \layout Standard
10939
10940 The above example will allocate the variable at offset 0x02 in the bit-addressab
10941 le space.
10942  There is no real advantage to assigning absolute addresses to variables
10943  in this manner, unless you want strict control over all the variables allocated.
10944  One possible use would be to write hardware portable code.
10945  For example, if you have a routine that uses one or more of the microcontroller
10946  I/O pins, and such pins are different for two different hardwares, you
10947  can declare the I/O pins in your routine using:
10948 \layout Verse
10949
10950
10951 \family typewriter 
10952 extern volatile
10953 \begin_inset LatexCommand \index{volatile}
10954
10955 \end_inset 
10956
10957  __bit MOSI;\SpecialChar ~
10958 \SpecialChar ~
10959 \SpecialChar ~
10960 \SpecialChar ~
10961 /* master out, slave in */
10962 \newline 
10963 extern volatile __bit MISO;\SpecialChar ~
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 /* master in, slave out */
10968 \newline 
10969 extern volatile __bit MCLK;\SpecialChar ~
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 /* master clock */
10974 \newline 
10975
10976 \newline 
10977 /* Input and Output of a byte on a 3-wire serial bus.
10978 \newline 
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 If needed adapt polarity of clock, polarity of data and bit order
10983 \newline 
10984 \SpecialChar ~
10985 */
10986 \newline 
10987 unsigned char spi_io(unsigned char out_byte) 
10988 \newline 
10989
10990 \newline 
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 \SpecialChar ~
10995 unsigned char i=8;
10996 \newline 
10997 \SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 \SpecialChar ~
11001 do { 
11002 \newline 
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 MOSI = out_byte & 0x80; 
11012 \newline 
11013 \SpecialChar ~
11014 \SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 out_byte <<= 1;
11022 \newline 
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 MCLK = 1; 
11032 \newline 
11033 \SpecialChar ~
11034 \SpecialChar ~
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 /* _asm nop _endasm; */\SpecialChar ~
11042 \SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 \SpecialChar ~
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 /* for slow peripherals */
11050 \newline 
11051 \SpecialChar ~
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 if(MISO) 
11060 \newline 
11061 \SpecialChar ~
11062 \SpecialChar ~
11063 \SpecialChar ~
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 out_byte += 1; 
11074 \newline 
11075 \SpecialChar ~
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 MCLK = 0; 
11084 \newline 
11085 \SpecialChar ~
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 } while(--i);
11090 \newline 
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 \SpecialChar ~
11095 return out_byte; 
11096 \newline 
11097 }
11098 \layout Standard
11099
11100 Then, someplace in the code for the first hardware you would use
11101 \layout Verse
11102
11103
11104 \family typewriter 
11105 __bit __at
11106 \begin_inset LatexCommand \index{at}
11107
11108 \end_inset 
11109
11110
11111 \begin_inset LatexCommand \index{\_\_at}
11112
11113 \end_inset 
11114
11115  (0x80) MOSI;\SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 /* I/O port 0, bit 0 */
11120 \newline 
11121 __bit __at (0x81) MISO;\SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 /* I/O port 0, bit 1 */
11126 \newline 
11127 __bit __at (0x82) MCLK;\SpecialChar ~
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 /* I/O port 0, bit 2 */
11132 \layout Standard
11133
11134 Similarly, for the second hardware you would use
11135 \layout Verse
11136
11137
11138 \family typewriter 
11139 __bit __at (0x83) MOSI;\SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 /* I/O port 0, bit 3 */
11144 \newline 
11145 __bit __at (0x91) MISO;\SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 /* I/O port 1, bit 1 */
11150 \newline 
11151 __bit
11152 \begin_inset LatexCommand \index{bit}
11153
11154 \end_inset 
11155
11156  __at (0x92) MCLK;\SpecialChar ~
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 /* I/O port 1, bit 2 */
11161 \layout Standard
11162 \added_space_bottom bigskip 
11163 and you can use the same hardware dependent routine without changes, as
11164  for example in a library.
11165  This is somehow similar to sbit, but only one absolute address has to be
11166  specified in the whole project.
11167 \layout Section
11168
11169 Parameters
11170 \begin_inset LatexCommand \index{Parameters}
11171
11172 \end_inset 
11173
11174
11175 \begin_inset LatexCommand \index{function parameter}
11176
11177 \end_inset 
11178
11179  & Local Variables
11180 \begin_inset LatexCommand \index{local variables}
11181
11182 \end_inset 
11183
11184
11185 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11186
11187 \end_inset 
11188
11189
11190 \layout Standard
11191
11192 Automatic (local) variables and parameters to functions can either be placed
11193  on the stack or in data-space.
11194  The default action of the compiler is to place these variables in the internal
11195  RAM (for small model) or external RAM (for large model).
11196  This in fact makes them similar to 
11197 \emph on 
11198 static
11199 \begin_inset LatexCommand \index{static}
11200
11201 \end_inset 
11202
11203
11204 \emph default 
11205  so by default functions are non-reentrant
11206 \begin_inset LatexCommand \index{reentrant}
11207
11208 \end_inset 
11209
11210 .
11211  
11212 \newline 
11213
11214 \newline 
11215 They can be placed on the stack
11216 \begin_inset LatexCommand \index{stack}
11217
11218 \end_inset 
11219
11220  by using the
11221 \emph on 
11222  -
11223 \begin_inset ERT
11224 status Collapsed
11225
11226 \layout Standard
11227
11228 \backslash 
11229 /
11230 \end_inset 
11231
11232 -stack-auto
11233 \begin_inset LatexCommand \index{-\/-stack-auto}
11234
11235 \end_inset 
11236
11237
11238 \emph default 
11239  option, by using 
11240 \emph on 
11241 #pragma\SpecialChar ~
11242 stackauto
11243 \emph default 
11244
11245 \begin_inset LatexCommand \index{\#pragma stackauto}
11246
11247 \end_inset 
11248
11249  or by using the 
11250 \emph on 
11251 reentrant
11252 \begin_inset LatexCommand \index{reentrant}
11253
11254 \end_inset 
11255
11256
11257 \emph default 
11258  keyword in the function declaration, e.g.:
11259 \layout Verse
11260
11261
11262 \family typewriter 
11263 unsigned char foo(char i) __reentrant 
11264 \newline 
11265
11266 \newline 
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 \SpecialChar ~
11270 \SpecialChar ~
11271 ...
11272  
11273 \newline 
11274 }
11275 \layout Standard
11276
11277 Since stack space on 8051 is limited, the 
11278 \emph on 
11279 reentrant 
11280 \emph default 
11281 keyword or the
11282 \emph on 
11283  -
11284 \begin_inset ERT
11285 status Collapsed
11286
11287 \layout Standard
11288
11289 \backslash 
11290 /
11291 \end_inset 
11292
11293 -stack-auto
11294 \emph default 
11295  option should be used sparingly.
11296  Note that the reentrant keyword just means that the parameters & local
11297  variables will be allocated to the stack, it 
11298 \emph on 
11299 does not
11300 \emph default 
11301  mean that the function is register bank
11302 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11303
11304 \end_inset 
11305
11306  independent.
11307 \newline 
11308
11309 \newline 
11310 Local variables
11311 \begin_inset LatexCommand \index{local variables}
11312
11313 \end_inset 
11314
11315  can be assigned storage classes and absolute
11316 \begin_inset LatexCommand \index{Absolute addressing}
11317
11318 \end_inset 
11319
11320  addresses, e.g.: 
11321 \layout Verse
11322
11323
11324 \family typewriter 
11325 unsigned char foo() 
11326 \newline 
11327 {
11328 \newline 
11329 \SpecialChar ~
11330 \SpecialChar ~
11331 \SpecialChar ~
11332 \SpecialChar ~
11333 __xdata unsigned char i;
11334 \newline 
11335 \SpecialChar ~
11336 \SpecialChar ~
11337 \SpecialChar ~
11338 \SpecialChar ~
11339 __bit bvar;
11340 \newline 
11341 \SpecialChar ~
11342 \SpecialChar ~
11343 \SpecialChar ~
11344 \SpecialChar ~
11345 __data __at
11346 \begin_inset LatexCommand \index{at}
11347
11348 \end_inset 
11349
11350  (0x31) unsigned char j;
11351 \newline 
11352 \SpecialChar ~
11353 \SpecialChar ~
11354 \SpecialChar ~
11355 \SpecialChar ~
11356 ...
11357  
11358 \newline 
11359 }
11360 \layout Standard
11361
11362 In the above example the variable 
11363 \emph on 
11364 i
11365 \emph default 
11366  will be allocated in the external ram, 
11367 \emph on 
11368 bvar
11369 \emph default 
11370  in bit addressable space and
11371 \emph on 
11372  j
11373 \emph default 
11374  in internal ram.
11375  When compiled with 
11376 \emph on 
11377 -
11378 \begin_inset ERT
11379 status Collapsed
11380
11381 \layout Standard
11382
11383 \backslash 
11384 /
11385 \end_inset 
11386
11387 -stack-auto
11388 \emph default 
11389  or when a function is declared as 
11390 \emph on 
11391 reentrant
11392 \emph default 
11393  this should only be done for static variables.
11394 \layout Standard
11395
11396 Parameters
11397 \begin_inset LatexCommand \index{function parameter}
11398
11399 \end_inset 
11400
11401  however are not allowed any storage class
11402 \begin_inset LatexCommand \index{Storage class}
11403
11404 \end_inset 
11405
11406 , (storage classes for parameters will be ignored), their allocation is
11407  governed by the memory model in use, and the reentrancy options.
11408 \layout Standard
11409
11410 It is however allowed to use bit parameters in reentrant functions and also
11411  non-static local bit variables are supported.
11412  Efficient use is limited to 8 semi-bitregisters in bit space.
11413  They are pushed and popped to stack
11414 \begin_inset LatexCommand \index{stack}
11415
11416 \end_inset 
11417
11418  as a single byte just like the normal registers.
11419 \layout Section
11420
11421 Overlaying
11422 \begin_inset LatexCommand \label{sub:Overlaying}
11423
11424 \end_inset 
11425
11426
11427 \begin_inset LatexCommand \index{Overlaying}
11428
11429 \end_inset 
11430
11431
11432 \layout Standard
11433
11434 For non-reentrant
11435 \begin_inset LatexCommand \index{reentrant}
11436
11437 \end_inset 
11438
11439  functions SDCC will try to reduce internal ram space usage by overlaying
11440  parameters and local variables of a function (if possible).
11441  Parameters and local variables
11442 \begin_inset LatexCommand \index{local variables}
11443
11444 \end_inset 
11445
11446  of a function will be allocated to an overlayable segment if the function
11447  has 
11448 \emph on 
11449 no other function calls and the function is non-reentrant and the memory
11450  model
11451 \begin_inset LatexCommand \index{Memory model}
11452
11453 \end_inset 
11454
11455  is small.
11456
11457 \emph default 
11458  If an explicit storage class
11459 \begin_inset LatexCommand \index{Storage class}
11460
11461 \end_inset 
11462
11463  is specified for a local variable, it will NOT be overlayed.
11464 \layout Standard
11465
11466 Note that the compiler (not the linkage editor) makes the decision for overlayin
11467 g the data items.
11468  Functions that are called from an interrupt service routine
11469 \begin_inset Marginal
11470 collapsed true
11471
11472 \layout Standard
11473
11474
11475 \series bold 
11476 !
11477 \end_inset 
11478
11479  should be preceded by a #pragma\SpecialChar ~
11480 nooverlay
11481 \begin_inset LatexCommand \index{\#pragma nooverlay}
11482
11483 \end_inset 
11484
11485  if they are not reentrant.
11486 \layout Standard
11487
11488 Also note that the compiler does not do any processing of inline assembler
11489  code, so the compiler might incorrectly assign local variables and parameters
11490  of a function into the overlay segment if the inline assembler code calls
11491  other c-functions that might use the overlay.
11492  In that case the #pragma\SpecialChar ~
11493 nooverlay should be used.
11494 \layout Standard
11495
11496 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11497 tion
11498 \begin_inset LatexCommand \index{Multiplication}
11499
11500 \end_inset 
11501
11502  or division
11503 \begin_inset LatexCommand \index{Division}
11504
11505 \end_inset 
11506
11507  will NOT be overlayed since these are implemented using external functions,
11508  e.g.:
11509 \layout Verse
11510
11511
11512 \family typewriter 
11513 #pragma save 
11514 \newline 
11515 #pragma nooverlay
11516 \begin_inset LatexCommand \index{\#pragma nooverlay}
11517
11518 \end_inset 
11519
11520  
11521 \newline 
11522 void set_error(unsigned char errcd) 
11523 \newline 
11524 {
11525 \newline 
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 P3 = errcd;
11531 \newline 
11532
11533 \newline 
11534 #pragma restore 
11535 \newline 
11536
11537 \newline 
11538 void some_isr () __interrupt
11539 \begin_inset LatexCommand \index{interrupt}
11540
11541 \end_inset 
11542
11543  (2)
11544 \newline 
11545 {
11546 \newline 
11547 \SpecialChar ~
11548 \SpecialChar ~
11549 \SpecialChar ~
11550 \SpecialChar ~
11551 ...
11552 \newline 
11553 \SpecialChar ~
11554 \SpecialChar ~
11555 \SpecialChar ~
11556 \SpecialChar ~
11557 set_error(10);
11558 \newline 
11559 \SpecialChar ~
11560 \SpecialChar ~
11561 \SpecialChar ~
11562 \SpecialChar ~
11563 ...
11564  
11565 \newline 
11566 }
11567 \layout Standard
11568 \added_space_bottom bigskip 
11569 In the above example the parameter 
11570 \emph on 
11571 errcd
11572 \emph default 
11573  for the function 
11574 \emph on 
11575 set_error
11576 \emph default 
11577  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11578 nooverlay was
11579  not present, this could cause unpredictable runtime behavior when called
11580  from an interrupt service routine.
11581  The #pragma\SpecialChar ~
11582 nooverlay ensures that the parameters and local variables for
11583  the function are NOT overlayed.
11584 \layout Section
11585
11586 Interrupt Service Routines
11587 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11588
11589 \end_inset 
11590
11591
11592 \layout Subsection
11593
11594 General Information
11595 \layout Standard
11596
11597 SDCC allows 
11598 \emph on 
11599 i
11600 \emph default 
11601 nterrupt 
11602 \emph on 
11603 s
11604 \emph default 
11605 ervice 
11606 \emph on 
11607 r
11608 \emph default 
11609 outines to be coded in C, with some extended keywords.
11610 \layout Verse
11611
11612
11613 \family typewriter 
11614 void timer_isr (void) __interrupt (1) __using (1) 
11615 \newline 
11616
11617 \newline 
11618 \SpecialChar ~
11619 \SpecialChar ~
11620 \SpecialChar ~
11621 \SpecialChar ~
11622 ...
11623  
11624 \newline 
11625 }
11626 \layout Standard
11627
11628 The optional number following the 
11629 \emph on 
11630 interrupt
11631 \begin_inset LatexCommand \index{interrupt}
11632
11633 \end_inset 
11634
11635
11636 \begin_inset LatexCommand \index{\_\_interrupt}
11637
11638 \end_inset 
11639
11640
11641 \emph default 
11642  keyword is the interrupt number this routine will service.
11643  When present, the compiler will insert a call to this routine in the interrupt
11644  vector table
11645 \begin_inset LatexCommand \index{interrupt vector table}
11646
11647 \end_inset 
11648
11649  for the interrupt number specified.
11650  If you have multiple source files in your project, interrupt service routines
11651  can be present in any of them, but a prototype of the isr MUST be present
11652  or included in the file that contains the function 
11653 \emph on 
11654 main
11655 \emph default 
11656 .
11657  The optional (8051 specific) keyword 
11658 \emph on 
11659 using
11660 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11661
11662 \end_inset 
11663
11664
11665 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11666
11667 \end_inset 
11668
11669
11670 \emph default 
11671  can be used to tell the compiler to use the specified register bank when
11672  generating code for this function.
11673  
11674 \newline 
11675 Interrupt service routines open the door for some very interesting bugs:
11676 \layout Subsubsection
11677
11678
11679 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11680
11681 \end_inset 
11682
11683 Common interrupt pitfall: variable not declared 
11684 \emph on 
11685 volatile
11686 \layout Standard
11687
11688 If an interrupt service routine changes variables which are accessed by
11689  other functions these variables have to be declared 
11690 \emph on 
11691 volatile
11692 \emph default 
11693
11694 \begin_inset LatexCommand \index{volatile}
11695
11696 \end_inset 
11697
11698 .
11699  See 
11700 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11701
11702 \end_inset 
11703
11704  .
11705 \layout Subsubsection
11706
11707
11708 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11709
11710 \end_inset 
11711
11712 Common interrupt pitfall: 
11713 \emph on 
11714 non-atomic access
11715 \layout Standard
11716
11717 If the access to these variables is not 
11718 \emph on 
11719 atomic
11720 \begin_inset LatexCommand \index{atomic}
11721
11722 \end_inset 
11723
11724
11725 \emph default 
11726  (i.e.
11727  the processor needs more than one instruction for the access and could
11728  be interrupted while accessing the variable) the interrupt must be disabled
11729  during the access to avoid inconsistent data.
11730  
11731 \newline 
11732 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11733  should be protected by disabling interrupts.
11734  You're not automatically on the safe side if you use 8 bit variables though.
11735  We need an example here: f.e.
11736  on the 8051 the harmless looking 
11737 \begin_inset Quotes srd
11738 \end_inset 
11739
11740
11741 \family typewriter 
11742 flags\SpecialChar ~
11743 |=\SpecialChar ~
11744 0x80;
11745 \family default 
11746
11747 \begin_inset Quotes sld
11748 \end_inset 
11749
11750  is not atomic if 
11751 \family typewriter 
11752 flags
11753 \family default 
11754  resides in xdata.
11755  Setting 
11756 \begin_inset Quotes srd
11757 \end_inset 
11758
11759
11760 \family typewriter 
11761 flags\SpecialChar ~
11762 |=\SpecialChar ~
11763 0x40;
11764 \family default 
11765
11766 \begin_inset Quotes sld
11767 \end_inset 
11768
11769  from within an interrupt routine might get lost if the interrupt occurs
11770  at the wrong time.
11771  
11772 \begin_inset Quotes sld
11773 \end_inset 
11774
11775
11776 \family typewriter 
11777 counter\SpecialChar ~
11778 +=\SpecialChar ~
11779 8;
11780 \family default 
11781
11782 \begin_inset Quotes srd
11783 \end_inset 
11784
11785  is not atomic on the 8051 even if 
11786 \family typewriter 
11787 counter
11788 \family default 
11789  is located in data memory.
11790 \newline 
11791 Bugs like these are hard to reproduce and can cause a lot of trouble.
11792  
11793 \layout Subsubsection
11794
11795
11796 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11797
11798 \end_inset 
11799
11800 Common interrupt pitfall: 
11801 \emph on 
11802 stack overflow
11803 \layout Standard
11804
11805 The return address and the registers used in the interrupt service routine
11806  are saved on the stack
11807 \begin_inset LatexCommand \index{stack}
11808
11809 \end_inset 
11810
11811  so there must be sufficient stack space.
11812  If there isn't variables or registers (or even the return address itself)
11813  will be corrupted.
11814  This 
11815 \emph on 
11816 stack overflow
11817 \emph default 
11818
11819 \begin_inset LatexCommand \index{stack overflow}
11820
11821 \end_inset 
11822
11823  is most likely to happen if the interrupt occurs during the 
11824 \begin_inset Quotes sld
11825 \end_inset 
11826
11827 deepest
11828 \begin_inset Quotes srd
11829 \end_inset 
11830
11831  subroutine when the stack is already in use for f.e.
11832  many return addresses.
11833 \layout Subsubsection
11834
11835
11836 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11837
11838 \end_inset 
11839
11840 Common interrupt pitfall: 
11841 \emph on 
11842 use of non-reentrant functions
11843 \layout Standard
11844
11845 A special note here, int (16 bit) and long (32 bit) integer division
11846 \begin_inset LatexCommand \index{Division}
11847
11848 \end_inset 
11849
11850 , multiplication
11851 \begin_inset LatexCommand \index{Multiplication}
11852
11853 \end_inset 
11854
11855  & modulus
11856 \begin_inset LatexCommand \index{Modulus}
11857
11858 \end_inset 
11859
11860  and floating-point
11861 \begin_inset LatexCommand \index{Floating point support}
11862
11863 \end_inset 
11864
11865  operations are implemented using external support routines.
11866  If an interrupt service routine needs to do any of these operations then
11867  the support routines (as mentioned in a following section) will have to
11868  be recompiled using the
11869 \emph on 
11870  -
11871 \begin_inset ERT
11872 status Collapsed
11873
11874 \layout Standard
11875
11876 \backslash 
11877 /
11878 \end_inset 
11879
11880 -stack-auto
11881 \begin_inset LatexCommand \index{-\/-stack-auto}
11882
11883 \end_inset 
11884
11885
11886 \emph default 
11887  option and the source file will need to be compiled using the 
11888 \emph on 
11889 -
11890 \begin_inset ERT
11891 status Collapsed
11892
11893 \layout Standard
11894
11895 \backslash 
11896 /
11897 \end_inset 
11898
11899 -int-long-reent
11900 \emph default 
11901
11902 \begin_inset LatexCommand \index{-\/-int-long-reent}
11903
11904 \end_inset 
11905
11906  compiler option.
11907  
11908 \newline 
11909 Note, the type promotion
11910 \begin_inset LatexCommand \index{type promotion}
11911
11912 \end_inset 
11913
11914  required by ANSI C can cause 16 bit routines to be used
11915 \begin_inset Marginal
11916 collapsed true
11917
11918 \layout Standard
11919
11920
11921 \series bold 
11922 \SpecialChar ~
11923 !
11924 \end_inset 
11925
11926  without the programmer being aware of it.
11927  See f.e.
11928  the cast 
11929 \family typewriter 
11930 (unsigned char)(tail-1)
11931 \family default 
11932  within the if clause in section 
11933 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11934
11935 \end_inset 
11936
11937 .
11938 \layout Standard
11939 \added_space_bottom bigskip 
11940 Calling other functions from an interrupt service routine is not recommended,
11941  avoid it if possible.
11942  Note that when some function is called from an interrupt service routine
11943  it should be preceded by a #pragma\SpecialChar ~
11944 nooverlay
11945 \begin_inset LatexCommand \index{\#pragma nooverlay}
11946
11947 \end_inset 
11948
11949  if it is not reentrant.
11950  Furthermore nonreentrant functions should not be called from the main program
11951  while the interrupt service routine might be active.
11952  They also must not be called from low priority interrupt service routines
11953  while a high priority interrupt service routine might be active.
11954  You could use semaphores or make the function
11955 \emph on 
11956  critical
11957 \emph default 
11958  if all parameters are passed in registers.
11959 \newline 
11960  Also see section 
11961 \begin_inset LatexCommand \ref{sub:Overlaying}
11962
11963 \end_inset 
11964
11965 \SpecialChar ~
11966 about Overlaying and section 
11967 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11968
11969 \end_inset 
11970
11971 \SpecialChar ~
11972 about Functions using private register banks.
11973 \layout Subsection
11974
11975 MCS51/DS390 Interrupt Service Routines
11976 \layout Standard
11977
11978 Interrupt
11979 \begin_inset LatexCommand \index{interrupt}
11980
11981 \end_inset 
11982
11983  numbers and the corresponding address & descriptions for the Standard 8051/8052
11984  are listed below.
11985  SDCC will automatically adjust the 
11986 \begin_inset LatexCommand \index{interrupt vector table}
11987
11988 \end_inset 
11989
11990  to the maximum interrupt number specified.
11991 \newline 
11992
11993 \layout Standard
11994 \align center 
11995
11996 \begin_inset  Tabular
11997 <lyxtabular version="3" rows="9" columns="3">
11998 <features>
11999 <column alignment="center" valignment="top" leftline="true" width="0in">
12000 <column alignment="left" valignment="top" leftline="true" width="0in">
12001 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12002 <row topline="true" bottomline="true">
12003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12004 \begin_inset Text
12005
12006 \layout Standard
12007
12008 Interrupt #
12009 \end_inset 
12010 </cell>
12011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12012 \begin_inset Text
12013
12014 \layout Standard
12015
12016 Description
12017 \end_inset 
12018 </cell>
12019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12020 \begin_inset Text
12021
12022 \layout Standard
12023
12024 Vector Address
12025 \end_inset 
12026 </cell>
12027 </row>
12028 <row topline="true">
12029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12030 \begin_inset Text
12031
12032 \layout Standard
12033
12034 0
12035 \end_inset 
12036 </cell>
12037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12038 \begin_inset Text
12039
12040 \layout Standard
12041
12042 External 0
12043 \end_inset 
12044 </cell>
12045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12046 \begin_inset Text
12047
12048 \layout Standard
12049
12050 0x0003
12051 \end_inset 
12052 </cell>
12053 </row>
12054 <row topline="true">
12055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12056 \begin_inset Text
12057
12058 \layout Standard
12059
12060 1
12061 \end_inset 
12062 </cell>
12063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12064 \begin_inset Text
12065
12066 \layout Standard
12067
12068 Timer 0
12069 \end_inset 
12070 </cell>
12071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12072 \begin_inset Text
12073
12074 \layout Standard
12075
12076 0x000b
12077 \end_inset 
12078 </cell>
12079 </row>
12080 <row topline="true">
12081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12082 \begin_inset Text
12083
12084 \layout Standard
12085
12086 2
12087 \end_inset 
12088 </cell>
12089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12090 \begin_inset Text
12091
12092 \layout Standard
12093
12094 External 1
12095 \end_inset 
12096 </cell>
12097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12098 \begin_inset Text
12099
12100 \layout Standard
12101
12102 0x0013
12103 \end_inset 
12104 </cell>
12105 </row>
12106 <row topline="true">
12107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12108 \begin_inset Text
12109
12110 \layout Standard
12111
12112 3
12113 \end_inset 
12114 </cell>
12115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12116 \begin_inset Text
12117
12118 \layout Standard
12119
12120 Timer 1
12121 \end_inset 
12122 </cell>
12123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12124 \begin_inset Text
12125
12126 \layout Standard
12127
12128 0x001b
12129 \end_inset 
12130 </cell>
12131 </row>
12132 <row topline="true">
12133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12134 \begin_inset Text
12135
12136 \layout Standard
12137
12138 4
12139 \end_inset 
12140 </cell>
12141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12142 \begin_inset Text
12143
12144 \layout Standard
12145
12146 Serial
12147 \end_inset 
12148 </cell>
12149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12150 \begin_inset Text
12151
12152 \layout Standard
12153
12154 0x0023
12155 \end_inset 
12156 </cell>
12157 </row>
12158 <row topline="true">
12159 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12160 \begin_inset Text
12161
12162 \layout Standard
12163
12164 5
12165 \end_inset 
12166 </cell>
12167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12168 \begin_inset Text
12169
12170 \layout Standard
12171
12172 Timer 2 (8052)
12173 \end_inset 
12174 </cell>
12175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12176 \begin_inset Text
12177
12178 \layout Standard
12179
12180 0x002b
12181 \end_inset 
12182 </cell>
12183 </row>
12184 <row topline="true">
12185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12186 \begin_inset Text
12187
12188 \layout Standard
12189
12190 ...
12191 \end_inset 
12192 </cell>
12193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12194 \begin_inset Text
12195
12196 \layout Standard
12197
12198 \end_inset 
12199 </cell>
12200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12201 \begin_inset Text
12202
12203 \layout Standard
12204
12205 ...
12206 \end_inset 
12207 </cell>
12208 </row>
12209 <row topline="true" bottomline="true">
12210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12211 \begin_inset Text
12212
12213 \layout Standard
12214
12215 n
12216 \end_inset 
12217 </cell>
12218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12219 \begin_inset Text
12220
12221 \layout Standard
12222
12223 \end_inset 
12224 </cell>
12225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12226 \begin_inset Text
12227
12228 \layout Standard
12229
12230 0x0003 + 8*n
12231 \end_inset 
12232 </cell>
12233 </row>
12234 </lyxtabular>
12235
12236 \end_inset 
12237
12238
12239 \newline 
12240
12241 \layout Standard
12242
12243 If the interrupt service routine is defined without 
12244 \emph on 
12245 using
12246 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12247
12248 \end_inset 
12249
12250
12251 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12252
12253 \end_inset 
12254
12255
12256 \emph default 
12257  a register bank or with register bank 0 (
12258 \emph on 
12259 using
12260 \emph default 
12261  0), the compiler will save the registers used by itself on the stack upon
12262  entry and restore them at exit, however if such an interrupt service routine
12263  calls another function then the entire register bank will be saved on the
12264  stack.
12265  This scheme may be advantageous for small interrupt service routines which
12266  have low register usage.
12267 \layout Standard
12268 \added_space_bottom bigskip 
12269 If the interrupt service routine is defined to be using a specific register
12270  bank then only 
12271 \emph on 
12272 a, b, dptr
12273 \emph default 
12274  & psw are saved and restored, if such an interrupt service routine calls
12275  another function (using another register bank) then the entire register
12276  bank of the called function will be saved on the stack
12277 \begin_inset LatexCommand \index{stack}
12278
12279 \end_inset 
12280
12281 .
12282  This scheme is recommended for larger interrupt service routines.
12283 \layout Subsection
12284
12285 HC08
12286 \begin_inset LatexCommand \index{HC08}
12287
12288 \end_inset 
12289
12290  Interrupt Service Routines
12291 \layout Standard
12292 \added_space_bottom bigskip 
12293 Since the number of interrupts
12294 \begin_inset LatexCommand \index{HC08!interrupt}
12295
12296 \end_inset 
12297
12298  available is chip specific and the interrupt vector table always ends at
12299  the last byte of memory, the interrupt numbers corresponds to the interrupt
12300  vectors in reverse order of address.
12301  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12302  2 will use the interrupt vector at 0xfffa, and so on.
12303  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12304  this way; instead see section 
12305 \begin_inset LatexCommand \ref{sub:Startup-Code}
12306
12307 \end_inset 
12308
12309  for details on customizing startup.
12310 \layout Subsection
12311
12312 Z80 Interrupt Service Routines
12313 \layout Standard
12314
12315 The Z80
12316 \begin_inset LatexCommand \index{Z80}
12317
12318 \end_inset 
12319
12320  uses several different methods for determining the correct interrupt
12321 \begin_inset LatexCommand \index{Z80!interrupt}
12322
12323 \end_inset 
12324
12325  vector depending on the hardware implementation.
12326  Therefore, SDCC ignores the optional interrupt number and does not attempt
12327  to generate an interrupt vector table.
12328 \layout Standard
12329
12330 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12331  instruction to return from the interrupt.
12332  To write an interrupt handler for the non-maskable interrupt, which needs
12333  a RETN instruction instead, add the 
12334 \emph on 
12335 critical
12336 \emph default 
12337  keyword:
12338 \layout Verse
12339
12340
12341 \family typewriter 
12342 void nmi_isr (void) critical interrupt
12343 \newline 
12344
12345 \newline 
12346 \SpecialChar ~
12347 \SpecialChar ~
12348 \SpecialChar ~
12349 \SpecialChar ~
12350 ...
12351  
12352 \newline 
12353 }
12354 \layout Standard
12355 \added_space_bottom bigskip 
12356 However if you need to create a non-interruptable interrupt service routine
12357  you would also require the 
12358 \emph on 
12359 critical
12360 \emph default 
12361  keyword.
12362  To distinguish between this and an nmi_isr you must provide an interrupt
12363  number.
12364 \layout Section
12365
12366 Enabling and Disabling Interrupts
12367 \layout Subsection
12368
12369 Critical Functions and Critical Statements
12370 \layout Standard
12371
12372 A special keyword may be associated with a block or a function declaring
12373  it as 
12374 \emph on 
12375 critical
12376 \emph default 
12377 .
12378  SDCC will generate code to disable all interrupts
12379 \begin_inset LatexCommand \index{interrupt}
12380
12381 \end_inset 
12382
12383  upon entry to a critical function and restore the interrupt enable to the
12384  previous state before returning.
12385  Nesting critical functions will need one additional byte on the stack
12386 \begin_inset LatexCommand \index{stack}
12387
12388 \end_inset 
12389
12390  for each call.
12391 \layout Verse
12392
12393
12394 \family typewriter 
12395 int foo () __critical
12396 \begin_inset LatexCommand \index{critical}
12397
12398 \end_inset 
12399
12400
12401 \begin_inset LatexCommand \index{\_\_critical}
12402
12403 \end_inset 
12404
12405  
12406 \newline 
12407
12408 \newline 
12409 \SpecialChar ~
12410 \SpecialChar ~
12411 \SpecialChar ~
12412 \SpecialChar ~
12413 ...
12414  
12415 \newline 
12416 \SpecialChar ~
12417 \SpecialChar ~
12418 \SpecialChar ~
12419 \SpecialChar ~
12420 ...
12421  
12422 \newline 
12423 }
12424 \layout Standard
12425
12426 The critical attribute maybe used with other attributes like 
12427 \emph on 
12428 reentrant.
12429 \emph default 
12430
12431 \newline 
12432 The keyword 
12433 \emph on 
12434 critical
12435 \emph default 
12436  may also be used to disable interrupts more locally:
12437 \layout Verse
12438
12439
12440 \family typewriter 
12441 __critical{ i++; }
12442 \layout Standard
12443
12444 More than one statement could have been included in the block.
12445 \layout Subsection
12446
12447 Enabling and Disabling Interrupts directly
12448 \layout Standard
12449
12450 Interrupts
12451 \begin_inset LatexCommand \index{interrupt}
12452
12453 \end_inset 
12454
12455  can also be disabled and enabled directly (8051):
12456 \layout Verse
12457
12458
12459 \family typewriter 
12460 EA = 0;\SpecialChar ~
12461 \SpecialChar ~
12462 \SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 or:\SpecialChar ~
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 \SpecialChar ~
12480 \SpecialChar ~
12481 \SpecialChar ~
12482 \SpecialChar ~
12483 EA_SAVE = EA;
12484 \layout Verse
12485
12486
12487 \family typewriter 
12488 ...\SpecialChar ~
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 \SpecialChar ~
12492 \SpecialChar ~
12493 \SpecialChar ~
12494 \SpecialChar ~
12495 \SpecialChar ~
12496 \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 EA = 0;
12519 \layout Verse
12520
12521
12522 \family typewriter 
12523 EA = 1;\SpecialChar ~
12524 \SpecialChar ~
12525 \SpecialChar ~
12526 \SpecialChar ~
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 ...
12550 \layout Verse
12551
12552
12553 \family typewriter 
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 \SpecialChar ~
12560 \SpecialChar ~
12561 \SpecialChar ~
12562 \SpecialChar ~
12563 \SpecialChar ~
12564 \SpecialChar ~
12565 \SpecialChar ~
12566 \SpecialChar ~
12567 \SpecialChar ~
12568 \SpecialChar ~
12569 \SpecialChar ~
12570 \SpecialChar ~
12571 \SpecialChar ~
12572 \SpecialChar ~
12573 \SpecialChar ~
12574 \SpecialChar ~
12575 \SpecialChar ~
12576 \SpecialChar ~
12577 \SpecialChar ~
12578 \SpecialChar ~
12579 \SpecialChar ~
12580 \SpecialChar ~
12581 \SpecialChar ~
12582 \SpecialChar ~
12583 \SpecialChar ~
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 \SpecialChar ~
12587 EA = EA_SAVE;
12588 \layout Standard
12589
12590 On other architectures which have seperate opcodes for enabling and disabling
12591  interrupts you might want to make use of defines with inline assembly
12592 \begin_inset LatexCommand \index{Assembler routines}
12593
12594 \end_inset 
12595
12596  (HC08
12597 \begin_inset LatexCommand \index{HC08!interrupt}
12598
12599 \end_inset 
12600
12601 ):
12602 \layout Verse
12603
12604
12605 \family typewriter 
12606 #define CLI _asm
12607 \begin_inset LatexCommand \index{\_asm}
12608
12609 \end_inset 
12610
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 cli\SpecialChar ~
12614 \SpecialChar ~
12615 _endasm
12616 \begin_inset LatexCommand \index{\_endasm}
12617
12618 \end_inset 
12619
12620
12621 \layout Verse
12622
12623
12624 \family typewriter 
12625 #define SEI _asm\SpecialChar ~
12626 \SpecialChar ~
12627 sei\SpecialChar ~
12628 \SpecialChar ~
12629 _endasm; 
12630 \layout Verse
12631
12632
12633 \family typewriter 
12634 ...
12635 \layout Standard
12636
12637 Note: it is sometimes sufficient to disable only a specific interrupt source
12638  like f.e.
12639  a timer or serial interrupt by manipulating an 
12640 \emph on 
12641 interrupt mask
12642 \begin_inset LatexCommand \index{interrupt mask}
12643
12644 \end_inset 
12645
12646
12647 \emph default 
12648  register.
12649  
12650 \layout Standard
12651
12652 Usually the time during which interrupts are disabled should be kept as
12653  short as possible.
12654  This minimizes both 
12655 \emph on 
12656 interrupt latency
12657 \emph default 
12658
12659 \begin_inset LatexCommand \index{interrupt latency}
12660
12661 \end_inset 
12662
12663  (the time between the occurrence of the interrupt and the execution of
12664  the first code in the interrupt routine) and 
12665 \emph on 
12666 interrupt jitter
12667 \emph default 
12668
12669 \begin_inset LatexCommand \index{interrupt jitter}
12670
12671 \end_inset 
12672
12673  (the difference between the shortest and the longest interrupt latency).
12674  These really are something different, f.e.
12675  a serial interrupt has to be served before its buffer overruns so it cares
12676  for the maximum interrupt latency, whereas it does not care about jitter.
12677  On a loudspeaker driven via a digital to analog converter which is fed
12678  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12679  a much smaller jitter will be very audible.
12680 \layout Standard
12681
12682 You can reenable interrupts within an interrupt routine and on some architecture
12683 s you can make use of two (or more) levels of 
12684 \emph on 
12685 interrupt priorities
12686 \emph default 
12687
12688 \begin_inset LatexCommand \index{interrupt priority}
12689
12690 \end_inset 
12691
12692 .
12693  On some architectures which don't support interrupt priorities these can
12694  be implemented by manipulating the interrupt mask and reenabling interrupts
12695  within the interrupt routine.
12696  Check there is sufficient space on the stack
12697 \begin_inset LatexCommand \index{stack}
12698
12699 \end_inset 
12700
12701  and don't add complexity unless you have to.
12702  
12703 \layout Subsection
12704
12705 Semaphore
12706 \begin_inset LatexCommand \index{semaphore}
12707
12708 \end_inset 
12709
12710  locking (mcs51/ds390)
12711 \layout Standard
12712
12713 Some architectures (mcs51/ds390) have an atomic
12714 \begin_inset LatexCommand \index{atomic}
12715
12716 \end_inset 
12717
12718  bit test and
12719 \emph on 
12720  
12721 \emph default 
12722 clear
12723 \emph on 
12724  
12725 \emph default 
12726 instruction.
12727  These type of instructions are typically used in preemptive multitasking
12728  systems, where a routine f.e.
12729  claims the use of a data structure ('acquires a lock
12730 \begin_inset LatexCommand \index{lock}
12731
12732 \end_inset 
12733
12734  on it'), makes some modifications and then releases the lock when the data
12735  structure is consistent again.
12736  The instruction may also be used if interrupt and non-interrupt code have
12737  to compete for a resource.
12738  With the atomic bit test and clear instruction interrupts
12739 \begin_inset LatexCommand \index{interrupt}
12740
12741 \end_inset 
12742
12743  don't have to be disabled for the locking operation.
12744  
12745 \layout Standard
12746
12747 SDCC generates this instruction if the source follows this pattern:
12748 \layout Verse
12749
12750
12751 \family typewriter 
12752 volatile
12753 \begin_inset LatexCommand \index{volatile}
12754
12755 \end_inset 
12756
12757  bit resource_is_free; 
12758 \newline 
12759
12760 \newline 
12761 if (resource_is_free) 
12762 \newline 
12763 \SpecialChar ~
12764 \SpecialChar ~
12765
12766 \newline 
12767 \SpecialChar ~
12768 \SpecialChar ~
12769 \SpecialChar ~
12770 \SpecialChar ~
12771 resource_is_free=0; 
12772 \newline 
12773 \SpecialChar ~
12774 \SpecialChar ~
12775 \SpecialChar ~
12776 \SpecialChar ~
12777 ...
12778  
12779 \newline 
12780 \SpecialChar ~
12781 \SpecialChar ~
12782 \SpecialChar ~
12783 \SpecialChar ~
12784 resource_is_free=1;
12785 \newline 
12786 \SpecialChar ~
12787 \SpecialChar ~
12788
12789 \layout Standard
12790
12791 Note, mcs51 and ds390 support only an atomic
12792 \begin_inset LatexCommand \index{atomic}
12793
12794 \end_inset 
12795
12796  bit test and 
12797 \emph on 
12798 clear
12799 \emph default 
12800  instruction (as opposed to atomic bit test and 
12801 \emph on 
12802 set).
12803 \layout Section
12804
12805 Functions using private register banks
12806 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12807
12808 \end_inset 
12809
12810  (mcs51/ds390)
12811 \layout Standard
12812
12813 Some architectures have support for quickly changing register sets.
12814  SDCC supports this feature with the 
12815 \emph on 
12816 using
12817 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12818
12819 \end_inset 
12820
12821
12822 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12823
12824 \end_inset 
12825
12826
12827 \emph default 
12828  attribute (which tells the compiler to use a register bank
12829 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12830
12831 \end_inset 
12832
12833  other than the default bank zero).
12834  It should only be applied to 
12835 \emph on 
12836 interrupt
12837 \begin_inset LatexCommand \index{interrupt}
12838
12839 \end_inset 
12840
12841
12842 \emph default 
12843  functions (see footnote below).
12844  This will in most circumstances make the generated ISR code more efficient
12845  since it will not have to save registers on the stack.
12846 \layout Standard
12847
12848 The 
12849 \emph on 
12850 using
12851 \emph default 
12852  attribute will have no effect on the generated code for a 
12853 \emph on 
12854 non-interrupt
12855 \emph default 
12856  function (but may occasionally be useful anyway
12857 \begin_inset Foot
12858 collapsed false
12859
12860 \layout Standard
12861
12862 possible exception: if a function is called ONLY from 'interrupt' functions
12863  using a particular bank, it can be declared with the same 'using' attribute
12864  as the calling 'interrupt' functions.
12865  For instance, if you have several ISRs using bank one, and all of them
12866  call memcpy(), it might make sense to create a specialized version of memcpy()
12867  'using 1', since this would prevent the ISR from having to save bank zero
12868  to the stack on entry and switch to bank zero before calling the function
12869 \end_inset 
12870
12871 ).
12872 \newline 
12873
12874 \emph on 
12875 (pending: Note, nowadays the 
12876 \emph default 
12877 using
12878 \emph on 
12879  attribute has an effect on
12880 \emph default 
12881  
12882 \emph on 
12883 the generated code for a 
12884 \emph default 
12885 non-interrupt
12886 \emph on 
12887  function
12888 \emph default 
12889 .
12890 \emph on 
12891 )
12892 \layout Standard
12893
12894 An 
12895 \emph on 
12896 interrupt
12897 \emph default 
12898  function using a non-zero bank will assume that it can trash that register
12899  bank, and will not save it.
12900  Since high-priority interrupts
12901 \begin_inset LatexCommand \index{interrupts}
12902
12903 \end_inset 
12904
12905
12906 \begin_inset LatexCommand \index{interrupt priority}
12907
12908 \end_inset 
12909
12910  can interrupt low-priority ones on the 8051 and friends, this means that
12911  if a high-priority ISR 
12912 \emph on 
12913 using
12914 \emph default 
12915  a particular bank occurs while processing a low-priority ISR 
12916 \emph on 
12917 using
12918 \emph default 
12919  the same bank, terrible and bad things can happen.
12920  To prevent this, no single register bank should be 
12921 \emph on 
12922 used
12923 \emph default 
12924  by both a high priority and a low priority ISR.
12925  This is probably most easily done by having all high priority ISRs use
12926  one bank and all low priority ISRs use another.
12927  If you have an ISR which can change priority at runtime, you're on your
12928  own: I suggest using the default bank zero and taking the small performance
12929  hit.
12930 \layout Standard
12931 \added_space_bottom bigskip 
12932 It is most efficient if your ISR calls no other functions.
12933  If your ISR must call other functions, it is most efficient if those functions
12934  use the same bank as the ISR (see note 1 below); the next best is if the
12935  called functions use bank zero.
12936  It is very inefficient to call a function using a different, non-zero bank
12937  from an ISR.
12938  
12939 \layout Section
12940
12941 Startup Code
12942 \begin_inset LatexCommand \label{sub:Startup-Code}
12943
12944 \end_inset 
12945
12946
12947 \begin_inset LatexCommand \index{Startup code}
12948
12949 \end_inset 
12950
12951
12952 \layout Subsection
12953
12954 MCS51/DS390 Startup Code
12955 \layout Standard
12956
12957 The compiler inserts a call to the C routine 
12958 \emph on 
12959 _sdcc_external_startup()
12960 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12961
12962 \end_inset 
12963
12964
12965 \series bold 
12966 \emph default 
12967  
12968 \series default 
12969 at the start of the CODE area.
12970  This routine is in the runtime library
12971 \begin_inset LatexCommand \index{Runtime library}
12972
12973 \end_inset 
12974
12975 .
12976  By default this routine returns 0, if this routine returns a non-zero value,
12977  the static & global variable initialization will be skipped and the function
12978  main will be invoked.
12979  Otherwise static & global variables will be initialized before the function
12980  main is invoked.
12981  You could add a 
12982 \emph on 
12983 _sdcc_external_startup()
12984 \emph default 
12985  routine to your program to override the default if you need to setup hardware
12986  or perform some other critical operation prior to static & global variable
12987  initialization
12988 \begin_inset LatexCommand \index{Variable initialization}
12989
12990 \end_inset 
12991
12992 .
12993  On some mcs51 variants xdata
12994 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12995
12996 \end_inset 
12997
12998  memory has to be explicitly enabled before it can be accessed or if the
12999  watchdog
13000 \begin_inset LatexCommand \index{watchdog}
13001
13002 \end_inset 
13003
13004  needs to be disabled, this is the place to do it.
13005  The startup code clears all internal data memory, 256 bytes by default,
13006  but from 0 to n-1 if 
13007 \emph on 
13008 -
13009 \begin_inset ERT
13010 status Collapsed
13011
13012 \layout Standard
13013
13014 \backslash 
13015 /
13016 \end_inset 
13017
13018 -iram-size
13019 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13020
13021 \end_inset 
13022
13023 n
13024 \emph default 
13025  is used.
13026  (recommended for Chipcon CC1010).
13027 \layout Standard
13028 \added_space_bottom bigskip 
13029 See also the compiler options 
13030 \emph on 
13031 -
13032 \begin_inset ERT
13033 status Collapsed
13034
13035 \layout Standard
13036
13037 \backslash 
13038 /
13039 \end_inset 
13040
13041 -no-xinit
13042 \emph default 
13043 -
13044 \emph on 
13045 opt
13046 \emph default 
13047
13048 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13049
13050 \end_inset 
13051
13052
13053 \emph on 
13054 -
13055 \begin_inset ERT
13056 status Collapsed
13057
13058 \layout Standard
13059
13060 \backslash 
13061 /
13062 \end_inset 
13063
13064 -main-return
13065 \emph default 
13066
13067 \begin_inset LatexCommand \index{-\/-main-return}
13068
13069 \end_inset 
13070
13071  and section 
13072 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13073
13074 \end_inset 
13075
13076  about MCS51-variants.
13077 \layout Subsection
13078
13079 HC08 Startup Code
13080 \layout Standard
13081 \added_space_bottom bigskip 
13082 The HC08
13083 \begin_inset LatexCommand \index{HC08}
13084
13085 \end_inset 
13086
13087  startup code follows the same scheme as the MCS51 startup code.
13088 \layout Subsection
13089
13090 Z80 Startup Code
13091 \layout Standard
13092 \added_space_bottom bigskip 
13093 On the Z80
13094 \begin_inset LatexCommand \index{Z80}
13095
13096 \end_inset 
13097
13098  the startup code is inserted by linking with crt0.o which is generated from
13099  sdcc/device/lib/z80/crt0.s.
13100  If you need a different startup code you can use the compiler option 
13101 \emph on 
13102 -
13103 \series bold 
13104 \emph default 
13105
13106 \begin_inset ERT
13107 status Collapsed
13108
13109 \layout Standard
13110
13111 \backslash 
13112 /
13113 \end_inset 
13114
13115
13116 \series default 
13117 \emph on 
13118 -no-std-crt0
13119 \emph default 
13120
13121 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13122
13123 \end_inset 
13124
13125  and provide your own crt0.o.
13126  
13127 \layout Section
13128
13129 Inline Assembler Code
13130 \begin_inset LatexCommand \index{Assembler routines}
13131
13132 \end_inset 
13133
13134
13135 \layout Subsection
13136
13137 A Step by Step Introduction
13138 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13139
13140 \end_inset 
13141
13142
13143 \layout Standard
13144
13145 Starting from a small snippet of c-code this example shows for the MCS51
13146  how to use inline assembly, access variables, a function parameter and
13147  an array in xdata memory.
13148  The example uses an MCS51 here but is easily adapted for other architectures.
13149  This is a buffer routine which should be optimized:
13150 \layout Verse
13151
13152
13153 \family typewriter 
13154 \size footnotesize 
13155 unsigned char __far
13156 \begin_inset LatexCommand \index{far (storage class)}
13157
13158 \end_inset 
13159
13160
13161 \begin_inset LatexCommand \index{\_\_far (storage class)}
13162
13163 \end_inset 
13164
13165  __at
13166 \begin_inset LatexCommand \index{at}
13167
13168 \end_inset 
13169
13170
13171 \begin_inset LatexCommand \index{\_\_at}
13172
13173 \end_inset 
13174
13175 (0x7f00) buf[0x100];
13176 \begin_inset LatexCommand \index{Aligned array}
13177
13178 \end_inset 
13179
13180
13181 \newline 
13182 unsigned char head, tail;\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 /* if interrupts
13200 \begin_inset LatexCommand \index{interrupt}
13201
13202 \end_inset 
13203
13204  are involved see
13205 \newline 
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 \SpecialChar ~
13225 \SpecialChar ~
13226 \SpecialChar ~
13227 \SpecialChar ~
13228 \SpecialChar ~
13229 \SpecialChar ~
13230 \SpecialChar ~
13231 \SpecialChar ~
13232 \SpecialChar ~
13233 \SpecialChar ~
13234 \SpecialChar ~
13235 \SpecialChar ~
13236 \SpecialChar ~
13237 \SpecialChar ~
13238 \SpecialChar ~
13239 \SpecialChar ~
13240 \SpecialChar ~
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 \SpecialChar ~
13246 \SpecialChar ~
13247 \SpecialChar ~
13248 \SpecialChar ~
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 section 
13252 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13253
13254 \end_inset 
13255
13256  about
13257 \series bold 
13258  volatile
13259 \series default 
13260  */
13261 \newline 
13262
13263 \newline 
13264 void to_buffer( unsigned char c ) 
13265 \newline 
13266 {
13267 \newline 
13268 \SpecialChar ~
13269 \SpecialChar ~
13270 \SpecialChar ~
13271 \SpecialChar ~
13272 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13273 /* cast 
13274 \series bold 
13275 needed
13276 \series default 
13277  to avoid promotion
13278 \begin_inset LatexCommand \index{promotion to signed int}
13279
13280 \end_inset 
13281
13282
13283 \begin_inset LatexCommand \index{type promotion}
13284
13285 \end_inset 
13286
13287  to integer */
13288 \begin_inset Marginal
13289 collapsed true
13290
13291 \layout Standard
13292
13293
13294 \series bold 
13295 \SpecialChar ~
13296 !
13297 \end_inset 
13298
13299
13300 \newline 
13301 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 \SpecialChar ~
13306 \SpecialChar ~
13307 \SpecialChar ~
13308 \SpecialChar ~
13309 buf[ head++ ] = c;\SpecialChar ~
13310 \SpecialChar ~
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 \SpecialChar ~
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 \SpecialChar ~
13324 \SpecialChar ~
13325 /* access to a 256 byte aligned array */
13326 \newline 
13327
13328 \layout Standard
13329
13330 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13331  then a corresponding buffer.asm file is generated.
13332  We define a new function 
13333 \family typewriter 
13334 to_buffer_asm()
13335 \family default 
13336  in file buffer.c in which we cut and paste the generated code, removing
13337  unwanted comments and some ':'.
13338  Then add 
13339 \begin_inset Quotes sld
13340 \end_inset 
13341
13342 _asm
13343 \begin_inset Quotes srd
13344 \end_inset 
13345
13346  and 
13347 \begin_inset Quotes sld
13348 \end_inset 
13349
13350 _endasm;
13351 \begin_inset Quotes srd
13352 \end_inset 
13353
13354  to the beginning and the end of the function body:
13355 \layout Verse
13356
13357
13358 \family typewriter 
13359 \size footnotesize 
13360 /* With a cut and paste from the .asm file, we have something to start with.
13361 \newline 
13362 \SpecialChar ~
13363 \SpecialChar ~
13364 \SpecialChar ~
13365 The function is not yet OK! (registers aren't saved) */ 
13366 \newline 
13367 void to_buffer_asm( unsigned char c ) 
13368 \newline 
13369
13370 \newline 
13371 \SpecialChar ~
13372 \SpecialChar ~
13373 \SpecialChar ~
13374 \SpecialChar ~
13375 _asm
13376 \begin_inset LatexCommand \index{\_asm}
13377
13378 \end_inset 
13379
13380
13381 \begin_inset LatexCommand \index{\_\_asm}
13382
13383 \end_inset 
13384
13385
13386 \newline 
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 mov\SpecialChar ~
13392 \SpecialChar ~
13393 r2,dpl 
13394 \newline 
13395 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13396 /* cast 
13397 \series bold 
13398 needed
13399 \series default 
13400  to avoid promotion
13401 \begin_inset LatexCommand \index{promotion to signed int}
13402
13403 \end_inset 
13404
13405
13406 \begin_inset LatexCommand \index{type promotion}
13407
13408 \end_inset 
13409
13410  to integer */
13411 \newline 
13412 \SpecialChar ~
13413 \SpecialChar ~
13414 \SpecialChar ~
13415 \SpecialChar ~
13416 mov\SpecialChar ~
13417 \SpecialChar ~
13418 a,_tail 
13419 \newline 
13420 \SpecialChar ~
13421 \SpecialChar ~
13422 \SpecialChar ~
13423 \SpecialChar ~
13424 dec\SpecialChar ~
13425 \SpecialChar ~
13426
13427 \newline 
13428 \SpecialChar ~
13429 \SpecialChar ~
13430 \SpecialChar ~
13431 \SpecialChar ~
13432 mov\SpecialChar ~
13433 \SpecialChar ~
13434 r3,a 
13435 \newline 
13436 \SpecialChar ~
13437 \SpecialChar ~
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 mov\SpecialChar ~
13441 \SpecialChar ~
13442 a,_head 
13443 \newline 
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 cjne a,ar3,00106$ 
13449 \newline 
13450 \SpecialChar ~
13451 \SpecialChar ~
13452 \SpecialChar ~
13453 \SpecialChar ~
13454 ret
13455 \newline 
13456 00106$: 
13457 \newline 
13458 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13459 \begin_inset LatexCommand \index{Aligned array}
13460
13461 \end_inset 
13462
13463
13464 \newline 
13465 \SpecialChar ~
13466 \SpecialChar ~
13467 \SpecialChar ~
13468 \SpecialChar ~
13469 mov\SpecialChar ~
13470 \SpecialChar ~
13471 r3,_head 
13472 \newline 
13473 \SpecialChar ~
13474 \SpecialChar ~
13475 \SpecialChar ~
13476 \SpecialChar ~
13477 inc\SpecialChar ~
13478 \SpecialChar ~
13479 _head 
13480 \newline 
13481 \SpecialChar ~
13482 \SpecialChar ~
13483 \SpecialChar ~
13484 \SpecialChar ~
13485 mov\SpecialChar ~
13486 \SpecialChar ~
13487 dpl,r3 
13488 \newline 
13489 \SpecialChar ~
13490 \SpecialChar ~
13491 \SpecialChar ~
13492 \SpecialChar ~
13493 mov\SpecialChar ~
13494 \SpecialChar ~
13495 dph,#(_buf >> 8) 
13496 \newline 
13497 \SpecialChar ~
13498 \SpecialChar ~
13499 \SpecialChar ~
13500 \SpecialChar ~
13501 mov\SpecialChar ~
13502 \SpecialChar ~
13503 a,r2 
13504 \newline 
13505 \SpecialChar ~
13506 \SpecialChar ~
13507 \SpecialChar ~
13508 \SpecialChar ~
13509 movx @dptr,a 
13510 \newline 
13511 00103$: 
13512 \newline 
13513 \SpecialChar ~
13514 \SpecialChar ~
13515 \SpecialChar ~
13516 \SpecialChar ~
13517 ret
13518 \newline 
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 \SpecialChar ~
13522 \SpecialChar ~
13523 _endasm
13524 \begin_inset LatexCommand \index{\_endasm}
13525
13526 \end_inset 
13527
13528
13529 \begin_inset LatexCommand \index{\_\_endasm}
13530
13531 \end_inset 
13532
13533 ;
13534 \newline 
13535
13536 \layout Standard
13537
13538 The new file buffer.c should compile with only one warning about the unreferenced
13539  function argument 'c'.
13540  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13541  (1) and finally have:
13542 \layout Verse
13543
13544
13545 \family typewriter 
13546 \size footnotesize 
13547 unsigned char __far __at(0x7f00) buf[0x100];
13548 \newline 
13549 unsigned char head, tail;
13550 \newline 
13551 #define USE_ASSEMBLY (1)
13552 \newline 
13553
13554 \newline 
13555 #if !USE_ASSEMBLY
13556 \newline 
13557
13558 \newline 
13559 void to_buffer( unsigned char c )
13560 \newline 
13561 {
13562 \newline 
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 if( head != (unsigned char)(tail-1) )
13568 \newline 
13569 \SpecialChar ~
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 \SpecialChar ~
13575 \SpecialChar ~
13576 \SpecialChar ~
13577 buf[ head++ ] = c;
13578 \newline 
13579 }
13580 \newline 
13581
13582 \newline 
13583 #else
13584 \newline 
13585
13586 \newline 
13587 void to_buffer( unsigned char c )
13588 \newline 
13589 {
13590 \newline 
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 \SpecialChar ~
13595 c; // to avoid warning: unreferenced function argument
13596 \newline 
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 _asm
13602 \begin_inset LatexCommand \index{\_asm}
13603
13604 \end_inset 
13605
13606
13607 \begin_inset LatexCommand \index{\_\_asm}
13608
13609 \end_inset 
13610
13611
13612 \newline 
13613 \SpecialChar ~
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 \SpecialChar ~
13619 \SpecialChar ~
13620 \SpecialChar ~
13621 ; save used registers here.
13622  
13623 \newline 
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 \SpecialChar ~
13629 \SpecialChar ~
13630 \SpecialChar ~
13631 \SpecialChar ~
13632 ; If we were still using r2,r3 we would have to push them here.
13633  
13634 \newline 
13635 ; if( head != (unsigned char)(tail-1) )
13636 \newline 
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 \SpecialChar ~
13641 \SpecialChar ~
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 mov\SpecialChar ~
13646  a,_tail
13647 \newline 
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 \SpecialChar ~
13652 \SpecialChar ~
13653 \SpecialChar ~
13654 \SpecialChar ~
13655 \SpecialChar ~
13656 dec\SpecialChar ~
13657  a
13658 \newline 
13659 \SpecialChar ~
13660 \SpecialChar ~
13661 \SpecialChar ~
13662 \SpecialChar ~
13663 \SpecialChar ~
13664 \SpecialChar ~
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 xrl\SpecialChar ~
13668  a,_head
13669 \newline 
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 \SpecialChar ~
13674 \SpecialChar ~
13675 \SpecialChar ~
13676 \SpecialChar ~
13677 \SpecialChar ~
13678 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13679 \newline 
13680 \SpecialChar ~
13681 \SpecialChar ~
13682 \SpecialChar ~
13683 \SpecialChar ~
13684 \SpecialChar ~
13685 \SpecialChar ~
13686 \SpecialChar ~
13687 \SpecialChar ~
13688 jz\SpecialChar ~
13689 \SpecialChar ~
13690  t_b_end$
13691 \newline 
13692 \SpecialChar ~
13693 \SpecialChar ~
13694 \SpecialChar ~
13695 \SpecialChar ~
13696 \SpecialChar ~
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 ;
13701 \newline 
13702 ; buf[ head++ ] = c;
13703 \newline 
13704 \SpecialChar ~
13705 \SpecialChar ~
13706 \SpecialChar ~
13707 \SpecialChar ~
13708 \SpecialChar ~
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 mov\SpecialChar ~
13713  a,dpl \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 \SpecialChar ~
13718 \SpecialChar ~
13719 \SpecialChar ~
13720 ; dpl holds lower byte of function argument
13721 \newline 
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 \SpecialChar ~
13729 \SpecialChar ~
13730 mov\SpecialChar ~
13731  dpl,_head \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 ; buf is 0x100 byte aligned so head can be used directly
13735 \newline 
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 \SpecialChar ~
13739 \SpecialChar ~
13740 \SpecialChar ~
13741 \SpecialChar ~
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 mov\SpecialChar ~
13745  dph,#(_buf>>8)
13746 \newline 
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 \SpecialChar ~
13751 \SpecialChar ~
13752 \SpecialChar ~
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 movx @dptr,a
13756 \newline 
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 \SpecialChar ~
13763 \SpecialChar ~
13764 \SpecialChar ~
13765 inc \SpecialChar ~
13766 _head
13767 \newline 
13768 \SpecialChar ~
13769 \SpecialChar ~
13770 \SpecialChar ~
13771 \SpecialChar ~
13772 \SpecialChar ~
13773 \SpecialChar ~
13774 \SpecialChar ~
13775 \SpecialChar ~
13776 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13777 \newline 
13778 t_b_end$:
13779 \newline 
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 \SpecialChar ~
13786 \SpecialChar ~
13787 \SpecialChar ~
13788 ; restore used registers here 
13789 \newline 
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 _endasm
13795 \begin_inset LatexCommand \index{\_endasm}
13796
13797 \end_inset 
13798
13799
13800 \begin_inset LatexCommand \index{\_\_endasm}
13801
13802 \end_inset 
13803
13804 ;
13805 \newline 
13806 }
13807 \newline 
13808 #endif
13809 \layout Standard
13810
13811 The inline assembler code can contain any valid code understood by the assembler
13812 , this includes any assembler directives and comment lines.
13813  The assembler does not like some characters like ':' or ''' in comments.
13814  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13815 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13816
13817 \end_inset 
13818
13819
13820 \begin_inset LatexCommand \index{Assembler documentation}
13821
13822 \end_inset 
13823
13824  or online at 
13825 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13826
13827 \end_inset 
13828
13829 \SpecialChar ~
13830 .
13831 \layout Standard
13832
13833 The compiler does not do any validation of the code within the 
13834 \family typewriter 
13835 _asm
13836 \begin_inset LatexCommand \index{\_asm}
13837
13838 \end_inset 
13839
13840
13841 \begin_inset LatexCommand \index{\_\_asm}
13842
13843 \end_inset 
13844
13845  ...
13846  _endasm
13847 \size footnotesize 
13848
13849 \begin_inset LatexCommand \index{\_endasm}
13850
13851 \end_inset 
13852
13853
13854 \begin_inset LatexCommand \index{\_\_endasm}
13855
13856 \end_inset 
13857
13858
13859 \size default 
13860 ;
13861 \family default 
13862  keyword pair.
13863  Specifically it will not know which registers are used and thus register
13864  pushing/popping
13865 \begin_inset LatexCommand \index{push/pop}
13866
13867 \end_inset 
13868
13869  has to be done manually.
13870  
13871 \layout Standard
13872
13873 It is recommended that each assembly instruction (including labels) be placed
13874  in a separate line (as the example shows).
13875  When the -
13876 \begin_inset ERT
13877 status Collapsed
13878
13879 \layout Standard
13880
13881 \backslash 
13882 /
13883 \end_inset 
13884
13885 -
13886 \emph on 
13887 peep-asm
13888 \begin_inset LatexCommand \index{-\/-peep-asm}
13889
13890 \end_inset 
13891
13892
13893 \emph default 
13894  command line option is used, the inline assembler code will be passed through
13895  the peephole optimizer
13896 \begin_inset LatexCommand \index{Peephole optimizer}
13897
13898 \end_inset 
13899
13900 .
13901  There are only a few (if any) cases where this option makes sense, it might
13902  cause some unexpected changes in the inline assembler code.
13903  Please go through the peephole optimizer rules defined in file 
13904 \emph on 
13905 SDCCpeeph.def
13906 \emph default 
13907  before using this option.
13908 \layout Subsection
13909
13910 Naked Functions
13911 \begin_inset LatexCommand \label{sub:Naked-Functions}
13912
13913 \end_inset 
13914
13915
13916 \begin_inset LatexCommand \index{Naked functions}
13917
13918 \end_inset 
13919
13920
13921 \layout Standard
13922
13923 A special keyword may be associated with a function declaring it as 
13924 \emph on 
13925 _naked
13926 \begin_inset LatexCommand \index{\_naked}
13927
13928 \end_inset 
13929
13930
13931 \begin_inset LatexCommand \index{\_\_naked}
13932
13933 \end_inset 
13934
13935 .
13936  
13937 \emph default 
13938 The 
13939 \emph on 
13940 _naked
13941 \emph default 
13942  function modifier attribute prevents the compiler from generating prologue
13943 \begin_inset LatexCommand \index{function prologue}
13944
13945 \end_inset 
13946
13947  and epilogue
13948 \begin_inset LatexCommand \index{function epilogue}
13949
13950 \end_inset 
13951
13952  code for that function.
13953  This means that the user is entirely responsible for such things as saving
13954  any registers that may need to be preserved, selecting the proper register
13955  bank, generating the 
13956 \emph on 
13957 return
13958 \emph default 
13959  instruction at the end, etc.
13960  Practically, this means that the contents of the function must be written
13961  in inline assembler.
13962  This is particularly useful for interrupt functions, which can have a large
13963  (and often unnecessary) prologue/epilogue.
13964  For example, compare the code generated by these two functions:
13965 \layout Verse
13966
13967
13968 \family typewriter 
13969 volatile
13970 \begin_inset LatexCommand \index{volatile}
13971
13972 \end_inset 
13973
13974  data unsigned char counter;
13975 \newline 
13976
13977 \newline 
13978 void simpleInterrupt(void) __interrupt
13979 \begin_inset LatexCommand \index{interrupt}
13980
13981 \end_inset 
13982
13983
13984 \begin_inset LatexCommand \index{\_\_interrupt}
13985
13986 \end_inset 
13987
13988  (1)
13989 \newline 
13990 {
13991 \newline 
13992 \SpecialChar ~
13993 \SpecialChar ~
13994 \SpecialChar ~
13995 \SpecialChar ~
13996 counter++;
13997 \newline 
13998 }
13999 \newline 
14000
14001 \newline 
14002 void nakedInterrupt(void) __interrupt (2) __naked
14003 \newline 
14004 {
14005 \newline 
14006 \SpecialChar ~
14007 \SpecialChar ~
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 _asm
14011 \begin_inset LatexCommand \index{\_asm}
14012
14013 \end_inset 
14014
14015
14016 \begin_inset LatexCommand \index{\_\_asm}
14017
14018 \end_inset 
14019
14020
14021 \newline 
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 \SpecialChar ~
14025 \SpecialChar ~
14026 \SpecialChar ~
14027 \SpecialChar ~
14028 inc\SpecialChar ~
14029 \SpecialChar ~
14030 \SpecialChar ~
14031 \SpecialChar ~
14032 \SpecialChar ~
14033 _counter ; does not change flags, no need to save psw
14034 \newline 
14035 \SpecialChar ~
14036 \SpecialChar ~
14037 \SpecialChar ~
14038 \SpecialChar ~
14039 \SpecialChar ~
14040 \SpecialChar ~
14041 reti\SpecialChar ~
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 \SpecialChar ~
14045 ; MUST explicitly include ret or reti in _naked function.
14046 \newline 
14047 \SpecialChar ~
14048 \SpecialChar ~
14049 \SpecialChar ~
14050 \SpecialChar ~
14051 _endasm
14052 \begin_inset LatexCommand \index{\_endasm}
14053
14054 \end_inset 
14055
14056
14057 \begin_inset LatexCommand \index{\_\_endasm}
14058
14059 \end_inset 
14060
14061 ;
14062 \newline 
14063 }
14064 \layout Standard
14065
14066 For an 8051 target, the generated simpleInterrupt looks like:
14067 \layout Verse
14068
14069
14070 \family typewriter 
14071 Note, this is an 
14072 \emph on 
14073 outdated
14074 \emph default 
14075  example, recent versions of SDCC generate
14076 \newline 
14077 the 
14078 \emph on 
14079 same
14080 \emph default 
14081  code for simpleInterrupt() and nakedInterrupt()!
14082 \newline 
14083
14084 \newline 
14085 _simpleInterrupt:
14086 \newline 
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 push\SpecialChar ~
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 \SpecialChar ~
14095 acc
14096 \newline 
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 push\SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 \SpecialChar ~
14105 b
14106 \newline 
14107 \SpecialChar ~
14108 \SpecialChar ~
14109 \SpecialChar ~
14110 \SpecialChar ~
14111 push\SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 \SpecialChar ~
14115 dpl
14116 \newline 
14117 \SpecialChar ~
14118 \SpecialChar ~
14119 \SpecialChar ~
14120 \SpecialChar ~
14121 push\SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 dph
14126 \newline 
14127 \SpecialChar ~
14128 \SpecialChar ~
14129 \SpecialChar ~
14130 \SpecialChar ~
14131 push\SpecialChar ~
14132 \SpecialChar ~
14133 \SpecialChar ~
14134 \SpecialChar ~
14135 psw
14136 \newline 
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 mov\SpecialChar ~
14142 \SpecialChar ~
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 psw,#0x00
14147 \newline 
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 inc\SpecialChar ~
14153 \SpecialChar ~
14154 \SpecialChar ~
14155 \SpecialChar ~
14156 \SpecialChar ~
14157 _counter
14158 \newline 
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 pop\SpecialChar ~
14164 \SpecialChar ~
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 psw
14169 \newline 
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 pop\SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 dph
14180 \newline 
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 pop\SpecialChar ~
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 dpl
14191 \newline 
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 pop\SpecialChar ~
14197 \SpecialChar ~
14198 \SpecialChar ~
14199 \SpecialChar ~
14200 \SpecialChar ~
14201 b
14202 \newline 
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 pop\SpecialChar ~
14208 \SpecialChar ~
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 acc
14213 \newline 
14214 \SpecialChar ~
14215 \SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 reti
14219 \layout Standard
14220
14221 whereas nakedInterrupt looks like:
14222 \layout Verse
14223
14224
14225 \family typewriter 
14226 _nakedInterrupt:
14227 \newline 
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 \SpecialChar ~
14231 \SpecialChar ~
14232 inc\SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 _counter ; does not change flags, no need to save psw
14237 \newline 
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 \SpecialChar ~
14242 reti\SpecialChar ~
14243 \SpecialChar ~
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 \SpecialChar ~
14248 \SpecialChar ~
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 \SpecialChar ~
14253 \SpecialChar ~
14254 ; MUST explicitly include ret or reti in _naked function
14255 \layout Standard
14256
14257 The related directive #pragma exclude
14258 \begin_inset LatexCommand \index{\#pragma exclude}
14259
14260 \end_inset 
14261
14262  allows a more fine grained control over pushing & popping
14263 \begin_inset LatexCommand \index{push/pop}
14264
14265 \end_inset 
14266
14267  the registers.
14268 \layout Standard
14269
14270 While there is nothing preventing you from writing C code inside a 
14271 \family typewriter 
14272 _naked
14273 \family default 
14274  function, there are many ways to shoot yourself in the foot doing this,
14275  and it is recommended that you stick to inline assembler.
14276 \layout Subsection
14277
14278 Use of Labels within Inline Assembler
14279 \layout Standard
14280
14281 SDCC allows the use of in-line assembler with a few restrictions regarding
14282  labels.
14283  In older versions of the compiler all labels defined within inline assembler
14284  code 
14285 \emph on 
14286 had to be
14287 \emph default 
14288  of the form 
14289 \emph on 
14290 nnnnn$
14291 \emph default 
14292  where nnnn is a number less than 100 (which implies a limit of utmost 100
14293  inline assembler labels 
14294 \emph on 
14295 per function
14296 \emph default 
14297 \noun on 
14298 )
14299 \noun default 
14300 .
14301  
14302 \layout Verse
14303
14304
14305 \family typewriter 
14306 _asm
14307 \begin_inset LatexCommand \index{\_asm}
14308
14309 \end_inset 
14310
14311
14312 \begin_inset LatexCommand \index{\_\_asm}
14313
14314 \end_inset 
14315
14316  
14317 \newline 
14318 \SpecialChar ~
14319 \SpecialChar ~
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 mov\SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 b,#10 
14328 \newline 
14329 00001$: 
14330 \newline 
14331 \SpecialChar ~
14332 \SpecialChar ~
14333 \SpecialChar ~
14334 \SpecialChar ~
14335 djnz\SpecialChar ~
14336 \SpecialChar ~
14337 \SpecialChar ~
14338 \SpecialChar ~
14339 b,00001$ 
14340 \newline 
14341 _endasm
14342 \begin_inset LatexCommand \index{\_endasm}
14343
14344 \end_inset 
14345
14346
14347 \begin_inset LatexCommand \index{\_\_endasm}
14348
14349 \end_inset 
14350
14351  ;
14352 \layout Standard
14353
14354 Inline assembler code cannot reference any C-Labels, however it can reference
14355  labels
14356 \begin_inset LatexCommand \index{Labels}
14357
14358 \end_inset 
14359
14360  defined by the inline assembler, e.g.:
14361 \layout Verse
14362
14363
14364 \family typewriter 
14365 foo() { 
14366 \newline 
14367 \SpecialChar ~
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 /* some c code */ 
14372 \newline 
14373 \SpecialChar ~
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 _asm 
14378 \newline 
14379 \SpecialChar ~
14380 \SpecialChar ~
14381 \SpecialChar ~
14382 \SpecialChar ~
14383 \SpecialChar ~
14384 \SpecialChar ~
14385 ; some assembler code 
14386 \newline 
14387 \SpecialChar ~
14388 \SpecialChar ~
14389 \SpecialChar ~
14390 \SpecialChar ~
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 ljmp $0003 
14394 \newline 
14395 \SpecialChar ~
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 _endasm; 
14400 \newline 
14401 \SpecialChar ~
14402 \SpecialChar ~
14403 \SpecialChar ~
14404 \SpecialChar ~
14405 /* some more c code */ 
14406 \newline 
14407 clabel:\SpecialChar ~
14408 \SpecialChar ~
14409 /* inline assembler cannot reference this label */ 
14410 \newline 
14411 \SpecialChar ~
14412 \SpecialChar ~
14413 \SpecialChar ~
14414 \SpecialChar ~
14415 _asm
14416 \newline 
14417 \SpecialChar ~
14418 \SpecialChar ~
14419 \SpecialChar ~
14420 \SpecialChar ~
14421 $0003: ;label (can be referenced by inline assembler only) 
14422 \newline 
14423 \SpecialChar ~
14424 \SpecialChar ~
14425 \SpecialChar ~
14426 \SpecialChar ~
14427 _endasm
14428 \begin_inset LatexCommand \index{\_endasm}
14429
14430 \end_inset 
14431
14432
14433 \begin_inset LatexCommand \index{\_\_endasm}
14434
14435 \end_inset 
14436
14437  ; 
14438 \newline 
14439 \SpecialChar ~
14440 \SpecialChar ~
14441 \SpecialChar ~
14442 \SpecialChar ~
14443 /* some more c code */
14444 \newline 
14445 }
14446 \layout Standard
14447
14448 In other words inline assembly code can access labels defined in inline
14449  assembly within the scope of the function.
14450  The same goes the other way, i.e.
14451  labels defines in inline assembly can not be accessed by C statements.
14452 \layout Section
14453
14454 Interfacing with Assembler Code
14455 \begin_inset LatexCommand \index{Assembler routines}
14456
14457 \end_inset 
14458
14459
14460 \layout Subsection
14461
14462 Global Registers used for Parameter Passing
14463 \begin_inset LatexCommand \index{Parameter passing}
14464
14465 \end_inset 
14466
14467
14468 \layout Standard
14469
14470 The compiler always uses the global registers 
14471 \emph on 
14472 DPL, DPH
14473 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14474
14475 \end_inset 
14476
14477
14478 \begin_inset LatexCommand \index{DPTR}
14479
14480 \end_inset 
14481
14482 , B
14483 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14484
14485 \end_inset 
14486
14487  
14488 \emph default 
14489 and
14490 \emph on 
14491  ACC
14492 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14493
14494 \end_inset 
14495
14496
14497 \emph default 
14498  to pass the first parameter to a routine.
14499  The second parameter onwards is either allocated on the stack (for reentrant
14500  routines or if -
14501 \begin_inset ERT
14502 status Collapsed
14503
14504 \layout Standard
14505
14506 \backslash 
14507 /
14508 \end_inset 
14509
14510 -stack-auto is used) or in data / xdata memory (depending on the memory
14511  model).
14512  
14513 \layout Subsection
14514
14515 Assembler Routine (non-reentrant)
14516 \layout Standard
14517
14518 In the following example
14519 \begin_inset LatexCommand \index{reentrant}
14520
14521 \end_inset 
14522
14523
14524 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14525
14526 \end_inset 
14527
14528  the function c_func calls an assembler routine asm_func, which takes two
14529  parameters
14530 \begin_inset LatexCommand \index{function parameter}
14531
14532 \end_inset 
14533
14534 .
14535 \layout Verse
14536
14537
14538 \family typewriter 
14539 extern int asm_func(unsigned char, unsigned char);
14540 \newline 
14541
14542 \newline 
14543 int c_func (unsigned char i, unsigned char j)
14544 \newline 
14545 {
14546 \newline 
14547 \SpecialChar ~
14548 \SpecialChar ~
14549 \SpecialChar ~
14550 \SpecialChar ~
14551 return asm_func(i,j);
14552 \newline 
14553 }
14554 \newline 
14555
14556 \newline 
14557 int main()
14558 \newline 
14559 {
14560 \newline 
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 \SpecialChar ~
14564 \SpecialChar ~
14565 return c_func(10,9);
14566 \newline 
14567 }
14568 \layout Standard
14569
14570 The corresponding assembler function is:
14571 \layout Verse
14572
14573
14574 \family typewriter 
14575 .globl _asm_func_PARM_2 
14576 \newline 
14577 \SpecialChar ~
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 \SpecialChar ~
14581 \SpecialChar ~
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 \SpecialChar ~
14585 .globl _asm_func 
14586 \newline 
14587 \SpecialChar ~
14588 \SpecialChar ~
14589 \SpecialChar ~
14590 \SpecialChar ~
14591 \SpecialChar ~
14592 \SpecialChar ~
14593 \SpecialChar ~
14594 \SpecialChar ~
14595 .area OSEG 
14596 \newline 
14597 _asm_func_PARM_2:
14598 \newline 
14599 \SpecialChar ~
14600 \SpecialChar ~
14601 \SpecialChar ~
14602 \SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 \SpecialChar ~
14607 .ds    1 
14608 \newline 
14609 \SpecialChar ~
14610 \SpecialChar ~
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 \SpecialChar ~
14616 \SpecialChar ~
14617 .area CSEG 
14618 \newline 
14619 _asm_func: 
14620 \newline 
14621 \SpecialChar ~
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 \SpecialChar ~
14625 \SpecialChar ~
14626 \SpecialChar ~
14627 \SpecialChar ~
14628 \SpecialChar ~
14629 mov\SpecialChar ~
14630 \SpecialChar ~
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 a,dpl 
14634 \newline 
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 add\SpecialChar ~
14644 \SpecialChar ~
14645 \SpecialChar ~
14646 \SpecialChar ~
14647 a,_asm_func_PARM_2 
14648 \newline 
14649 \SpecialChar ~
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 \SpecialChar ~
14653 \SpecialChar ~
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 mov\SpecialChar ~
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 dpl,a 
14662 \newline 
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667 \SpecialChar ~
14668 \SpecialChar ~
14669 \SpecialChar ~
14670 \SpecialChar ~
14671 mov\SpecialChar ~
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 dph
14676 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14677
14678 \end_inset 
14679
14680 ,#0x00 
14681 \newline 
14682 \SpecialChar ~
14683 \SpecialChar ~
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 ret
14691 \layout Standard
14692
14693 Note here that the return values
14694 \begin_inset LatexCommand \index{return value}
14695
14696 \end_inset 
14697
14698  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14699  two byte values.
14700  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14701 b' & 'acc' for four byte values.
14702 \layout Standard
14703
14704 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14705  the parameter number starting from 1, and counting from the left.
14706  The first parameter is passed in 
14707 \begin_inset Quotes eld
14708 \end_inset 
14709
14710 dpl
14711 \begin_inset Quotes erd
14712 \end_inset 
14713
14714  for a one byte parameter, 
14715 \begin_inset Quotes eld
14716 \end_inset 
14717
14718 dptr
14719 \begin_inset Quotes erd
14720 \end_inset 
14721
14722  for two bytes, 
14723 \begin_inset Quotes eld
14724 \end_inset 
14725
14726 b,dptr
14727 \begin_inset Quotes erd
14728 \end_inset 
14729
14730  for three bytes and 
14731 \begin_inset Quotes eld
14732 \end_inset 
14733
14734 acc,b,dptr
14735 \begin_inset Quotes erd
14736 \end_inset 
14737
14738  for a four bytes parameter.
14739  The variable name for the second parameter will be _<function_name>_PARM_2.
14740 \newline 
14741
14742 \newline 
14743 Assemble the assembler routine with the following command:
14744 \newline 
14745
14746 \newline 
14747
14748 \family sans 
14749 \series bold 
14750 asx8051 -losg asmfunc.asm
14751 \newline 
14752
14753 \newline 
14754
14755 \family default 
14756 \series default 
14757 Then compile and link the assembler routine to the C source file with the
14758  following command:
14759 \newline 
14760
14761 \newline 
14762
14763 \family sans 
14764 \series bold 
14765 sdcc cfunc.c asmfunc.rel
14766 \layout Subsection
14767
14768 Assembler Routine (reentrant)
14769 \layout Standard
14770
14771 In this case
14772 \begin_inset LatexCommand \index{reentrant}
14773
14774 \end_inset 
14775
14776
14777 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14778
14779 \end_inset 
14780
14781  the second parameter
14782 \begin_inset LatexCommand \index{function parameter}
14783
14784 \end_inset 
14785
14786  onwards will be passed on the stack, the parameters are pushed from right
14787  to left i.e.
14788  after the call the leftmost parameter will be on the top of the stack.
14789  Here is an example:
14790 \layout Verse
14791
14792
14793 \family typewriter 
14794 extern int asm_func(unsigned char, unsigned char);
14795 \newline 
14796
14797 \newline 
14798 int c_func (unsigned char i, unsigned char j) reentrant 
14799 \newline 
14800
14801 \newline 
14802 \SpecialChar ~
14803 \SpecialChar ~
14804 \SpecialChar ~
14805 \SpecialChar ~
14806 return asm_func(i,j); 
14807 \newline 
14808
14809 \newline 
14810
14811 \newline 
14812 int main() 
14813 \newline 
14814
14815 \newline 
14816 \SpecialChar ~
14817 \SpecialChar ~
14818 \SpecialChar ~
14819 \SpecialChar ~
14820 return c_func(10,9); 
14821 \newline 
14822 }
14823 \layout Standard
14824
14825 The corresponding assembler routine is:
14826 \layout Verse
14827
14828
14829 \family typewriter 
14830 .globl _asm_func 
14831 \newline 
14832 _asm_func: 
14833 \newline 
14834 \SpecialChar ~
14835 \SpecialChar ~
14836 \SpecialChar ~
14837 \SpecialChar ~
14838 push  _bp 
14839 \newline 
14840 \SpecialChar ~
14841 \SpecialChar ~
14842 \SpecialChar ~
14843 \SpecialChar ~
14844 mov _bp,sp 
14845 \newline 
14846 \SpecialChar ~
14847 \SpecialChar ~
14848 \SpecialChar ~
14849 \SpecialChar ~
14850 mov r2,dpl
14851 \newline 
14852 \SpecialChar ~
14853 \SpecialChar ~
14854 \SpecialChar ~
14855 \SpecialChar ~
14856 mov a,_bp 
14857 \newline 
14858 \SpecialChar ~
14859 \SpecialChar ~
14860 \SpecialChar ~
14861 \SpecialChar ~
14862 add a,#0xfd 
14863 \newline 
14864 \SpecialChar ~
14865 \SpecialChar ~
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 mov r0,a 
14869 \newline 
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 \SpecialChar ~
14873 \SpecialChar ~
14874 add  a,#0xfc ;?
14875 \newline 
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 \SpecialChar ~
14880 mov  r1,a 
14881 \newline 
14882 \SpecialChar ~
14883 \SpecialChar ~
14884 \SpecialChar ~
14885 \SpecialChar ~
14886 mov  a,@r0 
14887 \newline 
14888 \SpecialChar ~
14889 \SpecialChar ~
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 add  a,r2 ;?
14893 \newline 
14894 \SpecialChar ~
14895 \SpecialChar ~
14896 \SpecialChar ~
14897 \SpecialChar ~
14898 mov  dpl,a 
14899 \newline 
14900 \SpecialChar ~
14901 \SpecialChar ~
14902 \SpecialChar ~
14903 \SpecialChar ~
14904 mov  dph,#0x00 
14905 \newline 
14906 \SpecialChar ~
14907 \SpecialChar ~
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 mov  sp,_bp 
14911 \newline 
14912 \SpecialChar ~
14913 \SpecialChar ~
14914 \SpecialChar ~
14915 \SpecialChar ~
14916 pop  _bp 
14917 \newline 
14918 \SpecialChar ~
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 ret
14923 \layout Standard
14924 \added_space_bottom bigskip 
14925 The compiling and linking procedure remains the same, however note the extra
14926  entry & exit linkage required for the assembler code, _bp is the stack
14927  frame pointer and is used to compute the offset into the stack for parameters
14928  and local variables.
14929 \layout Section
14930
14931 int (16 bit)
14932 \begin_inset LatexCommand \index{int (16 bit)}
14933
14934 \end_inset 
14935
14936  and long (32 bit)
14937 \begin_inset LatexCommand \index{long (32 bit)}
14938
14939 \end_inset 
14940
14941  Support
14942 \layout Standard
14943
14944 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14945  multiplication and modulus operations are implemented by support routines.
14946  These support routines are all developed in ANSI-C to facilitate porting
14947  to other MCUs, although some model specific assembler optimizations are
14948  used.
14949  The following files contain the described routines, all of them can be
14950  found in <installdir>/share/sdcc/lib.
14951 \newline 
14952
14953 \layout Standard
14954 \align center 
14955
14956 \begin_inset  Tabular
14957 <lyxtabular version="3" rows="11" columns="2">
14958 <features>
14959 <column alignment="left" valignment="top" leftline="true" width="0">
14960 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14961 <row topline="true" bottomline="true">
14962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14963 \begin_inset Text
14964
14965 \layout Standard
14966
14967
14968 \series bold 
14969 Function
14970 \end_inset 
14971 </cell>
14972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14973 \begin_inset Text
14974
14975 \layout Standard
14976
14977
14978 \series bold 
14979 Description
14980 \end_inset 
14981 </cell>
14982 </row>
14983 <row topline="true">
14984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14985 \begin_inset Text
14986
14987 \layout Standard
14988
14989 _mulint.c 
14990 \end_inset 
14991 </cell>
14992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14993 \begin_inset Text
14994
14995 \layout Standard
14996
14997 16 bit multiplication
14998 \end_inset 
14999 </cell>
15000 </row>
15001 <row topline="true">
15002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15003 \begin_inset Text
15004
15005 \layout Standard
15006
15007 _divsint.c 
15008 \end_inset 
15009 </cell>
15010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15011 \begin_inset Text
15012
15013 \layout Standard
15014
15015  signed 16 bit division (calls _divuint)
15016 \end_inset 
15017 </cell>
15018 </row>
15019 <row topline="true">
15020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15021 \begin_inset Text
15022
15023 \layout Standard
15024
15025 _divuint.c 
15026 \end_inset 
15027 </cell>
15028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15029 \begin_inset Text
15030
15031 \layout Standard
15032
15033  unsigned 16 bit division
15034 \end_inset 
15035 </cell>
15036 </row>
15037 <row topline="true">
15038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15039 \begin_inset Text
15040
15041 \layout Standard
15042
15043 _modsint.c
15044 \end_inset 
15045 </cell>
15046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15047 \begin_inset Text
15048
15049 \layout Standard
15050
15051 signed 16 bit modulus (calls _moduint)
15052 \end_inset 
15053 </cell>
15054 </row>
15055 <row topline="true">
15056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15057 \begin_inset Text
15058
15059 \layout Standard
15060
15061 _moduint.c
15062 \end_inset 
15063 </cell>
15064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15065 \begin_inset Text
15066
15067 \layout Standard
15068
15069 unsigned 16 bit modulus
15070 \end_inset 
15071 </cell>
15072 </row>
15073 <row topline="true">
15074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15075 \begin_inset Text
15076
15077 \layout Standard
15078
15079 _mullong.c
15080 \end_inset 
15081 </cell>
15082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15083 \begin_inset Text
15084
15085 \layout Standard
15086
15087 32 bit multiplication
15088 \end_inset 
15089 </cell>
15090 </row>
15091 <row topline="true">
15092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15093 \begin_inset Text
15094
15095 \layout Standard
15096
15097 _divslong.c 
15098 \end_inset 
15099 </cell>
15100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15101 \begin_inset Text
15102
15103 \layout Standard
15104
15105  signed 32 division (calls _divulong)
15106 \end_inset 
15107 </cell>
15108 </row>
15109 <row topline="true">
15110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15111 \begin_inset Text
15112
15113 \layout Standard
15114
15115 _divulong.c 
15116 \end_inset 
15117 </cell>
15118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15119 \begin_inset Text
15120
15121 \layout Standard
15122
15123 unsigned 32 division
15124 \end_inset 
15125 </cell>
15126 </row>
15127 <row topline="true">
15128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15129 \begin_inset Text
15130
15131 \layout Standard
15132
15133 _modslong.c
15134 \end_inset 
15135 </cell>
15136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15137 \begin_inset Text
15138
15139 \layout Standard
15140
15141  signed 32 bit modulus (calls _modulong)
15142 \end_inset 
15143 </cell>
15144 </row>
15145 <row topline="true" bottomline="true">
15146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15147 \begin_inset Text
15148
15149 \layout Standard
15150
15151 _modulong.c
15152 \end_inset 
15153 </cell>
15154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15155 \begin_inset Text
15156
15157 \layout Standard
15158
15159 unsigned 32 bit modulus
15160 \end_inset 
15161 </cell>
15162 </row>
15163 </lyxtabular>
15164
15165 \end_inset 
15166
15167
15168 \newline 
15169
15170 \layout Standard
15171
15172 Since they are compiled as 
15173 \emph on 
15174 non-reentrant
15175 \emph default 
15176
15177 \begin_inset LatexCommand \index{reentrant}
15178
15179 \end_inset 
15180
15181 , interrupt
15182 \begin_inset LatexCommand \index{interrupt}
15183
15184 \end_inset 
15185
15186  service routines should not do any of the above operations.
15187  If this is unavoidable then the above routines will need to be compiled
15188  with the 
15189 \emph on 
15190 -
15191 \begin_inset ERT
15192 status Collapsed
15193
15194 \layout Standard
15195
15196 \backslash 
15197 /
15198 \end_inset 
15199
15200 -stack-auto
15201 \begin_inset LatexCommand \index{-\/-stack-auto}
15202
15203 \end_inset 
15204
15205
15206 \emph default 
15207  option, after which the source program will have to be compiled with 
15208 \emph on 
15209 -
15210 \begin_inset ERT
15211 status Collapsed
15212
15213 \layout Standard
15214
15215 \backslash 
15216 /
15217 \end_inset 
15218
15219 -int-long-reent
15220 \begin_inset LatexCommand \index{-\/-int-long-reent}
15221
15222 \end_inset 
15223
15224
15225 \emph default 
15226  option.
15227  Notice that you don't have to call these routines directly.
15228  The compiler will use them automatically every time an integer operation
15229  is required.
15230 \layout Section
15231
15232 Floating Point Support
15233 \begin_inset LatexCommand \index{Floating point support}
15234
15235 \end_inset 
15236
15237
15238 \layout Standard
15239
15240 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15241  The floating point support routines are derived from gcc's floatlib.c and
15242  consist of the following routines:
15243 \newline 
15244
15245 \layout Standard
15246 \align center 
15247
15248 \size footnotesize 
15249
15250 \begin_inset  Tabular
15251 <lyxtabular version="3" rows="17" columns="2">
15252 <features>
15253 <column alignment="left" valignment="top" leftline="true" width="0">
15254 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15255 <row topline="true" bottomline="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 Function 
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 Description
15279 \end_inset 
15280 </cell>
15281 </row>
15282 <row topline="true">
15283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15284 \begin_inset Text
15285
15286 \layout Standard
15287
15288
15289 \family roman 
15290 \series medium 
15291 \shape up 
15292 \size normal 
15293 \emph off 
15294 \bar no 
15295 \noun off 
15296 \color none
15297 _fsadd.c
15298 \end_inset 
15299 </cell>
15300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15301 \begin_inset Text
15302
15303 \layout Standard
15304
15305
15306 \family roman 
15307 \series medium 
15308 \shape up 
15309 \size normal 
15310 \emph off 
15311 \bar no 
15312 \noun off 
15313 \color none
15314 add floating point numbers
15315 \end_inset 
15316 </cell>
15317 </row>
15318 <row topline="true">
15319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15320 \begin_inset Text
15321
15322 \layout Standard
15323
15324
15325 \family roman 
15326 \series medium 
15327 \shape up 
15328 \size normal 
15329 \emph off 
15330 \bar no 
15331 \noun off 
15332 \color none
15333 _fssub.c 
15334 \end_inset 
15335 </cell>
15336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15337 \begin_inset Text
15338
15339 \layout Standard
15340
15341
15342 \family roman 
15343 \series medium 
15344 \shape up 
15345 \size normal 
15346 \emph off 
15347 \bar no 
15348 \noun off 
15349 \color none
15350 subtract floating point numbers 
15351 \end_inset 
15352 </cell>
15353 </row>
15354 <row topline="true">
15355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15356 \begin_inset Text
15357
15358 \layout Standard
15359
15360
15361 \family roman 
15362 \series medium 
15363 \shape up 
15364 \size normal 
15365 \emph off 
15366 \bar no 
15367 \noun off 
15368 \color none
15369 _fsdiv.c 
15370 \end_inset 
15371 </cell>
15372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15373 \begin_inset Text
15374
15375 \layout Standard
15376
15377
15378 \family roman 
15379 \series medium 
15380 \shape up 
15381 \size normal 
15382 \emph off 
15383 \bar no 
15384 \noun off 
15385 \color none
15386 divide floating point numbers 
15387 \end_inset 
15388 </cell>
15389 </row>
15390 <row topline="true">
15391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15392 \begin_inset Text
15393
15394 \layout Standard
15395
15396
15397 \family roman 
15398 \series medium 
15399 \shape up 
15400 \size normal 
15401 \emph off 
15402 \bar no 
15403 \noun off 
15404 \color none
15405 _fsmul.c 
15406 \end_inset 
15407 </cell>
15408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15409 \begin_inset Text
15410
15411 \layout Standard
15412
15413
15414 \family roman 
15415 \series medium 
15416 \shape up 
15417 \size normal 
15418 \emph off 
15419 \bar no 
15420 \noun off 
15421 \color none
15422 multiply floating point numbers 
15423 \end_inset 
15424 </cell>
15425 </row>
15426 <row topline="true">
15427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15428 \begin_inset Text
15429
15430 \layout Standard
15431
15432
15433 \family roman 
15434 \series medium 
15435 \shape up 
15436 \size normal 
15437 \emph off 
15438 \bar no 
15439 \noun off 
15440 \color none
15441 _fs2uchar.c
15442 \end_inset 
15443 </cell>
15444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15445 \begin_inset Text
15446
15447 \layout Standard
15448
15449
15450 \family roman 
15451 \series medium 
15452 \shape up 
15453 \size normal 
15454 \emph off 
15455 \bar no 
15456 \noun off 
15457 \color none
15458 convert floating point to unsigned char
15459 \end_inset 
15460 </cell>
15461 </row>
15462 <row topline="true">
15463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15464 \begin_inset Text
15465
15466 \layout Standard
15467
15468
15469 \family roman 
15470 \series medium 
15471 \shape up 
15472 \size normal 
15473 \emph off 
15474 \bar no 
15475 \noun off 
15476 \color none
15477 _fs2char.c
15478 \end_inset 
15479 </cell>
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15481 \begin_inset Text
15482
15483 \layout Standard
15484
15485
15486 \family roman 
15487 \series medium 
15488 \shape up 
15489 \size normal 
15490 \emph off 
15491 \bar no 
15492 \noun off 
15493 \color none
15494 convert floating point to signed char
15495 \end_inset 
15496 </cell>
15497 </row>
15498 <row topline="true">
15499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15500 \begin_inset Text
15501
15502 \layout Standard
15503
15504
15505 \family roman 
15506 \series medium 
15507 \shape up 
15508 \size normal 
15509 \emph off 
15510 \bar no 
15511 \noun off 
15512 \color none
15513 _fs2uint.c
15514 \end_inset 
15515 </cell>
15516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15517 \begin_inset Text
15518
15519 \layout Standard
15520
15521
15522 \family roman 
15523 \series medium 
15524 \shape up 
15525 \size normal 
15526 \emph off 
15527 \bar no 
15528 \noun off 
15529 \color none
15530 convert floating point to unsigned int
15531 \end_inset 
15532 </cell>
15533 </row>
15534 <row topline="true">
15535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15536 \begin_inset Text
15537
15538 \layout Standard
15539
15540
15541 \family roman 
15542 \series medium 
15543 \shape up 
15544 \size normal 
15545 \emph off 
15546 \bar no 
15547 \noun off 
15548 \color none
15549 _fs2int.c
15550 \end_inset 
15551 </cell>
15552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15553 \begin_inset Text
15554
15555 \layout Standard
15556
15557
15558 \family roman 
15559 \series medium 
15560 \shape up 
15561 \size normal 
15562 \emph off 
15563 \bar no 
15564 \noun off 
15565 \color none
15566 convert floating point to signed int
15567 \end_inset 
15568 </cell>
15569 </row>
15570 <row topline="true">
15571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15572 \begin_inset Text
15573
15574 \layout Standard
15575
15576
15577 \family roman 
15578 \series medium 
15579 \shape up 
15580 \size normal 
15581 \emph off 
15582 \bar no 
15583 \noun off 
15584 \color none
15585 _fs2ulong.
15586 \family default 
15587 \series default 
15588 \shape default 
15589 \size default 
15590 \emph default 
15591 \bar default 
15592 \noun default 
15593 \color default
15594 c
15595 \end_inset 
15596 </cell>
15597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15598 \begin_inset Text
15599
15600 \layout Standard
15601
15602
15603 \family roman 
15604 \series medium 
15605 \shape up 
15606 \size normal 
15607 \emph off 
15608 \bar no 
15609 \noun off 
15610 \color none
15611 convert floating point to unsigned long
15612 \end_inset 
15613 </cell>
15614 </row>
15615 <row topline="true">
15616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15617 \begin_inset Text
15618
15619 \layout Standard
15620
15621
15622 \family roman 
15623 \series medium 
15624 \shape up 
15625 \size normal 
15626 \emph off 
15627 \bar no 
15628 \noun off 
15629 \color none
15630 _fs2long.c
15631 \end_inset 
15632 </cell>
15633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15634 \begin_inset Text
15635
15636 \layout Standard
15637
15638
15639 \family roman 
15640 \series medium 
15641 \shape up 
15642 \size normal 
15643 \emph off 
15644 \bar no 
15645 \noun off 
15646 \color none
15647 convert floating point to signed long
15648 \end_inset 
15649 </cell>
15650 </row>
15651 <row topline="true">
15652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15653 \begin_inset Text
15654
15655 \layout Standard
15656
15657
15658 \family roman 
15659 \series medium 
15660 \shape up 
15661 \size normal 
15662 \emph off 
15663 \bar no 
15664 \noun off 
15665 \color none
15666 _uchar2fs.c
15667 \end_inset 
15668 </cell>
15669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15670 \begin_inset Text
15671
15672 \layout Standard
15673
15674
15675 \family roman 
15676 \series medium 
15677 \shape up 
15678 \size normal 
15679 \emph off 
15680 \bar no 
15681 \noun off 
15682 \color none
15683 convert unsigned char to floating point
15684 \end_inset 
15685 </cell>
15686 </row>
15687 <row topline="true">
15688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15689 \begin_inset Text
15690
15691 \layout Standard
15692
15693
15694 \family roman 
15695 \series medium 
15696 \shape up 
15697 \size normal 
15698 \emph off 
15699 \bar no 
15700 \noun off 
15701 \color none
15702 _char2fs.c
15703 \end_inset 
15704 </cell>
15705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15706 \begin_inset Text
15707
15708 \layout Standard
15709
15710
15711 \family roman 
15712 \series medium 
15713 \shape up 
15714 \size normal 
15715 \emph off 
15716 \bar no 
15717 \noun off 
15718 \color none
15719 convert char to floating point number
15720 \end_inset 
15721 </cell>
15722 </row>
15723 <row topline="true">
15724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15725 \begin_inset Text
15726
15727 \layout Standard
15728
15729
15730 \family roman 
15731 \series medium 
15732 \shape up 
15733 \size normal 
15734 \emph off 
15735 \bar no 
15736 \noun off 
15737 \color none
15738 _uint2fs.c
15739 \end_inset 
15740 </cell>
15741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15742 \begin_inset Text
15743
15744 \layout Standard
15745
15746
15747 \family roman 
15748 \series medium 
15749 \shape up 
15750 \size normal 
15751 \emph off 
15752 \bar no 
15753 \noun off 
15754 \color none
15755 convert unsigned int to floating point
15756 \end_inset 
15757 </cell>
15758 </row>
15759 <row topline="true">
15760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15761 \begin_inset Text
15762
15763 \layout Standard
15764
15765
15766 \family roman 
15767 \series medium 
15768 \shape up 
15769 \size normal 
15770 \emph off 
15771 \bar no 
15772 \noun off 
15773 \color none
15774 _int2fs.c
15775 \end_inset 
15776 </cell>
15777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15778 \begin_inset Text
15779
15780 \layout Standard
15781
15782
15783 \family roman 
15784 \series medium 
15785 \shape up 
15786 \size normal 
15787 \emph off 
15788 \bar no 
15789 \noun off 
15790 \color none
15791 convert int to floating point numbers
15792 \end_inset 
15793 </cell>
15794 </row>
15795 <row topline="true">
15796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15797 \begin_inset Text
15798
15799 \layout Standard
15800
15801
15802 \family roman 
15803 \series medium 
15804 \shape up 
15805 \size normal 
15806 \emph off 
15807 \bar no 
15808 \noun off 
15809 \color none
15810 _ulong2fs.c
15811 \end_inset 
15812 </cell>
15813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15814 \begin_inset Text
15815
15816 \layout Standard
15817
15818
15819 \family roman 
15820 \series medium 
15821 \shape up 
15822 \size normal 
15823 \emph off 
15824 \bar no 
15825 \noun off 
15826 \color none
15827 convert unsigned long to floating point number
15828 \end_inset 
15829 </cell>
15830 </row>
15831 <row topline="true" bottomline="true">
15832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15833 \begin_inset Text
15834
15835 \layout Standard
15836
15837
15838 \family roman 
15839 \series medium 
15840 \shape up 
15841 \size normal 
15842 \emph off 
15843 \bar no 
15844 \noun off 
15845 \color none
15846 _long2fs.c
15847 \end_inset 
15848 </cell>
15849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15850 \begin_inset Text
15851
15852 \layout Standard
15853
15854
15855 \family roman 
15856 \series medium 
15857 \shape up 
15858 \size normal 
15859 \emph off 
15860 \bar no 
15861 \noun off 
15862 \color none
15863 convert long to floating point number
15864 \end_inset 
15865 </cell>
15866 </row>
15867 </lyxtabular>
15868
15869 \end_inset 
15870
15871
15872 \newline 
15873
15874 \layout Standard
15875 \added_space_bottom bigskip 
15876 These support routines are developed in ANSI-C so there is room for space
15877  and speed improvement
15878 \begin_inset Foot
15879 collapsed false
15880
15881 \layout Standard
15882
15883 These floating point routines (
15884 \emph on 
15885 not
15886 \emph default 
15887  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15888  
15889 \end_inset 
15890
15891 .
15892  Note if all these routines are used simultaneously the data space might
15893  overflow.
15894  For serious floating point usage the large model might be needed.
15895  Also notice that you don't have to call this routines directly.
15896  The compiler will use them automatically every time a floating point operation
15897  is required.
15898 \layout Section
15899
15900 Library Routines
15901 \begin_inset LatexCommand \index{Libraries}
15902
15903 \end_inset 
15904
15905
15906 \layout Standard
15907
15908
15909 \emph on 
15910 <pending: this is messy and incomplete - a little more information is in
15911  sdcc/doc/libdoc.txt
15912 \emph default 
15913  >
15914 \layout Subsection
15915
15916 Compiler support routines (_gptrget, _mulint etc.)
15917 \layout Subsection
15918
15919 Stdclib functions (puts, printf, strcat etc.)
15920 \layout Subsubsection
15921
15922 <stdio.h>
15923 \layout Standard
15924
15925
15926 \begin_inset LatexCommand \index{<stdio.h>}
15927
15928 \end_inset 
15929
15930 As usual on embedded systems you have to provide your own 
15931 \family typewriter 
15932 getchar()
15933 \begin_inset LatexCommand \index{getchar()}
15934
15935 \end_inset 
15936
15937  
15938 \family default 
15939 and 
15940 \family typewriter 
15941 putchar()
15942 \begin_inset LatexCommand \index{putchar()}
15943
15944 \end_inset 
15945
15946
15947 \family default 
15948  routines.
15949  SDCC does not know whether the system connects to a serial line with or
15950  without handshake, LCD, keyboard or other device.
15951  And whether a 
15952 \family typewriter 
15953 lf
15954 \family default 
15955  to 
15956 \family typewriter 
15957 crlf
15958 \family default 
15959  conversion within 
15960 \family typewriter 
15961 putchar()
15962 \family default 
15963  is intended.
15964  You'll find examples for serial routines f.e.
15965  in sdcc/device/lib.
15966 \layout Standard
15967
15968 The default
15969 \family typewriter 
15970  printf()
15971 \begin_inset LatexCommand \index{printf()}
15972
15973 \end_inset 
15974
15975
15976 \family default 
15977 implementation in
15978 \family typewriter 
15979  printf_large.c
15980 \family default 
15981  does not support float (except on ds390).
15982  To enable this recompile it with the option 
15983 \emph on 
15984 -
15985 \begin_inset ERT
15986 status Collapsed
15987
15988 \layout Standard
15989
15990 \backslash 
15991 /
15992 \end_inset 
15993
15994 DUSE_FLOATS=1
15995 \begin_inset LatexCommand \index{USE\_FLOATS}
15996
15997 \end_inset 
15998
15999
16000 \emph default 
16001  on the command line.
16002  Use
16003 \emph on 
16004  -
16005 \begin_inset ERT
16006 status Collapsed
16007
16008 \layout Standard
16009
16010 \backslash 
16011 /
16012 \end_inset 
16013
16014 -model-large
16015 \begin_inset LatexCommand \index{-\/-model-large}
16016
16017 \end_inset 
16018
16019
16020 \emph default 
16021  for the mcs51 port, since this uses a lot of memory.
16022 \layout Standard
16023
16024 If you're short on memory you might want to use 
16025 \family typewriter 
16026 printf_small()
16027 \begin_inset LatexCommand \index{printf\_small()}
16028
16029 \end_inset 
16030
16031
16032 \family default 
16033  
16034 \emph on 
16035 instead
16036 \emph default 
16037  of
16038 \family typewriter 
16039  printf().
16040
16041 \family default 
16042  For the mcs51 there additionally are assembly versions 
16043 \family typewriter 
16044 printf_tiny()
16045 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16046
16047 \end_inset 
16048
16049
16050 \family default 
16051  (subset of printf using less than 270 bytes) and 
16052 \family typewriter 
16053 printf_fast()
16054 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16055
16056 \end_inset 
16057
16058  
16059 \family default 
16060 and
16061 \family typewriter 
16062  printf_fast_f()
16063 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16064
16065 \end_inset 
16066
16067
16068 \family default 
16069  (floating-point aware version of printf_fast) which should fit the requirements
16070  of many embedded systems (printf_fast() can be customized by unsetting
16071  #defines to 
16072 \emph on 
16073 not
16074 \emph default 
16075  support long variables and field widths).
16076 \layout Subsubsection
16077
16078 <malloc.h>
16079 \begin_inset LatexCommand \index{malloc.h}
16080
16081 \end_inset 
16082
16083
16084 \layout Standard
16085
16086 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16087  using dynamic memory allocation
16088 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16089
16090 \end_inset 
16091
16092  and a default heap
16093 \begin_inset LatexCommand \index{heap (malloc)}
16094
16095 \end_inset 
16096
16097  space of 1024 bytes is provided for malloc to allocate memory from.
16098  If you need a different heap size you need to recompile _heap.c with the
16099  required size defined in HEAP_SIZE.
16100  It is recommended to make a copy of this file into your project directory
16101  and compile it there with:
16102 \layout Verse
16103
16104
16105 \family typewriter 
16106 sdcc -c _heap.c -D HEAD_SIZE=2048
16107 \newline 
16108
16109 \family default 
16110 And then link it with:
16111 \layout Verse
16112
16113
16114 \family typewriter 
16115 sdcc main.rel _heap.rel
16116 \newline 
16117
16118 \layout Subsection
16119
16120 Math functions (sinf, powf, sqrtf etc.)
16121 \layout Subsubsection
16122
16123 <math.h>
16124 \layout Standard
16125
16126 See definitions in file <math.h>.
16127 \layout Subsection
16128
16129 Other libraries
16130 \layout Standard
16131
16132 Libraries
16133 \begin_inset LatexCommand \index{Libraries}
16134
16135 \end_inset 
16136
16137  included in SDCC should have a license at least as liberal as the GNU Lesser
16138  General Public License
16139 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16140
16141 \end_inset 
16142
16143  
16144 \emph on 
16145 LGPL
16146 \emph default 
16147 .
16148 \layout Comment
16149
16150 license statements for the libraries are missing.
16151  sdcc/device/lib/ser_ir.c
16152 \layout Comment
16153
16154 or _decdptr f.e.
16155  come with a GPL (as opposed to LGPL) License - this will not be liberal
16156  enough for many embedded programmers.
16157 \layout Standard
16158
16159 If you have ported some library or want to share experience about some code
16160  which f.e.
16161  falls into any of these categories Busses (I
16162 \begin_inset Formula $^{\textrm{2}}$
16163 \end_inset 
16164
16165 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16166  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16167  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16168 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16169
16170 \end_inset 
16171
16172 \SpecialChar ~
16173 would certainly like to hear about it.
16174 \layout Standard
16175 \added_space_bottom bigskip 
16176 Programmers coding for embedded systems are not especially famous for being
16177  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16178 e these references are very valuable.
16179  Let's help to create a climate where information is shared.
16180 \layout Section
16181
16182 Memory Models
16183 \layout Subsection
16184
16185 MCS51 Memory Models
16186 \begin_inset LatexCommand \index{Memory model}
16187
16188 \end_inset 
16189
16190
16191 \begin_inset LatexCommand \index{MCS51 memory model}
16192
16193 \end_inset 
16194
16195
16196 \layout Subsubsection
16197
16198 Small, Medium and Large
16199 \layout Standard
16200
16201 SDCC allows three memory models for MCS51 code, 
16202 \shape slanted 
16203 small, medium
16204 \shape default 
16205  and 
16206 \shape slanted 
16207 large
16208 \shape default 
16209 .
16210  Modules compiled with different memory models should 
16211 \emph on 
16212 never
16213 \emph default 
16214  be combined together or the results would be unpredictable.
16215  The library routines supplied with the compiler are compiled as small,
16216  medium and large.
16217  The compiled library modules are contained in separate directories as small,
16218  medium and large so that you can link to the appropriate set.
16219 \layout Standard
16220
16221 When the medium or large model is used all variables declared without a
16222  storage class will be allocated into the external ram, this includes all
16223  parameters and local variables (for non-reentrant
16224 \begin_inset LatexCommand \index{reentrant}
16225
16226 \end_inset 
16227
16228  functions).
16229  When the small model is used variables without storage class are allocated
16230  in the internal ram.
16231 \layout Standard
16232
16233 Judicious usage of the processor specific storage classes
16234 \begin_inset LatexCommand \index{Storage class}
16235
16236 \end_inset 
16237
16238  and the 'reentrant' function type will yield much more efficient code,
16239  than using the large model.
16240  Several optimizations are disabled when the program is compiled using the
16241  large model, it is therefore recommended that the small model be used unless
16242  absolutely required.
16243 \layout Subsubsection
16244
16245 External Stack
16246 \begin_inset LatexCommand \label{sub:External-Stack}
16247
16248 \end_inset 
16249
16250
16251 \begin_inset LatexCommand \index{stack}
16252
16253 \end_inset 
16254
16255
16256 \begin_inset LatexCommand \index{External stack (mcs51)}
16257
16258 \end_inset 
16259
16260
16261 \layout Standard
16262
16263 The external stack (-
16264 \begin_inset ERT
16265 status Collapsed
16266
16267 \layout Standard
16268
16269 \backslash 
16270 /
16271 \end_inset 
16272
16273 -xstack option
16274 \begin_inset LatexCommand \index{-\/-xstack}
16275
16276 \end_inset 
16277
16278 ) is located in pdata
16279 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16280
16281 \end_inset 
16282
16283  memory (usually at the start of the external ram segment) and uses all
16284  unused space in pdata (max.
16285  256 bytes).
16286  When -
16287 \begin_inset ERT
16288 status Collapsed
16289
16290 \layout Standard
16291
16292 \backslash 
16293 /
16294 \end_inset 
16295
16296 -xstack option is used to compile the program, the parameters and local
16297  variables
16298 \begin_inset LatexCommand \index{local variables}
16299
16300 \end_inset 
16301
16302  of all reentrant functions are allocated in this area.
16303  This option is provided for programs with large stack space requirements.
16304  When used with the -
16305 \begin_inset ERT
16306 status Collapsed
16307
16308 \layout Standard
16309
16310 \backslash 
16311 /
16312 \end_inset 
16313
16314 -stack-auto
16315 \begin_inset LatexCommand \index{-\/-stack-auto}
16316
16317 \end_inset 
16318
16319  option, all parameters and local variables are allocated on the external
16320  stack (note: support libraries will need to be recompiled with the same
16321  options.
16322  There is a predefined target in the library makefile).
16323 \layout Standard
16324
16325 The compiler outputs the higher order address byte of the external ram segment
16326  into port P2
16327 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16328
16329 \end_inset 
16330
16331  (see also section 
16332 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16333
16334 \end_inset 
16335
16336 ), therefore when using the External Stack option, this port 
16337 \emph on 
16338 may not
16339 \emph default 
16340  be used by the application program.
16341 \layout Subsection
16342
16343 DS390 Memory Model
16344 \begin_inset LatexCommand \index{Memory model}
16345
16346 \end_inset 
16347
16348
16349 \begin_inset LatexCommand \index{DS390 memory model}
16350
16351 \end_inset 
16352
16353
16354 \layout Standard
16355
16356 The only model supported is Flat 24
16357 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16358
16359 \end_inset 
16360
16361 .
16362  This generates code for the 24 bit contiguous addressing mode of the Dallas
16363  DS80C390 part.
16364  In this mode, up to four meg of external RAM or code space can be directly
16365  addressed.
16366  See the data sheets at www.dalsemi.com for further information on this part.
16367 \newline 
16368
16369 \newline 
16370 Note that the compiler does not generate any code to place the processor
16371  into 24 bitmode (although 
16372 \emph on 
16373 tinibios
16374 \emph default 
16375  in the ds390 libraries will do that for you).
16376  If you don't use 
16377 \emph on 
16378 tinibios
16379 \emph default 
16380
16381 \begin_inset LatexCommand \index{Tinibios (DS390)}
16382
16383 \end_inset 
16384
16385 , the boot loader or similar code must ensure that the processor is in 24
16386  bit contiguous addressing mode before calling the SDCC startup code.
16387 \newline 
16388
16389 \newline 
16390 Like the 
16391 \emph on 
16392 -
16393 \begin_inset ERT
16394 status Collapsed
16395
16396 \layout Standard
16397
16398 \backslash 
16399 /
16400 \end_inset 
16401
16402 -model-large
16403 \emph default 
16404  option, variables will by default be placed into the XDATA segment.
16405  
16406 \newline 
16407
16408 \newline 
16409 Segments may be placed anywhere in the 4 meg address space using the usual
16410  -
16411 \begin_inset ERT
16412 status Collapsed
16413
16414 \layout Standard
16415
16416 \backslash 
16417 /
16418 \end_inset 
16419
16420 -*-loc options.
16421  Note that if any segments are located above 64K, the -r flag must be passed
16422  to the linker to generate the proper segment relocations, and the Intel
16423  HEX output format must be used.
16424  The -r flag can be passed to the linker by using the option 
16425 \emph on 
16426 -Wl-r
16427 \emph default 
16428  on the SDCC command line.
16429  However, currently the linker can not handle code segments > 64k.
16430 \layout Section
16431
16432 Pragmas
16433 \begin_inset LatexCommand \label{sec:Pragmas}
16434
16435 \end_inset 
16436
16437
16438 \begin_inset LatexCommand \index{Pragmas}
16439
16440 \end_inset 
16441
16442
16443 \layout Standard
16444
16445 SDCC supports the following #pragma directives:
16446 \layout Itemize
16447
16448
16449 \series bold 
16450 save
16451 \series default 
16452
16453 \begin_inset LatexCommand \index{\#pragma save}
16454
16455 \end_inset 
16456
16457  - this will save most current options to the save/restore stack.
16458  See #pragma\SpecialChar ~
16459 restore.
16460 \layout Itemize
16461
16462
16463 \series bold 
16464 restore
16465 \series default 
16466
16467 \begin_inset LatexCommand \index{\#pragma restore}
16468
16469 \end_inset 
16470
16471  - will restore saved options from the last save.
16472  saves & restores can be nested.
16473  SDCC uses a save/restore stack: save pushes current options to the stack,
16474  restore pulls current options from the stack.
16475  See #pragma\SpecialChar ~
16476 save.
16477 \newline 
16478
16479 \layout Itemize
16480
16481
16482 \series bold 
16483 callee_saves
16484 \series default 
16485
16486 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16487
16488 \end_inset 
16489
16490
16491 \begin_inset LatexCommand \index{function prologue}
16492
16493 \end_inset 
16494
16495  function1[,function2[,function3...]] - The compiler by default uses a caller
16496  saves convention for register saving across function calls, however this
16497  can cause unnecessary register pushing & popping
16498 \begin_inset LatexCommand \index{push/pop}
16499
16500 \end_inset 
16501
16502  when calling small functions from larger functions.
16503  This option can be used to switch off the register saving convention for
16504  the function names specified.
16505  The compiler will not save registers when calling these functions, extra
16506  code need to be manually inserted at the entry & exit for these functions
16507  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16508  reduce code & improve run time performance of the generated code.
16509  In the future the compiler (with inter procedural analysis) may be able
16510  to determine the appropriate scheme to use for each function call.
16511  If -
16512 \begin_inset ERT
16513 status Collapsed
16514
16515 \layout Standard
16516
16517 \backslash 
16518 /
16519 \end_inset 
16520
16521 -callee-saves command line option is used, the function names specified
16522  in #pragma\SpecialChar ~
16523 callee_saves
16524 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16525
16526 \end_inset 
16527
16528  is appended to the list of functions specified in the command line.
16529 \layout Itemize
16530
16531
16532 \series bold 
16533 exclude
16534 \series default 
16535
16536 \begin_inset LatexCommand \index{\#pragma exclude}
16537
16538 \end_inset 
16539
16540  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16541  of pairs of push/pop
16542 \begin_inset LatexCommand \index{push/pop}
16543
16544 \end_inset 
16545
16546  instructions in 
16547 \emph on 
16548 I
16549 \emph default 
16550 nterrupt
16551 \begin_inset LatexCommand \index{interrupt}
16552
16553 \end_inset 
16554
16555  
16556 \emph on 
16557 S
16558 \emph default 
16559 ervice 
16560 \emph on 
16561 R
16562 \emph default 
16563 outines.
16564  The directive should be placed immediately before the ISR function definition
16565  and it affects ALL ISR functions following it.
16566  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16567 exclude\SpecialChar ~
16568 none
16569 \begin_inset LatexCommand \index{\#pragma exclude}
16570
16571 \end_inset 
16572
16573 .
16574  See also the related keyword _naked
16575 \begin_inset LatexCommand \index{\_naked}
16576
16577 \end_inset 
16578
16579
16580 \begin_inset LatexCommand \index{\_\_naked}
16581
16582 \end_inset 
16583
16584 .
16585 \layout Itemize
16586
16587
16588 \series bold 
16589 less_pedantic
16590 \series default 
16591
16592 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16593
16594 \end_inset 
16595
16596  - the compiler will not warn you anymore for obvious mistakes, you'r on
16597  your own now ;-(
16598 \layout Itemize
16599
16600
16601 \series bold 
16602 disable_warning
16603 \series default 
16604  <nnnn>
16605 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16606
16607 \end_inset 
16608
16609  - the compiler will not warn you anymore about warning number <nnnn>.
16610 \layout Itemize
16611
16612
16613 \series bold 
16614 nogcse
16615 \series default 
16616
16617 \begin_inset LatexCommand \index{\#pragma nogcse}
16618
16619 \end_inset 
16620
16621  - will stop global common subexpression elimination.
16622 \layout Itemize
16623
16624
16625 \series bold 
16626 noinduction
16627 \series default 
16628
16629 \begin_inset LatexCommand \index{\#pragma noinduction}
16630
16631 \end_inset 
16632
16633  - will stop loop induction optimizations.
16634 \layout Itemize
16635
16636
16637 \series bold 
16638 noinvariant
16639 \series default 
16640
16641 \begin_inset LatexCommand \index{\#pragma noinvariant}
16642
16643 \end_inset 
16644
16645  - will not do loop invariant optimizations.
16646  For more details see Loop Invariants in section
16647 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16648
16649 \end_inset 
16650
16651 .
16652 \layout Itemize
16653
16654
16655 \series bold 
16656 noiv
16657 \series default 
16658
16659 \begin_inset LatexCommand \index{\#pragma noiv}
16660
16661 \end_inset 
16662
16663  - Do not generate interrupt
16664 \begin_inset LatexCommand \index{interrupt}
16665
16666 \end_inset 
16667
16668  vector table
16669 \begin_inset LatexCommand \index{interrupt vector table}
16670
16671 \end_inset 
16672
16673  entries for all ISR functions defined after the pragma.
16674  This is useful in cases where the interrupt vector table must be defined
16675  manually, or when there is a secondary, manually defined interrupt vector
16676  table (e.g.
16677  for the autovector feature of the Cypress EZ-USB FX2).
16678  More elegantly this can be achieved by obmitting the optional interrupt
16679  number after the interrupt keyword, see section 
16680 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16681
16682 \end_inset 
16683
16684 \SpecialChar ~
16685 about interrupts.
16686 \layout Itemize
16687
16688
16689 \series bold 
16690 nojtbound
16691 \series default 
16692
16693 \begin_inset LatexCommand \index{\#pragma nojtbound}
16694
16695 \end_inset 
16696
16697  - will not generate code for boundary value checking, when switch statements
16698  are turned into jump-tables (dangerous).
16699  For more details see section 
16700 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16701
16702 \end_inset 
16703
16704 .
16705 \layout Itemize
16706
16707
16708 \series bold 
16709 noloopreverse
16710 \series default 
16711
16712 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16713
16714 \end_inset 
16715
16716  - Will not do loop reversal optimization
16717 \layout Itemize
16718
16719
16720 \series bold 
16721 nooverlay
16722 \series default 
16723
16724 \begin_inset LatexCommand \index{\#pragma nooverlay}
16725
16726 \end_inset 
16727
16728  - the compiler will not overlay the parameters and local variables of a
16729  function.
16730 \layout Itemize
16731
16732
16733 \series bold 
16734 stackauto
16735 \series default 
16736
16737 \begin_inset LatexCommand \index{\#pragma stackauto}
16738
16739 \end_inset 
16740
16741 - See option -
16742 \begin_inset ERT
16743 status Collapsed
16744
16745 \layout Standard
16746
16747 \backslash 
16748 /
16749 \end_inset 
16750
16751 -stack-auto
16752 \begin_inset LatexCommand \index{-\/-stack-auto}
16753
16754 \end_inset 
16755
16756  and section 
16757 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16758
16759 \end_inset 
16760
16761  Parameters and Local Variables.
16762 \layout Itemize
16763
16764
16765 \series bold 
16766 opt_code_speed
16767 \series default 
16768  
16769 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16770
16771 \end_inset 
16772
16773 - The compiler will optimize code generation towards fast code, possibly
16774  at the expense of code size.
16775  Currently this has little effect.
16776 \layout Itemize
16777
16778
16779 \series bold 
16780 opt_code_size
16781 \series default 
16782  
16783 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16784
16785 \end_inset 
16786
16787 - The compiler will optimize code generation towards compact code, possibly
16788  at the expense of code speed.
16789  Currently this has little effect.
16790 \layout Itemize
16791
16792
16793 \series bold 
16794 opt_code_balanced
16795 \series default 
16796  
16797 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16798
16799 \end_inset 
16800
16801 - The compiler will attempt to generate code that is both compact and fast,
16802  as long as meeting one goal is not a detriment to the other (this is the
16803  default).
16804  
16805 \layout Itemize
16806
16807
16808 \series bold 
16809 std_sdcc89
16810 \series default 
16811  
16812 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16813
16814 \end_inset 
16815
16816 - Generally follow the C89 standard, but allow SDCC features that conflict
16817  with the standard (default).
16818 \layout Itemize
16819
16820
16821 \series bold 
16822 std_c89
16823 \series default 
16824  
16825 \begin_inset LatexCommand \index{\#pragma std\_c89}
16826
16827 \end_inset 
16828
16829 - Follow the C89 standard and disable SDCC features that conflict with the
16830  standard.
16831 \layout Itemize
16832
16833
16834 \series bold 
16835 std_sdcc99
16836 \series default 
16837  
16838 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16839
16840 \end_inset 
16841
16842 - Generally follow the C99 standard, but allow SDCC features that conflict
16843  with the standard (incomplete support).
16844 \layout Itemize
16845
16846
16847 \series bold 
16848 std_c99
16849 \series default 
16850  
16851 \begin_inset LatexCommand \index{\#pragma std\_c99}
16852
16853 \end_inset 
16854
16855 - Follow the C99 standard and disable SDCC features that conflict with the
16856  standard (incomplete support).
16857 \layout Itemize
16858
16859
16860 \series bold 
16861 codeseg
16862 \series default 
16863  <name>
16864 \begin_inset LatexCommand \index{\#pragma codeseg}
16865
16866 \end_inset 
16867
16868 - Use this name (max.
16869  8 characters) for the code segment.
16870  See option -
16871 \begin_inset ERT
16872 status Collapsed
16873
16874 \layout Standard
16875
16876 \backslash 
16877 /
16878 \end_inset 
16879
16880 -codeseg.
16881 \layout Itemize
16882
16883
16884 \series bold 
16885 constseg
16886 \series default 
16887  <name>
16888 \begin_inset LatexCommand \index{\#pragma constseg}
16889
16890 \end_inset 
16891
16892 - Use this name (max.
16893  8 characters) for the const segment.
16894  See option -
16895 \begin_inset ERT
16896 status Collapsed
16897
16898 \layout Standard
16899
16900 \backslash 
16901 /
16902 \end_inset 
16903
16904 -constseg.
16905 \layout Standard
16906
16907 The preprocessor SDCPP
16908 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16909
16910 \end_inset 
16911
16912  supports the following #pragma directives:
16913 \layout Itemize
16914
16915
16916 \series bold 
16917 pedantic_parse_number
16918 \series default 
16919
16920 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
16921
16922 \end_inset 
16923
16924  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
16925  parsed properly and the macro LO_B(3) gets expanded.
16926  Default is off.
16927  Below is an example on how to use this pragma.
16928
16929 \emph on 
16930  Note: this functionality is not in conformance with standard!
16931 \layout Verse
16932
16933
16934 \family typewriter 
16935 #pragma pedantic_parse_number +
16936 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
16937
16938 \end_inset 
16939
16940
16941 \newline 
16942
16943 \newline 
16944 #define LO_B(x) ((x) & 0xff)
16945 \newline 
16946
16947 \newline 
16948 unsigned char foo(void)
16949 \newline 
16950 {
16951 \newline 
16952 \SpecialChar ~
16953 \SpecialChar ~
16954 \SpecialChar ~
16955 unsigned char c=0xfe-LO_B(3);
16956 \newline 
16957
16958 \newline 
16959 \SpecialChar ~
16960 \SpecialChar ~
16961 \SpecialChar ~
16962 return c;
16963 \newline 
16964 }
16965 \newline 
16966
16967 \family default 
16968
16969 \layout Itemize
16970
16971
16972 \series bold 
16973 preproc_asm
16974 \series default 
16975
16976 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16977
16978 \end_inset 
16979
16980  (+ | -) - switch _asm _endasm block preprocessing on / off.
16981  Default is on.
16982  You use this prama to define multilines of assembly code.
16983  This will prevent the preprocessor from changing the formating required
16984  by assembly code.
16985  Below is an example on how to use this pragma.
16986 \layout Verse
16987
16988
16989 \family typewriter 
16990 #pragma preproc_asm -
16991 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16992
16993 \end_inset 
16994
16995
16996 \newline 
16997 #define MYDELAY _asm
16998 \newline 
16999 \SpecialChar ~
17000 \SpecialChar ~
17001 \SpecialChar ~
17002 nop ;my assembly comment...
17003 \newline 
17004 \SpecialChar ~
17005 \SpecialChar ~
17006 \SpecialChar ~
17007 nop
17008 \newline 
17009 \SpecialChar ~
17010 \SpecialChar ~
17011 \SpecialChar ~
17012 nop
17013 \newline 
17014 _endasm
17015 \newline 
17016 #pragma preproc_asm +
17017 \newline 
17018
17019 \newline 
17020 void foo (void) 
17021 \newline 
17022
17023 \newline 
17024 \SpecialChar ~
17025 \SpecialChar ~
17026 \SpecialChar ~
17027  ...
17028  
17029 \newline 
17030 \SpecialChar ~
17031 \SpecialChar ~
17032 \SpecialChar ~
17033  MYDELAY;
17034 \newline 
17035 \SpecialChar ~
17036 \SpecialChar ~
17037 \SpecialChar ~
17038  ...
17039  
17040 \newline 
17041
17042 \newline 
17043
17044 \layout Itemize
17045
17046
17047 \series bold 
17048 sdcc_hash
17049 \series default 
17050
17051 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17052
17053 \end_inset 
17054
17055  (+ | -) - Allow "naked" hash in macro definition, for example:
17056 \newline 
17057
17058 \family typewriter 
17059 #define DIR_LO(x) #(x & 0xff)
17060 \family default 
17061
17062 \newline 
17063 Default is off.
17064  Below is an example on how to use this pragma.
17065 \layout Verse
17066
17067
17068 \family typewriter 
17069 #pragma preproc_asm +
17070 \newline 
17071 #pragma sdcc_hash +
17072 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17073
17074 \end_inset 
17075
17076
17077 \newline 
17078
17079 \newline 
17080 #define ROMCALL(x) 
17081 \backslash 
17082
17083 \newline 
17084 \SpecialChar ~
17085 \SpecialChar ~
17086 \SpecialChar ~
17087 mov R6_B3, #(x & 0xff) 
17088 \backslash 
17089
17090 \newline 
17091 \SpecialChar ~
17092 \SpecialChar ~
17093 \SpecialChar ~
17094 mov R7_B3, #((x >> 8) & 0xff) 
17095 \backslash 
17096
17097 \newline 
17098 \SpecialChar ~
17099 \SpecialChar ~
17100 \SpecialChar ~
17101 lcall __romcall
17102 \newline 
17103
17104 \newline 
17105 ...
17106 \newline 
17107 _asm
17108 \newline 
17109 ROMCALL(72)
17110 \newline 
17111 _endasm;
17112 \newline 
17113 ...
17114 \newline 
17115
17116 \family default 
17117
17118 \layout Standard
17119
17120 The pragma's are intended to be used to turn-on or off certain optimizations
17121  which might cause the compiler to generate extra stack / data space to
17122  store compiler generated temporary variables.
17123  This usually happens in large functions.
17124  Pragma directives should be used as shown in the following example, they
17125  are used to control options & optimizations for a given function; pragmas
17126  should be placed before and/or after a function, placing pragma's inside
17127  a function body could have unpredictable results.
17128 \layout Verse
17129
17130
17131 \family typewriter 
17132 #pragma save
17133 \begin_inset LatexCommand \index{\#pragma save}
17134
17135 \end_inset 
17136
17137  \SpecialChar ~
17138 \SpecialChar ~
17139 \SpecialChar ~
17140 \SpecialChar ~
17141 \SpecialChar ~
17142 \SpecialChar ~
17143 \SpecialChar ~
17144 /* save the current settings */ 
17145 \newline 
17146 #pragma nogcse
17147 \begin_inset LatexCommand \index{\#pragma nogcse}
17148
17149 \end_inset 
17150
17151  \SpecialChar ~
17152 \SpecialChar ~
17153 \SpecialChar ~
17154 \SpecialChar ~
17155 \SpecialChar ~
17156 /* turnoff global subexpression elimination */ 
17157 \newline 
17158 #pragma noinduction
17159 \begin_inset LatexCommand \index{\#pragma noinduction}
17160
17161 \end_inset 
17162
17163  /* turn off induction optimizations */ 
17164 \newline 
17165 int foo () 
17166 \newline 
17167
17168 \newline 
17169 \SpecialChar ~
17170  \SpecialChar ~
17171  ...
17172  
17173 \newline 
17174 \SpecialChar ~
17175  \SpecialChar ~
17176  /* large code */ 
17177 \newline 
17178 \SpecialChar ~
17179  \SpecialChar ~
17180  ...
17181  
17182 \newline 
17183
17184 \newline 
17185 #pragma restore
17186 \begin_inset LatexCommand \index{\#pragma restore}
17187
17188 \end_inset 
17189
17190  /* turn the optimizations back on */
17191 \layout Standard
17192
17193 The compiler will generate a warning message when extra space is allocated.
17194  It is strongly recommended that the save and restore pragma's be used when
17195  changing options for a function.
17196 \newline 
17197
17198 \newline 
17199
17200 \newline 
17201
17202 \layout Section
17203
17204 Defines Created by the Compiler
17205 \layout Standard
17206
17207 The compiler creates the following #defines
17208 \begin_inset LatexCommand \index{\#defines}
17209
17210 \end_inset 
17211
17212
17213 \begin_inset LatexCommand \index{Defines created by the compiler}
17214
17215 \end_inset 
17216
17217 :
17218 \newline 
17219
17220 \layout Standard
17221
17222
17223 \begin_inset  Tabular
17224 <lyxtabular version="3" rows="11" columns="2">
17225 <features>
17226 <column alignment="left" valignment="top" leftline="true" width="3in">
17227 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17228 <row topline="true" bottomline="true">
17229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17230 \begin_inset Text
17231
17232 \layout Standard
17233
17234
17235 \series bold 
17236 #define
17237 \end_inset 
17238 </cell>
17239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17240 \begin_inset Text
17241
17242 \layout Standard
17243
17244
17245 \series bold 
17246 Description
17247 \end_inset 
17248 </cell>
17249 </row>
17250 <row topline="true">
17251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17252 \begin_inset Text
17253
17254 \layout Standard
17255
17256 SDCC
17257 \begin_inset LatexCommand \index{SDCC}
17258
17259 \end_inset 
17260
17261  
17262 \end_inset 
17263 </cell>
17264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17265 \begin_inset Text
17266
17267 \layout Standard
17268
17269 Always defined.
17270  Since version 2.5.6 the version number as an int (ex.
17271  256)
17272 \end_inset 
17273 </cell>
17274 </row>
17275 <row topline="true">
17276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17277 \begin_inset Text
17278
17279 \layout Standard
17280
17281 SDCC_mcs51
17282 \begin_inset LatexCommand \index{SDCC\_mcs51}
17283
17284 \end_inset 
17285
17286  or SDCC_ds390
17287 \begin_inset LatexCommand \index{SDCC\_ds390}
17288
17289 \end_inset 
17290
17291  or SDCC_z80
17292 \begin_inset LatexCommand \index{SDCC\_z80}
17293
17294 \end_inset 
17295
17296 , etc.
17297 \end_inset 
17298 </cell>
17299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17300 \begin_inset Text
17301
17302 \layout Standard
17303
17304 depending on the model used (e.g.: -mds390)
17305 \end_inset 
17306 </cell>
17307 </row>
17308 <row topline="true">
17309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17310 \begin_inset Text
17311
17312 \layout Standard
17313
17314 __mcs51
17315 \begin_inset LatexCommand \index{\_\_mcs51}
17316
17317 \end_inset 
17318
17319 , __ds390
17320 \begin_inset LatexCommand \index{\_\_ds390}
17321
17322 \end_inset 
17323
17324 , __hc08
17325 \begin_inset LatexCommand \index{\_\_hc08}
17326
17327 \end_inset 
17328
17329 , __z80
17330 \begin_inset LatexCommand \index{\_\_z80}
17331
17332 \end_inset 
17333
17334 , etc
17335 \end_inset 
17336 </cell>
17337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17338 \begin_inset Text
17339
17340 \layout Standard
17341
17342 depending on the model used (e.g.
17343  -mz80)
17344 \end_inset 
17345 </cell>
17346 </row>
17347 <row topline="true">
17348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17349 \begin_inset Text
17350
17351 \layout Standard
17352
17353 SDCC_STACK_AUTO
17354 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17355
17356 \end_inset 
17357
17358
17359 \end_inset 
17360 </cell>
17361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17362 \begin_inset Text
17363
17364 \layout Standard
17365
17366 when 
17367 \emph on 
17368 -
17369 \begin_inset ERT
17370 status Collapsed
17371
17372 \layout Standard
17373
17374 \backslash 
17375 /
17376 \end_inset 
17377
17378 -stack-auto
17379 \emph default 
17380  option is used
17381 \end_inset 
17382 </cell>
17383 </row>
17384 <row topline="true">
17385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17386 \begin_inset Text
17387
17388 \layout Standard
17389
17390 SDCC_MODEL_SMALL
17391 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17392
17393 \end_inset 
17394
17395
17396 \end_inset 
17397 </cell>
17398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17399 \begin_inset Text
17400
17401 \layout Standard
17402
17403 when 
17404 \emph on 
17405 -
17406 \begin_inset ERT
17407 status Collapsed
17408
17409 \layout Standard
17410
17411 \backslash 
17412 /
17413 \end_inset 
17414
17415 -model-small
17416 \emph default 
17417  is used
17418 \end_inset 
17419 </cell>
17420 </row>
17421 <row topline="true">
17422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17423 \begin_inset Text
17424
17425 \layout Standard
17426
17427 SDCC_MODEL_MEDIUM
17428 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17429
17430 \end_inset 
17431
17432
17433 \end_inset 
17434 </cell>
17435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17436 \begin_inset Text
17437
17438 \layout Standard
17439
17440 when 
17441 \emph on 
17442 -
17443 \begin_inset ERT
17444 status Collapsed
17445
17446 \layout Standard
17447
17448 \backslash 
17449 /
17450 \end_inset 
17451
17452 -model-medium
17453 \emph default 
17454  is used
17455 \end_inset 
17456 </cell>
17457 </row>
17458 <row topline="true">
17459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17460 \begin_inset Text
17461
17462 \layout Standard
17463
17464 SDCC_MODEL_LARGE
17465 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17466
17467 \end_inset 
17468
17469
17470 \end_inset 
17471 </cell>
17472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17473 \begin_inset Text
17474
17475 \layout Standard
17476
17477 when 
17478 \emph on 
17479 -
17480 \begin_inset ERT
17481 status Collapsed
17482
17483 \layout Standard
17484
17485 \backslash 
17486 /
17487 \end_inset 
17488
17489 -model-large
17490 \emph default 
17491  is used
17492 \end_inset 
17493 </cell>
17494 </row>
17495 <row topline="true">
17496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17497 \begin_inset Text
17498
17499 \layout Standard
17500
17501 SDCC_USE_XSTACK
17502 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17503
17504 \end_inset 
17505
17506
17507 \end_inset 
17508 </cell>
17509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17510 \begin_inset Text
17511
17512 \layout Standard
17513
17514 when 
17515 \emph on 
17516 -
17517 \begin_inset ERT
17518 status Collapsed
17519
17520 \layout Standard
17521
17522 \backslash 
17523 /
17524 \end_inset 
17525
17526 -xstack
17527 \emph default 
17528  option is used
17529 \end_inset 
17530 </cell>
17531 </row>
17532 <row topline="true">
17533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17534 \begin_inset Text
17535
17536 \layout Standard
17537
17538 SDCC_STACK_TENBIT
17539 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17540
17541 \end_inset 
17542
17543  
17544 \end_inset 
17545 </cell>
17546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17547 \begin_inset Text
17548
17549 \layout Standard
17550
17551 when 
17552 \emph on 
17553 -mds390
17554 \emph default 
17555  is used
17556 \end_inset 
17557 </cell>
17558 </row>
17559 <row topline="true" bottomline="true">
17560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17561 \begin_inset Text
17562
17563 \layout Standard
17564
17565 SDCC_MODEL_FLAT24
17566 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17567
17568 \end_inset 
17569
17570
17571 \end_inset 
17572 </cell>
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17574 \begin_inset Text
17575
17576 \layout Standard
17577
17578 when 
17579 \emph on 
17580 -mds390
17581 \emph default 
17582  is used
17583 \end_inset 
17584 </cell>
17585 </row>
17586 </lyxtabular>
17587
17588 \end_inset 
17589
17590
17591 \layout Chapter
17592
17593 Notes on supported Processors
17594 \layout Section
17595
17596 MCS51 variants
17597 \begin_inset LatexCommand \label{sub:MCS51-variants}
17598
17599 \end_inset 
17600
17601
17602 \begin_inset LatexCommand \index{MCS51 variants}
17603
17604 \end_inset 
17605
17606
17607 \layout Standard
17608
17609 MCS51 processors are available from many vendors and come in many different
17610  flavours.
17611  While they might differ considerably in respect to Special Function Registers
17612  the core MCS51 is usually not modified or is kept compatible.
17613  
17614 \layout Subsection
17615
17616 pdata access by SFR 
17617 \layout Standard
17618
17619 With the upcome of devices with internal xdata and flash memory devices
17620  using port P2
17621 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17622
17623 \end_inset 
17624
17625  as dedicated I/O port is becoming more popular.
17626  Switching the high byte for pdata
17627 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17628
17629 \end_inset 
17630
17631  access which was formerly done by port P2 is then achieved by a Special
17632  Function Register
17633 \begin_inset LatexCommand \index{sfr}
17634
17635 \end_inset 
17636
17637 .
17638  In well-established MCS51 tradition the address of this 
17639 \emph on 
17640 sfr
17641 \emph default 
17642  is where the chip designers decided to put it.
17643  Needless to say that they didn't agree on a common name either.
17644  So that the startup code can correctly initialize xdata variables, you
17645  should define an sfr with the name _XPAGE
17646 \family typewriter 
17647
17648 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17649
17650 \end_inset 
17651
17652
17653 \family default 
17654  at the appropriate location if the default, port P2, is not used for this.
17655  Some examples are:
17656 \layout Verse
17657
17658
17659 \family typewriter 
17660 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17661 \layout Verse
17662
17663
17664 \family typewriter 
17665 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17666 \layout Verse
17667
17668
17669 \family typewriter 
17670 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17671 \layout Standard
17672
17673 For more exotic implementations further customizations may be needed.
17674  See section 
17675 \begin_inset LatexCommand \ref{sub:Startup-Code}
17676
17677 \end_inset 
17678
17679  for other possibilities.
17680 \layout Subsection
17681
17682 Other Features available by SFR
17683 \layout Standard
17684 \added_space_bottom bigskip 
17685 Some MCS51 variants offer features like Double DPTR
17686 \begin_inset LatexCommand \index{DPTR}
17687
17688 \end_inset 
17689
17690 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17691  These are currently not used for the MCS51 port.
17692  If you absolutely need them you can fall back to inline assembly or submit
17693  a patch to SDCC.
17694 \layout Section
17695
17696 DS400 port
17697 \layout Standard
17698 \added_space_bottom bigskip 
17699 The DS80C400
17700 \begin_inset LatexCommand \index{DS80C400}
17701
17702 \end_inset 
17703
17704
17705 \begin_inset LatexCommand \index{DS400}
17706
17707 \end_inset 
17708
17709  microcontroller has a rich set of peripherals.
17710  In its built-in ROM library it includes functions to access some of the
17711  features, among them is a TCP stack with IP4 and IP6 support.
17712  Library headers (currently in beta status) and other files are provided
17713  at 
17714 \size footnotesize 
17715
17716 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17717
17718 \end_inset 
17719
17720 .
17721  
17722 \layout Section
17723
17724 The Z80 and gbz80 port
17725 \layout Standard
17726
17727 SDCC can target both the Zilog Z80
17728 \begin_inset LatexCommand \index{Z80}
17729
17730 \end_inset 
17731
17732  and the Nintendo Gameboy's Z80-like gbz80
17733 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17734
17735 \end_inset 
17736
17737 .
17738  The Z80 port is passed through the same 
17739 \emph on 
17740 regressions tests
17741 \begin_inset LatexCommand \index{Regression test}
17742
17743 \end_inset 
17744
17745
17746 \emph default 
17747  (see section 
17748 \begin_inset LatexCommand \ref{sec:Quality-control}
17749
17750 \end_inset 
17751
17752 ) as the MCS51 and DS390 ports, so floating point support, support for long
17753  variables and bitfield support is fine.
17754  See mailing lists and forums about interrupt routines.
17755 \layout Standard
17756 \added_space_bottom bigskip 
17757 As always, the code is the authoritative reference - see z80/ralloc.c and
17758  z80/gen.c.
17759  The stack
17760 \begin_inset LatexCommand \index{Z80!stack}
17761
17762 \end_inset 
17763
17764  frame is similar to that generated by the IAR Z80 compiler.
17765  IX is used as the base pointer, HL and IY are used as a temporary registers,
17766  and BC and DE are available for holding variables.
17767  Return values
17768 \begin_inset LatexCommand \index{Z80!return value}
17769
17770 \end_inset 
17771
17772  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17773  bytes).
17774  The gbz80 port use the same set of registers for the return values, but
17775  in a different order of significance: E (one byte), DE (two bytes), or
17776  HLDE (four bytes).
17777 \layout Section
17778
17779 The HC08 port
17780 \layout Standard
17781
17782 The port to the Freescale/Motorola HC08
17783 \begin_inset LatexCommand \index{HC08}
17784
17785 \end_inset 
17786
17787  family has been added in October 2003, and is still undergoing some basic
17788  development.
17789  The code generator is complete, but the register allocation is still quite
17790  unoptimized.
17791  Some of the SDCC's standard C library functions have embedded non-HC08
17792  inline assembly and so are not yet usable.
17793 \layout Standard
17794 \added_space_bottom bigskip 
17795 The HC08 port passes the regression test suite (see section 
17796 \begin_inset LatexCommand \ref{sec:Quality-control}
17797
17798 \end_inset 
17799
17800 ).
17801 \layout Section
17802 \pagebreak_top 
17803 The PIC14 port
17804 \layout Standard
17805
17806 The 14bit PIC
17807 \begin_inset LatexCommand \index{PIC14}
17808
17809 \end_inset 
17810
17811  port still requires a major effort from the development community.
17812  However it can work for simple code.
17813  It passes its (smaller set of) regression tests
17814 \begin_inset LatexCommand \index{Regression test (PIC14)}
17815
17816 \end_inset 
17817
17818  in the directory 
17819 \shape italic 
17820 sdcc/src/regression
17821 \shape default 
17822 .
17823 \layout Subsection
17824
17825 C code and 14bit PIC code page
17826 \begin_inset LatexCommand \index{code page (pic14)}
17827
17828 \end_inset 
17829
17830  and RAM banks
17831 \begin_inset LatexCommand \index{RAM bank (pic14)}
17832
17833 \end_inset 
17834
17835
17836 \layout Standard
17837
17838 The linker organizes allocation for the code page and RAM banks.
17839  It does not have intimate knowledge of the code flow.
17840  It will put all the code section of a single asm file into a single code
17841  page.
17842  In order to make use of multiple code pages, separate asm files must be
17843  used.
17844  The compiler treats all functions of a single C file as being in the same
17845  code page unless it is non static.
17846  The compiler treats all local variables of a single C file as being in
17847  the same RAM bank unless it is an extern.
17848 \newline 
17849
17850 \newline 
17851 To get the best follow these guide lines:
17852 \layout Enumerate
17853
17854 make local functions static, as non static functions require code page selection
17855  overhead.
17856 \layout Enumerate
17857
17858 Make local variables static as extern variables require RAM bank selection
17859  overhead.
17860 \layout Enumerate
17861
17862 For devices that have multiple code pages it is more efficient to use the
17863  same number of files as pages, i.e.
17864  for the 16F877 use 4 separate files and i.e.
17865  for the 16F874 use 2 separate files.
17866  This way the linker can put the code for each file into different code
17867  pages and the compiler can allocate reusable variables more efficiently
17868  and there's less page selection overhead.
17869  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17870  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17871 \layout Subsection
17872
17873 Creating a device include file 
17874 \layout Standard
17875
17876 For generating a device include file
17877 \begin_inset LatexCommand \index{PIC14!Header files}
17878
17879 \end_inset 
17880
17881  use the support perl script inc2h.pl kept in directory support/script.
17882 \layout Subsection
17883
17884 Interrupt code
17885 \layout Standard
17886
17887 For the interrupt function, use the keyword 'interrupt'
17888 \begin_inset LatexCommand \index{PIC14!interrupt}
17889
17890 \end_inset 
17891
17892  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17893  there to avoid a syntax error - it ought to be fixed).
17894  E.g.:
17895 \layout Verse
17896
17897
17898 \family typewriter 
17899 void Intr(void) interrupt 0
17900 \newline 
17901 {
17902 \newline 
17903 \SpecialChar ~
17904 \SpecialChar ~
17905 T0IF = 0; /* Clear timer interrupt */
17906 \newline 
17907 }
17908 \layout Subsection
17909
17910 Linking and assembling
17911 \layout Standard
17912
17913 For assembling you can use either GPUTILS'
17914 \begin_inset LatexCommand \index{gputils (pic tools)}
17915
17916 \end_inset 
17917
17918  gpasm.exe or MPLAB's mpasmwin.exe.
17919  GPUTILS is available from 
17920 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17921
17922 \end_inset 
17923
17924 .
17925  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17926  If you use MPLAB and an interrupt function then the linker script file
17927  vectors section will need to be enlarged to link with mplink.
17928 \newline 
17929
17930 \newline 
17931 Here is a 
17932 \family typewriter 
17933 Makefile
17934 \family default 
17935  using GPUTILS:
17936 \layout Verse
17937
17938
17939 \family typewriter 
17940 .c.o:
17941 \newline 
17942 \SpecialChar ~
17943 \SpecialChar ~
17944 \SpecialChar ~
17945 \SpecialChar ~
17946 \SpecialChar ~
17947 \SpecialChar ~
17948 \SpecialChar ~
17949 \SpecialChar ~
17950 sdcc -S -V -mpic14 -p16F877 $< 
17951 \newline 
17952 \SpecialChar ~
17953 \SpecialChar ~
17954 \SpecialChar ~
17955 \SpecialChar ~
17956 \SpecialChar ~
17957 \SpecialChar ~
17958 \SpecialChar ~
17959 \SpecialChar ~
17960 gpasm -c $*.asm
17961 \newline 
17962
17963 \newline 
17964 $(PRJ).hex: $(OBJS) 
17965 \newline 
17966 \SpecialChar ~
17967 \SpecialChar ~
17968 \SpecialChar ~
17969 \SpecialChar ~
17970 \SpecialChar ~
17971 \SpecialChar ~
17972 \SpecialChar ~
17973 \SpecialChar ~
17974 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17975 \layout Standard
17976
17977 Here is a 
17978 \family typewriter 
17979 Makefile
17980 \family default 
17981  using MPLAB:
17982 \layout Verse
17983
17984
17985 \family typewriter 
17986 .c.o: 
17987 \newline 
17988 \SpecialChar ~
17989 \SpecialChar ~
17990 \SpecialChar ~
17991 \SpecialChar ~
17992 \SpecialChar ~
17993 \SpecialChar ~
17994 \SpecialChar ~
17995 \SpecialChar ~
17996 sdcc -S -V -mpic14 -p16F877 $< 
17997 \newline 
17998 \SpecialChar ~
17999 \SpecialChar ~
18000 \SpecialChar ~
18001 \SpecialChar ~
18002 \SpecialChar ~
18003 \SpecialChar ~
18004 \SpecialChar ~
18005 \SpecialChar ~
18006 mpasmwin /q /o $*.asm
18007 \newline 
18008
18009 \newline 
18010 $(PRJ).hex: $(OBJS) 
18011 \newline 
18012 \SpecialChar ~
18013 \SpecialChar ~
18014 \SpecialChar ~
18015 \SpecialChar ~
18016 \SpecialChar ~
18017 \SpecialChar ~
18018 \SpecialChar ~
18019 \SpecialChar ~
18020 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
18021 \layout Standard
18022
18023 Please note that indentations within a
18024 \family typewriter 
18025  Makefile
18026 \family default 
18027  have to be done with a tabulator character.
18028 \layout Subsection
18029
18030 Command-line options
18031 \layout Standard
18032
18033 Besides the switches common to all SDCC backends, the PIC14 port accepts
18034  the following options (for an updated list see sdcc -
18035 \begin_inset ERT
18036 status Collapsed
18037
18038 \layout Standard
18039
18040 \backslash 
18041 /
18042 \end_inset 
18043
18044 -help):
18045 \layout List
18046 \labelwidthstring 00.00.0000
18047
18048 -
18049 \begin_inset ERT
18050 status Collapsed
18051
18052 \layout Standard
18053
18054 \backslash 
18055 /
18056 \end_inset 
18057
18058 -debug-extra
18059 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
18060
18061 \end_inset 
18062
18063  emit debug info in assembly output
18064 \layout List
18065 \labelwidthstring 00.00.0000
18066
18067 -
18068 \begin_inset ERT
18069 status Collapsed
18070
18071 \layout Standard
18072
18073 \backslash 
18074 /
18075 \end_inset 
18076
18077 -no-pcode-opt
18078 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
18079
18080 \end_inset 
18081
18082  disable (slightly faulty) optimization on pCode
18083 \layout Subsection
18084
18085 The library
18086 \layout Subsubsection
18087
18088 error: missing definition for symbol 
18089 \begin_inset Quotes sld
18090 \end_inset 
18091
18092 __gptrget1
18093 \begin_inset Quotes srd
18094 \end_inset 
18095
18096
18097 \layout Standard
18098
18099 The PIC14 port uses library routines to provide more complex operations
18100  like multiplication, division/modulus and (generic) pointer dereferencing.
18101  In order to add these routines to your project, you must link with PIC14's
18102  
18103 \family typewriter 
18104 libsdcc.lib
18105 \family default 
18106 .
18107  For single source file projects this is done automatically, more complex
18108  projects must add 
18109 \family typewriter 
18110 libsdcc.lib
18111 \family default 
18112  to the linker's arguments.
18113  Make sure you also add an include path for the library (using the -I switch
18114  to the linker)!
18115 \layout Subsubsection
18116
18117 Processor mismatch in file 
18118 \begin_inset Quotes sld
18119 \end_inset 
18120
18121 XXX
18122 \begin_inset Quotes srd
18123 \end_inset 
18124
18125 .
18126 \layout Standard
18127
18128 This warning can usually be ignored due to the very good compatibility amongst
18129  14 bit PIC
18130 \begin_inset LatexCommand \index{PIC14}
18131
18132 \end_inset 
18133
18134  devices.
18135 \layout Standard
18136
18137 You might also consider recompiling the library for your specific device
18138  by changing the ARCH=p16f877 (default target) entry in 
18139 \family typewriter 
18140 device/lib/pic/Makefile.in
18141 \family default 
18142  and 
18143 \family typewriter 
18144 device/lib/pic/Makefile
18145 \family default 
18146  to reflect your device.
18147  This might even improve performance for smaller devices as unneccesary
18148  BANKSELs migth be removed.
18149 \layout Subsection
18150
18151 Known bugs
18152 \layout Subsubsection
18153
18154 initialized data
18155 \layout Standard
18156
18157 Currently, data can only be initialized if it resides in the source file
18158  together with 
18159 \emph on 
18160 main()
18161 \emph default 
18162 .
18163  Data in other source files will silently 
18164 \series bold 
18165 not
18166 \series default 
18167  be initialized.
18168 \family typewriter 
18169 \size footnotesize 
18170
18171 \begin_inset Marginal
18172 collapsed true
18173
18174 \layout Standard
18175
18176
18177 \series bold 
18178 \SpecialChar ~
18179 !
18180 \end_inset 
18181
18182
18183 \layout Section
18184 \pagebreak_top 
18185 The PIC16
18186 \begin_inset LatexCommand \index{PIC16}
18187
18188 \end_inset 
18189
18190  port
18191 \layout Standard
18192
18193 The PIC16
18194 \begin_inset LatexCommand \index{PIC16}
18195
18196 \end_inset 
18197
18198  port is the portion of SDCC that is responsible to produce code for the
18199  Microchip
18200 \begin_inset LatexCommand \index{Microchip}
18201
18202 \end_inset 
18203
18204 (TM) microcontrollers with 16 bit core.
18205  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18206  Currently supported devices are:
18207 \layout Standard
18208 \align center 
18209
18210 \begin_inset  Tabular
18211 <lyxtabular version="3" rows="4" columns="6">
18212 <features>
18213 <column alignment="center" valignment="top" leftline="true" width="0">
18214 <column alignment="center" valignment="top" leftline="true" width="0">
18215 <column alignment="center" valignment="top" leftline="true" width="0">
18216 <column alignment="center" valignment="top" leftline="true" width="0">
18217 <column alignment="center" valignment="top" leftline="true" width="0">
18218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18219 <row topline="true">
18220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18221 \begin_inset Text
18222
18223 \layout Standard
18224
18225 18F242
18226 \end_inset 
18227 </cell>
18228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18229 \begin_inset Text
18230
18231 \layout Standard
18232
18233 18F248
18234 \end_inset 
18235 </cell>
18236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18237 \begin_inset Text
18238
18239 \layout Standard
18240
18241 18F252
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 18F258
18250 \end_inset 
18251 </cell>
18252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18253 \begin_inset Text
18254
18255 \layout Standard
18256
18257 18F442
18258 \end_inset 
18259 </cell>
18260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18261 \begin_inset Text
18262
18263 \layout Standard
18264
18265 18F448
18266 \end_inset 
18267 </cell>
18268 </row>
18269 <row topline="true">
18270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18271 \begin_inset Text
18272
18273 \layout Standard
18274
18275 18F452
18276 \end_inset 
18277 </cell>
18278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18279 \begin_inset Text
18280
18281 \layout Standard
18282
18283 18F458
18284 \end_inset 
18285 </cell>
18286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18287 \begin_inset Text
18288
18289 \layout Standard
18290
18291 18F1220
18292 \end_inset 
18293 </cell>
18294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18295 \begin_inset Text
18296
18297 \layout Standard
18298
18299 18F2220
18300 \end_inset 
18301 </cell>
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18303 \begin_inset Text
18304
18305 \layout Standard
18306
18307 18F2550
18308 \end_inset 
18309 </cell>
18310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18311 \begin_inset Text
18312
18313 \layout Standard
18314
18315 18F4331
18316 \end_inset 
18317 </cell>
18318 </row>
18319 <row topline="true">
18320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18321 \begin_inset Text
18322
18323 \layout Standard
18324
18325 18F4455
18326 \end_inset 
18327 </cell>
18328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18329 \begin_inset Text
18330
18331 \layout Standard
18332
18333 18F6520
18334 \end_inset 
18335 </cell>
18336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18337 \begin_inset Text
18338
18339 \layout Standard
18340
18341 18F6620
18342 \end_inset 
18343 </cell>
18344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18345 \begin_inset Text
18346
18347 \layout Standard
18348
18349 18F6680
18350 \end_inset 
18351 </cell>
18352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18353 \begin_inset Text
18354
18355 \layout Standard
18356
18357 18F6720
18358 \end_inset 
18359 </cell>
18360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18361 \begin_inset Text
18362
18363 \layout Standard
18364
18365 18F8520
18366 \end_inset 
18367 </cell>
18368 </row>
18369 <row topline="true" bottomline="true">
18370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18371 \begin_inset Text
18372
18373 \layout Standard
18374
18375 18F8620
18376 \end_inset 
18377 </cell>
18378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18379 \begin_inset Text
18380
18381 \layout Standard
18382
18383 18F8680
18384 \end_inset 
18385 </cell>
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18387 \begin_inset Text
18388
18389 \layout Standard
18390
18391 18F8720
18392 \end_inset 
18393 </cell>
18394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18395 \begin_inset Text
18396
18397 \layout Standard
18398
18399 \end_inset 
18400 </cell>
18401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18402 \begin_inset Text
18403
18404 \layout Standard
18405
18406 \end_inset 
18407 </cell>
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18409 \begin_inset Text
18410
18411 \layout Standard
18412
18413 \end_inset 
18414 </cell>
18415 </row>
18416 </lyxtabular>
18417
18418 \end_inset 
18419
18420
18421 \layout Subsection
18422
18423 Global Options
18424 \layout Standard
18425
18426 PIC16 port supports the standard command line arguments as supposed, with
18427  the exception of certain cases that will be mentioned in the following
18428  list:
18429 \layout List
18430 \labelwidthstring 00.00.0000
18431
18432 -
18433 \begin_inset ERT
18434 status Collapsed
18435
18436 \layout Standard
18437
18438 \backslash 
18439 /
18440 \end_inset 
18441
18442 -callee-saves
18443 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18444
18445 \end_inset 
18446
18447  See -
18448 \begin_inset ERT
18449 status Collapsed
18450
18451 \layout Standard
18452
18453 \backslash 
18454 /
18455 \end_inset 
18456
18457 -all-callee-saves
18458 \layout List
18459 \labelwidthstring 00.00.0000
18460
18461 -
18462 \begin_inset ERT
18463 status Collapsed
18464
18465 \layout Standard
18466
18467 \backslash 
18468 /
18469 \end_inset 
18470
18471 -all-callee-saves
18472 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18473
18474 \end_inset 
18475
18476  All function arguments are passed on stack by default.
18477  
18478 \emph on 
18479 There is no need to specify this in the command line.
18480 \layout List
18481 \labelwidthstring 00.00.0000
18482
18483 -
18484 \begin_inset ERT
18485 status Collapsed
18486
18487 \layout Standard
18488
18489 \backslash 
18490 /
18491 \end_inset 
18492
18493 -fommit-frame-pointer
18494 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18495
18496 \end_inset 
18497
18498  Frame pointer will be omitted when the function uses no local variables.
18499 \layout Subsection
18500
18501 Port Specific Options
18502 \begin_inset LatexCommand \index{Options PIC16}
18503
18504 \end_inset 
18505
18506
18507 \layout Standard
18508
18509 The port specific options appear after the global options in the sdcc --help
18510  output.
18511 \layout Subsubsection
18512
18513 General Options
18514 \layout Standard
18515
18516 General options enable certain port features and optimizations.
18517 \layout List
18518 \labelwidthstring 00.00.0000
18519
18520 -
18521 \begin_inset ERT
18522 status Collapsed
18523
18524 \layout Standard
18525
18526 \backslash 
18527 /
18528 \end_inset 
18529
18530 -stack-model=[model] Used in conjuction with the command above.
18531  Defines the stack model to be used, valid stack models are : 
18532 \begin_deeper 
18533 \layout List
18534 \labelwidthstring 00.00.0000
18535
18536
18537 \emph on 
18538 small
18539 \emph default 
18540  Selects small stack model.
18541  8 bit stack and frame pointers.
18542  Supports 256 bytes stack size.
18543 \layout List
18544 \labelwidthstring 00.00.0000
18545
18546
18547 \emph on 
18548 large
18549 \emph default 
18550  Selects large stack model.
18551  16 bit stack and frame pointers.
18552  Supports 65536 bytes stack size.
18553 \end_deeper 
18554 \layout List
18555 \labelwidthstring 00.00.0000
18556
18557 -
18558 \begin_inset ERT
18559 status Collapsed
18560
18561 \layout Standard
18562
18563 \backslash 
18564 /
18565 \end_inset 
18566
18567 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18568  unitialized data variables with [kword].
18569  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18570 \layout List
18571 \labelwidthstring 00.00.0000
18572
18573 -
18574 \begin_inset ERT
18575 status Collapsed
18576
18577 \layout Standard
18578
18579 \backslash 
18580 /
18581 \end_inset 
18582
18583 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18584  Useful for bootloaders.
18585 \layout List
18586 \labelwidthstring 00.00.0000
18587
18588 -
18589 \begin_inset ERT
18590 status Collapsed
18591
18592 \layout Standard
18593
18594 \backslash 
18595 /
18596 \end_inset 
18597
18598 -asm= sets the full path and name of an external assembler to call.
18599 \layout List
18600 \labelwidthstring 00.00.0000
18601
18602 -
18603 \begin_inset ERT
18604 status Collapsed
18605
18606 \layout Standard
18607
18608 \backslash 
18609 /
18610 \end_inset 
18611
18612 -link= sets the full path and name of an external linker to call.
18613 \layout List
18614 \labelwidthstring 00.00.0000
18615
18616 -
18617 \begin_inset ERT
18618 status Collapsed
18619
18620 \layout Standard
18621
18622 \backslash 
18623 /
18624 \end_inset 
18625
18626 -mplab-comp MPLAB
18627 \begin_inset LatexCommand \index{PIC16!MPLAB}
18628
18629 \end_inset 
18630
18631  compatibility option.
18632  Currently only suppresses special gpasm directives.
18633 \layout Subsubsection
18634
18635 Optimization Options
18636 \layout List
18637 \labelwidthstring 00.00.0000
18638
18639 -
18640 \begin_inset ERT
18641 status Collapsed
18642
18643 \layout Standard
18644
18645 \backslash 
18646 /
18647 \end_inset 
18648
18649 -optimize-goto Try to use (conditional) BRA instead of GOTO
18650 \layout List
18651 \labelwidthstring 00.00.0000
18652
18653 -
18654 \begin_inset ERT
18655 status Collapsed
18656
18657 \layout Standard
18658
18659 \backslash 
18660 /
18661 \end_inset 
18662
18663 -optimize-cmp Try to optimize some compares.
18664 \layout List
18665 \labelwidthstring 00.00.0000
18666
18667 -
18668 \begin_inset ERT
18669 status Collapsed
18670
18671 \layout Standard
18672
18673 \backslash 
18674 /
18675 \end_inset 
18676
18677 -optimize-df Analyze the dataflow of the generated code and improve it.
18678 \layout List
18679 \labelwidthstring 00.00.0000
18680
18681 -
18682 \begin_inset ERT
18683 status Collapsed
18684
18685 \layout Standard
18686
18687 \backslash 
18688 /
18689 \end_inset 
18690
18691 -obanksel=nn Set optimization level for inserting BANKSELs.
18692 \newline 
18693
18694 \begin_deeper 
18695 \layout List
18696 \labelwidthstring 00.00.0000
18697
18698 0 no optimization
18699 \layout List
18700 \labelwidthstring 00.00.0000
18701
18702 1 checks previous used register and if it is the same then does not emit
18703  BANKSEL, accounts only for labels.
18704 \layout List
18705 \labelwidthstring 00.00.0000
18706
18707 2 tries to check the location of (even different) symbols and removes BANKSELs
18708  if they are in the same bank.
18709  
18710 \newline 
18711
18712 \emph on 
18713 Important: There might be problems if the linker script has data sections
18714  across bank borders!
18715 \end_deeper 
18716 \layout Subsubsection
18717
18718 Linking Options
18719 \layout List
18720 \labelwidthstring 00.00.0000
18721
18722 -
18723 \begin_inset ERT
18724 status Collapsed
18725
18726 \layout Standard
18727
18728 \backslash 
18729 /
18730 \end_inset 
18731
18732 -nodefaultlibs do not link default libraries when linking
18733 \layout List
18734 \labelwidthstring 00.00.0000
18735
18736 -
18737 \begin_inset ERT
18738 status Collapsed
18739
18740 \layout Standard
18741
18742 \backslash 
18743 /
18744 \end_inset 
18745
18746 -no-crt Don't link the default run-time modules
18747 \layout List
18748 \labelwidthstring 00.00.0000
18749
18750 -
18751 \begin_inset ERT
18752 status Collapsed
18753
18754 \layout Standard
18755
18756 \backslash 
18757 /
18758 \end_inset 
18759
18760 -use-crt= Use a custom run-time module instead of the defaults.
18761 \layout Subsubsection
18762
18763 Debugging Options
18764 \layout Standard
18765
18766 Debugging options enable extra debugging information in the output files.
18767 \layout List
18768 \labelwidthstring 00.00.0000
18769
18770 -
18771 \begin_inset ERT
18772 status Collapsed
18773
18774 \layout Standard
18775
18776 \backslash 
18777 /
18778 \end_inset 
18779
18780 -debug-xtra Similar to -
18781 \begin_inset ERT
18782 status Collapsed
18783
18784 \layout Standard
18785
18786 \backslash 
18787 /
18788 \end_inset 
18789
18790 -debug
18791 \begin_inset LatexCommand \index{-\/-debug}
18792
18793 \end_inset 
18794
18795 , but dumps more information.
18796 \layout List
18797 \labelwidthstring 00.00.0000
18798
18799 -
18800 \begin_inset ERT
18801 status Collapsed
18802
18803 \layout Standard
18804
18805 \backslash 
18806 /
18807 \end_inset 
18808
18809 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18810  information.
18811  <source> is the name of the file compiled.
18812 \layout List
18813 \labelwidthstring 00.00.0000
18814
18815 -
18816 \begin_inset ERT
18817 status Collapsed
18818
18819 \layout Standard
18820
18821 \backslash 
18822 /
18823 \end_inset 
18824
18825 -pcode-verbose Enable pcode debugging information in translation.
18826 \layout List
18827 \labelwidthstring 00.00.0000
18828
18829 -
18830 \begin_inset ERT
18831 status Collapsed
18832
18833 \layout Standard
18834
18835 \backslash 
18836 /
18837 \end_inset 
18838
18839 -denable-peeps Force the usage of peepholes.
18840  Use with care.
18841 \layout List
18842 \labelwidthstring 00.00.0000
18843
18844 -
18845 \begin_inset ERT
18846 status Collapsed
18847
18848 \layout Standard
18849
18850 \backslash 
18851 /
18852 \end_inset 
18853
18854 -gstack Trace push/pops for stack pointer overflow
18855 \layout List
18856 \labelwidthstring 00.00.0000
18857
18858 -
18859 \begin_inset ERT
18860 status Collapsed
18861
18862 \layout Standard
18863
18864 \backslash 
18865 /
18866 \end_inset 
18867
18868 -call-tree dump call tree in .calltree file
18869 \layout Subsection
18870
18871 Enviromental Variables
18872 \layout Standard
18873
18874 There is a number of enviromental variables that can be used when running
18875  SDCC to enable certain optimizations or force a specific program behaviour.
18876  these variables are primarily for debugging purposes so they can be enabled/dis
18877 abled at will.
18878 \layout Standard
18879
18880 Currently there is only two such variables available:
18881 \layout List
18882 \labelwidthstring 00.00.0000
18883
18884 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18885  bitfields is optimized by directly loading FSR0 with the address of the
18886  bitfield structure.
18887  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18888  then load FSR0.
18889  This step saves data ram and code space for functions that perform heavy
18890  use of bitfields.
18891  (ie.
18892  80 bytes of code space are saved when compiling malloc.c with this option).
18893  
18894 \layout List
18895 \labelwidthstring 00.00.0000
18896
18897 NO_REG_OPT do not perform pCode registers optimization.
18898  This should be used for debugging purposes.
18899  In some where bugs in the pcode optimizer are found, users can benefit
18900  from temporarily disabling the optimizer until the bug is fixed.
18901 \layout Subsection
18902
18903 Preprocessor Macros
18904 \layout Standard
18905
18906 PIC16
18907 \begin_inset LatexCommand \index{PIC16}
18908
18909 \end_inset 
18910
18911  port defines the following preprocessor macros while translating a source.
18912 \layout Standard
18913 \align center 
18914
18915 \begin_inset  Tabular
18916 <lyxtabular version="3" rows="6" columns="2">
18917 <features>
18918 <column alignment="center" valignment="top" leftline="true" width="0">
18919 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18920 <row topline="true" bottomline="true">
18921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18922 \begin_inset Text
18923
18924 \layout Standard
18925
18926 Macro
18927 \end_inset 
18928 </cell>
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18930 \begin_inset Text
18931
18932 \layout Standard
18933
18934 Description
18935 \end_inset 
18936 </cell>
18937 </row>
18938 <row topline="true">
18939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18940 \begin_inset Text
18941
18942 \layout Standard
18943
18944 SDCC_pic16
18945 \end_inset 
18946 </cell>
18947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18948 \begin_inset Text
18949
18950 \layout Standard
18951
18952 Port identification
18953 \end_inset 
18954 </cell>
18955 </row>
18956 <row topline="true">
18957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18958 \begin_inset Text
18959
18960 \layout Standard
18961
18962 _
18963 \begin_inset ERT
18964 status Collapsed
18965
18966 \layout Standard
18967
18968 \backslash 
18969 /
18970 \end_inset 
18971
18972 _pic16
18973 \end_inset 
18974 </cell>
18975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18976 \begin_inset Text
18977
18978 \layout Standard
18979
18980 Port identification (same as above)
18981 \end_inset 
18982 </cell>
18983 </row>
18984 <row topline="true">
18985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18986 \begin_inset Text
18987
18988 \layout Standard
18989
18990 pic18fxxxx
18991 \end_inset 
18992 </cell>
18993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18994 \begin_inset Text
18995
18996 \layout Standard
18997
18998 MCU Identification.
18999  
19000 \emph on 
19001 xxxx
19002 \emph default 
19003  is the microcontrol identification number, i.e.
19004  452, 6620, etc
19005 \end_inset 
19006 </cell>
19007 </row>
19008 <row topline="true">
19009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19010 \begin_inset Text
19011
19012 \layout Standard
19013
19014 _
19015 \begin_inset ERT
19016 status Collapsed
19017
19018 \layout Standard
19019
19020 \backslash 
19021 /
19022 \end_inset 
19023
19024 _18Fxxxx
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 MCU Identification (same as above)
19033 \end_inset 
19034 </cell>
19035 </row>
19036 <row topline="true" bottomline="true">
19037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19038 \begin_inset Text
19039
19040 \layout Standard
19041
19042 STACK_MODEL_nnn
19043 \end_inset 
19044 </cell>
19045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19046 \begin_inset Text
19047
19048 \layout Standard
19049
19050 nnn = SMALL or LARGE respectively according to the stack model used
19051 \end_inset 
19052 </cell>
19053 </row>
19054 </lyxtabular>
19055
19056 \end_inset 
19057
19058
19059 \layout Standard
19060
19061 In addition the following macros are defined when calling assembler:
19062 \layout Standard
19063 \align center 
19064
19065 \begin_inset  Tabular
19066 <lyxtabular version="3" rows="4" columns="2">
19067 <features>
19068 <column alignment="center" valignment="top" leftline="true" width="0">
19069 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19070 <row topline="true" bottomline="true">
19071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19072 \begin_inset Text
19073
19074 \layout Standard
19075
19076 Macro
19077 \end_inset 
19078 </cell>
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19080 \begin_inset Text
19081
19082 \layout Standard
19083
19084 Description
19085 \end_inset 
19086 </cell>
19087 </row>
19088 <row topline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19090 \begin_inset Text
19091
19092 \layout Standard
19093
19094 __18Fxxxx
19095 \end_inset 
19096 </cell>
19097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19098 \begin_inset Text
19099
19100 \layout Standard
19101
19102 MCU Identification.
19103  
19104 \emph on 
19105 xxxx
19106 \emph default 
19107  is the microcontrol identification number, i.e.
19108  452, 6620, etc
19109 \end_inset 
19110 </cell>
19111 </row>
19112 <row topline="true">
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19114 \begin_inset Text
19115
19116 \layout Standard
19117
19118 SDCC_MODEL_nnn
19119 \end_inset 
19120 </cell>
19121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19122 \begin_inset Text
19123
19124 \layout Standard
19125
19126 nnn = SMALL or LARGE respectively according to the memory model used for
19127  SDCC
19128 \end_inset 
19129 </cell>
19130 </row>
19131 <row topline="true" bottomline="true">
19132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19133 \begin_inset Text
19134
19135 \layout Standard
19136
19137 STACK_MODEL_nnn
19138 \end_inset 
19139 </cell>
19140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19141 \begin_inset Text
19142
19143 \layout Standard
19144
19145 nnn = SMALL or LARGE respectively according to the stack model used
19146 \end_inset 
19147 </cell>
19148 </row>
19149 </lyxtabular>
19150
19151 \end_inset 
19152
19153
19154 \layout Subsection
19155
19156 Directories
19157 \layout Standard
19158
19159 PIC16
19160 \begin_inset LatexCommand \index{PIC16}
19161
19162 \end_inset 
19163
19164  port uses the following directories for searching header files and libraries.
19165 \layout Standard
19166 \align center 
19167
19168 \begin_inset  Tabular
19169 <lyxtabular version="3" rows="3" columns="4">
19170 <features>
19171 <column alignment="center" valignment="top" leftline="true" width="0">
19172 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19173 <column alignment="center" valignment="top" width="0">
19174 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19175 <row topline="true" bottomline="true">
19176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19177 \begin_inset Text
19178
19179 \layout Standard
19180
19181 Directory
19182 \end_inset 
19183 </cell>
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19185 \begin_inset Text
19186
19187 \layout Standard
19188
19189 Description
19190 \end_inset 
19191 </cell>
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19193 \begin_inset Text
19194
19195 \layout Standard
19196
19197 Target
19198 \end_inset 
19199 </cell>
19200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19201 \begin_inset Text
19202
19203 \layout Standard
19204
19205 Command prefix
19206 \end_inset 
19207 </cell>
19208 </row>
19209 <row topline="true">
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19211 \begin_inset Text
19212
19213 \layout Standard
19214
19215 PREFIX/sdcc/include/pic16
19216 \end_inset 
19217 </cell>
19218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19219 \begin_inset Text
19220
19221 \layout Standard
19222
19223 PIC16 specific headers
19224 \end_inset 
19225 </cell>
19226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19227 \begin_inset Text
19228
19229 \layout Standard
19230
19231 Compiler
19232 \end_inset 
19233 </cell>
19234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19235 \begin_inset Text
19236
19237 \layout Standard
19238
19239 -I
19240 \end_inset 
19241 </cell>
19242 </row>
19243 <row topline="true" bottomline="true">
19244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19245 \begin_inset Text
19246
19247 \layout Standard
19248
19249 PREFIX/sdcc/lib/pic16
19250 \end_inset 
19251 </cell>
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19253 \begin_inset Text
19254
19255 \layout Standard
19256
19257 PIC16 specific libraries
19258 \end_inset 
19259 </cell>
19260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19261 \begin_inset Text
19262
19263 \layout Standard
19264
19265 Linker
19266 \end_inset 
19267 </cell>
19268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19269 \begin_inset Text
19270
19271 \layout Standard
19272
19273 -L
19274 \end_inset 
19275 </cell>
19276 </row>
19277 </lyxtabular>
19278
19279 \end_inset 
19280
19281
19282 \layout Subsection
19283
19284 Pragmas
19285 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19286
19287 \end_inset 
19288
19289
19290 \layout Standard
19291
19292 PIC16
19293 \begin_inset LatexCommand \index{PIC16}
19294
19295 \end_inset 
19296
19297  port currently supports the following pragmas:
19298 \layout List
19299 \labelwidthstring 00.00.0000
19300
19301 stack
19302 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19303
19304 \end_inset 
19305
19306  pragma stack
19307 \begin_inset LatexCommand \index{PIC16!stack}
19308
19309 \end_inset 
19310
19311  forces the code generator to initialize the stack & frame pointers at a
19312  specific address.
19313  This is an adhoc solution for cases where no STACK directive is available
19314  in the linker script or gplink is not instructed to create a stack section.
19315 \newline 
19316 The stack pragma should be used only once in a project.
19317  Multiple pragmas may result in indeterminate behaviour of the program.
19318 \begin_inset Foot
19319 collapsed false
19320
19321 \layout Standard
19322
19323 The old format (ie.
19324  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19325  cross page boundaries (or even exceed the available data RAM) and crash
19326  the program.
19327  Make sure that stack does not cross page boundaries when using the SMALL
19328  stack model.
19329 \end_inset 
19330
19331
19332 \newline 
19333 The format is as follows:
19334 \layout LyX-Code
19335
19336 #pragma stack bottom_address [stack_size]
19337 \layout Standard
19338
19339
19340 \emph on 
19341 bottom_address
19342 \emph default 
19343  is the lower bound of the stack section.
19344  The stack pointer initially will point at address (bottom_address+stack_size-1).
19345 \layout LyX-Code
19346
19347 Example:
19348 \layout LyX-Code
19349
19350 \layout LyX-Code
19351
19352 /* initializes stack of 100 bytes at RAM address 0x200 */
19353 \layout LyX-Code
19354
19355 #pragma stack 0x200 100
19356 \layout Standard
19357
19358 If the stack_size field is omitted then a stack is created with the default
19359  size of 64.
19360  This size might be enough for most programs, but its not enough for operations
19361  with deep function nesting or excessive stack usage.
19362 \layout List
19363 \labelwidthstring 00.00.0000
19364
19365 code
19366 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19367
19368 \end_inset 
19369
19370  place a function symbol at static FLASH address
19371 \layout LyX-Code
19372
19373 Example:
19374 \layout LyX-Code
19375
19376 \layout LyX-Code
19377
19378 /* place function test_func at 0x4000 */
19379 \layout LyX-Code
19380
19381 #pragma code test_func 0x4000
19382 \layout LyX-Code
19383
19384 \layout List
19385 \labelwidthstring 00.00.0000
19386
19387 library instructs the linker to use a library module.
19388 \newline 
19389 Usage:
19390 \layout LyX-Code
19391
19392 #pragma library module_name
19393 \layout Standard
19394
19395
19396 \emph on 
19397 module_name
19398 \emph default 
19399  can be any library or object file (including its path).
19400  Note that there are four reserved keywords which have special meaning.
19401  These are:
19402 \layout Standard
19403 \align center 
19404
19405 \begin_inset  Tabular
19406 <lyxtabular version="3" rows="6" columns="3">
19407 <features>
19408 <column alignment="center" valignment="top" leftline="true" width="0">
19409 <column alignment="block" valignment="top" leftline="true" width="20page%">
19410 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19411 <row topline="true" bottomline="true">
19412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19413 \begin_inset Text
19414
19415 \layout Standard
19416
19417 Keyword
19418 \end_inset 
19419 </cell>
19420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19421 \begin_inset Text
19422
19423 \layout Standard
19424
19425 Description
19426 \end_inset 
19427 </cell>
19428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19429 \begin_inset Text
19430
19431 \layout Standard
19432
19433 Module to link
19434 \end_inset 
19435 </cell>
19436 </row>
19437 <row topline="true">
19438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19439 \begin_inset Text
19440
19441 \layout Standard
19442
19443
19444 \series bold 
19445 ignore
19446 \end_inset 
19447 </cell>
19448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19449 \begin_inset Text
19450
19451 \layout Standard
19452
19453 ignore all library pragmas
19454 \end_inset 
19455 </cell>
19456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19457 \begin_inset Text
19458
19459 \layout Standard
19460
19461
19462 \emph on 
19463 (none)
19464 \end_inset 
19465 </cell>
19466 </row>
19467 <row topline="true">
19468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19469 \begin_inset Text
19470
19471 \layout Standard
19472
19473
19474 \series bold 
19475 c
19476 \end_inset 
19477 </cell>
19478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19479 \begin_inset Text
19480
19481 \layout Standard
19482
19483 link the C library
19484 \end_inset 
19485 </cell>
19486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19487 \begin_inset Text
19488
19489 \layout Standard
19490
19491
19492 \emph on 
19493 libc18f
19494 \emph default 
19495 .lib
19496 \end_inset 
19497 </cell>
19498 </row>
19499 <row topline="true">
19500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 \begin_inset Text
19502
19503 \layout Standard
19504
19505
19506 \series bold 
19507 math
19508 \end_inset 
19509 </cell>
19510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19511 \begin_inset Text
19512
19513 \layout Standard
19514
19515 link the Math libarary
19516 \end_inset 
19517 </cell>
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19519 \begin_inset Text
19520
19521 \layout Standard
19522
19523
19524 \emph on 
19525 libm18f
19526 \emph default 
19527 .lib
19528 \end_inset 
19529 </cell>
19530 </row>
19531 <row topline="true">
19532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19533 \begin_inset Text
19534
19535 \layout Standard
19536
19537
19538 \series bold 
19539 io
19540 \end_inset 
19541 </cell>
19542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19543 \begin_inset Text
19544
19545 \layout Standard
19546
19547 link the I/O library
19548 \end_inset 
19549 </cell>
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19551 \begin_inset Text
19552
19553 \layout Standard
19554
19555
19556 \emph on 
19557 libio18f*
19558 \emph default 
19559 .lib
19560 \end_inset 
19561 </cell>
19562 </row>
19563 <row topline="true" bottomline="true">
19564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19565 \begin_inset Text
19566
19567 \layout Standard
19568
19569
19570 \series bold 
19571 debug
19572 \end_inset 
19573 </cell>
19574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19575 \begin_inset Text
19576
19577 \layout Standard
19578
19579 link the debug library
19580 \end_inset 
19581 </cell>
19582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19583 \begin_inset Text
19584
19585 \layout Standard
19586
19587
19588 \emph on 
19589 libdebug
19590 \emph default 
19591 .lib
19592 \end_inset 
19593 </cell>
19594 </row>
19595 </lyxtabular>
19596
19597 \end_inset 
19598
19599
19600 \newline 
19601 * is the device number, i.e.
19602  452 for PIC18F452 MCU.
19603 \layout Standard
19604
19605 This feature allows for linking with specific libraries withoug having to
19606  explicit name them in the command line.
19607  Note that the 
19608 \noun on 
19609 ignore
19610 \noun default 
19611  keyword will reject all modules specified by the library pragma.
19612 \layout List
19613 \labelwidthstring 00.00.0000
19614
19615 udata pragma udata instructs the compiler to emit code so that linker will
19616  place a variable at a specific memory bank
19617 \layout LyX-Code
19618
19619 Example:
19620 \layout LyX-Code
19621
19622 \layout LyX-Code
19623
19624 /* places variable foo at bank2 */
19625 \layout LyX-Code
19626
19627 #pragma udata bank2 foo
19628 \layout LyX-Code
19629
19630 char foo;
19631 \layout Standard
19632
19633 In order for this pragma to work extra SECTION directives should be added
19634  in the .lkr script.
19635  In the following example a sample .lkr file is shown:
19636 \layout LyX-Code
19637
19638 \layout LyX-Code
19639
19640 // Sample linker script for the PIC18F452 processor
19641 \layout LyX-Code
19642
19643 LIBPATH .
19644 \layout LyX-Code
19645
19646 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19647 \layout LyX-Code
19648
19649 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19650 \layout LyX-Code
19651
19652 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19653 \layout LyX-Code
19654
19655 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19656 \layout LyX-Code
19657
19658 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19659 \layout LyX-Code
19660
19661 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19662 \layout LyX-Code
19663
19664 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19665 \layout LyX-Code
19666
19667 \layout LyX-Code
19668
19669 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19670 \layout LyX-Code
19671
19672 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19673 \layout LyX-Code
19674
19675 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19676 \layout LyX-Code
19677
19678 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19679 \layout LyX-Code
19680
19681 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19682 \layout LyX-Code
19683
19684 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19685 \layout LyX-Code
19686
19687 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19688 \layout LyX-Code
19689
19690 \layout LyX-Code
19691
19692 SECTION    NAME=CONFIG     ROM=config
19693 \layout LyX-Code
19694
19695 \layout LyX-Code
19696
19697 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19698 \layout LyX-Code
19699
19700 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19701 \layout LyX-Code
19702
19703 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19704 \layout LyX-Code
19705
19706 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19707 \layout LyX-Code
19708
19709 SECTION    NAME=bank4      RAM=gpr4
19710 \layout LyX-Code
19711
19712 SECTION    NAME=bank5      RAM=gpr5
19713 \layout Standard
19714
19715 The linker will recognise the section name set in the pragma statement and
19716  will position the variable at the memory bank set with the RAM field at
19717  the SECTION line in the linker script file.
19718 \layout Subsection
19719
19720 Header Files
19721 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19722
19723 \end_inset 
19724
19725
19726 \layout Standard
19727
19728 There is one main header file
19729 \begin_inset LatexCommand \index{PIC16!Header files}
19730
19731 \end_inset 
19732
19733  that can be included to the source files using the pic16
19734 \begin_inset LatexCommand \index{PIC16}
19735
19736 \end_inset 
19737
19738  port.
19739  That file is the 
19740 \series bold 
19741 pic18fregs.h
19742 \series default 
19743 .
19744  This header file contains the definitions for the processor special registers,
19745  so it is necessary if the source accesses them.
19746  It can be included by adding the following line in the beginning of the
19747  file:
19748 \layout LyX-Code
19749
19750 #include <pic18fregs.h>
19751 \layout Standard
19752
19753 The specific microcontroller is selected within the pic18fregs.h automatically,
19754  so the same source can be used with a variety of devices.
19755 \layout Subsection
19756
19757 Libraries
19758 \layout Standard
19759
19760 The libraries
19761 \begin_inset LatexCommand \index{PIC16!Libraries}
19762
19763 \end_inset 
19764
19765  that PIC16
19766 \begin_inset LatexCommand \index{PIC16}
19767
19768 \end_inset 
19769
19770  port depends on are the microcontroller device libraries which contain
19771  the symbol definitions for the microcontroller special function registers.
19772  These libraries have the format pic18fxxxx.lib, where 
19773 \emph on 
19774 xxxx
19775 \emph default 
19776  is the microcontroller identification number.
19777  The specific library is selected automatically by the compiler at link
19778  stage according to the selected device.
19779 \layout Standard
19780
19781 Libraries are created with gplib which is part of the gputils package 
19782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19783
19784 \end_inset 
19785
19786 .
19787 \layout Subsubsection*
19788
19789 Building the libraries
19790 \layout Standard
19791
19792 Before using SDCC/pic16 there are some libraries that need to be compiled.
19793  This process is not done automatically by SDCC since not all users use
19794  SDCC for pic16 projects.
19795  So each user should compile the libraries separately.
19796 \layout Standard
19797
19798 The steps to compile the pic16 libraries under Linux are:
19799 \layout LyX-Code
19800
19801 cd device/lib/pic16
19802 \layout LyX-Code
19803
19804 ./configure
19805 \layout LyX-Code
19806
19807 make
19808 \layout LyX-Code
19809
19810 cd ..
19811 \layout LyX-Code
19812
19813 make model-pic16
19814 \layout LyX-Code
19815
19816 su -c 'make install'     # install the libraries, you need the root password
19817 \layout Standard
19818
19819 If you need to install the headers too, do:
19820 \layout LyX-Code
19821
19822 cd device/include
19823 \layout LyX-Code
19824
19825 su -c 'make install'     # install the headers, you need the root password
19826 \layout Standard
19827
19828 There exist a special target to build the I/O libraries.
19829  This target is not automatically build because it will build the I/O library
19830  for 
19831 \emph on 
19832 every
19833 \emph default 
19834  supported device.
19835  This way building will take quite a lot of time.
19836  Users are advised to edit the 
19837 \series bold 
19838 device/lib/pic16/pics.build
19839 \series default 
19840  file and then execute:
19841 \layout LyX-Code
19842
19843 make lib-io
19844 \layout Subsection
19845
19846 Memory Models
19847 \layout Standard
19848
19849 The following memory models are supported by the PIC16 port:
19850 \layout Itemize
19851
19852 small model
19853 \layout Itemize
19854
19855 large model
19856 \layout Standard
19857
19858 Memory model affects the default size of pointers within the source.
19859  The sizes are shown in the next table:
19860 \layout Standard
19861 \align center 
19862
19863 \begin_inset  Tabular
19864 <lyxtabular version="3" rows="3" columns="3">
19865 <features>
19866 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19867 <column alignment="center" valignment="top" leftline="true" width="0">
19868 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19869 <row topline="true" bottomline="true">
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19871 \begin_inset Text
19872
19873 \layout Standard
19874
19875 Pointer sizes according to memory model
19876 \end_inset 
19877 </cell>
19878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19879 \begin_inset Text
19880
19881 \layout Standard
19882
19883 small model
19884 \end_inset 
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \layout Standard
19890
19891 large model
19892 \end_inset 
19893 </cell>
19894 </row>
19895 <row topline="true" bottomline="true">
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \layout Standard
19900
19901 code pointers
19902 \end_inset 
19903 </cell>
19904 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19905 \begin_inset Text
19906
19907 \layout Standard
19908
19909 16-bits
19910 \end_inset 
19911 </cell>
19912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19913 \begin_inset Text
19914
19915 \layout Standard
19916
19917 24-bits
19918 \end_inset 
19919 </cell>
19920 </row>
19921 <row topline="true" bottomline="true">
19922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19923 \begin_inset Text
19924
19925 \layout Standard
19926
19927 data pointers
19928 \end_inset 
19929 </cell>
19930 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19931 \begin_inset Text
19932
19933 \layout Standard
19934
19935 16-bits
19936 \end_inset 
19937 </cell>
19938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19939 \begin_inset Text
19940
19941 \layout Standard
19942
19943 16-bits
19944 \end_inset 
19945 </cell>
19946 </row>
19947 </lyxtabular>
19948
19949 \end_inset 
19950
19951
19952 \layout Standard
19953
19954 It is advisable that all sources within a project are compiled with the
19955  same memory model.
19956  If one wants to override the default memory model, this can be done by
19957  declaring a pointer as 
19958 \series bold 
19959 far
19960 \series default 
19961  or 
19962 \series bold 
19963 near
19964 \series default 
19965 .
19966  Far selects large memory model's pointers, while near selects small memory
19967  model's pointers.
19968 \layout Standard
19969
19970 The standard device libraries (see 
19971 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19972
19973 \end_inset 
19974
19975 ) contain no reference to pointers, so they can be used with both memory
19976  models.
19977 \layout Subsection
19978
19979 Stack
19980 \layout Standard
19981
19982 The stack
19983 \begin_inset LatexCommand \index{PIC16!stack}
19984
19985 \end_inset 
19986
19987  implementation for the PIC16 port uses two indirect registers, FSR1 and
19988  FSR2.
19989 \layout List
19990 \labelwidthstring 00.00.0000
19991
19992 FSR1 is assigned as stack pointer
19993 \layout List
19994 \labelwidthstring 00.00.0000
19995
19996 FSR2 is assigned as frame pointer
19997 \layout Standard
19998
19999 The following stack models are supported by the PIC16 port
20000 \layout Itemize
20001
20002
20003 \noun on 
20004 small
20005 \noun default 
20006  model
20007 \layout Itemize
20008
20009
20010 \noun on 
20011 large
20012 \noun default 
20013  model
20014 \layout Standard
20015
20016
20017 \noun on 
20018 Small
20019 \noun default 
20020  model means that only the FSRxL byte is used to access stack and frame,
20021  while 
20022 \emph on 
20023 \noun on 
20024 large
20025 \emph default 
20026 \noun default 
20027  uses both FSRxL and FSRxH registers.
20028  The following table shows the stack/frame pointers sizes according to stack
20029  model and the maximum space they can address:
20030 \layout Standard
20031 \align center 
20032
20033 \begin_inset  Tabular
20034 <lyxtabular version="3" rows="3" columns="3">
20035 <features>
20036 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20037 <column alignment="center" valignment="top" leftline="true" width="0">
20038 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20039 <row topline="true" bottomline="true">
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20041 \begin_inset Text
20042
20043 \layout Standard
20044
20045 Stack & Frame pointer sizes according to stack model
20046 \end_inset 
20047 </cell>
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20049 \begin_inset Text
20050
20051 \layout Standard
20052
20053 small
20054 \end_inset 
20055 </cell>
20056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20057 \begin_inset Text
20058
20059 \layout Standard
20060
20061 large
20062 \end_inset 
20063 </cell>
20064 </row>
20065 <row topline="true">
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20067 \begin_inset Text
20068
20069 \layout Standard
20070
20071 Stack pointer FSR1
20072 \end_inset 
20073 </cell>
20074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20075 \begin_inset Text
20076
20077 \layout Standard
20078
20079 8-bits
20080 \end_inset 
20081 </cell>
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20083 \begin_inset Text
20084
20085 \layout Standard
20086
20087 16-bits
20088 \end_inset 
20089 </cell>
20090 </row>
20091 <row topline="true" bottomline="true">
20092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20093 \begin_inset Text
20094
20095 \layout Standard
20096
20097 Frame pointer FSR2
20098 \end_inset 
20099 </cell>
20100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20101 \begin_inset Text
20102
20103 \layout Standard
20104
20105 8-bits
20106 \end_inset 
20107 </cell>
20108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_inset Text
20110
20111 \layout Standard
20112
20113 16-bits
20114 \end_inset 
20115 </cell>
20116 </row>
20117 </lyxtabular>
20118
20119 \end_inset 
20120
20121
20122 \layout Standard
20123
20124
20125 \noun on 
20126 Large 
20127 \noun default 
20128 stack model is currently not working properly throughout the code generator.
20129  So its use is not advised.
20130  Also there are some other points that need special care:
20131 \newline 
20132
20133 \layout Enumerate
20134
20135 Do not create stack sections with size more than one physical bank (that
20136  is 256 bytes)
20137 \layout Enumerate
20138
20139 Stack sections should no cross physical bank limits (i.e.
20140  #pragma stack 0x50 0x100)
20141 \layout Standard
20142
20143 These limitations are caused by the fact that only FSRxL is modified when
20144  using SMALL stack model, so no more than 256 bytes of stack can be used.
20145  This problem will disappear after LARGE model is fully implemented.
20146 \layout Subsection
20147
20148 Functions
20149 \layout Standard
20150
20151 In addition to the standard SDCC function keywords, PIC16
20152 \begin_inset LatexCommand \index{PIC16}
20153
20154 \end_inset 
20155
20156  port makes available two more:
20157 \layout List
20158 \labelwidthstring 00.00.0000
20159
20160 wparam
20161 \begin_inset LatexCommand \index{PIC16!wparam}
20162
20163 \end_inset 
20164
20165  Use the WREG to pass one byte of the first function argument.
20166  This improves speed but you may not use this for functions with arguments
20167  that are called via function pointers, otherwise the first byte of the
20168  first parameter will get lost.
20169  Usage:
20170 \layout LyX-Code
20171
20172 void func_wparam(int a) wparam
20173 \layout LyX-Code
20174
20175 {
20176 \layout LyX-Code
20177
20178     /* WREG hold the lower part of a */
20179 \layout LyX-Code
20180
20181     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20182  */
20183 \layout LyX-Code
20184
20185 ...
20186 \layout LyX-Code
20187
20188 }
20189 \layout List
20190 \labelwidthstring 00.00.0000
20191
20192 shadowregs
20193 \begin_inset LatexCommand \index{PIC16!shadowregs}
20194
20195 \end_inset 
20196
20197  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20198  hardware shadow registers which hold the values of WREG, STATUS and BSR
20199  registers.
20200  This can be done by adding the keyword 
20201 \emph on 
20202 shadowregs
20203 \emph default 
20204  before the 
20205 \emph on 
20206 interrupt
20207 \emph default 
20208  keyword in the function's header.
20209 \layout LyX-Code
20210
20211 void isr_shadow(void) shadowregs interrupt 1
20212 \layout LyX-Code
20213
20214 {
20215 \layout LyX-Code
20216
20217 ...
20218 \layout LyX-Code
20219
20220 }
20221 \layout Standard
20222
20223
20224 \emph on 
20225 shadowregs
20226 \emph default 
20227  instructs the code generator not to store/restore WREG, STATUS, BSR when
20228  entering/exiting the ISR.
20229 \layout Subsection
20230
20231 Function return values
20232 \layout Standard
20233
20234 Return values from functions are placed to the appropriate registers following
20235  a modified Microchip policy optimized for SDCC.
20236  The following table shows these registers:
20237 \layout Standard
20238 \align center 
20239
20240 \begin_inset  Tabular
20241 <lyxtabular version="3" rows="6" columns="2">
20242 <features>
20243 <column alignment="center" valignment="top" leftline="true" width="0">
20244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20245 <row topline="true" bottomline="true">
20246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20247 \begin_inset Text
20248
20249 \layout Standard
20250
20251 size
20252 \end_inset 
20253 </cell>
20254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20255 \begin_inset Text
20256
20257 \layout Standard
20258
20259 destination register
20260 \end_inset 
20261 </cell>
20262 </row>
20263 <row topline="true">
20264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20265 \begin_inset Text
20266
20267 \layout Standard
20268
20269 8 bits
20270 \end_inset 
20271 </cell>
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20273 \begin_inset Text
20274
20275 \layout Standard
20276
20277 WREG
20278 \end_inset 
20279 </cell>
20280 </row>
20281 <row topline="true">
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20283 \begin_inset Text
20284
20285 \layout Standard
20286
20287 16 bits
20288 \end_inset 
20289 </cell>
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20291 \begin_inset Text
20292
20293 \layout Standard
20294
20295 PRODL:WREG
20296 \end_inset 
20297 </cell>
20298 </row>
20299 <row topline="true">
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \layout Standard
20304
20305 24 bits
20306 \end_inset 
20307 </cell>
20308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20309 \begin_inset Text
20310
20311 \layout Standard
20312
20313 PRODH:PRODL:WREG
20314 \end_inset 
20315 </cell>
20316 </row>
20317 <row topline="true">
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \layout Standard
20322
20323 32 bits
20324 \end_inset 
20325 </cell>
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20327 \begin_inset Text
20328
20329 \layout Standard
20330
20331 FSR0L:PRODH:PRODL:WREG
20332 \end_inset 
20333 </cell>
20334 </row>
20335 <row topline="true" bottomline="true">
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20337 \begin_inset Text
20338
20339 \layout Standard
20340
20341 >32 bits
20342 \end_inset 
20343 </cell>
20344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20345 \begin_inset Text
20346
20347 \layout Standard
20348
20349 on stack, FSR0 points to the beginning
20350 \end_inset 
20351 </cell>
20352 </row>
20353 </lyxtabular>
20354
20355 \end_inset 
20356
20357
20358 \layout Subsection
20359
20360 Interrupts
20361 \layout Standard
20362
20363 An interrupt
20364 \begin_inset LatexCommand \index{PIC16!interrupt}
20365
20366 \end_inset 
20367
20368  service routine (ISR) is declared using the 
20369 \emph on 
20370 interrupt
20371 \emph default 
20372  keyword.
20373 \layout LyX-Code
20374
20375 void isr(void) interrupt 
20376 \emph on 
20377 n
20378 \layout LyX-Code
20379
20380 {
20381 \layout LyX-Code
20382
20383 ...
20384 \layout LyX-Code
20385
20386 }
20387 \layout Standard
20388
20389
20390 \emph on 
20391 n
20392 \emph default 
20393  is the interrupt number, which for PIC18F devices can be:
20394 \layout Standard
20395 \align center 
20396
20397 \begin_inset  Tabular
20398 <lyxtabular version="3" rows="4" columns="3">
20399 <features>
20400 <column alignment="center" valignment="top" leftline="true" width="0">
20401 <column alignment="center" valignment="top" leftline="true" width="0">
20402 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20403 <row topline="true" bottomline="true">
20404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20405 \begin_inset Text
20406
20407 \layout Standard
20408
20409
20410 \emph on 
20411 n
20412 \end_inset 
20413 </cell>
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20415 \begin_inset Text
20416
20417 \layout Standard
20418
20419 Interrupt Vector
20420 \end_inset 
20421 </cell>
20422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20423 \begin_inset Text
20424
20425 \layout Standard
20426
20427 Interrupt Vector Address
20428 \end_inset 
20429 </cell>
20430 </row>
20431 <row topline="true">
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20433 \begin_inset Text
20434
20435 \layout Standard
20436
20437 0
20438 \end_inset 
20439 </cell>
20440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20441 \begin_inset Text
20442
20443 \layout Standard
20444
20445 RESET vector
20446 \end_inset 
20447 </cell>
20448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20449 \begin_inset Text
20450
20451 \layout Standard
20452
20453 0x000000
20454 \end_inset 
20455 </cell>
20456 </row>
20457 <row topline="true">
20458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20459 \begin_inset Text
20460
20461 \layout Standard
20462
20463
20464 \family roman 
20465 \series medium 
20466 \shape up 
20467 \size normal 
20468 \emph off 
20469 \bar no 
20470 \noun off 
20471 \color none
20472 1
20473 \end_inset 
20474 </cell>
20475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20476 \begin_inset Text
20477
20478 \layout Standard
20479
20480
20481 \family roman 
20482 \series medium 
20483 \shape up 
20484 \size normal 
20485 \emph off 
20486 \bar no 
20487 \noun off 
20488 \color none
20489 HIGH priority interrupts
20490 \end_inset 
20491 </cell>
20492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20493 \begin_inset Text
20494
20495 \layout Standard
20496
20497 0x000008
20498 \end_inset 
20499 </cell>
20500 </row>
20501 <row topline="true" bottomline="true">
20502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20503 \begin_inset Text
20504
20505 \layout Standard
20506
20507 2
20508 \end_inset 
20509 </cell>
20510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20511 \begin_inset Text
20512
20513 \layout Standard
20514
20515 LOW priority interrupts
20516 \end_inset 
20517 </cell>
20518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20519 \begin_inset Text
20520
20521 \layout Standard
20522
20523 0x000018
20524 \end_inset 
20525 </cell>
20526 </row>
20527 </lyxtabular>
20528
20529 \end_inset 
20530
20531
20532 \layout Standard
20533
20534 When generating assembly code for ISR the code generator places a 
20535 \noun on 
20536 goto 
20537 \noun default 
20538 instruction at the 
20539 \emph on 
20540 Interrupt Vector Address
20541 \emph default 
20542  which points at the genetated ISR.
20543  This single GOTO instruction is part of an automatically generated 
20544 \emph on 
20545 interrupt entry point
20546 \emph default 
20547  function.
20548  The actuall ISR code is placed as normally would in the code space.
20549  Upon interrupt request, the GOTO instruction is executed which jumps to
20550  the ISR code.
20551  When declaring interrupt functions as _naked this GOTO instruction is 
20552 \series bold 
20553 not
20554 \series default 
20555  generated.
20556  The whole interrupt functions is therefore placed at the Interrupt Vector
20557  Address of the specific interrupt.
20558  This is not a problem for the LOW priority interrupts, but it is a problem
20559  for the RESET and the HIGH priority interrupts because code may be written
20560  at the next interrupt´s vector address and cause undeterminate program
20561  behaviour if that interrupt is raised.
20562 \begin_inset Foot
20563 collapsed false
20564
20565 \layout Standard
20566
20567 This is not a problem when
20568 \layout Enumerate
20569
20570 this is a HIGH interrupt ISR and LOW interrupts are 
20571 \emph on 
20572 disabled
20573 \emph default 
20574  or not used.
20575 \layout Enumerate
20576
20577 when the ISR is small enough not to reach the next interrupt´s vector address.
20578 \end_inset 
20579
20580
20581 \layout Standard
20582
20583
20584 \emph on 
20585 n
20586 \emph default 
20587  is possible to be omitted.
20588  This way a function is generated similar to an ISR, but it is not assigned
20589  to any interrupt.
20590 \layout Standard
20591
20592 When entering an interrupt, currently the PIC16
20593 \begin_inset LatexCommand \index{PIC16}
20594
20595 \end_inset 
20596
20597  port automatically saves the following registers:
20598 \layout Itemize
20599
20600 WREG
20601 \layout Itemize
20602
20603 STATUS
20604 \layout Itemize
20605
20606 BSR
20607 \layout Itemize
20608
20609 PROD (PRODL and PRODH)
20610 \layout Itemize
20611
20612 FSR0 (FSR0L and FSR0H)
20613 \layout Standard
20614
20615 These registers are restored upon return from the interrupt routine.
20616 \begin_inset Foot
20617 collapsed false
20618
20619 \layout Standard
20620
20621 NOTE that when the _naked attribute is specified for an interrupt routine,
20622  then NO registers are stored or restored.
20623 \end_inset 
20624
20625
20626 \layout Subsection
20627
20628 Generic Pointers
20629 \layout Standard
20630
20631 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20632  There are 3 types of generic pointers currently implemented data, code
20633  and eeprom pointers.
20634  They are differentiated by the value of the 7th and 6th bits of the upper
20635  byte:
20636 \layout Standard
20637 \align center 
20638
20639 \begin_inset  Tabular
20640 <lyxtabular version="3" rows="5" columns="5">
20641 <features>
20642 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20643 <column alignment="center" valignment="top" width="0">
20644 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20645 <column alignment="center" valignment="top" width="0">
20646 <column alignment="left" valignment="top" rightline="true" width="0">
20647 <row topline="true" bottomline="true">
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20649 \begin_inset Text
20650
20651 \layout Standard
20652
20653 pointer type
20654 \end_inset 
20655 </cell>
20656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20657 \begin_inset Text
20658
20659 \layout Standard
20660
20661 7th bit
20662 \end_inset 
20663 </cell>
20664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20665 \begin_inset Text
20666
20667 \layout Standard
20668
20669 6th bit
20670 \end_inset 
20671 </cell>
20672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20673 \begin_inset Text
20674
20675 \layout Standard
20676
20677 rest of the pointer
20678 \end_inset 
20679 </cell>
20680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20681 \begin_inset Text
20682
20683 \layout Standard
20684
20685 description
20686 \end_inset 
20687 </cell>
20688 </row>
20689 <row topline="true" bottomline="true">
20690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20691 \begin_inset Text
20692
20693 \layout Standard
20694
20695 data 
20696 \end_inset 
20697 </cell>
20698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20699 \begin_inset Text
20700
20701 \layout Standard
20702
20703 1
20704 \end_inset 
20705 </cell>
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \layout Standard
20710
20711 0
20712 \end_inset 
20713 </cell>
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20715 \begin_inset Text
20716
20717 \layout Standard
20718
20719
20720 \family typewriter 
20721 \shape slanted 
20722 \emph on 
20723 uuuuuu uuuuxxxx xxxxxxxx
20724 \end_inset 
20725 </cell>
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20727 \begin_inset Text
20728
20729 \layout Standard
20730
20731 a 12-bit data pointer in data RAM memory
20732 \end_inset 
20733 </cell>
20734 </row>
20735 <row bottomline="true">
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_inset Text
20738
20739 \layout Standard
20740
20741 code
20742 \end_inset 
20743 </cell>
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \layout Standard
20748
20749 0
20750 \end_inset 
20751 </cell>
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20753 \begin_inset Text
20754
20755 \layout Standard
20756
20757 0
20758 \end_inset 
20759 </cell>
20760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20761 \begin_inset Text
20762
20763 \layout Standard
20764
20765
20766 \family typewriter 
20767 \shape slanted 
20768 \emph on 
20769 uxxxxx xxxxxxxx xxxxxxxx
20770 \end_inset 
20771 </cell>
20772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20773 \begin_inset Text
20774
20775 \layout Standard
20776
20777 a 21-bit code pointer in FLASH memory
20778 \end_inset 
20779 </cell>
20780 </row>
20781 <row bottomline="true">
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20783 \begin_inset Text
20784
20785 \layout Standard
20786
20787 eeprom
20788 \end_inset 
20789 </cell>
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20791 \begin_inset Text
20792
20793 \layout Standard
20794
20795 0
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 1
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
20812 \family typewriter 
20813 \shape slanted 
20814 \emph on 
20815 uuuuuu uuuuuuxx xxxxxxxx
20816 \end_inset 
20817 </cell>
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20819 \begin_inset Text
20820
20821 \layout Standard
20822
20823 a 10-bit eeprom pointer in EEPROM memory
20824 \end_inset 
20825 </cell>
20826 </row>
20827 <row bottomline="true">
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20829 \begin_inset Text
20830
20831 \layout Standard
20832
20833 (unimplemented)
20834 \end_inset 
20835 </cell>
20836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20837 \begin_inset Text
20838
20839 \layout Standard
20840
20841 1
20842 \end_inset 
20843 </cell>
20844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20845 \begin_inset Text
20846
20847 \layout Standard
20848
20849 1
20850 \end_inset 
20851 </cell>
20852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20853 \begin_inset Text
20854
20855 \layout Standard
20856
20857
20858 \family typewriter 
20859 \shape slanted 
20860 \emph on 
20861 xxxxxx xxxxxxxx xxxxxxxx
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 unimplemented pointer type
20870 \end_inset 
20871 </cell>
20872 </row>
20873 </lyxtabular>
20874
20875 \end_inset 
20876
20877
20878 \layout Standard
20879
20880 Generic pointer are read and written with a set of library functions which
20881  read/write 1, 2, 3, 4 bytes.
20882 \layout Subsection
20883
20884 PIC16 C Libraries
20885 \layout Subsubsection
20886
20887 Standard I/O Streams
20888 \layout Standard
20889
20890 In the 
20891 \emph on 
20892 stdio.h
20893 \emph default 
20894  the type FILE is defined as:
20895 \layout LyX-Code
20896
20897 typedef char * FILE;
20898 \layout Standard
20899
20900 This type is the stream type implemented I/O in the PIC18F devices.
20901  Also the standard input and output streams are declared in stdio.h:
20902 \layout LyX-Code
20903
20904 extern FILE * stdin;
20905 \layout LyX-Code
20906
20907 extern FILE * stdout;
20908 \layout Standard
20909
20910 The FILE type is actually a generic pointer which defines one more type
20911  of generic pointers, the 
20912 \emph on 
20913 stream 
20914 \emph default 
20915 pointer.
20916  This new type has the format:
20917 \layout Standard
20918 \align center 
20919
20920 \begin_inset  Tabular
20921 <lyxtabular version="3" rows="2" columns="7">
20922 <features>
20923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20924 <column alignment="center" valignment="top" width="0">
20925 <column alignment="center" valignment="top" leftline="true" width="0">
20926 <column alignment="center" valignment="top" leftline="true" width="0">
20927 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20928 <column alignment="center" valignment="top" width="0">
20929 <column alignment="left" valignment="top" rightline="true" width="0">
20930 <row topline="true" bottomline="true">
20931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20932 \begin_inset Text
20933
20934 \layout Standard
20935
20936 pointer type
20937 \end_inset 
20938 </cell>
20939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20940 \begin_inset Text
20941
20942 \layout Standard
20943
20944 <7:6>
20945 \end_inset 
20946 </cell>
20947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20948 \begin_inset Text
20949
20950 \layout Standard
20951
20952 <5>
20953 \end_inset 
20954 </cell>
20955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20956 \begin_inset Text
20957
20958 \layout Standard
20959
20960 <4>
20961 \end_inset 
20962 </cell>
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20964 \begin_inset Text
20965
20966 \layout Standard
20967
20968 <3:0>
20969 \end_inset 
20970 </cell>
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20972 \begin_inset Text
20973
20974 \layout Standard
20975
20976 rest of the pointer
20977 \end_inset 
20978 </cell>
20979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20980 \begin_inset Text
20981
20982 \layout Standard
20983
20984 descrption
20985 \end_inset 
20986 </cell>
20987 </row>
20988 <row topline="true" bottomline="true">
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \layout Standard
20993
20994 stream
20995 \end_inset 
20996 </cell>
20997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20998 \begin_inset Text
20999
21000 \layout Standard
21001
21002 00
21003 \end_inset 
21004 </cell>
21005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21006 \begin_inset Text
21007
21008 \layout Standard
21009
21010 1
21011 \end_inset 
21012 </cell>
21013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21014 \begin_inset Text
21015
21016 \layout Standard
21017
21018 0
21019 \end_inset 
21020 </cell>
21021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21022 \begin_inset Text
21023
21024 \layout Standard
21025
21026 nnnn
21027 \end_inset 
21028 </cell>
21029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21030 \begin_inset Text
21031
21032 \layout Standard
21033
21034
21035 \family typewriter 
21036 \shape slanted 
21037 \emph on 
21038 uuuuuuuu uuuuuuuu
21039 \end_inset 
21040 </cell>
21041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21042 \begin_inset Text
21043
21044 \layout Standard
21045
21046 upper byte high nubble is 0x2n, the rest are zeroes
21047 \end_inset 
21048 </cell>
21049 </row>
21050 </lyxtabular>
21051
21052 \end_inset 
21053
21054
21055 \layout Standard
21056
21057 Currently implemented there are 3 types of streams defined:
21058 \layout Standard
21059 \align center 
21060
21061 \begin_inset  Tabular
21062 <lyxtabular version="3" rows="4" columns="4">
21063 <features>
21064 <column alignment="center" valignment="top" leftline="true" width="0">
21065 <column alignment="center" valignment="top" leftline="true" width="0">
21066 <column alignment="center" valignment="top" leftline="true" width="0">
21067 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21068 <row topline="true" bottomline="true">
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_inset Text
21071
21072 \layout Standard
21073
21074 stream type
21075 \end_inset 
21076 </cell>
21077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21078 \begin_inset Text
21079
21080 \layout Standard
21081
21082 value
21083 \end_inset 
21084 </cell>
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21086 \begin_inset Text
21087
21088 \layout Standard
21089
21090 module
21091 \end_inset 
21092 </cell>
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21094 \begin_inset Text
21095
21096 \layout Standard
21097
21098 description
21099 \end_inset 
21100 </cell>
21101 </row>
21102 <row topline="true">
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21104 \begin_inset Text
21105
21106 \layout Standard
21107
21108 STREAM_USART
21109 \end_inset 
21110 </cell>
21111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21112 \begin_inset Text
21113
21114 \layout Standard
21115
21116
21117 \family typewriter 
21118 0x200000UL
21119 \end_inset 
21120 </cell>
21121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21122 \begin_inset Text
21123
21124 \layout Standard
21125
21126 USART
21127 \end_inset 
21128 </cell>
21129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21130 \begin_inset Text
21131
21132 \layout Standard
21133
21134 Writes/Reads characters via the USART peripheral
21135 \end_inset 
21136 </cell>
21137 </row>
21138 <row topline="true">
21139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21140 \begin_inset Text
21141
21142 \layout Standard
21143
21144 STREAM_MSSP
21145 \end_inset 
21146 </cell>
21147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21148 \begin_inset Text
21149
21150 \layout Standard
21151
21152
21153 \family typewriter 
21154 0x210000UL
21155 \end_inset 
21156 </cell>
21157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21158 \begin_inset Text
21159
21160 \layout Standard
21161
21162 MSSP
21163 \end_inset 
21164 </cell>
21165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21166 \begin_inset Text
21167
21168 \layout Standard
21169
21170 Writes/Reads characters via the MSSP peripheral
21171 \end_inset 
21172 </cell>
21173 </row>
21174 <row topline="true" bottomline="true">
21175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21176 \begin_inset Text
21177
21178 \layout Standard
21179
21180 STREAM_USER
21181 \end_inset 
21182 </cell>
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \layout Standard
21187
21188
21189 \family typewriter 
21190 0x2f0000UL
21191 \end_inset 
21192 </cell>
21193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21194 \begin_inset Text
21195
21196 \layout Standard
21197
21198 (none)
21199 \end_inset 
21200 </cell>
21201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21202 \begin_inset Text
21203
21204 \layout Standard
21205
21206 Writes/Reads characters via used defined functions
21207 \end_inset 
21208 </cell>
21209 </row>
21210 </lyxtabular>
21211
21212 \end_inset 
21213
21214
21215 \layout Standard
21216
21217 The stream identifiers are declared as macros in the stdio.h header.
21218 \layout Standard
21219
21220 In the libc library there exist the functions that are used to write to
21221  each of the above streams.
21222  These are
21223 \layout List
21224 \labelwidthstring 00.00.0000
21225
21226 _
21227 \begin_inset ERT
21228 status Collapsed
21229
21230 \layout Standard
21231
21232 \backslash 
21233 /
21234 \end_inset 
21235
21236 _stream_usart_putchar writes a character at the USART stream
21237 \layout List
21238 \labelwidthstring 00.00.0000
21239
21240 _
21241 \begin_inset ERT
21242 status Collapsed
21243
21244 \layout Standard
21245
21246 \backslash 
21247 /
21248 \end_inset 
21249
21250 _stream_mssp_putchar writes a character at the MSSP stream
21251 \layout List
21252 \labelwidthstring 00.00.0000
21253
21254 putchar dummy function.
21255  This writes a character to a user specified manner.
21256 \layout Standard
21257
21258 In order to increase performance 
21259 \emph on 
21260 putchar 
21261 \emph default 
21262 is declared in stdio.h as having its parameter in WREG (it has the wparam
21263  keyword).
21264  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21265  in a user-friendly way.
21266  
21267 \emph on 
21268 arg
21269 \emph default 
21270  is the name of the variable that holds the character to print.
21271  An example follows:
21272 \layout LyX-Code
21273
21274 #include <pic18fregs.h>
21275 \newline 
21276 #include <stdio.h>
21277 \newline 
21278
21279 \newline 
21280 PUTCHAR( c )
21281 \layout LyX-Code
21282
21283 {
21284 \layout LyX-Code
21285
21286     PORTA = c;    /* dump character c to PORTA */
21287 \layout LyX-Code
21288
21289
21290 \newline 
21291
21292 \newline 
21293 void main(void)
21294 \layout LyX-Code
21295
21296 {
21297 \layout LyX-Code
21298
21299     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21300 \layout LyX-Code
21301
21302                               * by default to STREAM_USER */
21303 \layout LyX-Code
21304
21305     printf (¨This is a printf test
21306 \backslash 
21307 n¨);
21308 \layout LyX-Code
21309
21310 }
21311 \layout LyX-Code
21312
21313 \layout Subsubsection
21314
21315 Printing functions
21316 \layout Standard
21317
21318 PIC16 contains an implementation of the printf-family of functions.
21319  There exist the following functions:
21320 \layout LyX-Code
21321
21322 extern unsigned int sprintf(char *buf, char *fmt, ...);
21323 \layout LyX-Code
21324
21325 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21326 \layout LyX-Code
21327
21328 \layout LyX-Code
21329
21330 extern unsigned int printf(char *fmt, ...);
21331 \layout LyX-Code
21332
21333 extern unsigned int vprintf(char *fmt, va_lista ap);
21334 \layout LyX-Code
21335
21336 \layout LyX-Code
21337
21338 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21339 \layout LyX-Code
21340
21341 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21342 \layout Standard
21343
21344 For sprintf and vsprintf 
21345 \emph on 
21346 buf 
21347 \emph default 
21348 should normally be a data pointer where the resulting string will be placed.
21349  No range checking is done so the user should allocate the necessery buffer.
21350  For fprintf and vfprintf 
21351 \emph on 
21352 fp
21353 \emph default 
21354  should be a stream pointer (i.e.
21355  stdout, STREAM_MSSP, etc...).
21356 \layout Subsubsection
21357
21358 Signals
21359 \layout Standard
21360
21361 The PIC18F family of microcontrollers supports a number of interrupt sources.
21362  A list of these interrupts is shown in the following table:
21363 \layout Standard
21364 \align center 
21365
21366 \begin_inset  Tabular
21367 <lyxtabular version="3" rows="11" columns="4">
21368 <features>
21369 <column alignment="left" valignment="top" leftline="true" width="0">
21370 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21371 <column alignment="left" valignment="top" leftline="true" width="0">
21372 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21373 <row topline="true" bottomline="true">
21374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21375 \begin_inset Text
21376
21377 \layout Standard
21378
21379 signal name
21380 \end_inset 
21381 </cell>
21382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21383 \begin_inset Text
21384
21385 \layout Standard
21386
21387 description
21388 \end_inset 
21389 </cell>
21390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21391 \begin_inset Text
21392
21393 \layout Standard
21394
21395 signal name
21396 \end_inset 
21397 </cell>
21398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21399 \begin_inset Text
21400
21401 \layout Standard
21402
21403 descritpion
21404 \end_inset 
21405 </cell>
21406 </row>
21407 <row topline="true">
21408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21409 \begin_inset Text
21410
21411 \layout Standard
21412
21413 SIG_RB
21414 \end_inset 
21415 </cell>
21416 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21417 \begin_inset Text
21418
21419 \layout Standard
21420
21421 PORTB change interrupt
21422 \end_inset 
21423 </cell>
21424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21425 \begin_inset Text
21426
21427 \layout Standard
21428
21429 SIG_EE
21430 \end_inset 
21431 </cell>
21432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21433 \begin_inset Text
21434
21435 \layout Standard
21436
21437 EEPROM/FLASH write complete interrupt
21438 \end_inset 
21439 </cell>
21440 </row>
21441 <row topline="true">
21442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21443 \begin_inset Text
21444
21445 \layout Standard
21446
21447 SIG_INT0
21448 \end_inset 
21449 </cell>
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21451 \begin_inset Text
21452
21453 \layout Standard
21454
21455 INT0 external interrupt
21456 \end_inset 
21457 </cell>
21458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21459 \begin_inset Text
21460
21461 \layout Standard
21462
21463 SIG_BCOL
21464 \end_inset 
21465 </cell>
21466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21467 \begin_inset Text
21468
21469 \layout Standard
21470
21471 Bus collision interrupt
21472 \end_inset 
21473 </cell>
21474 </row>
21475 <row topline="true">
21476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21477 \begin_inset Text
21478
21479 \layout Standard
21480
21481 SIG_INT1
21482 \end_inset 
21483 </cell>
21484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21485 \begin_inset Text
21486
21487 \layout Standard
21488
21489 INT1 external interrupt
21490 \end_inset 
21491 </cell>
21492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21493 \begin_inset Text
21494
21495 \layout Standard
21496
21497 SIG_LVD
21498 \end_inset 
21499 </cell>
21500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21501 \begin_inset Text
21502
21503 \layout Standard
21504
21505 Low voltage detect interrupt
21506 \end_inset 
21507 </cell>
21508 </row>
21509 <row topline="true">
21510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21511 \begin_inset Text
21512
21513 \layout Standard
21514
21515 SIG_INT2
21516 \end_inset 
21517 </cell>
21518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21519 \begin_inset Text
21520
21521 \layout Standard
21522
21523 INT2 external interrupt
21524 \end_inset 
21525 </cell>
21526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21527 \begin_inset Text
21528
21529 \layout Standard
21530
21531 SIG_PSP
21532 \end_inset 
21533 </cell>
21534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21535 \begin_inset Text
21536
21537 \layout Standard
21538
21539 Parallel slave port interrupt
21540 \end_inset 
21541 </cell>
21542 </row>
21543 <row topline="true">
21544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21545 \begin_inset Text
21546
21547 \layout Standard
21548
21549 SIG_CCP1
21550 \end_inset 
21551 </cell>
21552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21553 \begin_inset Text
21554
21555 \layout Standard
21556
21557 CCP1 module interrupt
21558 \end_inset 
21559 </cell>
21560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21561 \begin_inset Text
21562
21563 \layout Standard
21564
21565 SIG_AD
21566 \end_inset 
21567 </cell>
21568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21569 \begin_inset Text
21570
21571 \layout Standard
21572
21573 AD convertion complete interrupt
21574 \end_inset 
21575 </cell>
21576 </row>
21577 <row topline="true">
21578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21579 \begin_inset Text
21580
21581 \layout Standard
21582
21583 SIG_CCP2
21584 \end_inset 
21585 </cell>
21586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21587 \begin_inset Text
21588
21589 \layout Standard
21590
21591 CCP2 module interrupt
21592 \end_inset 
21593 </cell>
21594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21595 \begin_inset Text
21596
21597 \layout Standard
21598
21599 SIG_RC
21600 \end_inset 
21601 </cell>
21602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21603 \begin_inset Text
21604
21605 \layout Standard
21606
21607 USART receive interrupt
21608 \end_inset 
21609 </cell>
21610 </row>
21611 <row topline="true">
21612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21613 \begin_inset Text
21614
21615 \layout Standard
21616
21617 SIG_TMR0
21618 \end_inset 
21619 </cell>
21620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21621 \begin_inset Text
21622
21623 \layout Standard
21624
21625 TMR0 overflow interrupt
21626 \end_inset 
21627 </cell>
21628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21629 \begin_inset Text
21630
21631 \layout Standard
21632
21633 SIG_TX
21634 \end_inset 
21635 </cell>
21636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21637 \begin_inset Text
21638
21639 \layout Standard
21640
21641 USART transmit interrupt
21642 \end_inset 
21643 </cell>
21644 </row>
21645 <row topline="true">
21646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21647 \begin_inset Text
21648
21649 \layout Standard
21650
21651 SIG_TMR1
21652 \end_inset 
21653 </cell>
21654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21655 \begin_inset Text
21656
21657 \layout Standard
21658
21659 TMR1 overflow interrupt
21660 \end_inset 
21661 </cell>
21662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21663 \begin_inset Text
21664
21665 \layout Standard
21666
21667 SIG_MSSP
21668 \end_inset 
21669 </cell>
21670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21671 \begin_inset Text
21672
21673 \layout Standard
21674
21675 SSP receive/transmit interrupt
21676 \end_inset 
21677 </cell>
21678 </row>
21679 <row topline="true">
21680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21681 \begin_inset Text
21682
21683 \layout Standard
21684
21685 SIG_TMR2
21686 \end_inset 
21687 </cell>
21688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21689 \begin_inset Text
21690
21691 \layout Standard
21692
21693 TMR2 matches PR2 interrupt
21694 \end_inset 
21695 </cell>
21696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21697 \begin_inset Text
21698
21699 \layout Standard
21700
21701 \end_inset 
21702 </cell>
21703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21704 \begin_inset Text
21705
21706 \layout Standard
21707
21708 \end_inset 
21709 </cell>
21710 </row>
21711 <row topline="true" bottomline="true">
21712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21713 \begin_inset Text
21714
21715 \layout Standard
21716
21717 SIG_TMR3
21718 \end_inset 
21719 </cell>
21720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21721 \begin_inset Text
21722
21723 \layout Standard
21724
21725 TMR3 overflow interrupt
21726 \end_inset 
21727 </cell>
21728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21729 \begin_inset Text
21730
21731 \layout Standard
21732
21733 \end_inset 
21734 </cell>
21735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21736 \begin_inset Text
21737
21738 \layout Standard
21739
21740 \end_inset 
21741 </cell>
21742 </row>
21743 </lyxtabular>
21744
21745 \end_inset 
21746
21747
21748 \layout Standard
21749
21750 The prototypes for these names are defined in the header file 
21751 \emph on 
21752 signal.h
21753 \emph default 
21754  .
21755 \layout Standard
21756
21757 In order to simplify signal handling, a number of macros is provided:
21758 \layout List
21759 \labelwidthstring 00.00.0000
21760
21761 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21762  high priority interrupts.
21763  
21764 \emph on 
21765 name
21766 \emph default 
21767  is the function name to use.
21768 \layout List
21769 \labelwidthstring 00.00.0000
21770
21771 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21772  low priority interrupt.
21773  
21774 \emph on 
21775 name
21776 \emph default 
21777  is the function name to use.
21778 \layout List
21779 \labelwidthstring 00.00.0000
21780
21781 DEF_HANDLER(sig,handler) define a handler for signal 
21782 \emph on 
21783 sig.
21784 \layout List
21785 \labelwidthstring 00.00.0000
21786
21787 END_DEF end the declaration of the dispatch table.
21788 \layout Standard
21789
21790 Additionally there are two more macros to simplify the declaration of the
21791  signal handler:
21792 \layout List
21793 \labelwidthstring 00.00.0000
21794
21795
21796 \series medium 
21797 SIGHANDLER(handler) 
21798 \series default 
21799 this declares the function prototype for the 
21800 \emph on 
21801 handler
21802 \emph default 
21803  function.
21804 \layout List
21805 \labelwidthstring 00.00.0000
21806
21807 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21808 \layout Standard
21809
21810 An example of using the macros above is shown below:
21811 \layout LyX-Code
21812
21813 #include <pic18fregs.h>
21814 \layout LyX-Code
21815
21816 #include <signal.h>
21817 \newline 
21818
21819 \newline 
21820 DEF_INTHIGH(high_int)
21821 \layout LyX-Code
21822
21823 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21824 \layout LyX-Code
21825
21826 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21827 \layout LyX-Code
21828
21829 END_DEF
21830 \newline 
21831
21832 \newline 
21833 SIGHANDLER(_tmr0_handler)
21834 \layout LyX-Code
21835
21836 {
21837 \layout LyX-Code
21838
21839   /* action to be taken when timer 0 overflows */
21840 \layout LyX-Code
21841
21842 }
21843 \newline 
21844
21845 \newline 
21846 SIGHANDLERNAKED(_bcol_handler)
21847 \layout LyX-Code
21848
21849 {
21850 \layout LyX-Code
21851
21852   _asm
21853 \layout LyX-Code
21854
21855     /* action to be taken when bus collision occurs */
21856 \layout LyX-Code
21857
21858     retfie
21859 \layout LyX-Code
21860
21861  _endasm;
21862 \layout LyX-Code
21863
21864 }
21865 \layout Standard
21866
21867
21868 \series bold 
21869 NOTES:
21870 \series default 
21871  Special care should be taken when using the above scheme:
21872 \layout Itemize
21873
21874 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21875 \layout Itemize
21876
21877 when declaring SIGHANDLERNAKED handler never forget to use 
21878 \emph on 
21879 retfie
21880 \emph default 
21881  for proper returning.
21882 \layout Subsection
21883
21884 PIC16 Port -- Tips
21885 \layout Standard
21886
21887 Here you can find some general tips for compiling programs with SDCC/pic16.
21888 \layout Subsubsection
21889
21890 Stack size
21891 \layout Standard
21892
21893 The default stack
21894 \begin_inset LatexCommand \index{PIC16!stack}
21895
21896 \end_inset 
21897
21898  size (that is 64 bytes) probably is enough for many programs.
21899  One must take care that when there are many levels of function nesting,
21900  or there is excessive usage of stack, its size should be extended.
21901  An example of such a case is the printf/sprintf family of functions.
21902  If you encounter problems like not being able to print integers, then you
21903  need to set the stack size around the maximum (256 for small stack model).
21904  The following diagram shows what happens when calling printf to print an
21905  integer:
21906 \layout LyX-Code
21907
21908 printf () --> ltoa () --> ultoa () --> divschar ()
21909 \layout Standard
21910
21911 It is should be understood that stack is easily consumed when calling complicate
21912 d functions.
21913  Using command line arguments like -
21914 \begin_inset ERT
21915 status Collapsed
21916
21917 \layout Standard
21918
21919 \backslash 
21920 /
21921 \end_inset 
21922
21923 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21924  stack frames.
21925  Other ways to reduce stack usage may exist.
21926 \layout Subsection
21927
21928 Known bugs
21929 \layout Standard
21930
21931 The PIC16 Port currently does not pass SDCC's regression test
21932 \begin_inset LatexCommand \index{Regression test (PIC16)}
21933
21934 \end_inset 
21935
21936  suite (see section 
21937 \begin_inset LatexCommand \ref{sec:Quality-control}
21938
21939 \end_inset 
21940
21941 ) and thus the nightly regression tests for the PIC16 target are currently
21942  disabled for all hosts except for 
21943 \emph on 
21944 Linux on Opteron.
21945
21946 \emph default 
21947  This means you can see the result of the PIC16 regression tests f.e.
21948  by checking the log files in 
21949 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
21950
21951 \end_inset 
21952
21953  (pick the most up to date file there, scroll down, lend a hand).
21954 \layout Chapter
21955
21956 Debugging
21957 \layout Standard
21958
21959 There are several approaches to debugging your code.
21960  This chapter is meant to show your options and to give detail on some of
21961  them:
21962 \newline 
21963
21964 \newline 
21965 When writing your code:
21966 \layout Itemize
21967
21968 write your code with debugging in mind (avoid duplicating code, put conceptually
21969  similar variables into structs, use structured code, have strategic points
21970  within your code where all variables are consistent, ...)
21971 \layout Itemize
21972
21973 run a syntax-checking tool like splint
21974 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21975
21976 \end_inset 
21977
21978
21979 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21980
21981 \end_inset 
21982
21983  (see -
21984 \begin_inset ERT
21985 status Collapsed
21986
21987 \layout Standard
21988
21989 \backslash 
21990 /
21991 \end_inset 
21992
21993 -more-pedantic 
21994 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21995
21996 \end_inset 
21997
21998 ) over the code.
21999 \layout Itemize
22000
22001 for the high level code use a C-compiler (like f.e.
22002  GCC) to compile run and debug the code on your host.
22003  See (see -
22004 \begin_inset ERT
22005 status Collapsed
22006
22007 \layout Standard
22008
22009 \backslash 
22010 /
22011 \end_inset 
22012
22013 -more-pedantic 
22014 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22015
22016 \end_inset 
22017
22018  ) on howto handle syntax extensions like __xdata, __at(), ...
22019  
22020 \layout Itemize
22021
22022 use another C-compiler to compile code for your target.
22023  Always an option but not recommended:) And not very likely to help you.
22024  If you seriously consider walking this path you should at least occasionally
22025  check portability of your code.
22026  Most commercial compiler vendors will offer an evaluation version so you
22027  can test compile your code or snippets of your code.
22028 \layout Standard
22029
22030 Debugging on a simulator:
22031 \layout Itemize
22032
22033 there is a separate section about SDCDB (section 
22034 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
22035
22036 \end_inset 
22037
22038 ) below.
22039 \layout Itemize
22040
22041 or (8051 specific) use a freeware/commercial simulator which interfaces
22042  to the AOMF
22043 \begin_inset LatexCommand \index{AOMF, AOMF51}
22044
22045 \end_inset 
22046
22047  file (see 
22048 \begin_inset LatexCommand \ref{OMF file}
22049
22050 \end_inset 
22051
22052 ) optionally generated by SDCC.
22053 \layout Standard
22054
22055 Debugging On-target: 
22056 \layout Itemize
22057
22058 use a MCU port pin to serially output debug data to the RS232 port of your
22059  host.
22060  You'll probably want some level shifting device typically involving a MAX232
22061  or similar IC.
22062  If the hardware serial port of the MCU is not available search for 'Software
22063  UART' in your favourite search machine.
22064 \layout Itemize
22065
22066 use an on-target monitor.
22067  In this context a monitor is a small program which usually accepts commands
22068  via a serial line and allows to set program counter, to single step through
22069  a program and read/write memory locations.
22070  For the 8051 good examples of monitors are paulmon and cmon51 (see section
22071  
22072 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
22073
22074 \end_inset 
22075
22076 ).
22077 \layout Itemize
22078
22079 toggle MCU port pins at strategic points within your code and use an oscilloscop
22080 e.
22081  A 
22082 \emph on 
22083 digital oscilloscope
22084 \emph default 
22085
22086 \begin_inset LatexCommand \index{Oscilloscope}
22087
22088 \end_inset 
22089
22090  with deep trace memory is really helpful especially if you have to debug
22091  a realtime application.
22092  If you need to monitor more pins than your oscilloscope provides you can
22093  sometimes get away with a small R-2R network.
22094  On a single channel oscilloscope you could f.e.
22095  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22096 k
22097 \begin_inset Formula $\Omega$
22098 \end_inset 
22099
22100  resistor and the other one by a 5\SpecialChar ~
22101 k
22102 \begin_inset Formula $\Omega$
22103 \end_inset 
22104
22105  resistor to the oscilloscope probe (check output drive capability of the
22106  pins you want to monitor).
22107  If you need to monitor many more pins a 
22108 \emph on 
22109 logic analyzer
22110 \emph default 
22111  will be handy.
22112 \layout Itemize
22113
22114 use an ICE (
22115 \emph on 
22116 i
22117 \emph default 
22118
22119 \emph on 
22120 c
22121 \emph default 
22122 ircuit 
22123 \emph on 
22124 e
22125 \emph default 
22126 mulator
22127 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22128
22129 \end_inset 
22130
22131 ).
22132  Usually very expensive.
22133  And very nice to have too.
22134  And usually locks you (for years...) to the devices the ICE can emulate.
22135  
22136 \layout Itemize
22137
22138 use a remote debugger.
22139  In most 8-bit systems the symbol information is not available on the target,
22140  and a complete debugger is too bulky for the target system.
22141  Therefore usually a debugger on the host system connects to an on-target
22142  debugging stub which accepts only primitive commands.
22143  
22144 \newline 
22145 Terms to enter into your favourite search engine could be 'remote debugging',
22146  'gdb stub' or 'inferior debugger'.
22147  (is there one?)
22148 \layout Itemize
22149
22150 use an on target hardware debugger.
22151  Some of the more modern MCUs include hardware support for setting break
22152  points and monitoring/changing variables by using dedicated hardware pins.
22153  This facility doesn't require additional code to run on the target and
22154  
22155 \emph on 
22156 usually
22157 \emph default 
22158  doesn't affect runtime behaviour until a breakpoint is hit.
22159  For the mcs51 most hardware debuggers use the AOMF
22160 \begin_inset LatexCommand \index{AOMF, AOMF51}
22161
22162 \end_inset 
22163
22164  file (see 
22165 \begin_inset LatexCommand \ref{OMF file}
22166
22167 \end_inset 
22168
22169 ) as input file.
22170  
22171 \layout Standard
22172
22173 Last not least:
22174 \layout Itemize
22175
22176 if you are not familiar with any of the following terms you're likely to
22177  run into problems rather sooner than later: 
22178 \emph on 
22179 volatile
22180 \emph default 
22181
22182 \emph on 
22183 atomic
22184 \emph default 
22185
22186 \emph on 
22187 memory map
22188 \emph default 
22189
22190 \emph on 
22191 overlay
22192 \emph default 
22193 .
22194  As an embedded programmer you 
22195 \emph on 
22196 have
22197 \emph default 
22198  to know them so why not look them up 
22199 \emph on 
22200 before
22201 \emph default 
22202  you have problems?)
22203 \layout Itemize
22204
22205 tell someone else about your problem (actually this is a surprisingly effective
22206  means to hunt down the bug even if the listener is not familiar with your
22207  environment).
22208  As 'failure to communicate' is probably one of the job-induced deformations
22209  of an embedded programmer this is highly encouraged.
22210 \layout Section
22211
22212 Debugging with SDCDB
22213 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22214
22215 \end_inset 
22216
22217
22218 \begin_inset LatexCommand \index{SDCDB (debugger)}
22219
22220 \end_inset 
22221
22222  
22223 \layout Standard
22224
22225 SDCC is distributed with a source level debugger
22226 \begin_inset LatexCommand \index{Debugger}
22227
22228 \end_inset 
22229
22230 .
22231  The debugger uses a command line interface, the command repertoire of the
22232  debugger has been kept as close to gdb
22233 \begin_inset LatexCommand \index{gdb}
22234
22235 \end_inset 
22236
22237  (the GNU debugger) as possible.
22238  The configuration and build process is part of the standard compiler installati
22239 on, which also builds and installs the debugger in the target directory
22240  specified during configuration.
22241  The debugger allows you debug BOTH at the C source and at the ASM source
22242  level.
22243 \layout Subsection
22244
22245 Compiling for Debugging
22246 \layout Standard
22247
22248 The -
22249 \begin_inset ERT
22250 status Collapsed
22251
22252 \layout Standard
22253
22254 \backslash 
22255 /
22256 \end_inset 
22257
22258 -debug
22259 \begin_inset LatexCommand \index{-\/-debug}
22260
22261 \end_inset 
22262
22263  option must be specified for all files for which debug information is to
22264  be generated.
22265  The compiler generates a .adb file for each of these files.
22266  The linker creates the .cdb
22267 \begin_inset LatexCommand \index{<file>.cdb}
22268
22269 \end_inset 
22270
22271  file from the .adb
22272 \begin_inset LatexCommand \index{<file>.adb}
22273
22274 \end_inset 
22275
22276  files and the address information.
22277  This .cdb is used by the debugger.
22278 \layout Subsection
22279
22280 How the Debugger Works
22281 \layout Standard
22282
22283 When the -
22284 \begin_inset ERT
22285 status Collapsed
22286
22287 \layout Standard
22288
22289 \backslash 
22290 /
22291 \end_inset 
22292
22293 -debug option is specified the compiler generates extra symbol information
22294  some of which are put into the assembler source and some are put into the
22295  .adb file.
22296  Then the linker creates the .cdb file from the individual .adb files with
22297  the address information for the symbols.
22298  The debugger reads the symbolic information generated by the compiler &
22299  the address information generated by the linker.
22300  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22301  execution is controlled by the debugger.
22302  When a command is issued for the debugger, it translates it into appropriate
22303  commands for the simulator.
22304  (Currently SDCDM only connects to the simulator but 
22305 \emph on 
22306 newcdb
22307 \emph default 
22308  at 
22309 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22310
22311 \end_inset 
22312
22313  is an effort to connect directly to the hardware.) 
22314 \layout Subsection
22315
22316 Starting the Debugger SDCDB
22317 \layout Standard
22318
22319 The debugger can be started using the following command line.
22320  (Assume the file you are debugging has the file name foo).
22321 \newline 
22322
22323 \newline 
22324
22325 \family sans 
22326 \series bold 
22327 sdcdb foo
22328 \newline 
22329
22330 \family default 
22331 \series default 
22332
22333 \newline 
22334 The debugger will look for the following files.
22335 \layout Itemize
22336
22337 foo.c - the source file.
22338 \layout Itemize
22339
22340 foo.cdb - the debugger symbol information file.
22341 \layout Itemize
22342
22343 foo.ihx - the Intel hex format
22344 \begin_inset LatexCommand \index{Intel hex format}
22345
22346 \end_inset 
22347
22348  object file.
22349 \layout Subsection
22350
22351 SDCDB Command Line Options
22352 \layout Itemize
22353
22354 -
22355 \begin_inset ERT
22356 status Collapsed
22357
22358 \layout Standard
22359
22360 \backslash 
22361 /
22362 \end_inset 
22363
22364 -directory=<source file directory> this option can used to specify the directory
22365  search list.
22366  The debugger will look into the directory list specified for source, cdb
22367  & ihx files.
22368  The items in the directory list must be separated by ':', e.g.
22369  if the source files can be in the directories /home/src1 and /home/src2,
22370  the -
22371 \begin_inset ERT
22372 status Collapsed
22373
22374 \layout Standard
22375
22376 \backslash 
22377 /
22378 \end_inset 
22379
22380 -directory option should be -
22381 \begin_inset ERT
22382 status Collapsed
22383
22384 \layout Standard
22385
22386 \backslash 
22387 /
22388 \end_inset 
22389
22390 -directory=/home/src1:/home/src2.
22391  Note there can be no spaces in the option.
22392  
22393 \layout Itemize
22394
22395 -cd <directory> - change to the <directory>.
22396 \layout Itemize
22397
22398 -fullname - used by GUI front ends.
22399 \layout Itemize
22400
22401 -cpu <cpu-type> - this argument is passed to the simulator please see the
22402  simulator docs for details.
22403 \layout Itemize
22404
22405 -X <Clock frequency > this options is passed to the simulator please see
22406  the simulator docs for details.
22407 \layout Itemize
22408
22409 -s <serial port file> passed to simulator see the simulator docs for details.
22410 \layout Itemize
22411
22412 -S <serial in,out> passed to simulator see the simulator docs for details.
22413 \layout Itemize
22414
22415 -k <port number> passed to simulator see the simulator docs for details.
22416 \layout Subsection
22417
22418 SDCDB Debugger Commands
22419 \layout Standard
22420
22421 As mentioned earlier the command interface for the debugger has been deliberatel
22422 y kept as close the GNU debugger gdb, as possible.
22423  This will help the integration with existing graphical user interfaces
22424  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22425  If you use a graphical user interface for the debugger you can skip this
22426  section.
22427 \layout Subsubsection*
22428
22429 break [line | file:line | function | file:function]
22430 \layout Standard
22431
22432 Set breakpoint at specified line or function:
22433 \newline 
22434
22435 \newline 
22436
22437 \family sans 
22438 \series bold 
22439 sdcdb>break 100 
22440 \newline 
22441 sdcdb>break foo.c:100
22442 \newline 
22443 sdcdb>break funcfoo
22444 \newline 
22445 sdcdb>break foo.c:funcfoo
22446 \layout Subsubsection*
22447
22448 clear [line | file:line | function | file:function ]
22449 \layout Standard
22450
22451 Clear breakpoint at specified line or function:
22452 \newline 
22453
22454 \newline 
22455
22456 \family sans 
22457 \series bold 
22458 sdcdb>clear 100
22459 \newline 
22460 sdcdb>clear foo.c:100
22461 \newline 
22462 sdcdb>clear funcfoo
22463 \newline 
22464 sdcdb>clear foo.c:funcfoo
22465 \layout Subsubsection*
22466
22467 continue
22468 \layout Standard
22469
22470 Continue program being debugged, after breakpoint.
22471 \layout Subsubsection*
22472
22473 finish
22474 \layout Standard
22475
22476 Execute till the end of the current function.
22477 \layout Subsubsection*
22478
22479 delete [n]
22480 \layout Standard
22481
22482 Delete breakpoint number 'n'.
22483  If used without any option clear ALL user defined break points.
22484 \layout Subsubsection*
22485
22486 info [break | stack | frame | registers ]
22487 \layout Itemize
22488
22489 info break - list all breakpoints
22490 \layout Itemize
22491
22492 info stack - show the function call stack.
22493 \layout Itemize
22494
22495 info frame - show information about the current execution frame.
22496 \layout Itemize
22497
22498 info registers - show content of all registers.
22499 \layout Subsubsection*
22500
22501 step
22502 \layout Standard
22503
22504 Step program until it reaches a different source line.
22505  Note: pressing <return> repeats the last command.
22506 \layout Subsubsection*
22507
22508 next
22509 \layout Standard
22510
22511 Step program, proceeding through subroutine calls.
22512 \layout Subsubsection*
22513
22514 run
22515 \layout Standard
22516
22517 Start debugged program.
22518 \layout Subsubsection*
22519
22520 ptype variable 
22521 \layout Standard
22522
22523 Print type information of the variable.
22524 \layout Subsubsection*
22525
22526 print variable
22527 \layout Standard
22528
22529 print value of variable.
22530 \layout Subsubsection*
22531
22532 file filename
22533 \layout Standard
22534
22535 load the given file name.
22536  Note this is an alternate method of loading file for debugging.
22537 \layout Subsubsection*
22538
22539 frame
22540 \layout Standard
22541
22542 print information about current frame.
22543 \layout Subsubsection*
22544
22545 set srcmode
22546 \layout Standard
22547
22548 Toggle between C source & assembly source.
22549 \layout Subsubsection*
22550
22551 ! simulator command
22552 \layout Standard
22553
22554 Send the string following '!' to the simulator, the simulator response is
22555  displayed.
22556  Note the debugger does not interpret the command being sent to the simulator,
22557  so if a command like 'go' is sent the debugger can loose its execution
22558  context and may display incorrect values.
22559 \layout Subsubsection*
22560
22561 quit
22562 \layout Standard
22563
22564 "Watch me now.
22565  Iam going Down.
22566  My name is Bobby Brown"
22567 \layout Subsection
22568
22569 Interfacing SDCDB with DDD
22570 \layout Comment
22571
22572 The screenshot was converted from png to eps with: 
22573 \begin_inset Quotes sld
22574 \end_inset 
22575
22576 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22577 \begin_inset Quotes srd
22578 \end_inset 
22579
22580  which produces a pretty compact eps file which is free from compression
22581  artifacts.
22582 \layout Comment
22583
22584 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22585  as this broke the build system on Sourceforge (pdf-file was broken.
22586  pdflatex does not accept eps files).
22587 \layout Standard
22588
22589 The 
22590 \emph on 
22591 p
22592 \emph default 
22593 ortable 
22594 \emph on 
22595 n
22596 \emph default 
22597 etwork 
22598 \emph on 
22599 g
22600 \emph default 
22601 raphics File 
22602 \size footnotesize 
22603
22604 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22605
22606 \end_inset 
22607
22608
22609 \size default 
22610  shows a screenshot of a debugging session with DDD
22611 \begin_inset LatexCommand \index{DDD (debugger)}
22612
22613 \end_inset 
22614
22615  (Unix only) on a simulated 8032.
22616  The debugging session might not run as smoothly as the screenshot suggests.
22617  The debugger allows setting of breakpoints, displaying and changing variables,
22618  single stepping through C and assembler code.
22619  
22620 \newline 
22621 The source was compiled with 
22622 \family sans 
22623 \series bold 
22624
22625 \newline 
22626
22627 \newline 
22628 sdcc -
22629 \family default 
22630 \series default 
22631
22632 \begin_inset ERT
22633 status Collapsed
22634
22635 \layout Standard
22636
22637 \backslash 
22638 /
22639 \end_inset 
22640
22641
22642 \family sans 
22643 \series bold 
22644 -debug ddd_example.c
22645 \family default 
22646 \series default 
22647  
22648 \family sans 
22649 \series bold 
22650
22651 \newline 
22652
22653 \family default 
22654 \series default 
22655
22656 \newline 
22657 and DDD was invoked with 
22658 \family sans 
22659 \series bold 
22660
22661 \newline 
22662
22663 \newline 
22664 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22665 \layout Subsection
22666
22667 Interfacing SDCDB with XEmacs
22668 \begin_inset LatexCommand \index{XEmacs}
22669
22670 \end_inset 
22671
22672
22673 \begin_inset LatexCommand \index{Emacs}
22674
22675 \end_inset 
22676
22677
22678 \layout Standard
22679
22680 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22681  sdcdb.el and sdcdbsrc.el.
22682  These two files can be found in the $(prefix)/bin directory after the installat
22683 ion is complete.
22684  These files need to be loaded into XEmacs for the interface to work.
22685  This can be done at XEmacs startup time by inserting the following into
22686  your '.xemacs' file (which can be found in your HOME directory): 
22687 \newline 
22688
22689 \newline 
22690
22691 \family typewriter 
22692 (load-file sdcdbsrc.el) 
22693 \family default 
22694
22695 \newline 
22696
22697 \newline 
22698 .xemacs is a lisp file so the () around the command is REQUIRED.
22699  The files can also be loaded dynamically while XEmacs is running, set the
22700  environment variable 'EMACSLOADPATH' to the installation bin directory
22701  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22702  To start the interface enter the following command: 
22703 \newline 
22704
22705 \newline 
22706
22707 \family sans 
22708 \series bold 
22709 ESC-x sdcdbsrc
22710 \family default 
22711 \series default 
22712
22713 \newline 
22714
22715 \newline 
22716 You will prompted to enter the file name to be debugged.
22717  
22718 \newline 
22719
22720 \newline 
22721 The command line options that are passed to the simulator directly are bound
22722  to default values in the file sdcdbsrc.el.
22723  The variables are listed below, these values maybe changed as required.
22724 \layout Itemize
22725
22726 sdcdbsrc-cpu-type '51
22727 \layout Itemize
22728
22729 sdcdbsrc-frequency '11059200
22730 \layout Itemize
22731
22732 sdcdbsrc-serial nil
22733 \layout Standard
22734
22735 The following is a list of key mapping for the debugger interface.
22736 \layout Standard
22737
22738 \SpecialChar ~
22739
22740 \family typewriter 
22741
22742 \newline 
22743 ;;\SpecialChar ~
22744 Current Listing :: 
22745 \newline 
22746 ;;key\SpecialChar ~
22747 \SpecialChar ~
22748 \SpecialChar ~
22749 \SpecialChar ~
22750 \SpecialChar ~
22751 \SpecialChar ~
22752 \SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 binding\SpecialChar ~
22761 \SpecialChar ~
22762 \SpecialChar ~
22763 \SpecialChar ~
22764 \SpecialChar ~
22765 \SpecialChar ~
22766 \SpecialChar ~
22767 \SpecialChar ~
22768 \SpecialChar ~
22769 \SpecialChar ~
22770 \SpecialChar ~
22771 \SpecialChar ~
22772 \SpecialChar ~
22773 \SpecialChar ~
22774 \SpecialChar ~
22775 \SpecialChar ~
22776 \SpecialChar ~
22777 \SpecialChar ~
22778 \SpecialChar ~
22779 \SpecialChar ~
22780 \SpecialChar ~
22781 \SpecialChar ~
22782 Comment 
22783 \newline 
22784 ;;---\SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 \SpecialChar ~
22789 \SpecialChar ~
22790 \SpecialChar ~
22791 \SpecialChar ~
22792 \SpecialChar ~
22793 \SpecialChar ~
22794 \SpecialChar ~
22795 \SpecialChar ~
22796 \SpecialChar ~
22797 \SpecialChar ~
22798 -------\SpecialChar ~
22799 \SpecialChar ~
22800 \SpecialChar ~
22801 \SpecialChar ~
22802 \SpecialChar ~
22803 \SpecialChar ~
22804 \SpecialChar ~
22805 \SpecialChar ~
22806 \SpecialChar ~
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 -------
22821 \newline 
22822 ;; 
22823 \newline 
22824 ;;\SpecialChar ~
22825 n\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 sdcdb-next-from-src\SpecialChar ~
22841 \SpecialChar ~
22842 \SpecialChar ~
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 \SpecialChar ~
22846 \SpecialChar ~
22847 \SpecialChar ~
22848 \SpecialChar ~
22849 \SpecialChar ~
22850 SDCDB next command 
22851 \newline 
22852 ;;\SpecialChar ~
22853 b\SpecialChar ~
22854 \SpecialChar ~
22855 \SpecialChar ~
22856 \SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 \SpecialChar ~
22862 \SpecialChar ~
22863 \SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 sdcdb-back-from-src\SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 \SpecialChar ~
22872 \SpecialChar ~
22873 \SpecialChar ~
22874 \SpecialChar ~
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 SDCDB back command 
22879 \newline 
22880 ;;\SpecialChar ~
22881 c\SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 \SpecialChar ~
22886 \SpecialChar ~
22887 \SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 sdcdb-cont-from-src\SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 \SpecialChar ~
22902 \SpecialChar ~
22903 \SpecialChar ~
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 SDCDB continue command
22907 \newline 
22908 ;;\SpecialChar ~
22909 s\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 sdcdb-step-from-src\SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 SDCDB step command 
22935 \newline 
22936 ;;\SpecialChar ~
22937 ?\SpecialChar ~
22938 \SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 \SpecialChar ~
22943 \SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 sdcdb-whatis-c-sexp\SpecialChar ~
22953 \SpecialChar ~
22954 \SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 \SpecialChar ~
22960 \SpecialChar ~
22961 \SpecialChar ~
22962 SDCDB ptypecommand for data at 
22963 \newline 
22964 ;;\SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 \SpecialChar ~
22969 \SpecialChar ~
22970 \SpecialChar ~
22971 \SpecialChar ~
22972 \SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 \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 buffer point 
23012 \newline 
23013 ;;\SpecialChar ~
23014 x\SpecialChar ~
23015 \SpecialChar ~
23016 \SpecialChar ~
23017 \SpecialChar ~
23018 \SpecialChar ~
23019 \SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 \SpecialChar ~
23025 \SpecialChar ~
23026 \SpecialChar ~
23027 \SpecialChar ~
23028 \SpecialChar ~
23029 sdcdbsrc-delete\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 SDCDB Delete all breakpoints if no arg 
23044 \newline 
23045 ;;\SpecialChar ~
23046 \SpecialChar ~
23047 \SpecialChar ~
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 \SpecialChar ~
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 \SpecialChar ~
23056 \SpecialChar ~
23057 \SpecialChar ~
23058 \SpecialChar ~
23059 \SpecialChar ~
23060 \SpecialChar ~
23061 \SpecialChar ~
23062 \SpecialChar ~
23063 \SpecialChar ~
23064 \SpecialChar ~
23065 \SpecialChar ~
23066 \SpecialChar ~
23067 \SpecialChar ~
23068 \SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 \SpecialChar ~
23073 \SpecialChar ~
23074 \SpecialChar ~
23075 \SpecialChar ~
23076 \SpecialChar ~
23077 \SpecialChar ~
23078 \SpecialChar ~
23079 \SpecialChar ~
23080 \SpecialChar ~
23081 \SpecialChar ~
23082 \SpecialChar ~
23083 \SpecialChar ~
23084 \SpecialChar ~
23085 \SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 \SpecialChar ~
23092 given or delete arg (C-u arg x) 
23093 \newline 
23094 ;;\SpecialChar ~
23095 m\SpecialChar ~
23096 \SpecialChar ~
23097 \SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 \SpecialChar ~
23110 sdcdbsrc-frame\SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 \SpecialChar ~
23125 SDCDB Display current frame if no arg, 
23126 \newline 
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 \SpecialChar ~
23173 \SpecialChar ~
23174 given or display frame arg 
23175 \newline 
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 \SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 \SpecialChar ~
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 \SpecialChar ~
23199 \SpecialChar ~
23200 \SpecialChar ~
23201 \SpecialChar ~
23202 \SpecialChar ~
23203 \SpecialChar ~
23204 \SpecialChar ~
23205 \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 \SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 buffer point 
23224 \newline 
23225 ;;\SpecialChar ~
23226 !\SpecialChar ~
23227 \SpecialChar ~
23228 \SpecialChar ~
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235 \SpecialChar ~
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 \SpecialChar ~
23239 \SpecialChar ~
23240 \SpecialChar ~
23241 sdcdbsrc-goto-sdcdb\SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249 \SpecialChar ~
23250 \SpecialChar ~
23251 Goto the SDCDB output buffer 
23252 \newline 
23253 ;;\SpecialChar ~
23254 p\SpecialChar ~
23255 \SpecialChar ~
23256 \SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 \SpecialChar ~
23260 \SpecialChar ~
23261 \SpecialChar ~
23262 \SpecialChar ~
23263 \SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 \SpecialChar ~
23267 \SpecialChar ~
23268 \SpecialChar ~
23269 sdcdb-print-c-sexp\SpecialChar ~
23270 \SpecialChar ~
23271 \SpecialChar ~
23272 \SpecialChar ~
23273 \SpecialChar ~
23274 \SpecialChar ~
23275 \SpecialChar ~
23276 \SpecialChar ~
23277 \SpecialChar ~
23278 \SpecialChar ~
23279 \SpecialChar ~
23280 SDCDB print command for data at 
23281 \newline 
23282 ;;\SpecialChar ~
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 \SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 \SpecialChar ~
23290 \SpecialChar ~
23291 \SpecialChar ~
23292 \SpecialChar ~
23293 \SpecialChar ~
23294 \SpecialChar ~
23295 \SpecialChar ~
23296 \SpecialChar ~
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 \SpecialChar ~
23301 \SpecialChar ~
23302 \SpecialChar ~
23303 \SpecialChar ~
23304 \SpecialChar ~
23305 \SpecialChar ~
23306 \SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 \SpecialChar ~
23324 \SpecialChar ~
23325 \SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 \SpecialChar ~
23329 buffer point 
23330 \newline 
23331 ;;\SpecialChar ~
23332 g\SpecialChar ~
23333 \SpecialChar ~
23334 \SpecialChar ~
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 sdcdbsrc-goto-sdcdb\SpecialChar ~
23348 \SpecialChar ~
23349 \SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 \SpecialChar ~
23355 \SpecialChar ~
23356 \SpecialChar ~
23357 Goto the SDCDB output buffer 
23358 \newline 
23359 ;;\SpecialChar ~
23360 t\SpecialChar ~
23361 \SpecialChar ~
23362 \SpecialChar ~
23363 \SpecialChar ~
23364 \SpecialChar ~
23365 \SpecialChar ~
23366 \SpecialChar ~
23367 \SpecialChar ~
23368 \SpecialChar ~
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 \SpecialChar ~
23372 \SpecialChar ~
23373 \SpecialChar ~
23374 \SpecialChar ~
23375 sdcdbsrc-mode\SpecialChar ~
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 \SpecialChar ~
23379 \SpecialChar ~
23380 \SpecialChar ~
23381 \SpecialChar ~
23382 \SpecialChar ~
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 \SpecialChar ~
23386 \SpecialChar ~
23387 \SpecialChar ~
23388 \SpecialChar ~
23389 \SpecialChar ~
23390 \SpecialChar ~
23391 Toggles Sdcdbsrc mode (turns it off) 
23392 \newline 
23393 ;; 
23394 \newline 
23395 ;;\SpecialChar ~
23396 C-c\SpecialChar ~
23397 C-f\SpecialChar ~
23398 \SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 \SpecialChar ~
23403 \SpecialChar ~
23404 \SpecialChar ~
23405 \SpecialChar ~
23406 sdcdb-finish-from-src\SpecialChar ~
23407 \SpecialChar ~
23408 \SpecialChar ~
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 \SpecialChar ~
23414 SDCDB finish command 
23415 \newline 
23416 ;; 
23417 \newline 
23418 ;;\SpecialChar ~
23419 C-x\SpecialChar ~
23420 SPC\SpecialChar ~
23421 \SpecialChar ~
23422 \SpecialChar ~
23423 \SpecialChar ~
23424 \SpecialChar ~
23425 \SpecialChar ~
23426 \SpecialChar ~
23427 \SpecialChar ~
23428 \SpecialChar ~
23429 sdcdb-break\SpecialChar ~
23430 \SpecialChar ~
23431 \SpecialChar ~
23432 \SpecialChar ~
23433 \SpecialChar ~
23434 \SpecialChar ~
23435 \SpecialChar ~
23436 \SpecialChar ~
23437 \SpecialChar ~
23438 \SpecialChar ~
23439 \SpecialChar ~
23440 \SpecialChar ~
23441 \SpecialChar ~
23442 \SpecialChar ~
23443 \SpecialChar ~
23444 \SpecialChar ~
23445 \SpecialChar ~
23446 \SpecialChar ~
23447 Set break for line with point 
23448 \newline 
23449 ;;\SpecialChar ~
23450 ESC\SpecialChar ~
23451 t\SpecialChar ~
23452 \SpecialChar ~
23453 \SpecialChar ~
23454 \SpecialChar ~
23455 \SpecialChar ~
23456 \SpecialChar ~
23457 \SpecialChar ~
23458 \SpecialChar ~
23459 \SpecialChar ~
23460 \SpecialChar ~
23461 \SpecialChar ~
23462 sdcdbsrc-mode\SpecialChar ~
23463 \SpecialChar ~
23464 \SpecialChar ~
23465 \SpecialChar ~
23466 \SpecialChar ~
23467 \SpecialChar ~
23468 \SpecialChar ~
23469 \SpecialChar ~
23470 \SpecialChar ~
23471 \SpecialChar ~
23472 \SpecialChar ~
23473 \SpecialChar ~
23474 \SpecialChar ~
23475 \SpecialChar ~
23476 \SpecialChar ~
23477 \SpecialChar ~
23478 Toggle Sdcdbsrc mode 
23479 \newline 
23480 ;;\SpecialChar ~
23481 ESC\SpecialChar ~
23482 m\SpecialChar ~
23483 \SpecialChar ~
23484 \SpecialChar ~
23485 \SpecialChar ~
23486 \SpecialChar ~
23487 \SpecialChar ~
23488 \SpecialChar ~
23489 \SpecialChar ~
23490 \SpecialChar ~
23491 \SpecialChar ~
23492 \SpecialChar ~
23493 sdcdbsrc-srcmode\SpecialChar ~
23494 \SpecialChar ~
23495 \SpecialChar ~
23496 \SpecialChar ~
23497 \SpecialChar ~
23498 \SpecialChar ~
23499 \SpecialChar ~
23500 \SpecialChar ~
23501 \SpecialChar ~
23502 \SpecialChar ~
23503 \SpecialChar ~
23504 \SpecialChar ~
23505 \SpecialChar ~
23506 Toggle list mode 
23507 \newline 
23508 ;; 
23509 \newline 
23510
23511 \layout Chapter
23512 \pagebreak_top 
23513 TIPS
23514 \layout Standard
23515
23516 Here are a few guidelines that will help the compiler generate more efficient
23517  code, some of the tips are specific to this compiler others are generally
23518  good programming practice.
23519 \layout Itemize
23520
23521 Use the smallest data type to represent your data-value.
23522  If it is known in advance that the value is going to be less than 256 then
23523  use an 'unsigned char' instead of a 'short' or 'int'.
23524  Please note, that ANSI C requires both signed and unsigned chars to be
23525  promoted to 'signed int'
23526 \begin_inset LatexCommand \index{promotion to signed int}
23527
23528 \end_inset 
23529
23530
23531 \begin_inset Marginal
23532 collapsed true
23533
23534 \layout Standard
23535
23536
23537 \series bold 
23538 \SpecialChar ~
23539 !
23540 \end_inset 
23541
23542  before doing any operation.
23543  This promotion
23544 \begin_inset LatexCommand \index{type promotion}
23545
23546 \end_inset 
23547
23548
23549 \begin_inset LatexCommand \label{type promotion}
23550
23551 \end_inset 
23552
23553  can be omitted, if the result is the same.
23554  The effect of the promotion rules together with the sign-extension is often
23555  surprising:
23556 \begin_deeper 
23557 \layout Verse
23558
23559
23560 \family typewriter 
23561 unsigned char uc = 0xfe;
23562 \newline 
23563 if (uc * uc < 0) /* this is true! */
23564 \newline 
23565 {
23566 \newline 
23567 \SpecialChar ~
23568 \SpecialChar ~
23569 \SpecialChar ~
23570 \SpecialChar ~
23571 ....
23572 \newline 
23573 }
23574 \layout Standard
23575
23576
23577 \family typewriter 
23578 uc * uc
23579 \family default 
23580  is evaluated as 
23581 \family typewriter 
23582 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23583 \family default 
23584 .
23585  
23586 \newline 
23587 Another one:
23588 \layout Verse
23589
23590
23591 \family typewriter 
23592 (unsigned char) -12 / (signed char) -3 = ...
23593 \layout Standard
23594
23595 No, the result is not 4:
23596 \layout Verse
23597
23598
23599 \family typewriter 
23600 (int) (unsigned char) -12 / (int) (signed char) -3 =
23601 \newline 
23602 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23603 \newline 
23604 (int) 0x00f4 / (int) 0xfffd =
23605 \newline 
23606 (int) 0x00f4 / (int) 0xfffd =
23607 \newline 
23608 (int) 244 / (int) -3 =
23609 \newline 
23610 (int) -81 = (int) 0xffaf;
23611 \layout Standard
23612
23613 Don't complain, that gcc gives you a different result.
23614  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23615  Therefore the results are different.
23616 \newline 
23617 From 
23618 \begin_inset Quotes sld
23619 \end_inset 
23620
23621 comp.lang.c FAQ
23622 \begin_inset Quotes srd
23623 \end_inset 
23624
23625 :
23626 \layout Quote
23627
23628
23629 \emph on 
23630 If well-defined overflow characteristics are important and negative values
23631  are not, or if you want to steer clear of sign-extension problems when
23632  manipulating bits or bytes, use one of the corresponding unsigned types.
23633  (Beware when mixing signed and unsigned values in expressions, though.)
23634 \newline 
23635 Although character types (especially unsigned char) can be used as "tiny"
23636  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23637 ble sign extension and increased code size.
23638 \end_deeper 
23639 \layout Itemize
23640
23641 Use unsigned when it is known in advance that the value is not going to
23642  be negative.
23643  This helps especially if you are doing division or multiplication, bit-shifting
23644  or are using an array index.
23645 \layout Itemize
23646
23647 NEVER jump into a LOOP.
23648 \layout Itemize
23649
23650 Declare the variables to be local
23651 \begin_inset LatexCommand \index{local variables}
23652
23653 \end_inset 
23654
23655  whenever possible, especially loop control variables (induction).
23656 \layout Itemize
23657
23658 Since the compiler does not always do implicit integral promotion, the programme
23659 r should do an explicit cast when integral promotion is required.
23660 \layout Itemize
23661
23662 Reducing the size of division, multiplication & modulus operations can reduce
23663  code size substantially.
23664  Take the following code for example.
23665 \begin_deeper 
23666 \layout Verse
23667
23668
23669 \family typewriter 
23670 foobar(unsigned int p1, unsigned char ch)
23671 \newline 
23672 {
23673 \newline 
23674 \SpecialChar ~
23675 \SpecialChar ~
23676 \SpecialChar ~
23677 \SpecialChar ~
23678 unsigned char ch1 = p1 % ch ;
23679 \newline 
23680 \SpecialChar ~
23681 \SpecialChar ~
23682 \SpecialChar ~
23683 \SpecialChar ~
23684 ....
23685 \newline 
23686 }
23687 \layout Standard
23688
23689 For the modulus operation the variable ch will be promoted to unsigned int
23690  first then the modulus operation will be performed (this will lead to a
23691  call to support routine _moduint()), and the result will be casted to a
23692  char.
23693  If the code is changed to 
23694 \layout Verse
23695
23696
23697 \family typewriter 
23698 foobar(unsigned int p1, unsigned char ch)
23699 \newline 
23700 {
23701 \newline 
23702 \SpecialChar ~
23703 \SpecialChar ~
23704 \SpecialChar ~
23705 \SpecialChar ~
23706 unsigned char ch1 = (unsigned char)p1 % ch ;
23707 \newline 
23708 \SpecialChar ~
23709 \SpecialChar ~
23710 \SpecialChar ~
23711 \SpecialChar ~
23712 ....
23713 \newline 
23714 }
23715 \layout Standard
23716
23717 It would substantially reduce the code generated (future versions of the
23718  compiler will be smart enough to detect such optimization opportunities).
23719 \end_deeper 
23720 \layout Itemize
23721
23722 Have a look at the assembly listing to get a 
23723 \begin_inset Quotes sld
23724 \end_inset 
23725
23726 feeling
23727 \begin_inset Quotes srd
23728 \end_inset 
23729
23730  for the code generation.
23731 \layout Section
23732
23733 Porting code from or to other compilers
23734 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23735
23736 \end_inset 
23737
23738
23739 \layout Itemize
23740
23741 check whether endianness of the compilers differs and adapt where needed.
23742 \layout Itemize
23743
23744 check the device specific header files
23745 \begin_inset LatexCommand \index{Header files}
23746
23747 \end_inset 
23748
23749
23750 \begin_inset LatexCommand \index{Include files}
23751
23752 \end_inset 
23753
23754  for compiler specific syntax.
23755  Eventually include the file <compiler.h
23756 \begin_inset LatexCommand \index{compiler.h (include file)}
23757
23758 \end_inset 
23759
23760
23761 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23762
23763 \end_inset 
23764
23765  to allow using common header files.
23766  (see f.e.
23767  cc2510fx.h 
23768 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23769
23770 \end_inset 
23771
23772 ).
23773 \layout Itemize
23774
23775 check whether the startup code contains the correct initialization (watchdog,
23776  peripherals).
23777 \layout Itemize
23778
23779 check whether the sizes of short, int, long match.
23780 \layout Itemize
23781
23782 check if some 16 or 32 bit hardware registers require a specific addressing
23783  order (least significant or most significant byte first) and adapt if needed
23784  (
23785 \emph on 
23786 first
23787 \emph default 
23788  and 
23789 \emph on 
23790 last
23791 \emph default 
23792  relate to time and not to lower/upper memory location here, so this is
23793  
23794 \emph on 
23795 not
23796 \emph default 
23797  the same as endianness).
23798 \layout Itemize
23799
23800 check whether the keyword 
23801 \emph on 
23802 volatile
23803 \emph default 
23804  is used where needed.
23805  The compilers might differ in their optimization characteristics (as different
23806  versions of the same compiler might also use more clever optimizations
23807  this is good idea anyway).
23808  See section 
23809 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23810
23811 \end_inset 
23812
23813 .
23814 \layout Itemize
23815
23816 check that the compilers are not told to supress warnings.
23817 \layout Itemize
23818
23819 check and convert compiler specific extensions (interrupts, memory areas,
23820  pragmas etc.).
23821 \layout Itemize
23822
23823 check for differences in type promotion.
23824  Especially check for math operations on 
23825 \family typewriter 
23826 char
23827 \family default 
23828  or 
23829 \family typewriter 
23830 unsigned char
23831 \family default 
23832  variables.
23833  For the sake of C99 compatibility SDCC will probably promote these to 
23834 \family typewriter 
23835 int
23836 \family default 
23837  more often than other compilers.
23838  Eventually insert explicit casts to 
23839 \family typewriter 
23840 (char) 
23841 \family default 
23842 or
23843 \family typewriter 
23844  (unsigned char)
23845 \family default 
23846 .
23847  Also check that the ~\SpecialChar ~
23848 operator
23849 \begin_inset LatexCommand \index{\~\/ Operator}
23850
23851 \end_inset 
23852
23853  is not used on 
23854 \family typewriter 
23855 bit
23856 \begin_inset LatexCommand \index{bit}
23857
23858 \end_inset 
23859
23860
23861 \family default 
23862  variables, use the !\SpecialChar ~
23863 operator instead.
23864  See sections 
23865 \begin_inset LatexCommand \ref{type promotion}
23866
23867 \end_inset 
23868
23869  and 
23870 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23871
23872 \end_inset 
23873
23874 .
23875 \layout Itemize
23876
23877 check the assembly code generated for interrupt routines (f.e.
23878  for calls to possibly non-reentrant library functions).
23879 \layout Itemize
23880
23881 check whether timing loops result in proper timing (or preferably consider
23882  a rewrite of the code with timer based delays instead).
23883 \layout Itemize
23884
23885 check for differences in printf parameters (some compilers push (va_arg
23886 \begin_inset LatexCommand \index{vararg, va\_arg}
23887
23888 \end_inset 
23889
23890 ) char variables as 
23891 \family typewriter 
23892 int
23893 \family default 
23894  others push them as 
23895 \family typewriter 
23896 char
23897 \family default 
23898 .
23899  See section 
23900 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23901
23902 \end_inset 
23903
23904 ).
23905 \layout Itemize
23906
23907 check the resulting memory map
23908 \begin_inset LatexCommand \index{Memory map}
23909
23910 \end_inset 
23911
23912 .
23913  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23914 ly idata, pdata, xdata).
23915  Eventually check if unexpected library functions are included.
23916 \layout Section
23917
23918 Tools
23919 \begin_inset LatexCommand \index{Tools}
23920
23921 \end_inset 
23922
23923  included in the distribution
23924 \layout Standard
23925 \align left 
23926
23927 \begin_inset  Tabular
23928 <lyxtabular version="3" rows="12" columns="3">
23929 <features>
23930 <column alignment="left" valignment="top" leftline="true" width="0pt">
23931 <column alignment="left" valignment="top" leftline="true" width="0pt">
23932 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23933 <row topline="true" bottomline="true">
23934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23935 \begin_inset Text
23936
23937 \layout Standard
23938
23939 Name
23940 \end_inset 
23941 </cell>
23942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23943 \begin_inset Text
23944
23945 \layout Standard
23946
23947 Purpose
23948 \end_inset 
23949 </cell>
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23951 \begin_inset Text
23952
23953 \layout Standard
23954
23955 Directory
23956 \end_inset 
23957 </cell>
23958 </row>
23959 <row topline="true">
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23961 \begin_inset Text
23962
23963 \layout Standard
23964
23965 ucSsim
23966 \end_inset 
23967 </cell>
23968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23969 \begin_inset Text
23970
23971 \layout Standard
23972
23973 Simulator for various architectures
23974 \end_inset 
23975 </cell>
23976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23977 \begin_inset Text
23978
23979 \layout Standard
23980
23981 sdcc/sim/ucsim
23982 \end_inset 
23983 </cell>
23984 </row>
23985 <row topline="true">
23986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23987 \begin_inset Text
23988
23989 \layout Standard
23990
23991 keil2sdcc.pl
23992 \end_inset 
23993 </cell>
23994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23995 \begin_inset Text
23996
23997 \layout Standard
23998
23999 header file
24000 \begin_inset LatexCommand \index{Header files}
24001
24002 \end_inset 
24003
24004
24005 \begin_inset LatexCommand \index{Include files}
24006
24007 \end_inset 
24008
24009  conversion
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 sdcc/support/scripts
24018 \end_inset 
24019 </cell>
24020 </row>
24021 <row topline="true">
24022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24023 \begin_inset Text
24024
24025 \layout Standard
24026
24027 mh2h.c
24028 \end_inset 
24029 </cell>
24030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24031 \begin_inset Text
24032
24033 \layout Standard
24034
24035 header file conversion
24036 \end_inset 
24037 </cell>
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24039 \begin_inset Text
24040
24041 \layout Standard
24042
24043 sdcc/support/scripts
24044 \end_inset 
24045 </cell>
24046 </row>
24047 <row topline="true">
24048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24049 \begin_inset Text
24050
24051 \layout Standard
24052
24053 as-gbz80
24054 \end_inset 
24055 </cell>
24056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24057 \begin_inset Text
24058
24059 \layout Standard
24060
24061 Assembler
24062 \end_inset 
24063 </cell>
24064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24065 \begin_inset Text
24066
24067 \layout Standard
24068
24069
24070 \family roman 
24071 \series medium 
24072 \shape up 
24073 \size normal 
24074 \emph off 
24075 \bar no 
24076 \noun off 
24077 \color none
24078 sdcc/bin
24079 \end_inset 
24080 </cell>
24081 </row>
24082 <row topline="true">
24083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24084 \begin_inset Text
24085
24086 \layout Standard
24087
24088 as-z80
24089 \end_inset 
24090 </cell>
24091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24092 \begin_inset Text
24093
24094 \layout Standard
24095
24096 Assembler
24097 \end_inset 
24098 </cell>
24099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24100 \begin_inset Text
24101
24102 \layout Standard
24103
24104
24105 \family roman 
24106 \series medium 
24107 \shape up 
24108 \size normal 
24109 \emph off 
24110 \bar no 
24111 \noun off 
24112 \color none
24113 sdcc/bin
24114 \end_inset 
24115 </cell>
24116 </row>
24117 <row topline="true">
24118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24119 \begin_inset Text
24120
24121 \layout Standard
24122
24123 asx8051
24124 \end_inset 
24125 </cell>
24126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24127 \begin_inset Text
24128
24129 \layout Standard
24130
24131 Assembler
24132 \end_inset 
24133 </cell>
24134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24135 \begin_inset Text
24136
24137 \layout Standard
24138
24139
24140 \family roman 
24141 \series medium 
24142 \shape up 
24143 \size normal 
24144 \emph off 
24145 \bar no 
24146 \noun off 
24147 \color none
24148 sdcc/bin
24149 \end_inset 
24150 </cell>
24151 </row>
24152 <row topline="true">
24153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24154 \begin_inset Text
24155
24156 \layout Standard
24157
24158 SDCDB
24159 \end_inset 
24160 </cell>
24161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24162 \begin_inset Text
24163
24164 \layout Standard
24165
24166 Simulator
24167 \end_inset 
24168 </cell>
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24170 \begin_inset Text
24171
24172 \layout Standard
24173
24174
24175 \family roman 
24176 \series medium 
24177 \shape up 
24178 \size normal 
24179 \emph off 
24180 \bar no 
24181 \noun off 
24182 \color none
24183 sdcc/bin
24184 \end_inset 
24185 </cell>
24186 </row>
24187 <row topline="true">
24188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24189 \begin_inset Text
24190
24191 \layout Standard
24192
24193 aslink
24194 \end_inset 
24195 </cell>
24196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24197 \begin_inset Text
24198
24199 \layout Standard
24200
24201 Linker
24202 \end_inset 
24203 </cell>
24204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24205 \begin_inset Text
24206
24207 \layout Standard
24208
24209
24210 \family roman 
24211 \series medium 
24212 \shape up 
24213 \size normal 
24214 \emph off 
24215 \bar no 
24216 \noun off 
24217 \color none
24218 sdcc/bin
24219 \end_inset 
24220 </cell>
24221 </row>
24222 <row topline="true">
24223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24224 \begin_inset Text
24225
24226 \layout Standard
24227
24228 link-z80
24229 \end_inset 
24230 </cell>
24231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24232 \begin_inset Text
24233
24234 \layout Standard
24235
24236 Linker
24237 \end_inset 
24238 </cell>
24239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24240 \begin_inset Text
24241
24242 \layout Standard
24243
24244
24245 \family roman 
24246 \series medium 
24247 \shape up 
24248 \size normal 
24249 \emph off 
24250 \bar no 
24251 \noun off 
24252 \color none
24253 sdcc/bin
24254 \end_inset 
24255 </cell>
24256 </row>
24257 <row topline="true">
24258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24259 \begin_inset Text
24260
24261 \layout Standard
24262
24263 link-gbz80
24264 \end_inset 
24265 </cell>
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24267 \begin_inset Text
24268
24269 \layout Standard
24270
24271 Linker
24272 \end_inset 
24273 </cell>
24274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24275 \begin_inset Text
24276
24277 \layout Standard
24278
24279
24280 \family roman 
24281 \series medium 
24282 \shape up 
24283 \size normal 
24284 \emph off 
24285 \bar no 
24286 \noun off 
24287 \color none
24288 sdcc/bin
24289 \end_inset 
24290 </cell>
24291 </row>
24292 <row topline="true" bottomline="true">
24293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24294 \begin_inset Text
24295
24296 \layout Standard
24297
24298 packihx
24299 \end_inset 
24300 </cell>
24301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24302 \begin_inset Text
24303
24304 \layout Standard
24305
24306 Intel Hex packer 
24307 \begin_inset LatexCommand \index{packihx (tool)}
24308
24309 \end_inset 
24310
24311
24312 \end_inset 
24313 </cell>
24314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24315 \begin_inset Text
24316
24317 \layout Standard
24318
24319
24320 \family roman 
24321 \series medium 
24322 \shape up 
24323 \size normal 
24324 \emph off 
24325 \bar no 
24326 \noun off 
24327 \color none
24328 sdcc/bin
24329 \end_inset 
24330 </cell>
24331 </row>
24332 </lyxtabular>
24333
24334 \end_inset 
24335
24336
24337 \newline 
24338
24339 \layout Section
24340
24341 Documentation
24342 \begin_inset LatexCommand \index{Documentation}
24343
24344 \end_inset 
24345
24346  included in the distribution
24347 \layout Standard
24348 \align left 
24349
24350 \begin_inset  Tabular
24351 <lyxtabular version="3" rows="10" columns="2">
24352 <features>
24353 <column alignment="left" valignment="top" leftline="true" width="0">
24354 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24355 <row topline="true" bottomline="true">
24356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24357 \begin_inset Text
24358
24359 \layout Standard
24360
24361 Subject / Title
24362 \end_inset 
24363 </cell>
24364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24365 \begin_inset Text
24366
24367 \layout Standard
24368
24369 Where to get / filename
24370 \end_inset 
24371 </cell>
24372 </row>
24373 <row topline="true">
24374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24375 \begin_inset Text
24376
24377 \layout Standard
24378
24379 SDCC Compiler User Guide
24380 \end_inset 
24381 </cell>
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24383 \begin_inset Text
24384
24385 \layout Standard
24386
24387 You're reading it right now
24388 \end_inset 
24389 </cell>
24390 </row>
24391 <row topline="true">
24392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24393 \begin_inset Text
24394
24395 \layout Standard
24396
24397 Changelog of SDCC
24398 \end_inset 
24399 </cell>
24400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24401 \begin_inset Text
24402
24403 \layout Standard
24404
24405 sdcc/Changelog
24406 \end_inset 
24407 </cell>
24408 </row>
24409 <row topline="true">
24410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24411 \begin_inset Text
24412
24413 \layout Standard
24414
24415 ASXXXX
24416 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24417
24418 \end_inset 
24419
24420
24421 \begin_inset LatexCommand \index{Assembler documentation}
24422
24423 \end_inset 
24424
24425  Assemblers and ASLINK
24426 \begin_inset LatexCommand \index{aslink}
24427
24428 \end_inset 
24429
24430
24431 \begin_inset LatexCommand \index{Linker documentation}
24432
24433 \end_inset 
24434
24435  Relocating Linker
24436 \end_inset 
24437 </cell>
24438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24439 \begin_inset Text
24440
24441 \layout Standard
24442
24443 sdcc/as/doc/asxhtm.html
24444 \end_inset 
24445 </cell>
24446 </row>
24447 <row topline="true">
24448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24449 \begin_inset Text
24450
24451 \layout Standard
24452
24453 SDCC regression test
24454 \begin_inset LatexCommand \index{Regression test}
24455
24456 \end_inset 
24457
24458
24459 \end_inset 
24460 </cell>
24461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24462 \begin_inset Text
24463
24464 \layout Standard
24465
24466 sdcc/doc/test_suite_spec.pdf
24467 \end_inset 
24468 </cell>
24469 </row>
24470 <row topline="true">
24471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24472 \begin_inset Text
24473
24474 \layout Standard
24475
24476 Various notes
24477 \end_inset 
24478 </cell>
24479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24480 \begin_inset Text
24481
24482 \layout Standard
24483
24484 sdcc/doc/*
24485 \end_inset 
24486 </cell>
24487 </row>
24488 <row topline="true">
24489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24490 \begin_inset Text
24491
24492 \layout Standard
24493
24494 Notes on debugging with SDCDB
24495 \begin_inset LatexCommand \index{SDCDB (debugger)}
24496
24497 \end_inset 
24498
24499
24500 \end_inset 
24501 </cell>
24502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24503 \begin_inset Text
24504
24505 \layout Standard
24506
24507 sdcc/debugger/README
24508 \end_inset 
24509 </cell>
24510 </row>
24511 <row topline="true">
24512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24513 \begin_inset Text
24514
24515 \layout Standard
24516
24517 Software simulator for microcontrollers
24518 \end_inset 
24519 </cell>
24520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24521 \begin_inset Text
24522
24523 \layout Standard
24524
24525
24526 \family roman 
24527 \series medium 
24528 \shape up 
24529 \size normal 
24530 \emph off 
24531 \bar no 
24532 \noun off 
24533 \color none
24534 sdcc/sim/ucsim/doc
24535 \family default 
24536 \series default 
24537 \shape default 
24538 \size default 
24539 \emph default 
24540 \bar default 
24541 \noun default 
24542 \color default
24543 /index.html
24544 \end_inset 
24545 </cell>
24546 </row>
24547 <row topline="true">
24548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24549 \begin_inset Text
24550
24551 \layout Standard
24552
24553 Temporary notes on the pic16
24554 \begin_inset LatexCommand \index{PIC16}
24555
24556 \end_inset 
24557
24558  port
24559 \end_inset 
24560 </cell>
24561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24562 \begin_inset Text
24563
24564 \layout Standard
24565
24566 sdcc/src/pic16/NOTES
24567 \end_inset 
24568 </cell>
24569 </row>
24570 <row topline="true" bottomline="true">
24571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24572 \begin_inset Text
24573
24574 \layout Standard
24575
24576 SDCC internal documentation (debugging file format)
24577 \end_inset 
24578 </cell>
24579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24580 \begin_inset Text
24581
24582 \layout Standard
24583
24584 sdcc/doc/
24585 \family roman 
24586 \series medium 
24587 \shape up 
24588 \size normal 
24589 \emph off 
24590 \bar no 
24591 \noun off 
24592 \color none
24593 cdbfileformat.pd
24594 \family default 
24595 \series default 
24596 \shape default 
24597 \size default 
24598 \emph default 
24599 \bar default 
24600 \noun default 
24601 \color default
24602 f
24603 \end_inset 
24604 </cell>
24605 </row>
24606 </lyxtabular>
24607
24608 \end_inset 
24609
24610
24611 \newline 
24612
24613 \layout Section
24614
24615 Related open source tools
24616 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24617
24618 \end_inset 
24619
24620
24621 \begin_inset LatexCommand \index{Related tools}
24622
24623 \end_inset 
24624
24625
24626 \layout Standard
24627 \align left 
24628
24629 \begin_inset  Tabular
24630 <lyxtabular version="3" rows="14" columns="3">
24631 <features>
24632 <column alignment="left" valignment="top" leftline="true" width="0pt">
24633 <column alignment="block" valignment="top" leftline="true" width="30line%">
24634 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24635 <row topline="true" bottomline="true">
24636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24637 \begin_inset Text
24638
24639 \layout Standard
24640
24641 Name
24642 \end_inset 
24643 </cell>
24644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24645 \begin_inset Text
24646
24647 \layout Standard
24648
24649 Purpose
24650 \end_inset 
24651 </cell>
24652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24653 \begin_inset Text
24654
24655 \layout Standard
24656
24657 Where to get
24658 \end_inset 
24659 </cell>
24660 </row>
24661 <row topline="true">
24662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24663 \begin_inset Text
24664
24665 \layout Standard
24666
24667 gpsim
24668 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24669
24670 \end_inset 
24671
24672
24673 \end_inset 
24674 </cell>
24675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24676 \begin_inset Text
24677
24678 \layout Standard
24679
24680 PIC simulator
24681 \end_inset 
24682 </cell>
24683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24684 \begin_inset Text
24685
24686 \layout Standard
24687
24688
24689 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24690
24691 \end_inset 
24692
24693
24694 \end_inset 
24695 </cell>
24696 </row>
24697 <row topline="true">
24698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24699 \begin_inset Text
24700
24701 \layout Standard
24702
24703 gputils
24704 \begin_inset LatexCommand \index{gputils (pic tools)}
24705
24706 \end_inset 
24707
24708
24709 \end_inset 
24710 </cell>
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24712 \begin_inset Text
24713
24714 \layout Standard
24715
24716 GNU PIC utilities
24717 \end_inset 
24718 </cell>
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24720 \begin_inset Text
24721
24722 \layout Standard
24723
24724
24725 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24726
24727 \end_inset 
24728
24729
24730 \end_inset 
24731 </cell>
24732 </row>
24733 <row topline="true">
24734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24735 \begin_inset Text
24736
24737 \layout Standard
24738
24739 flP5
24740 \end_inset 
24741 </cell>
24742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24743 \begin_inset Text
24744
24745 \layout Standard
24746
24747 PIC programmer
24748 \end_inset 
24749 </cell>
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24751 \begin_inset Text
24752
24753 \layout Standard
24754
24755
24756 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24757
24758 \end_inset 
24759
24760
24761 \end_inset 
24762 </cell>
24763 </row>
24764 <row topline="true">
24765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24766 \begin_inset Text
24767
24768 \layout Standard
24769
24770 ec2drv/newcdb
24771 \end_inset 
24772 </cell>
24773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24774 \begin_inset Text
24775
24776 \layout Standard
24777
24778 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24779  (Unix only)
24780 \end_inset 
24781 </cell>
24782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24783 \begin_inset Text
24784
24785 \layout Standard
24786
24787
24788 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24789
24790 \end_inset 
24791
24792
24793 \end_inset 
24794 </cell>
24795 </row>
24796 <row topline="true">
24797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24798 \begin_inset Text
24799
24800 \layout Standard
24801
24802 indent
24803 \begin_inset LatexCommand \index{indent (source formatting tool)}
24804
24805 \end_inset 
24806
24807
24808 \end_inset 
24809 </cell>
24810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24811 \begin_inset Text
24812
24813 \layout Standard
24814
24815 Formats C source - Master of the white spaces
24816 \end_inset 
24817 </cell>
24818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24819 \begin_inset Text
24820
24821 \layout Standard
24822
24823
24824 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24825
24826 \end_inset 
24827
24828
24829 \end_inset 
24830 </cell>
24831 </row>
24832 <row topline="true">
24833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24834 \begin_inset Text
24835
24836 \layout Standard
24837
24838 srecord
24839 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24840
24841 \end_inset 
24842
24843
24844 \end_inset 
24845 </cell>
24846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24847 \begin_inset Text
24848
24849 \layout Standard
24850
24851 Object file conversion, checksumming, ...
24852 \end_inset 
24853 </cell>
24854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24855 \begin_inset Text
24856
24857 \layout Standard
24858
24859
24860 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24861
24862 \end_inset 
24863
24864
24865 \end_inset 
24866 </cell>
24867 </row>
24868 <row topline="true">
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24870 \begin_inset Text
24871
24872 \layout Standard
24873
24874 objdump
24875 \begin_inset LatexCommand \index{objdump (tool)}
24876
24877 \end_inset 
24878
24879
24880 \end_inset 
24881 </cell>
24882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24883 \begin_inset Text
24884
24885 \layout Standard
24886
24887 Object file conversion, ...
24888 \end_inset 
24889 </cell>
24890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24891 \begin_inset Text
24892
24893 \layout Standard
24894
24895 Part of binutils (should be there anyway)
24896 \end_inset 
24897 </cell>
24898 </row>
24899 <row topline="true">
24900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24901 \begin_inset Text
24902
24903 \layout Standard
24904
24905 cmon51
24906 \end_inset 
24907 </cell>
24908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24909 \begin_inset Text
24910
24911 \layout Standard
24912
24913 8051 monitor (hex up-/download, single step, disassemble)
24914 \end_inset 
24915 </cell>
24916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24917 \begin_inset Text
24918
24919 \layout Standard
24920
24921
24922 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24923
24924 \end_inset 
24925
24926
24927 \end_inset 
24928 </cell>
24929 </row>
24930 <row topline="true">
24931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24932 \begin_inset Text
24933
24934 \layout Standard
24935
24936 doxygen
24937 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24938
24939 \end_inset 
24940
24941
24942 \end_inset 
24943 </cell>
24944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24945 \begin_inset Text
24946
24947 \layout Standard
24948
24949 Source code documentation system
24950 \end_inset 
24951 </cell>
24952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24953 \begin_inset Text
24954
24955 \layout Standard
24956
24957
24958 \begin_inset LatexCommand \url{http://www.doxygen.org}
24959
24960 \end_inset 
24961
24962
24963 \end_inset 
24964 </cell>
24965 </row>
24966 <row topline="true">
24967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24968 \begin_inset Text
24969
24970 \layout Standard
24971
24972 kdevelop
24973 \end_inset 
24974 </cell>
24975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24976 \begin_inset Text
24977
24978 \layout Standard
24979
24980 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24981 \end_inset 
24982 </cell>
24983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24984 \begin_inset Text
24985
24986 \layout Standard
24987
24988
24989 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24990
24991 \end_inset 
24992
24993
24994 \end_inset 
24995 </cell>
24996 </row>
24997 <row topline="true">
24998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24999 \begin_inset Text
25000
25001 \layout Standard
25002
25003 paulmon
25004 \end_inset 
25005 </cell>
25006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25007 \begin_inset Text
25008
25009 \layout Standard
25010
25011 8051 monitor (hex up-/download, single step, disassemble)
25012 \end_inset 
25013 </cell>
25014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25015 \begin_inset Text
25016
25017 \layout Standard
25018
25019
25020 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
25021
25022 \end_inset 
25023
25024
25025 \end_inset 
25026 </cell>
25027 </row>
25028 <row topline="true">
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25030 \begin_inset Text
25031
25032 \layout Standard
25033
25034 splint
25035 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25036
25037 \end_inset 
25038
25039
25040 \end_inset 
25041 </cell>
25042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25043 \begin_inset Text
25044
25045 \layout Standard
25046
25047 Statically checks c sources (see 
25048 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25049
25050 \end_inset 
25051
25052 )
25053 \end_inset 
25054 </cell>
25055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25056 \begin_inset Text
25057
25058 \layout Standard
25059
25060
25061 \begin_inset LatexCommand \url{http://www.splint.org}
25062
25063 \end_inset 
25064
25065
25066 \end_inset 
25067 </cell>
25068 </row>
25069 <row topline="true" bottomline="true">
25070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25071 \begin_inset Text
25072
25073 \layout Standard
25074
25075 ddd
25076 \begin_inset LatexCommand \index{DDD (debugger)}
25077
25078 \end_inset 
25079
25080
25081 \end_inset 
25082 </cell>
25083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25084 \begin_inset Text
25085
25086 \layout Standard
25087
25088 Debugger, serves nicely as GUI to SDCDB
25089 \begin_inset LatexCommand \index{SDCDB (debugger)}
25090
25091 \end_inset 
25092
25093  (Unix only)
25094 \end_inset 
25095 </cell>
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25097 \begin_inset Text
25098
25099 \layout Standard
25100
25101
25102 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
25103
25104 \end_inset 
25105
25106
25107 \end_inset 
25108 </cell>
25109 </row>
25110 </lyxtabular>
25111
25112 \end_inset 
25113
25114
25115 \newline 
25116
25117 \layout Section
25118
25119 Related documentation / recommended reading
25120 \layout Standard
25121 \align left 
25122
25123 \begin_inset  Tabular
25124 <lyxtabular version="3" rows="7" columns="3">
25125 <features>
25126 <column alignment="left" valignment="top" leftline="true" width="0pt">
25127 <column alignment="center" valignment="top" leftline="true" width="0">
25128 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25129 <row topline="true" bottomline="true">
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25131 \begin_inset Text
25132
25133 \layout Standard
25134
25135 Name
25136 \end_inset 
25137 </cell>
25138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25139 \begin_inset Text
25140
25141 \layout Standard
25142
25143 Subject / Title
25144 \end_inset 
25145 </cell>
25146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25147 \begin_inset Text
25148
25149 \layout Standard
25150
25151 Where to get
25152 \end_inset 
25153 </cell>
25154 </row>
25155 <row topline="true">
25156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25157 \begin_inset Text
25158
25159 \layout Standard
25160
25161
25162 \family roman 
25163 \series medium 
25164 \shape up 
25165 \size normal 
25166 \emph off 
25167 \bar no 
25168 \noun off 
25169 \color none
25170 c-refcard.pdf
25171 \end_inset 
25172 </cell>
25173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25174 \begin_inset Text
25175
25176 \layout Standard
25177
25178 C Reference Card
25179 \begin_inset LatexCommand \index{C Reference card}
25180
25181 \end_inset 
25182
25183 , 2 pages
25184 \end_inset 
25185 </cell>
25186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25187 \begin_inset Text
25188
25189 \layout Standard
25190
25191
25192 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25193
25194 \end_inset 
25195
25196
25197 \end_inset 
25198 </cell>
25199 </row>
25200 <row topline="true">
25201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25202 \begin_inset Text
25203
25204 \layout Standard
25205
25206 c-faq
25207 \end_inset 
25208 </cell>
25209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25210 \begin_inset Text
25211
25212 \layout Standard
25213
25214 C-FAQ
25215 \begin_inset LatexCommand \index{C FAQ}
25216
25217 \end_inset 
25218
25219
25220 \end_inset 
25221 </cell>
25222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25223 \begin_inset Text
25224
25225 \layout Standard
25226
25227
25228 \begin_inset LatexCommand \url{http://www.c-faq.com}
25229
25230 \end_inset 
25231
25232
25233 \end_inset 
25234 </cell>
25235 </row>
25236 <row topline="true">
25237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25238 \begin_inset Text
25239
25240 \layout Standard
25241
25242 ISO/IEC 9899:TC2
25243 \end_inset 
25244 </cell>
25245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25246 \begin_inset Text
25247
25248 \layout Standard
25249
25250
25251 \begin_inset Quotes sld
25252 \end_inset 
25253
25254 C-Standard
25255 \begin_inset Quotes srd
25256 \end_inset 
25257
25258
25259 \end_inset 
25260 </cell>
25261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25262 \begin_inset Text
25263
25264 \layout Standard
25265
25266
25267 \size footnotesize 
25268
25269 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25270
25271 \end_inset 
25272
25273
25274 \end_inset 
25275 </cell>
25276 </row>
25277 <row topline="true">
25278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25279 \begin_inset Text
25280
25281 \layout Standard
25282
25283 ISO/IEC DTR 18037
25284 \end_inset 
25285 </cell>
25286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25287 \begin_inset Text
25288
25289 \layout Standard
25290
25291
25292 \begin_inset Quotes sld
25293 \end_inset 
25294
25295 Extensions for Embedded C
25296 \begin_inset Quotes srd
25297 \end_inset 
25298
25299
25300 \end_inset 
25301 </cell>
25302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25303 \begin_inset Text
25304
25305 \layout Standard
25306
25307
25308 \size footnotesize 
25309
25310 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25311
25312 \end_inset 
25313
25314
25315 \end_inset 
25316 </cell>
25317 </row>
25318 <row topline="true">
25319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25320 \begin_inset Text
25321
25322 \layout Standard
25323
25324 \end_inset 
25325 </cell>
25326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25327 \begin_inset Text
25328
25329 \layout Standard
25330
25331 Latest datasheet of target CPU
25332 \end_inset 
25333 </cell>
25334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25335 \begin_inset Text
25336
25337 \layout Standard
25338
25339 vendor
25340 \end_inset 
25341 </cell>
25342 </row>
25343 <row topline="true" bottomline="true">
25344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25345 \begin_inset Text
25346
25347 \layout Standard
25348
25349 \end_inset 
25350 </cell>
25351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25352 \begin_inset Text
25353
25354 \layout Standard
25355
25356 Revision history of datasheet
25357 \end_inset 
25358 </cell>
25359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25360 \begin_inset Text
25361
25362 \layout Standard
25363
25364 vendor
25365 \end_inset 
25366 </cell>
25367 </row>
25368 </lyxtabular>
25369
25370 \end_inset 
25371
25372
25373 \newline 
25374
25375 \layout Section
25376
25377 Application notes specifically for SDCC
25378 \layout Standard
25379
25380 SDCC makes no claims about the completeness of this list and about up-to-datenes
25381 s or correctness of the application notes
25382 \begin_inset LatexCommand \index{Application notes}
25383
25384 \end_inset 
25385
25386 .
25387 \layout Standard
25388 \align left 
25389
25390 \size footnotesize 
25391
25392 \begin_inset  Tabular
25393 <lyxtabular version="3" rows="7" columns="3">
25394 <features>
25395 <column alignment="block" valignment="top" leftline="true" width="17col%">
25396 <column alignment="block" valignment="top" leftline="true" width="27col%">
25397 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25398 <row topline="true" bottomline="true">
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25400 \begin_inset Text
25401
25402 \layout Standard
25403
25404
25405 \size footnotesize 
25406 Vendor
25407 \end_inset 
25408 </cell>
25409 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25410 \begin_inset Text
25411
25412 \layout Standard
25413
25414
25415 \size footnotesize 
25416 Subject / Title
25417 \end_inset 
25418 </cell>
25419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25420 \begin_inset Text
25421
25422 \layout Standard
25423
25424
25425 \size footnotesize 
25426 Where to get
25427 \end_inset 
25428 </cell>
25429 </row>
25430 <row topline="true">
25431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25432 \begin_inset Text
25433
25434 \layout Standard
25435
25436
25437 \size footnotesize 
25438 Maxim / Dallas
25439 \end_inset 
25440 </cell>
25441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25442 \begin_inset Text
25443
25444 \layout Standard
25445
25446
25447 \size footnotesize 
25448 Using the SDCC Compiler for the DS80C400
25449 \begin_inset LatexCommand \index{DS80C400}
25450
25451 \end_inset 
25452
25453
25454 \end_inset 
25455 </cell>
25456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25457 \begin_inset Text
25458
25459 \layout Standard
25460
25461
25462 \size footnotesize 
25463
25464 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25465
25466 \end_inset 
25467
25468
25469 \end_inset 
25470 </cell>
25471 </row>
25472 <row topline="true">
25473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25474 \begin_inset Text
25475
25476 \layout Standard
25477
25478
25479 \size footnotesize 
25480 Maxim / Dallas
25481 \end_inset 
25482 </cell>
25483 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25484 \begin_inset Text
25485
25486 \layout Standard
25487
25488
25489 \size footnotesize 
25490 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25491 \begin_inset LatexCommand \index{DS89C4x0}
25492
25493 \end_inset 
25494
25495  Family of Microcontrollers
25496 \end_inset 
25497 </cell>
25498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25499 \begin_inset Text
25500
25501 \layout Standard
25502
25503
25504 \size footnotesize 
25505
25506 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25507
25508 \end_inset 
25509
25510
25511 \end_inset 
25512 </cell>
25513 </row>
25514 <row topline="true">
25515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25516 \begin_inset Text
25517
25518 \layout Standard
25519
25520
25521 \size footnotesize 
25522 Silicon Laboratories / Cygnal
25523 \end_inset 
25524 </cell>
25525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25526 \begin_inset Text
25527
25528 \layout Standard
25529
25530
25531 \size footnotesize 
25532 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25533 \begin_inset LatexCommand \index{IDE}
25534
25535 \end_inset 
25536
25537
25538 \end_inset 
25539 </cell>
25540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25541 \begin_inset Text
25542
25543 \layout Standard
25544
25545
25546 \size footnotesize 
25547
25548 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25549
25550 \end_inset 
25551
25552
25553 \end_inset 
25554 </cell>
25555 </row>
25556 <row topline="true">
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25558 \begin_inset Text
25559
25560 \layout Standard
25561
25562
25563 \size footnotesize 
25564 Ramtron / Goal Semiconductor
25565 \end_inset 
25566 </cell>
25567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25568 \begin_inset Text
25569
25570 \layout Standard
25571
25572
25573 \size footnotesize 
25574 Interfacing SDCC to Syn and Textpad
25575 \end_inset 
25576 </cell>
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25578 \begin_inset Text
25579
25580 \layout Standard
25581
25582
25583 \size footnotesize 
25584
25585 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25586
25587 \end_inset 
25588
25589
25590 \end_inset 
25591 </cell>
25592 </row>
25593 <row topline="true">
25594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25595 \begin_inset Text
25596
25597 \layout Standard
25598
25599
25600 \size footnotesize 
25601 Ramtron / Goal Semiconductor
25602 \end_inset 
25603 </cell>
25604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25605 \begin_inset Text
25606
25607 \layout Standard
25608
25609
25610 \size footnotesize 
25611 Installing and Configuring SDCC and Crimson Editor 
25612 \end_inset 
25613 </cell>
25614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25615 \begin_inset Text
25616
25617 \layout Standard
25618
25619
25620 \size footnotesize 
25621
25622 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25623
25624 \end_inset 
25625
25626
25627 \end_inset 
25628 </cell>
25629 </row>
25630 <row topline="true" bottomline="true">
25631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25632 \begin_inset Text
25633
25634 \layout Standard
25635
25636
25637 \size footnotesize 
25638 Texas Instruments
25639 \end_inset 
25640 </cell>
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25642 \begin_inset Text
25643
25644 \layout Standard
25645
25646
25647 \size footnotesize 
25648 MSC12xx Programming with SDCC
25649 \end_inset 
25650 </cell>
25651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25652 \begin_inset Text
25653
25654 \layout Standard
25655
25656
25657 \size footnotesize 
25658
25659 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25660
25661 \end_inset 
25662
25663
25664 \end_inset 
25665 </cell>
25666 </row>
25667 </lyxtabular>
25668
25669 \end_inset 
25670
25671
25672 \layout Section
25673
25674 Some Questions
25675 \layout Standard
25676
25677 Some questions answered, some pointers given - it might be time to in turn
25678  ask 
25679 \emph on 
25680 you
25681 \emph default 
25682  some questions: 
25683 \layout Itemize
25684
25685 can you solve your project with the selected microcontroller? Would you
25686  find out early or rather late that your target is too small/slow/whatever?
25687  Can you switch to a slightly better device if it doesn't fit?
25688 \layout Itemize
25689
25690 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25691  and/or another programming language be more adequate? Would an operating
25692  system on the target device help?
25693 \layout Itemize
25694
25695 if you solved the problem, will the marketing department be happy?
25696 \layout Itemize
25697
25698 if the marketing department is happy, will customers be happy?
25699 \layout Itemize
25700
25701 if you're the project manager, marketing department and maybe even the customer
25702  in one person, have you tried to see the project from the outside?
25703 \layout Itemize
25704
25705 is the project done if you think it is done? Or is just that other interface/pro
25706 tocol/feature/configuration/option missing? How about website, manual(s),
25707  internationali(z|s)ation, packaging, labels, 2nd source for components,
25708  electromagnetic compatability/interference, documentation for production,
25709  production test software, update mechanism, patent issues?
25710 \layout Itemize
25711
25712 is your project adequately positioned in that magic triangle: fame, fortune,
25713  fun?
25714 \layout Standard
25715
25716 Maybe not all answers to these questions are known and some answers may
25717  even be 
25718 \emph on 
25719 no
25720 \emph default 
25721 , nevertheless knowing these questions may help you to avoid burnout
25722 \begin_inset Foot
25723 collapsed false
25724
25725 \layout Standard
25726
25727 burnout is bad for electronic devices, programmers and motorcycle tyres
25728 \end_inset 
25729
25730 .
25731  Chances are you didn't want to hear some of them...
25732 \layout Chapter
25733
25734 Support
25735 \begin_inset LatexCommand \index{Support}
25736
25737 \end_inset 
25738
25739
25740 \layout Standard
25741
25742 SDCC has grown to be a large project.
25743  The compiler alone (without the preprocessor, assembler and linker) is
25744  well over 150,000 lines of code (blank stripped).
25745  The open source nature of this project is a key to its continued growth
25746  and support.
25747  You gain the benefit and support of many active software developers and
25748  end users.
25749  Is SDCC perfect? No, that's why we need your help.
25750  The developers take pride in fixing reported bugs.
25751  You can help by reporting the bugs and helping other SDCC users.
25752  There are lots of ways to contribute, and we encourage you to take part
25753  in making SDCC a great software package.
25754  
25755 \layout Standard
25756
25757 The SDCC project is hosted on the SDCC sourceforge site at 
25758 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25759
25760 \end_inset 
25761
25762 .
25763  You'll find the complete set of mailing lists
25764 \begin_inset LatexCommand \index{Mailing list(s)}
25765
25766 \end_inset 
25767
25768 , forums, bug reporting system, patch submission
25769 \begin_inset LatexCommand \index{Patch submission}
25770
25771 \end_inset 
25772
25773  system, download
25774 \begin_inset LatexCommand \index{download}
25775
25776 \end_inset 
25777
25778  area and Subversion code repository
25779 \begin_inset LatexCommand \index{Subversion code repository}
25780
25781 \end_inset 
25782
25783  there.
25784 \layout Section
25785
25786 Reporting Bugs
25787 \begin_inset LatexCommand \index{Bug reporting}
25788
25789 \end_inset 
25790
25791
25792 \begin_inset LatexCommand \index{Reporting bugs}
25793
25794 \end_inset 
25795
25796
25797 \layout Standard
25798
25799 The recommended way of reporting bugs is using the infrastructure of the
25800  sourceforge site.
25801  You can follow the status of bug reports there and have an overview about
25802  the known bugs.
25803 \layout Standard
25804
25805 Bug reports are automatically forwarded to the developer mailing list and
25806  will be fixed ASAP.
25807  When reporting a bug, it is very useful to include a small test program
25808  (the smaller the better) which reproduces the problem.
25809  If you can isolate the problem by looking at the generated assembly code,
25810  this can be very helpful.
25811  Compiling your program with the -
25812 \begin_inset ERT
25813 status Collapsed
25814
25815 \layout Standard
25816
25817 \backslash 
25818 /
25819 \end_inset 
25820
25821 -dumpall
25822 \begin_inset LatexCommand \index{-\/-dumpall}
25823
25824 \end_inset 
25825
25826  option can sometimes be useful in locating optimization problems.
25827  When reporting a bug please make sure you:
25828 \layout Enumerate
25829
25830 Attach the code you are compiling with SDCC.
25831  
25832 \layout Enumerate
25833
25834 Specify the exact command you use to run SDCC, or attach your Makefile.
25835  
25836 \layout Enumerate
25837
25838 Specify the SDCC version (type "
25839 \family sans 
25840 \series bold 
25841 sdcc -v
25842 \family default 
25843 \series default 
25844 "), your platform, and operating system.
25845  
25846 \layout Enumerate
25847
25848 Provide an exact copy of any error message or incorrect output.
25849  
25850 \layout Enumerate
25851
25852 Put something meaningful in the subject of your message.
25853 \layout Standard
25854
25855 Please attempt to include these 5 important parts, as applicable, in all
25856  requests for support or when reporting any problems or bugs with SDCC.
25857  Though this will make your message lengthy, it will greatly improve your
25858  chance that SDCC users and developers will be able to help you.
25859  Some SDCC developers are frustrated by bug reports without code provided
25860  that they can use to reproduce and ultimately fix the problem, so please
25861  be sure to provide sample code if you are reporting a bug! 
25862 \layout Standard
25863
25864 Please have a short check that you are using a recent version of SDCC and
25865  the bug is not yet known.
25866  This is the link for reporting bugs: 
25867 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25868
25869 \end_inset 
25870
25871 .
25872  With SDCC on average having more than 200 downloads
25873 \begin_inset LatexCommand \index{download}
25874
25875 \end_inset 
25876
25877  on sourceforge per day
25878 \begin_inset Foot
25879 collapsed false
25880
25881 \layout Standard
25882
25883 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25884  between 2002 and 2005.
25885  This does not include other methods of distribution.
25886 \end_inset 
25887
25888  there must be some users.
25889  So it's not exactly easy to find a new bug.
25890  If you find one we need it: 
25891 \emph on 
25892 reporting bugs is good
25893 \emph default 
25894 .
25895 \layout Section
25896
25897 Requesting Features
25898 \begin_inset LatexCommand \label{sub:Requesting-Features}
25899
25900 \end_inset 
25901
25902
25903 \begin_inset LatexCommand \index{Feature request}
25904
25905 \end_inset 
25906
25907
25908 \begin_inset LatexCommand \index{Requesting features}
25909
25910 \end_inset 
25911
25912
25913 \layout Standard
25914
25915 Like bug reports feature requests are forwarded to the developer mailing
25916  list.
25917  This is the link for requesting features: 
25918 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25919
25920 \end_inset 
25921
25922 .
25923 \layout Section
25924
25925 Submitting patches
25926 \layout Standard
25927
25928 Like bug reports contributed patches are forwarded to the developer mailing
25929  list.
25930  This is the link for submitting patches
25931 \begin_inset LatexCommand \index{Patch submission}
25932
25933 \end_inset 
25934
25935
25936 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25937
25938 \end_inset 
25939
25940 .
25941 \layout Standard
25942
25943 You need to specify some parameters to the 
25944 \family typewriter 
25945 diff
25946 \family default 
25947  command for the patches to be useful.
25948  If you modified more than one file a patch created f.e.
25949  with 
25950 \family sans 
25951 \series bold 
25952
25953 \begin_inset Quotes sld
25954 \end_inset 
25955
25956 diff -Naur unmodified_directory modified_directory >my_changes.patch
25957 \begin_inset Quotes srd
25958 \end_inset 
25959
25960
25961 \family default 
25962 \series default 
25963  will be fine, otherwise 
25964 \family sans 
25965 \series bold 
25966
25967 \begin_inset Quotes sld
25968 \end_inset 
25969
25970 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25971 \begin_inset Quotes srd
25972 \end_inset 
25973
25974
25975 \series default 
25976  
25977 \family default 
25978 will do.
25979 \layout Section
25980
25981 Getting Help
25982 \layout Standard
25983
25984 These links should take you directly to the 
25985 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25986
25987 \end_inset 
25988
25989
25990 \begin_inset Foot
25991 collapsed false
25992
25993 \layout Standard
25994
25995 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25996  automated messages (mid 2003)
25997 \end_inset 
25998
25999  and the 
26000 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
26001
26002 \end_inset 
26003
26004 , lists
26005 \begin_inset LatexCommand \index{Mailing list(s)}
26006
26007 \end_inset 
26008
26009  and forums are archived and searchable so if you are lucky someone already
26010  had a similar problem.
26011  While mails to the lists themselves are delivered promptly their web front
26012  end on sourceforge sometimes shows a severe time lag (up to several weeks),
26013  if you're seriously using SDCC please consider subscribing to the lists.
26014 \layout Section
26015
26016 ChangeLog
26017 \layout Standard
26018
26019 You can follow the status of the Subversion version
26020 \begin_inset LatexCommand \index{version}
26021
26022 \end_inset 
26023
26024  of SDCC by watching the Changelog
26025 \begin_inset LatexCommand \index{Changelog}
26026
26027 \end_inset 
26028
26029  in the Subversion repository
26030 \size footnotesize 
26031  
26032 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26033
26034 \end_inset 
26035
26036 .
26037 \layout Section
26038
26039 Subversion Source Code Repository
26040 \layout Standard
26041
26042 The output of 
26043 \family sans 
26044 \series bold 
26045 sdcc --version
26046 \family default 
26047 \series default 
26048  or the filenames of the snapshot versions of SDCC include date and its
26049  Subversion
26050 \begin_inset LatexCommand \index{Subversion code repository}
26051
26052 \end_inset 
26053
26054  number.
26055  Subversion allows to download the source of recent or previous versions
26056  
26057 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
26058
26059 \end_inset 
26060
26061  (by number or by date).
26062  An on-line source code browser and detailled instructions are also available
26063  there.
26064  SDCC versions starting from 1999 up to now are available (currently the
26065  versions prior to the conversion from cvs
26066 \begin_inset LatexCommand \index{cvs|see{Subversion}}
26067
26068 \end_inset 
26069
26070  to Subversion (April 2006) are either by accessible by Subversion or by
26071  cvs).
26072 \layout Section
26073
26074 Release policy
26075 \begin_inset LatexCommand \index{Release policy}
26076
26077 \end_inset 
26078
26079
26080 \layout Standard
26081
26082 Historically there often were long delays between official releases and
26083  the sourceforge download area tends to get not updated at all.
26084  Excuses in the past might have referred to problems with live range analysis,
26085  but as this was fixed a while ago, the current problem is that another
26086  excuse has to be found.
26087  Kidding aside, we have to get better there! On the other hand there are
26088  daily snapshots available at 
26089 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
26090
26091 \end_inset 
26092
26093 , and you can always build the very last version (hopefully with many bugs
26094  fixed, and features added) from the source code available at 
26095 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
26096
26097 \end_inset 
26098
26099 .
26100  A release wiki
26101 \begin_inset LatexCommand \index{wiki}
26102
26103 \end_inset 
26104
26105
26106 \begin_inset LatexCommand \index{Release wiki}
26107
26108 \end_inset 
26109
26110  at 
26111 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
26112
26113 \end_inset 
26114
26115  also holds some information about past and future releases.
26116 \layout Section
26117
26118 Examples
26119 \begin_inset LatexCommand \index{Examples}
26120
26121 \end_inset 
26122
26123
26124 \layout Standard
26125
26126 You'll find some small examples in the directory 
26127 \emph on 
26128 sdcc/device/examples/.
26129  
26130 \emph default 
26131 More examples and libraries are available at
26132 \emph on 
26133  The SDCC Open Knowledge Resource 
26134 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
26135
26136 \end_inset 
26137
26138  
26139 \emph default 
26140 web site or at 
26141 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
26142
26143 \end_inset 
26144
26145 .
26146 \layout Comment
26147
26148 I did insert a reference to Paul's web site here although it seems rather
26149  dedicated to a specific 8032 board (I think it's okay because it f.e.
26150  shows LCD/Harddisc interface and has a free 8051 monitor.
26151  Independent 8032 board vendors face hard competition of heavily subsidized
26152  development boards anyway).
26153 \layout Comment
26154
26155 Maybe we should include some links to real world applications.
26156  Preferably pointer to pointers (one for each architecture) so this stays
26157  manageable here?
26158 \layout Section
26159
26160 Quality control
26161 \begin_inset LatexCommand \label{sec:Quality-control}
26162
26163 \end_inset 
26164
26165
26166 \begin_inset LatexCommand \index{Quality control}
26167
26168 \end_inset 
26169
26170
26171 \layout Standard
26172
26173 The compiler is passed through nightly compile and build checks.
26174  The so called 
26175 \shape italic 
26176 regression tests
26177 \shape default 
26178
26179 \begin_inset LatexCommand \index{Regression test}
26180
26181 \end_inset 
26182
26183  check that SDCC itself compiles flawlessly on several host platforms (i386,
26184  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26185  the quality of the code generated by SDCC by running the code for several
26186  target platforms through simulators.
26187  The regression test suite comprises more than 100 files which expand to
26188  more than 500 test cases which include more than 4500 tests.
26189  The results of these tests are published daily on SDCC's snapshot page
26190  (click on the red or green symbols on the right side of 
26191 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26192
26193 \end_inset 
26194
26195 ).
26196 \layout Standard
26197
26198 There is a separate document 
26199 \shape italic 
26200 test_suite.pdf 
26201 \begin_inset LatexCommand \index{Test suite}
26202
26203 \end_inset 
26204
26205
26206 \shape default 
26207  
26208 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26209
26210 \end_inset 
26211
26212  about the regression test suite.
26213 \layout Standard
26214
26215 You'll find the test code in the directory 
26216 \shape italic 
26217 sdcc/support/regression
26218 \shape default 
26219 .
26220  You can run these tests manually by running 
26221 \family sans 
26222 make
26223 \family default 
26224  in this directory (or f.e.
26225  
26226 \family sans 
26227 \series bold 
26228
26229 \begin_inset Quotes sld
26230 \end_inset 
26231
26232 make test-mcs51
26233 \begin_inset Quotes srd
26234 \end_inset 
26235
26236
26237 \family default 
26238 \series default 
26239  if you don't want to run the complete tests).
26240  The test code might also be interesting if you want to look for examples
26241 \begin_inset LatexCommand \index{Examples}
26242
26243 \end_inset 
26244
26245  checking corner cases of SDCC or if you plan to submit patches
26246 \begin_inset LatexCommand \index{Patch submission}
26247
26248 \end_inset 
26249
26250 .
26251 \layout Standard
26252
26253 The 14bit pic port uses a different set of regression tests 
26254 \begin_inset LatexCommand \index{Regression test (PIC14)}
26255
26256 \end_inset 
26257
26258 , you'll find them in the directory 
26259 \shape italic 
26260 sdcc/src/regression
26261 \shape default 
26262 .
26263 \layout Section
26264
26265 Use of SDCC in Education
26266 \layout Standard
26267
26268 In short: 
26269 \emph on 
26270 highly
26271 \emph default 
26272  encouraged
26273 \begin_inset Foot
26274 collapsed false
26275
26276 \layout Standard
26277
26278 the phrase "use in education" might evoke the association "
26279 \emph on 
26280 only
26281 \emph default 
26282  fit for use in education".
26283  This connotation is not intended but nevertheless risked as the licensing
26284  of SDCC makes it difficult to offer educational discounts
26285 \end_inset 
26286
26287 .
26288  If your rationales are to:
26289 \layout Enumerate
26290
26291 give students a chance to understand the 
26292 \emph on 
26293 complete
26294 \emph default 
26295  steps of code generation
26296 \layout Enumerate
26297
26298 have a curriculum that can be extended for years.
26299  Then you could use an fpga board as target and your curriculum will seamlessly
26300  extend from logic synthesis (
26301 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26302
26303 \end_inset 
26304
26305
26306 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26307
26308 \end_inset 
26309
26310 ), over assembly programming, to C to FPGA compilers (
26311 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26312
26313 \end_inset 
26314
26315 ) and to C.
26316 \layout Enumerate
26317
26318 be able to insert excursions about skills like using a revision control
26319  system, submitting/applying patches, using a type-setting (as opposed to
26320  word-processing) engine LyX/LaTeX, using 
26321 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26322
26323 \end_inset 
26324
26325 , following some 
26326 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26327
26328 \end_inset 
26329
26330 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26331  Source Software, CPU simulation, compiler regression tests
26332 \begin_inset LatexCommand \index{Regression test}
26333
26334 \end_inset 
26335
26336 .
26337  
26338 \newline 
26339 And if there should be a shortage of ideas then you can always point students
26340  to the ever-growing feature request list 
26341 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26342
26343 \end_inset 
26344
26345 .
26346 \layout Enumerate
26347
26348 not tie students to a specific host platform and instead allow them to use
26349  a host platform of 
26350 \emph on 
26351 their
26352 \emph default 
26353  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26354  eventually 
26355 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26356
26357 \end_inset 
26358
26359 )
26360 \layout Enumerate
26361
26362 not encourage students to use illegal copies of educational software
26363 \layout Enumerate
26364
26365 be immune to licensing/availability/price changes of the chosen tool chain
26366 \layout Enumerate
26367
26368 be able to change to a new target platform without having to adopt a new
26369  tool chain
26370 \layout Enumerate
26371
26372 have complete control over and insight into the tool chain
26373 \layout Enumerate
26374
26375 make your students aware about the pros and cons of open source software
26376  development
26377 \layout Enumerate
26378
26379 give back to the public as you are probably at least partially publically
26380  funded
26381 \layout Enumerate
26382
26383 give students a chance to publically prove their skills and to possibly
26384  see a world wide impact
26385 \layout Standard
26386
26387 then SDCC is probably among the first choices.
26388  Well, probably SDCC might be the only choice.
26389 \layout Chapter
26390 \pagebreak_top 
26391 SDCC Technical Data
26392 \layout Section
26393
26394 Optimizations
26395 \begin_inset LatexCommand \index{Optimizations}
26396
26397 \end_inset 
26398
26399
26400 \layout Standard
26401
26402 SDCC performs a host of standard optimizations in addition to some MCU specific
26403  optimizations.
26404  
26405 \layout Subsection
26406
26407 Sub-expression Elimination
26408 \begin_inset LatexCommand \index{Subexpression elimination}
26409
26410 \end_inset 
26411
26412
26413 \layout Standard
26414
26415 The compiler does local and 
26416 \emph on 
26417 g
26418 \emph default 
26419 lobal 
26420 \emph on 
26421 c
26422 \emph default 
26423 ommon 
26424 \emph on 
26425 s
26426 \emph default 
26427 ubexpression 
26428 \emph on 
26429 e
26430 \emph default 
26431 limination, e.g.: 
26432 \layout Verse
26433
26434
26435 \family typewriter 
26436 i = x + y + 1; 
26437 \newline 
26438 j = x + y;
26439 \layout Standard
26440
26441 will be translated to
26442 \layout Verse
26443
26444
26445 \family typewriter 
26446 iTemp = x + y; 
26447 \newline 
26448 i = iTemp + 1; 
26449 \newline 
26450 j = iTemp;
26451 \layout Standard
26452
26453 Some subexpressions are not as obvious as the above example, e.g.:
26454 \layout Verse
26455
26456
26457 \family typewriter 
26458 a->b[i].c = 10; 
26459 \newline 
26460 a->b[i].d = 11;
26461 \layout Standard
26462
26463 In this case the address arithmetic a->b[i] will be computed only once;
26464  the equivalent code in C would be.
26465 \layout Verse
26466
26467
26468 \family typewriter 
26469 iTemp = a->b[i]; 
26470 \newline 
26471 iTemp.c = 10; 
26472 \newline 
26473 iTemp.d = 11;
26474 \layout Standard
26475
26476 The compiler will try to keep these temporary variables in registers.
26477 \layout Subsection
26478
26479 Dead-Code Elimination
26480 \begin_inset LatexCommand \index{Dead-code elimination}
26481
26482 \end_inset 
26483
26484
26485 \layout Verse
26486
26487
26488 \family typewriter 
26489 int global;
26490 \newline 
26491
26492 \newline 
26493 void f () { 
26494 \newline 
26495 \SpecialChar ~
26496 \SpecialChar ~
26497 int i; 
26498 \newline 
26499 \SpecialChar ~
26500 \SpecialChar ~
26501 i = 1; \SpecialChar ~
26502 \SpecialChar ~
26503 \SpecialChar ~
26504 \SpecialChar ~
26505 \SpecialChar ~
26506 /* dead store */ 
26507 \newline 
26508 \SpecialChar ~
26509 \SpecialChar ~
26510 global = 1;\SpecialChar ~
26511 /* dead store */ 
26512 \newline 
26513 \SpecialChar ~
26514 \SpecialChar ~
26515 global = 2; 
26516 \newline 
26517 \SpecialChar ~
26518 \SpecialChar ~
26519 return; 
26520 \newline 
26521 \SpecialChar ~
26522 \SpecialChar ~
26523 global = 3;\SpecialChar ~
26524 /* unreachable */ 
26525 \newline 
26526 }
26527 \layout Standard
26528
26529 will be changed to
26530 \layout Verse
26531
26532
26533 \family typewriter 
26534 int global;
26535 \newline 
26536
26537 \newline 
26538 void f () {
26539 \newline 
26540 \SpecialChar ~
26541 \SpecialChar ~
26542 global = 2; 
26543 \newline 
26544 }
26545 \layout Subsection
26546
26547 Copy-Propagation
26548 \begin_inset LatexCommand \index{Copy propagation}
26549
26550 \end_inset 
26551
26552
26553 \layout Verse
26554
26555
26556 \family typewriter 
26557 int f() { 
26558 \newline 
26559 \SpecialChar ~
26560 \SpecialChar ~
26561 int i, j; 
26562 \newline 
26563 \SpecialChar ~
26564 \SpecialChar ~
26565 i = 10; 
26566 \newline 
26567 \SpecialChar ~
26568 \SpecialChar ~
26569 j = i; 
26570 \newline 
26571 \SpecialChar ~
26572 \SpecialChar ~
26573 return j; 
26574 \newline 
26575 }
26576 \layout Standard
26577
26578 will be changed to 
26579 \layout Verse
26580
26581
26582 \family typewriter 
26583 int f() { 
26584 \newline 
26585 \SpecialChar ~
26586 \SpecialChar ~
26587 int i, j; 
26588 \newline 
26589 \SpecialChar ~
26590 \SpecialChar ~
26591 i = 10; 
26592 \newline 
26593 \SpecialChar ~
26594 \SpecialChar ~
26595 j = 10; 
26596 \newline 
26597 \SpecialChar ~
26598 \SpecialChar ~
26599 return 10; 
26600 \newline 
26601 }
26602 \layout Standard
26603
26604 Note: the dead stores created by this copy propagation will be eliminated
26605  by dead-code elimination.
26606 \layout Subsection
26607
26608 Loop Optimizations
26609 \begin_inset LatexCommand \index{Loop optimization}
26610
26611 \end_inset 
26612
26613
26614 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26615
26616 \end_inset 
26617
26618
26619 \layout Standard
26620
26621 Two types of loop optimizations are done by SDCC 
26622 \emph on 
26623 loop invariant
26624 \emph default 
26625  lifting and
26626 \emph on 
26627  strength reduction
26628 \emph default 
26629  of loop induction variables.
26630  In addition to the strength reduction the optimizer marks the induction
26631  variables and the register allocator tries to keep the induction variables
26632  in registers for the duration of the loop.
26633  Because of this preference of the register allocator
26634 \begin_inset LatexCommand \index{Register allocation}
26635
26636 \end_inset 
26637
26638 , loop induction optimization causes an increase in register pressure, which
26639  may cause unwanted spilling of other temporary variables into the stack
26640 \begin_inset LatexCommand \index{stack}
26641
26642 \end_inset 
26643
26644  / data space.
26645  The compiler will generate a warning message when it is forced to allocate
26646  extra space either on the stack or data space.
26647  If this extra space allocation is undesirable then induction optimization
26648  can be eliminated either for the entire source file (with -
26649 \begin_inset ERT
26650 status Collapsed
26651
26652 \layout Standard
26653
26654 \backslash 
26655 /
26656 \end_inset 
26657
26658 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26659 noinduction
26660 \begin_inset LatexCommand \index{\#pragma noinduction}
26661
26662 \end_inset 
26663
26664 .
26665 \newline 
26666
26667 \newline 
26668 Loop Invariant:
26669 \layout Verse
26670
26671
26672 \family typewriter 
26673 for (i = 0 ; i < 100 ; i ++) 
26674 \newline 
26675 \SpecialChar ~
26676 \SpecialChar ~
26677 \SpecialChar ~
26678 \SpecialChar ~
26679 f += k + l;
26680 \layout Standard
26681
26682 changed to
26683 \layout Verse
26684
26685
26686 \family typewriter 
26687 itemp = k + l; 
26688 \newline 
26689 for (i = 0; i < 100; i++) 
26690 \newline 
26691 \SpecialChar ~
26692 \SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695 f += itemp;
26696 \layout Standard
26697
26698 As mentioned previously some loop invariants are not as apparent, all static
26699  address computations are also moved out of the loop.
26700 \newline 
26701
26702 \newline 
26703 Strength Reduction
26704 \begin_inset LatexCommand \index{Strength reduction}
26705
26706 \end_inset 
26707
26708 , this optimization substitutes an expression by a cheaper expression:
26709 \layout Verse
26710
26711
26712 \family typewriter 
26713 for (i=0;i < 100; i++)
26714 \newline 
26715 \SpecialChar ~
26716 \SpecialChar ~
26717 \SpecialChar ~
26718 \SpecialChar ~
26719 ar[i*5] = i*3;
26720 \layout Standard
26721
26722 changed to
26723 \layout Verse
26724
26725
26726 \family typewriter 
26727 itemp1 = 0; 
26728 \newline 
26729 itemp2 = 0; 
26730 \newline 
26731 for (i=0;i< 100;i++) { 
26732 \newline 
26733 \SpecialChar ~
26734 \SpecialChar ~
26735 \SpecialChar ~
26736 \SpecialChar ~
26737 ar[itemp1] = itemp2; 
26738 \newline 
26739 \SpecialChar ~
26740 \SpecialChar ~
26741 \SpecialChar ~
26742 \SpecialChar ~
26743 itemp1 += 5; 
26744 \newline 
26745 \SpecialChar ~
26746 \SpecialChar ~
26747 \SpecialChar ~
26748 \SpecialChar ~
26749 itemp2 += 3; 
26750 \newline 
26751 }
26752 \layout Standard
26753
26754 The more expensive multiplication
26755 \begin_inset LatexCommand \index{Multiplication}
26756
26757 \end_inset 
26758
26759  is changed to a less expensive addition.
26760 \layout Subsection
26761
26762 Loop Reversing
26763 \begin_inset LatexCommand \index{Loop reversing}
26764
26765 \end_inset 
26766
26767
26768 \layout Standard
26769
26770 This optimization is done to reduce the overhead of checking loop boundaries
26771  for every iteration.
26772  Some simple loops can be reversed and implemented using a 
26773 \begin_inset Quotes eld
26774 \end_inset 
26775
26776 decrement and jump if not zero
26777 \begin_inset Quotes erd
26778 \end_inset 
26779
26780  instruction.
26781  SDCC checks for the following criterion to determine if a loop is reversible
26782  (note: more sophisticated compilers use data-dependency analysis to make
26783  this determination, SDCC uses a more simple minded analysis).
26784 \layout Itemize
26785
26786 The 'for' loop is of the form 
26787 \newline 
26788
26789 \newline 
26790
26791 \family typewriter 
26792 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26793  += 1])
26794 \newline 
26795 \SpecialChar ~
26796 \SpecialChar ~
26797 \SpecialChar ~
26798 \SpecialChar ~
26799 <for body>
26800 \layout Itemize
26801
26802 The <for body> does not contain 
26803 \begin_inset Quotes eld
26804 \end_inset 
26805
26806 continue
26807 \begin_inset Quotes erd
26808 \end_inset 
26809
26810  or 'break
26811 \begin_inset Quotes erd
26812 \end_inset 
26813
26814 .
26815 \layout Itemize
26816
26817 All goto's are contained within the loop.
26818 \layout Itemize
26819
26820 No function calls within the loop.
26821 \layout Itemize
26822
26823 The loop control variable <sym> is not assigned any value within the loop
26824 \layout Itemize
26825
26826 The loop control variable does NOT participate in any arithmetic operation
26827  within the loop.
26828 \layout Itemize
26829
26830 There are NO switch statements in the loop.
26831 \layout Subsection
26832
26833 Algebraic Simplifications
26834 \layout Standard
26835
26836 SDCC does numerous algebraic simplifications, the following is a small sub-set
26837  of these optimizations.
26838 \layout Verse
26839
26840
26841 \family typewriter 
26842 i = j + 0;\SpecialChar ~
26843 \SpecialChar ~
26844 \SpecialChar ~
26845 \SpecialChar ~
26846  /* changed to: */\SpecialChar ~
26847 \SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850  i = j; 
26851 \newline 
26852 i /= 2;\SpecialChar ~
26853 \SpecialChar ~
26854 \SpecialChar ~
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 \SpecialChar ~
26859  /* changed to: */\SpecialChar ~
26860 \SpecialChar ~
26861 \SpecialChar ~
26862 \SpecialChar ~
26863  i >>= 1; 
26864 \newline 
26865 i = j - j;\SpecialChar ~
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 \SpecialChar ~
26869  /* changed to: */\SpecialChar ~
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 \SpecialChar ~
26873  i = 0; 
26874 \newline 
26875 i = j / 1;\SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878 \SpecialChar ~
26879  /* changed to: */\SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 \SpecialChar ~
26883  i = j;
26884 \layout Standard
26885
26886 Note the subexpressions
26887 \begin_inset LatexCommand \index{Subexpression}
26888
26889 \end_inset 
26890
26891  given above are generally introduced by macro expansions or as a result
26892  of copy/constant propagation.
26893 \layout Subsection
26894
26895 'switch' Statements
26896 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26897
26898 \end_inset 
26899
26900
26901 \begin_inset LatexCommand \index{switch statement}
26902
26903 \end_inset 
26904
26905
26906 \layout Standard
26907
26908 SDCC can optimize switch statements to jump tables
26909 \begin_inset LatexCommand \index{jump tables}
26910
26911 \end_inset 
26912
26913 .
26914  It makes the decision based on an estimate of the generated code size.
26915  SDCC is quite liberal in the requirements for jump table generation: 
26916 \layout Itemize
26917
26918 The labels need not be in order, and the starting number need not be one
26919  or zero, the case labels are in numerical sequence or not too many case
26920  labels are missing.
26921 \begin_deeper 
26922 \layout Verse
26923
26924
26925 \family typewriter 
26926 switch(i) {\SpecialChar ~
26927 \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 switch (i) { 
26953 \newline 
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 case 4: ...\SpecialChar ~
26958 \SpecialChar ~
26959 \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 case 0: ...
26984  
26985 \newline 
26986 \SpecialChar ~
26987 \SpecialChar ~
26988 \SpecialChar ~
26989 case 5: ...\SpecialChar ~
26990 \SpecialChar ~
26991 \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 case 1: ...
27016  
27017 \newline 
27018 \SpecialChar ~
27019 \SpecialChar ~
27020 \SpecialChar ~
27021 case 3: ...\SpecialChar ~
27022 \SpecialChar ~
27023 \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
27048 \newline 
27049 \SpecialChar ~
27050 \SpecialChar ~
27051 \SpecialChar ~
27052 case 6: ...\SpecialChar ~
27053 \SpecialChar ~
27054 \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 case 3: ...
27079  
27080 \newline 
27081 \SpecialChar ~
27082 \SpecialChar ~
27083 \SpecialChar ~
27084 case 7: ...\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 case 4: ...
27111  
27112 \newline 
27113 \SpecialChar ~
27114 \SpecialChar ~
27115 \SpecialChar ~
27116 case 8: ...\SpecialChar ~
27117 \SpecialChar ~
27118 \SpecialChar ~
27119 \SpecialChar ~
27120 \SpecialChar ~
27121 \SpecialChar ~
27122 \SpecialChar ~
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 \SpecialChar ~
27126 \SpecialChar ~
27127 \SpecialChar ~
27128 \SpecialChar ~
27129 \SpecialChar ~
27130 \SpecialChar ~
27131 \SpecialChar ~
27132 \SpecialChar ~
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 \SpecialChar ~
27138 \SpecialChar ~
27139 \SpecialChar ~
27140 \SpecialChar ~
27141 \SpecialChar ~
27142 case 5: ...
27143  
27144 \newline 
27145 \SpecialChar ~
27146 \SpecialChar ~
27147 \SpecialChar ~
27148 case 9: ...\SpecialChar ~
27149 \SpecialChar ~
27150 \SpecialChar ~
27151 \SpecialChar ~
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 \SpecialChar ~
27155 \SpecialChar ~
27156 \SpecialChar ~
27157 \SpecialChar ~
27158 \SpecialChar ~
27159 \SpecialChar ~
27160 \SpecialChar ~
27161 \SpecialChar ~
27162 \SpecialChar ~
27163 \SpecialChar ~
27164 \SpecialChar ~
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 \SpecialChar ~
27168 \SpecialChar ~
27169 \SpecialChar ~
27170 \SpecialChar ~
27171 \SpecialChar ~
27172 \SpecialChar ~
27173 \SpecialChar ~
27174 case 6: ...
27175  
27176 \newline 
27177 \SpecialChar ~
27178 \SpecialChar ~
27179 \SpecialChar ~
27180 case 10: ...\SpecialChar ~
27181 \SpecialChar ~
27182 \SpecialChar ~
27183 \SpecialChar ~
27184 \SpecialChar ~
27185 \SpecialChar ~
27186 \SpecialChar ~
27187 \SpecialChar ~
27188 \SpecialChar ~
27189 \SpecialChar ~
27190 \SpecialChar ~
27191 \SpecialChar ~
27192 \SpecialChar ~
27193 \SpecialChar ~
27194 \SpecialChar ~
27195 \SpecialChar ~
27196 \SpecialChar ~
27197 \SpecialChar ~
27198 \SpecialChar ~
27199 \SpecialChar ~
27200 \SpecialChar ~
27201 \SpecialChar ~
27202 \SpecialChar ~
27203 \SpecialChar ~
27204 \SpecialChar ~
27205 case 7: ...
27206  
27207 \newline 
27208 \SpecialChar ~
27209 \SpecialChar ~
27210 \SpecialChar ~
27211 case 11: ...\SpecialChar ~
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 \SpecialChar ~
27215 \SpecialChar ~
27216 \SpecialChar ~
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 \SpecialChar ~
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 \SpecialChar ~
27223 \SpecialChar ~
27224 \SpecialChar ~
27225 \SpecialChar ~
27226 \SpecialChar ~
27227 \SpecialChar ~
27228 \SpecialChar ~
27229 \SpecialChar ~
27230 \SpecialChar ~
27231 \SpecialChar ~
27232 \SpecialChar ~
27233 \SpecialChar ~
27234 \SpecialChar ~
27235 \SpecialChar ~
27236 case 8: ...
27237  
27238 \newline 
27239 }\SpecialChar ~
27240 \SpecialChar ~
27241 \SpecialChar ~
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 \SpecialChar ~
27245 \SpecialChar ~
27246 \SpecialChar ~
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 \SpecialChar ~
27250 \SpecialChar ~
27251 \SpecialChar ~
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 \SpecialChar ~
27257 \SpecialChar ~
27258 \SpecialChar ~
27259 \SpecialChar ~
27260 \SpecialChar ~
27261 \SpecialChar ~
27262 \SpecialChar ~
27263 \SpecialChar ~
27264 \SpecialChar ~
27265 \SpecialChar ~
27266 \SpecialChar ~
27267 \SpecialChar ~
27268 \SpecialChar ~
27269 \SpecialChar ~
27270 \SpecialChar ~
27271 \SpecialChar ~
27272 \SpecialChar ~
27273 \SpecialChar ~
27274 \SpecialChar ~
27275 }
27276 \layout Standard
27277
27278 Both the above switch statements will be implemented using a jump-table.
27279  The example to the right side is slightly more efficient as the check for
27280  the lower boundary of the jump-table is not needed.
27281 \end_deeper 
27282 \layout Itemize
27283
27284 The number of case labels is not larger than supported by the target architectur
27285 e.
27286 \layout Itemize
27287
27288 If the case labels are not in numerical sequence ('gaps' between cases)
27289  SDCC checks whether a jump table with additionally inserted dummy cases
27290  is still attractive.
27291  
27292 \layout Itemize
27293
27294 If the starting number is not zero and a check for the lower boundary of
27295  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27296  ...
27297  .
27298 \layout Standard
27299
27300 Switch statements which have large gaps in the numeric sequence or those
27301  that have too many case labels can be split into more than one switch statement
27302  for efficient code generation, e.g.:
27303 \layout Verse
27304
27305
27306 \family typewriter 
27307 switch (i) { 
27308 \newline 
27309 \SpecialChar ~
27310 \SpecialChar ~
27311 case 1: ...
27312  
27313 \newline 
27314 \SpecialChar ~
27315 \SpecialChar ~
27316 case 2: ...
27317  
27318 \newline 
27319 \SpecialChar ~
27320 \SpecialChar ~
27321 case 3: ...
27322  
27323 \newline 
27324 \SpecialChar ~
27325 \SpecialChar ~
27326 case 4: ...
27327  
27328 \newline 
27329 \SpecialChar ~
27330 \SpecialChar ~
27331 case 5: ...
27332  
27333 \newline 
27334 \SpecialChar ~
27335 \SpecialChar ~
27336 case 6: ...
27337  
27338 \newline 
27339 \SpecialChar ~
27340 \SpecialChar ~
27341 case 7: ...
27342  
27343 \newline 
27344 \SpecialChar ~
27345 \SpecialChar ~
27346 case 101: ...
27347  
27348 \newline 
27349 \SpecialChar ~
27350 \SpecialChar ~
27351 case 102: ...
27352  
27353 \newline 
27354 \SpecialChar ~
27355 \SpecialChar ~
27356 case 103: ...
27357  
27358 \newline 
27359 \SpecialChar ~
27360 \SpecialChar ~
27361 case 104: ...
27362  
27363 \newline 
27364 \SpecialChar ~
27365 \SpecialChar ~
27366 case 105: ...
27367  
27368 \newline 
27369 \SpecialChar ~
27370 \SpecialChar ~
27371 case 106: ...
27372  
27373 \newline 
27374 \SpecialChar ~
27375 \SpecialChar ~
27376 case 107: ...
27377  
27378 \newline 
27379 }
27380 \layout Standard
27381
27382 If the above switch statement is broken down into two switch statements
27383 \layout Verse
27384
27385
27386 \family typewriter 
27387 switch (i) { 
27388 \newline 
27389 \SpecialChar ~
27390 \SpecialChar ~
27391 case 1: ...
27392  
27393 \newline 
27394 \SpecialChar ~
27395 \SpecialChar ~
27396 case 2: ...
27397  
27398 \newline 
27399 \SpecialChar ~
27400 \SpecialChar ~
27401 case 3: ...
27402  
27403 \newline 
27404 \SpecialChar ~
27405 \SpecialChar ~
27406 case 4: ...
27407  
27408 \newline 
27409 \SpecialChar ~
27410 \SpecialChar ~
27411 case 5: ...
27412  
27413 \newline 
27414 \SpecialChar ~
27415 \SpecialChar ~
27416 case 6: ...
27417  
27418 \newline 
27419 \SpecialChar ~
27420 \SpecialChar ~
27421 case 7: ...
27422  
27423 \newline 
27424 }
27425 \layout Standard
27426
27427 and
27428 \layout Verse
27429
27430
27431 \family typewriter 
27432 switch (i) { 
27433 \newline 
27434 \SpecialChar ~
27435 \SpecialChar ~
27436 case 101: ...
27437  
27438 \newline 
27439 \SpecialChar ~
27440 \SpecialChar ~
27441 case 102: ...
27442  
27443 \newline 
27444 \SpecialChar ~
27445 \SpecialChar ~
27446 case 103: ...
27447  
27448 \newline 
27449 \SpecialChar ~
27450 \SpecialChar ~
27451 case 104: ...
27452  
27453 \newline 
27454 \SpecialChar ~
27455 \SpecialChar ~
27456 case 105: ...
27457  
27458 \newline 
27459 \SpecialChar ~
27460 \SpecialChar ~
27461 case 106: ...
27462  
27463 \newline 
27464 \SpecialChar ~
27465 \SpecialChar ~
27466 case 107: ...
27467  
27468 \newline 
27469 }
27470 \layout Standard
27471
27472 then both the switch statements will be implemented using jump-tables whereas
27473  the unmodified switch statement will not be.
27474 \layout Comment
27475
27476 There might be reasons which SDCC cannot know about to either favour or
27477  not favour jump tables.
27478  If the target system has to be as quick for the last switch case as for
27479  the first (pro jump table), or if the switch argument is known to be zero
27480  in the majority of the cases (contra jump table).
27481 \layout Standard
27482
27483 The pragma nojtbound
27484 \begin_inset LatexCommand \index{\#pragma nojtbound}
27485
27486 \end_inset 
27487
27488  can be used to turn off checking the 
27489 \emph on 
27490 j
27491 \emph default 
27492 ump 
27493 \emph on 
27494 t
27495 \emph default 
27496 able 
27497 \emph on 
27498 bound
27499 \emph default 
27500 aries.
27501  It has no effect if a default label is supplied.
27502  Use of this pragma is dangerous: if the switch
27503 \begin_inset LatexCommand \index{switch statement}
27504
27505 \end_inset 
27506
27507  argument is not matched by a case statement the processor will happily
27508  jump into Nirvana.
27509 \layout Subsection
27510
27511 Bit-shifting Operations
27512 \begin_inset LatexCommand \index{Bit shifting}
27513
27514 \end_inset 
27515
27516 .
27517 \layout Standard
27518
27519 Bit shifting is one of the most frequently used operation in embedded programmin
27520 g.
27521  SDCC tries to implement bit-shift operations in the most efficient way
27522  possible, e.g.:
27523 \layout Verse
27524
27525
27526 \family typewriter 
27527 unsigned char i;
27528 \newline 
27529 ...
27530  
27531 \newline 
27532 i >>= 4; 
27533 \newline 
27534 ...
27535 \layout Standard
27536
27537 generates the following code:
27538 \layout Verse
27539
27540
27541 \family typewriter 
27542 mov\SpecialChar ~
27543  a,_i 
27544 \newline 
27545 swap a 
27546 \newline 
27547 anl\SpecialChar ~
27548  a,#0x0f 
27549 \newline 
27550 mov\SpecialChar ~
27551  _i,a
27552 \layout Standard
27553
27554 In general SDCC will never setup a loop if the shift count is known.
27555  Another example:
27556 \layout Verse
27557
27558
27559 \family typewriter 
27560 unsigned int i; 
27561 \newline 
27562 ...
27563  
27564 \newline 
27565 i >>= 9; 
27566 \newline 
27567 ...
27568 \layout Standard
27569
27570 will generate:
27571 \layout Verse
27572
27573
27574 \family typewriter 
27575 mov\SpecialChar ~
27576 \SpecialChar ~
27577 a,(_i + 1) 
27578 \newline 
27579 mov\SpecialChar ~
27580 \SpecialChar ~
27581 (_i + 1),#0x00 
27582 \newline 
27583 clr\SpecialChar ~
27584 \SpecialChar ~
27585
27586 \newline 
27587 rrc\SpecialChar ~
27588 \SpecialChar ~
27589
27590 \newline 
27591 mov\SpecialChar ~
27592 \SpecialChar ~
27593 _i,a
27594 \layout Subsection
27595
27596 Bit-rotation
27597 \begin_inset LatexCommand \index{Bit rotation}
27598
27599 \end_inset 
27600
27601
27602 \layout Standard
27603
27604 A special case of the bit-shift operation is bit rotation
27605 \begin_inset LatexCommand \index{rotating bits}
27606
27607 \end_inset 
27608
27609 , SDCC recognizes the following expression to be a left bit-rotation:
27610 \layout Verse
27611
27612
27613 \family typewriter 
27614 \series bold 
27615 unsigned
27616 \series default 
27617 \SpecialChar ~
27618 \SpecialChar ~
27619 char i;\SpecialChar ~
27620 \SpecialChar ~
27621 \SpecialChar ~
27622 \SpecialChar ~
27623 \SpecialChar ~
27624 \SpecialChar ~
27625 \SpecialChar ~
27626 \SpecialChar ~
27627 \SpecialChar ~
27628 \SpecialChar ~
27629 \SpecialChar ~
27630 /* unsigned is needed for rotation */ 
27631 \newline 
27632 ...
27633  
27634 \newline 
27635 i = ((i << 1) | (i >> 7)); 
27636 \family default 
27637
27638 \newline 
27639
27640 \family typewriter 
27641 ...
27642 \layout Standard
27643
27644 will generate the following code:
27645 \layout Verse
27646
27647
27648 \family typewriter 
27649 mov\SpecialChar ~
27650 \SpecialChar ~
27651 a,_i 
27652 \newline 
27653 rl\SpecialChar ~
27654 \SpecialChar ~
27655 \SpecialChar ~
27656
27657 \newline 
27658 mov\SpecialChar ~
27659 \SpecialChar ~
27660 _i,a
27661 \layout Standard
27662
27663 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27664 ns of this case will also be recognized as bit-rotation, i.e.: 
27665 \layout Verse
27666
27667
27668 \family typewriter 
27669 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27670 \layout Subsection
27671
27672 Nibble and Byte Swapping
27673 \layout Standard
27674
27675 Other special cases of the bit-shift operations are nibble or byte swapping
27676 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27677
27678 \end_inset 
27679
27680 , SDCC recognizes the following expressions:
27681 \layout Verse
27682
27683
27684 \family typewriter 
27685 \series bold 
27686 unsigned
27687 \series default 
27688 \SpecialChar ~
27689 \SpecialChar ~
27690 char i; 
27691 \newline 
27692
27693 \series bold 
27694 unsigned
27695 \series default 
27696 \SpecialChar ~
27697 \SpecialChar ~
27698 int j; 
27699 \newline 
27700 ...
27701  
27702 \newline 
27703 i = ((i << 4) | (i >> 4)); 
27704 \family default 
27705
27706 \newline 
27707
27708 \family typewriter 
27709 j = ((j << 8) | (j >> 8)); 
27710 \layout Standard
27711
27712 and generates a swap instruction for the nibble swapping
27713 \begin_inset LatexCommand \index{Nibble swapping}
27714
27715 \end_inset 
27716
27717  or move instructions for the byte swapping
27718 \begin_inset LatexCommand \index{Byte swapping}
27719
27720 \end_inset 
27721
27722 .
27723  The 
27724 \begin_inset Quotes sld
27725 \end_inset 
27726
27727 j
27728 \begin_inset Quotes srd
27729 \end_inset 
27730
27731  example can be used to convert from little to big-endian or vice versa.
27732  If you want to change the endianness of a 
27733 \emph on 
27734 signed
27735 \emph default 
27736  integer you have to cast to 
27737 \family typewriter 
27738 (unsigned int)
27739 \family default 
27740  first.
27741 \layout Standard
27742
27743 Note that SDCC stores numbers in little-endian
27744 \begin_inset Foot
27745 collapsed false
27746
27747 \layout Standard
27748
27749 Usually 8-bit processors don't care much about endianness.
27750  This is not the case for the standard 8051 which only has an instruction
27751  to increment its 
27752 \emph on 
27753 dptr
27754 \emph default 
27755
27756 \begin_inset LatexCommand \index{DPTR}
27757
27758 \end_inset 
27759
27760 -datapointer
27761 \emph on 
27762  
27763 \emph default 
27764 so little-endian is the more efficient byte order.
27765 \end_inset 
27766
27767
27768 \begin_inset LatexCommand \index{little-endian}
27769
27770 \end_inset 
27771
27772
27773 \begin_inset LatexCommand \index{Endianness}
27774
27775 \end_inset 
27776
27777  format (i.e.
27778  lowest order first).
27779 \layout Subsection
27780
27781 Highest Order Bit
27782 \begin_inset LatexCommand \index{Highest Order Bit}
27783
27784 \end_inset 
27785
27786  / Any Order Bit
27787 \begin_inset LatexCommand \index{Any Order Bit}
27788
27789 \end_inset 
27790
27791
27792 \layout Standard
27793
27794 It is frequently required to obtain the highest order bit of an integral
27795  type (long, int, short or char types).
27796  Also obtaining any other order bit is not uncommon.
27797  SDCC recognizes the following expressions to yield the highest order bit
27798  and generates optimized code for it, e.g.:
27799 \layout Verse
27800
27801
27802 \family typewriter 
27803 unsigned int gint; 
27804 \newline 
27805
27806 \newline 
27807 foo () { 
27808 \newline 
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 unsigned char hob1, aob1; 
27812 \newline 
27813 \SpecialChar ~
27814 \SpecialChar ~
27815 bit hob2, hob3, aob2, aob3; 
27816 \newline 
27817 \SpecialChar ~
27818 \SpecialChar ~
27819 ...
27820  
27821 \newline 
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 hob1 = (gint >> 15) & 1; 
27825 \newline 
27826 \SpecialChar ~
27827 \SpecialChar ~
27828 hob2 = (gint >> 15) & 1; 
27829 \newline 
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 hob3 = gint & 0x8000; 
27833 \newline 
27834 \SpecialChar ~
27835 \SpecialChar ~
27836 aob1 = (gint >> 9) & 1; 
27837 \newline 
27838 \SpecialChar ~
27839 \SpecialChar ~
27840 aob2 = (gint >> 8) & 1; 
27841 \newline 
27842 \SpecialChar ~
27843 \SpecialChar ~
27844 aob3 = gint & 0x0800; 
27845 \newline 
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 ..
27849  
27850 \newline 
27851 }
27852 \layout Standard
27853
27854 will generate the following code:
27855 \layout Verse
27856
27857
27858 \family typewriter 
27859 \SpecialChar ~
27860 \SpecialChar ~
27861 \SpecialChar ~
27862 \SpecialChar ~
27863 \SpecialChar ~
27864 \SpecialChar ~
27865 \SpecialChar ~
27866 \SpecialChar ~
27867 \SpecialChar ~
27868 \SpecialChar ~
27869 \SpecialChar ~
27870 \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  61 ;\SpecialChar ~
27885  hob.c 7 
27886 \newline 
27887 000A E5*01\SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 \SpecialChar ~
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902  62\SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 \SpecialChar ~
27909 \SpecialChar ~
27910  mov\SpecialChar ~
27911 \SpecialChar ~
27912  a,(_gint + 1) 
27913 \newline 
27914 000C 23\SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920 \SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925 \SpecialChar ~
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932  63\SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935 \SpecialChar ~
27936 \SpecialChar ~
27937 \SpecialChar ~
27938 \SpecialChar ~
27939 \SpecialChar ~
27940  rl\SpecialChar ~
27941 \SpecialChar ~
27942 \SpecialChar ~
27943  a 
27944 \newline 
27945 000D 54 01\SpecialChar ~
27946 \SpecialChar ~
27947 \SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950 \SpecialChar ~
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955 \SpecialChar ~
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960  64\SpecialChar ~
27961 \SpecialChar ~
27962 \SpecialChar ~
27963 \SpecialChar ~
27964 \SpecialChar ~
27965 \SpecialChar ~
27966 \SpecialChar ~
27967 \SpecialChar ~
27968  anl\SpecialChar ~
27969 \SpecialChar ~
27970  a,#0x01 
27971 \newline 
27972 000F F5*02\SpecialChar ~
27973 \SpecialChar ~
27974 \SpecialChar ~
27975 \SpecialChar ~
27976 \SpecialChar ~
27977 \SpecialChar ~
27978 \SpecialChar ~
27979 \SpecialChar ~
27980 \SpecialChar ~
27981 \SpecialChar ~
27982 \SpecialChar ~
27983 \SpecialChar ~
27984 \SpecialChar ~
27985 \SpecialChar ~
27986 \SpecialChar ~
27987  65\SpecialChar ~
27988 \SpecialChar ~
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992 \SpecialChar ~
27993 \SpecialChar ~
27994 \SpecialChar ~
27995  mov\SpecialChar ~
27996 \SpecialChar ~
27997  _foo_hob1_1_1,a 
27998 \newline 
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 \SpecialChar ~
28003 \SpecialChar ~
28004 \SpecialChar ~
28005 \SpecialChar ~
28006 \SpecialChar ~
28007 \SpecialChar ~
28008 \SpecialChar ~
28009 \SpecialChar ~
28010 \SpecialChar ~
28011 \SpecialChar ~
28012 \SpecialChar ~
28013 \SpecialChar ~
28014 \SpecialChar ~
28015 \SpecialChar ~
28016 \SpecialChar ~
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 \SpecialChar ~
28020 \SpecialChar ~
28021 \SpecialChar ~
28022 \SpecialChar ~
28023 \SpecialChar ~
28024  66 ;\SpecialChar ~
28025  hob.c 8 
28026 \newline 
28027 0011 E5*01\SpecialChar ~
28028 \SpecialChar ~
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 \SpecialChar ~
28036 \SpecialChar ~
28037 \SpecialChar ~
28038 \SpecialChar ~
28039 \SpecialChar ~
28040 \SpecialChar ~
28041 \SpecialChar ~
28042  67\SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045 \SpecialChar ~
28046 \SpecialChar ~
28047 \SpecialChar ~
28048 \SpecialChar ~
28049 \SpecialChar ~
28050  mov\SpecialChar ~
28051 \SpecialChar ~
28052  a,(_gint + 1) 
28053 \newline 
28054 0013 33\SpecialChar ~
28055 \SpecialChar ~
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 \SpecialChar ~
28064 \SpecialChar ~
28065 \SpecialChar ~
28066 \SpecialChar ~
28067 \SpecialChar ~
28068 \SpecialChar ~
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072  68\SpecialChar ~
28073 \SpecialChar ~
28074 \SpecialChar ~
28075 \SpecialChar ~
28076 \SpecialChar ~
28077 \SpecialChar ~
28078 \SpecialChar ~
28079 \SpecialChar ~
28080  rlc\SpecialChar ~
28081 \SpecialChar ~
28082  a 
28083 \newline 
28084 0014 92*00\SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088 \SpecialChar ~
28089 \SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 \SpecialChar ~
28099  69\SpecialChar ~
28100 \SpecialChar ~
28101 \SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104 \SpecialChar ~
28105 \SpecialChar ~
28106 \SpecialChar ~
28107  mov\SpecialChar ~
28108 \SpecialChar ~
28109  _foo_hob2_1_1,c 
28110 \newline 
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 \SpecialChar ~
28114 \SpecialChar ~
28115 \SpecialChar ~
28116 \SpecialChar ~
28117 \SpecialChar ~
28118 \SpecialChar ~
28119 \SpecialChar ~
28120 \SpecialChar ~
28121 \SpecialChar ~
28122 \SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130 \SpecialChar ~
28131 \SpecialChar ~
28132 \SpecialChar ~
28133 \SpecialChar ~
28134 \SpecialChar ~
28135 \SpecialChar ~
28136  66 ;\SpecialChar ~
28137  hob.c 9 
28138 \newline 
28139 0016 E5*01\SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147 \SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150 \SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 \SpecialChar ~
28154  67\SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 \SpecialChar ~
28160 \SpecialChar ~
28161 \SpecialChar ~
28162  mov\SpecialChar ~
28163 \SpecialChar ~
28164  a,(_gint + 1) 
28165 \newline 
28166 0018 33\SpecialChar ~
28167 \SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182 \SpecialChar ~
28183 \SpecialChar ~
28184  68\SpecialChar ~
28185 \SpecialChar ~
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189 \SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192  rlc\SpecialChar ~
28193 \SpecialChar ~
28194  a 
28195 \newline 
28196 0019 92*01\SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202 \SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211  69\SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214 \SpecialChar ~
28215 \SpecialChar ~
28216 \SpecialChar ~
28217 \SpecialChar ~
28218 \SpecialChar ~
28219  mov\SpecialChar ~
28220 \SpecialChar ~
28221  _foo_hob3_1_1,c 
28222 \newline 
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226 \SpecialChar ~
28227 \SpecialChar ~
28228 \SpecialChar ~
28229 \SpecialChar ~
28230 \SpecialChar ~
28231 \SpecialChar ~
28232 \SpecialChar ~
28233 \SpecialChar ~
28234 \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  70 ;\SpecialChar ~
28249  hob.c 10 
28250 \newline 
28251 001B E5*01\SpecialChar ~
28252 \SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259 \SpecialChar ~
28260 \SpecialChar ~
28261 \SpecialChar ~
28262 \SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266  71\SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274  mov\SpecialChar ~
28275 \SpecialChar ~
28276  a,(_gint + 1) 
28277 \newline 
28278 001D 03\SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 \SpecialChar ~
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 \SpecialChar ~
28286 \SpecialChar ~
28287 \SpecialChar ~
28288 \SpecialChar ~
28289 \SpecialChar ~
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294 \SpecialChar ~
28295 \SpecialChar ~
28296  72\SpecialChar ~
28297 \SpecialChar ~
28298 \SpecialChar ~
28299 \SpecialChar ~
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 \SpecialChar ~
28303 \SpecialChar ~
28304  rr\SpecialChar ~
28305 \SpecialChar ~
28306 \SpecialChar ~
28307  a 
28308 \newline 
28309 001E 54 01\SpecialChar ~
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 \SpecialChar ~
28313 \SpecialChar ~
28314 \SpecialChar ~
28315 \SpecialChar ~
28316 \SpecialChar ~
28317 \SpecialChar ~
28318 \SpecialChar ~
28319 \SpecialChar ~
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324  73\SpecialChar ~
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329 \SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332  anl\SpecialChar ~
28333 \SpecialChar ~
28334  a,#0x01 
28335 \newline 
28336 0020 F5*03\SpecialChar ~
28337 \SpecialChar ~
28338 \SpecialChar ~
28339 \SpecialChar ~
28340 \SpecialChar ~
28341 \SpecialChar ~
28342 \SpecialChar ~
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 \SpecialChar ~
28350 \SpecialChar ~
28351  74\SpecialChar ~
28352 \SpecialChar ~
28353 \SpecialChar ~
28354 \SpecialChar ~
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359  mov\SpecialChar ~
28360 \SpecialChar ~
28361  _foo_aob1_1_1,a 
28362 \newline 
28363 \SpecialChar ~
28364 \SpecialChar ~
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369 \SpecialChar ~
28370 \SpecialChar ~
28371 \SpecialChar ~
28372 \SpecialChar ~
28373 \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  75 ;\SpecialChar ~
28389  hob.c 11 
28390 \newline 
28391 0022 E5*01\SpecialChar ~
28392 \SpecialChar ~
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398 \SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406  76\SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410 \SpecialChar ~
28411 \SpecialChar ~
28412 \SpecialChar ~
28413 \SpecialChar ~
28414  mov\SpecialChar ~
28415 \SpecialChar ~
28416  a,(_gint + 1) 
28417 \newline 
28418 0024 13\SpecialChar ~
28419 \SpecialChar ~
28420 \SpecialChar ~
28421 \SpecialChar ~
28422 \SpecialChar ~
28423 \SpecialChar ~
28424 \SpecialChar ~
28425 \SpecialChar ~
28426 \SpecialChar ~
28427 \SpecialChar ~
28428 \SpecialChar ~
28429 \SpecialChar ~
28430 \SpecialChar ~
28431 \SpecialChar ~
28432 \SpecialChar ~
28433 \SpecialChar ~
28434 \SpecialChar ~
28435 \SpecialChar ~
28436  77\SpecialChar ~
28437 \SpecialChar ~
28438 \SpecialChar ~
28439 \SpecialChar ~
28440 \SpecialChar ~
28441 \SpecialChar ~
28442 \SpecialChar ~
28443 \SpecialChar ~
28444  rrc\SpecialChar ~
28445 \SpecialChar ~
28446  a 
28447 \newline 
28448 0025 92*02\SpecialChar ~
28449 \SpecialChar ~
28450 \SpecialChar ~
28451 \SpecialChar ~
28452 \SpecialChar ~
28453 \SpecialChar ~
28454 \SpecialChar ~
28455 \SpecialChar ~
28456 \SpecialChar ~
28457 \SpecialChar ~
28458 \SpecialChar ~
28459 \SpecialChar ~
28460 \SpecialChar ~
28461 \SpecialChar ~
28462 \SpecialChar ~
28463  78\SpecialChar ~
28464 \SpecialChar ~
28465 \SpecialChar ~
28466 \SpecialChar ~
28467 \SpecialChar ~
28468 \SpecialChar ~
28469 \SpecialChar ~
28470 \SpecialChar ~
28471  mov\SpecialChar ~
28472 \SpecialChar ~
28473  _foo_aob2_1_1,c 
28474 \newline 
28475 \SpecialChar ~
28476 \SpecialChar ~
28477 \SpecialChar ~
28478 \SpecialChar ~
28479 \SpecialChar ~
28480 \SpecialChar ~
28481 \SpecialChar ~
28482 \SpecialChar ~
28483 \SpecialChar ~
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 \SpecialChar ~
28487 \SpecialChar ~
28488 \SpecialChar ~
28489 \SpecialChar ~
28490 \SpecialChar ~
28491 \SpecialChar ~
28492 \SpecialChar ~
28493 \SpecialChar ~
28494 \SpecialChar ~
28495 \SpecialChar ~
28496 \SpecialChar ~
28497 \SpecialChar ~
28498 \SpecialChar ~
28499 \SpecialChar ~
28500  79 ;\SpecialChar ~
28501  hob.c 12 
28502 \newline 
28503 0027 E5*01\SpecialChar ~
28504 \SpecialChar ~
28505 \SpecialChar ~
28506 \SpecialChar ~
28507 \SpecialChar ~
28508 \SpecialChar ~
28509 \SpecialChar ~
28510 \SpecialChar ~
28511 \SpecialChar ~
28512 \SpecialChar ~
28513 \SpecialChar ~
28514 \SpecialChar ~
28515 \SpecialChar ~
28516 \SpecialChar ~
28517 \SpecialChar ~
28518  80\SpecialChar ~
28519 \SpecialChar ~
28520 \SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526  mov\SpecialChar ~
28527 \SpecialChar ~
28528  a,(_gint + 1) 
28529 \newline 
28530 0029 A2 E3\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 \SpecialChar ~
28544 \SpecialChar ~
28545  81\SpecialChar ~
28546 \SpecialChar ~
28547 \SpecialChar ~
28548 \SpecialChar ~
28549 \SpecialChar ~
28550 \SpecialChar ~
28551 \SpecialChar ~
28552 \SpecialChar ~
28553  mov\SpecialChar ~
28554 \SpecialChar ~
28555  c,acc[3] 
28556 \newline 
28557 002B 92*03\SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 \SpecialChar ~
28562 \SpecialChar ~
28563 \SpecialChar ~
28564 \SpecialChar ~
28565 \SpecialChar ~
28566 \SpecialChar ~
28567 \SpecialChar ~
28568 \SpecialChar ~
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 \SpecialChar ~
28572  82\SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580  mov\SpecialChar ~
28581 \SpecialChar ~
28582  _foo_aob3_1_1,c 
28583 \layout Standard
28584
28585 Other variations of these cases however will 
28586 \emph on 
28587 not
28588 \emph default 
28589  be recognized.
28590  They are standard C expressions, so I heartily recommend these be the only
28591  way to get the highest order bit, (it is portable).
28592  Of course it will be recognized even if it is embedded in other expressions,
28593  e.g.:
28594 \layout Verse
28595
28596
28597 \family typewriter 
28598 xyz = gint + ((gint >> 15) & 1);
28599 \layout Standard
28600
28601 will still be recognized.
28602 \layout Subsection
28603
28604 Higher Order Byte
28605 \begin_inset LatexCommand \index{Higher Order Byte}
28606
28607 \end_inset 
28608
28609  / Higher Order Word
28610 \begin_inset LatexCommand \index{Higher Order Word}
28611
28612 \end_inset 
28613
28614
28615 \layout Standard
28616
28617 It is also frequently required to obtain a higher order byte or word of
28618  a larger integral type (long, int or short types).
28619  SDCC recognizes the following expressions to yield the higher order byte
28620  or word and generates optimized code for it, e.g.:
28621 \layout Verse
28622
28623
28624 \family typewriter 
28625 unsigned int gint; 
28626 \newline 
28627 unsigned long int glong; 
28628 \newline 
28629
28630 \newline 
28631 foo () { 
28632 \newline 
28633 \SpecialChar ~
28634 \SpecialChar ~
28635 unsigned char hob1, hob2; 
28636 \newline 
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 unsigned int how1, how2; 
28640 \newline 
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 ...
28644  
28645 \newline 
28646 \SpecialChar ~
28647 \SpecialChar ~
28648 hob1 = (gint >> 8) & 0xFF; 
28649 \newline 
28650 \SpecialChar ~
28651 \SpecialChar ~
28652 hob2 = glong >> 24; 
28653 \newline 
28654 \SpecialChar ~
28655 \SpecialChar ~
28656 how1 = (glong >> 16) & 0xFFFF; 
28657 \newline 
28658 \SpecialChar ~
28659 \SpecialChar ~
28660 how2 = glong >> 8; 
28661 \newline 
28662 \SpecialChar ~
28663 \SpecialChar ~
28664 ..
28665  
28666 \newline 
28667 }
28668 \layout Standard
28669
28670 will generate the following code:
28671 \layout Verse
28672
28673
28674 \family typewriter 
28675 \SpecialChar ~
28676 \SpecialChar ~
28677 \SpecialChar ~
28678 \SpecialChar ~
28679 \SpecialChar ~
28680 \SpecialChar ~
28681 \SpecialChar ~
28682 \SpecialChar ~
28683 \SpecialChar ~
28684 \SpecialChar ~
28685 \SpecialChar ~
28686 \SpecialChar ~
28687 \SpecialChar ~
28688 \SpecialChar ~
28689 \SpecialChar ~
28690 \SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693 \SpecialChar ~
28694 \SpecialChar ~
28695 \SpecialChar ~
28696 \SpecialChar ~
28697 \SpecialChar ~
28698 \SpecialChar ~
28699 \SpecialChar ~
28700  91 ;\SpecialChar ~
28701  hob.c 15 
28702 \newline 
28703 0037 85*01*06\SpecialChar ~
28704 \SpecialChar ~
28705 \SpecialChar ~
28706 \SpecialChar ~
28707 \SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710 \SpecialChar ~
28711 \SpecialChar ~
28712 \SpecialChar ~
28713 \SpecialChar ~
28714 \SpecialChar ~
28715  92\SpecialChar ~
28716 \SpecialChar ~
28717 \SpecialChar ~
28718 \SpecialChar ~
28719 \SpecialChar ~
28720 \SpecialChar ~
28721 \SpecialChar ~
28722 \SpecialChar ~
28723  mov\SpecialChar ~
28724 \SpecialChar ~
28725  _foo_hob1_1_1,(_gint + 1) 
28726 \newline 
28727 \SpecialChar ~
28728 \SpecialChar ~
28729 \SpecialChar ~
28730 \SpecialChar ~
28731 \SpecialChar ~
28732 \SpecialChar ~
28733 \SpecialChar ~
28734 \SpecialChar ~
28735 \SpecialChar ~
28736 \SpecialChar ~
28737 \SpecialChar ~
28738 \SpecialChar ~
28739 \SpecialChar ~
28740 \SpecialChar ~
28741 \SpecialChar ~
28742 \SpecialChar ~
28743 \SpecialChar ~
28744 \SpecialChar ~
28745 \SpecialChar ~
28746 \SpecialChar ~
28747 \SpecialChar ~
28748 \SpecialChar ~
28749 \SpecialChar ~
28750 \SpecialChar ~
28751 \SpecialChar ~
28752  93 ;\SpecialChar ~
28753  hob.c 16 
28754 \newline 
28755 003A 85*05*07\SpecialChar ~
28756 \SpecialChar ~
28757 \SpecialChar ~
28758 \SpecialChar ~
28759 \SpecialChar ~
28760 \SpecialChar ~
28761 \SpecialChar ~
28762 \SpecialChar ~
28763 \SpecialChar ~
28764 \SpecialChar ~
28765 \SpecialChar ~
28766 \SpecialChar ~
28767  94\SpecialChar ~
28768 \SpecialChar ~
28769 \SpecialChar ~
28770 \SpecialChar ~
28771 \SpecialChar ~
28772 \SpecialChar ~
28773 \SpecialChar ~
28774 \SpecialChar ~
28775  mov\SpecialChar ~
28776 \SpecialChar ~
28777  _foo_hob2_1_1,(_glong + 3) 
28778 \newline 
28779 \SpecialChar ~
28780 \SpecialChar ~
28781 \SpecialChar ~
28782 \SpecialChar ~
28783 \SpecialChar ~
28784 \SpecialChar ~
28785 \SpecialChar ~
28786 \SpecialChar ~
28787 \SpecialChar ~
28788 \SpecialChar ~
28789 \SpecialChar ~
28790 \SpecialChar ~
28791 \SpecialChar ~
28792 \SpecialChar ~
28793 \SpecialChar ~
28794 \SpecialChar ~
28795 \SpecialChar ~
28796 \SpecialChar ~
28797 \SpecialChar ~
28798 \SpecialChar ~
28799 \SpecialChar ~
28800 \SpecialChar ~
28801 \SpecialChar ~
28802 \SpecialChar ~
28803 \SpecialChar ~
28804  95 ;\SpecialChar ~
28805  hob.c 17 
28806 \newline 
28807 003D 85*04*08\SpecialChar ~
28808 \SpecialChar ~
28809 \SpecialChar ~
28810 \SpecialChar ~
28811 \SpecialChar ~
28812 \SpecialChar ~
28813 \SpecialChar ~
28814 \SpecialChar ~
28815 \SpecialChar ~
28816 \SpecialChar ~
28817 \SpecialChar ~
28818 \SpecialChar ~
28819  96\SpecialChar ~
28820 \SpecialChar ~
28821 \SpecialChar ~
28822 \SpecialChar ~
28823 \SpecialChar ~
28824 \SpecialChar ~
28825 \SpecialChar ~
28826 \SpecialChar ~
28827  mov\SpecialChar ~
28828 \SpecialChar ~
28829  _foo_how1_1_1,(_glong + 2) 
28830 \newline 
28831 0040 85*05*09\SpecialChar ~
28832 \SpecialChar ~
28833 \SpecialChar ~
28834 \SpecialChar ~
28835 \SpecialChar ~
28836 \SpecialChar ~
28837 \SpecialChar ~
28838 \SpecialChar ~
28839 \SpecialChar ~
28840 \SpecialChar ~
28841 \SpecialChar ~
28842 \SpecialChar ~
28843  97\SpecialChar ~
28844 \SpecialChar ~
28845 \SpecialChar ~
28846 \SpecialChar ~
28847 \SpecialChar ~
28848 \SpecialChar ~
28849 \SpecialChar ~
28850 \SpecialChar ~
28851  mov\SpecialChar ~
28852 \SpecialChar ~
28853  (_foo_how1_1_1 + 1),(_glong + 3) 
28854 \newline 
28855 0043 85*03*0A\SpecialChar ~
28856 \SpecialChar ~
28857 \SpecialChar ~
28858 \SpecialChar ~
28859 \SpecialChar ~
28860 \SpecialChar ~
28861 \SpecialChar ~
28862 \SpecialChar ~
28863 \SpecialChar ~
28864 \SpecialChar ~
28865 \SpecialChar ~
28866 \SpecialChar ~
28867  98\SpecialChar ~
28868 \SpecialChar ~
28869 \SpecialChar ~
28870 \SpecialChar ~
28871 \SpecialChar ~
28872 \SpecialChar ~
28873 \SpecialChar ~
28874 \SpecialChar ~
28875  mov\SpecialChar ~
28876 \SpecialChar ~
28877  _foo_how2_1_1,(_glong + 1) 
28878 \newline 
28879 0046 85*04*0B\SpecialChar ~
28880 \SpecialChar ~
28881 \SpecialChar ~
28882 \SpecialChar ~
28883 \SpecialChar ~
28884 \SpecialChar ~
28885 \SpecialChar ~
28886 \SpecialChar ~
28887 \SpecialChar ~
28888 \SpecialChar ~
28889 \SpecialChar ~
28890 \SpecialChar ~
28891  99\SpecialChar ~
28892 \SpecialChar ~
28893 \SpecialChar ~
28894 \SpecialChar ~
28895 \SpecialChar ~
28896 \SpecialChar ~
28897 \SpecialChar ~
28898 \SpecialChar ~
28899  mov\SpecialChar ~
28900 \SpecialChar ~
28901  (_foo_how2_1_1 + 1),(_glong + 2) 
28902 \layout Standard
28903
28904 Again, variations of these cases may 
28905 \emph on 
28906 not
28907 \emph default 
28908  be recognized.
28909  They are standard C expressions, so I heartily recommend these be the only
28910  way to get the higher order byte/word, (it is portable).
28911  Of course it will be recognized even if it is embedded in other expressions,
28912  e.g.:
28913 \layout Verse
28914
28915
28916 \family typewriter 
28917 xyz = gint + ((gint >> 8) & 0xFF);
28918 \layout Standard
28919
28920 will still be recognized.
28921 \layout Subsection
28922
28923 Peephole Optimizer
28924 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28925
28926 \end_inset 
28927
28928
28929 \begin_inset LatexCommand \index{Peephole optimizer}
28930
28931 \end_inset 
28932
28933
28934 \layout Standard
28935
28936 The compiler uses a rule based, pattern matching and re-writing mechanism
28937  for peep-hole optimization.
28938  It is inspired by 
28939 \emph on 
28940 copt
28941 \emph default 
28942  a peep-hole optimizer by Christopher W.
28943  Fraser (cwfraser\SpecialChar ~
28944 @\SpecialChar ~
28945 microsoft.com).
28946  A default set of rules are compiled into the compiler, additional rules
28947  may be added with the 
28948 \emph on 
28949 -
28950 \begin_inset ERT
28951 status Collapsed
28952
28953 \layout Standard
28954
28955 \backslash 
28956 /
28957 \end_inset 
28958
28959 -peep-file
28960 \begin_inset LatexCommand \index{-\/-peep-file}
28961
28962 \end_inset 
28963
28964  <filename>
28965 \emph default 
28966  option.
28967  The rule language is best illustrated with examples.
28968 \layout Verse
28969
28970
28971 \family typewriter 
28972 replace { 
28973 \newline 
28974 \SpecialChar ~
28975 \SpecialChar ~
28976 mov %1,a 
28977 \newline 
28978 \SpecialChar ~
28979 \SpecialChar ~
28980 mov a,%1
28981 \newline 
28982 } by {
28983 \newline 
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 mov %1,a
28987 \newline 
28988 }
28989 \layout Standard
28990
28991 The above rule will change the following assembly
28992 \begin_inset LatexCommand \index{Assembler routines}
28993
28994 \end_inset 
28995
28996  sequence:
28997 \layout Verse
28998
28999
29000 \family typewriter 
29001 mov r1,a 
29002 \newline 
29003 mov a,r1
29004 \layout Standard
29005
29006 to
29007 \layout Verse
29008
29009
29010 \family typewriter 
29011 mov r1,a
29012 \layout Standard
29013
29014 Note: All occurrences of a 
29015 \emph on 
29016 %n
29017 \emph default 
29018  (pattern variable) must denote the same string.
29019  With the above rule, the assembly sequence:
29020 \layout Verse
29021
29022
29023 \family typewriter 
29024 mov r1,a 
29025 \newline 
29026 mov a,r2
29027 \layout Standard
29028
29029 will remain unmodified.
29030 \newline 
29031
29032 \newline 
29033 Other special case optimizations may be added by the user (via 
29034 \emph on 
29035 -
29036 \begin_inset ERT
29037 status Collapsed
29038
29039 \layout Standard
29040
29041 \backslash 
29042 /
29043 \end_inset 
29044
29045 -peep-file option
29046 \emph default 
29047 ).
29048  E.g.
29049  some variants of the 8051 MCU
29050 \begin_inset LatexCommand \index{MCS51 variants}
29051
29052 \end_inset 
29053
29054  allow only 
29055 \family typewriter 
29056 ajmp
29057 \family default 
29058  and 
29059 \family typewriter 
29060 acall
29061 \family default 
29062 .
29063  The following two rules will change all 
29064 \family typewriter 
29065 ljmp
29066 \family default 
29067  and 
29068 \family typewriter 
29069 lcall
29070 \family default 
29071  to 
29072 \family typewriter 
29073 ajmp
29074 \family default 
29075  and 
29076 \family typewriter 
29077 acall
29078 \layout Verse
29079
29080
29081 \family typewriter 
29082 replace { lcall %1 } by { acall %1 } 
29083 \newline 
29084 replace { ljmp %1 } by { ajmp %1 }
29085 \layout Standard
29086
29087 The 
29088 \emph on 
29089 inline-assembler code
29090 \emph default 
29091  is also passed through the peep hole optimizer, thus the peephole optimizer
29092  can also be used as an assembly level macro expander.
29093  The rules themselves are MCU dependent whereas the rule language infra-structur
29094 e is MCU independent.
29095  Peephole optimization rules for other MCU can be easily programmed using
29096  the rule language.
29097 \newline 
29098
29099 \newline 
29100 The syntax for a rule is as follows:
29101 \layout Verse
29102
29103
29104 \family typewriter 
29105 rule := replace [ restart ] '{' <assembly sequence> '
29106 \backslash 
29107 n' 
29108 \newline 
29109 \SpecialChar ~
29110  \SpecialChar ~
29111  \SpecialChar ~
29112  \SpecialChar ~
29113  \SpecialChar ~
29114  \SpecialChar ~
29115  \SpecialChar ~
29116  \SpecialChar ~
29117  \SpecialChar ~
29118  \SpecialChar ~
29119  \SpecialChar ~
29120  \SpecialChar ~
29121  \SpecialChar ~
29122  \SpecialChar ~
29123  '}' by '{' '
29124 \backslash 
29125 n' 
29126 \newline 
29127 \SpecialChar ~
29128  \SpecialChar ~
29129  \SpecialChar ~
29130  \SpecialChar ~
29131  \SpecialChar ~
29132  \SpecialChar ~
29133  \SpecialChar ~
29134  \SpecialChar ~
29135  \SpecialChar ~
29136  \SpecialChar ~
29137  \SpecialChar ~
29138  \SpecialChar ~
29139  \SpecialChar ~
29140  \SpecialChar ~
29141  \SpecialChar ~
29142  \SpecialChar ~
29143  <assembly sequence> '
29144 \backslash 
29145 n' 
29146 \newline 
29147 \SpecialChar ~
29148  \SpecialChar ~
29149  \SpecialChar ~
29150  \SpecialChar ~
29151  \SpecialChar ~
29152  \SpecialChar ~
29153  \SpecialChar ~
29154  \SpecialChar ~
29155  \SpecialChar ~
29156  \SpecialChar ~
29157  \SpecialChar ~
29158  \SpecialChar ~
29159  \SpecialChar ~
29160  \SpecialChar ~
29161  '}' [if <functionName> ] '
29162 \backslash 
29163 n' 
29164 \layout Standard
29165
29166 <assembly sequence> := assembly instruction (each instruction including
29167  labels must be on a separate line).
29168 \newline 
29169
29170 \newline 
29171 The optimizer will apply to the rules one by one from the top in the sequence
29172  of their appearance, it will terminate when all rules are exhausted.
29173  If the 'restart' option is specified, then the optimizer will start matching
29174  the rules again from the top, this option for a rule is expensive (performance)
29175 , it is intended to be used in situations where a transformation will trigger
29176  the same rule again.
29177  An example of this (not a good one, it has side effects) is the following
29178  rule:
29179 \layout Verse
29180
29181
29182 \family typewriter 
29183 replace restart { 
29184 \newline 
29185 \SpecialChar ~
29186 \SpecialChar ~
29187 pop %1 
29188 \newline 
29189 \SpecialChar ~
29190 \SpecialChar ~
29191 push %1 } by { 
29192 \newline 
29193 \SpecialChar ~
29194 \SpecialChar ~
29195 ; nop 
29196 \newline 
29197 }
29198 \layout Standard
29199
29200 Note that the replace pattern cannot be a blank, but can be a comment line.
29201  Without the 'restart' option only the innermost 'pop' 'push' pair would
29202  be eliminated, i.e.:
29203 \layout Verse
29204
29205
29206 \family typewriter 
29207 pop ar1 
29208 \newline 
29209 pop ar2 
29210 \newline 
29211 push ar2 
29212 \newline 
29213 push ar1
29214 \layout Standard
29215
29216 would result in:
29217 \layout Verse
29218
29219
29220 \family typewriter 
29221 pop ar1 
29222 \newline 
29223 ; nop 
29224 \newline 
29225 push ar1
29226 \layout Standard
29227
29228
29229 \emph on 
29230 with
29231 \emph default 
29232  the restart option the rule will be applied again to the resulting code
29233  and then all the pop-push pairs will be eliminated to yield:
29234 \layout Verse
29235
29236
29237 \family typewriter 
29238 ; nop 
29239 \newline 
29240 ; nop
29241 \layout Standard
29242
29243 A conditional function can be attached to a rule.
29244  Attaching rules are somewhat more involved, let me illustrate this with
29245  an example.
29246 \layout Verse
29247
29248
29249 \family typewriter 
29250 replace { 
29251 \newline 
29252 \SpecialChar ~
29253  \SpecialChar ~
29254  \SpecialChar ~
29255 ljmp %5 
29256 \newline 
29257 %2:
29258 \newline 
29259 } by { 
29260 \newline 
29261 \SpecialChar ~
29262  \SpecialChar ~
29263  \SpecialChar ~
29264 sjmp %5 
29265 \newline 
29266 %2:
29267 \newline 
29268 } if labelInRange
29269 \layout Standard
29270
29271 The optimizer does a look-up of a function name table defined in function
29272  
29273 \emph on 
29274 callFuncByName
29275 \emph default 
29276  in the source file SDCCpeeph.c, with the name 
29277 \emph on 
29278 labelInRange
29279 \emph default 
29280 .
29281  If it finds a corresponding entry the function is called.
29282  Note there can be no parameters specified for these functions, in this
29283  case the use of 
29284 \emph on 
29285 %5
29286 \emph default 
29287  is crucial, since the function 
29288 \emph on 
29289 labelInRange
29290 \emph default 
29291  expects to find the label in that particular variable (the hash table containin
29292 g the variable bindings is passed as a parameter).
29293  If you want to code more such functions, take a close look at the function
29294  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29295  Currently implemented are 
29296 \emph on 
29297 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29298  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29299 \emph default 
29300 and
29301 \emph on 
29302  notVolatile
29303 \emph default 
29304 .
29305 \layout Standard
29306
29307 I know this whole thing is a little kludgey, but maybe some day we will
29308  have some better means.
29309  If you are looking at this file, you will see the default rules that are
29310  compiled into the compiler, you can add your own rules in the default set
29311  there if you get tired of specifying the -
29312 \begin_inset ERT
29313 status Collapsed
29314
29315 \layout Standard
29316
29317 \backslash 
29318 /
29319 \end_inset 
29320
29321 -peep-file option.
29322 \layout Section
29323
29324 ANSI-Compliance
29325 \begin_inset LatexCommand \index{ANSI-compliance}
29326
29327 \end_inset 
29328
29329
29330 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29331
29332 \end_inset 
29333
29334
29335 \layout Standard
29336
29337 The latest publically available version of the standard 
29338 \emph on 
29339 ISO/IEC 9899 - Programming languages - C
29340 \emph default 
29341  should be available at: 
29342 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29343
29344 \end_inset 
29345
29346 .
29347 \newline 
29348
29349 \layout Standard
29350
29351 Deviations from the compliance:
29352 \layout Itemize
29353
29354 functions are not reentrant
29355 \begin_inset LatexCommand \index{reentrant}
29356
29357 \end_inset 
29358
29359  unless explicitly declared as such or the 
29360 \series bold 
29361 -
29362 \begin_inset ERT
29363 status Collapsed
29364
29365 \layout Standard
29366
29367 \backslash 
29368 /
29369 \end_inset 
29370
29371 -stack-auto
29372 \begin_inset LatexCommand \index{-\/-stack-auto}
29373
29374 \end_inset 
29375
29376
29377 \series default 
29378  command line option is specified.
29379 \layout Itemize
29380
29381 structures
29382 \begin_inset LatexCommand \index{struct}
29383
29384 \end_inset 
29385
29386  and unions
29387 \begin_inset LatexCommand \index{union}
29388
29389 \end_inset 
29390
29391  cannot be assigned values directly, cannot be passed as function parameters
29392  or assigned to each other and cannot be a return value
29393 \begin_inset LatexCommand \index{return value}
29394
29395 \end_inset 
29396
29397  from a function, e.g.:
29398 \begin_deeper 
29399 \layout Verse
29400
29401
29402 \family typewriter 
29403 struct s { ...
29404  }; 
29405 \newline 
29406 struct s s1, s2; 
29407 \newline 
29408 foo() 
29409 \newline 
29410
29411 \newline 
29412 \SpecialChar ~
29413 \SpecialChar ~
29414 \SpecialChar ~
29415 \SpecialChar ~
29416 ...
29417  
29418 \newline 
29419 \SpecialChar ~
29420 \SpecialChar ~
29421 \SpecialChar ~
29422 \SpecialChar ~
29423 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29424 \newline 
29425 \SpecialChar ~
29426 \SpecialChar ~
29427 \SpecialChar ~
29428 \SpecialChar ~
29429 ...
29430  
29431 \newline 
29432 }
29433 \newline 
29434
29435 \series bold 
29436 struct
29437 \series default 
29438  s foo1 (
29439 \series bold 
29440 struct
29441 \series default 
29442  s parms) /* invalid in SDCC although allowed in ANSI */
29443 \newline 
29444
29445 \newline 
29446 \SpecialChar ~
29447 \SpecialChar ~
29448 \SpecialChar ~
29449 \SpecialChar ~
29450 struct s rets; 
29451 \newline 
29452 \SpecialChar ~
29453 \SpecialChar ~
29454 \SpecialChar ~
29455 \SpecialChar ~
29456 ...
29457  
29458 \newline 
29459 \SpecialChar ~
29460 \SpecialChar ~
29461 \SpecialChar ~
29462 \SpecialChar ~
29463 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29464 \newline 
29465 }
29466 \end_deeper 
29467 \layout Itemize
29468
29469 initialization of structure arrays must be fully braced.
29470 \begin_deeper 
29471 \layout Verse
29472
29473
29474 \family typewriter 
29475 struct s { char x } a[] = {1, 2};\SpecialChar ~
29476 \SpecialChar ~
29477 \SpecialChar ~
29478 \SpecialChar ~
29479 \SpecialChar ~
29480 /* invalid in SDCC */
29481 \newline 
29482 struct s { char x } a[] = {{1}, {2}}; /* OK */
29483 \end_deeper 
29484 \layout Itemize
29485
29486 'long long
29487 \begin_inset LatexCommand \index{long long (not supported)}
29488
29489 \end_inset 
29490
29491 ' (64 bit integers
29492 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29493
29494 \end_inset 
29495
29496 ) not supported.
29497 \layout Itemize
29498
29499 'double
29500 \begin_inset LatexCommand \index{double (not supported)}
29501
29502 \end_inset 
29503
29504 ' precision floating point 
29505 \begin_inset LatexCommand \index{Floating point support}
29506
29507 \end_inset 
29508
29509 not supported.
29510 \layout Itemize
29511
29512 Old K&R style
29513 \begin_inset LatexCommand \index{K\&R style}
29514
29515 \end_inset 
29516
29517  function declarations are NOT allowed.
29518 \begin_deeper 
29519 \layout Verse
29520
29521
29522 \family typewriter 
29523 foo(i,j) /* this old style of function declarations */ 
29524 \newline 
29525 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29526 \newline 
29527
29528 \newline 
29529 \SpecialChar ~
29530 \SpecialChar ~
29531 \SpecialChar ~
29532 \SpecialChar ~
29533 ...
29534  
29535 \newline 
29536 }
29537 \end_deeper 
29538 \layout Itemize
29539
29540 Most enhancements in C99 are not supported, f.e.:
29541 \begin_deeper 
29542 \layout Verse
29543
29544
29545 \family typewriter 
29546 \series bold 
29547 inline
29548 \begin_inset LatexCommand \index{inline (not supported)}
29549
29550 \end_inset 
29551
29552
29553 \series default 
29554  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29555  in C99.
29556  An empty define 
29557 \emph on 
29558 #define inline
29559 \emph default 
29560  can be used as a work around */
29561 \newline 
29562
29563 \newline 
29564 for (
29565 \series bold 
29566 int
29567 \series default 
29568  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29569 \end_deeper 
29570 \layout Itemize
29571
29572 Certain words that are valid identifiers in the standard may be reserved
29573  words in SDCC unless the 
29574 \series bold 
29575 -
29576 \begin_inset ERT
29577 status Collapsed
29578
29579 \layout Standard
29580
29581 \backslash 
29582 /
29583 \end_inset 
29584
29585 -std-c89
29586 \begin_inset LatexCommand \index{-\/-std-c89}
29587
29588 \end_inset 
29589
29590  or -
29591 \begin_inset ERT
29592 status Collapsed
29593
29594 \layout Standard
29595
29596 \backslash 
29597 /
29598 \end_inset 
29599
29600 -std-c99
29601 \begin_inset LatexCommand \index{-\/-std-c99}
29602
29603 \end_inset 
29604
29605
29606 \series default 
29607  command line options are used.
29608  These may include (depending on the selected processor): 'at', 'banked',
29609  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29610 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29611  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29612  '_naked'.
29613  Compliant equivalents of these keywords are always available in a form
29614  that begin with two underscores
29615 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29616
29617 \end_inset 
29618
29619 , f.e.
29620  '__data' instead of 'data'.
29621 \layout Section
29622
29623 Cyclomatic Complexity
29624 \begin_inset LatexCommand \index{Cyclomatic complexity}
29625
29626 \end_inset 
29627
29628
29629 \layout Standard
29630
29631 Cyclomatic complexity of a function is defined as the number of independent
29632  paths the program can take during execution of the function.
29633  This is an important number since it defines the number test cases you
29634  have to generate to validate the function.
29635  The accepted industry standard for complexity number is 10, if the cyclomatic
29636  complexity reported by SDCC exceeds 10 you should think about simplification
29637  of the function logic.
29638  Note that the complexity level is not related to the number of lines of
29639  code in a function.
29640  Large functions can have low complexity, and small functions can have large
29641  complexity levels.
29642  
29643 \newline 
29644
29645 \newline 
29646 SDCC uses the following formula to compute the complexity:
29647 \newline 
29648
29649 \layout Standard
29650
29651 complexity = (number of edges in control flow graph) - (number of nodes
29652  in control flow graph) + 2;
29653 \newline 
29654
29655 \newline 
29656 Having said that the industry standard is 10, you should be aware that in
29657  some cases it be may unavoidable to have a complexity level of less than
29658  10.
29659  For example if you have switch statement with more than 10 case labels,
29660  each case label adds one to the complexity level.
29661  The complexity level is by no means an absolute measure of the algorithmic
29662  complexity of the function, it does however provide a good starting point
29663  for which functions you might look at for further optimization.
29664 \layout Section
29665
29666 Retargetting for other Processors
29667 \layout Standard
29668
29669 The issues for retargetting the compiler are far too numerous to be covered
29670  by this document.
29671  What follows is a brief description of each of the seven phases of the
29672  compiler and its MCU dependency.
29673 \layout Itemize
29674
29675 Parsing the source and building the annotated parse tree.
29676  This phase is largely MCU independent (except for the language extensions).
29677  Syntax & semantic checks are also done in this phase, along with some initial
29678  optimizations like back patching labels and the pattern matching optimizations
29679  like bit-rotation etc.
29680 \layout Itemize
29681
29682 The second phase involves generating an intermediate code which can be easy
29683  manipulated during the later phases.
29684  This phase is entirely MCU independent.
29685  The intermediate code generation assumes the target machine has unlimited
29686  number of registers, and designates them with the name iTemp.
29687  The compiler can be made to dump a human readable form of the code generated
29688  by using the -
29689 \begin_inset ERT
29690 status Collapsed
29691
29692 \layout Standard
29693
29694 \backslash 
29695 /
29696 \end_inset 
29697
29698 -dumpraw option.
29699 \layout Itemize
29700
29701 This phase does the bulk of the standard optimizations and is also MCU independe
29702 nt.
29703  This phase can be broken down into several sub-phases:
29704 \newline 
29705
29706 \newline 
29707 Break down intermediate code (iCode) into basic blocks.
29708 \newline 
29709 Do control flow & data flow analysis on the basic blocks.
29710 \newline 
29711 Do local common subexpression elimination, then global subexpression elimination
29712 \newline 
29713 Dead code elimination
29714 \newline 
29715 Loop optimizations
29716 \newline 
29717 If loop optimizations caused any changes then do 'global subexpression eliminati
29718 on' and 'dead code elimination' again.
29719 \layout Itemize
29720
29721 This phase determines the live-ranges; by live range I mean those iTemp
29722  variables defined by the compiler that still survive after all the optimization
29723 s.
29724  Live range analysis
29725 \begin_inset LatexCommand \index{Live range analysis}
29726
29727 \end_inset 
29728
29729  is essential for register allocation, since these computation determines
29730  which of these iTemps will be assigned to registers, and for how long.
29731 \layout Itemize
29732
29733 Phase five is register allocation.
29734  There are two parts to this process.
29735 \newline 
29736
29737 \newline 
29738 The first part I call 'register packing' (for lack of a better term).
29739  In this case several MCU specific expression folding is done to reduce
29740  register pressure.
29741 \newline 
29742
29743 \newline 
29744 The second part is more MCU independent and deals with allocating registers
29745  to the remaining live ranges.
29746  A lot of MCU specific code does creep into this phase because of the limited
29747  number of index registers available in the 8051.
29748 \layout Itemize
29749
29750 The Code generation phase is (unhappily), entirely MCU dependent and very
29751  little (if any at all) of this code can be reused for other MCU.
29752  However the scheme for allocating a homogenized assembler operand for each
29753  iCode operand may be reused.
29754 \layout Itemize
29755
29756 As mentioned in the optimization section the peep-hole optimizer is rule
29757  based system, which can reprogrammed for other MCUs.
29758 \layout Standard
29759
29760 More information is available in a wiki
29761 \begin_inset LatexCommand \index{wiki}
29762
29763 \end_inset 
29764
29765  (preliminary link 
29766 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
29767
29768 \end_inset 
29769
29770 ) and in the thread 
29771 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
29772
29773 \end_inset 
29774
29775  .
29776 \layout Chapter
29777
29778 Compiler internals
29779 \begin_inset LatexCommand \index{Compiler internals}
29780
29781 \end_inset 
29782
29783
29784 \layout Section
29785
29786 The anatomy of the compiler
29787 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29788
29789 \end_inset 
29790
29791
29792 \layout Standard
29793
29794
29795 \shape italic 
29796 This is an excerpt from an article published in Circuit Cellar Magazine
29797  in 
29798 \series bold 
29799 August 2000
29800 \series default 
29801 .
29802  It's a little outdated (the compiler is much more efficient now and user/develo
29803 per friendly), but pretty well exposes the guts of it all.
29804 \shape default 
29805
29806 \newline 
29807
29808 \newline 
29809 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29810  It is fairly easy to retarget for other 8-bit MCU.
29811  Here we take a look at some of the internals of the compiler.
29812  
29813 \layout Paragraph*
29814
29815 Parsing
29816 \begin_inset LatexCommand \index{Parsing}
29817
29818 \end_inset 
29819
29820  
29821 \layout Standard
29822
29823 Parsing the input source file and creating an AST (Annotated Syntax Tree
29824 \begin_inset LatexCommand \index{Annotated syntax tree}
29825
29826 \end_inset 
29827
29828 ).
29829  This phase also involves propagating types (annotating each node of the
29830  parse tree with type information) and semantic analysis.
29831  There are some MCU specific parsing rules.
29832  For example the storage classes, the extended storage classes are MCU specific
29833  while there may be a xdata storage class for 8051 there is no such storage
29834  class for z80 or Atmel AVR.
29835  SDCC allows MCU specific storage class extensions, i.e.
29836  xdata will be treated as a storage class specifier when parsing 8051 C
29837  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29838  C code.
29839 \layout Paragraph*
29840
29841 Generating iCode
29842 \begin_inset LatexCommand \index{iCode}
29843
29844 \end_inset 
29845
29846
29847 \layout Standard
29848
29849 Intermediate code generation.
29850  In this phase the AST is broken down into three-operand form (iCode).
29851  These three operand forms are represented as doubly linked lists.
29852  ICode is the term given to the intermediate form generated by the compiler.
29853  ICode example section shows some examples of iCode generated for some simple
29854  C source functions.
29855 \layout Paragraph*
29856
29857 Optimizations
29858 \begin_inset LatexCommand \index{Optimizations}
29859
29860 \end_inset 
29861
29862 .
29863 \layout Standard
29864
29865 Bulk of the target independent optimizations is performed in this phase.
29866  The optimizations include constant propagation, common sub-expression eliminati
29867 on, loop invariant code movement, strength reduction of loop induction variables
29868  and dead-code elimination.
29869 \layout Paragraph*
29870
29871 Live range analysis
29872 \begin_inset LatexCommand \index{Live range analysis}
29873
29874 \end_inset 
29875
29876
29877 \layout Standard
29878
29879 During intermediate code generation phase, the compiler assumes the target
29880  machine has infinite number of registers and generates a lot of temporary
29881  variables.
29882  The live range computation determines the lifetime of each of these compiler-ge
29883 nerated temporaries.
29884  A picture speaks a thousand words.
29885  ICode example sections show the live range annotations for each of the
29886  operand.
29887  It is important to note here, each iCode is assigned a number in the order
29888  of its execution in the function.
29889  The live ranges are computed in terms of these numbers.
29890  The from number is the number of the iCode which first defines the operand
29891  and the to number signifies the iCode which uses this operand last.
29892 \layout Paragraph*
29893
29894 Register Allocation
29895 \begin_inset LatexCommand \index{Register allocation}
29896
29897 \end_inset 
29898
29899
29900 \layout Standard
29901
29902 The register allocation determines the type and number of registers needed
29903  by each operand.
29904  In most MCUs only a few registers can be used for indirect addressing.
29905  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29906  address the internal ram and DPTR to indirectly address the external ram.
29907  The compiler will try to allocate the appropriate register to pointer variables
29908  if it can.
29909  ICode example section shows the operands annotated with the registers assigned
29910  to them.
29911  The compiler will try to keep operands in registers as much as possible;
29912  there are several schemes the compiler uses to do achieve this.
29913  When the compiler runs out of registers the compiler will check to see
29914  if there are any live operands which is not used or defined in the current
29915  basic block being processed, if there are any found then it will push that
29916  operand and use the registers in this block, the operand will then be popped
29917  at the end of the basic block.
29918  
29919 \layout Standard
29920
29921 There are other MCU specific considerations in this phase.
29922  Some MCUs have an accumulator; very short-lived operands could be assigned
29923  to the accumulator instead of a general-purpose register.
29924 \layout Paragraph*
29925
29926 Code generation
29927 \layout Standard
29928
29929 Figure II gives a table of iCode
29930 \begin_inset LatexCommand \index{iCode}
29931
29932 \end_inset 
29933
29934  operations supported by the compiler.
29935  The code generation involves translating these operations into corresponding
29936  assembly code for the processor.
29937  This sounds overly simple but that is the essence of code generation.
29938  Some of the iCode operations are generated on a MCU specific manner for
29939  example, the z80 port does not use registers to pass parameters so the
29940  SEND and RECV iCode operations will not be generated, and it also does
29941  not support JUMPTABLES.
29942  
29943 \newline 
29944
29945 \layout Standard
29946
29947
29948 \size footnotesize 
29949 Figure II 
29950 \begin_inset  Tabular
29951 <lyxtabular version="3" rows="39" columns="4">
29952 <features islongtable="true" headBottomDL="true">
29953 <column alignment="block" valignment="top" leftline="true" width="13col%">
29954 <column alignment="left" valignment="top" leftline="true" width="13col%">
29955 <column alignment="block" valignment="top" leftline="true" width="22col%">
29956 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
29957 <row topline="true" bottomline="true" endhead="true">
29958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29959 \begin_inset Text
29960
29961 \layout Standard
29962
29963
29964 \series bold 
29965 iCode
29966 \series default 
29967
29968 \begin_inset LatexCommand \index{iCode}
29969
29970 \end_inset 
29971
29972
29973 \end_inset 
29974 </cell>
29975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29976 \begin_inset Text
29977
29978 \layout Standard
29979
29980
29981 \series bold 
29982 Operands
29983 \end_inset 
29984 </cell>
29985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29986 \begin_inset Text
29987
29988 \layout Standard
29989
29990
29991 \series bold 
29992 Description
29993 \end_inset 
29994 </cell>
29995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29996 \begin_inset Text
29997
29998 \layout Standard
29999
30000
30001 \series bold 
30002 C Equivalent
30003 \end_inset 
30004 </cell>
30005 </row>
30006 <row topline="true">
30007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30008 \begin_inset Text
30009
30010 \layout Standard
30011
30012
30013 \size footnotesize 
30014 '!'
30015 \end_inset 
30016 </cell>
30017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30018 \begin_inset Text
30019
30020 \layout Standard
30021
30022
30023 \size footnotesize 
30024 IC_LEFT() IC_RESULT()
30025 \end_inset 
30026 </cell>
30027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30028 \begin_inset Text
30029
30030 \layout Standard
30031
30032
30033 \size footnotesize 
30034 NOT operation 
30035 \end_inset 
30036 </cell>
30037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30038 \begin_inset Text
30039
30040 \layout Standard
30041
30042
30043 \size footnotesize 
30044 IC_RESULT = ! IC_LEFT;
30045 \end_inset 
30046 </cell>
30047 </row>
30048 <row topline="true">
30049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30050 \begin_inset Text
30051
30052 \layout Standard
30053
30054
30055 \size footnotesize 
30056 '~'
30057 \end_inset 
30058 </cell>
30059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30060 \begin_inset Text
30061
30062 \layout Standard
30063
30064
30065 \size footnotesize 
30066 IC_LEFT() IC_RESULT()
30067 \end_inset 
30068 </cell>
30069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30070 \begin_inset Text
30071
30072 \layout Standard
30073
30074
30075 \size footnotesize 
30076 Bitwise complement of 
30077 \end_inset 
30078 </cell>
30079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30080 \begin_inset Text
30081
30082 \layout Standard
30083
30084
30085 \size footnotesize 
30086 IC_RESULT = ~IC_LEFT;
30087 \end_inset 
30088 </cell>
30089 </row>
30090 <row topline="true">
30091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30092 \begin_inset Text
30093
30094 \layout Standard
30095
30096
30097 \size footnotesize 
30098 RRC
30099 \end_inset 
30100 </cell>
30101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30102 \begin_inset Text
30103
30104 \layout Standard
30105
30106
30107 \size footnotesize 
30108 IC_LEFT() IC_RESULT()
30109 \end_inset 
30110 </cell>
30111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30112 \begin_inset Text
30113
30114 \layout Standard
30115
30116
30117 \size footnotesize 
30118 Rotate right with carry
30119 \end_inset 
30120 </cell>
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30122 \begin_inset Text
30123
30124 \layout Standard
30125
30126
30127 \size footnotesize 
30128 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
30129 \end_inset 
30130 </cell>
30131 </row>
30132 <row topline="true">
30133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30134 \begin_inset Text
30135
30136 \layout Standard
30137
30138
30139 \size footnotesize 
30140 RLC
30141 \end_inset 
30142 </cell>
30143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30144 \begin_inset Text
30145
30146 \layout Standard
30147
30148
30149 \size footnotesize 
30150 IC_LEFT() IC_RESULT()
30151 \end_inset 
30152 </cell>
30153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30154 \begin_inset Text
30155
30156 \layout Standard
30157
30158
30159 \size footnotesize 
30160 Rotate left with carry
30161 \end_inset 
30162 </cell>
30163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30164 \begin_inset Text
30165
30166 \layout Standard
30167
30168
30169 \size footnotesize 
30170 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
30171 \end_inset 
30172 </cell>
30173 </row>
30174 <row topline="true">
30175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30176 \begin_inset Text
30177
30178 \layout Standard
30179
30180
30181 \size footnotesize 
30182 GETHBIT
30183 \end_inset 
30184 </cell>
30185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30186 \begin_inset Text
30187
30188 \layout Standard
30189
30190
30191 \size footnotesize 
30192 IC_LEFT() IC_RESULT()
30193 \end_inset 
30194 </cell>
30195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30196 \begin_inset Text
30197
30198 \layout Standard
30199
30200
30201 \size footnotesize 
30202 Get the highest order bit of IC_LEFT
30203 \end_inset 
30204 </cell>
30205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30206 \begin_inset Text
30207
30208 \layout Standard
30209
30210
30211 \size footnotesize 
30212 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
30213 \end_inset 
30214 </cell>
30215 </row>
30216 <row topline="true">
30217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30218 \begin_inset Text
30219
30220 \layout Standard
30221
30222
30223 \size footnotesize 
30224 UNARYMINUS
30225 \end_inset 
30226 </cell>
30227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30228 \begin_inset Text
30229
30230 \layout Standard
30231
30232
30233 \size footnotesize 
30234 IC_LEFT() IC_RESULT()
30235 \end_inset 
30236 </cell>
30237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30238 \begin_inset Text
30239
30240 \layout Standard
30241
30242
30243 \size footnotesize 
30244 Unary minus
30245 \end_inset 
30246 </cell>
30247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30248 \begin_inset Text
30249
30250 \layout Standard
30251
30252
30253 \size footnotesize 
30254 IC_RESULT = - IC_LEFT;
30255 \end_inset 
30256 </cell>
30257 </row>
30258 <row topline="true">
30259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30260 \begin_inset Text
30261
30262 \layout Standard
30263
30264
30265 \size footnotesize 
30266 IPUSH
30267 \end_inset 
30268 </cell>
30269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30270 \begin_inset Text
30271
30272 \layout Standard
30273
30274
30275 \size footnotesize 
30276 IC_LEFT()
30277 \end_inset 
30278 </cell>
30279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30280 \begin_inset Text
30281
30282 \layout Standard
30283
30284
30285 \size footnotesize 
30286 Push the operand into stack
30287 \end_inset 
30288 </cell>
30289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30290 \begin_inset Text
30291
30292 \layout Standard
30293
30294
30295 \size footnotesize 
30296 NONE
30297 \end_inset 
30298 </cell>
30299 </row>
30300 <row topline="true">
30301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30302 \begin_inset Text
30303
30304 \layout Standard
30305
30306
30307 \size footnotesize 
30308 IPOP
30309 \end_inset 
30310 </cell>
30311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30312 \begin_inset Text
30313
30314 \layout Standard
30315
30316
30317 \size footnotesize 
30318 IC_LEFT()
30319 \end_inset 
30320 </cell>
30321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30322 \begin_inset Text
30323
30324 \layout Standard
30325
30326
30327 \size footnotesize 
30328 Pop the operand from the stack 
30329 \end_inset 
30330 </cell>
30331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30332 \begin_inset Text
30333
30334 \layout Standard
30335
30336
30337 \size footnotesize 
30338 NONE
30339 \end_inset 
30340 </cell>
30341 </row>
30342 <row topline="true">
30343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30344 \begin_inset Text
30345
30346 \layout Standard
30347
30348
30349 \size footnotesize 
30350 CALL
30351 \end_inset 
30352 </cell>
30353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30354 \begin_inset Text
30355
30356 \layout Standard
30357
30358
30359 \size footnotesize 
30360 IC_LEFT() IC_RESULT()
30361 \end_inset 
30362 </cell>
30363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30364 \begin_inset Text
30365
30366 \layout Standard
30367
30368
30369 \size footnotesize 
30370 Call the function represented by IC_LEFT 
30371 \end_inset 
30372 </cell>
30373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30374 \begin_inset Text
30375
30376 \layout Standard
30377
30378
30379 \size footnotesize 
30380 IC_RESULT = IC_LEFT();
30381 \end_inset 
30382 </cell>
30383 </row>
30384 <row topline="true">
30385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30386 \begin_inset Text
30387
30388 \layout Standard
30389
30390
30391 \size footnotesize 
30392 PCALL
30393 \end_inset 
30394 </cell>
30395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30396 \begin_inset Text
30397
30398 \layout Standard
30399
30400
30401 \size footnotesize 
30402 IC_LEFT() IC_RESULT()
30403 \end_inset 
30404 </cell>
30405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30406 \begin_inset Text
30407
30408 \layout Standard
30409
30410
30411 \size footnotesize 
30412 Call via function pointer
30413 \end_inset 
30414 </cell>
30415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30416 \begin_inset Text
30417
30418 \layout Standard
30419
30420
30421 \size footnotesize 
30422 IC_RESULT = (*IC_LEFT)();
30423 \end_inset 
30424 </cell>
30425 </row>
30426 <row topline="true">
30427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30428 \begin_inset Text
30429
30430 \layout Standard
30431
30432
30433 \size footnotesize 
30434 RETURN
30435 \end_inset 
30436 </cell>
30437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30438 \begin_inset Text
30439
30440 \layout Standard
30441
30442
30443 \size footnotesize 
30444 IC_LEFT()
30445 \end_inset 
30446 </cell>
30447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30448 \begin_inset Text
30449
30450 \layout Standard
30451
30452
30453 \size footnotesize 
30454 Return the value in operand IC_LEFT 
30455 \end_inset 
30456 </cell>
30457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30458 \begin_inset Text
30459
30460 \layout Standard
30461
30462
30463 \size footnotesize 
30464 return IC_LEFT;
30465 \end_inset 
30466 </cell>
30467 </row>
30468 <row topline="true">
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30470 \begin_inset Text
30471
30472 \layout Standard
30473
30474
30475 \size footnotesize 
30476 LABEL
30477 \end_inset 
30478 </cell>
30479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30480 \begin_inset Text
30481
30482 \layout Standard
30483
30484
30485 \size footnotesize 
30486 IC_LABEL() 
30487 \end_inset 
30488 </cell>
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30490 \begin_inset Text
30491
30492 \layout Standard
30493
30494
30495 \size footnotesize 
30496 Label
30497 \end_inset 
30498 </cell>
30499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30500 \begin_inset Text
30501
30502 \layout Standard
30503
30504
30505 \size footnotesize 
30506 IC_LABEL:
30507 \end_inset 
30508 </cell>
30509 </row>
30510 <row topline="true">
30511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30512 \begin_inset Text
30513
30514 \layout Standard
30515
30516
30517 \size footnotesize 
30518 GOTO
30519 \end_inset 
30520 </cell>
30521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30522 \begin_inset Text
30523
30524 \layout Standard
30525
30526
30527 \size footnotesize 
30528 IC_LABEL() 
30529 \end_inset 
30530 </cell>
30531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30532 \begin_inset Text
30533
30534 \layout Standard
30535
30536
30537 \size footnotesize 
30538 Goto label
30539 \end_inset 
30540 </cell>
30541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30542 \begin_inset Text
30543
30544 \layout Standard
30545
30546
30547 \size footnotesize 
30548 goto IC_LABEL();
30549 \end_inset 
30550 </cell>
30551 </row>
30552 <row topline="true">
30553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30554 \begin_inset Text
30555
30556 \layout Standard
30557
30558
30559 \size footnotesize 
30560 '+'
30561 \end_inset 
30562 </cell>
30563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30564 \begin_inset Text
30565
30566 \layout Standard
30567
30568
30569 \size footnotesize 
30570 IC_LEFT() IC_RIGHT() IC_RESULT()
30571 \end_inset 
30572 </cell>
30573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30574 \begin_inset Text
30575
30576 \layout Standard
30577
30578
30579 \size footnotesize 
30580 Addition
30581 \end_inset 
30582 </cell>
30583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30584 \begin_inset Text
30585
30586 \layout Standard
30587
30588
30589 \size footnotesize 
30590 IC_RESULT = IC_LEFT + IC_RIGHT
30591 \end_inset 
30592 </cell>
30593 </row>
30594 <row topline="true">
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30596 \begin_inset Text
30597
30598 \layout Standard
30599
30600
30601 \size footnotesize 
30602 '-'
30603 \end_inset 
30604 </cell>
30605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30606 \begin_inset Text
30607
30608 \layout Standard
30609
30610
30611 \size footnotesize 
30612 IC_LEFT() IC_RIGHT() IC_RESULT()
30613 \end_inset 
30614 </cell>
30615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30616 \begin_inset Text
30617
30618 \layout Standard
30619
30620
30621 \size footnotesize 
30622 Subtraction
30623 \end_inset 
30624 </cell>
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30626 \begin_inset Text
30627
30628 \layout Standard
30629
30630
30631 \size footnotesize 
30632 IC_RESULT = IC_LEFT - IC_RIGHT 
30633 \end_inset 
30634 </cell>
30635 </row>
30636 <row topline="true">
30637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30638 \begin_inset Text
30639
30640 \layout Standard
30641
30642
30643 \size footnotesize 
30644 '*'
30645 \end_inset 
30646 </cell>
30647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30648 \begin_inset Text
30649
30650 \layout Standard
30651
30652
30653 \size footnotesize 
30654 IC_LEFT() IC_RIGHT() IC_RESULT()
30655 \end_inset 
30656 </cell>
30657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30658 \begin_inset Text
30659
30660 \layout Standard
30661
30662
30663 \size footnotesize 
30664 Multiplication 
30665 \end_inset 
30666 </cell>
30667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30668 \begin_inset Text
30669
30670 \layout Standard
30671
30672
30673 \size footnotesize 
30674 IC_RESULT = IC_LEFT * IC_RIGHT;
30675 \end_inset 
30676 </cell>
30677 </row>
30678 <row topline="true">
30679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30680 \begin_inset Text
30681
30682 \layout Standard
30683
30684
30685 \size footnotesize 
30686 '/'
30687 \end_inset 
30688 </cell>
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30690 \begin_inset Text
30691
30692 \layout Standard
30693
30694
30695 \size footnotesize 
30696 IC_LEFT() IC_RIGHT() IC_RESULT()
30697 \end_inset 
30698 </cell>
30699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30700 \begin_inset Text
30701
30702 \layout Standard
30703
30704
30705 \size footnotesize 
30706 Division
30707 \end_inset 
30708 </cell>
30709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30710 \begin_inset Text
30711
30712 \layout Standard
30713
30714
30715 \size footnotesize 
30716 IC_RESULT = IC_LEFT / IC_RIGHT;
30717 \end_inset 
30718 </cell>
30719 </row>
30720 <row topline="true">
30721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30722 \begin_inset Text
30723
30724 \layout Standard
30725
30726
30727 \size footnotesize 
30728 '%'
30729 \end_inset 
30730 </cell>
30731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30732 \begin_inset Text
30733
30734 \layout Standard
30735
30736
30737 \size footnotesize 
30738 IC_LEFT() IC_RIGHT() IC_RESULT()
30739 \end_inset 
30740 </cell>
30741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30742 \begin_inset Text
30743
30744 \layout Standard
30745
30746
30747 \size footnotesize 
30748 Modulus
30749 \end_inset 
30750 </cell>
30751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30752 \begin_inset Text
30753
30754 \layout Standard
30755
30756
30757 \size footnotesize 
30758 IC_RESULT = IC_LEFT % IC_RIGHT;
30759 \end_inset 
30760 </cell>
30761 </row>
30762 <row topline="true">
30763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30764 \begin_inset Text
30765
30766 \layout Standard
30767
30768
30769 \size footnotesize 
30770 '<'
30771 \end_inset 
30772 </cell>
30773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30774 \begin_inset Text
30775
30776 \layout Standard
30777
30778
30779 \size footnotesize 
30780 IC_LEFT() IC_RIGHT() IC_RESULT()
30781 \end_inset 
30782 </cell>
30783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30784 \begin_inset Text
30785
30786 \layout Standard
30787
30788
30789 \size footnotesize 
30790 Less than
30791 \end_inset 
30792 </cell>
30793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30794 \begin_inset Text
30795
30796 \layout Standard
30797
30798
30799 \size footnotesize 
30800 IC_RESULT = IC_LEFT < IC_RIGHT;
30801 \end_inset 
30802 </cell>
30803 </row>
30804 <row topline="true">
30805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30806 \begin_inset Text
30807
30808 \layout Standard
30809
30810
30811 \size footnotesize 
30812 '>'
30813 \end_inset 
30814 </cell>
30815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30816 \begin_inset Text
30817
30818 \layout Standard
30819
30820
30821 \size footnotesize 
30822 IC_LEFT() IC_RIGHT() IC_RESULT()
30823 \end_inset 
30824 </cell>
30825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30826 \begin_inset Text
30827
30828 \layout Standard
30829
30830
30831 \size footnotesize 
30832 Greater than 
30833 \end_inset 
30834 </cell>
30835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30836 \begin_inset Text
30837
30838 \layout Standard
30839
30840
30841 \size footnotesize 
30842 IC_RESULT = IC_LEFT > IC_RIGHT;
30843 \end_inset 
30844 </cell>
30845 </row>
30846 <row topline="true">
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30848 \begin_inset Text
30849
30850 \layout Standard
30851
30852
30853 \size footnotesize 
30854 EQ_OP
30855 \end_inset 
30856 </cell>
30857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30858 \begin_inset Text
30859
30860 \layout Standard
30861
30862
30863 \size footnotesize 
30864 IC_LEFT() IC_RIGHT() IC_RESULT()
30865 \end_inset 
30866 </cell>
30867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30868 \begin_inset Text
30869
30870 \layout Standard
30871
30872
30873 \size footnotesize 
30874 Equal to 
30875 \end_inset 
30876 </cell>
30877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30878 \begin_inset Text
30879
30880 \layout Standard
30881
30882
30883 \size footnotesize 
30884 IC_RESULT = IC_LEFT == IC_RIGHT;
30885 \end_inset 
30886 </cell>
30887 </row>
30888 <row topline="true">
30889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30890 \begin_inset Text
30891
30892 \layout Standard
30893
30894
30895 \size footnotesize 
30896 AND_OP
30897 \end_inset 
30898 </cell>
30899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30900 \begin_inset Text
30901
30902 \layout Standard
30903
30904
30905 \size footnotesize 
30906 IC_LEFT() IC_RIGHT() IC_RESULT() 
30907 \end_inset 
30908 </cell>
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30910 \begin_inset Text
30911
30912 \layout Standard
30913
30914
30915 \size footnotesize 
30916 Logical and operation
30917 \end_inset 
30918 </cell>
30919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30920 \begin_inset Text
30921
30922 \layout Standard
30923
30924
30925 \size footnotesize 
30926 IC_RESULT = IC_LEFT && IC_RIGHT; 
30927 \end_inset 
30928 </cell>
30929 </row>
30930 <row topline="true">
30931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30932 \begin_inset Text
30933
30934 \layout Standard
30935
30936
30937 \size footnotesize 
30938 OR_OP
30939 \end_inset 
30940 </cell>
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30942 \begin_inset Text
30943
30944 \layout Standard
30945
30946
30947 \size footnotesize 
30948 IC_LEFT() IC_RIGHT() IC_RESULT() 
30949 \end_inset 
30950 </cell>
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30952 \begin_inset Text
30953
30954 \layout Standard
30955
30956
30957 \size footnotesize 
30958 Logical or operation 
30959 \end_inset 
30960 </cell>
30961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30962 \begin_inset Text
30963
30964 \layout Standard
30965
30966
30967 \size footnotesize 
30968 IC_RESULT = IC_LEFT || IC_RIGHT; 
30969 \end_inset 
30970 </cell>
30971 </row>
30972 <row topline="true">
30973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30974 \begin_inset Text
30975
30976 \layout Standard
30977
30978
30979 \size footnotesize 
30980 '^'
30981 \end_inset 
30982 </cell>
30983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30984 \begin_inset Text
30985
30986 \layout Standard
30987
30988
30989 \size footnotesize 
30990 IC_LEFT() IC_RIGHT() IC_RESULT() 
30991 \end_inset 
30992 </cell>
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_inset Text
30995
30996 \layout Standard
30997
30998
30999 \size footnotesize 
31000 Exclusive OR
31001 \end_inset 
31002 </cell>
31003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31004 \begin_inset Text
31005
31006 \layout Standard
31007
31008
31009 \size footnotesize 
31010 IC_RESULT = IC_LEFT ^ IC_RIGHT;
31011 \end_inset 
31012 </cell>
31013 </row>
31014 <row topline="true">
31015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31016 \begin_inset Text
31017
31018 \layout Standard
31019
31020
31021 \size footnotesize 
31022 '|'
31023 \end_inset 
31024 </cell>
31025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31026 \begin_inset Text
31027
31028 \layout Standard
31029
31030
31031 \size footnotesize 
31032 IC_LEFT() IC_RIGHT() IC_RESULT() 
31033 \end_inset 
31034 </cell>
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31036 \begin_inset Text
31037
31038 \layout Standard
31039
31040
31041 \size footnotesize 
31042 Bitwise OR 
31043 \end_inset 
31044 </cell>
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31046 \begin_inset Text
31047
31048 \layout Standard
31049
31050
31051 \size footnotesize 
31052 IC_RESULT = IC_LEFT | IC_RIGHT;
31053 \end_inset 
31054 </cell>
31055 </row>
31056 <row topline="true">
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31058 \begin_inset Text
31059
31060 \layout Standard
31061
31062
31063 \size footnotesize 
31064 BITWISEAND
31065 \end_inset 
31066 </cell>
31067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31068 \begin_inset Text
31069
31070 \layout Standard
31071
31072
31073 \size footnotesize 
31074 IC_LEFT() IC_RIGHT() IC_RESULT()
31075 \end_inset 
31076 </cell>
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31078 \begin_inset Text
31079
31080 \layout Standard
31081
31082
31083 \size footnotesize 
31084 Bitwise AND 
31085 \end_inset 
31086 </cell>
31087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31088 \begin_inset Text
31089
31090 \layout Standard
31091
31092
31093 \size footnotesize 
31094 IC_RESULT = IC_LEFT & IC_RIGHT;
31095 \end_inset 
31096 </cell>
31097 </row>
31098 <row topline="true">
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \layout Standard
31103
31104
31105 \size footnotesize 
31106 LEFT_OP
31107 \end_inset 
31108 </cell>
31109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31110 \begin_inset Text
31111
31112 \layout Standard
31113
31114
31115 \size footnotesize 
31116 IC_LEFT() IC_RIGHT() IC_RESULT()
31117 \end_inset 
31118 </cell>
31119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31120 \begin_inset Text
31121
31122 \layout Standard
31123
31124
31125 \size footnotesize 
31126 Left shift 
31127 \end_inset 
31128 </cell>
31129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31130 \begin_inset Text
31131
31132 \layout Standard
31133
31134
31135 \size footnotesize 
31136 IC_RESULT = IC_LEFT << IC_RIGHT 
31137 \end_inset 
31138 </cell>
31139 </row>
31140 <row topline="true">
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31142 \begin_inset Text
31143
31144 \layout Standard
31145
31146
31147 \size footnotesize 
31148 RIGHT_OP
31149 \end_inset 
31150 </cell>
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31152 \begin_inset Text
31153
31154 \layout Standard
31155
31156
31157 \size footnotesize 
31158 IC_LEFT() IC_RIGHT() IC_RESULT()
31159 \end_inset 
31160 </cell>
31161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31162 \begin_inset Text
31163
31164 \layout Standard
31165
31166
31167 \size footnotesize 
31168 Right shift
31169 \end_inset 
31170 </cell>
31171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31172 \begin_inset Text
31173
31174 \layout Standard
31175
31176
31177 \size footnotesize 
31178 IC_RESULT = IC_LEFT >> IC_RIGHT 
31179 \end_inset 
31180 </cell>
31181 </row>
31182 <row topline="true">
31183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31184 \begin_inset Text
31185
31186 \layout Standard
31187
31188
31189 \size footnotesize 
31190 GET_VALUE_
31191 \newline 
31192 AT_ ADDRESS
31193 \end_inset 
31194 </cell>
31195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31196 \begin_inset Text
31197
31198 \layout Standard
31199
31200
31201 \size footnotesize 
31202 IC_LEFT() IC_RESULT()
31203 \end_inset 
31204 </cell>
31205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31206 \begin_inset Text
31207
31208 \layout Standard
31209
31210
31211 \size footnotesize 
31212 Indirect fetch 
31213 \end_inset 
31214 </cell>
31215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31216 \begin_inset Text
31217
31218 \layout Standard
31219
31220
31221 \size footnotesize 
31222 IC_RESULT = (*IC_LEFT);
31223 \end_inset 
31224 </cell>
31225 </row>
31226 <row topline="true">
31227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_inset Text
31229
31230 \layout Standard
31231
31232
31233 \size footnotesize 
31234 POINTER_SET
31235 \end_inset 
31236 </cell>
31237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31238 \begin_inset Text
31239
31240 \layout Standard
31241
31242
31243 \size footnotesize 
31244 IC_RIGHT() IC_RESULT() 
31245 \end_inset 
31246 </cell>
31247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31248 \begin_inset Text
31249
31250 \layout Standard
31251
31252
31253 \size footnotesize 
31254 Indirect set
31255 \end_inset 
31256 </cell>
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31258 \begin_inset Text
31259
31260 \layout Standard
31261
31262
31263 \size footnotesize 
31264 (*IC_RESULT) = IC_RIGHT;
31265 \end_inset 
31266 </cell>
31267 </row>
31268 <row topline="true">
31269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31270 \begin_inset Text
31271
31272 \layout Standard
31273
31274
31275 \size footnotesize 
31276 '='
31277 \end_inset 
31278 </cell>
31279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31280 \begin_inset Text
31281
31282 \layout Standard
31283
31284
31285 \size footnotesize 
31286 IC_RIGHT() IC_RESULT()
31287 \end_inset 
31288 </cell>
31289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31290 \begin_inset Text
31291
31292 \layout Standard
31293
31294
31295 \size footnotesize 
31296 Assignment
31297 \end_inset 
31298 </cell>
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \layout Standard
31303
31304
31305 \size footnotesize 
31306 IC_RESULT = IC_RIGHT;
31307 \end_inset 
31308 </cell>
31309 </row>
31310 <row topline="true">
31311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31312 \begin_inset Text
31313
31314 \layout Standard
31315
31316
31317 \size footnotesize 
31318 IFX
31319 \end_inset 
31320 </cell>
31321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31322 \begin_inset Text
31323
31324 \layout Standard
31325
31326
31327 \size footnotesize 
31328 IC_COND IC_TRUE IC_LABEL
31329 \end_inset 
31330 </cell>
31331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31332 \begin_inset Text
31333
31334 \layout Standard
31335
31336
31337 \size footnotesize 
31338 Conditional jump.
31339  If true label is present then jump to true label if condition is true else
31340  jump to false label if condition is false 
31341 \end_inset 
31342 </cell>
31343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31344 \begin_inset Text
31345
31346 \layout Standard
31347
31348
31349 \size footnotesize 
31350 if (IC_COND) goto IC_TRUE; 
31351 \newline 
31352 \SpecialChar ~
31353 \SpecialChar ~
31354 Or 
31355 \newline 
31356 If (!IC_COND) goto IC_FALSE;
31357 \end_inset 
31358 </cell>
31359 </row>
31360 <row topline="true">
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \layout Standard
31365
31366
31367 \size footnotesize 
31368 ADDRESS_OF
31369 \end_inset 
31370 </cell>
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31372 \begin_inset Text
31373
31374 \layout Standard
31375
31376
31377 \size footnotesize 
31378 IC_LEFT() IC_RESULT()
31379 \end_inset 
31380 </cell>
31381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31382 \begin_inset Text
31383
31384 \layout Standard
31385
31386
31387 \size footnotesize 
31388 Address of 
31389 \end_inset 
31390 </cell>
31391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31392 \begin_inset Text
31393
31394 \layout Standard
31395
31396
31397 \size footnotesize 
31398 IC_RESULT = &IC_LEFT();
31399 \end_inset 
31400 </cell>
31401 </row>
31402 <row topline="true">
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31404 \begin_inset Text
31405
31406 \layout Standard
31407
31408
31409 \size footnotesize 
31410 JUMPTABLE
31411 \end_inset 
31412 </cell>
31413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31414 \begin_inset Text
31415
31416 \layout Standard
31417
31418
31419 \size footnotesize 
31420 IC_JTCOND IC_JTLABELS
31421 \end_inset 
31422 </cell>
31423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31424 \begin_inset Text
31425
31426 \layout Standard
31427
31428
31429 \size footnotesize 
31430 Jump to list of labels depending on the value of JTCOND
31431 \end_inset 
31432 </cell>
31433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31434 \begin_inset Text
31435
31436 \layout Standard
31437
31438
31439 \size footnotesize 
31440 Switch statement
31441 \end_inset 
31442 </cell>
31443 </row>
31444 <row topline="true">
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31446 \begin_inset Text
31447
31448 \layout Standard
31449
31450
31451 \size footnotesize 
31452 CAST
31453 \end_inset 
31454 </cell>
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31456 \begin_inset Text
31457
31458 \layout Standard
31459
31460
31461 \size footnotesize 
31462 IC_RIGHT() IC_LEFT() IC_RESULT()
31463 \end_inset 
31464 </cell>
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31466 \begin_inset Text
31467
31468 \layout Standard
31469
31470
31471 \size footnotesize 
31472 Cast types 
31473 \end_inset 
31474 </cell>
31475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31476 \begin_inset Text
31477
31478 \layout Standard
31479
31480
31481 \size footnotesize 
31482 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
31483 \end_inset 
31484 </cell>
31485 </row>
31486 <row topline="true">
31487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_inset Text
31489
31490 \layout Standard
31491
31492
31493 \size footnotesize 
31494 SEND
31495 \end_inset 
31496 </cell>
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \layout Standard
31501
31502
31503 \size footnotesize 
31504 IC_LEFT()
31505 \end_inset 
31506 </cell>
31507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31508 \begin_inset Text
31509
31510 \layout Standard
31511
31512
31513 \size footnotesize 
31514 This is used for passing parameters in registers; 
31515 \newline 
31516 move IC_LEFT to the next available parameter register.
31517 \end_inset 
31518 </cell>
31519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31520 \begin_inset Text
31521
31522 \layout Standard
31523
31524
31525 \size footnotesize 
31526 None
31527 \end_inset 
31528 </cell>
31529 </row>
31530 <row topline="true">
31531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31532 \begin_inset Text
31533
31534 \layout Standard
31535
31536
31537 \size footnotesize 
31538 RECV
31539 \end_inset 
31540 </cell>
31541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31542 \begin_inset Text
31543
31544 \layout Standard
31545
31546
31547 \size footnotesize 
31548 IC_RESULT()
31549 \end_inset 
31550 </cell>
31551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31552 \begin_inset Text
31553
31554 \layout Standard
31555
31556
31557 \size footnotesize 
31558 This is used for receiving parameters passed in registers;
31559 \newline 
31560 Move the values in the next parameter register to IC_RESULT 
31561 \end_inset 
31562 </cell>
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31564 \begin_inset Text
31565
31566 \layout Standard
31567
31568
31569 \size footnotesize 
31570 None
31571 \end_inset 
31572 </cell>
31573 </row>
31574 <row topline="true" bottomline="true">
31575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31576 \begin_inset Text
31577
31578 \layout Standard
31579
31580
31581 \shape slanted 
31582 \size footnotesize 
31583 (some more have been added)
31584 \end_inset 
31585 </cell>
31586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31587 \begin_inset Text
31588
31589 \layout Standard
31590
31591 \end_inset 
31592 </cell>
31593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31594 \begin_inset Text
31595
31596 \layout Standard
31597
31598 \end_inset 
31599 </cell>
31600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31601 \begin_inset Text
31602
31603 \layout Standard
31604
31605
31606 \shape slanted 
31607 \size footnotesize 
31608 see f.e.
31609  
31610 \family typewriter 
31611 gen51Code()
31612 \family default 
31613  in 
31614 \family typewriter 
31615 src/mcs51/gen.c
31616 \end_inset 
31617 </cell>
31618 </row>
31619 </lyxtabular>
31620
31621 \end_inset 
31622
31623
31624 \layout Comment
31625
31626 In the original article Figure II was announced to be downloadable on 
31627 \shape italic 
31628 Circuit Cellar
31629 \shape default 
31630 's web site.
31631  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
31632 \layout Paragraph*
31633
31634 ICode Example
31635 \begin_inset LatexCommand \index{iCode}
31636
31637 \end_inset 
31638
31639
31640 \layout Standard
31641
31642 This section shows some details of iCode.
31643  The example C code does not do anything useful; it is used as an example
31644  to illustrate the intermediate code generated by the compiler.
31645 \layout Verse
31646
31647
31648 \family typewriter 
31649 1.\SpecialChar ~
31650 xdata int * p;
31651 \newline 
31652 2.\SpecialChar ~
31653 int gint;
31654 \newline 
31655 3.\SpecialChar ~
31656 /* This function does nothing useful.
31657  It is used
31658 \newline 
31659 4.\SpecialChar ~
31660 \SpecialChar ~
31661 \SpecialChar ~
31662 \SpecialChar ~
31663 for the purpose of explaining iCode */
31664 \newline 
31665 5.\SpecialChar ~
31666 short function (data int *x)
31667 \newline 
31668 6.\SpecialChar ~
31669 {
31670 \newline 
31671 7.\SpecialChar ~
31672 \SpecialChar ~
31673 \SpecialChar ~
31674 short i=10; \SpecialChar ~
31675 \SpecialChar ~
31676 /* dead initialization eliminated */
31677 \newline 
31678 8.\SpecialChar ~
31679 \SpecialChar ~
31680 \SpecialChar ~
31681 short sum=10; /* dead initialization eliminated */
31682 \newline 
31683 9.\SpecialChar ~
31684 \SpecialChar ~
31685 \SpecialChar ~
31686 short mul;
31687 \newline 
31688 10.\SpecialChar ~
31689 \SpecialChar ~
31690 int j ;
31691 \newline 
31692 11.\SpecialChar ~
31693 \SpecialChar ~
31694 while (*x) *x++ = *p++; 
31695 \newline 
31696 12.\SpecialChar ~
31697 \SpecialChar ~
31698 \SpecialChar ~
31699 \SpecialChar ~
31700 sum = 0 ; 
31701 \newline 
31702 13.\SpecialChar ~
31703 \SpecialChar ~
31704 mul = 0;
31705 \newline 
31706 14.\SpecialChar ~
31707 \SpecialChar ~
31708 /* compiler detects i,j to be induction variables */
31709 \newline 
31710 15.\SpecialChar ~
31711 \SpecialChar ~
31712 for (i = 0, j = 10 ; i < 10 ; i++, j
31713 \family default 
31714 -
31715 \begin_inset ERT
31716 status Collapsed
31717
31718 \layout Standard
31719
31720 \backslash 
31721 /
31722 \end_inset 
31723
31724 -
31725 \family typewriter 
31726 ) {
31727 \newline 
31728 16.\SpecialChar ~
31729 \SpecialChar ~
31730 \SpecialChar ~
31731 \SpecialChar ~
31732 sum += i;
31733 \newline 
31734 17.\SpecialChar ~
31735 \SpecialChar ~
31736 \SpecialChar ~
31737 \SpecialChar ~
31738 mul += i * 3; \SpecialChar ~
31739 \SpecialChar ~
31740 /* this multiplication remains */
31741 \newline 
31742 18.\SpecialChar ~
31743 \SpecialChar ~
31744 \SpecialChar ~
31745 \SpecialChar ~
31746 gint += j * 3;\SpecialChar ~
31747 \SpecialChar ~
31748 /* this multiplication changed to addition */
31749 \newline 
31750 19.\SpecialChar ~
31751 \SpecialChar ~
31752 }
31753 \newline 
31754 20.\SpecialChar ~
31755 \SpecialChar ~
31756 return sum+mul;
31757 \newline 
31758 21.\SpecialChar ~
31759 }
31760 \layout Standard
31761
31762 In addition to the operands each iCode contains information about the filename
31763  and line it corresponds to in the source file.
31764  The first field in the listing should be interpreted as follows:
31765 \newline 
31766
31767 \shape italic 
31768 \size footnotesize 
31769 Filename(linenumber: iCode Execution sequence number : ICode hash table
31770  key : loop depth of the iCode).
31771 \shape default 
31772 \size default 
31773
31774 \newline 
31775 Then follows the human readable form of the ICode operation.
31776  Each operand of this triplet form can be of three basic types a) compiler
31777  generated temporary b) user defined variable c) a constant value.
31778  Note that local variables and parameters are replaced by compiler generated
31779  temporaries.
31780  Live ranges
31781 \begin_inset LatexCommand \index{Live range analysis}
31782
31783 \end_inset 
31784
31785  are computed only for temporaries (i.e.
31786  live ranges are not computed for global variables).
31787  Registers
31788 \begin_inset LatexCommand \index{Register allocation}
31789
31790 \end_inset 
31791
31792  are allocated for temporaries only.
31793  Operands are formatted in the following manner:
31794 \newline 
31795
31796 \shape italic 
31797 \size footnotesize 
31798 Operand Name [lr live-from : live-to ] { type information } [ registers
31799  allocated ].
31800 \shape default 
31801 \size default 
31802
31803 \newline 
31804 As mentioned earlier the live ranges are computed in terms of the execution
31805  sequence number of the iCodes, for example 
31806 \newline 
31807 the iTemp0 is live from (i.e.
31808  first defined in iCode with execution sequence number 3, and is last used
31809  in the iCode with sequence number 5).
31810  For induction variables such as iTemp21 the live range computation extends
31811  the lifetime from the start to the end of the loop.
31812 \newline 
31813 The register allocator used the live range information to allocate registers,
31814  the same registers may be used for different temporaries if their live
31815  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
31816  iTemp17 since their live ranges do not overlap.
31817  In addition the allocator also takes into consideration the type and usage
31818  of a temporary, for example itemp6 is a pointer to near space and is used
31819  as to fetch data from (i.e.
31820  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
31821  Some short lived temporaries are allocated to special registers which have
31822  meaning to the code generator e.g.
31823  iTemp13 is allocated to a pseudo register CC which tells the back end that
31824  the temporary is used only for a conditional jump the code generation makes
31825  use of this information to optimize a compare and jump ICode.
31826 \newline 
31827 There are several loop optimizations
31828 \begin_inset LatexCommand \index{Loop optimization}
31829
31830 \end_inset 
31831
31832  performed by the compiler.
31833  It can detect induction variables iTemp21(i) and iTemp23(j).
31834  Also note the compiler does selective strength reduction
31835 \begin_inset LatexCommand \index{Strength reduction}
31836
31837 \end_inset 
31838
31839 , i.e.
31840  the multiplication of an induction variable in line 18 (gint = j * 3) is
31841  changed to addition, a new temporary iTemp17 is allocated and assigned
31842  a initial value, a constant 3 is then added for each iteration of the loop.
31843  The compiler does not change the multiplication
31844 \begin_inset LatexCommand \index{Multiplication}
31845
31846 \end_inset 
31847
31848  in line 17 however since the processor does support an 8 * 8 bit multiplication.
31849 \newline 
31850 Note the dead code elimination
31851 \begin_inset LatexCommand \index{Dead-code elimination}
31852
31853 \end_inset 
31854
31855  optimization eliminated the dead assignments in line 7 & 8 to I and sum
31856  respectively.
31857 \newline 
31858
31859 \layout Standard
31860
31861
31862 \size footnotesize 
31863 Sample.c (5:1:0:0) _entry($9) :
31864 \layout Standard
31865
31866
31867 \size footnotesize 
31868 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
31869 \layout Standard
31870
31871
31872 \size footnotesize 
31873 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
31874 \layout Standard
31875
31876
31877 \size footnotesize 
31878 Sample.c(11:4:53:0) preHeaderLbl0($11) :
31879 \layout Standard
31880
31881
31882 \size footnotesize 
31883 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
31884  * int}[r2]
31885 \layout Standard
31886
31887
31888 \size footnotesize 
31889 Sample.c(11:6:5:1) _whilecontinue_0($1) :
31890 \layout Standard
31891
31892
31893 \size footnotesize 
31894 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
31895  int}[r0]]
31896 \layout Standard
31897
31898
31899 \size footnotesize 
31900 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
31901 \layout Standard
31902
31903
31904 \size footnotesize 
31905 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
31906  * int}
31907 \layout Standard
31908
31909
31910 \size footnotesize 
31911 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
31912  {short}
31913 \layout Standard
31914
31915
31916 \size footnotesize 
31917 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
31918  * int}[DPTR]]
31919 \layout Standard
31920
31921
31922 \size footnotesize 
31923 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
31924 }[r2 r3]
31925 \layout Standard
31926
31927
31928 \size footnotesize 
31929 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
31930  * int}[r0] + 0x2 {short}
31931 \layout Standard
31932
31933
31934 \size footnotesize 
31935 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
31936 \layout Standard
31937
31938
31939 \size footnotesize 
31940 Sample.c(11:17:21:0)_whilebreak_0($3) :
31941 \layout Standard
31942
31943
31944 \size footnotesize 
31945 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
31946 \layout Standard
31947
31948
31949 \size footnotesize 
31950 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
31951 \layout Standard
31952
31953
31954 \size footnotesize 
31955 Sample.c(15:20:54:0)preHeaderLbl1($13) :
31956 \layout Standard
31957
31958
31959 \size footnotesize 
31960 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
31961 \layout Standard
31962
31963
31964 \size footnotesize 
31965 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
31966 \layout Standard
31967
31968
31969 \size footnotesize 
31970 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
31971 \layout Standard
31972
31973
31974 \size footnotesize 
31975 Sample.c(15:24:26:1)_forcond_0($4) :
31976 \layout Standard
31977
31978
31979 \size footnotesize 
31980 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
31981  < 0xa {short}
31982 \layout Standard
31983
31984
31985 \size footnotesize 
31986 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
31987 \layout Standard
31988
31989
31990 \size footnotesize 
31991 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
31992  + ITemp21 [lr21:38]{short}[r4]
31993 \layout Standard
31994
31995
31996 \size footnotesize 
31997 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
31998  * 0x3 {short}
31999 \layout Standard
32000
32001
32002 \size footnotesize 
32003 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
32004  + iTemp15 [lr29:30]{short}[r1]
32005 \layout Standard
32006
32007
32008 \size footnotesize 
32009 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
32010  r0]- 0x3 {short}
32011 \layout Standard
32012
32013
32014 \size footnotesize 
32015 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
32016 int}[r7 r0]
32017 \layout Standard
32018
32019
32020 \size footnotesize 
32021 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
32022  + 0x1 {short}
32023 \layout Standard
32024
32025
32026 \size footnotesize 
32027 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
32028  r6]- 0x1 {short}
32029 \layout Standard
32030
32031
32032 \size footnotesize 
32033 Sample.c(19:38:47:1) goto _forcond_0($4)
32034 \layout Standard
32035
32036
32037 \size footnotesize 
32038 Sample.c(19:39:48:0)_forbreak_0($7) :
32039 \layout Standard
32040
32041
32042 \size footnotesize 
32043 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
32044  + ITemp11 [lr19:40]{short}[r3]
32045 \layout Standard
32046
32047
32048 \size footnotesize 
32049 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
32050 \layout Standard
32051
32052
32053 \size footnotesize 
32054 Sample.c(20:42:51:0)_return($8) :
32055 \layout Standard
32056
32057
32058 \size footnotesize 
32059 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
32060 \size default 
32061
32062 \newline 
32063
32064 \newline 
32065 Finally the code generated for this function:
32066 \newline 
32067
32068 \layout Standard
32069
32070
32071 \size footnotesize 
32072 .area DSEG (DATA)
32073 \layout Standard
32074
32075
32076 \size footnotesize 
32077 _p::
32078 \layout Standard
32079
32080
32081 \size footnotesize 
32082 \SpecialChar ~
32083 \SpecialChar ~
32084 .ds 2
32085 \layout Standard
32086
32087
32088 \size footnotesize 
32089 _gint::
32090 \layout Standard
32091
32092
32093 \size footnotesize 
32094 \SpecialChar ~
32095 \SpecialChar ~
32096 .ds 2
32097 \layout Standard
32098
32099
32100 \size footnotesize 
32101 ; sample.c 5
32102 \layout Standard
32103
32104
32105 \size footnotesize 
32106 ; ----------------------------------------------
32107 \layout Standard
32108
32109
32110 \size footnotesize 
32111 ; function function
32112 \layout Standard
32113
32114
32115 \size footnotesize 
32116 ; ----------------------------------------------
32117 \layout Standard
32118
32119
32120 \size footnotesize 
32121 _function:
32122 \layout Standard
32123
32124
32125 \size footnotesize 
32126 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
32127 \layout Standard
32128
32129
32130 \size footnotesize 
32131 \SpecialChar ~
32132 \SpecialChar ~
32133 mov r2,dpl
32134 \layout Standard
32135
32136
32137 \size footnotesize 
32138 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
32139 \layout Standard
32140
32141
32142 \size footnotesize 
32143 \SpecialChar ~
32144 \SpecialChar ~
32145 mov ar0,r2
32146 \layout Standard
32147
32148
32149 \size footnotesize 
32150 ;_whilecontinue_0($1) :
32151 \layout Standard
32152
32153
32154 \size footnotesize 
32155 00101$:
32156 \layout Standard
32157
32158
32159 \size footnotesize 
32160 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
32161 \layout Standard
32162
32163
32164 \size footnotesize 
32165 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32166 \layout Standard
32167
32168
32169 \size footnotesize 
32170 \SpecialChar ~
32171 \SpecialChar ~
32172 mov ar2,@r0
32173 \layout Standard
32174
32175
32176 \size footnotesize 
32177 \SpecialChar ~
32178 \SpecialChar ~
32179 inc r0
32180 \layout Standard
32181
32182
32183 \size footnotesize 
32184 \SpecialChar ~
32185 \SpecialChar ~
32186 mov ar3,@r0
32187 \layout Standard
32188
32189
32190 \size footnotesize 
32191 \SpecialChar ~
32192 \SpecialChar ~
32193 dec r0
32194 \layout Standard
32195
32196
32197 \size footnotesize 
32198 \SpecialChar ~
32199 \SpecialChar ~
32200 mov a,r2
32201 \layout Standard
32202
32203
32204 \size footnotesize 
32205 \SpecialChar ~
32206 \SpecialChar ~
32207 orl a,r3
32208 \layout Standard
32209
32210
32211 \size footnotesize 
32212 \SpecialChar ~
32213 \SpecialChar ~
32214 jz 00103$
32215 \layout Standard
32216
32217
32218 \size footnotesize 
32219 00114$:
32220 \layout Standard
32221
32222
32223 \size footnotesize 
32224 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
32225 \layout Standard
32226
32227
32228 \size footnotesize 
32229 \SpecialChar ~
32230 \SpecialChar ~
32231 mov dpl,_p
32232 \layout Standard
32233
32234
32235 \size footnotesize 
32236 \SpecialChar ~
32237 \SpecialChar ~
32238 mov dph,(_p + 1)
32239 \layout Standard
32240
32241
32242 \size footnotesize 
32243 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
32244 \layout Standard
32245
32246
32247 \size footnotesize 
32248 \SpecialChar ~
32249 \SpecialChar ~
32250 mov a,#0x02
32251 \layout Standard
32252
32253
32254 \size footnotesize 
32255 \SpecialChar ~
32256 \SpecialChar ~
32257 add a,_p
32258 \layout Standard
32259
32260
32261 \size footnotesize 
32262 \SpecialChar ~
32263 \SpecialChar ~
32264 mov _p,a
32265 \layout Standard
32266
32267
32268 \size footnotesize 
32269 \SpecialChar ~
32270 \SpecialChar ~
32271 clr a
32272 \layout Standard
32273
32274
32275 \size footnotesize 
32276 \SpecialChar ~
32277 \SpecialChar ~
32278 addc a,(_p + 1)
32279 \layout Standard
32280
32281
32282 \size footnotesize 
32283 \SpecialChar ~
32284 \SpecialChar ~
32285 mov (_p + 1),a
32286 \layout Standard
32287
32288
32289 \size footnotesize 
32290 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
32291 \layout Standard
32292
32293
32294 \size footnotesize 
32295 \SpecialChar ~
32296 \SpecialChar ~
32297 movx a,@dptr
32298 \layout Standard
32299
32300
32301 \size footnotesize 
32302 \SpecialChar ~
32303 \SpecialChar ~
32304 mov r2,a
32305 \layout Standard
32306
32307
32308 \size footnotesize 
32309 \SpecialChar ~
32310 \SpecialChar ~
32311 inc dptr
32312 \layout Standard
32313
32314
32315 \size footnotesize 
32316 \SpecialChar ~
32317 \SpecialChar ~
32318 movx a,@dptr
32319 \layout Standard
32320
32321
32322 \size footnotesize 
32323 \SpecialChar ~
32324 \SpecialChar ~
32325 mov r3,a
32326 \layout Standard
32327
32328
32329 \size footnotesize 
32330 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
32331 \layout Standard
32332
32333
32334 \size footnotesize 
32335 \SpecialChar ~
32336 \SpecialChar ~
32337 mov @r0,ar2
32338 \layout Standard
32339
32340
32341 \size footnotesize 
32342 \SpecialChar ~
32343 \SpecialChar ~
32344 inc r0
32345 \layout Standard
32346
32347
32348 \size footnotesize 
32349 \SpecialChar ~
32350 \SpecialChar ~
32351 mov @r0,ar3
32352 \layout Standard
32353
32354
32355 \size footnotesize 
32356 ; iTemp6 [lr5:16]{_near * int}[r0] = 
32357 \layout Standard
32358
32359
32360 \size footnotesize 
32361 ; iTemp6 [lr5:16]{_near * int}[r0] + 
32362 \layout Standard
32363
32364
32365 \size footnotesize 
32366 ; 0x2 {short}
32367 \layout Standard
32368
32369
32370 \size footnotesize 
32371 \SpecialChar ~
32372 \SpecialChar ~
32373 inc r0
32374 \layout Standard
32375
32376
32377 \size footnotesize 
32378 ; goto _whilecontinue_0($1)
32379 \layout Standard
32380
32381
32382 \size footnotesize 
32383 \SpecialChar ~
32384 \SpecialChar ~
32385 sjmp 00101$
32386 \layout Standard
32387
32388
32389 \size footnotesize 
32390 ; _whilebreak_0($3) :
32391 \layout Standard
32392
32393
32394 \size footnotesize 
32395 00103$:
32396 \layout Standard
32397
32398
32399 \size footnotesize 
32400 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32401 \layout Standard
32402
32403
32404 \size footnotesize 
32405 \SpecialChar ~
32406 \SpecialChar ~
32407 mov r2,#0x00
32408 \layout Standard
32409
32410
32411 \size footnotesize 
32412 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32413 \layout Standard
32414
32415
32416 \size footnotesize 
32417 \SpecialChar ~
32418 \SpecialChar ~
32419 mov r3,#0x00
32420 \layout Standard
32421
32422
32423 \size footnotesize 
32424 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32425 \layout Standard
32426
32427
32428 \size footnotesize 
32429 \SpecialChar ~
32430 \SpecialChar ~
32431 mov r4,#0x00
32432 \layout Standard
32433
32434
32435 \size footnotesize 
32436 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32437 \layout Standard
32438
32439
32440 \size footnotesize 
32441 \SpecialChar ~
32442 \SpecialChar ~
32443 mov r5,#0x0A
32444 \layout Standard
32445
32446
32447 \size footnotesize 
32448 \SpecialChar ~
32449 \SpecialChar ~
32450 mov r6,#0x00
32451 \layout Standard
32452
32453
32454 \size footnotesize 
32455 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32456 \layout Standard
32457
32458
32459 \size footnotesize 
32460 \SpecialChar ~
32461 \SpecialChar ~
32462 mov r7,#0x1E
32463 \layout Standard
32464
32465
32466 \size footnotesize 
32467 \SpecialChar ~
32468 \SpecialChar ~
32469 mov r0,#0x00
32470 \layout Standard
32471
32472
32473 \size footnotesize 
32474 ; _forcond_0($4) :
32475 \layout Standard
32476
32477
32478 \size footnotesize 
32479 00104$:
32480 \layout Standard
32481
32482
32483 \size footnotesize 
32484 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
32485 \layout Standard
32486
32487
32488 \size footnotesize 
32489 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32490 \layout Standard
32491
32492
32493 \size footnotesize 
32494 \SpecialChar ~
32495 \SpecialChar ~
32496 clr c
32497 \layout Standard
32498
32499
32500 \size footnotesize 
32501 \SpecialChar ~
32502 \SpecialChar ~
32503 mov a,r4
32504 \layout Standard
32505
32506
32507 \size footnotesize 
32508 \SpecialChar ~
32509 \SpecialChar ~
32510 xrl a,#0x80
32511 \layout Standard
32512
32513
32514 \size footnotesize 
32515 \SpecialChar ~
32516 \SpecialChar ~
32517 subb a,#0x8a
32518 \layout Standard
32519
32520
32521 \size footnotesize 
32522 \SpecialChar ~
32523 \SpecialChar ~
32524 jnc 00107$
32525 \layout Standard
32526
32527
32528 \size footnotesize 
32529 00115$:
32530 \layout Standard
32531
32532
32533 \size footnotesize 
32534 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
32535 \layout Standard
32536
32537
32538 \size footnotesize 
32539 ; iTemp21 [lr21:38]{short}[r4]
32540 \layout Standard
32541
32542
32543 \size footnotesize 
32544 \SpecialChar ~
32545 \SpecialChar ~
32546 mov a,r4
32547 \layout Standard
32548
32549
32550 \size footnotesize 
32551 \SpecialChar ~
32552 \SpecialChar ~
32553 add a,r2
32554 \layout Standard
32555
32556
32557 \size footnotesize 
32558 \SpecialChar ~
32559 \SpecialChar ~
32560 mov r2,a
32561 \layout Standard
32562
32563
32564 \size footnotesize 
32565 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
32566 \layout Standard
32567
32568
32569 \size footnotesize 
32570 \SpecialChar ~
32571 \SpecialChar ~
32572 mov b,#0x03
32573 \layout Standard
32574
32575
32576 \size footnotesize 
32577 \SpecialChar ~
32578 \SpecialChar ~
32579 mov a,r4
32580 \layout Standard
32581
32582
32583 \size footnotesize 
32584 \SpecialChar ~
32585 \SpecialChar ~
32586 mul ab
32587 \layout Standard
32588
32589
32590 \size footnotesize 
32591 \SpecialChar ~
32592 \SpecialChar ~
32593 mov r1,a
32594 \layout Standard
32595
32596
32597 \size footnotesize 
32598 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
32599 \layout Standard
32600
32601
32602 \size footnotesize 
32603 ; iTemp15 [lr29:30]{short}[r1]
32604 \layout Standard
32605
32606
32607 \size footnotesize 
32608 \SpecialChar ~
32609 \SpecialChar ~
32610 add a,r3
32611 \layout Standard
32612
32613
32614 \size footnotesize 
32615 \SpecialChar ~
32616 \SpecialChar ~
32617 mov r3,a
32618 \layout Standard
32619
32620
32621 \size footnotesize 
32622 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
32623 \layout Standard
32624
32625
32626 \size footnotesize 
32627 \SpecialChar ~
32628 \SpecialChar ~
32629 mov a,r7
32630 \layout Standard
32631
32632
32633 \size footnotesize 
32634 \SpecialChar ~
32635 \SpecialChar ~
32636 add a,#0xfd
32637 \layout Standard
32638
32639
32640 \size footnotesize 
32641 \SpecialChar ~
32642 \SpecialChar ~
32643 mov r7,a
32644 \layout Standard
32645
32646
32647 \size footnotesize 
32648 \SpecialChar ~
32649 \SpecialChar ~
32650 mov a,r0
32651 \layout Standard
32652
32653
32654 \size footnotesize 
32655 \SpecialChar ~
32656 \SpecialChar ~
32657 addc a,#0xff
32658 \layout Standard
32659
32660
32661 \size footnotesize 
32662 \SpecialChar ~
32663 \SpecialChar ~
32664 mov r0,a
32665 \layout Standard
32666
32667
32668 \size footnotesize 
32669 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
32670 \layout Standard
32671
32672
32673 \size footnotesize 
32674 \SpecialChar ~
32675 \SpecialChar ~
32676 mov a,r7
32677 \layout Standard
32678
32679
32680 \size footnotesize 
32681 \SpecialChar ~
32682 \SpecialChar ~
32683 add a,_gint
32684 \layout Standard
32685
32686
32687 \size footnotesize 
32688 \SpecialChar ~
32689 \SpecialChar ~
32690 mov _gint,a
32691 \layout Standard
32692
32693
32694 \size footnotesize 
32695 \SpecialChar ~
32696 \SpecialChar ~
32697 mov a,r0
32698 \layout Standard
32699
32700
32701 \size footnotesize 
32702 \SpecialChar ~
32703 \SpecialChar ~
32704 addc a,(_gint + 1)
32705 \layout Standard
32706
32707
32708 \size footnotesize 
32709 \SpecialChar ~
32710 \SpecialChar ~
32711 mov (_gint + 1),a
32712 \layout Standard
32713
32714
32715 \size footnotesize 
32716 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
32717 \layout Standard
32718
32719
32720 \size footnotesize 
32721 \SpecialChar ~
32722 \SpecialChar ~
32723 inc r4
32724 \layout Standard
32725
32726
32727 \size footnotesize 
32728 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
32729 \layout Standard
32730
32731
32732 \size footnotesize 
32733 \SpecialChar ~
32734 \SpecialChar ~
32735 dec r5
32736 \layout Standard
32737
32738
32739 \size footnotesize 
32740 \SpecialChar ~
32741 \SpecialChar ~
32742 cjne r5,#0xff,00104$
32743 \layout Standard
32744
32745
32746 \size footnotesize 
32747 \SpecialChar ~
32748 \SpecialChar ~
32749 dec r6
32750 \layout Standard
32751
32752
32753 \size footnotesize 
32754 ; goto _forcond_0($4)
32755 \layout Standard
32756
32757
32758 \size footnotesize 
32759 \SpecialChar ~
32760 \SpecialChar ~
32761 sjmp 00104$
32762 \layout Standard
32763
32764
32765 \size footnotesize 
32766 ; _forbreak_0($7) :
32767 \layout Standard
32768
32769
32770 \size footnotesize 
32771 00107$:
32772 \layout Standard
32773
32774
32775 \size footnotesize 
32776 ; ret iTemp24 [lr40:41]{short}
32777 \layout Standard
32778
32779
32780 \size footnotesize 
32781 \SpecialChar ~
32782 \SpecialChar ~
32783 mov a,r3
32784 \layout Standard
32785
32786
32787 \size footnotesize 
32788 \SpecialChar ~
32789 \SpecialChar ~
32790 add a,r2
32791 \layout Standard
32792
32793
32794 \size footnotesize 
32795 \SpecialChar ~
32796 \SpecialChar ~
32797 mov dpl,a
32798 \layout Standard
32799
32800
32801 \size footnotesize 
32802 ; _return($8) :
32803 \layout Standard
32804
32805
32806 \size footnotesize 
32807 00108$:
32808 \layout Standard
32809
32810
32811 \size footnotesize 
32812 \SpecialChar ~
32813 \SpecialChar ~
32814 ret
32815 \newline 
32816
32817 \layout Section
32818
32819 A few words about basic block successors, predecessors and dominators
32820 \layout Standard
32821
32822 Successors are basic blocks
32823 \begin_inset LatexCommand \index{Basic blocks}
32824
32825 \end_inset 
32826
32827  that might execute after this basic block.
32828 \newline 
32829 Predecessors are basic blocks that might execute before reaching this basic
32830  block.
32831 \newline 
32832 Dominators are basic blocks that WILL execute before reaching this basic
32833  block.
32834 \newline 
32835
32836 \layout Standard
32837
32838 [basic block 1]
32839 \layout Standard
32840
32841 if (something)
32842 \layout Standard
32843
32844 \SpecialChar ~
32845 \SpecialChar ~
32846 \SpecialChar ~
32847 \SpecialChar ~
32848 [basic block 2]
32849 \layout Standard
32850
32851 else
32852 \layout Standard
32853
32854 \SpecialChar ~
32855 \SpecialChar ~
32856 \SpecialChar ~
32857 \SpecialChar ~
32858 [basic block 3]
32859 \layout Standard
32860
32861 [basic block 4]
32862 \newline 
32863
32864 \layout Standard
32865
32866 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
32867 \layout Standard
32868
32869 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
32870 \layout Standard
32871
32872 c) domVect of [BB4] = BB1 ...
32873  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
32874  was executed.
32875 \layout Chapter
32876
32877 Acknowledgments
32878 \layout Standard
32879
32880
32881 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
32882
32883 \end_inset 
32884
32885
32886 \newline 
32887
32888 \newline 
32889
32890 \emph on 
32891 Thanks to all the other volunteer developers who have helped with coding,
32892  testing, web-page creation, distribution sets, etc.
32893  You know who you are :-)
32894 \emph default 
32895
32896 \newline 
32897
32898 \newline 
32899
32900 \emph on 
32901 Also thanks to Sourceforge 
32902 \begin_inset LatexCommand \url{http://www.sf.net}
32903
32904 \end_inset 
32905
32906  which has hosted the project since 1999 and donates significant download
32907  bandwidth and probably more than 
32908 \begin_inset ERT
32909 status Collapsed
32910
32911 \layout Standard
32912 $10^{13}$
32913 \end_inset 
32914
32915 CPU cycles per day.
32916 \newline 
32917  
32918 \begin_inset Note
32919 collapsed false
32920
32921 \layout Standard
32922
32923 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
32924  minutes for (configure+make+regression test), and there is (i386, amd64,
32925  alpha, ppc64, (mingw32), sparc, macosx).
32926  
32927 \end_inset 
32928
32929
32930 \layout Standard
32931
32932 This document was initially written by Sandeep Dutta
32933 \layout Standard
32934
32935 All product names mentioned herein may be trademarks
32936 \begin_inset LatexCommand \index{Trademarks}
32937
32938 \end_inset 
32939
32940  of their respective companies.
32941  
32942 \layout Section*
32943
32944 Alphabetical index
32945 \layout Standard
32946
32947 To avoid confusion, the installation and building options for SDCC itself
32948  (chapter 2) are not part of the index.
32949 \layout Standard
32950
32951
32952 \begin_inset LatexCommand \printindex{}
32953
32954 \end_inset 
32955
32956
32957 \the_end