* src/mcs51/peeph.def: added 101.a,b (moves to int/long xdata)
[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.1
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargeted for other microprocessors, support for Microchip PIC,
146  Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargetable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.295
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE 754
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 1.175494351E-38, 
506 \family roman 
507 \series medium 
508 \shape up 
509 \size normal 
510 \emph off 
511 \bar no 
512 \noun off 
513 \color none
514 3.402823466E+38
515 \end_inset 
516 </cell>
517 </row>
518 <row topline="true" bottomline="true">
519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
520 \begin_inset Text
521
522 \layout Standard
523
524 pointer
525 \end_inset 
526 </cell>
527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_inset Text
529
530 \layout Standard
531
532 1, 2, 3 or 4 bytes
533 \end_inset 
534 </cell>
535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
536 \begin_inset Text
537
538 \layout Standard
539
540 generic
541 \end_inset 
542 </cell>
543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_inset Text
545
546 \layout Standard
547
548 \end_inset 
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
551 \begin_inset Text
552
553 \layout Standard
554
555 \end_inset 
556 </cell>
557 </row>
558 </lyxtabular>
559
560 \end_inset 
561
562
563 \newline 
564 The compiler also allows 
565 \emph on 
566 inline assembler code
567 \emph default 
568  to be embedded anywhere in a function.
569  In addition, routines developed in assembly can also be called.
570 \newline 
571
572 \newline 
573 SDCC also provides an option (-
574 \begin_inset ERT
575 status Collapsed
576
577 \layout Standard
578
579 \backslash 
580 /
581 \end_inset 
582
583 -cyclomatic) to report the relative complexity of a function.
584  These functions can then be further optimized, or hand coded in assembly
585  if needed.
586  
587 \newline 
588
589 \newline 
590 SDCC also comes with a companion source level debugger SDCDB, the debugger
591  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
592 \newline 
593
594 \newline 
595 The latest version can be downloaded from 
596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
597
598 \end_inset 
599
600 .
601
602 \series bold 
603  
604 \series default 
605 \emph on 
606 Please note: the compiler will probably always be some steps ahead of this
607  documentation
608 \series bold 
609 \emph default 
610
611 \begin_inset LatexCommand \index{Status of documentation}
612
613 \end_inset 
614
615
616 \begin_inset Foot
617 collapsed false
618
619 \layout Standard
620
621 Obviously this has pros and cons
622 \end_inset 
623
624 .
625 \layout Section
626
627 Open Source
628 \layout Standard
629
630 All packages used in this compiler system are 
631 \emph on 
632 open source
633 \emph default 
634  and 
635 \emph on 
636 freeware
637 \emph default 
638 ; source code for all the sub-packages (pre-processor, assemblers, linkers
639  etc) is distributed with the package.
640  This documentation is maintained using a freeware word processor (LyX).
641 \newline 
642 This program is free software; you can redistribute it and/or modify it
643  under the terms of the GNU General Public License
644 \begin_inset LatexCommand \index{GNU General Public License, GPL}
645
646 \end_inset 
647
648  as published by the Free Software Foundation; either version 2, or (at
649  your option) any later version.
650  This program is distributed in the hope that it will be useful, but WITHOUT
651  ANY WARRANTY; without even the implied warranty
652 \begin_inset LatexCommand \index{warranty}
653
654 \end_inset 
655
656  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
657  See the GNU General Public License for more details.
658  You should have received a copy of the GNU General Public License along
659  with this program; if not, write to the Free Software Foundation, 59 Temple
660  Place - Suite 330, Boston, MA 02111-1307, USA.
661  In other words, you are welcome to use, share and improve this program.
662  You are forbidden to forbid anyone else to use, share and improve what
663  you give them.
664  Help stamp out software-hoarding! 
665 \layout Section
666
667 Typographic conventions
668 \begin_inset LatexCommand \index{Typographic conventions}
669
670 \end_inset 
671
672
673 \layout Standard
674
675 Throughout this manual, we will use the following convention.
676  Commands you have to type in are printed in 
677 \family sans 
678 \series bold 
679 "sans serif"
680 \series default 
681 .
682
683 \family default 
684  Code samples are printed in 
685 \family typewriter 
686 typewriter font.
687
688 \family default 
689  Interesting items and new terms are printed in 
690 \emph on 
691 italic.
692 \layout Section
693
694 Compatibility
695 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
696
697 \end_inset 
698
699  with previous versions
700 \begin_inset LatexCommand \index{Compatibility with previous versions}
701
702 \end_inset 
703
704
705 \layout Standard
706
707 This version has numerous bug fixes compared with the previous version.
708  But we also introduced some incompatibilities with older versions.
709  Not just for the fun of it, but to make the compiler more stable, efficient
710  and ANSI compliant
711 \begin_inset LatexCommand \index{ANSI-compliance}
712
713 \end_inset 
714
715  (see section 
716 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
717
718 \end_inset 
719
720  for ANSI-Compliance).
721  
722 \newline 
723
724 \layout Itemize
725
726 short is now equivalent to int (16 bits), it used to be equivalent to char
727  (8 bits) which is not ANSI compliant.
728 \layout Itemize
729
730 the default directory for gcc-builds where include, library and documentation
731  files are stored is now in /usr/local/share.
732 \layout Itemize
733
734 char type parameters to vararg
735 \begin_inset LatexCommand \index{vararg, va\_arg}
736
737 \end_inset 
738
739  functions are casted to int unless explicitly casted
740 \begin_inset Marginal
741 collapsed true
742
743 \layout Standard
744
745
746 \series bold 
747 \SpecialChar ~
748 !
749 \end_inset 
750
751 , e.g.: 
752 \newline 
753
754 \family typewriter 
755 \SpecialChar ~
756 \SpecialChar ~
757 char a=3;
758 \newline 
759 \SpecialChar ~
760 \SpecialChar ~
761 printf ("%d %c
762 \backslash 
763 n", a, (char)a);
764 \family default 
765
766 \newline 
767  will push a as an int and as a char resp.
768 \layout Itemize
769
770 option -
771 \begin_inset ERT
772 status Collapsed
773
774 \layout Standard
775
776 \backslash 
777 /
778 \end_inset 
779
780 -regextend has been removed.
781 \layout Itemize
782
783 option -
784 \begin_inset ERT
785 status Collapsed
786
787 \layout Standard
788
789 \backslash 
790 /
791 \end_inset 
792
793 -noregparms has been removed.
794 \layout Itemize
795
796 option -
797 \begin_inset ERT
798 status Collapsed
799
800 \layout Standard
801
802 \backslash 
803 /
804 \end_inset 
805
806 -stack-after-data has been removed.
807 \layout Itemize
808
809 bit
810 \begin_inset LatexCommand \index{bit}
811
812 \end_inset 
813
814  and sbit
815 \begin_inset LatexCommand \index{sbit}
816
817 \end_inset 
818
819
820 \begin_inset LatexCommand \index{\_\_sbit}
821
822 \end_inset 
823
824  types now consistently behave like the C99 _Bool type with respect to type
825  conversion
826 \begin_inset LatexCommand \index{type conversion}
827
828 \end_inset 
829
830
831 \begin_inset LatexCommand \index{type promotion}
832
833 \end_inset 
834
835 .
836  The most common incompatibility resulting from this change is related to
837  bit toggling
838 \begin_inset LatexCommand \index{Bit toggling}
839
840 \end_inset 
841
842  idioms, e.g.:
843 \newline 
844
845 \family typewriter 
846 \SpecialChar ~
847 \SpecialChar ~
848 bit b;
849 \newline 
850 \SpecialChar ~
851 \SpecialChar ~
852 b = ~
853 \begin_inset LatexCommand \index{\~\/ Operator}
854
855 \end_inset 
856
857 b; /* equivalent to b=1 instead of toggling b */
858 \begin_inset Marginal
859 collapsed true
860
861 \layout Standard
862
863
864 \series bold 
865 \SpecialChar ~
866 !
867 \end_inset 
868
869
870 \newline 
871 \SpecialChar ~
872 \SpecialChar ~
873 b = !b; /* toggles b */
874 \newline 
875
876 \family default 
877 In previous versions, both forms would have toggled the bit.
878 \layout Standard
879
880
881 \emph on 
882 <pending: more incompatibilities?>
883 \layout Section
884
885 System Requirements
886 \layout Standard
887
888 What do you need before you start installation of SDCC? A computer, and
889  a desire to compute.
890  The preferred method of installation is to compile SDCC from source using
891  GNU gcc and make.
892  For Windows some pre-compiled binary distributions are available for your
893  convenience.
894  You should have some experience with command line tools and compiler use.
895 \layout Section
896
897 Other Resources
898 \layout Standard
899
900 The SDCC home page at 
901 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
902
903 \end_inset 
904
905  is a great place to find distribution sets.
906  You can also find links to the user mailing lists that offer help or discuss
907  SDCC with other SDCC users.
908  Web links to other SDCC related sites can also be found here.
909  This document can be found in the DOC directory of the source package as
910  a text or HTML file.
911  A pdf version of this document is available at 
912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
913
914 \end_inset 
915
916 .
917  Some of the other tools (simulator and assembler) included with SDCC contain
918  their own documentation and can be found in the source distribution.
919  If you want the latest unreleased software, the complete source package
920  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
921 /trunk/sdcc.
922 \layout Section
923
924 Wishes for the future
925 \layout Standard
926
927 There are (and always will be) some things that could be done.
928  Here are some I can think of:
929 \newline 
930
931 \layout Standard
932
933
934 \family typewriter 
935 char KernelFunction3(char p) at 0x340;
936 \newline 
937
938 \layout Standard
939
940
941 \family typewriter 
942 better code banking
943 \begin_inset LatexCommand \index{code banking (limited support)}
944
945 \end_inset 
946
947  support for mcs51
948 \newline 
949
950 \newline 
951
952 \family default 
953 If you can think of some more, please see the section 
954 \begin_inset LatexCommand \ref{sub:Requesting-Features}
955
956 \end_inset 
957
958  about filing feature requests
959 \begin_inset LatexCommand \index{Requesting features}
960
961 \end_inset 
962
963
964 \begin_inset LatexCommand \index{Feature request}
965
966 \end_inset 
967
968 .
969 \newline 
970
971 \layout Chapter
972
973 Installing SDCC
974 \begin_inset LatexCommand \index{Installation}
975
976 \end_inset 
977
978
979 \layout Standard
980
981 For most users it is sufficient to skip to either section 
982 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
983
984 \end_inset 
985
986  (Unix) or section 
987 \begin_inset LatexCommand \ref{sub:Windows-Install}
988
989 \end_inset 
990
991  (Windows).
992  More detailed instructions follow below.
993 \layout Section
994
995 Configure Options
996 \begin_inset LatexCommand \index{Options SDCC configuration}
997
998 \end_inset 
999
1000
1001 \layout Standard
1002
1003 The install paths, search paths and other options are defined when running
1004  'configure'.
1005  The defaults can be overridden by:
1006 \layout List
1007 \labelwidthstring 00.00.0000
1008
1009 -
1010 \begin_inset ERT
1011 status Collapsed
1012
1013 \layout Standard
1014
1015 \backslash 
1016 /
1017 \end_inset 
1018
1019 -prefix see table below
1020 \layout List
1021 \labelwidthstring 00.00.0000
1022
1023 -
1024 \begin_inset ERT
1025 status Collapsed
1026
1027 \layout Standard
1028
1029 \backslash 
1030 /
1031 \end_inset 
1032
1033 -exec_prefix see table below
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036
1037 -
1038 \begin_inset ERT
1039 status Collapsed
1040
1041 \layout Standard
1042
1043 \backslash 
1044 /
1045 \end_inset 
1046
1047 -bindir see table below
1048 \layout List
1049 \labelwidthstring 00.00.0000
1050
1051 -
1052 \begin_inset ERT
1053 status Collapsed
1054
1055 \layout Standard
1056
1057 \backslash 
1058 /
1059 \end_inset 
1060
1061 -datadir see table below
1062 \newline 
1063
1064 \layout List
1065 \labelwidthstring 00.00.0000
1066
1067 \SpecialChar ~
1068 \SpecialChar ~
1069 docdir environment variable, see table below
1070 \layout List
1071 \labelwidthstring 00.00.0000
1072
1073 \SpecialChar ~
1074 \SpecialChar ~
1075 include_dir_suffix environment variable, see table below
1076 \layout List
1077 \labelwidthstring 00.00.0000
1078
1079 \SpecialChar ~
1080 \SpecialChar ~
1081 lib_dir_suffix environment variable, see table below
1082 \layout List
1083 \labelwidthstring 00.00.0000
1084
1085 \SpecialChar ~
1086 \SpecialChar ~
1087 sdccconf_h_dir_separator environment variable, either / or 
1088 \backslash 
1089
1090 \backslash 
1091  makes sense here.
1092  This character will only be used in sdccconf.h; don't forget it's a C-header,
1093  therefore a double-backslash is needed there.
1094 \newline 
1095
1096 \layout List
1097 \labelwidthstring 00.00.0000
1098
1099 -
1100 \begin_inset ERT
1101 status Collapsed
1102
1103 \layout Standard
1104
1105 \backslash 
1106 /
1107 \end_inset 
1108
1109 -disable-mcs51-port Excludes the Intel mcs51 port
1110 \layout List
1111 \labelwidthstring 00.00.0000
1112
1113 -
1114 \begin_inset ERT
1115 status Collapsed
1116
1117 \layout Standard
1118
1119 \backslash 
1120 /
1121 \end_inset 
1122
1123 -disable-gbz80-port Excludes the Gameboy gbz80 port
1124 \layout List
1125 \labelwidthstring 00.00.0000
1126
1127 -
1128 \begin_inset ERT
1129 status Collapsed
1130
1131 \layout Standard
1132
1133 \backslash 
1134 /
1135 \end_inset 
1136
1137 -disable-z80-port Excludes the z80 port
1138 \layout List
1139 \labelwidthstring 00.00.0000
1140
1141 -
1142 \begin_inset ERT
1143 status Collapsed
1144
1145 \layout Standard
1146
1147 \backslash 
1148 /
1149 \end_inset 
1150
1151 -disable-avr-port Excludes the AVR port
1152 \layout List
1153 \labelwidthstring 00.00.0000
1154
1155 -
1156 \begin_inset ERT
1157 status Collapsed
1158
1159 \layout Standard
1160
1161 \backslash 
1162 /
1163 \end_inset 
1164
1165 -disable-ds390-port Excludes the DS390 port
1166 \layout List
1167 \labelwidthstring 00.00.0000
1168
1169 -
1170 \begin_inset ERT
1171 status Collapsed
1172
1173 \layout Standard
1174
1175 \backslash 
1176 /
1177 \end_inset 
1178
1179 -disable-hc08-port Excludes the HC08 port
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182
1183 -
1184 \begin_inset ERT
1185 status Collapsed
1186
1187 \layout Standard
1188
1189 \backslash 
1190 /
1191 \end_inset 
1192
1193 -disable-pic-port Excludes the PIC port
1194 \layout List
1195 \labelwidthstring 00.00.0000
1196
1197 -
1198 \begin_inset ERT
1199 status Collapsed
1200
1201 \layout Standard
1202
1203 \backslash 
1204 /
1205 \end_inset 
1206
1207 -disable-xa51-port Excludes the XA51 port
1208 \layout List
1209 \labelwidthstring 00.00.0000
1210
1211 -
1212 \begin_inset ERT
1213 status Collapsed
1214
1215 \layout Standard
1216
1217 \backslash 
1218 /
1219 \end_inset 
1220
1221 -disable-ucsim Disables configuring and building of ucsim
1222 \layout List
1223 \labelwidthstring 00.00.0000
1224
1225 -
1226 \begin_inset ERT
1227 status Collapsed
1228
1229 \layout Standard
1230
1231 \backslash 
1232 /
1233 \end_inset 
1234
1235 -disable-device-lib Disables automatically building device libraries
1236 \layout List
1237 \labelwidthstring 00.00.0000
1238
1239 -
1240 \begin_inset ERT
1241 status Collapsed
1242
1243 \layout Standard
1244
1245 \backslash 
1246 /
1247 \end_inset 
1248
1249 -disable-packihx Disables building packihx
1250 \newline 
1251
1252 \layout List
1253 \labelwidthstring 00.00.0000
1254
1255 -
1256 \begin_inset ERT
1257 status Collapsed
1258
1259 \layout Standard
1260
1261 \backslash 
1262 /
1263 \end_inset 
1264
1265 -enable-doc Build pdf, html and txt files from the lyx sources
1266 \layout List
1267 \labelwidthstring 00.00.0000
1268
1269 -
1270 \begin_inset ERT
1271 status Collapsed
1272
1273 \layout Standard
1274
1275 \backslash 
1276 /
1277 \end_inset 
1278
1279 -enable-libgc Use the Bohem memory allocator.
1280  Lower runtime footprint.
1281 \layout Standard
1282
1283 Furthermore the environment variables CC, CFLAGS, ...
1284  the tools and their arguments can be influenced.
1285  Please see `configure -
1286 \begin_inset ERT
1287 status Collapsed
1288
1289 \layout Standard
1290
1291 \backslash 
1292 /
1293 \end_inset 
1294
1295 -help` and the man/info pages of `configure` for details.
1296 \newline 
1297
1298 \newline 
1299 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1300  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1301 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1302  At the moment it's not possible to change the default settings (it was
1303  simply never required).
1304 \newline 
1305
1306 \newline 
1307 These configure options are compiled into the binaries, and can only be
1308  changed by rerunning 'configure' and recompiling SDCC.
1309  The configure options are written in 
1310 \emph on 
1311 italics
1312 \emph default 
1313  to distinguish them from run time environment variables (see section search
1314  paths).
1315 \newline 
1316
1317 \newline 
1318 The settings for 
1319 \begin_inset Quotes sld
1320 \end_inset 
1321
1322 Win32 builds
1323 \begin_inset Quotes srd
1324 \end_inset 
1325
1326  are used by the SDCC team to build the official Win32 binaries.
1327  The SDCC team uses Mingw32 to build the official Windows binaries, because
1328  it's
1329 \layout Enumerate
1330
1331 open source, 
1332 \layout Enumerate
1333
1334 a gcc compiler and last but not least
1335 \layout Enumerate
1336
1337 the binaries can be built by cross compiling on Sourceforge's compile farm.
1338 \layout Standard
1339
1340 See the examples, how to pass the Win32 settings to 'configure'.
1341  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1342  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1343  for Win32.
1344 \newline 
1345
1346 \newline 
1347 These defaults are:
1348 \newline 
1349
1350 \layout Standard
1351 \align center 
1352
1353 \begin_inset  Tabular
1354 <lyxtabular version="3" rows="8" columns="3">
1355 <features>
1356 <column alignment="block" valignment="top" leftline="true" width="0in">
1357 <column alignment="block" valignment="top" leftline="true" width="0in">
1358 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1359 <row topline="true" bottomline="true">
1360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1361 \begin_inset Text
1362
1363 \layout Standard
1364
1365 Variable
1366 \end_inset 
1367 </cell>
1368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1369 \begin_inset Text
1370
1371 \layout Standard
1372
1373 default
1374 \end_inset 
1375 </cell>
1376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1377 \begin_inset Text
1378
1379 \layout Standard
1380
1381 Win32 builds
1382 \end_inset 
1383 </cell>
1384 </row>
1385 <row topline="true">
1386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1387 \begin_inset Text
1388
1389 \layout Standard
1390
1391
1392 \emph on 
1393 PREFIX
1394 \end_inset 
1395 </cell>
1396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1397 \begin_inset Text
1398
1399 \layout Standard
1400
1401 /usr/local
1402 \end_inset 
1403 </cell>
1404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1405 \begin_inset Text
1406
1407 \layout Standard
1408
1409
1410 \backslash 
1411 sdcc
1412 \end_inset 
1413 </cell>
1414 </row>
1415 <row topline="true">
1416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1417 \begin_inset Text
1418
1419 \layout Standard
1420
1421
1422 \emph on 
1423 EXEC_PREFIX
1424 \end_inset 
1425 </cell>
1426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1427 \begin_inset Text
1428
1429 \layout Standard
1430
1431
1432 \emph on 
1433 $PREFIX
1434 \end_inset 
1435 </cell>
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1437 \begin_inset Text
1438
1439 \layout Standard
1440
1441
1442 \emph on 
1443 $PREFIX
1444 \end_inset 
1445 </cell>
1446 </row>
1447 <row topline="true">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452
1453
1454 \emph on 
1455 BINDIR
1456 \end_inset 
1457 </cell>
1458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1459 \begin_inset Text
1460
1461 \layout Standard
1462
1463
1464 \emph on 
1465 $EXECPREFIX
1466 \emph default 
1467 /bin
1468 \end_inset 
1469 </cell>
1470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1471 \begin_inset Text
1472
1473 \layout Standard
1474
1475
1476 \emph on 
1477 $EXECPREFIX
1478 \emph default 
1479
1480 \backslash 
1481 bin
1482 \end_inset 
1483 </cell>
1484 </row>
1485 <row topline="true">
1486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1487 \begin_inset Text
1488
1489 \layout Standard
1490
1491
1492 \emph on 
1493 DATADIR
1494 \end_inset 
1495 </cell>
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501
1502 \emph on 
1503 $PREFIX
1504 \emph default 
1505 /share
1506 \end_inset 
1507 </cell>
1508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1509 \begin_inset Text
1510
1511 \layout Standard
1512
1513
1514 \emph on 
1515 $PREFIX
1516 \end_inset 
1517 </cell>
1518 </row>
1519 <row topline="true">
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1521 \begin_inset Text
1522
1523 \layout Standard
1524
1525
1526 \emph on 
1527 DOCDIR
1528 \end_inset 
1529 </cell>
1530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1531 \begin_inset Text
1532
1533 \layout Standard
1534
1535
1536 \emph on 
1537 $DATADIR
1538 \emph default 
1539 /sdcc/doc
1540 \end_inset 
1541 </cell>
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1543 \begin_inset Text
1544
1545 \layout Standard
1546
1547
1548 \emph on 
1549 $DATADIR
1550 \emph default 
1551
1552 \backslash 
1553 doc
1554 \end_inset 
1555 </cell>
1556 </row>
1557 <row topline="true">
1558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1559 \begin_inset Text
1560
1561 \layout Standard
1562
1563
1564 \emph on 
1565 INCLUDE_DIR_SUFFIX
1566 \end_inset 
1567 </cell>
1568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1569 \begin_inset Text
1570
1571 \layout Standard
1572
1573 sdcc/include
1574 \end_inset 
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581 include
1582 \end_inset 
1583 </cell>
1584 </row>
1585 <row topline="true" bottomline="true">
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1587 \begin_inset Text
1588
1589 \layout Standard
1590
1591
1592 \emph on 
1593 LIB_DIR_SUFFIX
1594 \end_inset 
1595 </cell>
1596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1597 \begin_inset Text
1598
1599 \layout Standard
1600
1601 sdcc/lib
1602 \end_inset 
1603 </cell>
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1605 \begin_inset Text
1606
1607 \layout Standard
1608
1609 lib
1610 \end_inset 
1611 </cell>
1612 </row>
1613 </lyxtabular>
1614
1615 \end_inset 
1616
1617
1618 \newline 
1619
1620 \layout Standard
1621 \noindent 
1622 'configure' also computes relative paths.
1623  This is needed for full relocatability of a binary package and to complete
1624  search paths (see section search paths below):
1625 \newline 
1626  
1627 \layout Standard
1628 \align center 
1629
1630 \begin_inset  Tabular
1631 <lyxtabular version="3" rows="4" columns="3">
1632 <features>
1633 <column alignment="block" valignment="top" leftline="true" width="0in">
1634 <column alignment="block" valignment="top" leftline="true" width="0in">
1635 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1636 <row topline="true" bottomline="true">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1638 \begin_inset Text
1639
1640 \layout Standard
1641
1642 Variable (computed)
1643 \end_inset 
1644 </cell>
1645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1646 \begin_inset Text
1647
1648 \layout Standard
1649
1650 default
1651 \end_inset 
1652 </cell>
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1654 \begin_inset Text
1655
1656 \layout Standard
1657
1658 Win32 builds
1659 \end_inset 
1660 </cell>
1661 </row>
1662 <row topline="true" bottomline="true">
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1664 \begin_inset Text
1665
1666 \layout Standard
1667
1668
1669 \emph on 
1670 BIN2DATA_DIR
1671 \end_inset 
1672 </cell>
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1674 \begin_inset Text
1675
1676 \layout Standard
1677
1678 ../share
1679 \end_inset 
1680 </cell>
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1682 \begin_inset Text
1683
1684 \layout Standard
1685
1686 ..
1687 \end_inset 
1688 </cell>
1689 </row>
1690 <row bottomline="true">
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 \begin_inset Text
1693
1694 \layout Standard
1695
1696
1697 \emph on 
1698 PREFIX2BIN_DIR
1699 \end_inset 
1700 </cell>
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \layout Standard
1705
1706 bin
1707 \end_inset 
1708 </cell>
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713
1714 bin
1715 \end_inset 
1716 </cell>
1717 </row>
1718 <row bottomline="true">
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_inset Text
1721
1722 \layout Standard
1723
1724
1725 \emph on 
1726 PREFIX2DATA_DIR
1727 \end_inset 
1728 </cell>
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1730 \begin_inset Text
1731
1732 \layout Standard
1733
1734 share/sdcc
1735 \end_inset 
1736 </cell>
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1738 \begin_inset Text
1739
1740 \layout Standard
1741
1742 \end_inset 
1743 </cell>
1744 </row>
1745 </lyxtabular>
1746
1747 \end_inset 
1748
1749
1750 \newline 
1751
1752 \layout Standard
1753 \noindent 
1754 Examples:
1755 \layout LyX-Code
1756
1757 ./configure
1758 \newline 
1759 ./configure -
1760 \begin_inset ERT
1761 status Collapsed
1762
1763 \layout Standard
1764
1765 \backslash 
1766 /
1767 \end_inset 
1768
1769 -prefix=
1770 \begin_inset Quotes srd
1771 \end_inset 
1772
1773 /usr/bin
1774 \begin_inset Quotes srd
1775 \end_inset 
1776
1777  -
1778 \begin_inset ERT
1779 status Collapsed
1780
1781 \layout Standard
1782
1783 \backslash 
1784 /
1785 \end_inset 
1786
1787 -datadir=
1788 \begin_inset Quotes srd
1789 \end_inset 
1790
1791 /usr/share
1792 \begin_inset Quotes srd
1793 \end_inset 
1794
1795
1796 \newline 
1797 ./configure -
1798 \begin_inset ERT
1799 status Collapsed
1800
1801 \layout Standard
1802
1803 \backslash 
1804 /
1805 \end_inset 
1806
1807 -disable-avr-port -
1808 \begin_inset ERT
1809 status Collapsed
1810
1811 \layout Standard
1812
1813 \backslash 
1814 /
1815 \end_inset 
1816
1817 -disable-xa51-port
1818 \layout Standard
1819
1820 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1821 32'):
1822 \layout LyX-Code
1823
1824 ./configure 
1825 \backslash 
1826
1827 \newline 
1828 CC=
1829 \begin_inset Quotes srd
1830 \end_inset 
1831
1832 i586-mingw32msvc-gcc
1833 \begin_inset Quotes srd
1834 \end_inset 
1835
1836  CXX=
1837 \begin_inset Quotes srd
1838 \end_inset 
1839
1840 i586-mingw32msvc-g++
1841 \begin_inset Quotes srd
1842 \end_inset 
1843
1844  
1845 \backslash 
1846  
1847 \newline 
1848 RANLIB=
1849 \begin_inset Quotes srd
1850 \end_inset 
1851
1852 i586-mingw32msvc-ranlib
1853 \begin_inset Quotes srd
1854 \end_inset 
1855
1856  
1857 \backslash 
1858
1859 \newline 
1860 STRIP=
1861 \begin_inset Quotes srd
1862 \end_inset 
1863
1864 i586-mingw32msvc-strip
1865 \begin_inset Quotes srd
1866 \end_inset 
1867
1868  
1869 \backslash 
1870
1871 \newline 
1872 -
1873 \begin_inset ERT
1874 status Collapsed
1875
1876 \layout Standard
1877
1878 \backslash 
1879 /
1880 \end_inset 
1881
1882 -prefix=
1883 \begin_inset Quotes srd
1884 \end_inset 
1885
1886 /sdcc
1887 \begin_inset Quotes srd
1888 \end_inset 
1889
1890  
1891 \backslash 
1892
1893 \newline 
1894 -
1895 \begin_inset ERT
1896 status Collapsed
1897
1898 \layout Standard
1899
1900 \backslash 
1901 /
1902 \end_inset 
1903
1904 -datadir=
1905 \begin_inset Quotes srd
1906 \end_inset 
1907
1908 /sdcc
1909 \begin_inset Quotes srd
1910 \end_inset 
1911
1912  
1913 \backslash 
1914
1915 \newline 
1916 docdir=
1917 \begin_inset Quotes srd
1918 \end_inset 
1919
1920 /sdcc/doc
1921 \begin_inset Quotes srd
1922 \end_inset 
1923
1924  
1925 \backslash 
1926
1927 \newline 
1928 include_dir_suffix=
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932 include
1933 \begin_inset Quotes srd
1934 \end_inset 
1935
1936  
1937 \backslash 
1938
1939 \newline 
1940 lib_dir_suffix=
1941 \begin_inset Quotes srd
1942 \end_inset 
1943
1944 lib
1945 \begin_inset Quotes srd
1946 \end_inset 
1947
1948  
1949 \backslash 
1950
1951 \newline 
1952 sdccconf_h_dir_separator=
1953 \begin_inset Quotes srd
1954 \end_inset 
1955
1956
1957 \backslash 
1958
1959 \backslash 
1960
1961 \backslash 
1962
1963 \backslash 
1964
1965 \begin_inset Quotes srd
1966 \end_inset 
1967
1968  
1969 \backslash 
1970
1971 \newline 
1972 -
1973 \begin_inset ERT
1974 status Collapsed
1975
1976 \layout Standard
1977
1978 \backslash 
1979 /
1980 \end_inset 
1981
1982 -disable-device-lib
1983 \backslash 
1984
1985 \newline 
1986 -
1987 \begin_inset ERT
1988 status Collapsed
1989
1990 \layout Standard
1991
1992 \backslash 
1993 /
1994 \end_inset 
1995
1996 -host=i586-mingw32msvc
1997 \backslash 
1998
1999 \newline 
2000 -
2001 \begin_inset ERT
2002 status Collapsed
2003
2004 \layout Standard
2005
2006 \backslash 
2007 /
2008 \end_inset 
2009
2010 -build=unknown-unknown-linux-gnu
2011 \layout Standard
2012
2013 To 
2014 \begin_inset Quotes sld
2015 \end_inset 
2016
2017 cross
2018 \begin_inset Quotes srd
2019 \end_inset 
2020
2021 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2022 ):
2023 \layout LyX-Code
2024
2025 ./configure -C 
2026 \backslash 
2027
2028 \newline 
2029 -
2030 \begin_inset ERT
2031 status Collapsed
2032
2033 \layout Standard
2034
2035 \backslash 
2036 /
2037 \end_inset 
2038
2039 -prefix=
2040 \begin_inset Quotes srd
2041 \end_inset 
2042
2043 /sdcc
2044 \begin_inset Quotes srd
2045 \end_inset 
2046
2047  
2048 \backslash 
2049
2050 \newline 
2051 -
2052 \begin_inset ERT
2053 status Collapsed
2054
2055 \layout Standard
2056
2057 \backslash 
2058 /
2059 \end_inset 
2060
2061 -datadir=
2062 \begin_inset Quotes srd
2063 \end_inset 
2064
2065 /sdcc
2066 \begin_inset Quotes srd
2067 \end_inset 
2068
2069  
2070 \backslash 
2071
2072 \newline 
2073 docdir=
2074 \begin_inset Quotes srd
2075 \end_inset 
2076
2077 /sdcc/doc
2078 \begin_inset Quotes srd
2079 \end_inset 
2080
2081  
2082 \backslash 
2083  
2084 \newline 
2085 include_dir_suffix=
2086 \begin_inset Quotes srd
2087 \end_inset 
2088
2089 include
2090 \begin_inset Quotes srd
2091 \end_inset 
2092
2093  
2094 \backslash 
2095
2096 \newline 
2097 lib_dir_suffix=
2098 \begin_inset Quotes srd
2099 \end_inset 
2100
2101 lib
2102 \begin_inset Quotes srd
2103 \end_inset 
2104
2105  
2106 \backslash 
2107
2108 \newline 
2109 sdccconf_h_dir_separator=
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113
2114 \backslash 
2115
2116 \backslash 
2117
2118 \backslash 
2119
2120 \backslash 
2121
2122 \begin_inset Quotes srd
2123 \end_inset 
2124
2125  
2126 \backslash 
2127
2128 \newline 
2129 CC=
2130 \begin_inset Quotes srd
2131 \end_inset 
2132
2133 gcc -mno-cygwin
2134 \begin_inset Quotes srd
2135 \end_inset 
2136
2137  
2138 \backslash 
2139
2140 \newline 
2141 CXX=
2142 \begin_inset Quotes srd
2143 \end_inset 
2144
2145 g++ -mno-cygwin
2146 \begin_inset Quotes srd
2147 \end_inset 
2148
2149  
2150 \layout Standard
2151
2152 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2153  The option '-
2154 \begin_inset ERT
2155 status Collapsed
2156
2157 \layout Standard
2158
2159 \backslash 
2160 /
2161 \end_inset 
2162
2163 -C' turns on caching, which gives a little bit extra speed.
2164  However if options are changed, it can be necessary to delete the config.cache
2165  file.
2166 \layout Section
2167
2168 Install paths
2169 \begin_inset LatexCommand \label{sub:Install-paths}
2170
2171 \end_inset 
2172
2173
2174 \begin_inset LatexCommand \index{Install paths}
2175
2176 \end_inset 
2177
2178
2179 \layout Standard
2180 \added_space_top medskip \align center 
2181
2182 \begin_inset  Tabular
2183 <lyxtabular version="3" rows="5" columns="4">
2184 <features>
2185 <column alignment="left" valignment="top" leftline="true" width="0">
2186 <column alignment="left" valignment="top" leftline="true" width="0">
2187 <column alignment="left" valignment="top" leftline="true" width="0">
2188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2189 <row topline="true" bottomline="true">
2190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2191 \begin_inset Text
2192
2193 \layout Standard
2194
2195
2196 \series bold 
2197 Description
2198 \end_inset 
2199 </cell>
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2201 \begin_inset Text
2202
2203 \layout Standard
2204
2205
2206 \series bold 
2207 Path
2208 \end_inset 
2209 </cell>
2210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2211 \begin_inset Text
2212
2213 \layout Standard
2214
2215
2216 \series bold 
2217 Default
2218 \end_inset 
2219 </cell>
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2221 \begin_inset Text
2222
2223 \layout Standard
2224
2225
2226 \series bold 
2227 Win32 builds
2228 \end_inset 
2229 </cell>
2230 </row>
2231 <row topline="true">
2232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2233 \begin_inset Text
2234
2235 \layout Standard
2236
2237 Binary files*
2238 \end_inset 
2239 </cell>
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2241 \begin_inset Text
2242
2243 \layout Standard
2244
2245
2246 \emph on 
2247 $EXEC_PREFIX
2248 \end_inset 
2249 </cell>
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2251 \begin_inset Text
2252
2253 \layout Standard
2254
2255 /usr/local/bin
2256 \end_inset 
2257 </cell>
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2259 \begin_inset Text
2260
2261 \layout Standard
2262
2263
2264 \backslash 
2265 sdcc
2266 \backslash 
2267 bin
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 Include files
2278 \end_inset 
2279 </cell>
2280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2281 \begin_inset Text
2282
2283 \layout Standard
2284
2285
2286 \emph on 
2287 $DATADIR/ $INCLUDE_DIR_SUFFIX
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295 /usr/local/share/sdcc/include
2296 \end_inset 
2297 </cell>
2298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2299 \begin_inset Text
2300
2301 \layout Standard
2302
2303
2304 \backslash 
2305 sdcc
2306 \backslash 
2307 include
2308 \end_inset 
2309 </cell>
2310 </row>
2311 <row topline="true">
2312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2313 \begin_inset Text
2314
2315 \layout Standard
2316
2317 Library file**
2318 \end_inset 
2319 </cell>
2320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2321 \begin_inset Text
2322
2323 \layout Standard
2324
2325
2326 \emph on 
2327 $DATADIR/$LIB_DIR_SUFFIX
2328 \end_inset 
2329 </cell>
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2331 \begin_inset Text
2332
2333 \layout Standard
2334
2335 /usr/local/share/sdcc/lib
2336 \end_inset 
2337 </cell>
2338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2339 \begin_inset Text
2340
2341 \layout Standard
2342
2343
2344 \backslash 
2345 sdcc
2346 \backslash 
2347 lib
2348 \end_inset 
2349 </cell>
2350 </row>
2351 <row topline="true" bottomline="true">
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2353 \begin_inset Text
2354
2355 \layout Standard
2356
2357 Documentation
2358 \end_inset 
2359 </cell>
2360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2361 \begin_inset Text
2362
2363 \layout Standard
2364
2365
2366 \emph on 
2367 $DOCDIR
2368 \end_inset 
2369 </cell>
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375 /usr/local/share/sdcc/doc
2376 \end_inset 
2377 </cell>
2378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2379 \begin_inset Text
2380
2381 \layout Standard
2382
2383
2384 \backslash 
2385 sdcc
2386 \backslash 
2387 doc
2388 \end_inset 
2389 </cell>
2390 </row>
2391 </lyxtabular>
2392
2393 \end_inset 
2394
2395
2396 \layout Verse
2397
2398
2399 \size footnotesize 
2400 *compiler, preprocessor, assembler, and linker
2401 \newline 
2402 **the 
2403 \shape italic 
2404 model
2405 \shape default 
2406  is auto-appended by the compiler, e.g.
2407  small, large, z80, ds390 etc
2408 \layout Standard
2409 \noindent 
2410 The install paths can still be changed during `make install` with e.g.:
2411 \layout LyX-Code
2412
2413 make install prefix=$(HOME)/local/sdcc
2414 \layout Standard
2415
2416 Of course this doesn't change the search paths compiled into the binaries.
2417 \newline 
2418
2419 \newline 
2420 Moreover the install path can be changed by defining DESTDIR
2421 \begin_inset LatexCommand \index{DESTDIR}
2422
2423 \end_inset 
2424
2425 :
2426 \layout LyX-Code
2427
2428 make install DESTDIR=$(HOME)/sdcc.rpm/
2429 \layout Standard
2430
2431 Please note that DESTDIR must have a trailing slash!
2432 \layout Section
2433
2434 Search Paths
2435 \begin_inset LatexCommand \label{sub:Search-Paths}
2436
2437 \end_inset 
2438
2439
2440 \begin_inset LatexCommand \index{Search path}
2441
2442 \end_inset 
2443
2444
2445 \layout Standard
2446
2447 Some search paths or parts of them are determined by configure variables
2448  (in 
2449 \emph on 
2450 italics
2451 \emph default 
2452 , see section above).
2453  Further search paths are determined by environment variables during runtime.
2454  
2455 \newline 
2456 The paths searched when running the compiler are as follows (the first catch
2457  wins):
2458 \newline 
2459
2460 \newline 
2461 1.
2462  Binary files (preprocessor, assembler and linker)
2463 \newline 
2464
2465 \layout Standard
2466 \align center 
2467
2468 \begin_inset  Tabular
2469 <lyxtabular version="3" rows="4" columns="3">
2470 <features>
2471 <column alignment="block" valignment="top" leftline="true" width="0in">
2472 <column alignment="block" valignment="top" leftline="true" width="0in">
2473 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2474 <row topline="true" bottomline="true">
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479
2480 Search path
2481 \end_inset 
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 default
2489 \end_inset 
2490 </cell>
2491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2492 \begin_inset Text
2493
2494 \layout Standard
2495
2496 Win32 builds
2497 \end_inset 
2498 </cell>
2499 </row>
2500 <row topline="true">
2501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2502 \begin_inset Text
2503
2504 \layout Standard
2505
2506 $SDCC_HOME/
2507 \emph on 
2508 $PPREFIX2BIN_DIR
2509 \end_inset 
2510 </cell>
2511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2512 \begin_inset Text
2513
2514 \layout Standard
2515
2516 $SDCC_HOME/bin
2517 \end_inset 
2518 </cell>
2519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2520 \begin_inset Text
2521
2522 \layout Standard
2523
2524 $SDCC_HOME
2525 \backslash 
2526 bin
2527 \end_inset 
2528 </cell>
2529 </row>
2530 <row topline="true">
2531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2532 \begin_inset Text
2533
2534 \layout Standard
2535
2536 Path of argv[0] (if available)
2537 \end_inset 
2538 </cell>
2539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2540 \begin_inset Text
2541
2542 \layout Standard
2543
2544 Path of argv[0]
2545 \end_inset 
2546 </cell>
2547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2548 \begin_inset Text
2549
2550 \layout Standard
2551
2552 Path of argv[0]
2553 \end_inset 
2554 </cell>
2555 </row>
2556 <row topline="true" bottomline="true">
2557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2558 \begin_inset Text
2559
2560 \layout Standard
2561
2562 $PATH
2563 \end_inset 
2564 </cell>
2565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2566 \begin_inset Text
2567
2568 \layout Standard
2569
2570 $PATH
2571 \end_inset 
2572 </cell>
2573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2574 \begin_inset Text
2575
2576 \layout Standard
2577
2578 $PATH
2579 \end_inset 
2580 </cell>
2581 </row>
2582 </lyxtabular>
2583
2584 \end_inset 
2585
2586  
2587 \newline 
2588
2589 \layout Standard
2590 \noindent 
2591 2.
2592  Include files
2593 \newline 
2594
2595 \layout Standard
2596 \align center 
2597
2598 \begin_inset  Tabular
2599 <lyxtabular version="3" rows="6" columns="3">
2600 <features>
2601 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2602 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2603 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2604 <row topline="true" bottomline="true">
2605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2606 \begin_inset Text
2607
2608 \layout Standard
2609
2610 Search path
2611 \end_inset 
2612 </cell>
2613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2614 \begin_inset Text
2615
2616 \layout Standard
2617
2618 default
2619 \end_inset 
2620 </cell>
2621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2622 \begin_inset Text
2623
2624 \layout Standard
2625
2626 Win32 builds
2627 \end_inset 
2628 </cell>
2629 </row>
2630 <row topline="true">
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2632 \begin_inset Text
2633
2634 \layout Standard
2635
2636 -
2637 \begin_inset ERT
2638 status Collapsed
2639
2640 \layout Standard
2641
2642 \backslash 
2643 /
2644 \end_inset 
2645
2646 -I dir
2647 \end_inset 
2648 </cell>
2649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_inset Text
2651
2652 \layout Standard
2653
2654 -
2655 \begin_inset ERT
2656 status Collapsed
2657
2658 \layout Standard
2659
2660 \backslash 
2661 /
2662 \end_inset 
2663
2664 -I dir
2665 \end_inset 
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \layout Standard
2671
2672 -
2673 \begin_inset ERT
2674 status Collapsed
2675
2676 \layout Standard
2677
2678 \backslash 
2679 /
2680 \end_inset 
2681
2682 -I dir
2683 \end_inset 
2684 </cell>
2685 </row>
2686 <row topline="true">
2687 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2688 \begin_inset Text
2689
2690 \layout Standard
2691
2692 $SDCC_INCLUDE
2693 \end_inset 
2694 </cell>
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2696 \begin_inset Text
2697
2698 \layout Standard
2699
2700 $SDCC_INCLUDE
2701 \end_inset 
2702 </cell>
2703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2704 \begin_inset Text
2705
2706 \layout Standard
2707
2708 $SDCC_INCLUDE
2709 \end_inset 
2710 </cell>
2711 </row>
2712 <row topline="true">
2713 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_inset Text
2715
2716 \layout Standard
2717
2718 $SDCC_HOME/
2719 \newline 
2720
2721 \emph on 
2722 $PREFIX2DATA_DIR/
2723 \newline 
2724 $INCLUDE_DIR_SUFFIX
2725 \end_inset 
2726 </cell>
2727 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2728 \begin_inset Text
2729
2730 \layout Standard
2731
2732 $SDCC_ HOME/
2733 \newline 
2734 share/sdcc/
2735 \newline 
2736 include
2737 \end_inset 
2738 </cell>
2739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2740 \begin_inset Text
2741
2742 \layout Standard
2743
2744 $SDCC_HOME
2745 \backslash 
2746 include
2747 \end_inset 
2748 </cell>
2749 </row>
2750 <row topline="true">
2751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_inset Text
2753
2754 \layout Standard
2755
2756 path(argv[0])/
2757 \newline 
2758
2759 \emph on 
2760 $BIN2DATADIR/
2761 \emph default 
2762
2763 \newline 
2764
2765 \emph on 
2766 $INCLUDE_DIR_SUFFIX
2767 \end_inset 
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \layout Standard
2773
2774 path(argv[0])/
2775 \newline 
2776 ../sdcc/include
2777 \newline 
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783 \SpecialChar ~
2784 \SpecialChar ~
2785 \SpecialChar ~
2786 \SpecialChar ~
2787 \SpecialChar ~
2788 \SpecialChar ~
2789 \SpecialChar ~
2790 \SpecialChar ~
2791 \SpecialChar ~
2792 \SpecialChar ~
2793 \SpecialChar ~
2794 \SpecialChar ~
2795 \SpecialChar ~
2796 \SpecialChar ~
2797 \SpecialChar ~
2798 \SpecialChar ~
2799 \SpecialChar ~
2800 \SpecialChar ~
2801 \SpecialChar ~
2802 \SpecialChar ~
2803 \SpecialChar ~
2804 \SpecialChar ~
2805 \SpecialChar ~
2806 \SpecialChar ~
2807 \SpecialChar ~
2808 \SpecialChar ~
2809 \SpecialChar ~
2810 \SpecialChar ~
2811 \SpecialChar ~
2812 \SpecialChar ~
2813 \SpecialChar ~
2814 \SpecialChar ~
2815 \SpecialChar ~
2816
2817 \end_inset 
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824 path(argv[0])
2825 \backslash 
2826 ..
2827 \backslash 
2828 include
2829 \end_inset 
2830 </cell>
2831 </row>
2832 <row topline="true" bottomline="true">
2833 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2834 \begin_inset Text
2835
2836 \layout Standard
2837
2838
2839 \emph on 
2840 $DATADIR/
2841 \emph default 
2842
2843 \newline 
2844
2845 \emph on 
2846 $INCLUDE_DIR_SUFFIX
2847 \end_inset 
2848 </cell>
2849 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2850 \begin_inset Text
2851
2852 \layout Standard
2853
2854 /usr/local/share/sdcc/
2855 \newline 
2856 include
2857 \end_inset 
2858 </cell>
2859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2860 \begin_inset Text
2861
2862 \layout Standard
2863
2864 (not on Win32)
2865 \end_inset 
2866 </cell>
2867 </row>
2868 </lyxtabular>
2869
2870 \end_inset 
2871
2872  
2873 \newline 
2874
2875 \layout Standard
2876 \noindent 
2877 The option -
2878 \begin_inset ERT
2879 status Collapsed
2880
2881 \layout Standard
2882
2883 \backslash 
2884 /
2885 \end_inset 
2886
2887 -nostdinc disables the last two search paths.
2888 \newline 
2889
2890 \newline 
2891 3.
2892  Library files 
2893 \newline 
2894
2895 \layout Standard
2896
2897 With the exception of 
2898 \begin_inset Quotes sld
2899 \end_inset 
2900
2901 -
2902 \begin_inset ERT
2903 status Collapsed
2904
2905 \layout Standard
2906
2907 \backslash 
2908 /
2909 \end_inset 
2910
2911 -L dir
2912 \begin_inset Quotes srd
2913 \end_inset 
2914
2915  the 
2916 \shape italic 
2917 model
2918 \shape default 
2919  is auto-appended by the compiler (e.g.
2920  small, large, z80, ds390 etc.).
2921  
2922 \newline 
2923
2924 \layout Standard
2925 \align center 
2926
2927 \begin_inset  Tabular
2928 <lyxtabular version="3" rows="6" columns="3">
2929 <features>
2930 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2931 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2932 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2933 <row topline="true" bottomline="true">
2934 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2935 \begin_inset Text
2936
2937 \layout Standard
2938
2939 Search path
2940 \end_inset 
2941 </cell>
2942 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \layout Standard
2946
2947 default
2948 \end_inset 
2949 </cell>
2950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2951 \begin_inset Text
2952
2953 \layout Standard
2954
2955 Win32 builds
2956 \end_inset 
2957 </cell>
2958 </row>
2959 <row topline="true">
2960 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_inset Text
2962
2963 \layout Standard
2964
2965 -
2966 \begin_inset ERT
2967 status Collapsed
2968
2969 \layout Standard
2970
2971 \backslash 
2972 /
2973 \end_inset 
2974
2975 -L dir
2976 \end_inset 
2977 </cell>
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2979 \begin_inset Text
2980
2981 \layout Standard
2982
2983 -
2984 \begin_inset ERT
2985 status Collapsed
2986
2987 \layout Standard
2988
2989 \backslash 
2990 /
2991 \end_inset 
2992
2993 -L dir
2994 \end_inset 
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \layout Standard
3000
3001 -
3002 \begin_inset ERT
3003 status Collapsed
3004
3005 \layout Standard
3006
3007 \backslash 
3008 /
3009 \end_inset 
3010
3011 -L dir
3012 \end_inset 
3013 </cell>
3014 </row>
3015 <row topline="true">
3016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_inset Text
3018
3019 \layout Standard
3020
3021 $SDCC_LIB/
3022 \newline 
3023
3024 \emph on 
3025 <model>
3026 \end_inset 
3027 </cell>
3028 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 $SDCC_LIB/
3034 \newline 
3035
3036 \emph on 
3037 <model>
3038 \end_inset 
3039 </cell>
3040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3041 \begin_inset Text
3042
3043 \layout Standard
3044
3045 $SDCC_LIB
3046 \backslash 
3047
3048 \newline 
3049
3050 \emph on 
3051 <model>
3052 \end_inset 
3053 </cell>
3054 </row>
3055 <row topline="true">
3056 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3057 \begin_inset Text
3058
3059 \layout Standard
3060
3061 $SDCC_HOME/
3062 \newline 
3063
3064 \emph on 
3065 $PREFIX2DATA_DIR/
3066 \newline 
3067 $LIB_DIR_SUFFIX/<model>
3068 \end_inset 
3069 </cell>
3070 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3071 \begin_inset Text
3072
3073 \layout Standard
3074
3075 $SDCC_HOME/
3076 \newline 
3077 share/sdcc/
3078 \newline 
3079 lib/
3080 \emph on 
3081 <model>
3082 \end_inset 
3083 </cell>
3084 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3085 \begin_inset Text
3086
3087 \layout Standard
3088
3089 $SDCC_HOME
3090 \backslash 
3091 lib
3092 \backslash 
3093
3094 \emph on 
3095
3096 \newline 
3097 <model>
3098 \end_inset 
3099 </cell>
3100 </row>
3101 <row topline="true">
3102 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_inset Text
3104
3105 \layout Standard
3106
3107 path(argv[0])/
3108 \newline 
3109
3110 \emph on 
3111 $BIN2DATADIR/
3112 \emph default 
3113
3114 \newline 
3115
3116 \emph on 
3117 $LIB_DIR_SUFFIX/<model>
3118 \end_inset 
3119 </cell>
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3121 \begin_inset Text
3122
3123 \layout Standard
3124
3125 path(argv[0])/
3126 \newline 
3127 ../sdcc/lib/
3128 \emph on 
3129 <model>
3130 \newline 
3131 \SpecialChar ~
3132 \SpecialChar ~
3133 \SpecialChar ~
3134 \SpecialChar ~
3135 \SpecialChar ~
3136 \SpecialChar ~
3137 \SpecialChar ~
3138 \SpecialChar ~
3139 \SpecialChar ~
3140 \SpecialChar ~
3141 \SpecialChar ~
3142 \SpecialChar ~
3143 \SpecialChar ~
3144 \SpecialChar ~
3145 \SpecialChar ~
3146 \SpecialChar ~
3147 \SpecialChar ~
3148 \SpecialChar ~
3149 \SpecialChar ~
3150 \SpecialChar ~
3151 \SpecialChar ~
3152 \SpecialChar ~
3153 \SpecialChar ~
3154 \SpecialChar ~
3155 \SpecialChar ~
3156 \SpecialChar ~
3157 \SpecialChar ~
3158 \SpecialChar ~
3159 \SpecialChar ~
3160 \SpecialChar ~
3161 \SpecialChar ~
3162 \SpecialChar ~
3163 \SpecialChar ~
3164 \SpecialChar ~
3165 \SpecialChar ~
3166 \SpecialChar ~
3167 \SpecialChar ~
3168 \SpecialChar ~
3169 \SpecialChar ~
3170
3171 \end_inset 
3172 </cell>
3173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3174 \begin_inset Text
3175
3176 \layout Standard
3177
3178 path(argv[0])
3179 \backslash 
3180
3181 \newline 
3182 ..
3183 \backslash 
3184 lib
3185 \backslash 
3186
3187 \emph on 
3188 <model>
3189 \newline 
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 \SpecialChar ~
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211 \SpecialChar ~
3212 \SpecialChar ~
3213 \SpecialChar ~
3214 \SpecialChar ~
3215 \SpecialChar ~
3216 \SpecialChar ~
3217 \SpecialChar ~
3218 \SpecialChar ~
3219 \SpecialChar ~
3220 \SpecialChar ~
3221 \SpecialChar ~
3222 \SpecialChar ~
3223 \SpecialChar ~
3224 \SpecialChar ~
3225
3226 \end_inset 
3227 </cell>
3228 </row>
3229 <row topline="true" bottomline="true">
3230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3231 \begin_inset Text
3232
3233 \layout Standard
3234
3235
3236 \emph on 
3237 $DATADIR/
3238 \newline 
3239 $LIB_DIR_SUFFIX/<model>
3240 \end_inset 
3241 </cell>
3242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3243 \begin_inset Text
3244
3245 \layout Standard
3246
3247 /usr/local/share/sdcc/
3248 \newline 
3249 lib/
3250 \emph on 
3251 <model>
3252 \end_inset 
3253 </cell>
3254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3255 \begin_inset Text
3256
3257 \layout Standard
3258
3259 (not on Win32)
3260 \end_inset 
3261 </cell>
3262 </row>
3263 </lyxtabular>
3264
3265 \end_inset 
3266
3267
3268 \newline 
3269
3270 \layout Comment
3271
3272 Don't delete any of the stray spaces in the table above without checking
3273  the HTML output (last line)!
3274 \layout Standard
3275
3276 \SpecialChar ~
3277
3278 \newline 
3279 The option -
3280 \begin_inset ERT
3281 status Collapsed
3282
3283 \layout Standard
3284
3285 \backslash 
3286 /
3287 \end_inset 
3288
3289 -nostdlib disables the last two search paths.
3290 \layout Section
3291
3292 Building SDCC
3293 \begin_inset LatexCommand \index{Building SDCC}
3294
3295 \end_inset 
3296
3297
3298 \layout Subsection
3299
3300 Building SDCC on Linux
3301 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3302
3303 \end_inset 
3304
3305
3306 \layout Enumerate
3307
3308
3309 \series medium 
3310 Download the source package
3311 \series default 
3312  either from the SDCC Subversion repository or from the nightly snapshots
3313 \series medium 
3314 , it will be named something like sdcc
3315 \series default 
3316 .src
3317 \series medium 
3318 .t
3319 \series default 
3320 ar.
3321 \series medium 
3322 gz
3323 \series default 
3324  
3325 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3326
3327 \end_inset 
3328
3329 .
3330 \layout Enumerate
3331
3332
3333 \series medium 
3334 Bring up a command line terminal, such as xterm.
3335 \layout Enumerate
3336
3337
3338 \series medium 
3339 Unpack the file using a command like: 
3340 \family sans 
3341 \series bold 
3342 "tar -xvzf sdcc.src.tar.gz
3343 \family default 
3344 \series default 
3345 "
3346 \series medium 
3347 , this will create a sub-directory called sdcc with all of the sources.
3348 \layout Enumerate
3349
3350 Change directory into the main SDCC directory, for example type: 
3351 \family sans 
3352 \series bold 
3353 "cd sdcc
3354 \series default 
3355 ".
3356 \layout Enumerate
3357
3358
3359 \series medium 
3360 Type 
3361 \family sans 
3362 \series bold 
3363 "./configure
3364 \family default 
3365 \series default 
3366 ".
3367  This configures the package for compilation on your system.
3368 \layout Enumerate
3369
3370
3371 \series medium 
3372 Type 
3373 \family sans 
3374 \series bold 
3375 "make
3376 \family default 
3377 \series default 
3378 "
3379 \series medium 
3380 .
3381
3382 \series default 
3383  All of the source packages will compile, this can take a while.
3384 \layout Enumerate
3385
3386
3387 \series medium 
3388 Type 
3389 \family sans 
3390 \series bold 
3391 "make install"
3392 \family default 
3393 \series default 
3394  as root
3395 \series medium 
3396 .
3397
3398 \series default 
3399  This copies the binary executables, the include files, the libraries and
3400  the documentation to the install directories.
3401  Proceed with section 
3402 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3403
3404 \end_inset 
3405
3406 .
3407 \layout Subsection
3408
3409 Building SDCC on OSX 2.x
3410 \layout Standard
3411
3412 Follow the instruction for Linux.
3413 \newline 
3414
3415 \newline 
3416 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3417 )) fails to compile SDCC.
3418  Fortunately there's also gcc 2.9.x installed, which works fine.
3419  This compiler can be selected by running 'configure' with:
3420 \layout LyX-Code
3421
3422 ./configure CC=gcc2 CXX=g++2
3423 \layout Subsection
3424
3425 Cross compiling SDCC on Linux for Windows
3426 \layout Standard
3427
3428 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3429  See section 'Configure Options'.
3430 \layout Subsection
3431
3432 Building SDCC using Cygwin and Mingw32
3433 \layout Standard
3434
3435 For building and installing a Cygwin executable follow the instructions
3436  for Linux.
3437 \newline 
3438
3439 \newline 
3440 On Cygwin a 
3441 \begin_inset Quotes sld
3442 \end_inset 
3443
3444 native
3445 \begin_inset Quotes srd
3446 \end_inset 
3447
3448  Win32-binary can be built, which will not need the Cygwin-DLL.
3449  For the necessary 'configure' options see section 'configure options' or
3450  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3451 \newline 
3452
3453 \newline 
3454 In order to install Cygwin on Windows download setup.exe from 
3455 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3456
3457 \end_inset 
3458
3459 .
3460  Run it, set the 
3461 \begin_inset Quotes sld
3462 \end_inset 
3463
3464 default text file type
3465 \begin_inset Quotes srd
3466 \end_inset 
3467
3468  to 
3469 \begin_inset Quotes sld
3470 \end_inset 
3471
3472 unix
3473 \begin_inset Quotes srd
3474 \end_inset 
3475
3476  and download/install at least the following packages.
3477  Some packages are selected by default, others will be automatically selected
3478  because of dependencies with the manually selected packages.
3479  Never deselect these packages!
3480 \layout Itemize
3481
3482 flex
3483 \layout Itemize
3484
3485 bison
3486 \layout Itemize
3487
3488 gcc ; version 3.x is fine, no need to use the old 2.9x
3489 \layout Itemize
3490
3491 binutils ; selected with gcc
3492 \layout Itemize
3493
3494 make
3495 \layout Itemize
3496
3497 rxvt ; a nice console, which makes life much easier under windoze (see below)
3498 \layout Itemize
3499
3500 man ; not really needed for building SDCC, but you'll miss it sooner or
3501  later
3502 \layout Itemize
3503
3504 less ; not really needed for building SDCC, but you'll miss it sooner or
3505  later
3506 \layout Itemize
3507
3508 svn ; only if you use Subversion access
3509 \layout Standard
3510
3511 If you want to develop something you'll need:
3512 \layout Itemize
3513
3514 python ; for the regression tests
3515 \layout Itemize
3516
3517 gdb ; the gnu debugger, together with the nice GUI 
3518 \begin_inset Quotes sld
3519 \end_inset 
3520
3521 insight
3522 \begin_inset Quotes srd
3523 \end_inset 
3524
3525
3526 \layout Itemize
3527
3528 openssh ; to access the CF or commit changes
3529 \layout Itemize
3530
3531 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3532  use autoconf-stable!
3533 \layout Standard
3534
3535 rxvt is a nice console with history.
3536  Replace in your cygwin.bat the line
3537 \layout LyX-Code
3538
3539 bash -
3540 \begin_inset ERT
3541 status Collapsed
3542
3543 \layout Standard
3544
3545 \backslash 
3546 /
3547 \end_inset 
3548
3549 -login -i 
3550 \layout Standard
3551
3552 with (one line):
3553 \layout LyX-Code
3554
3555 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3556 \layout LyX-Code
3557
3558      -bg black -fg white -geometry 100x65 -e bash -
3559 \begin_inset ERT
3560 status Collapsed
3561
3562 \layout Standard
3563
3564 \backslash 
3565 /
3566 \end_inset 
3567
3568 -login
3569 \layout Standard
3570
3571 Text selected with the mouse is automatically copied to the clipboard, pasting
3572  works with shift-insert.
3573 \newline 
3574
3575 \newline 
3576 The other good tip is to make sure you have no //c/-style paths anywhere,
3577  use /cygdrive/c/ instead.
3578  Using // invokes a network lookup which is very slow.
3579  If you think 
3580 \begin_inset Quotes sld
3581 \end_inset 
3582
3583 cygdrive
3584 \begin_inset Quotes srd
3585 \end_inset 
3586
3587  is too long, you can change it with e.g.
3588 \layout LyX-Code
3589
3590 mount -s -u -c /mnt
3591 \layout Standard
3592
3593 SDCC sources use the unix line ending LF.
3594  Life is much easier, if you store the source tree on a drive which is mounted
3595  in binary mode.
3596  And use an editor which can handle LF-only line endings.
3597  Make sure not to commit files with windows line endings.
3598  The tabulator spacing
3599 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3600
3601 \end_inset 
3602
3603  used in the project is 8.
3604  Although a tabulator spacing of 8 is a sensible choice for programmers
3605  (it's a power of 2 and allows to display 8/16 bit signed variables without
3606  loosing columns) the plan is to move towards using only spaces in the source.
3607 \layout Subsection
3608
3609 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3610 \layout Standard
3611
3612
3613 \series medium 
3614 Download the source package
3615 \series default 
3616  either from the SDCC Subversion repository or from the 
3617 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3618
3619 \end_inset 
3620
3621
3622 \series medium 
3623 , it will be named something like sdcc
3624 \series default 
3625 .src
3626 \series medium 
3627 .tgz.
3628
3629 \series default 
3630  SDCC is distributed with all the projects, workspaces, and files you need
3631  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3632  The workspace name is 'sdcc.dsw'.
3633  Please note that as it is now, all the executables are created in a folder
3634  called sdcc
3635 \backslash 
3636 bin_vc.
3637  Once built you need to copy the executables from sdcc
3638 \backslash 
3639 bin_vc to sdcc
3640 \backslash 
3641 bin before running SDCC.
3642  
3643 \newline 
3644
3645 \newline 
3646 WARNING: Visual studio is very picky with line terminations; it expects
3647  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3648  When using the Subversion repository it's easiest to configure the svn
3649  client to convert automatically for you.
3650  If however you are getting a message such as "This makefile was not generated
3651  by Developer Studio etc.
3652  etc.
3653 \begin_inset Quotes srd
3654 \end_inset 
3655
3656  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3657  need to convert the Unix style line endings to DOS style line endings.
3658  To do so you can use the 
3659 \begin_inset Quotes sld
3660 \end_inset 
3661
3662 unix2dos
3663 \begin_inset Quotes srd
3664 \end_inset 
3665
3666  utility freely available on the internet.
3667  Doug Hawkins reported in the sdcc-user list that this works:
3668 \newline 
3669
3670 \newline 
3671 C:
3672 \backslash 
3673 Programming
3674 \backslash 
3675 SDCC> unix2dos sdcc.dsw
3676 \newline 
3677 C:
3678 \backslash 
3679 Programming
3680 \backslash 
3681 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3682 \newline 
3683
3684 \newline 
3685 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3686  flex.exe, and gawk.exe.
3687  One good place to get them is 
3688 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3689
3690 \end_inset 
3691
3692
3693 \newline 
3694
3695 \newline 
3696 Download the file UnxUtils
3697 \begin_inset LatexCommand \index{UnxUtils}
3698
3699 \end_inset 
3700
3701 .zip.
3702  Now you have to install the utilities and setup MSVC so it can locate the
3703  required programs.
3704  Here there are two alternatives (choose one!):
3705 \layout Enumerate
3706
3707 The easy way:
3708 \newline 
3709
3710 \newline 
3711 a) Extract UnxUtils.zip to your C:
3712 \backslash 
3713  hard disk PRESERVING the original paths, otherwise bison won't work.
3714  (If you are using WinZip make certain that 'Use folder names' is selected)
3715 \newline 
3716
3717 \newline 
3718 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3719  in 'Show directories for:' select 'Executable files', and in the directories
3720  window add a new path: 'C:
3721 \backslash 
3722 user
3723 \backslash 
3724 local
3725 \backslash 
3726 wbin', click ok.
3727 \newline 
3728
3729 \newline 
3730 (As a side effect, you get a bunch of Unix utilities that could be useful,
3731  such as diff and patch.)
3732 \layout Enumerate
3733
3734 A more compact way:
3735 \newline 
3736
3737 \newline 
3738 This one avoids extracting a bunch of files you may not use, but requires
3739  some extra work:
3740 \newline 
3741
3742 \newline 
3743 a) Create a directory were to put the tools needed, or use a directory already
3744  present.
3745  Say for example 'C:
3746 \backslash 
3747 util'.
3748 \newline 
3749
3750 \newline 
3751 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3752  to such directory WITHOUT preserving the original paths.
3753  (If you are using WinZip make certain that 'Use folder names' is not selected)
3754 \newline 
3755
3756 \newline 
3757 c) Rename bison.exe to '_bison.exe'.
3758 \newline 
3759
3760 \newline 
3761 d) Create a batch file 'bison.bat' in 'C:
3762 \backslash 
3763 util
3764 \backslash 
3765 ' and add these lines: 
3766 \newline 
3767 \SpecialChar ~
3768 \SpecialChar ~
3769 set BISON_SIMPLE=C:
3770 \backslash 
3771 util
3772 \backslash 
3773 bison.simple 
3774 \newline 
3775 \SpecialChar ~
3776 \SpecialChar ~
3777 set BISON_HAIRY=C:
3778 \backslash 
3779 util
3780 \backslash 
3781 bison.hairy
3782 \newline 
3783 \SpecialChar ~
3784 \SpecialChar ~
3785 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3786 \newline 
3787
3788 \newline 
3789 Steps 'c' and 'd' are needed because bison requires by default that the
3790  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3791  '/usr/local/share/' I think.
3792  So it is necessary to tell bison where those files are located if they
3793  are not in such directory.
3794  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3795 \newline 
3796
3797 \newline 
3798 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3799  in 'Show directories for:' select 'Executable files', and in the directories
3800  window add a new path: 'c:
3801 \backslash 
3802 util', click ok.
3803  Note that you can use any other path instead of 'c:
3804 \backslash 
3805 util', even the path where the Visual C++ tools are, probably: 'C:
3806 \backslash 
3807 Program Files
3808 \backslash 
3809 Microsoft Visual Studio
3810 \backslash 
3811 Common
3812 \backslash 
3813 Tools'.
3814  So you don't have to execute step 'e' :)
3815 \layout Standard
3816
3817 That is it.
3818  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3819  the executables from sdcc
3820 \backslash 
3821 bin_vc to sdcc
3822 \backslash 
3823 bin, and you can compile using SDCC.
3824 \layout Subsection
3825
3826 Building SDCC Using Borland
3827 \layout Enumerate
3828
3829 From the sdcc directory, run the command "make -f Makefile.bcc".
3830  This should regenerate all the .exe files in the bin directory except for
3831  SDCDB and ucSim.
3832 \layout Enumerate
3833
3834 If you modify any source files and need to rebuild, be aware that the dependenci
3835 es may not be correctly calculated.
3836  The safest option is to delete all .obj files and run the build again.
3837  From a Cygwin BASH prompt, this can easily be done with the command (be
3838  sure you are in the sdcc directory):
3839 \newline 
3840
3841 \newline 
3842
3843 \family sans 
3844 \series bold 
3845 find .
3846  
3847 \backslash 
3848 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3849 \backslash 
3850 ) -print -exec rm {} 
3851 \backslash 
3852 ;
3853 \family default 
3854 \series default 
3855
3856 \newline 
3857
3858 \newline 
3859 or on Windows NT/2000/XP from the command prompt with the command:
3860 \newline 
3861
3862 \family sans 
3863 \series bold 
3864
3865 \newline 
3866 del /s *.obj *.lib *.rul
3867 \family default 
3868 \series default 
3869  from the sdcc directory.
3870 \layout Subsection
3871
3872 Windows Install Using a ZIP Package
3873 \layout Enumerate
3874
3875 Download the binary zip package from 
3876 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3877
3878 \end_inset 
3879
3880  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3881  This should unpack to a group of sub-directories.
3882  An example directory structure after unpacking the mingw32 package is:
3883  c:
3884 \backslash 
3885 sdcc
3886 \backslash 
3887 bin for the executables, c:
3888 \backslash 
3889 sdcc
3890 \backslash 
3891 include and c:
3892 \backslash 
3893 sdcc
3894 \backslash 
3895 lib for the include and libraries.
3896 \layout Enumerate
3897
3898 Adjust your environment variable PATH to include the location of the bin
3899  directory or start sdcc using the full path.
3900 \layout Subsection
3901
3902 Windows Install Using the Setup Program
3903 \begin_inset LatexCommand \label{sub:Windows-Install}
3904
3905 \end_inset 
3906
3907
3908 \layout Standard
3909
3910 Download the setup program 
3911 \emph on 
3912 sdcc-x.y.z-setup.exe
3913 \emph default 
3914  for an official release from 
3915 \newline 
3916
3917 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3918
3919 \end_inset 
3920
3921  or a setup program for one of the snapshots 
3922 \emph on 
3923 sdcc-yyyymmdd-xxxx-setup.exe
3924 \emph default 
3925  from 
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3927
3928 \end_inset 
3929
3930  and execute it.
3931  A windows typical installer will guide you through the installation process.
3932 \layout Subsection
3933
3934 VPATH
3935 \begin_inset LatexCommand \index{VPATH}
3936
3937 \end_inset 
3938
3939  feature
3940 \layout Standard
3941
3942 SDCC supports the VPATH feature provided by configure and make.
3943  It allows to separate the source and build trees.
3944  Here's an example:
3945 \layout Standard
3946
3947
3948 \family typewriter 
3949 cd ~\SpecialChar ~
3950 \SpecialChar ~
3951 \SpecialChar ~
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 \SpecialChar ~
3955 \SpecialChar ~
3956 \SpecialChar ~
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 \SpecialChar ~
3961 \SpecialChar ~
3962 \SpecialChar ~
3963 \SpecialChar ~
3964 \SpecialChar ~
3965 \SpecialChar ~
3966 \SpecialChar ~
3967 \SpecialChar ~
3968 \SpecialChar ~
3969 \SpecialChar ~
3970 # cd $HOME
3971 \layout Standard
3972
3973
3974 \family typewriter 
3975 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3976 # extract source to directory sdcc
3977 \layout Standard
3978
3979
3980 \family typewriter 
3981 mkdir sdcc.build\SpecialChar ~
3982 \SpecialChar ~
3983 \SpecialChar ~
3984 \SpecialChar ~
3985 \SpecialChar ~
3986 \SpecialChar ~
3987 \SpecialChar ~
3988 \SpecialChar ~
3989 \SpecialChar ~
3990 # put output in sdcc.build
3991 \layout Standard
3992
3993
3994 \family typewriter 
3995 cd sdcc.build
3996 \layout Standard
3997
3998
3999 \family typewriter 
4000 ../sdcc/configure\SpecialChar ~
4001 \SpecialChar ~
4002 \SpecialChar ~
4003 \SpecialChar ~
4004 \SpecialChar ~
4005 \SpecialChar ~
4006 \SpecialChar ~
4007 \SpecialChar ~
4008 # configure is doing all the magic!
4009 \layout Standard
4010
4011
4012 \family typewriter 
4013 make
4014 \layout Standard
4015 \noindent 
4016 That's it! 
4017 \series bold 
4018 configure
4019 \series default 
4020  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4021  It automagically computes the variables srcdir, top_srcdir and top_buildir
4022  for each directory.
4023  After running 
4024 \series bold 
4025 make
4026 \series default 
4027  the generated files will be in ~/sdcc.build, while the source files stay
4028  in ~/sdcc.
4029 \newline 
4030 This is not only usefull for building different binaries, e.g.
4031  when cross compiling.
4032  It also gives you a much better overview in the source tree when all the
4033  generated files are not scattered between the source files.
4034  And the best thing is: if you want to change a file you can leave the original
4035  file untouched in the source directory.
4036  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4037  Makefile.dep` and `make`.
4038  
4039 \series bold 
4040 make
4041 \series default 
4042  will do the rest for you!
4043 \layout Section
4044
4045 Building the Documentation
4046 \layout Standard
4047
4048 Add -
4049 \begin_inset ERT
4050 status Collapsed
4051
4052 \layout Standard
4053
4054 \backslash 
4055 /
4056 \end_inset 
4057
4058 -enable-doc to the configure arguments to build the documentation together
4059  with all the other stuff.
4060  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4061  dvips and makeindex) to get the job done.
4062  Another possibility is to change to the doc directory and to type 
4063 \family sans 
4064 \series bold 
4065
4066 \begin_inset Quotes srd
4067 \end_inset 
4068
4069 make
4070 \begin_inset Quotes srd
4071 \end_inset 
4072
4073
4074 \family default 
4075 \series default 
4076  there.
4077  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4078 x).
4079  Using LyX 
4080 \begin_inset LatexCommand \url{http://www.lyx.org}
4081
4082 \end_inset 
4083
4084  as editor is straightforward.
4085  Prebuilt documentation in html and pdf format is available from 
4086 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4087
4088 \end_inset 
4089
4090 .
4091 \layout Section
4092
4093 Reading the Documentation
4094 \begin_inset LatexCommand \index{Documentation}
4095
4096 \end_inset 
4097
4098
4099 \layout Standard
4100
4101 Currently reading the document in pdf format is recommended, as for unknown
4102  reason the hyperlinks are working there whereas in the html version they
4103  are not
4104 \begin_inset Foot
4105 collapsed false
4106
4107 \layout Standard
4108
4109 If you should know why please drop us a note
4110 \end_inset 
4111
4112 .
4113  
4114 \newline 
4115 You'll find the pdf version
4116 \begin_inset LatexCommand \index{PDF version of this document}
4117
4118 \end_inset 
4119
4120  at 
4121 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4122
4123 \end_inset 
4124
4125 .
4126  
4127 \newline 
4128 A html version
4129 \begin_inset LatexCommand \index{HTML version of this document}
4130
4131 \end_inset 
4132
4133  should be online at 
4134 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4135
4136 \end_inset 
4137
4138 .
4139 \newline 
4140 This documentation is in some aspects different from a commercial documentation:
4141  
4142 \layout Itemize
4143
4144 It tries to document SDCC for several processor architectures in one document
4145  (commercially these probably would be separate documents/products).
4146  This document
4147 \begin_inset LatexCommand \index{Status of documentation}
4148
4149 \end_inset 
4150
4151  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4152 on about f.e.
4153  Z80, PIC14, PIC16 and HC08.
4154 \layout Itemize
4155
4156 There are many references pointing away from this documentation.
4157  Don't let this distract you.
4158  If there f.e.
4159  was a reference like 
4160 \begin_inset LatexCommand \url{http://www.opencores.org}
4161
4162 \end_inset 
4163
4164  together with a statement 
4165 \begin_inset Quotes sld
4166 \end_inset 
4167
4168 some processors which are targetted by SDCC can be implemented in a 
4169 \emph on 
4170 f
4171 \emph default 
4172 ield 
4173 \emph on 
4174 p
4175 \emph default 
4176 rogrammable 
4177 \emph on 
4178 g
4179 \emph default 
4180 ate 
4181 \emph on 
4182 a
4183 \emph default 
4184 rray
4185 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4186
4187 \end_inset 
4188
4189
4190 \begin_inset Quotes srd
4191 \end_inset 
4192
4193  or 
4194 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4195
4196 \end_inset 
4197
4198
4199 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4200
4201 \end_inset 
4202
4203  
4204 \begin_inset Quotes sld
4205 \end_inset 
4206
4207 have you ever heard of an open source compiler that compiles a subset of
4208  C for an FPGA?
4209 \begin_inset Quotes srd
4210 \end_inset 
4211
4212  we expect you to have a quick look there and come back.
4213  If you read this you are on the right track.
4214 \layout Itemize
4215
4216 Some sections attribute more space to problems, restrictions and warnings
4217  than to the solution.
4218 \layout Itemize
4219
4220 The installation section and the section about the debugger is intimidating.
4221 \layout Itemize
4222
4223 There are still lots of typos and there are more different writing styles
4224  than pictures.
4225 \layout Section
4226
4227 Testing the SDCC Compiler
4228 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4229
4230 \end_inset 
4231
4232
4233 \layout Standard
4234
4235 The first thing you should do after installing your SDCC compiler is to
4236  see if it runs.
4237  Type 
4238 \family sans 
4239 \series bold 
4240 "sdcc -
4241 \begin_inset ERT
4242 status Collapsed
4243
4244 \layout Standard
4245
4246 \backslash 
4247 /
4248 \end_inset 
4249
4250 -version"
4251 \begin_inset LatexCommand \index{version}
4252
4253 \end_inset 
4254
4255
4256 \family default 
4257 \series default 
4258  at the prompt, and the program should run and output its version like:
4259  
4260 \newline 
4261
4262 \family typewriter 
4263 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4264  (UNIX)
4265 \layout Standard
4266
4267 If it doesn't run, or gives a message about not finding sdcc program, then
4268  you need to check over your installation.
4269  Make sure that the sdcc bin directory is in your executable search path
4270  defined by the PATH environment setting (
4271 \series medium 
4272 see 
4273 \series default 
4274 section 
4275 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4276
4277 \end_inset 
4278
4279 \SpecialChar ~
4280
4281 \series medium 
4282 Install trouble-shooting for suggestions
4283 \series default 
4284 ).
4285  Make sure that the sdcc program is in the bin folder, if not perhaps something
4286  did not install correctly.
4287 \newline 
4288
4289 \newline 
4290
4291 \series medium 
4292 SDCC 
4293 \series default 
4294 is commonly installed as described in section 
4295 \begin_inset Quotes sld
4296 \end_inset 
4297
4298 Install and search paths
4299 \begin_inset Quotes srd
4300 \end_inset 
4301
4302 .
4303 \newline 
4304
4305 \newline 
4306
4307 \series medium 
4308 Make sure the compiler works on a very simple example.
4309  Type in the following test.c program using your favorite 
4310 \series default 
4311 ASCII 
4312 \series medium 
4313 editor:
4314 \layout Verse
4315
4316
4317 \family typewriter 
4318 char test;
4319 \newline 
4320
4321 \newline 
4322 void main(void) {
4323 \newline 
4324 \SpecialChar ~
4325 \SpecialChar ~
4326 \SpecialChar ~
4327 \SpecialChar ~
4328 test=0;
4329 \newline 
4330 }
4331 \layout Standard
4332
4333
4334 \series medium 
4335 Compile this using the following command: 
4336 \family sans 
4337 \series bold 
4338 "sdcc -c test.c".
4339
4340 \family default 
4341 \series default 
4342  
4343 \series medium 
4344 If all goes well, the compiler will generate a test.asm and test.rel file.
4345  Congratulations, you've just compiled your first program with SDCC.
4346  We used the -c option to tell SDCC not to link the generated code, just
4347  to keep things simple for this step.
4348 \series default 
4349
4350 \newline 
4351
4352 \newline 
4353
4354 \series medium 
4355 The next step is to try it with the linker.
4356  Type in 
4357 \family sans 
4358 \series bold 
4359 "sdcc test.c
4360 \family default 
4361 \series default 
4362 "
4363 \series medium 
4364 .
4365  If all goes well the compiler will link with the libraries and produce
4366  a test.ihx output file.
4367  If this step fails
4368 \series default 
4369  
4370 \series medium 
4371 (no test.ihx, and the linker generates warnings), then the problem is most
4372  likely that 
4373 \series default 
4374 SDCC
4375 \series medium 
4376  cannot find the 
4377 \series default 
4378 /
4379 \series medium 
4380 usr/local/share/sdcc/lib directory
4381 \series default 
4382  
4383 \series medium 
4384 (see 
4385 \series default 
4386 section 
4387 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4388
4389 \end_inset 
4390
4391 \SpecialChar ~
4392
4393 \series medium 
4394 Install trouble-shooting for suggestions).
4395 \series default 
4396
4397 \newline 
4398
4399 \newline 
4400
4401 \series medium 
4402 The final test is to ensure 
4403 \series default 
4404 SDCC
4405 \series medium 
4406  can use the 
4407 \series default 
4408 standard
4409 \series medium 
4410  header files and libraries.
4411  Edit test.c and change it to the following:
4412 \layout Verse
4413
4414
4415 \family typewriter 
4416 #include <string.h>
4417 \newline 
4418
4419 \newline 
4420 char str1[10];
4421 \newline 
4422
4423 \newline 
4424 void main(void) {
4425 \newline 
4426 \SpecialChar ~
4427 \SpecialChar ~
4428 strcpy(str1, "testing");
4429 \newline 
4430 }
4431 \layout Standard
4432
4433
4434 \series medium 
4435 Compile this by typing 
4436 \family sans 
4437 \series bold 
4438 "sdcc test.c"
4439 \family default 
4440 \series medium 
4441 .
4442  This should generate a test.ihx output file, and it should give no warnings
4443  such as not finding the string.h file.
4444  If it cannot find the string.h file, then the problem is that 
4445 \series default 
4446 SDCC
4447 \series medium 
4448  cannot find the /usr/local/share/sdcc/include directory
4449 \series default 
4450  
4451 \series medium 
4452 (see the 
4453 \series default 
4454 section 
4455 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4456
4457 \end_inset 
4458
4459 \SpecialChar ~
4460
4461 \series medium 
4462 Install trouble-shooting section for suggestions).
4463
4464 \series default 
4465  Use option 
4466 \series bold 
4467 -
4468 \begin_inset ERT
4469 status Collapsed
4470
4471 \layout Standard
4472
4473 \backslash 
4474 /
4475 \end_inset 
4476
4477 -print-search-dirs
4478 \series default 
4479
4480 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4481
4482 \end_inset 
4483
4484  to find exactly where SDCC is looking for the include and lib files.
4485 \layout Section
4486
4487 Install Trouble-shooting
4488 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4489
4490 \end_inset 
4491
4492
4493 \begin_inset LatexCommand \index{Install trouble-shooting}
4494
4495 \end_inset 
4496
4497
4498 \layout Subsection
4499
4500 If SDCC does not build correctly
4501 \layout Standard
4502
4503 A thing to try is starting from scratch by unpacking the .tgz source package
4504  again in an empty directory.
4505  Configure it like:
4506 \newline 
4507
4508 \newline 
4509
4510 \family sans 
4511 \series bold 
4512 ./configure 2>&1 | tee configure.log
4513 \family default 
4514 \series default 
4515
4516 \newline 
4517
4518 \newline 
4519 and build it like:
4520 \newline 
4521
4522 \newline 
4523
4524 \family sans 
4525 \series bold 
4526 make 2>&1 | tee make.log
4527 \family default 
4528 \series default 
4529
4530 \newline 
4531
4532 \newline 
4533 If anything goes wrong, you can review the log files to locate the problem.
4534  Or a relevant part of this can be attached to an email that could be helpful
4535  when requesting help from the mailing list.
4536 \layout Subsection
4537
4538 What the 
4539 \begin_inset Quotes sld
4540 \end_inset 
4541
4542 ./configure
4543 \begin_inset Quotes srd
4544 \end_inset 
4545
4546  does
4547 \layout Standard
4548
4549 The 
4550 \begin_inset Quotes sld
4551 \end_inset 
4552
4553 ./configure
4554 \begin_inset Quotes srd
4555 \end_inset 
4556
4557  command is a script that analyzes your system and performs some configuration
4558  to ensure the source package compiles on your system.
4559  It will take a few minutes to run, and will compile a few tests to determine
4560  what compiler features are installed.
4561 \layout Subsection
4562
4563 What the 
4564 \begin_inset Quotes sld
4565 \end_inset 
4566
4567 make
4568 \begin_inset Quotes srd
4569 \end_inset 
4570
4571  does
4572 \layout Standard
4573
4574 This runs the GNU make tool, which automatically compiles all the source
4575  packages into the final installed binary executables.
4576 \layout Subsection
4577
4578 What the 
4579 \begin_inset Quotes sld
4580 \end_inset 
4581
4582 make install
4583 \begin_inset Quotes erd
4584 \end_inset 
4585
4586  command does.
4587 \layout Standard
4588
4589 This will install the compiler, other executables libraries and include
4590  files into the appropriate directories.
4591  See sections 
4592 \begin_inset LatexCommand \ref{sub:Install-paths}
4593
4594 \end_inset 
4595
4596 ,\SpecialChar ~
4597
4598 \begin_inset LatexCommand \ref{sub:Search-Paths}
4599
4600 \end_inset 
4601
4602 \SpecialChar ~
4603 about install and search paths.
4604 \newline 
4605 On most systems you will need super-user privileges to do this.
4606 \layout Section
4607
4608 Components of SDCC
4609 \layout Standard
4610
4611 SDCC is not just a compiler, but a collection of tools by various developers.
4612  These include linkers, assemblers, simulators and other components.
4613  Here is a summary of some of the components.
4614  Note that the included simulator and assembler have separate documentation
4615  which you can find in the source package in their respective directories.
4616  As SDCC grows to include support for other processors, other packages from
4617  various developers are included and may have their own sets of documentation.
4618 \newline 
4619
4620 \newline 
4621 You might want to look at the files which are installed in <installdir>.
4622  At the time of this writing, we find the following programs for gcc-builds:
4623 \newline 
4624  
4625 \newline 
4626 In <installdir>/bin:
4627 \layout Itemize
4628
4629 sdcc - The compiler.
4630 \layout Itemize
4631
4632 sdcpp - The C preprocessor.
4633 \layout Itemize
4634
4635 asx8051 - The assembler for 8051 type processors.
4636 \layout Itemize
4637
4638 as-z80
4639 \series bold 
4640
4641 \series default 
4642 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4643 \layout Itemize
4644
4645 aslink -The linker for 8051 type processors.
4646 \layout Itemize
4647
4648 link-z80
4649 \series bold 
4650
4651 \series default 
4652 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4653 \layout Itemize
4654
4655 s51 - The ucSim 8051 simulator.
4656 \layout Itemize
4657
4658 sdcdb - The source debugger.
4659 \layout Itemize
4660
4661 packihx - A tool to pack (compress) Intel hex files.
4662 \layout Standard
4663
4664 In <installdir>/share/sdcc/include
4665 \layout Itemize
4666
4667 the include files
4668 \layout Standard
4669
4670 In <installdir>/share/sdcc/lib
4671 \layout Itemize
4672
4673 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4674  relocatables.
4675 \layout Standard
4676
4677 In <installdir>/share/sdcc/doc
4678 \layout Itemize
4679
4680 the documentation
4681 \layout Standard
4682
4683 As development for other processors proceeds, this list will expand to include
4684  executables to support processors like AVR, PIC, etc.
4685 \layout Subsection
4686
4687 sdcc - The Compiler
4688 \layout Standard
4689
4690 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4691  the assembler and linkage editor.
4692 \layout Subsection
4693
4694 sdcpp - The C-Preprocessor
4695 \layout Standard
4696
4697 The preprocessor
4698 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4699
4700 \end_inset 
4701
4702  is a modified version of the GNU cpp
4703 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4704
4705 \end_inset 
4706
4707  preprocessor 
4708 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4709
4710 \end_inset 
4711
4712 .
4713  The C preprocessor is used to pull in #include sources, process #ifdef
4714  statements, #defines and so on.
4715 \layout Subsection
4716
4717 as
4718 \emph on 
4719 xxxx
4720 \emph default 
4721 , aslink, link-
4722 \emph on 
4723 xxx
4724 \emph default 
4725  - The Assemblers and Linkage Editors
4726 \layout Standard
4727
4728 This is retargettable assembler & linkage editor, it was developed by Alan
4729  Baldwin.
4730  John Hartman created the version for 8051, and I (Sandeep) have made some
4731  enhancements and bug fixes for it to work properly with SDCC.
4732 \layout Subsection
4733
4734 s51 - The Simulator
4735 \layout Standard
4736
4737 S51
4738 \begin_inset LatexCommand \index{s51}
4739
4740 \end_inset 
4741
4742  is a freeware, opensource simulator developed by Daniel Drotos.
4743  The simulator is built as part of the build process.
4744  For more information visit Daniel's web site at: 
4745 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4746
4747 \end_inset 
4748
4749 .
4750  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4751  XA51 family.
4752 \layout Subsection
4753
4754 sdcdb - Source Level Debugger
4755 \layout Standard
4756
4757 SDCDB
4758 \begin_inset LatexCommand \index{SDCDB (debugger)}
4759
4760 \end_inset 
4761
4762  is the companion source level debugger.
4763  More about SDCDB in section 
4764 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4765
4766 \end_inset 
4767
4768 .
4769  The current version of the debugger uses Daniel's Simulator S51
4770 \begin_inset LatexCommand \index{s51}
4771
4772 \end_inset 
4773
4774 , but can be easily changed to use other simulators.
4775 \layout Chapter
4776
4777 Using SDCC
4778 \layout Section
4779
4780 Compiling
4781 \layout Subsection
4782
4783 Single Source File Projects
4784 \layout Standard
4785
4786 For single source file 8051 projects the process is very simple.
4787  Compile your programs with the following command 
4788 \family sans 
4789 \series bold 
4790 "sdcc sourcefile.c".
4791
4792 \family default 
4793 \series default 
4794  This will compile, assemble and link your source file.
4795  Output files are as follows:
4796 \layout Itemize
4797
4798 sourcefile.asm
4799 \begin_inset LatexCommand \index{<file>.asm}
4800
4801 \end_inset 
4802
4803  - Assembler source
4804 \begin_inset LatexCommand \index{Assembler source}
4805
4806 \end_inset 
4807
4808  file created by the compiler
4809 \layout Itemize
4810
4811 sourcefile.lst
4812 \begin_inset LatexCommand \index{<file>.lst}
4813
4814 \end_inset 
4815
4816  - Assembler listing
4817 \begin_inset LatexCommand \index{Assembler listing}
4818
4819 \end_inset 
4820
4821  file created by the Assembler
4822 \layout Itemize
4823
4824 sourcefile.rst
4825 \begin_inset LatexCommand \index{<file>.rst}
4826
4827 \end_inset 
4828
4829  - Assembler listing
4830 \begin_inset LatexCommand \index{Assembler listing}
4831
4832 \end_inset 
4833
4834  file updated with linkedit information, created by linkage editor
4835 \layout Itemize
4836
4837 sourcefile.sym
4838 \begin_inset LatexCommand \index{<file>.sym}
4839
4840 \end_inset 
4841
4842  - symbol listing
4843 \begin_inset LatexCommand \index{Symbol listing}
4844
4845 \end_inset 
4846
4847  for the sourcefile, created by the assembler
4848 \layout Itemize
4849
4850 sourcefile.rel
4851 \begin_inset LatexCommand \index{<file>.rel}
4852
4853 \end_inset 
4854
4855  or sourcefile.o
4856 \begin_inset LatexCommand \index{<file>.o}
4857
4858 \end_inset 
4859
4860  - Object file
4861 \begin_inset LatexCommand \index{Object file}
4862
4863 \end_inset 
4864
4865  created by the assembler, input to Linkage editor
4866 \layout Itemize
4867
4868 sourcefile.map
4869 \begin_inset LatexCommand \index{<file>.map}
4870
4871 \end_inset 
4872
4873  - The memory map
4874 \begin_inset LatexCommand \index{Memory map}
4875
4876 \end_inset 
4877
4878  for the load module, created by the Linker
4879 \layout Itemize
4880
4881 sourcefile.mem
4882 \begin_inset LatexCommand \index{<file>.mem}
4883
4884 \end_inset 
4885
4886  - A file with a summary of the memory usage
4887 \layout Itemize
4888
4889 sourcefile.ihx
4890 \begin_inset LatexCommand \index{<file>.ihx}
4891
4892 \end_inset 
4893
4894  - The load module in Intel hex format
4895 \begin_inset LatexCommand \index{Intel hex format}
4896
4897 \end_inset 
4898
4899  (you can select the Motorola S19 format
4900 \begin_inset LatexCommand \index{Motorola S19 format}
4901
4902 \end_inset 
4903
4904  with -
4905 \begin_inset ERT
4906 status Collapsed
4907
4908 \layout Standard
4909
4910 \backslash 
4911 /
4912 \end_inset 
4913
4914 -out-fmt-s19
4915 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4916
4917 \end_inset 
4918
4919 .
4920  If you need another format you might want to use 
4921 \family sans 
4922 \shape italic 
4923 objdump
4924 \family default 
4925 \shape default 
4926
4927 \begin_inset LatexCommand \index{objdump (tool)}
4928
4929 \end_inset 
4930
4931  or
4932 \family sans 
4933 \shape italic 
4934  srecord
4935 \family default 
4936 \shape default 
4937
4938 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4939
4940 \end_inset 
4941
4942 ).
4943  Both formats are documented in the documentation of srecord
4944 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4945
4946 \end_inset 
4947
4948
4949 \layout Itemize
4950
4951 sourcefile.adb
4952 \begin_inset LatexCommand \index{<file>.adb}
4953
4954 \end_inset 
4955
4956  - An intermediate file containing debug information needed to create the
4957  .cdb file (with -
4958 \begin_inset ERT
4959 status Collapsed
4960
4961 \layout Standard
4962
4963 \backslash 
4964 /
4965 \end_inset 
4966
4967 -debug
4968 \begin_inset LatexCommand \index{-\/-debug}
4969
4970 \end_inset 
4971
4972
4973 \layout Itemize
4974
4975 sourcefile.cdb
4976 \begin_inset LatexCommand \index{<file>.cdb}
4977
4978 \end_inset 
4979
4980  - An optional file (with -
4981 \begin_inset ERT
4982 status Collapsed
4983
4984 \layout Standard
4985
4986 \backslash 
4987 /
4988 \end_inset 
4989
4990 -debug) containing debug information.
4991  The format is documented in cdbfileformat.pdf
4992 \layout Itemize
4993
4994 sourcefile.
4995  - (no extension)
4996 \begin_inset LatexCommand \index{<file> (no extension)}
4997
4998 \end_inset 
4999
5000  An optional AOMF or AOMF51
5001 \begin_inset LatexCommand \index{AOMF, AOMF51}
5002
5003 \end_inset 
5004
5005  
5006 \begin_inset LatexCommand \label{OMF file}
5007
5008 \end_inset 
5009
5010 file containing debug information (generated with option -
5011 \begin_inset ERT
5012 status Collapsed
5013
5014 \layout Standard
5015
5016 \backslash 
5017 /
5018 \end_inset 
5019
5020 -debug).
5021  The (Intel)
5022 \emph on 
5023  a
5024 \emph default 
5025 bsolute 
5026 \emph on 
5027 o
5028 \emph default 
5029 bject 
5030 \emph on 
5031 m
5032 \emph default 
5033 odule 
5034 \emph on 
5035 f
5036 \emph default 
5037 ormat is commonly used by third party tools (debuggers
5038 \begin_inset LatexCommand \index{Debugger}
5039
5040 \end_inset 
5041
5042 , simulators, emulators)
5043 \layout Itemize
5044
5045 sourcefile.dump*
5046 \begin_inset LatexCommand \index{<file>.dump*}
5047
5048 \end_inset 
5049
5050  - Dump file to debug the compiler it self (generated with option -
5051 \begin_inset ERT
5052 status Collapsed
5053
5054 \layout Standard
5055
5056 \backslash 
5057 /
5058 \end_inset 
5059
5060 -dumpall) (see section 
5061 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5062
5063 \end_inset 
5064
5065 \SpecialChar ~
5066  and section 
5067 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5068
5069 \end_inset 
5070
5071 \SpecialChar ~
5072
5073 \begin_inset Quotes sld
5074 \end_inset 
5075
5076 Anatomy of the compiler
5077 \begin_inset Quotes srd
5078 \end_inset 
5079
5080 ).
5081 \layout Subsection
5082
5083 Postprocessing the Intel Hex
5084 \begin_inset LatexCommand \index{Intel hex format}
5085
5086 \end_inset 
5087
5088  file
5089 \layout Standard
5090
5091 In most cases this won't be needed but the Intel Hex file
5092 \begin_inset LatexCommand \index{<file>.ihx}
5093
5094 \end_inset 
5095
5096  which is generated by SDCC might include lines of varying length and the
5097  addresses within the file are not guaranteed to be strictly ascending.
5098  If your toolchain or a bootloader does not like this you can use the tool
5099  
5100 \family typewriter 
5101 packihx
5102 \family default 
5103
5104 \begin_inset LatexCommand \index{packihx (tool)}
5105
5106 \end_inset 
5107
5108  which is part of the SDCC distribution: 
5109 \newline 
5110
5111 \newline 
5112
5113 \family sans 
5114 \series bold 
5115  packihx sourcefile.ihx >sourcefile.hex
5116 \family default 
5117 \series default 
5118
5119 \newline 
5120
5121 \newline 
5122 The separately available
5123 \emph on 
5124  srecord
5125 \emph default 
5126
5127 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5128
5129 \end_inset 
5130
5131  package additionally allows to set undefined locations to a predefined
5132  value, to insert checksums
5133 \begin_inset LatexCommand \index{checksum}
5134
5135 \end_inset 
5136
5137  of various flavours (crc, add, xor) and to perform other manipulations
5138  (convert, split, crop, offset, ...).
5139  
5140 \newline 
5141
5142 \newline 
5143
5144 \family sans 
5145 \series bold 
5146 srec_cat\SpecialChar ~
5147 \SpecialChar ~
5148 sourcefile.ihx -intel\SpecialChar ~
5149 \SpecialChar ~
5150 -o sourcefile.hex -intel
5151 \newline 
5152
5153 \newline 
5154
5155 \family default 
5156 \series default 
5157 An example for a more complex command line
5158 \begin_inset Foot
5159 collapsed false
5160
5161 \layout Standard
5162
5163 the command backfills
5164 \begin_inset LatexCommand \index{backfill unused memory}
5165
5166 \end_inset 
5167
5168  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5169  block is zero.
5170  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5171  will be interpreted as an 
5172 \family typewriter 
5173 lcall
5174 \family default 
5175  to address 
5176 \family typewriter 
5177 0x1212
5178 \family default 
5179  (where an emergency routine could sit).
5180 \end_inset 
5181
5182  could look like:
5183 \newline 
5184
5185 \newline 
5186
5187 \family sans 
5188 \series bold 
5189 \size footnotesize 
5190 srec_cat\SpecialChar ~
5191 sourcefile.ihx -intel\SpecialChar ~
5192 \SpecialChar ~
5193 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5194 -little-endian-checksum-nega
5195 tive 0xfffe 0x02 0x02\SpecialChar ~
5196 \SpecialChar ~
5197 -o sourcefile.hex -intel
5198 \size default 
5199
5200 \newline 
5201
5202 \newline 
5203
5204 \family default 
5205 \series default 
5206 The srecord package is available at 
5207 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5208
5209 \end_inset 
5210
5211  .
5212 \layout Subsection
5213
5214 Projects with Multiple Source Files
5215 \layout Standard
5216
5217 SDCC can compile only ONE file at a time.
5218  Let us for example assume that you have a project containing the following
5219  files:
5220 \newline 
5221
5222 \newline 
5223 foo1.c (contains some functions)
5224 \newline 
5225 foo2.c (contains some more functions)
5226 \newline 
5227 foomain.c (contains more functions and the function main)
5228 \newline 
5229
5230 \size footnotesize 
5231
5232 \newline 
5233
5234 \size default 
5235 The first two files will need to be compiled separately with the commands:
5236 \size footnotesize 
5237  
5238 \size default 
5239
5240 \newline 
5241
5242 \newline 
5243
5244 \family sans 
5245 \series bold 
5246 sdcc\SpecialChar ~
5247 -c\SpecialChar ~
5248 foo1.c
5249 \family default 
5250 \series default 
5251 \size footnotesize 
5252
5253 \newline 
5254
5255 \family sans 
5256 \series bold 
5257 \size default 
5258 sdcc\SpecialChar ~
5259 -c\SpecialChar ~
5260 foo2.c
5261 \family default 
5262 \series default 
5263
5264 \newline 
5265
5266 \newline 
5267 Then compile the source file containing the 
5268 \emph on 
5269 main()
5270 \emph default 
5271  function and link
5272 \begin_inset LatexCommand \index{Linker}
5273
5274 \end_inset 
5275
5276  the files together with the following command: 
5277 \newline 
5278
5279 \newline 
5280
5281 \family sans 
5282 \series bold 
5283 sdcc\SpecialChar ~
5284 foomain.c\SpecialChar ~
5285 foo1.rel\SpecialChar ~
5286 foo2.rel
5287 \family default 
5288 \series default 
5289
5290 \begin_inset LatexCommand \index{<file>.rel}
5291
5292 \end_inset 
5293
5294
5295 \newline 
5296
5297 \newline 
5298 Alternatively, 
5299 \emph on 
5300 foomain.c 
5301 \emph default 
5302 can be separately compiled as well: 
5303 \family sans 
5304 \series bold 
5305
5306 \newline 
5307
5308 \newline 
5309 sdcc\SpecialChar ~
5310 -c\SpecialChar ~
5311 foomain.c
5312 \newline 
5313 sdcc foomain.rel foo1.rel foo2.rel
5314 \newline 
5315
5316 \newline 
5317
5318 \family default 
5319 \series default 
5320 The file containing the 
5321 \emph on 
5322 main()
5323 \emph default 
5324  function
5325 \emph on 
5326  
5327 \emph default 
5328 \noun on 
5329 must
5330 \noun default 
5331  be the 
5332 \noun on 
5333 first
5334 \noun default 
5335  file specified in the command line, since the linkage editor processes
5336  file in the order they are presented to it.
5337  The linker is invoked from SDCC using a script file with extension .lnk
5338 \begin_inset LatexCommand \index{<file>.lnk}
5339
5340 \end_inset 
5341
5342 .
5343  You can view this file to troubleshoot linking problems such as those arising
5344  from missing libraries.
5345 \layout Subsection
5346
5347 Projects with Additional Libraries
5348 \begin_inset LatexCommand \index{Libraries}
5349
5350 \end_inset 
5351
5352
5353 \layout Standard
5354
5355 Some reusable routines may be compiled into a library, see the documentation
5356  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5357  for how to create a 
5358 \emph on 
5359 .lib
5360 \begin_inset LatexCommand \index{<file>.lib}
5361
5362 \end_inset 
5363
5364
5365 \emph default 
5366  library file.
5367  Libraries created in this manner can be included in the command line.
5368  Make sure you include the -L <library-path> option to tell the linker where
5369  to look for these files if they are not in the current directory.
5370  Here is an example, assuming you have the source file 
5371 \emph on 
5372 foomain.c
5373 \emph default 
5374  and a library
5375 \emph on 
5376  foolib.lib
5377 \emph default 
5378  in the directory 
5379 \emph on 
5380 mylib
5381 \emph default 
5382  (if that is not the same as your current project):
5383 \newline 
5384
5385 \newline 
5386
5387 \family sans 
5388 \series bold 
5389 sdcc foomain.c foolib.lib -L mylib
5390 \newline 
5391
5392 \newline 
5393
5394 \family default 
5395 \series default 
5396 Note here that
5397 \emph on 
5398  mylib
5399 \emph default 
5400  must be an absolute path name.
5401 \newline 
5402
5403 \newline 
5404 The most efficient way to use libraries is to keep separate modules in separate
5405  source files.
5406  The lib file now should name all the modules.rel
5407 \begin_inset LatexCommand \index{<file>.rel}
5408
5409 \end_inset 
5410
5411  files.
5412  For an example see the standard library file 
5413 \emph on 
5414 libsdcc.lib
5415 \emph default 
5416  in the directory <installdir>/share/lib/small.
5417 \layout Subsection
5418
5419 Using sdcclib to Create and Manage Libraries
5420 \begin_inset LatexCommand \index{sdcclib}
5421
5422 \end_inset 
5423
5424
5425 \layout Standard
5426
5427 Alternatively, instead of having a .rel file for each entry on the library
5428  file as described in the preceding section, sdcclib can be used to embed
5429  all the modules belonging to such library in the library file itself.
5430  This results in a larger library file, but it greatly reduces the number
5431  of disk files accessed by the linker.
5432   Additionally, the packed library file contains an index of all include
5433  modules and symbols that significantly speeds up the linking process.
5434  To display a list of options supported by sdcclib type:
5435 \newline 
5436
5437 \layout Standard
5438
5439
5440 \family sans 
5441 \series bold 
5442 sdcclib -?
5443 \begin_inset LatexCommand \index{sdcclib}
5444
5445 \end_inset 
5446
5447
5448 \newline 
5449
5450 \newline 
5451
5452 \family default 
5453 \series default 
5454 To create a new library file, start by compiling all the required modules.
5455  For example:
5456 \newline 
5457
5458 \layout Standard
5459
5460
5461 \family sans 
5462 \series bold 
5463 sdcc -c _divsint.c
5464 \layout Standard
5465
5466
5467 \family sans 
5468 \series bold 
5469 sdcc -c _divuint.c
5470 \layout Standard
5471
5472
5473 \family sans 
5474 \series bold 
5475 sdcc -c _modsint.c
5476 \layout Standard
5477
5478
5479 \family sans 
5480 \series bold 
5481 sdcc -c _moduint.c
5482 \layout Standard
5483
5484
5485 \family sans 
5486 \series bold 
5487 sdcc -c _mulint.c
5488 \newline 
5489
5490 \layout Standard
5491
5492 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5493  and _mulint.rel.
5494  The next step is to add the .rel files to the library file:
5495 \newline 
5496
5497 \layout Standard
5498
5499
5500 \family sans 
5501 \series bold 
5502 sdcclib libint.lib _divsint.rel
5503 \family default 
5504
5505 \begin_inset LatexCommand \index{sdcclib}
5506
5507 \end_inset 
5508
5509
5510 \layout Standard
5511
5512
5513 \family sans 
5514 \series bold 
5515 sdcclib libint.lib _divuint.rel
5516 \layout Standard
5517
5518
5519 \family sans 
5520 \series bold 
5521 sdcclib libint.lib _modsint.rel
5522 \layout Standard
5523
5524
5525 \family sans 
5526 \series bold 
5527 sdcclib libint.lib _moduint.rel
5528 \layout Standard
5529
5530
5531 \family sans 
5532 \series bold 
5533 sdcclib libint.lib _mulint.rel
5534 \series default 
5535
5536 \newline 
5537
5538 \layout Standard
5539
5540 If the file already exists in the library, it will be replaced.
5541  To see what modules and symbols are included in the library, options -s
5542  and -m are available.
5543  For example:
5544 \newline 
5545
5546 \newline 
5547
5548 \family sans 
5549 \series bold 
5550 sdcclib -s libint.lib
5551 \family default 
5552
5553 \begin_inset LatexCommand \index{sdcclib}
5554
5555 \end_inset 
5556
5557
5558 \newline 
5559
5560 \family typewriter 
5561 \series default 
5562 _divsint.rel:
5563 \layout Standard
5564
5565
5566 \family typewriter 
5567 __divsint_a_1_1
5568 \layout Standard
5569
5570
5571 \family typewriter 
5572 __divsint_PARM_2
5573 \layout Standard
5574
5575
5576 \family typewriter 
5577 __divsint
5578 \newline 
5579 _divuint.rel:
5580 \layout Standard
5581
5582
5583 \family typewriter 
5584 __divuint_a_1_1
5585 \layout Standard
5586
5587
5588 \family typewriter 
5589 __divuint_PARM_2
5590 \layout Standard
5591
5592
5593 \family typewriter 
5594 __divuint_reste_1_1
5595 \layout Standard
5596
5597
5598 \family typewriter 
5599 __divuint_count_1_1
5600 \layout Standard
5601
5602
5603 \family typewriter 
5604 __divuint
5605 \newline 
5606 _modsint.rel:
5607 \layout Standard
5608
5609
5610 \family typewriter 
5611 __modsint_a_1_1
5612 \layout Standard
5613
5614
5615 \family typewriter 
5616 __modsint_PARM_2
5617 \layout Standard
5618
5619
5620 \family typewriter 
5621 __modsint
5622 \newline 
5623 _moduint.rel:
5624 \layout Standard
5625
5626
5627 \family typewriter 
5628 __moduint_a_1_1
5629 \layout Standard
5630
5631
5632 \family typewriter 
5633 __moduint_PARM_2
5634 \layout Standard
5635
5636
5637 \family typewriter 
5638 __moduint_count_1_1
5639 \layout Standard
5640
5641
5642 \family typewriter 
5643 __moduint
5644 \newline 
5645 _mulint.rel:
5646 \layout Standard
5647
5648
5649 \family typewriter 
5650 __mulint_PARM_2
5651 \layout Standard
5652
5653
5654 \family typewriter 
5655 __mulint
5656 \family default 
5657 \series bold 
5658
5659 \newline 
5660
5661 \layout Standard
5662 \added_space_bottom bigskip 
5663 If the source files are compiled using -
5664 \begin_inset ERT
5665 status Collapsed
5666
5667 \layout Standard
5668
5669 \backslash 
5670 /
5671 \end_inset 
5672
5673 -debug
5674 \begin_inset LatexCommand \index{-\/-debug}
5675
5676 \end_inset 
5677
5678 , the corresponding debug information file .adb will be include in the library
5679  file as well.
5680  The library files created with sdcclib are plain text files, so they can
5681  be viewed with a text editor.
5682  It is not recomended to modify a library file created with sdcclib using
5683  a text editor, as there are file indexes numbers located accross the file
5684  used by the linker to quickly locate the required module to link.
5685  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5686  it can be safely deleted, since all the information required for linking
5687  is embedded in the library file itself.
5688  Library files created using sdcclib are used as described in the preceding
5689  sections.
5690 \layout Section
5691
5692 Command Line Options
5693 \begin_inset LatexCommand \index{Command Line Options}
5694
5695 \end_inset 
5696
5697
5698 \layout Subsection
5699
5700 Processor Selection Options
5701 \begin_inset LatexCommand \index{Options processor selection}
5702
5703 \end_inset 
5704
5705
5706 \begin_inset LatexCommand \index{Processor selection options}
5707
5708 \end_inset 
5709
5710
5711 \layout List
5712 \labelwidthstring 00.00.0000
5713
5714
5715 \series bold 
5716 -mmcs51
5717 \begin_inset LatexCommand \index{-mmcs51}
5718
5719 \end_inset 
5720
5721
5722 \series default 
5723  Generate code for the Intel MCS51
5724 \begin_inset LatexCommand \index{MCS51}
5725
5726 \end_inset 
5727
5728  family of processors.
5729  This is the default processor target.
5730 \layout List
5731 \labelwidthstring 00.00.0000
5732
5733
5734 \series bold 
5735 -mds390
5736 \begin_inset LatexCommand \index{-mds390}
5737
5738 \end_inset 
5739
5740
5741 \series default 
5742  Generate code for the Dallas DS80C390
5743 \begin_inset LatexCommand \index{DS80C390}
5744
5745 \end_inset 
5746
5747  processor.
5748 \layout List
5749 \labelwidthstring 00.00.0000
5750
5751
5752 \series bold 
5753 -mds400
5754 \begin_inset LatexCommand \index{-mds400}
5755
5756 \end_inset 
5757
5758
5759 \series default 
5760  Generate code for the Dallas DS80C400
5761 \begin_inset LatexCommand \index{DS80C400}
5762
5763 \end_inset 
5764
5765  processor.
5766 \layout List
5767 \labelwidthstring 00.00.0000
5768
5769
5770 \series bold 
5771 -mhc08
5772 \begin_inset LatexCommand \index{-mhc08}
5773
5774 \end_inset 
5775
5776
5777 \series default 
5778  Generate code for the Freescale/Motorola HC08
5779 \begin_inset LatexCommand \index{HC08}
5780
5781 \end_inset 
5782
5783  family of processors.
5784 \layout List
5785 \labelwidthstring 00.00.0000
5786
5787
5788 \series bold 
5789 -mz80
5790 \begin_inset LatexCommand \index{-mz80}
5791
5792 \end_inset 
5793
5794
5795 \series default 
5796  Generate code for the Zilog Z80
5797 \begin_inset LatexCommand \index{Z80}
5798
5799 \end_inset 
5800
5801  family of processors.
5802 \layout List
5803 \labelwidthstring 00.00.0000
5804
5805
5806 \series bold 
5807 -mgbz80
5808 \begin_inset LatexCommand \index{-mgbz80}
5809
5810 \end_inset 
5811
5812
5813 \series default 
5814  Generate code for the GameBoy Z80
5815 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5816
5817 \end_inset 
5818
5819  processor (Not actively maintained).
5820 \layout List
5821 \labelwidthstring 00.00.0000
5822
5823
5824 \series bold 
5825 -mavr
5826 \begin_inset LatexCommand \index{-mavr}
5827
5828 \end_inset 
5829
5830
5831 \series default 
5832  Generate code for the Atmel AVR
5833 \begin_inset LatexCommand \index{AVR}
5834
5835 \end_inset 
5836
5837  processor (Not maintained, not complete).
5838  AVR users should probably have a look at winavr 
5839 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5840
5841 \end_inset 
5842
5843  or 
5844 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5845
5846 \end_inset 
5847
5848 .
5849 \layout Comment
5850
5851 I think it is fair to direct users there for now.
5852  Open source is also about avoiding unnecessary work .
5853  But I didn't find the 'official' link.
5854 \layout List
5855 \labelwidthstring 00.00.0000
5856
5857
5858 \series bold 
5859 -mpic14
5860 \begin_inset LatexCommand \index{-mpic14}
5861
5862 \end_inset 
5863
5864
5865 \series default 
5866  Generate code for the Microchip PIC 14
5867 \begin_inset LatexCommand \index{PIC14}
5868
5869 \end_inset 
5870
5871 -bit processors (p16f84 and variants.
5872  In development, not complete).
5873 \layout Comment
5874
5875 p16f627 p16f628 p16f84 p16f873 p16f877?
5876 \layout List
5877 \labelwidthstring 00.00.0000
5878
5879
5880 \series bold 
5881 -mpic16
5882 \begin_inset LatexCommand \index{-mpic16}
5883
5884 \end_inset 
5885
5886
5887 \series default 
5888  Generate code for the Microchip PIC 16
5889 \begin_inset LatexCommand \index{PIC16}
5890
5891 \end_inset 
5892
5893 -bit processors (p18f452 and variants.
5894  In development, not complete).
5895 \layout List
5896 \labelwidthstring 00.00.0000
5897
5898
5899 \series bold 
5900 -mtlcs900h
5901 \series default 
5902  Generate code for the Toshiba TLCS-900H
5903 \begin_inset LatexCommand \index{TLCS-900H}
5904
5905 \end_inset 
5906
5907  processor (Not maintained, not complete).
5908 \layout List
5909 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5910
5911
5912 \series bold 
5913 -mxa51
5914 \begin_inset LatexCommand \index{-mxa51}
5915
5916 \end_inset 
5917
5918
5919 \series default 
5920  Generate code for the Phillips XA51
5921 \begin_inset LatexCommand \index{XA51}
5922
5923 \end_inset 
5924
5925  processor (Not maintained, not complete).
5926 \layout Subsection
5927
5928 Preprocessor Options
5929 \begin_inset LatexCommand \index{Options preprocessor}
5930
5931 \end_inset 
5932
5933
5934 \begin_inset LatexCommand \index{Preprocessor options}
5935
5936 \end_inset 
5937
5938
5939 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5940
5941 \end_inset 
5942
5943
5944 \layout List
5945 \labelwidthstring 00.00.0000
5946
5947
5948 \series bold 
5949 -I<path>
5950 \begin_inset LatexCommand \index{-I<path>}
5951
5952 \end_inset 
5953
5954
5955 \series default 
5956  The additional location where the pre processor will look for <..h> or 
5957 \begin_inset Quotes eld
5958 \end_inset 
5959
5960 ..h
5961 \begin_inset Quotes erd
5962 \end_inset 
5963
5964  files.
5965 \layout List
5966 \labelwidthstring 00.00.0000
5967
5968
5969 \series bold 
5970 -D<macro[=value]>
5971 \begin_inset LatexCommand \index{-D<macro[=value]>}
5972
5973 \end_inset 
5974
5975
5976 \series default 
5977  Command line definition of macros.
5978  Passed to the preprocessor.
5979 \layout List
5980 \labelwidthstring 00.00.0000
5981
5982
5983 \series bold 
5984 -M
5985 \begin_inset LatexCommand \index{-M}
5986
5987 \end_inset 
5988
5989
5990 \series default 
5991  Tell the preprocessor to output a rule suitable for make describing the
5992  dependencies of each object file.
5993  For each source file, the preprocessor outputs one make-rule whose target
5994  is the object file name for that source file and whose dependencies are
5995  all the files `#include'd in it.
5996  This rule may be a single line or may be continued with `
5997 \backslash 
5998 '-newline if it is long.
5999  The list of rules is printed on standard output instead of the preprocessed
6000  C program.
6001  `-M' implies `-E
6002 \begin_inset LatexCommand \index{-E}
6003
6004 \end_inset 
6005
6006 '.
6007 \layout List
6008 \labelwidthstring 00.00.0000
6009
6010
6011 \series bold 
6012 -C
6013 \begin_inset LatexCommand \index{-C}
6014
6015 \end_inset 
6016
6017
6018 \series default 
6019  Tell the preprocessor not to discard comments.
6020  Used with the `-E' option.
6021 \layout List
6022 \labelwidthstring 00.00.0000
6023
6024
6025 \series bold 
6026 -MM
6027 \begin_inset LatexCommand \index{-MM}
6028
6029 \end_inset 
6030
6031
6032 \size large 
6033 \bar under 
6034  
6035 \series default 
6036 \size default 
6037 \bar default 
6038 Like `-M' but the output mentions only the user header files included with
6039  `#include 
6040 \begin_inset Quotes eld
6041 \end_inset 
6042
6043 file"'.
6044  System header files included with `#include <file>' are omitted.
6045 \layout List
6046 \labelwidthstring 00.00.0000
6047
6048
6049 \series bold 
6050 -Aquestion(answer)
6051 \begin_inset LatexCommand \index{-Aquestion(answer)}
6052
6053 \end_inset 
6054
6055
6056 \series default 
6057  Assert the answer answer for question, in case it is tested with a preprocessor
6058  conditional such as `#if #question(answer)'.
6059  `-A-' disables the standard assertions that normally describe the target
6060  machine.
6061 \layout List
6062 \labelwidthstring 00.00.0000
6063
6064
6065 \series bold 
6066 -Umacro
6067 \begin_inset LatexCommand \index{-Umacro}
6068
6069 \end_inset 
6070
6071
6072 \series default 
6073  Undefine macro macro.
6074  `-U' options are evaluated after all `-D' options, but before any `-include'
6075  and `-imacros' options.
6076 \layout List
6077 \labelwidthstring 00.00.0000
6078
6079
6080 \series bold 
6081 -dM
6082 \begin_inset LatexCommand \index{-dM}
6083
6084 \end_inset 
6085
6086
6087 \series default 
6088  Tell the preprocessor to output only a list of the macro definitions that
6089  are in effect at the end of preprocessing.
6090  Used with the `-E' option.
6091 \layout List
6092 \labelwidthstring 00.00.0000
6093
6094
6095 \series bold 
6096 -dD
6097 \begin_inset LatexCommand \index{-dD}
6098
6099 \end_inset 
6100
6101
6102 \series default 
6103  Tell the preprocessor to pass all macro definitions into the output, in
6104  their proper sequence in the rest of the output.
6105 \layout List
6106 \labelwidthstring 00.00.0000
6107
6108
6109 \series bold 
6110 -dN
6111 \begin_inset LatexCommand \index{-dN}
6112
6113 \end_inset 
6114
6115
6116 \size large 
6117 \bar under 
6118  
6119 \series default 
6120 \size default 
6121 \bar default 
6122 Like `-dD' except that the macro arguments and contents are omitted.
6123  Only `#define name' is included in the output.
6124 \layout List
6125 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6126
6127
6128 \series bold 
6129 -Wp\SpecialChar ~
6130 preprocessorOption[,preprocessorOption]
6131 \series default 
6132
6133 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6134
6135 \end_inset 
6136
6137 ...
6138  Pass the preprocessorOption to the preprocessor 
6139 \family typewriter 
6140 sdcpp
6141 \family default 
6142
6143 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6144
6145 \end_inset 
6146
6147 .
6148  SDCC uses an adapted version of the preprocessor 
6149 \emph on 
6150 cpp
6151 \emph default 
6152  of the GNU Compiler Collection
6153 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6154
6155 \end_inset 
6156
6157  (
6158 \emph on 
6159 gcc
6160 \emph default 
6161  
6162 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6163
6164 \end_inset 
6165
6166 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6167 3.3.6\SpecialChar ~
6168 CPP\SpecialChar ~
6169 Manual
6170  at 
6171 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6172
6173 \end_inset 
6174
6175 .
6176 \layout Subsection
6177
6178 Linker Options
6179 \begin_inset LatexCommand \index{Options linker}
6180
6181 \end_inset 
6182
6183
6184 \begin_inset LatexCommand \index{Linker options}
6185
6186 \end_inset 
6187
6188
6189 \layout List
6190 \labelwidthstring 00.00.0000
6191
6192
6193 \series bold 
6194 -L\SpecialChar ~
6195 -
6196 \series default 
6197
6198 \begin_inset ERT
6199 status Collapsed
6200
6201 \layout Standard
6202
6203 \backslash 
6204 /
6205 \end_inset 
6206
6207
6208 \series bold 
6209 -lib-path
6210 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6211
6212 \end_inset 
6213
6214
6215 \begin_inset LatexCommand \index{-L -\/-lib-path}
6216
6217 \end_inset 
6218
6219
6220 \series default 
6221 \SpecialChar ~
6222 <absolute path to additional libraries> This option is passed to the linkage
6223  editor's additional libraries
6224 \begin_inset LatexCommand \index{Libraries}
6225
6226 \end_inset 
6227
6228  search path.
6229  The path name must be absolute.
6230  Additional library files may be specified in the command line.
6231  See section Compiling programs for more details.
6232 \layout List
6233 \labelwidthstring 00.00.0000
6234
6235
6236 \series bold 
6237 -
6238 \begin_inset ERT
6239 status Collapsed
6240
6241 \layout Standard
6242
6243 \backslash 
6244 /
6245 \end_inset 
6246
6247 -xram-loc
6248 \series default 
6249
6250 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6251
6252 \end_inset 
6253
6254 \SpecialChar ~
6255 <Value> The start location of the external ram
6256 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6257
6258 \end_inset 
6259
6260 , default value is 0.
6261  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6262 \begin_inset ERT
6263 status Collapsed
6264
6265 \layout Standard
6266
6267 \backslash 
6268 /
6269 \end_inset 
6270
6271 -xram-loc 0x8000 or -
6272 \begin_inset ERT
6273 status Collapsed
6274
6275 \layout Standard
6276
6277 \backslash 
6278 /
6279 \end_inset 
6280
6281 -xram-loc 32768.
6282 \layout List
6283 \labelwidthstring 00.00.0000
6284
6285
6286 \series bold 
6287 -
6288 \begin_inset ERT
6289 status Collapsed
6290
6291 \layout Standard
6292
6293 \backslash 
6294 /
6295 \end_inset 
6296
6297 -code-loc
6298 \series default 
6299
6300 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6301
6302 \end_inset 
6303
6304 \SpecialChar ~
6305 <Value> The start location of the code
6306 \begin_inset LatexCommand \index{code}
6307
6308 \end_inset 
6309
6310  segment, default value 0.
6311  Note when this option is used the interrupt vector table
6312 \begin_inset LatexCommand \index{interrupt vector table}
6313
6314 \end_inset 
6315
6316  is also relocated to the given address.
6317  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6318 \begin_inset ERT
6319 status Collapsed
6320
6321 \layout Standard
6322
6323 \backslash 
6324 /
6325 \end_inset 
6326
6327 -code-loc 0x8000 or -
6328 \begin_inset ERT
6329 status Collapsed
6330
6331 \layout Standard
6332
6333 \backslash 
6334 /
6335 \end_inset 
6336
6337 -code-loc 32768.
6338 \layout List
6339 \labelwidthstring 00.00.0000
6340
6341
6342 \series bold 
6343 -
6344 \begin_inset ERT
6345 status Collapsed
6346
6347 \layout Standard
6348
6349 \backslash 
6350 /
6351 \end_inset 
6352
6353 -stack-loc
6354 \series default 
6355
6356 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6357
6358 \end_inset 
6359
6360 \SpecialChar ~
6361 <Value> By default the stack
6362 \begin_inset LatexCommand \index{stack}
6363
6364 \end_inset 
6365
6366  is placed after the data segment.
6367  Using this option the stack can be placed anywhere in the internal memory
6368  space of the 8051.
6369  The value entered can be in Hexadecimal or Decimal format, e.g.
6370  -
6371 \begin_inset ERT
6372 status Collapsed
6373
6374 \layout Standard
6375
6376 \backslash 
6377 /
6378 \end_inset 
6379
6380 -stack-loc 0x20 or -
6381 \begin_inset ERT
6382 status Collapsed
6383
6384 \layout Standard
6385
6386 \backslash 
6387 /
6388 \end_inset 
6389
6390 -stack-loc 32.
6391  Since the sp register is incremented before a push or call, the initial
6392  sp will be set to one byte prior the provided value.
6393  The provided value should not overlap any other memory areas such as used
6394  register banks or the data segment and with enough space for the current
6395  application.
6396  The 
6397 \series bold 
6398 -
6399 \begin_inset ERT
6400 status Collapsed
6401
6402 \layout Standard
6403
6404 \backslash 
6405 /
6406 \end_inset 
6407
6408 -pack-iram
6409 \series default 
6410 \SpecialChar ~
6411
6412 \begin_inset LatexCommand \index{-\/-pack-iram}
6413
6414 \end_inset 
6415
6416  option (which is now a default setting) will override this setting, so
6417  you should also specify the 
6418 \series bold 
6419 -
6420 \begin_inset ERT
6421 status Collapsed
6422
6423 \layout Standard
6424
6425 \backslash 
6426 /
6427 \end_inset 
6428
6429 -no-pack-iram
6430 \series default 
6431 \SpecialChar ~
6432
6433 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6434
6435 \end_inset 
6436
6437  option if you need to manually place the stack.
6438 \layout List
6439 \labelwidthstring 00.00.0000
6440
6441
6442 \series bold 
6443 -
6444 \begin_inset ERT
6445 status Collapsed
6446
6447 \layout Standard
6448
6449 \backslash 
6450 /
6451 \end_inset 
6452
6453 -xstack-loc
6454 \series default 
6455
6456 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6457
6458 \end_inset 
6459
6460 \SpecialChar ~
6461 <Value> By default the external stack
6462 \begin_inset LatexCommand \index{xstack}
6463
6464 \end_inset 
6465
6466  is placed after the pdata
6467 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6468
6469 \end_inset 
6470
6471  segment.
6472  Using this option the xstack can be placed anywhere in the external memory
6473  space of the 8051.
6474  The value entered can be in Hexadecimal or Decimal format, e.g.
6475  -
6476 \begin_inset ERT
6477 status Collapsed
6478
6479 \layout Standard
6480
6481 \backslash 
6482 /
6483 \end_inset 
6484
6485 -xstack-loc 0x8000 or -
6486 \begin_inset ERT
6487 status Collapsed
6488
6489 \layout Standard
6490
6491 \backslash 
6492 /
6493 \end_inset 
6494
6495 -stack-loc 32768.
6496  The provided value should not overlap any other memory areas such as the
6497  pdata or xdata segment and with enough space for the current application.
6498 \layout List
6499 \labelwidthstring 00.00.0000
6500
6501
6502 \series bold 
6503 -
6504 \begin_inset ERT
6505 status Collapsed
6506
6507 \layout Standard
6508
6509 \backslash 
6510 /
6511 \end_inset 
6512
6513 -data-loc
6514 \series default 
6515
6516 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6517
6518 \end_inset 
6519
6520 \SpecialChar ~
6521 <Value> The start location of the internal ram data
6522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6523
6524 \end_inset 
6525
6526  segment.
6527  The value entered can be in Hexadecimal or Decimal format, eg.
6528  -
6529 \begin_inset ERT
6530 status Collapsed
6531
6532 \layout Standard
6533
6534 \backslash 
6535 /
6536 \end_inset 
6537
6538 -data-loc 0x20 or -
6539 \begin_inset ERT
6540 status Collapsed
6541
6542 \layout Standard
6543
6544 \backslash 
6545 /
6546 \end_inset 
6547
6548 -data-loc 32.
6549  (By default, the start location of the internal ram data segment  is set
6550  as low as possible in memory, taking into account the used register banks
6551  and the bit segment at address 0x20.
6552  For example if register banks 0 and 1 are used without bit variables, the
6553  data segment will be set, if -
6554 \begin_inset ERT
6555 status Collapsed
6556
6557 \layout Standard
6558
6559 \backslash 
6560 /
6561 \end_inset 
6562
6563 -data-loc is not used, to location 0x10.)
6564 \layout List
6565 \labelwidthstring 00.00.0000
6566
6567
6568 \series bold 
6569 -
6570 \begin_inset ERT
6571 status Collapsed
6572
6573 \layout Standard
6574
6575 \backslash 
6576 /
6577 \end_inset 
6578
6579 -idata-loc
6580 \series default 
6581
6582 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6583
6584 \end_inset 
6585
6586 \SpecialChar ~
6587 <Value> The start location of the indirectly addressable internal ram
6588 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6589
6590 \end_inset 
6591
6592  of the 8051, default value is 0x80.
6593  The value entered can be in Hexadecimal or Decimal format, eg.
6594  -
6595 \begin_inset ERT
6596 status Collapsed
6597
6598 \layout Standard
6599
6600 \backslash 
6601 /
6602 \end_inset 
6603
6604 -idata-loc 0x88 or -
6605 \begin_inset ERT
6606 status Collapsed
6607
6608 \layout Standard
6609
6610 \backslash 
6611 /
6612 \end_inset 
6613
6614 -idata-loc 136.
6615 \layout List
6616 \labelwidthstring 00.00.0000
6617
6618
6619 \series bold 
6620 -
6621 \begin_inset ERT
6622 status Collapsed
6623
6624 \layout Standard
6625
6626 \backslash 
6627 /
6628 \end_inset 
6629
6630 -bit-loc
6631 \series default 
6632 \SpecialChar ~
6633 <Value> The start location of the bit
6634 \begin_inset LatexCommand \index{bit}
6635
6636 \end_inset 
6637
6638  addressable internal ram of the 8051.
6639  This is 
6640 \emph on 
6641 not
6642 \emph default 
6643  implemented yet.
6644  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6645 -bBSEG=<Value>.
6646 \layout List
6647 \labelwidthstring 00.00.0000
6648
6649
6650 \series bold 
6651 -
6652 \begin_inset ERT
6653 status Collapsed
6654
6655 \layout Standard
6656
6657 \backslash 
6658 /
6659 \end_inset 
6660
6661 -out-fmt-ihx
6662 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6663
6664 \end_inset 
6665
6666
6667 \bar under 
6668  
6669 \series default 
6670 \bar default 
6671 The linker output (final object code) is in Intel Hex format.
6672 \begin_inset LatexCommand \index{Intel hex format}
6673
6674 \end_inset 
6675
6676  This is the default option.
6677  The format itself is documented in the documentation of srecord
6678 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6679
6680 \end_inset 
6681
6682 .
6683 \layout List
6684 \labelwidthstring 00.00.0000
6685
6686
6687 \series bold 
6688 -
6689 \begin_inset ERT
6690 status Collapsed
6691
6692 \layout Standard
6693
6694 \backslash 
6695 /
6696 \end_inset 
6697
6698 -out-fmt-s19
6699 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6700
6701 \end_inset 
6702
6703
6704 \bar under 
6705  
6706 \series default 
6707 \bar default 
6708 The linker output (final object code) is in Motorola S19 format
6709 \begin_inset LatexCommand \index{Motorola S19 format}
6710
6711 \end_inset 
6712
6713 .
6714  The format itself is documented in the documentation of srecord.
6715 \layout List
6716 \labelwidthstring 00.00.0000
6717
6718
6719 \series bold 
6720 -
6721 \begin_inset ERT
6722 status Collapsed
6723
6724 \layout Standard
6725
6726 \backslash 
6727 /
6728 \end_inset 
6729
6730 -out-fmt-elf
6731 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6732
6733 \end_inset 
6734
6735
6736 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6737
6738 \end_inset 
6739
6740
6741 \bar under 
6742  
6743 \series default 
6744 \bar default 
6745 The linker output (final object code) is in ELF format
6746 \begin_inset LatexCommand \index{ELF format}
6747
6748 \end_inset 
6749
6750 .
6751  (Currently only supported for the HC08
6752 \begin_inset LatexCommand \index{HC08}
6753
6754 \end_inset 
6755
6756  processors)
6757 \layout List
6758 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6759
6760
6761 \series bold 
6762 -Wl\SpecialChar ~
6763 linkOption[,linkOption]
6764 \series default 
6765
6766 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6767
6768 \end_inset 
6769
6770 ...
6771  Pass the linkOption to the linker.
6772  If a bootloader is used an option like 
6773 \begin_inset Quotes sld
6774 \end_inset 
6775
6776 -Wl\SpecialChar ~
6777 -bCSEG=0x1000
6778 \begin_inset Quotes srd
6779 \end_inset 
6780
6781  would be typical to set the start of the code segment.
6782  See also #pragma constseg and #pragma codeseg in section 
6783 \begin_inset LatexCommand \ref{sec:Pragmas}
6784
6785 \end_inset 
6786
6787  .
6788  File sdcc/as/doc/asxhtm.html has more on linker options.
6789 \layout Subsection
6790
6791 MCS51 Options
6792 \begin_inset LatexCommand \index{Options MCS51}
6793
6794 \end_inset 
6795
6796
6797 \begin_inset LatexCommand \index{MCS51 options}
6798
6799 \end_inset 
6800
6801
6802 \layout List
6803 \labelwidthstring 00.00.0000
6804
6805
6806 \series bold 
6807 -
6808 \begin_inset ERT
6809 status Collapsed
6810
6811 \layout Standard
6812
6813 \backslash 
6814 /
6815 \end_inset 
6816
6817 -model-small
6818 \begin_inset LatexCommand \index{-\/-model-small}
6819
6820 \end_inset 
6821
6822
6823 \series default 
6824 \size large 
6825 \emph on 
6826  
6827 \size default 
6828 \emph default 
6829 Generate code for Small Model programs, see section Memory Models for more
6830  details.
6831  This is the default model.
6832 \layout List
6833 \labelwidthstring 00.00.0000
6834
6835
6836 \series bold 
6837 -
6838 \begin_inset ERT
6839 status Collapsed
6840
6841 \layout Standard
6842
6843 \backslash 
6844 /
6845 \end_inset 
6846
6847 -model-medium
6848 \begin_inset LatexCommand \index{-\/-model-medium}
6849
6850 \end_inset 
6851
6852
6853 \series default 
6854  Generate code for Medium model programs, see section Memory Models for
6855  more details.
6856  If this option is used all source files in the project have to be compiled
6857  with this option.
6858  It must also be used when invoking the linker.
6859 \layout List
6860 \labelwidthstring 00.00.0000
6861
6862
6863 \series bold 
6864 -
6865 \begin_inset ERT
6866 status Collapsed
6867
6868 \layout Standard
6869
6870 \backslash 
6871 /
6872 \end_inset 
6873
6874 -model-large
6875 \begin_inset LatexCommand \index{-\/-model-large}
6876
6877 \end_inset 
6878
6879
6880 \series default 
6881  Generate code for Large model programs, see section Memory Models for more
6882  details.
6883  If this option is used all source files in the project have to be compiled
6884  with this option.
6885  It must also be used when invoking the linker.
6886 \layout List
6887 \labelwidthstring 00.00.0000
6888
6889
6890 \series bold 
6891 -
6892 \begin_inset ERT
6893 status Collapsed
6894
6895 \layout Standard
6896
6897 \backslash 
6898 /
6899 \end_inset 
6900
6901 -xstack
6902 \begin_inset LatexCommand \index{-\/-xstack}
6903
6904 \end_inset 
6905
6906
6907 \series default 
6908  Uses a pseudo stack in the pdata
6909 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6910
6911 \end_inset 
6912
6913  area (usually the first 256 bytes in the external ram) for allocating variables
6914  and passing parameters.
6915  See section 
6916 \begin_inset LatexCommand \ref{sub:External-Stack}
6917
6918 \end_inset 
6919
6920 \SpecialChar ~
6921  External Stack for more details.
6922 \layout List
6923 \labelwidthstring 00.00.0000
6924
6925
6926 \series bold 
6927 -
6928 \begin_inset ERT
6929 status Collapsed
6930
6931 \layout Standard
6932
6933 \backslash 
6934 /
6935 \end_inset 
6936
6937 -iram-size
6938 \series default 
6939 \SpecialChar ~
6940 <Value>
6941 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6942
6943 \end_inset 
6944
6945  Causes the linker to check if the internal ram usage is within limits of
6946  the given value.
6947 \layout List
6948 \labelwidthstring 00.00.0000
6949
6950
6951 \series bold 
6952 -
6953 \begin_inset ERT
6954 status Collapsed
6955
6956 \layout Standard
6957
6958 \backslash 
6959 /
6960 \end_inset 
6961
6962 -xram-size
6963 \series default 
6964 \SpecialChar ~
6965 <Value>
6966 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6967
6968 \end_inset 
6969
6970  Causes the linker to check if the external ram usage is within limits of
6971  the given value.
6972 \layout List
6973 \labelwidthstring 00.00.0000
6974
6975
6976 \series bold 
6977 -
6978 \begin_inset ERT
6979 status Collapsed
6980
6981 \layout Standard
6982
6983 \backslash 
6984 /
6985 \end_inset 
6986
6987 -code-size
6988 \series default 
6989 \SpecialChar ~
6990 <Value>
6991 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6992
6993 \end_inset 
6994
6995  Causes the linker to check if the code memory usage is within limits of
6996  the given value.
6997 \layout List
6998 \labelwidthstring 00.00.0000
6999
7000
7001 \series bold 
7002 -
7003 \begin_inset ERT
7004 status Collapsed
7005
7006 \layout Standard
7007
7008 \backslash 
7009 /
7010 \end_inset 
7011
7012 -stack-size
7013 \series default 
7014 \SpecialChar ~
7015 <Value>
7016 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7017
7018 \end_inset 
7019
7020  Causes the linker to check if there is at minimum <Value> bytes for stack.
7021 \layout List
7022 \labelwidthstring 00.00.0000
7023
7024
7025 \series bold 
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032 \backslash 
7033 /
7034 \end_inset 
7035
7036 -pack-iram
7037 \series default 
7038 \SpecialChar ~
7039
7040 \begin_inset LatexCommand \index{-\/-pack-iram}
7041
7042 \end_inset 
7043
7044  Causes the linker to use unused register banks for data variables and pack
7045  data, idata and stack together.
7046  This is the default now.
7047 \layout List
7048 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7049
7050
7051 \series bold 
7052 -
7053 \begin_inset ERT
7054 status Collapsed
7055
7056 \layout Standard
7057
7058 \backslash 
7059 /
7060 \end_inset 
7061
7062 -no-pack-iram
7063 \series default 
7064 \SpecialChar ~
7065
7066 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7067
7068 \end_inset 
7069
7070  Causes the linker to use old style for allocating memory areas.
7071 \layout Subsection
7072
7073 DS390 / DS400 Options
7074 \begin_inset LatexCommand \index{Options DS390}
7075
7076 \end_inset 
7077
7078
7079 \begin_inset LatexCommand \index{DS390}
7080
7081 \end_inset 
7082
7083
7084 \layout List
7085 \labelwidthstring 00.00.0000
7086
7087
7088 \series bold 
7089 -
7090 \begin_inset ERT
7091 status Collapsed
7092
7093 \layout Standard
7094
7095 \backslash 
7096 /
7097 \end_inset 
7098
7099 -model-flat24
7100 \series default 
7101
7102 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7103
7104 \end_inset 
7105
7106
7107 \size large 
7108 \emph on 
7109  
7110 \size default 
7111 \emph default 
7112 Generate 24-bit flat mode code.
7113  This is the one and only that the ds390 code generator supports right now
7114  and is default when using 
7115 \emph on 
7116 -mds390
7117 \emph default 
7118 .
7119  See section Memory Models for more details.
7120 \layout List
7121 \labelwidthstring 00.00.0000
7122
7123
7124 \series bold 
7125 -
7126 \begin_inset ERT
7127 status Collapsed
7128
7129 \layout Standard
7130
7131 \backslash 
7132 /
7133 \end_inset 
7134
7135 -protect-sp-update
7136 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7137
7138 \end_inset 
7139
7140
7141 \series default 
7142  disable interrupts during ESP:SP updates.
7143 \layout List
7144 \labelwidthstring 00.00.0000
7145
7146
7147 \series bold 
7148 -
7149 \begin_inset ERT
7150 status Collapsed
7151
7152 \layout Standard
7153
7154 \backslash 
7155 /
7156 \end_inset 
7157
7158 -stack-10bit
7159 \series default 
7160
7161 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7162
7163 \end_inset 
7164
7165  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7166  This is the one and only that the ds390 code generator supports right now
7167  and is default when using 
7168 \emph on 
7169 -mds390
7170 \emph default 
7171 .
7172  In this mode, the stack is located in the lower 1K of the internal RAM,
7173  which is mapped to 0x400000.
7174  Note that the support is incomplete, since it still uses a single byte
7175  as the stack pointer.
7176  This means that only the lower 256 bytes of the potential 1K stack space
7177  will actually be used.
7178  However, this does allow you to reclaim the precious 256 bytes of low RAM
7179  for use for the DATA and IDATA segments.
7180  The compiler will not generate any code to put the processor into 10 bit
7181  stack mode.
7182  It is important to ensure that the processor is in this mode before calling
7183  any re-entrant functions compiled with this option.
7184  In principle, this should work with the 
7185 \emph on 
7186 -
7187 \begin_inset ERT
7188 status Collapsed
7189
7190 \layout Standard
7191
7192 \backslash 
7193 /
7194 \end_inset 
7195
7196 -stack-auto
7197 \begin_inset LatexCommand \index{-\/-stack-auto}
7198
7199 \end_inset 
7200
7201
7202 \emph default 
7203  option, but that has not been tested.
7204  It is incompatible with the 
7205 \emph on 
7206 -
7207 \begin_inset ERT
7208 status Collapsed
7209
7210 \layout Standard
7211
7212 \backslash 
7213 /
7214 \end_inset 
7215
7216 -xstack
7217 \begin_inset LatexCommand \index{-\/-xstack}
7218
7219 \end_inset 
7220
7221
7222 \emph default 
7223  option.
7224  It also only makes sense if the processor is in 24 bit contiguous addressing
7225  mode (see the 
7226 \emph on 
7227 -
7228 \begin_inset ERT
7229 status Collapsed
7230
7231 \layout Standard
7232
7233 \backslash 
7234 /
7235 \end_inset 
7236
7237 -model-flat24 option
7238 \emph default 
7239 ).
7240 \layout List
7241 \labelwidthstring 00.00.0000
7242
7243
7244 \series bold 
7245 -
7246 \begin_inset ERT
7247 status Collapsed
7248
7249 \layout Standard
7250
7251 \backslash 
7252 /
7253 \end_inset 
7254
7255 -stack-probe
7256 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7257
7258 \end_inset 
7259
7260
7261 \series default 
7262  insert call to function __stack_probe at each function prologue.
7263 \layout List
7264 \labelwidthstring 00.00.0000
7265
7266
7267 \series bold 
7268 -
7269 \begin_inset ERT
7270 status Collapsed
7271
7272 \layout Standard
7273
7274 \backslash 
7275 /
7276 \end_inset 
7277
7278 -tini-libid
7279 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7280
7281 \end_inset 
7282
7283
7284 \series default 
7285  <nnnn> LibraryID used in -mTININative.
7286  
7287 \layout List
7288 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7289
7290
7291 \series bold 
7292 -
7293 \begin_inset ERT
7294 status Collapsed
7295
7296 \layout Standard
7297
7298 \backslash 
7299 /
7300 \end_inset 
7301
7302 -use-accelerator
7303 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7304
7305 \end_inset 
7306
7307
7308 \series default 
7309  generate code for DS390 Arithmetic Accelerator.
7310  
7311 \layout Subsection
7312
7313 Z80 Options
7314 \begin_inset LatexCommand \index{Options Z80}
7315
7316 \end_inset 
7317
7318
7319 \begin_inset LatexCommand \index{Z80}
7320
7321 \end_inset 
7322
7323
7324 \layout List
7325 \labelwidthstring 00.00.0000
7326
7327
7328 \series bold 
7329 -
7330 \begin_inset ERT
7331 status Collapsed
7332
7333 \layout Standard
7334
7335 \backslash 
7336 /
7337 \end_inset 
7338
7339 -callee-saves-bc
7340 \series default 
7341
7342 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7343
7344 \end_inset 
7345
7346
7347 \size large 
7348 \emph on 
7349  
7350 \size default 
7351 \emph default 
7352 Force a called function to always save BC.
7353 \layout List
7354 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7355
7356
7357 \series bold 
7358 -
7359 \begin_inset ERT
7360 status Collapsed
7361
7362 \layout Standard
7363
7364 \backslash 
7365 /
7366 \end_inset 
7367
7368 -no-std-crt0
7369 \series default 
7370
7371 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7372
7373 \end_inset 
7374
7375  When linking, skip the standard crt0.o object file.
7376  You must provide your own crt0.o for your system when linking.
7377  
7378 \layout Subsection
7379
7380 Optimization Options
7381 \begin_inset LatexCommand \index{Options optimization}
7382
7383 \end_inset 
7384
7385
7386 \begin_inset LatexCommand \index{Optimization options}
7387
7388 \end_inset 
7389
7390
7391 \layout List
7392 \labelwidthstring 00.00.0000
7393
7394
7395 \series bold 
7396 -
7397 \begin_inset ERT
7398 status Collapsed
7399
7400 \layout Standard
7401
7402 \backslash 
7403 /
7404 \end_inset 
7405
7406 -nogcse
7407 \begin_inset LatexCommand \index{-\/-nogcse}
7408
7409 \end_inset 
7410
7411
7412 \series default 
7413  Will not do global subexpression elimination, this option may be used when
7414  the compiler creates undesirably large stack/data spaces to store compiler
7415  temporaries (
7416 \emph on 
7417 s
7418 \emph default 
7419 pill 
7420 \emph on 
7421 loc
7422 \emph default 
7423 ations, sloc
7424 \begin_inset LatexCommand \index{sloc (spill location)}
7425
7426 \end_inset 
7427
7428 ).
7429  A warning message will be generated when this happens and the compiler
7430  will indicate the number of extra bytes it allocated.
7431  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7432 nogcse
7433 \begin_inset LatexCommand \index{\#pragma nogcse}
7434
7435 \end_inset 
7436
7437  can be used to turn off global subexpression elimination
7438 \begin_inset LatexCommand \index{Subexpression elimination}
7439
7440 \end_inset 
7441
7442  for a given function only.
7443 \layout List
7444 \labelwidthstring 00.00.0000
7445
7446
7447 \series bold 
7448 -
7449 \begin_inset ERT
7450 status Collapsed
7451
7452 \layout Standard
7453
7454 \backslash 
7455 /
7456 \end_inset 
7457
7458 -noinvariant
7459 \begin_inset LatexCommand \index{-\/-noinvariant}
7460
7461 \end_inset 
7462
7463
7464 \series default 
7465  Will not do loop invariant optimizations, this may be turned off for reasons
7466  explained for the previous option.
7467  For more details of loop optimizations performed see Loop Invariants in
7468  section 
7469 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7470
7471 \end_inset 
7472
7473 .
7474  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7475 noinvariant
7476 \begin_inset LatexCommand \index{\#pragma noinvariant}
7477
7478 \end_inset 
7479
7480  can be used to turn off invariant optimizations for a given function only.
7481 \layout List
7482 \labelwidthstring 00.00.0000
7483
7484
7485 \series bold 
7486 -
7487 \begin_inset ERT
7488 status Collapsed
7489
7490 \layout Standard
7491
7492 \backslash 
7493 /
7494 \end_inset 
7495
7496 -noinduction
7497 \begin_inset LatexCommand \index{-\/-noinduction}
7498
7499 \end_inset 
7500
7501
7502 \series default 
7503  Will not do loop induction optimizations, see section strength reduction
7504  for more details.
7505  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7506 noinduction
7507 \begin_inset LatexCommand \index{\#pragma noinduction}
7508
7509 \end_inset 
7510
7511  can be used to turn off induction optimizations for a given function only.
7512 \layout List
7513 \labelwidthstring 00.00.0000
7514
7515
7516 \series bold 
7517 -
7518 \begin_inset ERT
7519 status Collapsed
7520
7521 \layout Standard
7522
7523 \backslash 
7524 /
7525 \end_inset 
7526
7527 -nojtbound
7528 \begin_inset LatexCommand \index{-\/-nojtbound}
7529
7530 \end_inset 
7531
7532
7533 \size large 
7534 \bar under 
7535  
7536 \series default 
7537 \size default 
7538 \bar default 
7539  Will not generate boundary condition check when switch statements
7540 \begin_inset LatexCommand \index{switch statement}
7541
7542 \end_inset 
7543
7544  are implemented using jump-tables.
7545  See section 
7546 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7547
7548 \end_inset 
7549
7550 \SpecialChar ~
7551 Switch Statements for more details.
7552  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7553 nojtbound
7554 \begin_inset LatexCommand \index{\#pragma nojtbound}
7555
7556 \end_inset 
7557
7558  can be used to turn off boundary checking for jump tables for a given function
7559  only.
7560 \layout List
7561 \labelwidthstring 00.00.0000
7562
7563
7564 \series bold 
7565 -
7566 \begin_inset ERT
7567 status Collapsed
7568
7569 \layout Standard
7570
7571 \backslash 
7572 /
7573 \end_inset 
7574
7575 -noloopreverse
7576 \begin_inset LatexCommand \index{-\/-noloopreverse}
7577
7578 \end_inset 
7579
7580
7581 \series default 
7582 \size large 
7583  
7584 \size default 
7585 Will not do loop reversal 
7586 \begin_inset LatexCommand \index{Loop reversing}
7587
7588 \end_inset 
7589
7590 optimization.
7591 \layout List
7592 \labelwidthstring 00.00.0000
7593
7594 -
7595 \begin_inset ERT
7596 status Collapsed
7597
7598 \layout Standard
7599
7600 \backslash 
7601 /
7602 \end_inset 
7603
7604 -
7605 \series bold 
7606 nolabelopt
7607 \series default 
7608  
7609 \begin_inset LatexCommand \index{-\/-nolabelopt }
7610
7611 \end_inset 
7612
7613 Will not optimize labels (makes the dumpfiles more readable).
7614 \layout List
7615 \labelwidthstring 00.00.0000
7616
7617
7618 \series bold 
7619 -
7620 \begin_inset ERT
7621 status Collapsed
7622
7623 \layout Standard
7624
7625 \backslash 
7626 /
7627 \end_inset 
7628
7629 -no-xinit-opt
7630 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7631
7632 \end_inset 
7633
7634
7635 \series default 
7636  Will not memcpy initialized data from code space into xdata space.
7637  This saves a few bytes in code space if you don't have initialized data
7638 \begin_inset LatexCommand \index{Variable initialization}
7639
7640 \end_inset 
7641
7642 .
7643 \layout List
7644 \labelwidthstring 00.00.0000
7645
7646
7647 \series bold 
7648 -
7649 \begin_inset ERT
7650 status Collapsed
7651
7652 \layout Standard
7653
7654 \backslash 
7655 /
7656 \end_inset 
7657
7658 -nooverlay
7659 \begin_inset LatexCommand \index{-\/-nooverlay}
7660
7661 \end_inset 
7662
7663
7664 \series default 
7665   The compiler will not overlay parameters and local variables of any function,
7666  see section Parameters and local variables for more details.
7667 \layout List
7668 \labelwidthstring 00.00.0000
7669
7670
7671 \series bold 
7672 -
7673 \begin_inset ERT
7674 status Collapsed
7675
7676 \layout Standard
7677
7678 \backslash 
7679 /
7680 \end_inset 
7681
7682 -no-peep
7683 \begin_inset LatexCommand \index{-\/-no-peep}
7684
7685 \end_inset 
7686
7687
7688 \series default 
7689  Disable peep-hole optimization with built-in rules.
7690 \layout List
7691 \labelwidthstring 00.00.0000
7692
7693
7694 \series bold 
7695 -
7696 \begin_inset ERT
7697 status Collapsed
7698
7699 \layout Standard
7700
7701 \backslash 
7702 /
7703 \end_inset 
7704
7705 -peep-file
7706 \series default 
7707
7708 \begin_inset LatexCommand \index{-\/-peep-file}
7709
7710 \end_inset 
7711
7712 \SpecialChar ~
7713 <filename> This option can be used to use additional rules to be used by
7714  the peep hole optimizer.
7715  See section 
7716 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7717
7718 \end_inset 
7719
7720 \SpecialChar ~
7721 Peep Hole optimizations for details on how to write these rules.
7722 \layout List
7723 \labelwidthstring 00.00.0000
7724
7725
7726 \series bold 
7727 -
7728 \begin_inset ERT
7729 status Collapsed
7730
7731 \layout Standard
7732
7733 \backslash 
7734 /
7735 \end_inset 
7736
7737 -peep-asm
7738 \begin_inset LatexCommand \index{-\/-peep-asm}
7739
7740 \end_inset 
7741
7742
7743 \series default 
7744  Pass the inline assembler code through the peep hole optimizer.
7745  This can cause unexpected changes to inline assembler code, please go through
7746  the peephole optimizer
7747 \begin_inset LatexCommand \index{Peephole optimizer}
7748
7749 \end_inset 
7750
7751  rules defined in the source file tree '<target>/peeph.def' before using
7752  this option.
7753 \layout List
7754 \labelwidthstring 00.00.0000
7755
7756
7757 \series bold 
7758 -
7759 \begin_inset ERT
7760 status Collapsed
7761
7762 \layout Standard
7763
7764 \backslash 
7765 /
7766 \end_inset 
7767
7768 -opt-code-speed
7769 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7770
7771 \end_inset 
7772
7773
7774 \series default 
7775  The compiler will optimize code generation towards fast code, possibly
7776  at the expense of code size.
7777 \layout List
7778 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7779
7780
7781 \series bold 
7782 -
7783 \begin_inset ERT
7784 status Collapsed
7785
7786 \layout Standard
7787
7788 \backslash 
7789 /
7790 \end_inset 
7791
7792 -opt-code-size
7793 \begin_inset LatexCommand \index{-\/-opt-code-size}
7794
7795 \end_inset 
7796
7797
7798 \series default 
7799  The compiler will optimize code generation towards compact code, possibly
7800  at the expense of code speed.
7801 \layout Subsection
7802
7803 Other Options
7804 \begin_inset LatexCommand \index{Options other}
7805
7806 \end_inset 
7807
7808
7809 \layout List
7810 \labelwidthstring 00.00.0000
7811
7812
7813 \series bold 
7814 -c\SpecialChar ~
7815 -
7816 \begin_inset ERT
7817 status Collapsed
7818
7819 \layout Standard
7820
7821 \backslash 
7822 /
7823 \end_inset 
7824
7825 -compile-only
7826 \begin_inset LatexCommand \index{-\/-compile-only}
7827
7828 \end_inset 
7829
7830
7831 \begin_inset LatexCommand \index{-c -\/-compile-only}
7832
7833 \end_inset 
7834
7835
7836 \series default 
7837  will compile and assemble the source, but will not call the linkage editor.
7838 \layout List
7839 \labelwidthstring 00.00.0000
7840
7841
7842 \series bold 
7843 -
7844 \series default 
7845
7846 \begin_inset ERT
7847 status Collapsed
7848
7849 \layout Standard
7850
7851 \backslash 
7852 /
7853 \end_inset 
7854
7855
7856 \series bold 
7857 -c1mode
7858 \begin_inset LatexCommand \index{-\/-c1mode}
7859
7860 \end_inset 
7861
7862
7863 \series default 
7864  reads the preprocessed source from standard input and compiles it.
7865  The file name for the assembler output must be specified using the -o option.
7866 \layout List
7867 \labelwidthstring 00.00.0000
7868
7869
7870 \series bold 
7871 -E
7872 \begin_inset LatexCommand \index{-E}
7873
7874 \end_inset 
7875
7876
7877 \series default 
7878  Run only the C preprocessor.
7879  Preprocess all the C source files specified and output the results to standard
7880  output.
7881 \layout List
7882 \labelwidthstring 00.00.0000
7883
7884
7885 \series bold 
7886 -o\SpecialChar ~
7887 <path/file>
7888 \begin_inset LatexCommand \index{-o <path/file>}
7889
7890 \end_inset 
7891
7892  
7893 \series default 
7894 The output path resp.
7895  file where everything will be placed.
7896  If the parameter is a path, it must have a trailing slash (or backslash
7897  for the Windows binaries) to be recognized as a path.
7898  
7899 \layout List
7900 \labelwidthstring 00.00.0000
7901
7902
7903 \series bold 
7904 -
7905 \begin_inset ERT
7906 status Collapsed
7907
7908 \layout Standard
7909
7910 \backslash 
7911 /
7912 \end_inset 
7913
7914 -stack-auto
7915 \begin_inset LatexCommand \index{-\/-stack-auto}
7916
7917 \end_inset 
7918
7919
7920 \series default 
7921 \size large 
7922 \emph on 
7923  
7924 \size default 
7925 \emph default 
7926 All functions in the source file will be compiled as 
7927 \emph on 
7928 reentrant
7929 \emph default 
7930
7931 \begin_inset LatexCommand \index{reentrant}
7932
7933 \end_inset 
7934
7935 , i.e.
7936  the parameters and local variables will be allocated on the stack
7937 \begin_inset LatexCommand \index{stack}
7938
7939 \end_inset 
7940
7941 .
7942  See section 
7943 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7944
7945 \end_inset 
7946
7947  Parameters and Local Variables for more details.
7948  If this option is used all source files in the project should be compiled
7949  with this option.
7950  It automatically implies --int-long-reent and --float-reent.
7951  
7952 \layout List
7953 \labelwidthstring 00.00.0000
7954
7955
7956 \series bold 
7957 -
7958 \begin_inset ERT
7959 status Collapsed
7960
7961 \layout Standard
7962
7963 \backslash 
7964 /
7965 \end_inset 
7966
7967 -callee-saves
7968 \begin_inset LatexCommand \index{-\/-callee-saves}
7969
7970 \end_inset 
7971
7972  function1[,function2][,function3]....
7973
7974 \series default 
7975  The compiler by default uses a caller saves convention for register saving
7976  across function calls, however this can cause unnecessary register pushing
7977  & popping when calling small functions from larger functions.
7978  This option can be used to switch the register saving convention for the
7979  function names specified.
7980  The compiler will not save registers when calling these functions, no extra
7981  code will be generated at the entry & exit (function prologue
7982 \series bold 
7983
7984 \begin_inset LatexCommand \index{function prologue}
7985
7986 \end_inset 
7987
7988
7989 \series default 
7990  & epilogue
7991 \series bold 
7992
7993 \begin_inset LatexCommand \index{function epilogue}
7994
7995 \end_inset 
7996
7997
7998 \series default 
7999 ) for these functions to save & restore the registers used by these functions,
8000  this can SUBSTANTIALLY reduce code & improve run time performance of the
8001  generated code.
8002  In the future the compiler (with inter procedural analysis) will be able
8003  to determine the appropriate scheme to use for each function call.
8004  DO NOT use this option for built-in functions such as _mulint..., if this
8005  option is used for a library function the appropriate library function
8006  needs to be recompiled with the same option.
8007  If the project consists of multiple source files then all the source file
8008  should be compiled with the same -
8009 \begin_inset ERT
8010 status Collapsed
8011
8012 \layout Standard
8013
8014 \backslash 
8015 /
8016 \end_inset 
8017
8018 -callee-saves option string.
8019  Also see #pragma\SpecialChar ~
8020 callee_saves
8021 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8022
8023 \end_inset 
8024
8025 .
8026 \layout List
8027 \labelwidthstring 00.00.0000
8028
8029
8030 \series bold 
8031 -
8032 \begin_inset ERT
8033 status Collapsed
8034
8035 \layout Standard
8036
8037 \backslash 
8038 /
8039 \end_inset 
8040
8041 -debug
8042 \begin_inset LatexCommand \index{-\/-debug}
8043
8044 \end_inset 
8045
8046
8047 \bar under 
8048  
8049 \series default 
8050 \bar default 
8051 When this option is used the compiler will generate debug information.
8052  The debug information collected in a file with .cdb extension can be used
8053  with the SDCDB.
8054  For more information see documentation for SDCDB.
8055  Another file with no extension contains debug information in AOMF or AOMF51
8056 \begin_inset LatexCommand \index{AOMF, AOMF51}
8057
8058 \end_inset 
8059
8060  format which is commonly used by third party tools.
8061 \layout List
8062 \labelwidthstring 00.00.0000
8063
8064
8065 \series bold 
8066 -S
8067 \begin_inset LatexCommand \index{-S}
8068
8069 \end_inset 
8070
8071
8072 \size large 
8073 \bar under 
8074  
8075 \series default 
8076 \size default 
8077 \bar default 
8078 Stop after the stage of compilation proper; do not assemble.
8079  The output is an assembler code file for the input file specified.
8080 \layout List
8081 \labelwidthstring 00.00.0000
8082
8083
8084 \series bold 
8085 -
8086 \begin_inset ERT
8087 status Collapsed
8088
8089 \layout Standard
8090
8091 \backslash 
8092 /
8093 \end_inset 
8094
8095 -int-long-reent
8096 \begin_inset LatexCommand \index{-\/-int-long-reent}
8097
8098 \end_inset 
8099
8100
8101 \series default 
8102  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8103  Note by default these libraries are compiled as non-reentrant.
8104  See section Installation for more details.
8105 \layout List
8106 \labelwidthstring 00.00.0000
8107
8108
8109 \series bold 
8110 -
8111 \begin_inset ERT
8112 status Collapsed
8113
8114 \layout Standard
8115
8116 \backslash 
8117 /
8118 \end_inset 
8119
8120 -cyclomatic
8121 \begin_inset LatexCommand \index{-\/-cyclomatic}
8122
8123 \end_inset 
8124
8125
8126 \bar under 
8127  
8128 \series default 
8129 \bar default 
8130 This option will cause the compiler to generate an information message for
8131  each function in the source file.
8132  The message contains some 
8133 \emph on 
8134 important
8135 \emph default 
8136  information about the function.
8137  The number of edges and nodes the compiler detected in the control flow
8138  graph of the function, and most importantly the 
8139 \emph on 
8140 cyclomatic complexity
8141 \begin_inset LatexCommand \index{Cyclomatic complexity}
8142
8143 \end_inset 
8144
8145
8146 \emph default 
8147  see section on Cyclomatic Complexity for more details.
8148 \layout List
8149 \labelwidthstring 00.00.0000
8150
8151
8152 \series bold 
8153 -
8154 \begin_inset ERT
8155 status Collapsed
8156
8157 \layout Standard
8158
8159 \backslash 
8160 /
8161 \end_inset 
8162
8163 -float-reent
8164 \begin_inset LatexCommand \index{-\/-float-reent}
8165
8166 \end_inset 
8167
8168
8169 \series default 
8170  Floating point library is compiled as reentrant
8171 \begin_inset LatexCommand \index{reentrant}
8172
8173 \end_inset 
8174
8175 .
8176  See section Installation for more details.
8177 \layout List
8178 \labelwidthstring 00.00.0000
8179
8180
8181 \series bold 
8182 -
8183 \begin_inset ERT
8184 status Collapsed
8185
8186 \layout Standard
8187
8188 \backslash 
8189 /
8190 \end_inset 
8191
8192 -main-return
8193 \begin_inset LatexCommand \index{-\/-main-return}
8194
8195 \end_inset 
8196
8197
8198 \series default 
8199  This option can be used if the code generated is called by a monitor program
8200  or if the main routine includes an endless loop.
8201  This option results in slightly smaller code and saves two bytes of stack
8202  space.
8203  The return from the 'main'
8204 \begin_inset LatexCommand \index{main return}
8205
8206 \end_inset 
8207
8208  function will return to the function calling main.
8209  The default setting is to lock up i.e.
8210  generate a '
8211 \family typewriter 
8212 sjmp .
8213 \family default 
8214 '.
8215 \layout List
8216 \labelwidthstring 00.00.0000
8217
8218
8219 \series bold 
8220 -
8221 \begin_inset ERT
8222 status Collapsed
8223
8224 \layout Standard
8225
8226 \backslash 
8227 /
8228 \end_inset 
8229
8230 -nostdinc
8231 \begin_inset LatexCommand \index{-\/-nostdinc}
8232
8233 \end_inset 
8234
8235
8236 \series default 
8237  This will prevent the compiler from passing on the default include path
8238  to the preprocessor.
8239 \layout List
8240 \labelwidthstring 00.00.0000
8241
8242
8243 \series bold 
8244 -
8245 \begin_inset ERT
8246 status Collapsed
8247
8248 \layout Standard
8249
8250 \backslash 
8251 /
8252 \end_inset 
8253
8254 -nostdlib
8255 \begin_inset LatexCommand \index{-\/-nostdlib}
8256
8257 \end_inset 
8258
8259
8260 \series default 
8261  This will prevent the compiler from passing on the default library
8262 \begin_inset LatexCommand \index{Libraries}
8263
8264 \end_inset 
8265
8266  path to the linker.
8267 \layout List
8268 \labelwidthstring 00.00.0000
8269
8270
8271 \series bold 
8272 -
8273 \begin_inset ERT
8274 status Collapsed
8275
8276 \layout Standard
8277
8278 \backslash 
8279 /
8280 \end_inset 
8281
8282 -verbose
8283 \begin_inset LatexCommand \index{-\/-verbose}
8284
8285 \end_inset 
8286
8287
8288 \series default 
8289  Shows the various actions the compiler is performing.
8290 \layout List
8291 \labelwidthstring 00.00.0000
8292
8293
8294 \series bold 
8295 -V
8296 \begin_inset LatexCommand \index{-V}
8297
8298 \end_inset 
8299
8300
8301 \series default 
8302  Shows the actual commands the compiler is executing.
8303 \layout List
8304 \labelwidthstring 00.00.0000
8305
8306
8307 \series bold 
8308 -
8309 \begin_inset ERT
8310 status Collapsed
8311
8312 \layout Standard
8313
8314 \backslash 
8315 /
8316 \end_inset 
8317
8318 -no-c-code-in-asm
8319 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8320
8321 \end_inset 
8322
8323
8324 \series default 
8325  Hides your ugly and inefficient c-code from the asm file, so you can always
8326  blame the compiler :)
8327 \layout List
8328 \labelwidthstring 00.00.0000
8329
8330
8331 \series bold 
8332 -
8333 \begin_inset ERT
8334 status Collapsed
8335
8336 \layout Standard
8337
8338 \backslash 
8339 /
8340 \end_inset 
8341
8342 -no-peep-comments
8343 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8344
8345 \end_inset 
8346
8347
8348 \series default 
8349  Will not include peep-hole comments in the generated files.
8350 \layout List
8351 \labelwidthstring 00.00.0000
8352
8353
8354 \series bold 
8355 -
8356 \begin_inset ERT
8357 status Collapsed
8358
8359 \layout Standard
8360
8361 \backslash 
8362 /
8363 \end_inset 
8364
8365 -i-code-in-asm
8366 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8367
8368 \end_inset 
8369
8370
8371 \series default 
8372  Include i-codes in the asm file.
8373  Sounds like noise but is most helpful for debugging the compiler itself.
8374 \layout List
8375 \labelwidthstring 00.00.0000
8376
8377
8378 \series bold 
8379 -
8380 \begin_inset ERT
8381 status Collapsed
8382
8383 \layout Standard
8384
8385 \backslash 
8386 /
8387 \end_inset 
8388
8389 -less-pedantic
8390 \begin_inset LatexCommand \index{-\/-less-pedantic}
8391
8392 \end_inset 
8393
8394
8395 \series default 
8396  Disable some of the more pedantic warnings
8397 \begin_inset LatexCommand \index{Warnings}
8398
8399 \end_inset 
8400
8401  (jwk burps: please be more specific here, please!).
8402 \layout List
8403 \labelwidthstring 00.00.0000
8404
8405
8406 \series bold 
8407 -
8408 \begin_inset ERT
8409 status Collapsed
8410
8411 \layout Standard
8412
8413 \backslash 
8414 /
8415 \end_inset 
8416
8417 -disable-warning\SpecialChar ~
8418 <nnnn>
8419 \begin_inset LatexCommand \index{-\/-disable-warning}
8420
8421 \end_inset 
8422
8423
8424 \series default 
8425  Disable specific warning with number <nnnn>.
8426 \layout List
8427 \labelwidthstring 00.00.0000
8428
8429
8430 \series bold 
8431 -
8432 \begin_inset ERT
8433 status Collapsed
8434
8435 \layout Standard
8436
8437 \backslash 
8438 /
8439 \end_inset 
8440
8441 -print-search-dirs
8442 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8443
8444 \end_inset 
8445
8446
8447 \series default 
8448  Display the directories in the compiler's search path
8449 \layout List
8450 \labelwidthstring 00.00.0000
8451
8452
8453 \series bold 
8454 -
8455 \begin_inset ERT
8456 status Collapsed
8457
8458 \layout Standard
8459
8460 \backslash 
8461 /
8462 \end_inset 
8463
8464 -vc
8465 \begin_inset LatexCommand \index{-\/-vc}
8466
8467 \end_inset 
8468
8469
8470 \series default 
8471  Display errors and warnings using MSVC style, so you can use SDCC with
8472  the visual studio IDE
8473 \begin_inset LatexCommand \index{IDE}
8474
8475 \end_inset 
8476
8477 .
8478  With SDCC both offering a GCC-like (the default) and a MSVC-like
8479 \begin_inset LatexCommand \index{MSVC output style}
8480
8481 \end_inset 
8482
8483  output style, integration into most programming editors should be straightforwa
8484 rd.
8485 \layout List
8486 \labelwidthstring 00.00.0000
8487
8488
8489 \series bold 
8490 -
8491 \begin_inset ERT
8492 status Collapsed
8493
8494 \layout Standard
8495
8496 \backslash 
8497 /
8498 \end_inset 
8499
8500 -use-stdout
8501 \begin_inset LatexCommand \index{-\/-use-stdout}
8502
8503 \end_inset 
8504
8505
8506 \series default 
8507  Send errors and warnings to stdout instead of stderr.
8508 \layout List
8509 \labelwidthstring 00.00.0000
8510
8511
8512 \series bold 
8513 -Wa\SpecialChar ~
8514 asmOption[,asmOption]
8515 \series default 
8516
8517 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8518
8519 \end_inset 
8520
8521 ...
8522  Pass the asmOption to the assembler
8523 \begin_inset LatexCommand \index{Options assembler}
8524
8525 \end_inset 
8526
8527
8528 \begin_inset LatexCommand \index{Assembler options}
8529
8530 \end_inset 
8531
8532 .
8533  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8534 \layout List
8535 \labelwidthstring 00.00.0000
8536
8537
8538 \series bold 
8539 -
8540 \begin_inset ERT
8541 status Collapsed
8542
8543 \layout Standard
8544
8545 \backslash 
8546 /
8547 \end_inset 
8548
8549 -std-sdcc89
8550 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8551
8552 \end_inset 
8553
8554
8555 \series default 
8556  Generally follow the C89 standard, but allow SDCC features that conflict
8557  with the standard (default).
8558 \layout List
8559 \labelwidthstring 00.00.0000
8560
8561
8562 \series bold 
8563 -
8564 \begin_inset ERT
8565 status Collapsed
8566
8567 \layout Standard
8568
8569 \backslash 
8570 /
8571 \end_inset 
8572
8573 -std-c89
8574 \begin_inset LatexCommand \index{-\/-std-c89}
8575
8576 \end_inset 
8577
8578
8579 \series default 
8580  Follow the C89 standard and disable SDCC features that conflict with the
8581  standard.
8582 \layout List
8583 \labelwidthstring 00.00.0000
8584
8585
8586 \series bold 
8587 -
8588 \begin_inset ERT
8589 status Collapsed
8590
8591 \layout Standard
8592
8593 \backslash 
8594 /
8595 \end_inset 
8596
8597 -std-sdcc99
8598 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8599
8600 \end_inset 
8601
8602
8603 \series default 
8604  Generally follow the C99 standard, but allow SDCC features that conflict
8605  with the standard (incomplete support).
8606 \layout List
8607 \labelwidthstring 00.00.0000
8608
8609
8610 \series bold 
8611 -
8612 \begin_inset ERT
8613 status Collapsed
8614
8615 \layout Standard
8616
8617 \backslash 
8618 /
8619 \end_inset 
8620
8621 -std-c99
8622 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8623
8624 \end_inset 
8625
8626
8627 \series default 
8628  Follow the C99 standard and disable SDCC features that conflict with the
8629  standard (incomplete support).
8630 \layout List
8631 \labelwidthstring 00.00.0000
8632
8633
8634 \series bold 
8635 -
8636 \begin_inset ERT
8637 status Collapsed
8638
8639 \layout Standard
8640
8641 \backslash 
8642 /
8643 \end_inset 
8644
8645 -codeseg
8646 \series default 
8647
8648 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8649
8650 \end_inset 
8651
8652 \SpecialChar ~
8653 <Name> The name to be used for the code
8654 \begin_inset LatexCommand \index{code}
8655
8656 \end_inset 
8657
8658  segment, default CSEG.
8659  This is useful if you need to tell the compiler to put the code in a special
8660  segment so you can later on tell the linker to put this segment in a special
8661  place in memory.
8662  Can be used for instance when using bank switching to put the code in a
8663  bank.
8664 \layout List
8665 \labelwidthstring 00.00.0000
8666
8667
8668 \series bold 
8669 -
8670 \begin_inset ERT
8671 status Collapsed
8672
8673 \layout Standard
8674
8675 \backslash 
8676 /
8677 \end_inset 
8678
8679 -constseg
8680 \series default 
8681
8682 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8683
8684 \end_inset 
8685
8686 \SpecialChar ~
8687 <Name> The name to be used for the const
8688 \begin_inset LatexCommand \index{code}
8689
8690 \end_inset 
8691
8692  segment, default CONST.
8693  This is useful if you need to tell the compiler to put the const data in
8694  a special segment so you can later on tell the linker to put this segment
8695  in a special place in memory.
8696  Can be used for instance when using bank switching to put the const data
8697  in a bank.
8698 \layout List
8699 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8700
8701
8702 \series bold 
8703 more-pedantic
8704 \series default 
8705  Actually this is 
8706 \series bold 
8707 \emph on 
8708 not
8709 \series default 
8710 \emph default 
8711  a SDCC compiler option but if you want 
8712 \emph on 
8713 more
8714 \emph default 
8715  warnings you can use a separate tool dedicated to syntax checking like
8716  splint
8717 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8718
8719 \end_inset 
8720
8721
8722 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8723
8724 \end_inset 
8725
8726  
8727 \begin_inset LatexCommand \url{http://www.splint.org}
8728
8729 \end_inset 
8730
8731 .
8732  To make your source files parseable by splint you will have to include
8733  
8734 \family sans 
8735 lint.h
8736 \family default 
8737
8738 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8739
8740 \end_inset 
8741
8742  in your source file and add brackets around extended keywords (like 
8743 \family sans 
8744
8745 \begin_inset Quotes sld
8746 \end_inset 
8747
8748 __at\SpecialChar ~
8749
8750 \series bold 
8751 (
8752 \series default 
8753 0xab
8754 \series bold 
8755 )
8756 \series default 
8757
8758 \begin_inset Quotes srd
8759 \end_inset 
8760
8761
8762 \family default 
8763  and 
8764 \family sans 
8765
8766 \begin_inset Quotes sld
8767 \end_inset 
8768
8769 __interrupt\SpecialChar ~
8770 (2)
8771 \begin_inset Quotes srd
8772 \end_inset 
8773
8774
8775 \family default 
8776 ).
8777  
8778 \newline 
8779 Splint has an excellent on line manual at 
8780 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8781
8782 \end_inset 
8783
8784  and it's capabilities go beyond pure syntax checking.
8785  You'll need to tell splint the location of SDCC's include files so a typical
8786  command line could look like this: 
8787 \newline 
8788
8789 \family sans 
8790 splint\SpecialChar ~
8791 -I\SpecialChar ~
8792 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8793 \SpecialChar ~
8794 myprogram.c
8795 \layout Subsection
8796
8797 Intermediate Dump Options
8798 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8799
8800 \end_inset 
8801
8802
8803 \begin_inset LatexCommand \index{Options intermediate dump}
8804
8805 \end_inset 
8806
8807
8808 \begin_inset LatexCommand \index{Intermediate dump options}
8809
8810 \end_inset 
8811
8812
8813 \layout Standard
8814
8815 The following options are provided for the purpose of retargetting and debugging
8816  the compiler.
8817  They provide a means to dump the intermediate code (iCode
8818 \begin_inset LatexCommand \index{iCode}
8819
8820 \end_inset 
8821
8822 ) generated by the compiler in human readable form at various stages of
8823  the compilation process.
8824  More on iCodes see chapter 
8825 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8826
8827 \end_inset 
8828
8829  
8830 \begin_inset Quotes srd
8831 \end_inset 
8832
8833 The anatomy of the compiler
8834 \begin_inset Quotes srd
8835 \end_inset 
8836
8837 .
8838 \layout List
8839 \labelwidthstring 00.00.0000
8840
8841
8842 \series bold 
8843 -
8844 \begin_inset ERT
8845 status Collapsed
8846
8847 \layout Standard
8848
8849 \backslash 
8850 /
8851 \end_inset 
8852
8853 -dumpraw
8854 \begin_inset LatexCommand \index{-\/-dumpraw}
8855
8856 \end_inset 
8857
8858
8859 \series default 
8860  This option will cause the compiler to dump the intermediate code into
8861  a file of named 
8862 \emph on 
8863 <source filename>.dumpraw
8864 \emph default 
8865  just after the intermediate code has been generated for a function, i.e.
8866  before any optimizations are done.
8867  The basic blocks
8868 \begin_inset LatexCommand \index{Basic blocks}
8869
8870 \end_inset 
8871
8872  at this stage ordered in the depth first number, so they may not be in
8873  sequence of execution.
8874 \layout List
8875 \labelwidthstring 00.00.0000
8876
8877
8878 \series bold 
8879 -
8880 \begin_inset ERT
8881 status Collapsed
8882
8883 \layout Standard
8884
8885 \backslash 
8886 /
8887 \end_inset 
8888
8889 -dumpgcse
8890 \begin_inset LatexCommand \index{-\/-dumpgcse}
8891
8892 \end_inset 
8893
8894
8895 \series default 
8896  Will create a dump of iCode's, after global subexpression elimination
8897 \begin_inset LatexCommand \index{Global subexpression elimination}
8898
8899 \end_inset 
8900
8901 , into a file named 
8902 \emph on 
8903 <source filename>.dumpgcse.
8904 \layout List
8905 \labelwidthstring 00.00.0000
8906
8907
8908 \series bold 
8909 -
8910 \begin_inset ERT
8911 status Collapsed
8912
8913 \layout Standard
8914
8915 \backslash 
8916 /
8917 \end_inset 
8918
8919 -dumpdeadcode
8920 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8921
8922 \end_inset 
8923
8924
8925 \series default 
8926  Will create a dump of iCode's, after deadcode elimination
8927 \begin_inset LatexCommand \index{Dead-code elimination}
8928
8929 \end_inset 
8930
8931 , into a file named 
8932 \emph on 
8933 <source filename>.dumpdeadcode.
8934 \layout List
8935 \labelwidthstring 00.00.0000
8936
8937
8938 \series bold 
8939 -
8940 \begin_inset ERT
8941 status Collapsed
8942
8943 \layout Standard
8944
8945 \backslash 
8946 /
8947 \end_inset 
8948
8949 -dumploop
8950 \begin_inset LatexCommand \index{-\/-dumploop}
8951
8952 \end_inset 
8953
8954
8955 \series default 
8956 \size large 
8957  
8958 \size default 
8959 Will create a dump of iCode's, after loop optimizations
8960 \begin_inset LatexCommand \index{Loop optimization}
8961
8962 \end_inset 
8963
8964 , into a file named 
8965 \emph on 
8966 <source filename>.dumploop.
8967 \layout List
8968 \labelwidthstring 00.00.0000
8969
8970
8971 \series bold 
8972 -
8973 \begin_inset ERT
8974 status Collapsed
8975
8976 \layout Standard
8977
8978 \backslash 
8979 /
8980 \end_inset 
8981
8982 -dumprange
8983 \begin_inset LatexCommand \index{-\/-dumprange}
8984
8985 \end_inset 
8986
8987
8988 \series default 
8989 \size large 
8990  
8991 \size default 
8992 Will create a dump of iCode's, after live range analysis
8993 \begin_inset LatexCommand \index{Live range analysis}
8994
8995 \end_inset 
8996
8997 , into a file named 
8998 \emph on 
8999 <source filename>.dumprange.
9000 \layout List
9001 \labelwidthstring 00.00.0000
9002
9003
9004 \series bold 
9005 -
9006 \begin_inset ERT
9007 status Collapsed
9008
9009 \layout Standard
9010
9011 \backslash 
9012 /
9013 \end_inset 
9014
9015 -dumlrange
9016 \begin_inset LatexCommand \index{-\/-dumlrange}
9017
9018 \end_inset 
9019
9020
9021 \series default 
9022  Will dump the life ranges
9023 \begin_inset LatexCommand \index{Live range analysis}
9024
9025 \end_inset 
9026
9027  for all symbols.
9028 \layout List
9029 \labelwidthstring 00.00.0000
9030
9031
9032 \series bold 
9033 -
9034 \begin_inset ERT
9035 status Collapsed
9036
9037 \layout Standard
9038
9039 \backslash 
9040 /
9041 \end_inset 
9042
9043 -dumpregassign
9044 \begin_inset LatexCommand \index{-\/-dumpregassign}
9045
9046 \end_inset 
9047
9048
9049 \bar under 
9050  
9051 \series default 
9052 \bar default 
9053 Will create a dump of iCode's, after register assignment
9054 \begin_inset LatexCommand \index{Register assignment}
9055
9056 \end_inset 
9057
9058 , into a file named 
9059 \emph on 
9060 <source filename>.dumprassgn.
9061 \layout List
9062 \labelwidthstring 00.00.0000
9063
9064
9065 \series bold 
9066 -
9067 \begin_inset ERT
9068 status Collapsed
9069
9070 \layout Standard
9071
9072 \backslash 
9073 /
9074 \end_inset 
9075
9076 -dumplrange
9077 \begin_inset LatexCommand \index{-\/-dumplrange}
9078
9079 \end_inset 
9080
9081
9082 \series default 
9083  Will create a dump of the live ranges of iTemp's
9084 \layout List
9085 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9086
9087
9088 \series bold 
9089 -
9090 \begin_inset ERT
9091 status Collapsed
9092
9093 \layout Standard
9094
9095 \backslash 
9096 /
9097 \end_inset 
9098
9099 -dumpall
9100 \begin_inset LatexCommand \index{-\/-dumpall}
9101
9102 \end_inset 
9103
9104
9105 \size large 
9106 \bar under 
9107  
9108 \series default 
9109 \size default 
9110 \bar default 
9111 Will cause all the above mentioned dumps to be created.
9112 \layout Subsection
9113
9114 Redirecting output on Windows Shells
9115 \layout Standard
9116 \added_space_bottom bigskip 
9117 By default SDCC writes it's error messages to 
9118 \begin_inset Quotes sld
9119 \end_inset 
9120
9121 standard error
9122 \begin_inset Quotes srd
9123 \end_inset 
9124
9125 .
9126  To force all messages to 
9127 \begin_inset Quotes sld
9128 \end_inset 
9129
9130 standard output
9131 \begin_inset Quotes srd
9132 \end_inset 
9133
9134  use 
9135 \series bold 
9136 -
9137 \series default 
9138 \emph on 
9139
9140 \begin_inset ERT
9141 status Collapsed
9142
9143 \layout Standard
9144
9145 \backslash 
9146 /
9147 \end_inset 
9148
9149
9150 \series bold 
9151 \emph default 
9152 -
9153 \series default 
9154 use-stdout
9155 \begin_inset LatexCommand \index{-\/-use-stdout}
9156
9157 \end_inset 
9158
9159 .
9160  Additionally, if you happen to have visual studio installed in your windows
9161  machine, you can use it to compile your sources using a custom build and
9162  the SDCC -
9163 \emph on 
9164
9165 \begin_inset ERT
9166 status Collapsed
9167
9168 \layout Standard
9169
9170 \backslash 
9171 /
9172 \end_inset 
9173
9174
9175 \emph default 
9176 -vc
9177 \begin_inset LatexCommand \index{-\/-vc}
9178
9179 \end_inset 
9180
9181  option.
9182  Something like this should work:
9183 \newline 
9184
9185 \newline 
9186
9187 \series bold 
9188 c:
9189 \backslash 
9190 sdcc
9191 \backslash 
9192 bin
9193 \backslash 
9194 sdcc.exe -
9195 \series default 
9196 \emph on 
9197
9198 \begin_inset ERT
9199 status Collapsed
9200
9201 \layout Standard
9202
9203 \backslash 
9204 /
9205 \end_inset 
9206
9207
9208 \series bold 
9209 \emph default 
9210 -vc -
9211 \series default 
9212 \emph on 
9213
9214 \begin_inset ERT
9215 status Collapsed
9216
9217 \layout Standard
9218
9219 \backslash 
9220 /
9221 \end_inset 
9222
9223
9224 \series bold 
9225 \emph default 
9226 -model-large -c $(InputPath)
9227 \layout Section
9228
9229 Environment variables
9230 \begin_inset LatexCommand \index{Environment variables}
9231
9232 \end_inset 
9233
9234
9235 \layout Standard
9236
9237 SDCC recognizes the following environment variables:
9238 \layout List
9239 \labelwidthstring 00.00.0000
9240
9241
9242 \series bold 
9243 SDCC_LEAVE_SIGNALS
9244 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9245
9246 \end_inset 
9247
9248
9249 \series default 
9250  SDCC installs a signal handler
9251 \begin_inset LatexCommand \index{signal handler}
9252
9253 \end_inset 
9254
9255  to be able to delete temporary files after an user break (^C) or an exception.
9256  If this environment variable is set, SDCC won't install the signal handler
9257  in order to be able to debug SDCC.
9258 \layout List
9259 \labelwidthstring 00.00.0000
9260
9261
9262 \series bold 
9263 TMP,\SpecialChar ~
9264 TEMP,\SpecialChar ~
9265 TMPDIR
9266 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9267
9268 \end_inset 
9269
9270
9271 \series default 
9272  Path, where temporary files will be created.
9273  The order of the variables is the search order.
9274  In a standard *nix environment these variables are not set, and there's
9275  no need to set them.
9276  On Windows it's recommended to set one of them.
9277 \layout List
9278 \labelwidthstring 00.00.0000
9279
9280
9281 \series bold 
9282 SDCC_HOME
9283 \begin_inset LatexCommand \index{SDCC\_HOME}
9284
9285 \end_inset 
9286
9287
9288 \series default 
9289  Path, see section 
9290 \begin_inset LatexCommand \ref{sub:Install-paths}
9291
9292 \end_inset 
9293
9294 \SpecialChar ~
9295
9296 \begin_inset Quotes sld
9297 \end_inset 
9298
9299  Install Paths
9300 \begin_inset Quotes srd
9301 \end_inset 
9302
9303 .
9304 \layout List
9305 \labelwidthstring 00.00.0000
9306
9307
9308 \series bold 
9309 SDCC_INCLUDE
9310 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9311
9312 \end_inset 
9313
9314
9315 \series default 
9316  Path, see section 
9317 \begin_inset LatexCommand \ref{sub:Search-Paths}
9318
9319 \end_inset 
9320
9321 \SpecialChar ~
9322
9323 \begin_inset Quotes sld
9324 \end_inset 
9325
9326 Search Paths
9327 \begin_inset Quotes srd
9328 \end_inset 
9329
9330 .
9331 \layout List
9332 \labelwidthstring 00.00.0000
9333
9334
9335 \series bold 
9336 SDCC_LIB
9337 \begin_inset LatexCommand \index{SDCC\_LIB}
9338
9339 \end_inset 
9340
9341
9342 \series default 
9343  Path, see section 
9344 \begin_inset LatexCommand \ref{sub:Search-Paths}
9345
9346 \end_inset 
9347
9348 \SpecialChar ~
9349
9350 \begin_inset Quotes sld
9351 \end_inset 
9352
9353 Search Paths
9354 \begin_inset Quotes srd
9355 \end_inset 
9356
9357 ..
9358 \layout Standard
9359 \added_space_bottom bigskip 
9360 There are some more environment variables recognized by SDCC, but these
9361  are solely used for debugging purposes.
9362  They can change or disappear very quickly, and will never be documented.
9363 \layout Section
9364
9365 Storage Class Language Extensions
9366 \layout Subsection
9367
9368 MCS51/DS390 Storage Class
9369 \begin_inset LatexCommand \index{Storage class}
9370
9371 \end_inset 
9372
9373  Language Extensions
9374 \layout Standard
9375
9376 In addition to the ANSI storage classes SDCC allows the following MCS51
9377  specific storage classes:
9378 \layout Subsubsection
9379
9380 data
9381 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9382
9383 \end_inset 
9384
9385
9386 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9387
9388 \end_inset 
9389
9390  / near
9391 \begin_inset LatexCommand \index{near (storage class)}
9392
9393 \end_inset 
9394
9395
9396 \begin_inset LatexCommand \index{\_\_near (storage class)}
9397
9398 \end_inset 
9399
9400
9401 \layout Standard
9402
9403 This is the 
9404 \series bold 
9405 default
9406 \series default 
9407  storage class for the Small Memory model (
9408 \emph on 
9409 data
9410 \emph default 
9411  and 
9412 \emph on 
9413 near
9414 \emph default 
9415  or the more ANSI-C compliant forms 
9416 \emph on 
9417 __data
9418 \emph default 
9419  and 
9420 \emph on 
9421 __near
9422 \emph default 
9423  can be used synonymously).
9424  Variables declared with this storage class will be allocated in the directly
9425  addressable portion of the internal RAM of a 8051, e.g.:
9426 \layout Verse
9427
9428
9429 \family typewriter 
9430 __data unsigned char test_data;
9431 \layout Standard
9432
9433 Writing 0x01 to this variable generates the assembly code:
9434 \layout Verse
9435
9436
9437 \family typewriter 
9438 75*00 01\SpecialChar ~
9439 \SpecialChar ~
9440 \SpecialChar ~
9441 mov\SpecialChar ~
9442 \SpecialChar ~
9443 _test_data,#0x01
9444 \layout Subsubsection
9445
9446 xdata
9447 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9448
9449 \end_inset 
9450
9451
9452 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9453
9454 \end_inset 
9455
9456  / far
9457 \begin_inset LatexCommand \index{far (storage class)}
9458
9459 \end_inset 
9460
9461
9462 \begin_inset LatexCommand \index{\_\_far (storage class)}
9463
9464 \end_inset 
9465
9466
9467 \layout Standard
9468
9469 Variables declared with this storage class will be placed in the external
9470  RAM.
9471  This is the 
9472 \series bold 
9473 default
9474 \series default 
9475  storage class for the Large Memory model, e.g.:
9476 \layout Verse
9477
9478
9479 \family typewriter 
9480 __xdata unsigned char test_xdata;
9481 \layout Standard
9482
9483 Writing 0x01 to this variable generates the assembly code:
9484 \layout Verse
9485
9486
9487 \family typewriter 
9488 90s00r00\SpecialChar ~
9489 \SpecialChar ~
9490 \SpecialChar ~
9491 mov\SpecialChar ~
9492 \SpecialChar ~
9493 dptr,#_test_xdata 
9494 \newline 
9495 74\SpecialChar ~
9496 01\SpecialChar ~
9497 \SpecialChar ~
9498 \SpecialChar ~
9499 \SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 mov\SpecialChar ~
9503 \SpecialChar ~
9504 a,#0x01 
9505 \newline 
9506 F0\SpecialChar ~
9507 \SpecialChar ~
9508 \SpecialChar ~
9509 \SpecialChar ~
9510 \SpecialChar ~
9511 \SpecialChar ~
9512 \SpecialChar ~
9513 \SpecialChar ~
9514 \SpecialChar ~
9515 movx\SpecialChar ~
9516 @dptr,a 
9517 \layout Subsubsection
9518
9519 idata
9520 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9521
9522 \end_inset 
9523
9524
9525 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9526
9527 \end_inset 
9528
9529
9530 \layout Standard
9531
9532 Variables declared with this storage class will be allocated into the indirectly
9533  addressable portion of the internal ram of a 8051, e.g.:
9534 \layout Verse
9535
9536
9537 \family typewriter 
9538 __idata unsigned char test_idata;
9539 \layout Standard
9540
9541 Writing 0x01 to this variable generates the assembly code:
9542 \layout Verse
9543
9544
9545 \family typewriter 
9546 78r00\SpecialChar ~
9547 \SpecialChar ~
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 \SpecialChar ~
9553 mov\SpecialChar ~
9554 \SpecialChar ~
9555 r0,#_test_idata
9556 \newline 
9557 76\SpecialChar ~
9558 01\SpecialChar ~
9559 \SpecialChar ~
9560 \SpecialChar ~
9561 \SpecialChar ~
9562 \SpecialChar ~
9563 \SpecialChar ~
9564 \SpecialChar ~
9565 mov\SpecialChar ~
9566 \SpecialChar ~
9567 @r0,#0x01
9568 \layout Standard
9569
9570 Please note, the first 128 byte of idata physically access the same RAM
9571  as the data memory.
9572  The original 8051 had 128 byte idata memory, nowadays most devices have
9573  256 byte idata memory.
9574  The stack
9575 \begin_inset LatexCommand \index{stack}
9576
9577 \end_inset 
9578
9579  is located in idata memory.
9580 \layout Subsubsection
9581
9582 pdata
9583 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9584
9585 \end_inset 
9586
9587
9588 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9589
9590 \end_inset 
9591
9592
9593 \layout Standard
9594
9595 Paged xdata access is just as straightforward as using the other addressing
9596  modes of a 8051.
9597  It is typically located at the start of xdata and has a maximum size of
9598  256 bytes.
9599  The following example writes 0x01 to the pdata variable.
9600  Please note, pdata access physically accesses xdata memory.
9601  The high byte of the address is determined by port P2 
9602 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9603
9604 \end_inset 
9605
9606 (or in case of some 8051 variants by a separate Special Function Register,
9607  see section 
9608 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9609
9610 \end_inset 
9611
9612 ).
9613  This is the 
9614 \series bold 
9615 default
9616 \series default 
9617  storage class for the Medium Memory model, e.g.:
9618 \layout Verse
9619
9620
9621 \family typewriter 
9622 __pdata unsigned char test_pdata;
9623 \layout Standard
9624
9625 Writing 0x01 to this variable generates the assembly code:
9626 \layout Verse
9627
9628
9629 \family typewriter 
9630 78r00\SpecialChar ~
9631 \SpecialChar ~
9632 \SpecialChar ~
9633 \SpecialChar ~
9634 \SpecialChar ~
9635 \SpecialChar ~
9636 mov r0,#_test_pdata
9637 \newline 
9638 74 01\SpecialChar ~
9639 \SpecialChar ~
9640 \SpecialChar ~
9641 \SpecialChar ~
9642 \SpecialChar ~
9643 \SpecialChar ~
9644 mov a,#0x01 
9645 \newline 
9646 F2\SpecialChar ~
9647 \SpecialChar ~
9648 \SpecialChar ~
9649 \SpecialChar ~
9650 \SpecialChar ~
9651 \SpecialChar ~
9652 \SpecialChar ~
9653 \SpecialChar ~
9654 \SpecialChar ~
9655 movx @r0,a
9656 \layout Standard
9657
9658 If the -
9659 \begin_inset ERT
9660 status Collapsed
9661
9662 \layout Standard
9663
9664 \backslash 
9665 /
9666 \end_inset 
9667
9668 -xstack
9669 \begin_inset LatexCommand \index{-\/-xstack}
9670
9671 \end_inset 
9672
9673  option is used the pdata memory area is followed by the xstack memory area
9674  and the sum of their sizes is limited to 256 bytes.
9675 \layout Subsubsection
9676
9677 code
9678 \begin_inset LatexCommand \index{code}
9679
9680 \end_inset 
9681
9682
9683 \begin_inset LatexCommand \index{\_\_code}
9684
9685 \end_inset 
9686
9687
9688 \layout Standard
9689
9690 'Variables' declared with this storage class will be placed in the code
9691  memory:
9692 \layout Verse
9693
9694
9695 \family typewriter 
9696 __code unsigned char test_code;
9697 \layout Standard
9698
9699 Read access to this variable generates the assembly code:
9700 \layout Verse
9701
9702
9703 \family typewriter 
9704 90s00r6F\SpecialChar ~
9705 \SpecialChar ~
9706 \SpecialChar ~
9707 mov dptr,#_test_code
9708 \newline 
9709 E4\SpecialChar ~
9710 \SpecialChar ~
9711 \SpecialChar ~
9712 \SpecialChar ~
9713 \SpecialChar ~
9714 \SpecialChar ~
9715 \SpecialChar ~
9716 \SpecialChar ~
9717 \SpecialChar ~
9718 clr a
9719 \newline 
9720 93\SpecialChar ~
9721 \SpecialChar ~
9722 \SpecialChar ~
9723 \SpecialChar ~
9724 \SpecialChar ~
9725 \SpecialChar ~
9726 \SpecialChar ~
9727 \SpecialChar ~
9728 \SpecialChar ~
9729 movc a,@a+dptr 
9730 \layout Standard
9731
9732
9733 \family typewriter 
9734 char
9735 \family default 
9736  indexed arrays of characters in code memory can be accessed efficiently:
9737 \layout Verse
9738
9739
9740 \family typewriter 
9741 __code char test_array[] = {'c','h','e','a','p'}; 
9742 \layout Standard
9743
9744 Read access to this array using an 8-bit unsigned index generates the assembly
9745  code:
9746 \layout Verse
9747
9748
9749 \family typewriter 
9750 E5*00\SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 \SpecialChar ~
9756 mov a,_index 
9757 \layout Verse
9758
9759
9760 \family typewriter 
9761 90s00r41\SpecialChar ~
9762 \SpecialChar ~
9763 \SpecialChar ~
9764 mov dptr,#_test_array
9765 \layout Verse
9766
9767
9768 \family typewriter 
9769 93\SpecialChar ~
9770 \SpecialChar ~
9771 \SpecialChar ~
9772 \SpecialChar ~
9773 \SpecialChar ~
9774 \SpecialChar ~
9775 \SpecialChar ~
9776 \SpecialChar ~
9777 \SpecialChar ~
9778 movc a,@a+dptr 
9779 \layout Subsubsection
9780
9781 bit
9782 \begin_inset LatexCommand \index{bit}
9783
9784 \end_inset 
9785
9786
9787 \begin_inset LatexCommand \index{\_\_bit}
9788
9789 \end_inset 
9790
9791
9792 \layout Standard
9793
9794 This is a data-type and a storage class specifier.
9795  When a variable is declared as a bit, it is allocated into the bit addressable
9796  memory of 8051, e.g.:
9797 \layout Verse
9798
9799
9800 \family typewriter 
9801 __bit test_bit;
9802 \layout Standard
9803
9804 Writing 1 to this variable generates the assembly code:
9805 \layout Verse
9806
9807
9808 \family typewriter 
9809 D2*00\SpecialChar ~
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 setb\SpecialChar ~
9817 _test_bit
9818 \layout Standard
9819
9820 The bit addressable memory consists of 128 bits which are located from 0x20
9821  to 0x2f in data memory.
9822  
9823 \newline 
9824 Apart from this 8051 specific storage class most architectures support ANSI-C
9825  bitfields
9826 \begin_inset LatexCommand \index{bitfields}
9827
9828 \end_inset 
9829
9830
9831 \begin_inset Foot
9832 collapsed false
9833
9834 \layout Standard
9835
9836 Not really meant as examples, but nevertheless showing what bitfields are
9837  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9838 \end_inset 
9839
9840 .
9841  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9842  signed modifier are implemented as unsigned.
9843 \layout Subsubsection
9844
9845 sfr
9846 \begin_inset LatexCommand \index{sfr}
9847
9848 \end_inset 
9849
9850
9851 \begin_inset LatexCommand \index{\_\_sfr}
9852
9853 \end_inset 
9854
9855  / sfr16
9856 \begin_inset LatexCommand \index{sfr16}
9857
9858 \end_inset 
9859
9860
9861 \begin_inset LatexCommand \index{\_\_sfr16}
9862
9863 \end_inset 
9864
9865  / sfr32
9866 \begin_inset LatexCommand \index{sfr32}
9867
9868 \end_inset 
9869
9870
9871 \begin_inset LatexCommand \index{\_\_sfr32}
9872
9873 \end_inset 
9874
9875  / sbit
9876 \begin_inset LatexCommand \index{\_\_sbit}
9877
9878 \end_inset 
9879
9880
9881 \begin_inset LatexCommand \index{sbit}
9882
9883 \end_inset 
9884
9885
9886 \layout Standard
9887
9888 Like the bit keyword, 
9889 \emph on 
9890 sfr / sfr16 / sfr32 / sbit 
9891 \emph default 
9892 signify both a data-type and storage class, they are used to describe the
9893  
9894 \emph on 
9895 s
9896 \emph default 
9897 pecial 
9898 \emph on 
9899 f
9900 \emph default 
9901 unction 
9902 \emph on 
9903 r
9904 \emph default 
9905 egisters and 
9906 \emph on 
9907 s
9908 \emph default 
9909 pecial 
9910 \emph on 
9911 bit
9912 \emph default 
9913  variables of a 8051, eg:
9914 \layout Verse
9915
9916
9917 \family typewriter 
9918 __sfr __at
9919 \begin_inset LatexCommand \index{at}
9920
9921 \end_inset 
9922
9923
9924 \begin_inset LatexCommand \index{\_\_at}
9925
9926 \end_inset 
9927
9928  (0x80) P0;\SpecialChar ~
9929  /* special function register P0 at location 0x80 */
9930 \newline 
9931
9932 \newline 
9933 /* 16 bit special function register combination for timer 0
9934 \newline 
9935 \SpecialChar ~
9936 \SpecialChar ~
9937  with the high byte at location 0x8C and the low byte at location 0x8A */
9938 \newline 
9939 __sfr16 __at (0x8C8A) TMR0;
9940 \newline 
9941
9942 \newline 
9943 __sbit __at
9944 \begin_inset LatexCommand \index{at}
9945
9946 \end_inset 
9947
9948
9949 \begin_inset LatexCommand \index{\_\_at}
9950
9951 \end_inset 
9952
9953  (0xd7) CY;\SpecialChar ~
9954  /* CY (Carry Flag
9955 \begin_inset LatexCommand \index{Flags}
9956
9957 \end_inset 
9958
9959
9960 \begin_inset LatexCommand \index{Carry flag}
9961
9962 \end_inset 
9963
9964 ) */
9965 \layout Standard
9966
9967 Special function registers which are located on an address dividable by
9968  8 are bit-addressable, an
9969 \emph on 
9970  sbit
9971 \emph default 
9972  addresses a specific bit within these sfr.
9973 \newline 
9974 16 Bit and 32 bit special function register combinations which require a
9975  certain access order are better not declared using 
9976 \emph on 
9977 sfr16
9978 \emph default 
9979  or 
9980 \emph on 
9981 sfr32.
9982
9983 \emph default 
9984  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9985  this is not guaranteed.
9986 \newline 
9987
9988 \layout Standard
9989
9990 Please note, if you use a header file which was written for another compiler
9991  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
9992  likely be 
9993 \emph on 
9994 not 
9995 \emph default 
9996 compatible.
9997  Specifically the syntax 
9998 \family typewriter 
9999 \SpecialChar ~
10000 sfr P0 = 0x80;\SpecialChar ~
10001
10002 \family default 
10003  is compiled 
10004 \emph on 
10005 without warning
10006 \emph default 
10007  by SDCC to an assignment of 0x80 to a variable called P0 
10008 \family typewriter 
10009
10010 \begin_inset Marginal
10011 collapsed true
10012
10013 \layout Standard
10014
10015
10016 \series bold 
10017 \SpecialChar ~
10018 !
10019 \end_inset 
10020
10021 .
10022  
10023 \family default 
10024 Nevertheless it is possible to write header files
10025 \begin_inset LatexCommand \index{Header files}
10026
10027 \end_inset 
10028
10029
10030 \begin_inset LatexCommand \index{Include files}
10031
10032 \end_inset 
10033
10034  which can be shared among different compilers (see section 
10035 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10036
10037 \end_inset 
10038
10039 ).
10040  
10041 \layout Subsubsection
10042
10043 Pointers
10044 \begin_inset LatexCommand \index{Pointer}
10045
10046 \end_inset 
10047
10048  to MCS51/DS390 specific memory spaces
10049 \layout Standard
10050
10051 SDCC allows (via language extensions) pointers to explicitly point to any
10052  of the memory spaces
10053 \begin_inset LatexCommand \index{Memory model}
10054
10055 \end_inset 
10056
10057  of the 8051.
10058  In addition to the explicit pointers, the compiler uses (by default) generic
10059  pointers which can be used to point to any of the memory spaces.
10060 \newline 
10061
10062 \newline 
10063 Pointer declaration examples:
10064 \layout Verse
10065
10066
10067 \family typewriter 
10068 /* pointer physically in internal ram pointing to object in external ram
10069  */ 
10070 \newline 
10071 __xdata unsigned char * __data p;
10072 \newline 
10073
10074 \newline 
10075 /* pointer physically in external ram pointing to object in internal ram
10076  */ 
10077 \newline 
10078 __data unsigned char * __xdata p;
10079 \newline 
10080
10081 \newline 
10082 /* pointer physically in code rom pointing to data in xdata space */ 
10083 \newline 
10084 __xdata unsigned char * __code p;
10085 \newline 
10086
10087 \newline 
10088 /* pointer physically in code space pointing to data in code space */ 
10089 \newline 
10090 __code unsigned char * __code p;
10091 \newline 
10092
10093 \newline 
10094 /* generic pointer physically located in xdata space */
10095 \newline 
10096 unsigned char * __xdata p;
10097 \newline 
10098
10099 \newline 
10100 /* generic pointer physically located in default memory space */
10101 \newline 
10102 unsigned char * p;
10103 \newline 
10104
10105 \newline 
10106 /* the following is a function pointer
10107 \begin_inset LatexCommand \index{function pointer}
10108
10109 \end_inset 
10110
10111  physically located in data space */
10112 \newline 
10113 char (* __data fp)(void);
10114 \layout Standard
10115
10116 Well you get the idea.
10117  
10118 \newline 
10119
10120 \newline 
10121 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10122 \emph on 
10123 generic
10124 \emph default 
10125  pointers.
10126  
10127 \size small 
10128
10129 \newline 
10130
10131 \newline 
10132
10133 \size default 
10134 The highest order byte of the 
10135 \emph on 
10136 generic
10137 \emph default 
10138  pointers contains the data space information.
10139  Assembler support routines are called whenever data is stored or retrieved
10140  using 
10141 \emph on 
10142 generic
10143 \emph default 
10144  pointers.
10145  These are useful for developing reusable library
10146 \begin_inset LatexCommand \index{Libraries}
10147
10148 \end_inset 
10149
10150  routines.
10151  Explicitly specifying the pointer
10152 \begin_inset LatexCommand \index{pointer}
10153
10154 \end_inset 
10155
10156  type will generate the most efficient code.
10157 \layout Subsubsection
10158
10159 Notes on MCS51 memory
10160 \begin_inset LatexCommand \index{MCS51 memory}
10161
10162 \end_inset 
10163
10164  layout
10165 \layout Standard
10166
10167 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10168  RAM memory which is structured as follows:
10169 \newline 
10170
10171 \newline 
10172 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10173  
10174 \newline 
10175 - Bytes 20-2F - 16 bytes to hold 128 bit
10176 \begin_inset LatexCommand \index{bit}
10177
10178 \end_inset 
10179
10180  variables and, 
10181 \newline 
10182 - Bytes 30-7F - 80 bytes for general purpose use.
10183 \newline 
10184
10185 \layout Standard
10186
10187 Additionally some members of the MCS51 family may have up to 128 bytes of
10188  additional, indirectly addressable, internal RAM memory (
10189 \emph on 
10190 idata
10191 \emph default 
10192
10193 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10194
10195 \end_inset 
10196
10197
10198 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10199
10200 \end_inset 
10201
10202 ).
10203  Furthermore, some chips may have some built in external memory (
10204 \emph on 
10205 xdata
10206 \emph default 
10207
10208 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10209
10210 \end_inset 
10211
10212
10213 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10214
10215 \end_inset 
10216
10217 ) which should not be confused with the internal, directly addressable RAM
10218  memory (
10219 \emph on 
10220 data
10221 \emph default 
10222
10223 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10224
10225 \end_inset 
10226
10227
10228 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10229
10230 \end_inset 
10231
10232 ).
10233  Sometimes this built in 
10234 \emph on 
10235 xdata
10236 \emph default 
10237  memory has to be activated before using it (you can probably find this
10238  information on the datasheet of the microcontroller your are using, see
10239  also section 
10240 \begin_inset LatexCommand \ref{sub:Startup-Code}
10241
10242 \end_inset 
10243
10244 \SpecialChar ~
10245 Startup-Code).
10246 \layout Standard
10247
10248 Normally SDCC will only use the first bank
10249 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10250
10251 \end_inset 
10252
10253  of registers (register bank 0), but it is possible to specify that other
10254  banks of registers (keyword 
10255 \emph on 
10256 using
10257 \emph default 
10258  
10259 \emph on 
10260
10261 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10262
10263 \end_inset 
10264
10265
10266 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10267
10268 \end_inset 
10269
10270
10271 \emph default 
10272 ) should be used in interrupt
10273 \begin_inset LatexCommand \index{interrupt}
10274
10275 \end_inset 
10276
10277
10278 \begin_inset LatexCommand \index{\_\_interrupt}
10279
10280 \end_inset 
10281
10282  routines.
10283  By default, the compiler will place the stack after the last byte of allocated
10284  memory for variables.
10285  For example, if the first 2 banks of registers are used, and only four
10286  bytes are used for 
10287 \emph on 
10288 data
10289 \emph default 
10290  variables, it will position the base of the internal stack at address 20
10291  (0x14).
10292  This implies that as the stack
10293 \begin_inset LatexCommand \index{stack}
10294
10295 \end_inset 
10296
10297  grows, it will use up the remaining register banks, and the 16 bytes used
10298  by the 128 bit variables, and 80 bytes for general purpose use.
10299  If any bit variables are used, the data variables will be placed in unused
10300  register banks and after the byte holding the last bit variable.
10301  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10302  (two bytes used), 
10303 \emph on 
10304 data
10305 \emph default 
10306  variables will be placed starting from address 0x10 to 0x20 and continue
10307  at address 0x22.
10308  You can also use -
10309 \begin_inset ERT
10310 status Collapsed
10311
10312 \layout Standard
10313
10314 \backslash 
10315 /
10316 \end_inset 
10317
10318 -data-loc
10319 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10320
10321 \end_inset 
10322
10323  to specify the start address of the 
10324 \emph on 
10325 data
10326 \emph default 
10327  and -
10328 \begin_inset ERT
10329 status Collapsed
10330
10331 \layout Standard
10332
10333 \backslash 
10334 /
10335 \end_inset 
10336
10337 -iram-size
10338 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10339
10340 \end_inset 
10341
10342  to specify the size of the total internal RAM (
10343 \emph on 
10344 data
10345 \emph default 
10346 +
10347 \emph on 
10348 idata
10349 \emph default 
10350 ).
10351  
10352 \newline 
10353
10354 \layout Standard
10355
10356 By default the 8051 linker will place the stack after the last byte of (i)data
10357  variables.
10358  Option -
10359 \begin_inset ERT
10360 status Collapsed
10361
10362 \layout Standard
10363
10364 \backslash 
10365 /
10366 \end_inset 
10367
10368 -stack-loc
10369 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10370
10371 \end_inset 
10372
10373  allows you to specify the start of the stack, i.e.
10374  you could start it after any data in the general purpose area.
10375  If your microcontroller has additional indirectly addressable internal
10376  RAM (
10377 \emph on 
10378 idata
10379 \emph default 
10380 ) you can place the stack on it.
10381  You may also need to use -
10382 \begin_inset ERT
10383 status Collapsed
10384
10385 \layout Standard
10386
10387 \backslash 
10388 /
10389 \end_inset 
10390
10391 -xdata-loc
10392 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10393
10394 \end_inset 
10395
10396  to set the start address of the external RAM (
10397 \emph on 
10398 xdata
10399 \emph default 
10400 ) and -
10401 \begin_inset ERT
10402 status Collapsed
10403
10404 \layout Standard
10405
10406 \backslash 
10407 /
10408 \end_inset 
10409
10410 -xram-size
10411 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10412
10413 \end_inset 
10414
10415  to specify its size.
10416  Same goes for the code memory, using -
10417 \begin_inset ERT
10418 status Collapsed
10419
10420 \layout Standard
10421
10422 \backslash 
10423 /
10424 \end_inset 
10425
10426 -code-loc
10427 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10428
10429 \end_inset 
10430
10431  and -
10432 \begin_inset ERT
10433 status Collapsed
10434
10435 \layout Standard
10436
10437 \backslash 
10438 /
10439 \end_inset 
10440
10441 -code-size
10442 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10443
10444 \end_inset 
10445
10446 .
10447  If in doubt, don't specify any options and see if the resulting memory
10448  layout is appropriate, then you can adjust it.
10449 \layout Standard
10450 \added_space_bottom bigskip 
10451 The linker generates two files with memory allocation information.
10452  The first, with extension .map
10453 \begin_inset LatexCommand \index{<file>.map}
10454
10455 \end_inset 
10456
10457  shows all the variables and segments.
10458  The second with extension .mem
10459 \begin_inset LatexCommand \index{<file>.mem}
10460
10461 \end_inset 
10462
10463  shows the final memory layout.
10464  The linker will complain either if memory segments overlap, there is not
10465  enough memory, or there is not enough space for stack.
10466  If you get any linking warnings and/or errors related to stack or segments
10467  allocation, take a look at either the .map or .mem files to find out what
10468  the problem is.
10469  The .mem file may even suggest a solution to the problem.
10470 \layout Subsection
10471
10472 Z80/Z180 Storage Class
10473 \begin_inset LatexCommand \index{Z80!Storage class}
10474
10475 \end_inset 
10476
10477  Language Extensions
10478 \layout Subsubsection
10479
10480 sfr
10481 \begin_inset LatexCommand \index{sfr}
10482
10483 \end_inset 
10484
10485
10486 \begin_inset LatexCommand \index{\_\_sfr}
10487
10488 \end_inset 
10489
10490  (in/out to 8-bit addresses)
10491 \layout Standard
10492
10493 The Z80
10494 \begin_inset LatexCommand \index{Z80}
10495
10496 \end_inset 
10497
10498  family has separate address spaces for memory and 
10499 \emph on 
10500 i
10501 \emph default 
10502 nput/
10503 \emph on 
10504 o
10505 \emph default 
10506 utput memory.
10507  I/O memory
10508 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10509
10510 \end_inset 
10511
10512
10513 \begin_inset LatexCommand \index{Z80!I/O memory}
10514
10515 \end_inset 
10516
10517
10518 \begin_inset LatexCommand \index{Z180!I/O memory}
10519
10520 \end_inset 
10521
10522  is accessed with special instructions, e.g.:
10523 \layout Verse
10524
10525
10526 \family typewriter 
10527 sfr at 0x78 IoPort;\SpecialChar ~
10528 \SpecialChar ~
10529 /* define a var in I/O space at 78h called IoPort */
10530  
10531 \layout Standard
10532
10533 Writing 0x01 to this variable generates the assembly code:
10534 \layout Verse
10535
10536
10537 \family typewriter 
10538 3E 01\SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 \SpecialChar ~
10542 \SpecialChar ~
10543 \SpecialChar ~
10544 ld a,#0x01
10545 \newline 
10546 D3 78\SpecialChar ~
10547 \SpecialChar ~
10548 \SpecialChar ~
10549 \SpecialChar ~
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 out (_IoPort),a 
10553 \layout Subsubsection
10554
10555 banked sfr
10556 \begin_inset LatexCommand \index{sfr}
10557
10558 \end_inset 
10559
10560
10561 \begin_inset LatexCommand \index{\_\_sfr}
10562
10563 \end_inset 
10564
10565  (in/out to 16-bit addresses)
10566 \layout Standard
10567
10568 The keyword 
10569 \emph on 
10570 banked
10571 \emph default 
10572  is used to support 16 bit addresses in I/O memory e.g.:
10573 \layout Verse
10574
10575
10576 \family typewriter 
10577 sfr banked at
10578 \begin_inset LatexCommand \index{at}
10579
10580 \end_inset 
10581
10582
10583 \begin_inset LatexCommand \index{\_\_at}
10584
10585 \end_inset 
10586
10587  0x123 IoPort; 
10588 \layout Standard
10589
10590 Writing 0x01 to this variable generates the assembly code:
10591 \layout Verse
10592
10593
10594 \family typewriter 
10595 01 23 01\SpecialChar ~
10596 \SpecialChar ~
10597 \SpecialChar ~
10598 ld bc,#_IoPort
10599 \newline 
10600 3E 01\SpecialChar ~
10601 \SpecialChar ~
10602 \SpecialChar ~
10603 \SpecialChar ~
10604 \SpecialChar ~
10605 \SpecialChar ~
10606 ld a,#0x01 
10607 \newline 
10608 ED 79\SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 \SpecialChar ~
10612 \SpecialChar ~
10613 \SpecialChar ~
10614 out (c),a 
10615 \layout Subsubsection
10616
10617 sfr
10618 \begin_inset LatexCommand \index{sfr}
10619
10620 \end_inset 
10621
10622
10623 \begin_inset LatexCommand \index{\_\_sfr}
10624
10625 \end_inset 
10626
10627  (in0/out0 to 8 bit addresses on Z180
10628 \begin_inset LatexCommand \index{Z180}
10629
10630 \end_inset 
10631
10632 /HD64180
10633 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10634
10635 \end_inset 
10636
10637 )
10638 \layout Standard
10639 \added_space_bottom bigskip 
10640 The compiler option -
10641 \begin_inset ERT
10642 status Collapsed
10643
10644 \layout Standard
10645
10646 \backslash 
10647 /
10648 \end_inset 
10649
10650 -portmode
10651 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10652
10653 \end_inset 
10654
10655 =180 (80) and a compiler #pragma\SpecialChar ~
10656 portmode
10657 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10658
10659 \end_inset 
10660
10661 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10662 ns 
10663 \family typewriter 
10664 in0/out0
10665 \family default 
10666  instead of 
10667 \family typewriter 
10668 in/out
10669 \family default 
10670 .
10671  If you include the file z180.h this will be set automatically.
10672 \layout Subsection
10673
10674 HC08 Storage Class
10675 \begin_inset LatexCommand \index{HC08!Storage class}
10676
10677 \end_inset 
10678
10679  Language Extensions
10680 \layout Subsubsection
10681
10682 data
10683 \begin_inset LatexCommand \index{data (hc08 storage class)}
10684
10685 \end_inset 
10686
10687
10688 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10689
10690 \end_inset 
10691
10692  
10693 \layout Standard
10694
10695 The data storage class declares a variable that resides in the first 256
10696  bytes of memory (the direct page).
10697  The HC08
10698 \begin_inset LatexCommand \index{HC08}
10699
10700 \end_inset 
10701
10702  is most efficient at accessing variables (especially pointers) stored here.
10703 \layout Subsubsection
10704
10705 xdata
10706 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10707
10708 \end_inset 
10709
10710
10711 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10712
10713 \end_inset 
10714
10715  
10716 \layout Standard
10717 \added_space_bottom bigskip 
10718 The xdata storage class declares a variable that can reside anywhere in
10719  memory.
10720  This is the default if no storage class is specified.
10721  
10722 \layout Section
10723
10724 Absolute Addressing
10725 \begin_inset LatexCommand \index{Absolute addressing}
10726
10727 \end_inset 
10728
10729
10730 \layout Standard
10731
10732 Data items can be assigned an absolute address with the 
10733 \emph on 
10734 at
10735 \begin_inset LatexCommand \index{at}
10736
10737 \end_inset 
10738
10739
10740 \begin_inset LatexCommand \index{\_\_at}
10741
10742 \end_inset 
10743
10744  <address>
10745 \emph default 
10746  keyword, in addition to a storage class, e.g.:
10747 \layout Verse
10748
10749
10750 \family typewriter 
10751 xdata
10752 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10753
10754 \end_inset 
10755
10756
10757 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10758
10759 \end_inset 
10760
10761  at
10762 \begin_inset LatexCommand \index{at}
10763
10764 \end_inset 
10765
10766
10767 \begin_inset LatexCommand \index{\_\_at}
10768
10769 \end_inset 
10770
10771  0x7ffe unsigned int chksum;
10772 \layout Standard
10773
10774 or, better conforming to ISO/IEC 9899 C:
10775 \layout Verse
10776
10777
10778 \family typewriter 
10779 __xdata __at (0x7ffe) unsigned int chksum;
10780 \layout Standard
10781
10782 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10783  of the external ram.
10784  The compiler does 
10785 \emph on 
10786 not
10787 \emph default 
10788  reserve any space for variables declared in this way
10789 \begin_inset Marginal
10790 collapsed true
10791
10792 \layout Standard
10793
10794
10795 \series bold 
10796 \SpecialChar ~
10797 !
10798 \end_inset 
10799
10800  (they are implemented with an equate in the assembler).
10801  Thus it is left to the programmer to make sure there are no overlaps with
10802  other variables that are declared without the absolute address.
10803  The assembler listing file (.lst
10804 \begin_inset LatexCommand \index{<file>.lst}
10805
10806 \end_inset 
10807
10808 ) and the linker output files (.rst
10809 \begin_inset LatexCommand \index{<file>.rst}
10810
10811 \end_inset 
10812
10813 ) and (.map
10814 \begin_inset LatexCommand \index{<file>.map}
10815
10816 \end_inset 
10817
10818 ) are good places to look for such overlaps.
10819  Variables with an absolute address are 
10820 \emph on 
10821 not
10822 \begin_inset Marginal
10823 collapsed true
10824
10825 \layout Standard
10826
10827
10828 \series bold 
10829 \SpecialChar ~
10830 !
10831 \end_inset 
10832
10833
10834 \emph default 
10835  initialized
10836 \begin_inset LatexCommand \index{Variable initialization}
10837
10838 \end_inset 
10839
10840 .
10841 \layout Standard
10842
10843 In case of memory mapped I/O devices the keyword 
10844 \emph on 
10845 volatile
10846 \emph default 
10847  has to be used to tell the compiler that accesses might not be removed:
10848 \layout Verse
10849
10850
10851 \family typewriter 
10852 volatile
10853 \begin_inset LatexCommand \index{volatile}
10854
10855 \end_inset 
10856
10857  __xdata
10858 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10859
10860 \end_inset 
10861
10862  __at
10863 \begin_inset LatexCommand \index{at}
10864
10865 \end_inset 
10866
10867  (0x8000) unsigned char PORTA_8255;
10868 \layout Standard
10869
10870 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10871 r) array
10872 \family typewriter 
10873 \size footnotesize 
10874
10875 \begin_inset LatexCommand \index{Aligned array}
10876
10877 \end_inset 
10878
10879
10880 \family default 
10881 \size default 
10882  starts at a block (256 byte) boundary
10883 \begin_inset LatexCommand \index{block boundary}
10884
10885 \end_inset 
10886
10887  (section 
10888 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10889
10890 \end_inset 
10891
10892  has an example).
10893 \newline 
10894 Absolute addresses can be specified for variables in all storage classes,
10895  e.g.:
10896 \layout Verse
10897
10898
10899 \family typewriter 
10900 __bit
10901 \begin_inset LatexCommand \index{bit}
10902
10903 \end_inset 
10904
10905  __at
10906 \begin_inset LatexCommand \index{at}
10907
10908 \end_inset 
10909
10910  (0x02) bvar;
10911 \layout Standard
10912
10913 The above example will allocate the variable at offset 0x02 in the bit-addressab
10914 le space.
10915  There is no real advantage to assigning absolute addresses to variables
10916  in this manner, unless you want strict control over all the variables allocated.
10917  One possible use would be to write hardware portable code.
10918  For example, if you have a routine that uses one or more of the microcontroller
10919  I/O pins, and such pins are different for two different hardwares, you
10920  can declare the I/O pins in your routine using:
10921 \layout Verse
10922
10923
10924 \family typewriter 
10925 extern volatile
10926 \begin_inset LatexCommand \index{volatile}
10927
10928 \end_inset 
10929
10930  __bit MOSI;\SpecialChar ~
10931 \SpecialChar ~
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 /* master out, slave in */
10935 \newline 
10936 extern volatile __bit MISO;\SpecialChar ~
10937 \SpecialChar ~
10938 \SpecialChar ~
10939 \SpecialChar ~
10940 /* master in, slave out */
10941 \newline 
10942 extern volatile __bit MCLK;\SpecialChar ~
10943 \SpecialChar ~
10944 \SpecialChar ~
10945 \SpecialChar ~
10946 /* master clock */
10947 \newline 
10948
10949 \newline 
10950 /* Input and Output of a byte on a 3-wire serial bus.
10951 \newline 
10952 \SpecialChar ~
10953 \SpecialChar ~
10954 \SpecialChar ~
10955 If needed adapt polarity of clock, polarity of data and bit order
10956 \newline 
10957 \SpecialChar ~
10958 */
10959 \newline 
10960 unsigned char spi_io(unsigned char out_byte) 
10961 \newline 
10962
10963 \newline 
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 \SpecialChar ~
10968 unsigned char i=8;
10969 \newline 
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 do { 
10975 \newline 
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 \SpecialChar ~
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 MOSI = out_byte & 0x80; 
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 \SpecialChar ~
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 out_byte <<= 1;
10995 \newline 
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 \SpecialChar ~
11001 \SpecialChar ~
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 MCLK = 1; 
11005 \newline 
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 /* _asm nop _endasm; */\SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 \SpecialChar ~
11022 /* for slow peripherals */
11023 \newline 
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 \SpecialChar ~
11032 if(MISO) 
11033 \newline 
11034 \SpecialChar ~
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 out_byte += 1; 
11047 \newline 
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 \SpecialChar ~
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 MCLK = 0; 
11057 \newline 
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 \SpecialChar ~
11062 } while(--i);
11063 \newline 
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 return out_byte; 
11069 \newline 
11070 }
11071 \layout Standard
11072
11073 Then, someplace in the code for the first hardware you would use
11074 \layout Verse
11075
11076
11077 \family typewriter 
11078 __bit __at
11079 \begin_inset LatexCommand \index{at}
11080
11081 \end_inset 
11082
11083
11084 \begin_inset LatexCommand \index{\_\_at}
11085
11086 \end_inset 
11087
11088  (0x80) MOSI;\SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 /* I/O port 0, bit 0 */
11093 \newline 
11094 __bit __at (0x81) MISO;\SpecialChar ~
11095 \SpecialChar ~
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 /* I/O port 0, bit 1 */
11099 \newline 
11100 __bit __at (0x82) MCLK;\SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 /* I/O port 0, bit 2 */
11105 \layout Standard
11106
11107 Similarly, for the second hardware you would use
11108 \layout Verse
11109
11110
11111 \family typewriter 
11112 __bit __at (0x83) MOSI;\SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 /* I/O port 0, bit 3 */
11117 \newline 
11118 __bit __at (0x91) MISO;\SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 /* I/O port 1, bit 1 */
11123 \newline 
11124 __bit
11125 \begin_inset LatexCommand \index{bit}
11126
11127 \end_inset 
11128
11129  __at (0x92) MCLK;\SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 /* I/O port 1, bit 2 */
11134 \layout Standard
11135 \added_space_bottom bigskip 
11136 and you can use the same hardware dependent routine without changes, as
11137  for example in a library.
11138  This is somehow similar to sbit, but only one absolute address has to be
11139  specified in the whole project.
11140 \layout Section
11141
11142 Parameters
11143 \begin_inset LatexCommand \index{Parameters}
11144
11145 \end_inset 
11146
11147
11148 \begin_inset LatexCommand \index{function parameter}
11149
11150 \end_inset 
11151
11152  & Local Variables
11153 \begin_inset LatexCommand \index{local variables}
11154
11155 \end_inset 
11156
11157
11158 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11159
11160 \end_inset 
11161
11162
11163 \layout Standard
11164
11165 Automatic (local) variables and parameters to functions can either be placed
11166  on the stack or in data-space.
11167  The default action of the compiler is to place these variables in the internal
11168  RAM (for small model) or external RAM (for large model).
11169  This in fact makes them similar to 
11170 \emph on 
11171 static
11172 \begin_inset LatexCommand \index{static}
11173
11174 \end_inset 
11175
11176
11177 \emph default 
11178  so by default functions are non-reentrant
11179 \begin_inset LatexCommand \index{reentrant}
11180
11181 \end_inset 
11182
11183 .
11184  
11185 \newline 
11186
11187 \newline 
11188 They can be placed on the stack
11189 \begin_inset LatexCommand \index{stack}
11190
11191 \end_inset 
11192
11193  by using the
11194 \emph on 
11195  -
11196 \begin_inset ERT
11197 status Collapsed
11198
11199 \layout Standard
11200
11201 \backslash 
11202 /
11203 \end_inset 
11204
11205 -stack-auto
11206 \begin_inset LatexCommand \index{-\/-stack-auto}
11207
11208 \end_inset 
11209
11210
11211 \emph default 
11212  option, by using 
11213 \emph on 
11214 #pragma\SpecialChar ~
11215 stackauto
11216 \emph default 
11217
11218 \begin_inset LatexCommand \index{\#pragma stackauto}
11219
11220 \end_inset 
11221
11222  or by using the 
11223 \emph on 
11224 reentrant
11225 \begin_inset LatexCommand \index{reentrant}
11226
11227 \end_inset 
11228
11229
11230 \emph default 
11231  keyword in the function declaration, e.g.:
11232 \layout Verse
11233
11234
11235 \family typewriter 
11236 unsigned char foo(char i) __reentrant 
11237 \newline 
11238
11239 \newline 
11240 \SpecialChar ~
11241 \SpecialChar ~
11242 \SpecialChar ~
11243 \SpecialChar ~
11244 ...
11245  
11246 \newline 
11247 }
11248 \layout Standard
11249
11250 Since stack space on 8051 is limited, the 
11251 \emph on 
11252 reentrant 
11253 \emph default 
11254 keyword or the
11255 \emph on 
11256  -
11257 \begin_inset ERT
11258 status Collapsed
11259
11260 \layout Standard
11261
11262 \backslash 
11263 /
11264 \end_inset 
11265
11266 -stack-auto
11267 \emph default 
11268  option should be used sparingly.
11269  Note that the reentrant keyword just means that the parameters & local
11270  variables will be allocated to the stack, it 
11271 \emph on 
11272 does not
11273 \emph default 
11274  mean that the function is register bank
11275 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11276
11277 \end_inset 
11278
11279  independent.
11280 \newline 
11281
11282 \newline 
11283 Local variables
11284 \begin_inset LatexCommand \index{local variables}
11285
11286 \end_inset 
11287
11288  can be assigned storage classes and absolute
11289 \begin_inset LatexCommand \index{Absolute addressing}
11290
11291 \end_inset 
11292
11293  addresses, e.g.: 
11294 \layout Verse
11295
11296
11297 \family typewriter 
11298 unsigned char foo() 
11299 \newline 
11300 {
11301 \newline 
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 __xdata unsigned char i;
11307 \newline 
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 \SpecialChar ~
11311 \SpecialChar ~
11312 __bit bvar;
11313 \newline 
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 __data __at
11319 \begin_inset LatexCommand \index{at}
11320
11321 \end_inset 
11322
11323  (0x31) unsigned char j;
11324 \newline 
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 \SpecialChar ~
11329 ...
11330  
11331 \newline 
11332 }
11333 \layout Standard
11334
11335 In the above example the variable 
11336 \emph on 
11337 i
11338 \emph default 
11339  will be allocated in the external ram, 
11340 \emph on 
11341 bvar
11342 \emph default 
11343  in bit addressable space and
11344 \emph on 
11345  j
11346 \emph default 
11347  in internal ram.
11348  When compiled with 
11349 \emph on 
11350 -
11351 \begin_inset ERT
11352 status Collapsed
11353
11354 \layout Standard
11355
11356 \backslash 
11357 /
11358 \end_inset 
11359
11360 -stack-auto
11361 \emph default 
11362  or when a function is declared as 
11363 \emph on 
11364 reentrant
11365 \emph default 
11366  this should only be done for static variables.
11367 \layout Standard
11368
11369 Parameters
11370 \begin_inset LatexCommand \index{function parameter}
11371
11372 \end_inset 
11373
11374  however are not allowed any storage class
11375 \begin_inset LatexCommand \index{Storage class}
11376
11377 \end_inset 
11378
11379 , (storage classes for parameters will be ignored), their allocation is
11380  governed by the memory model in use, and the reentrancy options.
11381 \layout Standard
11382
11383 It is however allowed to use bit parameters in reentrant functions and also
11384  non-static local bit variables are supported.
11385  Efficient use is limited to 8 semi-bitregisters in bit space.
11386  They are pushed and popped to stack
11387 \begin_inset LatexCommand \index{stack}
11388
11389 \end_inset 
11390
11391  as a single byte just like the normal registers.
11392 \layout Section
11393
11394 Overlaying
11395 \begin_inset LatexCommand \label{sub:Overlaying}
11396
11397 \end_inset 
11398
11399
11400 \begin_inset LatexCommand \index{Overlaying}
11401
11402 \end_inset 
11403
11404
11405 \layout Standard
11406
11407 For non-reentrant
11408 \begin_inset LatexCommand \index{reentrant}
11409
11410 \end_inset 
11411
11412  functions SDCC will try to reduce internal ram space usage by overlaying
11413  parameters and local variables of a function (if possible).
11414  Parameters and local variables
11415 \begin_inset LatexCommand \index{local variables}
11416
11417 \end_inset 
11418
11419  of a function will be allocated to an overlayable segment if the function
11420  has 
11421 \emph on 
11422 no other function calls and the function is non-reentrant and the memory
11423  model
11424 \begin_inset LatexCommand \index{Memory model}
11425
11426 \end_inset 
11427
11428  is small.
11429
11430 \emph default 
11431  If an explicit storage class
11432 \begin_inset LatexCommand \index{Storage class}
11433
11434 \end_inset 
11435
11436  is specified for a local variable, it will NOT be overlayed.
11437 \layout Standard
11438
11439 Note that the compiler (not the linkage editor) makes the decision for overlayin
11440 g the data items.
11441  Functions that are called from an interrupt service routine
11442 \begin_inset Marginal
11443 collapsed true
11444
11445 \layout Standard
11446
11447
11448 \series bold 
11449 !
11450 \end_inset 
11451
11452  should be preceded by a #pragma\SpecialChar ~
11453 nooverlay
11454 \begin_inset LatexCommand \index{\#pragma nooverlay}
11455
11456 \end_inset 
11457
11458  if they are not reentrant.
11459 \layout Standard
11460
11461 Also note that the compiler does not do any processing of inline assembler
11462  code, so the compiler might incorrectly assign local variables and parameters
11463  of a function into the overlay segment if the inline assembler code calls
11464  other c-functions that might use the overlay.
11465  In that case the #pragma\SpecialChar ~
11466 nooverlay should be used.
11467 \layout Standard
11468
11469 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11470 tion
11471 \begin_inset LatexCommand \index{Multiplication}
11472
11473 \end_inset 
11474
11475  or division
11476 \begin_inset LatexCommand \index{Division}
11477
11478 \end_inset 
11479
11480  will NOT be overlayed since these are implemented using external functions,
11481  e.g.:
11482 \layout Verse
11483
11484
11485 \family typewriter 
11486 #pragma save 
11487 \newline 
11488 #pragma nooverlay
11489 \begin_inset LatexCommand \index{\#pragma nooverlay}
11490
11491 \end_inset 
11492
11493  
11494 \newline 
11495 void set_error(unsigned char errcd) 
11496 \newline 
11497 {
11498 \newline 
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 P3 = errcd;
11504 \newline 
11505
11506 \newline 
11507 #pragma restore 
11508 \newline 
11509
11510 \newline 
11511 void some_isr () __interrupt
11512 \begin_inset LatexCommand \index{interrupt}
11513
11514 \end_inset 
11515
11516  (2)
11517 \newline 
11518 {
11519 \newline 
11520 \SpecialChar ~
11521 \SpecialChar ~
11522 \SpecialChar ~
11523 \SpecialChar ~
11524 ...
11525 \newline 
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 set_error(10);
11531 \newline 
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 \SpecialChar ~
11535 \SpecialChar ~
11536 ...
11537  
11538 \newline 
11539 }
11540 \layout Standard
11541 \added_space_bottom bigskip 
11542 In the above example the parameter 
11543 \emph on 
11544 errcd
11545 \emph default 
11546  for the function 
11547 \emph on 
11548 set_error
11549 \emph default 
11550  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11551 nooverlay was
11552  not present, this could cause unpredictable runtime behavior when called
11553  from an interrupt service routine.
11554  The #pragma\SpecialChar ~
11555 nooverlay ensures that the parameters and local variables for
11556  the function are NOT overlayed.
11557 \layout Section
11558
11559 Interrupt Service Routines
11560 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11561
11562 \end_inset 
11563
11564
11565 \layout Subsection
11566
11567 General Information
11568 \layout Standard
11569
11570 SDCC allows 
11571 \emph on 
11572 i
11573 \emph default 
11574 nterrupt 
11575 \emph on 
11576 s
11577 \emph default 
11578 ervice 
11579 \emph on 
11580 r
11581 \emph default 
11582 outines to be coded in C, with some extended keywords.
11583 \layout Verse
11584
11585
11586 \family typewriter 
11587 void timer_isr (void) __interrupt (1) __using (1) 
11588 \newline 
11589
11590 \newline 
11591 \SpecialChar ~
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 ...
11596  
11597 \newline 
11598 }
11599 \layout Standard
11600
11601 The optional number following the 
11602 \emph on 
11603 interrupt
11604 \begin_inset LatexCommand \index{interrupt}
11605
11606 \end_inset 
11607
11608
11609 \begin_inset LatexCommand \index{\_\_interrupt}
11610
11611 \end_inset 
11612
11613
11614 \emph default 
11615  keyword is the interrupt number this routine will service.
11616  When present, the compiler will insert a call to this routine in the interrupt
11617  vector table
11618 \begin_inset LatexCommand \index{interrupt vector table}
11619
11620 \end_inset 
11621
11622  for the interrupt number specified.
11623  If you have multiple source files in your project, interrupt service routines
11624  can be present in any of them, but a prototype of the isr MUST be present
11625  or included in the file that contains the function 
11626 \emph on 
11627 main
11628 \emph default 
11629 .
11630  The optional (8051 specific) keyword 
11631 \emph on 
11632 using
11633 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11634
11635 \end_inset 
11636
11637
11638 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11639
11640 \end_inset 
11641
11642
11643 \emph default 
11644  can be used to tell the compiler to use the specified register bank when
11645  generating code for this function.
11646  
11647 \newline 
11648 Interrupt service routines open the door for some very interesting bugs:
11649 \layout Subsubsection
11650
11651
11652 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11653
11654 \end_inset 
11655
11656 Common interrupt pitfall: variable not declared 
11657 \emph on 
11658 volatile
11659 \layout Standard
11660
11661 If an interrupt service routine changes variables which are accessed by
11662  other functions these variables have to be declared 
11663 \emph on 
11664 volatile
11665 \emph default 
11666
11667 \begin_inset LatexCommand \index{volatile}
11668
11669 \end_inset 
11670
11671 .
11672  See 
11673 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11674
11675 \end_inset 
11676
11677  .
11678 \layout Subsubsection
11679
11680
11681 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11682
11683 \end_inset 
11684
11685 Common interrupt pitfall: 
11686 \emph on 
11687 non-atomic access
11688 \layout Standard
11689
11690 If the access to these variables is not 
11691 \emph on 
11692 atomic
11693 \begin_inset LatexCommand \index{atomic}
11694
11695 \end_inset 
11696
11697
11698 \emph default 
11699  (i.e.
11700  the processor needs more than one instruction for the access and could
11701  be interrupted while accessing the variable) the interrupt must be disabled
11702  during the access to avoid inconsistent data.
11703  
11704 \newline 
11705 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11706  should be protected by disabling interrupts.
11707  You're not automatically on the safe side if you use 8 bit variables though.
11708  We need an example here: f.e.
11709  on the 8051 the harmless looking 
11710 \begin_inset Quotes srd
11711 \end_inset 
11712
11713
11714 \family typewriter 
11715 flags\SpecialChar ~
11716 |=\SpecialChar ~
11717 0x80;
11718 \family default 
11719
11720 \begin_inset Quotes sld
11721 \end_inset 
11722
11723  is not atomic if 
11724 \family typewriter 
11725 flags
11726 \family default 
11727  resides in xdata.
11728  Setting 
11729 \begin_inset Quotes srd
11730 \end_inset 
11731
11732
11733 \family typewriter 
11734 flags\SpecialChar ~
11735 |=\SpecialChar ~
11736 0x40;
11737 \family default 
11738
11739 \begin_inset Quotes sld
11740 \end_inset 
11741
11742  from within an interrupt routine might get lost if the interrupt occurs
11743  at the wrong time.
11744  
11745 \begin_inset Quotes sld
11746 \end_inset 
11747
11748
11749 \family typewriter 
11750 counter\SpecialChar ~
11751 +=\SpecialChar ~
11752 8;
11753 \family default 
11754
11755 \begin_inset Quotes srd
11756 \end_inset 
11757
11758  is not atomic on the 8051 even if 
11759 \family typewriter 
11760 counter
11761 \family default 
11762  is located in data memory.
11763 \newline 
11764 Bugs like these are hard to reproduce and can cause a lot of trouble.
11765  
11766 \layout Subsubsection
11767
11768
11769 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11770
11771 \end_inset 
11772
11773 Common interrupt pitfall: 
11774 \emph on 
11775 stack overflow
11776 \layout Standard
11777
11778 The return address and the registers used in the interrupt service routine
11779  are saved on the stack
11780 \begin_inset LatexCommand \index{stack}
11781
11782 \end_inset 
11783
11784  so there must be sufficient stack space.
11785  If there isn't variables or registers (or even the return address itself)
11786  will be corrupted.
11787  This 
11788 \emph on 
11789 stack overflow
11790 \emph default 
11791
11792 \begin_inset LatexCommand \index{stack overflow}
11793
11794 \end_inset 
11795
11796  is most likely to happen if the interrupt occurs during the 
11797 \begin_inset Quotes sld
11798 \end_inset 
11799
11800 deepest
11801 \begin_inset Quotes srd
11802 \end_inset 
11803
11804  subroutine when the stack is already in use for f.e.
11805  many return addresses.
11806 \layout Subsubsection
11807
11808
11809 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11810
11811 \end_inset 
11812
11813 Common interrupt pitfall: 
11814 \emph on 
11815 use of non-reentrant functions
11816 \layout Standard
11817
11818 A special note here, int (16 bit) and long (32 bit) integer division
11819 \begin_inset LatexCommand \index{Division}
11820
11821 \end_inset 
11822
11823 , multiplication
11824 \begin_inset LatexCommand \index{Multiplication}
11825
11826 \end_inset 
11827
11828  & modulus
11829 \begin_inset LatexCommand \index{Modulus}
11830
11831 \end_inset 
11832
11833  and floating-point
11834 \begin_inset LatexCommand \index{Floating point support}
11835
11836 \end_inset 
11837
11838  operations are implemented using external support routines.
11839  If an interrupt service routine needs to do any of these operations then
11840  the support routines (as mentioned in a following section) will have to
11841  be recompiled using the
11842 \emph on 
11843  -
11844 \begin_inset ERT
11845 status Collapsed
11846
11847 \layout Standard
11848
11849 \backslash 
11850 /
11851 \end_inset 
11852
11853 -stack-auto
11854 \begin_inset LatexCommand \index{-\/-stack-auto}
11855
11856 \end_inset 
11857
11858
11859 \emph default 
11860  option and the source file will need to be compiled using the 
11861 \emph on 
11862 -
11863 \begin_inset ERT
11864 status Collapsed
11865
11866 \layout Standard
11867
11868 \backslash 
11869 /
11870 \end_inset 
11871
11872 -int-long-reent
11873 \emph default 
11874
11875 \begin_inset LatexCommand \index{-\/-int-long-reent}
11876
11877 \end_inset 
11878
11879  compiler option.
11880  
11881 \newline 
11882 Note, the type promotion
11883 \begin_inset LatexCommand \index{type promotion}
11884
11885 \end_inset 
11886
11887  required by ANSI C can cause 16 bit routines to be used
11888 \begin_inset Marginal
11889 collapsed true
11890
11891 \layout Standard
11892
11893
11894 \series bold 
11895 \SpecialChar ~
11896 !
11897 \end_inset 
11898
11899  without the programmer being aware of it.
11900  See f.e.
11901  the cast 
11902 \family typewriter 
11903 (unsigned char)(tail-1)
11904 \family default 
11905  within the if clause in section 
11906 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11907
11908 \end_inset 
11909
11910 .
11911 \layout Standard
11912 \added_space_bottom bigskip 
11913 Calling other functions from an interrupt service routine is not recommended,
11914  avoid it if possible.
11915  Note that when some function is called from an interrupt service routine
11916  it should be preceded by a #pragma\SpecialChar ~
11917 nooverlay
11918 \begin_inset LatexCommand \index{\#pragma nooverlay}
11919
11920 \end_inset 
11921
11922  if it is not reentrant.
11923  Furthermore nonreentrant functions should not be called from the main program
11924  while the interrupt service routine might be active.
11925  They also must not be called from low priority interrupt service routines
11926  while a high priority interrupt service routine might be active.
11927  You could use semaphores or make the function
11928 \emph on 
11929  critical
11930 \emph default 
11931  if all parameters are passed in registers.
11932 \newline 
11933  Also see section 
11934 \begin_inset LatexCommand \ref{sub:Overlaying}
11935
11936 \end_inset 
11937
11938 \SpecialChar ~
11939 about Overlaying and section 
11940 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11941
11942 \end_inset 
11943
11944 \SpecialChar ~
11945 about Functions using private register banks.
11946 \layout Subsection
11947
11948 MCS51/DS390 Interrupt Service Routines
11949 \layout Standard
11950
11951 Interrupt
11952 \begin_inset LatexCommand \index{interrupt}
11953
11954 \end_inset 
11955
11956  numbers and the corresponding address & descriptions for the Standard 8051/8052
11957  are listed below.
11958  SDCC will automatically adjust the 
11959 \begin_inset LatexCommand \index{interrupt vector table}
11960
11961 \end_inset 
11962
11963  to the maximum interrupt number specified.
11964 \newline 
11965
11966 \layout Standard
11967 \align center 
11968
11969 \begin_inset  Tabular
11970 <lyxtabular version="3" rows="9" columns="3">
11971 <features>
11972 <column alignment="center" valignment="top" leftline="true" width="0in">
11973 <column alignment="left" valignment="top" leftline="true" width="0in">
11974 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11975 <row topline="true" bottomline="true">
11976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11977 \begin_inset Text
11978
11979 \layout Standard
11980
11981 Interrupt #
11982 \end_inset 
11983 </cell>
11984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11985 \begin_inset Text
11986
11987 \layout Standard
11988
11989 Description
11990 \end_inset 
11991 </cell>
11992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11993 \begin_inset Text
11994
11995 \layout Standard
11996
11997 Vector Address
11998 \end_inset 
11999 </cell>
12000 </row>
12001 <row topline="true">
12002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12003 \begin_inset Text
12004
12005 \layout Standard
12006
12007 0
12008 \end_inset 
12009 </cell>
12010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12011 \begin_inset Text
12012
12013 \layout Standard
12014
12015 External 0
12016 \end_inset 
12017 </cell>
12018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12019 \begin_inset Text
12020
12021 \layout Standard
12022
12023 0x0003
12024 \end_inset 
12025 </cell>
12026 </row>
12027 <row topline="true">
12028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12029 \begin_inset Text
12030
12031 \layout Standard
12032
12033 1
12034 \end_inset 
12035 </cell>
12036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12037 \begin_inset Text
12038
12039 \layout Standard
12040
12041 Timer 0
12042 \end_inset 
12043 </cell>
12044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12045 \begin_inset Text
12046
12047 \layout Standard
12048
12049 0x000b
12050 \end_inset 
12051 </cell>
12052 </row>
12053 <row topline="true">
12054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12055 \begin_inset Text
12056
12057 \layout Standard
12058
12059 2
12060 \end_inset 
12061 </cell>
12062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12063 \begin_inset Text
12064
12065 \layout Standard
12066
12067 External 1
12068 \end_inset 
12069 </cell>
12070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12071 \begin_inset Text
12072
12073 \layout Standard
12074
12075 0x0013
12076 \end_inset 
12077 </cell>
12078 </row>
12079 <row topline="true">
12080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12081 \begin_inset Text
12082
12083 \layout Standard
12084
12085 3
12086 \end_inset 
12087 </cell>
12088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12089 \begin_inset Text
12090
12091 \layout Standard
12092
12093 Timer 1
12094 \end_inset 
12095 </cell>
12096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12097 \begin_inset Text
12098
12099 \layout Standard
12100
12101 0x001b
12102 \end_inset 
12103 </cell>
12104 </row>
12105 <row topline="true">
12106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12107 \begin_inset Text
12108
12109 \layout Standard
12110
12111 4
12112 \end_inset 
12113 </cell>
12114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12115 \begin_inset Text
12116
12117 \layout Standard
12118
12119 Serial
12120 \end_inset 
12121 </cell>
12122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12123 \begin_inset Text
12124
12125 \layout Standard
12126
12127 0x0023
12128 \end_inset 
12129 </cell>
12130 </row>
12131 <row topline="true">
12132 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12133 \begin_inset Text
12134
12135 \layout Standard
12136
12137 5
12138 \end_inset 
12139 </cell>
12140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12141 \begin_inset Text
12142
12143 \layout Standard
12144
12145 Timer 2 (8052)
12146 \end_inset 
12147 </cell>
12148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12149 \begin_inset Text
12150
12151 \layout Standard
12152
12153 0x002b
12154 \end_inset 
12155 </cell>
12156 </row>
12157 <row topline="true">
12158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12159 \begin_inset Text
12160
12161 \layout Standard
12162
12163 ...
12164 \end_inset 
12165 </cell>
12166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12167 \begin_inset Text
12168
12169 \layout Standard
12170
12171 \end_inset 
12172 </cell>
12173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12174 \begin_inset Text
12175
12176 \layout Standard
12177
12178 ...
12179 \end_inset 
12180 </cell>
12181 </row>
12182 <row topline="true" bottomline="true">
12183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12184 \begin_inset Text
12185
12186 \layout Standard
12187
12188 n
12189 \end_inset 
12190 </cell>
12191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12192 \begin_inset Text
12193
12194 \layout Standard
12195
12196 \end_inset 
12197 </cell>
12198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12199 \begin_inset Text
12200
12201 \layout Standard
12202
12203 0x0003 + 8*n
12204 \end_inset 
12205 </cell>
12206 </row>
12207 </lyxtabular>
12208
12209 \end_inset 
12210
12211
12212 \newline 
12213
12214 \layout Standard
12215
12216 If the interrupt service routine is defined without 
12217 \emph on 
12218 using
12219 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12220
12221 \end_inset 
12222
12223
12224 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12225
12226 \end_inset 
12227
12228
12229 \emph default 
12230  a register bank or with register bank 0 (
12231 \emph on 
12232 using
12233 \emph default 
12234  0), the compiler will save the registers used by itself on the stack upon
12235  entry and restore them at exit, however if such an interrupt service routine
12236  calls another function then the entire register bank will be saved on the
12237  stack.
12238  This scheme may be advantageous for small interrupt service routines which
12239  have low register usage.
12240 \layout Standard
12241 \added_space_bottom bigskip 
12242 If the interrupt service routine is defined to be using a specific register
12243  bank then only 
12244 \emph on 
12245 a, b, dptr
12246 \emph default 
12247  & psw are saved and restored, if such an interrupt service routine calls
12248  another function (using another register bank) then the entire register
12249  bank of the called function will be saved on the stack
12250 \begin_inset LatexCommand \index{stack}
12251
12252 \end_inset 
12253
12254 .
12255  This scheme is recommended for larger interrupt service routines.
12256 \layout Subsection
12257
12258 HC08
12259 \begin_inset LatexCommand \index{HC08}
12260
12261 \end_inset 
12262
12263  Interrupt Service Routines
12264 \layout Standard
12265 \added_space_bottom bigskip 
12266 Since the number of interrupts
12267 \begin_inset LatexCommand \index{HC08!interrupt}
12268
12269 \end_inset 
12270
12271  available is chip specific and the interrupt vector table always ends at
12272  the last byte of memory, the interrupt numbers corresponds to the interrupt
12273  vectors in reverse order of address.
12274  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12275  2 will use the interrupt vector at 0xfffa, and so on.
12276  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12277  this way; instead see section 
12278 \begin_inset LatexCommand \ref{sub:Startup-Code}
12279
12280 \end_inset 
12281
12282  for details on customizing startup.
12283 \layout Subsection
12284
12285 Z80 Interrupt Service Routines
12286 \layout Standard
12287
12288 The Z80
12289 \begin_inset LatexCommand \index{Z80}
12290
12291 \end_inset 
12292
12293  uses several different methods for determining the correct interrupt
12294 \begin_inset LatexCommand \index{Z80!interrupt}
12295
12296 \end_inset 
12297
12298  vector depending on the hardware implementation.
12299  Therefore, SDCC ignores the optional interrupt number and does not attempt
12300  to generate an interrupt vector table.
12301 \layout Standard
12302
12303 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12304  instruction to return from the interrupt.
12305  To write an interrupt handler for the non-maskable interrupt, which needs
12306  a RETN instruction instead, add the 
12307 \emph on 
12308 critical
12309 \emph default 
12310  keyword:
12311 \layout Verse
12312
12313
12314 \family typewriter 
12315 void nmi_isr (void) critical interrupt
12316 \newline 
12317
12318 \newline 
12319 \SpecialChar ~
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 \SpecialChar ~
12323 ...
12324  
12325 \newline 
12326 }
12327 \layout Standard
12328 \added_space_bottom bigskip 
12329 However if you need to create a non-interruptable interrupt service routine
12330  you would also require the 
12331 \emph on 
12332 critical
12333 \emph default 
12334  keyword.
12335  To distinguish between this and an nmi_isr you must provide an interrupt
12336  number.
12337 \layout Section
12338
12339 Enabling and Disabling Interrupts
12340 \layout Subsection
12341
12342 Critical Functions and Critical Statements
12343 \layout Standard
12344
12345 A special keyword may be associated with a block or a function declaring
12346  it as 
12347 \emph on 
12348 critical
12349 \emph default 
12350 .
12351  SDCC will generate code to disable all interrupts
12352 \begin_inset LatexCommand \index{interrupt}
12353
12354 \end_inset 
12355
12356  upon entry to a critical function and restore the interrupt enable to the
12357  previous state before returning.
12358  Nesting critical functions will need one additional byte on the stack
12359 \begin_inset LatexCommand \index{stack}
12360
12361 \end_inset 
12362
12363  for each call.
12364 \layout Verse
12365
12366
12367 \family typewriter 
12368 int foo () __critical
12369 \begin_inset LatexCommand \index{critical}
12370
12371 \end_inset 
12372
12373
12374 \begin_inset LatexCommand \index{\_\_critical}
12375
12376 \end_inset 
12377
12378  
12379 \newline 
12380
12381 \newline 
12382 \SpecialChar ~
12383 \SpecialChar ~
12384 \SpecialChar ~
12385 \SpecialChar ~
12386 ...
12387  
12388 \newline 
12389 \SpecialChar ~
12390 \SpecialChar ~
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 ...
12394  
12395 \newline 
12396 }
12397 \layout Standard
12398
12399 The critical attribute maybe used with other attributes like 
12400 \emph on 
12401 reentrant.
12402 \emph default 
12403
12404 \newline 
12405 The keyword 
12406 \emph on 
12407 critical
12408 \emph default 
12409  may also be used to disable interrupts more locally:
12410 \layout Verse
12411
12412
12413 \family typewriter 
12414 __critical{ i++; }
12415 \layout Standard
12416
12417 More than one statement could have been included in the block.
12418 \layout Subsection
12419
12420 Enabling and Disabling Interrupts directly
12421 \layout Standard
12422
12423 Interrupts
12424 \begin_inset LatexCommand \index{interrupt}
12425
12426 \end_inset 
12427
12428  can also be disabled and enabled directly (8051):
12429 \layout Verse
12430
12431
12432 \family typewriter 
12433 EA = 0;\SpecialChar ~
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 \SpecialChar ~
12437 \SpecialChar ~
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 \SpecialChar ~
12442 \SpecialChar ~
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 or:\SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 \SpecialChar ~
12451 \SpecialChar ~
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 \SpecialChar ~
12456 EA_SAVE = EA;
12457 \layout Verse
12458
12459
12460 \family typewriter 
12461 ...\SpecialChar ~
12462 \SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 \SpecialChar ~
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 \SpecialChar ~
12480 \SpecialChar ~
12481 \SpecialChar ~
12482 \SpecialChar ~
12483 \SpecialChar ~
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 \SpecialChar ~
12487 \SpecialChar ~
12488 \SpecialChar ~
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 EA = 0;
12492 \layout Verse
12493
12494
12495 \family typewriter 
12496 EA = 1;\SpecialChar ~
12497 \SpecialChar ~
12498 \SpecialChar ~
12499 \SpecialChar ~
12500 \SpecialChar ~
12501 \SpecialChar ~
12502 \SpecialChar ~
12503 \SpecialChar ~
12504 \SpecialChar ~
12505 \SpecialChar ~
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 \SpecialChar ~
12509 \SpecialChar ~
12510 \SpecialChar ~
12511 \SpecialChar ~
12512 \SpecialChar ~
12513 \SpecialChar ~
12514 \SpecialChar ~
12515 \SpecialChar ~
12516 \SpecialChar ~
12517 \SpecialChar ~
12518 \SpecialChar ~
12519 \SpecialChar ~
12520 \SpecialChar ~
12521 \SpecialChar ~
12522 ...
12523 \layout Verse
12524
12525
12526 \family typewriter 
12527 \SpecialChar ~
12528 \SpecialChar ~
12529 \SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 \SpecialChar ~
12533 \SpecialChar ~
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 \SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 \SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 \SpecialChar ~
12560 EA = EA_SAVE;
12561 \layout Standard
12562
12563 On other architectures which have seperate opcodes for enabling and disabling
12564  interrupts you might want to make use of defines with inline assembly
12565 \begin_inset LatexCommand \index{Assembler routines}
12566
12567 \end_inset 
12568
12569  (HC08
12570 \begin_inset LatexCommand \index{HC08!interrupt}
12571
12572 \end_inset 
12573
12574 ):
12575 \layout Verse
12576
12577
12578 \family typewriter 
12579 #define CLI _asm
12580 \begin_inset LatexCommand \index{\_asm}
12581
12582 \end_inset 
12583
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 cli\SpecialChar ~
12587 \SpecialChar ~
12588 _endasm
12589 \begin_inset LatexCommand \index{\_endasm}
12590
12591 \end_inset 
12592
12593
12594 \layout Verse
12595
12596
12597 \family typewriter 
12598 #define SEI _asm\SpecialChar ~
12599 \SpecialChar ~
12600 sei\SpecialChar ~
12601 \SpecialChar ~
12602 _endasm; 
12603 \layout Verse
12604
12605
12606 \family typewriter 
12607 ...
12608 \layout Standard
12609
12610 Note: it is sometimes sufficient to disable only a specific interrupt source
12611  like f.e.
12612  a timer or serial interrupt by manipulating an 
12613 \emph on 
12614 interrupt mask
12615 \begin_inset LatexCommand \index{interrupt mask}
12616
12617 \end_inset 
12618
12619
12620 \emph default 
12621  register.
12622  
12623 \layout Standard
12624
12625 Usually the time during which interrupts are disabled should be kept as
12626  short as possible.
12627  This minimizes both 
12628 \emph on 
12629 interrupt latency
12630 \emph default 
12631
12632 \begin_inset LatexCommand \index{interrupt latency}
12633
12634 \end_inset 
12635
12636  (the time between the occurrence of the interrupt and the execution of
12637  the first code in the interrupt routine) and 
12638 \emph on 
12639 interrupt jitter
12640 \emph default 
12641
12642 \begin_inset LatexCommand \index{interrupt jitter}
12643
12644 \end_inset 
12645
12646  (the difference between the shortest and the longest interrupt latency).
12647  These really are something different, f.e.
12648  a serial interrupt has to be served before its buffer overruns so it cares
12649  for the maximum interrupt latency, whereas it does not care about jitter.
12650  On a loudspeaker driven via a digital to analog converter which is fed
12651  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12652  a much smaller jitter will be very audible.
12653 \layout Standard
12654
12655 You can reenable interrupts within an interrupt routine and on some architecture
12656 s you can make use of two (or more) levels of 
12657 \emph on 
12658 interrupt priorities
12659 \emph default 
12660
12661 \begin_inset LatexCommand \index{interrupt priority}
12662
12663 \end_inset 
12664
12665 .
12666  On some architectures which don't support interrupt priorities these can
12667  be implemented by manipulating the interrupt mask and reenabling interrupts
12668  within the interrupt routine.
12669  Check there is sufficient space on the stack
12670 \begin_inset LatexCommand \index{stack}
12671
12672 \end_inset 
12673
12674  and don't add complexity unless you have to.
12675  
12676 \layout Subsection
12677
12678 Semaphore
12679 \begin_inset LatexCommand \index{semaphore}
12680
12681 \end_inset 
12682
12683  locking (mcs51/ds390)
12684 \layout Standard
12685
12686 Some architectures (mcs51/ds390) have an atomic
12687 \begin_inset LatexCommand \index{atomic}
12688
12689 \end_inset 
12690
12691  bit test and
12692 \emph on 
12693  
12694 \emph default 
12695 clear
12696 \emph on 
12697  
12698 \emph default 
12699 instruction.
12700  These type of instructions are typically used in preemptive multitasking
12701  systems, where a routine f.e.
12702  claims the use of a data structure ('acquires a lock
12703 \begin_inset LatexCommand \index{lock}
12704
12705 \end_inset 
12706
12707  on it'), makes some modifications and then releases the lock when the data
12708  structure is consistent again.
12709  The instruction may also be used if interrupt and non-interrupt code have
12710  to compete for a resource.
12711  With the atomic bit test and clear instruction interrupts
12712 \begin_inset LatexCommand \index{interrupt}
12713
12714 \end_inset 
12715
12716  don't have to be disabled for the locking operation.
12717  
12718 \layout Standard
12719
12720 SDCC generates this instruction if the source follows this pattern:
12721 \layout Verse
12722
12723
12724 \family typewriter 
12725 volatile
12726 \begin_inset LatexCommand \index{volatile}
12727
12728 \end_inset 
12729
12730  bit resource_is_free; 
12731 \newline 
12732
12733 \newline 
12734 if (resource_is_free) 
12735 \newline 
12736 \SpecialChar ~
12737 \SpecialChar ~
12738
12739 \newline 
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 \SpecialChar ~
12743 \SpecialChar ~
12744 resource_is_free=0; 
12745 \newline 
12746 \SpecialChar ~
12747 \SpecialChar ~
12748 \SpecialChar ~
12749 \SpecialChar ~
12750 ...
12751  
12752 \newline 
12753 \SpecialChar ~
12754 \SpecialChar ~
12755 \SpecialChar ~
12756 \SpecialChar ~
12757 resource_is_free=1;
12758 \newline 
12759 \SpecialChar ~
12760 \SpecialChar ~
12761
12762 \layout Standard
12763
12764 Note, mcs51 and ds390 support only an atomic
12765 \begin_inset LatexCommand \index{atomic}
12766
12767 \end_inset 
12768
12769  bit test and 
12770 \emph on 
12771 clear
12772 \emph default 
12773  instruction (as opposed to atomic bit test and 
12774 \emph on 
12775 set).
12776 \layout Section
12777
12778 Functions using private register banks
12779 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12780
12781 \end_inset 
12782
12783  (mcs51/ds390)
12784 \layout Standard
12785
12786 Some architectures have support for quickly changing register sets.
12787  SDCC supports this feature with the 
12788 \emph on 
12789 using
12790 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12791
12792 \end_inset 
12793
12794
12795 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12796
12797 \end_inset 
12798
12799
12800 \emph default 
12801  attribute (which tells the compiler to use a register bank
12802 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12803
12804 \end_inset 
12805
12806  other than the default bank zero).
12807  It should only be applied to 
12808 \emph on 
12809 interrupt
12810 \begin_inset LatexCommand \index{interrupt}
12811
12812 \end_inset 
12813
12814
12815 \emph default 
12816  functions (see footnote below).
12817  This will in most circumstances make the generated ISR code more efficient
12818  since it will not have to save registers on the stack.
12819 \layout Standard
12820
12821 The 
12822 \emph on 
12823 using
12824 \emph default 
12825  attribute will have no effect on the generated code for a 
12826 \emph on 
12827 non-interrupt
12828 \emph default 
12829  function (but may occasionally be useful anyway
12830 \begin_inset Foot
12831 collapsed false
12832
12833 \layout Standard
12834
12835 possible exception: if a function is called ONLY from 'interrupt' functions
12836  using a particular bank, it can be declared with the same 'using' attribute
12837  as the calling 'interrupt' functions.
12838  For instance, if you have several ISRs using bank one, and all of them
12839  call memcpy(), it might make sense to create a specialized version of memcpy()
12840  'using 1', since this would prevent the ISR from having to save bank zero
12841  to the stack on entry and switch to bank zero before calling the function
12842 \end_inset 
12843
12844 ).
12845 \newline 
12846
12847 \emph on 
12848 (pending: Note, nowadays the 
12849 \emph default 
12850 using
12851 \emph on 
12852  attribute has an effect on
12853 \emph default 
12854  
12855 \emph on 
12856 the generated code for a 
12857 \emph default 
12858 non-interrupt
12859 \emph on 
12860  function
12861 \emph default 
12862 .
12863 \emph on 
12864 )
12865 \layout Standard
12866
12867 An 
12868 \emph on 
12869 interrupt
12870 \emph default 
12871  function using a non-zero bank will assume that it can trash that register
12872  bank, and will not save it.
12873  Since high-priority interrupts
12874 \begin_inset LatexCommand \index{interrupts}
12875
12876 \end_inset 
12877
12878
12879 \begin_inset LatexCommand \index{interrupt priority}
12880
12881 \end_inset 
12882
12883  can interrupt low-priority ones on the 8051 and friends, this means that
12884  if a high-priority ISR 
12885 \emph on 
12886 using
12887 \emph default 
12888  a particular bank occurs while processing a low-priority ISR 
12889 \emph on 
12890 using
12891 \emph default 
12892  the same bank, terrible and bad things can happen.
12893  To prevent this, no single register bank should be 
12894 \emph on 
12895 used
12896 \emph default 
12897  by both a high priority and a low priority ISR.
12898  This is probably most easily done by having all high priority ISRs use
12899  one bank and all low priority ISRs use another.
12900  If you have an ISR which can change priority at runtime, you're on your
12901  own: I suggest using the default bank zero and taking the small performance
12902  hit.
12903 \layout Standard
12904 \added_space_bottom bigskip 
12905 It is most efficient if your ISR calls no other functions.
12906  If your ISR must call other functions, it is most efficient if those functions
12907  use the same bank as the ISR (see note 1 below); the next best is if the
12908  called functions use bank zero.
12909  It is very inefficient to call a function using a different, non-zero bank
12910  from an ISR.
12911  
12912 \layout Section
12913
12914 Startup Code
12915 \begin_inset LatexCommand \label{sub:Startup-Code}
12916
12917 \end_inset 
12918
12919
12920 \begin_inset LatexCommand \index{Startup code}
12921
12922 \end_inset 
12923
12924
12925 \layout Subsection
12926
12927 MCS51/DS390 Startup Code
12928 \layout Standard
12929
12930 The compiler inserts a call to the C routine 
12931 \emph on 
12932 _sdcc_external_startup()
12933 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12934
12935 \end_inset 
12936
12937
12938 \series bold 
12939 \emph default 
12940  
12941 \series default 
12942 at the start of the CODE area.
12943  This routine is in the runtime library
12944 \begin_inset LatexCommand \index{Runtime library}
12945
12946 \end_inset 
12947
12948 .
12949  By default this routine returns 0, if this routine returns a non-zero value,
12950  the static & global variable initialization will be skipped and the function
12951  main will be invoked.
12952  Otherwise static & global variables will be initialized before the function
12953  main is invoked.
12954  You could add a 
12955 \emph on 
12956 _sdcc_external_startup()
12957 \emph default 
12958  routine to your program to override the default if you need to setup hardware
12959  or perform some other critical operation prior to static & global variable
12960  initialization
12961 \begin_inset LatexCommand \index{Variable initialization}
12962
12963 \end_inset 
12964
12965 .
12966  On some mcs51 variants xdata
12967 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12968
12969 \end_inset 
12970
12971  memory has to be explicitly enabled before it can be accessed or if the
12972  watchdog
12973 \begin_inset LatexCommand \index{watchdog}
12974
12975 \end_inset 
12976
12977  needs to be disabled, this is the place to do it.
12978  The startup code clears all internal data memory, 256 bytes by default,
12979  but from 0 to n-1 if 
12980 \emph on 
12981 -
12982 \begin_inset ERT
12983 status Collapsed
12984
12985 \layout Standard
12986
12987 \backslash 
12988 /
12989 \end_inset 
12990
12991 -iram-size
12992 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12993
12994 \end_inset 
12995
12996 n
12997 \emph default 
12998  is used.
12999  (recommended for Chipcon CC1010).
13000 \layout Standard
13001 \added_space_bottom bigskip 
13002 See also the compiler options 
13003 \emph on 
13004 -
13005 \begin_inset ERT
13006 status Collapsed
13007
13008 \layout Standard
13009
13010 \backslash 
13011 /
13012 \end_inset 
13013
13014 -no-xinit
13015 \emph default 
13016 -
13017 \emph on 
13018 opt
13019 \emph default 
13020
13021 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13022
13023 \end_inset 
13024
13025
13026 \emph on 
13027 -
13028 \begin_inset ERT
13029 status Collapsed
13030
13031 \layout Standard
13032
13033 \backslash 
13034 /
13035 \end_inset 
13036
13037 -main-return
13038 \emph default 
13039
13040 \begin_inset LatexCommand \index{-\/-main-return}
13041
13042 \end_inset 
13043
13044  and section 
13045 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13046
13047 \end_inset 
13048
13049  about MCS51-variants.
13050 \layout Subsection
13051
13052 HC08 Startup Code
13053 \layout Standard
13054 \added_space_bottom bigskip 
13055 The HC08
13056 \begin_inset LatexCommand \index{HC08}
13057
13058 \end_inset 
13059
13060  startup code follows the same scheme as the MCS51 startup code.
13061 \layout Subsection
13062
13063 Z80 Startup Code
13064 \layout Standard
13065 \added_space_bottom bigskip 
13066 On the Z80
13067 \begin_inset LatexCommand \index{Z80}
13068
13069 \end_inset 
13070
13071  the startup code is inserted by linking with crt0.o which is generated from
13072  sdcc/device/lib/z80/crt0.s.
13073  If you need a different startup code you can use the compiler option 
13074 \emph on 
13075 -
13076 \series bold 
13077 \emph default 
13078
13079 \begin_inset ERT
13080 status Collapsed
13081
13082 \layout Standard
13083
13084 \backslash 
13085 /
13086 \end_inset 
13087
13088
13089 \series default 
13090 \emph on 
13091 -no-std-crt0
13092 \emph default 
13093
13094 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13095
13096 \end_inset 
13097
13098  and provide your own crt0.o.
13099  
13100 \layout Section
13101
13102 Inline Assembler Code
13103 \begin_inset LatexCommand \index{Assembler routines}
13104
13105 \end_inset 
13106
13107
13108 \layout Subsection
13109
13110 A Step by Step Introduction
13111 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13112
13113 \end_inset 
13114
13115
13116 \layout Standard
13117
13118 Starting from a small snippet of c-code this example shows for the MCS51
13119  how to use inline assembly, access variables, a function parameter and
13120  an array in xdata memory.
13121  The example uses an MCS51 here but is easily adapted for other architectures.
13122  This is a buffer routine which should be optimized:
13123 \layout Verse
13124
13125
13126 \family typewriter 
13127 \size footnotesize 
13128 unsigned char __far
13129 \begin_inset LatexCommand \index{far (storage class)}
13130
13131 \end_inset 
13132
13133
13134 \begin_inset LatexCommand \index{\_\_far (storage class)}
13135
13136 \end_inset 
13137
13138  __at
13139 \begin_inset LatexCommand \index{at}
13140
13141 \end_inset 
13142
13143
13144 \begin_inset LatexCommand \index{\_\_at}
13145
13146 \end_inset 
13147
13148 (0x7f00) buf[0x100];
13149 \begin_inset LatexCommand \index{Aligned array}
13150
13151 \end_inset 
13152
13153
13154 \newline 
13155 unsigned char head, tail;\SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 \SpecialChar ~
13162 \SpecialChar ~
13163 \SpecialChar ~
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 \SpecialChar ~
13171 \SpecialChar ~
13172 /* if interrupts
13173 \begin_inset LatexCommand \index{interrupt}
13174
13175 \end_inset 
13176
13177  are involved see
13178 \newline 
13179 \SpecialChar ~
13180 \SpecialChar ~
13181 \SpecialChar ~
13182 \SpecialChar ~
13183 \SpecialChar ~
13184 \SpecialChar ~
13185 \SpecialChar ~
13186 \SpecialChar ~
13187 \SpecialChar ~
13188 \SpecialChar ~
13189 \SpecialChar ~
13190 \SpecialChar ~
13191 \SpecialChar ~
13192 \SpecialChar ~
13193 \SpecialChar ~
13194 \SpecialChar ~
13195 \SpecialChar ~
13196 \SpecialChar ~
13197 \SpecialChar ~
13198 \SpecialChar ~
13199 \SpecialChar ~
13200 \SpecialChar ~
13201 \SpecialChar ~
13202 \SpecialChar ~
13203 \SpecialChar ~
13204 \SpecialChar ~
13205 \SpecialChar ~
13206 \SpecialChar ~
13207 \SpecialChar ~
13208 \SpecialChar ~
13209 \SpecialChar ~
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 \SpecialChar ~
13214 \SpecialChar ~
13215 \SpecialChar ~
13216 \SpecialChar ~
13217 \SpecialChar ~
13218 \SpecialChar ~
13219 \SpecialChar ~
13220 \SpecialChar ~
13221 \SpecialChar ~
13222 \SpecialChar ~
13223 \SpecialChar ~
13224 section 
13225 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13226
13227 \end_inset 
13228
13229  about
13230 \series bold 
13231  volatile
13232 \series default 
13233  */
13234 \newline 
13235
13236 \newline 
13237 void to_buffer( unsigned char c ) 
13238 \newline 
13239 {
13240 \newline 
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13246 /* cast 
13247 \series bold 
13248 needed
13249 \series default 
13250  to avoid promotion
13251 \begin_inset LatexCommand \index{promotion to signed int}
13252
13253 \end_inset 
13254
13255
13256 \begin_inset LatexCommand \index{type promotion}
13257
13258 \end_inset 
13259
13260  to integer */
13261 \begin_inset Marginal
13262 collapsed true
13263
13264 \layout Standard
13265
13266
13267 \series bold 
13268 \SpecialChar ~
13269 !
13270 \end_inset 
13271
13272
13273 \newline 
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 buf[ head++ ] = c;\SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 \SpecialChar ~
13288 \SpecialChar ~
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 /* access to a 256 byte aligned array */
13299 \newline 
13300
13301 \layout Standard
13302
13303 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13304  then a corresponding buffer.asm file is generated.
13305  We define a new function 
13306 \family typewriter 
13307 to_buffer_asm()
13308 \family default 
13309  in file buffer.c in which we cut and paste the generated code, removing
13310  unwanted comments and some ':'.
13311  Then add 
13312 \begin_inset Quotes sld
13313 \end_inset 
13314
13315 _asm
13316 \begin_inset Quotes srd
13317 \end_inset 
13318
13319  and 
13320 \begin_inset Quotes sld
13321 \end_inset 
13322
13323 _endasm;
13324 \begin_inset Quotes srd
13325 \end_inset 
13326
13327  to the beginning and the end of the function body:
13328 \layout Verse
13329
13330
13331 \family typewriter 
13332 \size footnotesize 
13333 /* With a cut and paste from the .asm file, we have something to start with.
13334 \newline 
13335 \SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 The function is not yet OK! (registers aren't saved) */ 
13339 \newline 
13340 void to_buffer_asm( unsigned char c ) 
13341 \newline 
13342
13343 \newline 
13344 \SpecialChar ~
13345 \SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 _asm
13349 \begin_inset LatexCommand \index{\_asm}
13350
13351 \end_inset 
13352
13353
13354 \begin_inset LatexCommand \index{\_\_asm}
13355
13356 \end_inset 
13357
13358
13359 \newline 
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 \SpecialChar ~
13363 \SpecialChar ~
13364 mov\SpecialChar ~
13365 \SpecialChar ~
13366 r2,dpl 
13367 \newline 
13368 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13369 /* cast 
13370 \series bold 
13371 needed
13372 \series default 
13373  to avoid promotion
13374 \begin_inset LatexCommand \index{promotion to signed int}
13375
13376 \end_inset 
13377
13378
13379 \begin_inset LatexCommand \index{type promotion}
13380
13381 \end_inset 
13382
13383  to integer */
13384 \newline 
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 mov\SpecialChar ~
13390 \SpecialChar ~
13391 a,_tail 
13392 \newline 
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 dec\SpecialChar ~
13398 \SpecialChar ~
13399
13400 \newline 
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 mov\SpecialChar ~
13406 \SpecialChar ~
13407 r3,a 
13408 \newline 
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 \SpecialChar ~
13412 \SpecialChar ~
13413 mov\SpecialChar ~
13414 \SpecialChar ~
13415 a,_head 
13416 \newline 
13417 \SpecialChar ~
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 cjne a,ar3,00106$ 
13422 \newline 
13423 \SpecialChar ~
13424 \SpecialChar ~
13425 \SpecialChar ~
13426 \SpecialChar ~
13427 ret
13428 \newline 
13429 00106$: 
13430 \newline 
13431 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13432 \begin_inset LatexCommand \index{Aligned array}
13433
13434 \end_inset 
13435
13436
13437 \newline 
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 \SpecialChar ~
13442 mov\SpecialChar ~
13443 \SpecialChar ~
13444 r3,_head 
13445 \newline 
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 \SpecialChar ~
13449 \SpecialChar ~
13450 inc\SpecialChar ~
13451 \SpecialChar ~
13452 _head 
13453 \newline 
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 \SpecialChar ~
13457 \SpecialChar ~
13458 mov\SpecialChar ~
13459 \SpecialChar ~
13460 dpl,r3 
13461 \newline 
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 mov\SpecialChar ~
13467 \SpecialChar ~
13468 dph,#(_buf >> 8) 
13469 \newline 
13470 \SpecialChar ~
13471 \SpecialChar ~
13472 \SpecialChar ~
13473 \SpecialChar ~
13474 mov\SpecialChar ~
13475 \SpecialChar ~
13476 a,r2 
13477 \newline 
13478 \SpecialChar ~
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 movx @dptr,a 
13483 \newline 
13484 00103$: 
13485 \newline 
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 \SpecialChar ~
13490 ret
13491 \newline 
13492 \SpecialChar ~
13493 \SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 _endasm
13497 \begin_inset LatexCommand \index{\_endasm}
13498
13499 \end_inset 
13500
13501
13502 \begin_inset LatexCommand \index{\_\_endasm}
13503
13504 \end_inset 
13505
13506 ;
13507 \newline 
13508
13509 \layout Standard
13510
13511 The new file buffer.c should compile with only one warning about the unreferenced
13512  function argument 'c'.
13513  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13514  (1) and finally have:
13515 \layout Verse
13516
13517
13518 \family typewriter 
13519 \size footnotesize 
13520 unsigned char __far __at(0x7f00) buf[0x100];
13521 \newline 
13522 unsigned char head, tail;
13523 \newline 
13524 #define USE_ASSEMBLY (1)
13525 \newline 
13526
13527 \newline 
13528 #if !USE_ASSEMBLY
13529 \newline 
13530
13531 \newline 
13532 void to_buffer( unsigned char c )
13533 \newline 
13534 {
13535 \newline 
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 \SpecialChar ~
13539 \SpecialChar ~
13540 if( head != (unsigned char)(tail-1) )
13541 \newline 
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 \SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 buf[ head++ ] = c;
13551 \newline 
13552 }
13553 \newline 
13554
13555 \newline 
13556 #else
13557 \newline 
13558
13559 \newline 
13560 void to_buffer( unsigned char c )
13561 \newline 
13562 {
13563 \newline 
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 \SpecialChar ~
13568 c; // to avoid warning: unreferenced function argument
13569 \newline 
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 _asm
13575 \begin_inset LatexCommand \index{\_asm}
13576
13577 \end_inset 
13578
13579
13580 \begin_inset LatexCommand \index{\_\_asm}
13581
13582 \end_inset 
13583
13584
13585 \newline 
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 ; save used registers here.
13595  
13596 \newline 
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 \SpecialChar ~
13605 ; If we were still using r2,r3 we would have to push them here.
13606  
13607 \newline 
13608 ; if( head != (unsigned char)(tail-1) )
13609 \newline 
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 \SpecialChar ~
13613 \SpecialChar ~
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 mov\SpecialChar ~
13619  a,_tail
13620 \newline 
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 \SpecialChar ~
13629 dec\SpecialChar ~
13630  a
13631 \newline 
13632 \SpecialChar ~
13633 \SpecialChar ~
13634 \SpecialChar ~
13635 \SpecialChar ~
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 xrl\SpecialChar ~
13641  a,_head
13642 \newline 
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 \SpecialChar ~
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13652 \newline 
13653 \SpecialChar ~
13654 \SpecialChar ~
13655 \SpecialChar ~
13656 \SpecialChar ~
13657 \SpecialChar ~
13658 \SpecialChar ~
13659 \SpecialChar ~
13660 \SpecialChar ~
13661 jz\SpecialChar ~
13662 \SpecialChar ~
13663  t_b_end$
13664 \newline 
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 \SpecialChar ~
13668 \SpecialChar ~
13669 \SpecialChar ~
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 ;
13674 \newline 
13675 ; buf[ head++ ] = c;
13676 \newline 
13677 \SpecialChar ~
13678 \SpecialChar ~
13679 \SpecialChar ~
13680 \SpecialChar ~
13681 \SpecialChar ~
13682 \SpecialChar ~
13683 \SpecialChar ~
13684 \SpecialChar ~
13685 mov\SpecialChar ~
13686  a,dpl \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 ; dpl holds lower byte of function argument
13694 \newline 
13695 \SpecialChar ~
13696 \SpecialChar ~
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 mov\SpecialChar ~
13704  dpl,_head \SpecialChar ~
13705 \SpecialChar ~
13706 \SpecialChar ~
13707 ; buf is 0x100 byte aligned so head can be used directly
13708 \newline 
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 mov\SpecialChar ~
13718  dph,#(_buf>>8)
13719 \newline 
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 movx @dptr,a
13729 \newline 
13730 \SpecialChar ~
13731 \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 inc \SpecialChar ~
13739 _head
13740 \newline 
13741 \SpecialChar ~
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13750 \newline 
13751 t_b_end$:
13752 \newline 
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 ; restore used registers here 
13762 \newline 
13763 \SpecialChar ~
13764 \SpecialChar ~
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 _endasm
13768 \begin_inset LatexCommand \index{\_endasm}
13769
13770 \end_inset 
13771
13772
13773 \begin_inset LatexCommand \index{\_\_endasm}
13774
13775 \end_inset 
13776
13777 ;
13778 \newline 
13779 }
13780 \newline 
13781 #endif
13782 \layout Standard
13783
13784 The inline assembler code can contain any valid code understood by the assembler
13785 , this includes any assembler directives and comment lines.
13786  The assembler does not like some characters like ':' or ''' in comments.
13787  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13788 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13789
13790 \end_inset 
13791
13792
13793 \begin_inset LatexCommand \index{Assembler documentation}
13794
13795 \end_inset 
13796
13797  or online at 
13798 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13799
13800 \end_inset 
13801
13802 \SpecialChar ~
13803 .
13804 \layout Standard
13805
13806 The compiler does not do any validation of the code within the 
13807 \family typewriter 
13808 _asm
13809 \begin_inset LatexCommand \index{\_asm}
13810
13811 \end_inset 
13812
13813
13814 \begin_inset LatexCommand \index{\_\_asm}
13815
13816 \end_inset 
13817
13818  ...
13819  _endasm
13820 \size footnotesize 
13821
13822 \begin_inset LatexCommand \index{\_endasm}
13823
13824 \end_inset 
13825
13826
13827 \begin_inset LatexCommand \index{\_\_endasm}
13828
13829 \end_inset 
13830
13831
13832 \size default 
13833 ;
13834 \family default 
13835  keyword pair.
13836  Specifically it will not know which registers are used and thus register
13837  pushing/popping
13838 \begin_inset LatexCommand \index{push/pop}
13839
13840 \end_inset 
13841
13842  has to be done manually.
13843  
13844 \layout Standard
13845
13846 It is recommended that each assembly instruction (including labels) be placed
13847  in a separate line (as the example shows).
13848  When the -
13849 \begin_inset ERT
13850 status Collapsed
13851
13852 \layout Standard
13853
13854 \backslash 
13855 /
13856 \end_inset 
13857
13858 -
13859 \emph on 
13860 peep-asm
13861 \begin_inset LatexCommand \index{-\/-peep-asm}
13862
13863 \end_inset 
13864
13865
13866 \emph default 
13867  command line option is used, the inline assembler code will be passed through
13868  the peephole optimizer
13869 \begin_inset LatexCommand \index{Peephole optimizer}
13870
13871 \end_inset 
13872
13873 .
13874  There are only a few (if any) cases where this option makes sense, it might
13875  cause some unexpected changes in the inline assembler code.
13876  Please go through the peephole optimizer rules defined in file 
13877 \emph on 
13878 SDCCpeeph.def
13879 \emph default 
13880  before using this option.
13881 \layout Subsection
13882
13883 Naked Functions
13884 \begin_inset LatexCommand \label{sub:Naked-Functions}
13885
13886 \end_inset 
13887
13888
13889 \begin_inset LatexCommand \index{Naked functions}
13890
13891 \end_inset 
13892
13893
13894 \layout Standard
13895
13896 A special keyword may be associated with a function declaring it as 
13897 \emph on 
13898 _naked
13899 \begin_inset LatexCommand \index{\_naked}
13900
13901 \end_inset 
13902
13903
13904 \begin_inset LatexCommand \index{\_\_naked}
13905
13906 \end_inset 
13907
13908 .
13909  
13910 \emph default 
13911 The 
13912 \emph on 
13913 _naked
13914 \emph default 
13915  function modifier attribute prevents the compiler from generating prologue
13916 \begin_inset LatexCommand \index{function prologue}
13917
13918 \end_inset 
13919
13920  and epilogue
13921 \begin_inset LatexCommand \index{function epilogue}
13922
13923 \end_inset 
13924
13925  code for that function.
13926  This means that the user is entirely responsible for such things as saving
13927  any registers that may need to be preserved, selecting the proper register
13928  bank, generating the 
13929 \emph on 
13930 return
13931 \emph default 
13932  instruction at the end, etc.
13933  Practically, this means that the contents of the function must be written
13934  in inline assembler.
13935  This is particularly useful for interrupt functions, which can have a large
13936  (and often unnecessary) prologue/epilogue.
13937  For example, compare the code generated by these two functions:
13938 \layout Verse
13939
13940
13941 \family typewriter 
13942 volatile
13943 \begin_inset LatexCommand \index{volatile}
13944
13945 \end_inset 
13946
13947  data unsigned char counter;
13948 \newline 
13949
13950 \newline 
13951 void simpleInterrupt(void) __interrupt
13952 \begin_inset LatexCommand \index{interrupt}
13953
13954 \end_inset 
13955
13956
13957 \begin_inset LatexCommand \index{\_\_interrupt}
13958
13959 \end_inset 
13960
13961  (1)
13962 \newline 
13963 {
13964 \newline 
13965 \SpecialChar ~
13966 \SpecialChar ~
13967 \SpecialChar ~
13968 \SpecialChar ~
13969 counter++;
13970 \newline 
13971 }
13972 \newline 
13973
13974 \newline 
13975 void nakedInterrupt(void) __interrupt (2) __naked
13976 \newline 
13977 {
13978 \newline 
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 _asm
13984 \begin_inset LatexCommand \index{\_asm}
13985
13986 \end_inset 
13987
13988
13989 \begin_inset LatexCommand \index{\_\_asm}
13990
13991 \end_inset 
13992
13993
13994 \newline 
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 \SpecialChar ~
14000 \SpecialChar ~
14001 inc\SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 _counter ; does not change flags, no need to save psw
14007 \newline 
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 \SpecialChar ~
14011 \SpecialChar ~
14012 \SpecialChar ~
14013 \SpecialChar ~
14014 reti\SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 ; MUST explicitly include ret or reti in _naked function.
14019 \newline 
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 _endasm
14025 \begin_inset LatexCommand \index{\_endasm}
14026
14027 \end_inset 
14028
14029
14030 \begin_inset LatexCommand \index{\_\_endasm}
14031
14032 \end_inset 
14033
14034 ;
14035 \newline 
14036 }
14037 \layout Standard
14038
14039 For an 8051 target, the generated simpleInterrupt looks like:
14040 \layout Verse
14041
14042
14043 \family typewriter 
14044 Note, this is an 
14045 \emph on 
14046 outdated
14047 \emph default 
14048  example, recent versions of SDCC generate
14049 \newline 
14050 the 
14051 \emph on 
14052 same
14053 \emph default 
14054  code for simpleInterrupt() and nakedInterrupt()!
14055 \newline 
14056
14057 \newline 
14058 _simpleInterrupt:
14059 \newline 
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 \SpecialChar ~
14063 \SpecialChar ~
14064 push\SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 acc
14069 \newline 
14070 \SpecialChar ~
14071 \SpecialChar ~
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 push\SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 b
14079 \newline 
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 push\SpecialChar ~
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 dpl
14089 \newline 
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 push\SpecialChar ~
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 dph
14099 \newline 
14100 \SpecialChar ~
14101 \SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 push\SpecialChar ~
14105 \SpecialChar ~
14106 \SpecialChar ~
14107 \SpecialChar ~
14108 psw
14109 \newline 
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 mov\SpecialChar ~
14115 \SpecialChar ~
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 \SpecialChar ~
14119 psw,#0x00
14120 \newline 
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 inc\SpecialChar ~
14126 \SpecialChar ~
14127 \SpecialChar ~
14128 \SpecialChar ~
14129 \SpecialChar ~
14130 _counter
14131 \newline 
14132 \SpecialChar ~
14133 \SpecialChar ~
14134 \SpecialChar ~
14135 \SpecialChar ~
14136 pop\SpecialChar ~
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 psw
14142 \newline 
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 pop\SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 dph
14153 \newline 
14154 \SpecialChar ~
14155 \SpecialChar ~
14156 \SpecialChar ~
14157 \SpecialChar ~
14158 pop\SpecialChar ~
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 dpl
14164 \newline 
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 pop\SpecialChar ~
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 b
14175 \newline 
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 pop\SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 acc
14186 \newline 
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 reti
14192 \layout Standard
14193
14194 whereas nakedInterrupt looks like:
14195 \layout Verse
14196
14197
14198 \family typewriter 
14199 _nakedInterrupt:
14200 \newline 
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 inc\SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 \SpecialChar ~
14209 _counter ; does not change flags, no need to save psw
14210 \newline 
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 \SpecialChar ~
14215 reti\SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 \SpecialChar ~
14226 \SpecialChar ~
14227 ; MUST explicitly include ret or reti in _naked function
14228 \layout Standard
14229
14230 The related directive #pragma exclude
14231 \begin_inset LatexCommand \index{\#pragma exclude}
14232
14233 \end_inset 
14234
14235  allows a more fine grained control over pushing & popping
14236 \begin_inset LatexCommand \index{push/pop}
14237
14238 \end_inset 
14239
14240  the registers.
14241 \layout Standard
14242
14243 While there is nothing preventing you from writing C code inside a 
14244 \family typewriter 
14245 _naked
14246 \family default 
14247  function, there are many ways to shoot yourself in the foot doing this,
14248  and it is recommended that you stick to inline assembler.
14249 \layout Subsection
14250
14251 Use of Labels within Inline Assembler
14252 \layout Standard
14253
14254 SDCC allows the use of in-line assembler with a few restrictions regarding
14255  labels.
14256  In older versions of the compiler all labels defined within inline assembler
14257  code 
14258 \emph on 
14259 had to be
14260 \emph default 
14261  of the form 
14262 \emph on 
14263 nnnnn$
14264 \emph default 
14265  where nnnn is a number less than 100 (which implies a limit of utmost 100
14266  inline assembler labels 
14267 \emph on 
14268 per function
14269 \emph default 
14270 \noun on 
14271 )
14272 \noun default 
14273 .
14274  
14275 \layout Verse
14276
14277
14278 \family typewriter 
14279 _asm
14280 \begin_inset LatexCommand \index{\_asm}
14281
14282 \end_inset 
14283
14284
14285 \begin_inset LatexCommand \index{\_\_asm}
14286
14287 \end_inset 
14288
14289  
14290 \newline 
14291 \SpecialChar ~
14292 \SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 mov\SpecialChar ~
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 b,#10 
14301 \newline 
14302 00001$: 
14303 \newline 
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 djnz\SpecialChar ~
14309 \SpecialChar ~
14310 \SpecialChar ~
14311 \SpecialChar ~
14312 b,00001$ 
14313 \newline 
14314 _endasm
14315 \begin_inset LatexCommand \index{\_endasm}
14316
14317 \end_inset 
14318
14319
14320 \begin_inset LatexCommand \index{\_\_endasm}
14321
14322 \end_inset 
14323
14324  ;
14325 \layout Standard
14326
14327 Inline assembler code cannot reference any C-Labels, however it can reference
14328  labels
14329 \begin_inset LatexCommand \index{Labels}
14330
14331 \end_inset 
14332
14333  defined by the inline assembler, e.g.:
14334 \layout Verse
14335
14336
14337 \family typewriter 
14338 foo() { 
14339 \newline 
14340 \SpecialChar ~
14341 \SpecialChar ~
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 /* some c code */ 
14345 \newline 
14346 \SpecialChar ~
14347 \SpecialChar ~
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 _asm 
14351 \newline 
14352 \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 \SpecialChar ~
14356 \SpecialChar ~
14357 \SpecialChar ~
14358 ; some assembler code 
14359 \newline 
14360 \SpecialChar ~
14361 \SpecialChar ~
14362 \SpecialChar ~
14363 \SpecialChar ~
14364 \SpecialChar ~
14365 \SpecialChar ~
14366 ljmp $0003 
14367 \newline 
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 _endasm; 
14373 \newline 
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 \SpecialChar ~
14378 /* some more c code */ 
14379 \newline 
14380 clabel:\SpecialChar ~
14381 \SpecialChar ~
14382 /* inline assembler cannot reference this label */ 
14383 \newline 
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 _asm
14389 \newline 
14390 \SpecialChar ~
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 $0003: ;label (can be referenced by inline assembler only) 
14395 \newline 
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 _endasm
14401 \begin_inset LatexCommand \index{\_endasm}
14402
14403 \end_inset 
14404
14405
14406 \begin_inset LatexCommand \index{\_\_endasm}
14407
14408 \end_inset 
14409
14410  ; 
14411 \newline 
14412 \SpecialChar ~
14413 \SpecialChar ~
14414 \SpecialChar ~
14415 \SpecialChar ~
14416 /* some more c code */
14417 \newline 
14418 }
14419 \layout Standard
14420
14421 In other words inline assembly code can access labels defined in inline
14422  assembly within the scope of the function.
14423  The same goes the other way, i.e.
14424  labels defines in inline assembly can not be accessed by C statements.
14425 \layout Section
14426
14427 Interfacing with Assembler Code
14428 \begin_inset LatexCommand \index{Assembler routines}
14429
14430 \end_inset 
14431
14432
14433 \layout Subsection
14434
14435 Global Registers used for Parameter Passing
14436 \begin_inset LatexCommand \index{Parameter passing}
14437
14438 \end_inset 
14439
14440
14441 \layout Standard
14442
14443 The compiler always uses the global registers 
14444 \emph on 
14445 DPL, DPH
14446 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14447
14448 \end_inset 
14449
14450
14451 \begin_inset LatexCommand \index{DPTR}
14452
14453 \end_inset 
14454
14455 , B
14456 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14457
14458 \end_inset 
14459
14460  
14461 \emph default 
14462 and
14463 \emph on 
14464  ACC
14465 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14466
14467 \end_inset 
14468
14469
14470 \emph default 
14471  to pass the first parameter to a routine.
14472  The second parameter onwards is either allocated on the stack (for reentrant
14473  routines or if -
14474 \begin_inset ERT
14475 status Collapsed
14476
14477 \layout Standard
14478
14479 \backslash 
14480 /
14481 \end_inset 
14482
14483 -stack-auto is used) or in data / xdata memory (depending on the memory
14484  model).
14485  
14486 \layout Subsection
14487
14488 Assembler Routine (non-reentrant)
14489 \layout Standard
14490
14491 In the following example
14492 \begin_inset LatexCommand \index{reentrant}
14493
14494 \end_inset 
14495
14496
14497 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14498
14499 \end_inset 
14500
14501  the function c_func calls an assembler routine asm_func, which takes two
14502  parameters
14503 \begin_inset LatexCommand \index{function parameter}
14504
14505 \end_inset 
14506
14507 .
14508 \layout Verse
14509
14510
14511 \family typewriter 
14512 extern int asm_func(unsigned char, unsigned char);
14513 \newline 
14514
14515 \newline 
14516 int c_func (unsigned char i, unsigned char j)
14517 \newline 
14518 {
14519 \newline 
14520 \SpecialChar ~
14521 \SpecialChar ~
14522 \SpecialChar ~
14523 \SpecialChar ~
14524 return asm_func(i,j);
14525 \newline 
14526 }
14527 \newline 
14528
14529 \newline 
14530 int main()
14531 \newline 
14532 {
14533 \newline 
14534 \SpecialChar ~
14535 \SpecialChar ~
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 return c_func(10,9);
14539 \newline 
14540 }
14541 \layout Standard
14542
14543 The corresponding assembler function is:
14544 \layout Verse
14545
14546
14547 \family typewriter 
14548 .globl _asm_func_PARM_2 
14549 \newline 
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 \SpecialChar ~
14554 \SpecialChar ~
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 .globl _asm_func 
14559 \newline 
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 \SpecialChar ~
14564 \SpecialChar ~
14565 \SpecialChar ~
14566 \SpecialChar ~
14567 \SpecialChar ~
14568 .area OSEG 
14569 \newline 
14570 _asm_func_PARM_2:
14571 \newline 
14572 \SpecialChar ~
14573 \SpecialChar ~
14574 \SpecialChar ~
14575 \SpecialChar ~
14576 \SpecialChar ~
14577 \SpecialChar ~
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 .ds    1 
14581 \newline 
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 \SpecialChar ~
14585 \SpecialChar ~
14586 \SpecialChar ~
14587 \SpecialChar ~
14588 \SpecialChar ~
14589 \SpecialChar ~
14590 .area CSEG 
14591 \newline 
14592 _asm_func: 
14593 \newline 
14594 \SpecialChar ~
14595 \SpecialChar ~
14596 \SpecialChar ~
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 \SpecialChar ~
14600 \SpecialChar ~
14601 \SpecialChar ~
14602 mov\SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 a,dpl 
14607 \newline 
14608 \SpecialChar ~
14609 \SpecialChar ~
14610 \SpecialChar ~
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 \SpecialChar ~
14616 add\SpecialChar ~
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 \SpecialChar ~
14620 a,_asm_func_PARM_2 
14621 \newline 
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 \SpecialChar ~
14625 \SpecialChar ~
14626 \SpecialChar ~
14627 \SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 mov\SpecialChar ~
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 \SpecialChar ~
14634 dpl,a 
14635 \newline 
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 mov\SpecialChar ~
14645 \SpecialChar ~
14646 \SpecialChar ~
14647 \SpecialChar ~
14648 dph
14649 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14650
14651 \end_inset 
14652
14653 ,#0x00 
14654 \newline 
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 ret
14664 \layout Standard
14665
14666 Note here that the return values
14667 \begin_inset LatexCommand \index{return value}
14668
14669 \end_inset 
14670
14671  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14672  two byte values.
14673  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14674 b' & 'acc' for four byte values.
14675 \layout Standard
14676
14677 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14678  the parameter number starting from 1, and counting from the left.
14679  The first parameter is passed in 
14680 \begin_inset Quotes eld
14681 \end_inset 
14682
14683 dpl
14684 \begin_inset Quotes erd
14685 \end_inset 
14686
14687  for a one byte parameter, 
14688 \begin_inset Quotes eld
14689 \end_inset 
14690
14691 dptr
14692 \begin_inset Quotes erd
14693 \end_inset 
14694
14695  for two bytes, 
14696 \begin_inset Quotes eld
14697 \end_inset 
14698
14699 b,dptr
14700 \begin_inset Quotes erd
14701 \end_inset 
14702
14703  for three bytes and 
14704 \begin_inset Quotes eld
14705 \end_inset 
14706
14707 acc,b,dptr
14708 \begin_inset Quotes erd
14709 \end_inset 
14710
14711  for a four bytes parameter.
14712  The variable name for the second parameter will be _<function_name>_PARM_2.
14713 \newline 
14714
14715 \newline 
14716 Assemble the assembler routine with the following command:
14717 \newline 
14718
14719 \newline 
14720
14721 \family sans 
14722 \series bold 
14723 asx8051 -losg asmfunc.asm
14724 \newline 
14725
14726 \newline 
14727
14728 \family default 
14729 \series default 
14730 Then compile and link the assembler routine to the C source file with the
14731  following command:
14732 \newline 
14733
14734 \newline 
14735
14736 \family sans 
14737 \series bold 
14738 sdcc cfunc.c asmfunc.rel
14739 \layout Subsection
14740
14741 Assembler Routine (reentrant)
14742 \layout Standard
14743
14744 In this case
14745 \begin_inset LatexCommand \index{reentrant}
14746
14747 \end_inset 
14748
14749
14750 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14751
14752 \end_inset 
14753
14754  the second parameter
14755 \begin_inset LatexCommand \index{function parameter}
14756
14757 \end_inset 
14758
14759  onwards will be passed on the stack, the parameters are pushed from right
14760  to left i.e.
14761  after the call the leftmost parameter will be on the top of the stack.
14762  Here is an example:
14763 \layout Verse
14764
14765
14766 \family typewriter 
14767 extern int asm_func(unsigned char, unsigned char);
14768 \newline 
14769
14770 \newline 
14771 int c_func (unsigned char i, unsigned char j) reentrant 
14772 \newline 
14773
14774 \newline 
14775 \SpecialChar ~
14776 \SpecialChar ~
14777 \SpecialChar ~
14778 \SpecialChar ~
14779 return asm_func(i,j); 
14780 \newline 
14781
14782 \newline 
14783
14784 \newline 
14785 int main() 
14786 \newline 
14787
14788 \newline 
14789 \SpecialChar ~
14790 \SpecialChar ~
14791 \SpecialChar ~
14792 \SpecialChar ~
14793 return c_func(10,9); 
14794 \newline 
14795 }
14796 \layout Standard
14797
14798 The corresponding assembler routine is:
14799 \layout Verse
14800
14801
14802 \family typewriter 
14803 .globl _asm_func 
14804 \newline 
14805 _asm_func: 
14806 \newline 
14807 \SpecialChar ~
14808 \SpecialChar ~
14809 \SpecialChar ~
14810 \SpecialChar ~
14811 push  _bp 
14812 \newline 
14813 \SpecialChar ~
14814 \SpecialChar ~
14815 \SpecialChar ~
14816 \SpecialChar ~
14817 mov _bp,sp 
14818 \newline 
14819 \SpecialChar ~
14820 \SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 mov r2,dpl
14824 \newline 
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 \SpecialChar ~
14829 mov a,_bp 
14830 \newline 
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 \SpecialChar ~
14834 \SpecialChar ~
14835 add a,#0xfd 
14836 \newline 
14837 \SpecialChar ~
14838 \SpecialChar ~
14839 \SpecialChar ~
14840 \SpecialChar ~
14841 mov r0,a 
14842 \newline 
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 \SpecialChar ~
14846 \SpecialChar ~
14847 add  a,#0xfc ;?
14848 \newline 
14849 \SpecialChar ~
14850 \SpecialChar ~
14851 \SpecialChar ~
14852 \SpecialChar ~
14853 mov  r1,a 
14854 \newline 
14855 \SpecialChar ~
14856 \SpecialChar ~
14857 \SpecialChar ~
14858 \SpecialChar ~
14859 mov  a,@r0 
14860 \newline 
14861 \SpecialChar ~
14862 \SpecialChar ~
14863 \SpecialChar ~
14864 \SpecialChar ~
14865 add  a,r2 ;?
14866 \newline 
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 mov  dpl,a 
14872 \newline 
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 mov  dph,#0x00 
14878 \newline 
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 mov  sp,_bp 
14884 \newline 
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 \SpecialChar ~
14888 \SpecialChar ~
14889 pop  _bp 
14890 \newline 
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 ret
14896 \layout Standard
14897 \added_space_bottom bigskip 
14898 The compiling and linking procedure remains the same, however note the extra
14899  entry & exit linkage required for the assembler code, _bp is the stack
14900  frame pointer and is used to compute the offset into the stack for parameters
14901  and local variables.
14902 \layout Section
14903
14904 int (16 bit)
14905 \begin_inset LatexCommand \index{int (16 bit)}
14906
14907 \end_inset 
14908
14909  and long (32 bit)
14910 \begin_inset LatexCommand \index{long (32 bit)}
14911
14912 \end_inset 
14913
14914  Support
14915 \layout Standard
14916
14917 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14918  multiplication and modulus operations are implemented by support routines.
14919  These support routines are all developed in ANSI-C to facilitate porting
14920  to other MCUs, although some model specific assembler optimizations are
14921  used.
14922  The following files contain the described routines, all of them can be
14923  found in <installdir>/share/sdcc/lib.
14924 \newline 
14925
14926 \layout Standard
14927 \align center 
14928
14929 \begin_inset  Tabular
14930 <lyxtabular version="3" rows="11" columns="2">
14931 <features>
14932 <column alignment="left" valignment="top" leftline="true" width="0">
14933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14934 <row topline="true" bottomline="true">
14935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14936 \begin_inset Text
14937
14938 \layout Standard
14939
14940
14941 \series bold 
14942 Function
14943 \end_inset 
14944 </cell>
14945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14946 \begin_inset Text
14947
14948 \layout Standard
14949
14950
14951 \series bold 
14952 Description
14953 \end_inset 
14954 </cell>
14955 </row>
14956 <row topline="true">
14957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14958 \begin_inset Text
14959
14960 \layout Standard
14961
14962 _mulint.c 
14963 \end_inset 
14964 </cell>
14965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14966 \begin_inset Text
14967
14968 \layout Standard
14969
14970 16 bit multiplication
14971 \end_inset 
14972 </cell>
14973 </row>
14974 <row topline="true">
14975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14976 \begin_inset Text
14977
14978 \layout Standard
14979
14980 _divsint.c 
14981 \end_inset 
14982 </cell>
14983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14984 \begin_inset Text
14985
14986 \layout Standard
14987
14988  signed 16 bit division (calls _divuint)
14989 \end_inset 
14990 </cell>
14991 </row>
14992 <row topline="true">
14993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14994 \begin_inset Text
14995
14996 \layout Standard
14997
14998 _divuint.c 
14999 \end_inset 
15000 </cell>
15001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15002 \begin_inset Text
15003
15004 \layout Standard
15005
15006  unsigned 16 bit division
15007 \end_inset 
15008 </cell>
15009 </row>
15010 <row topline="true">
15011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15012 \begin_inset Text
15013
15014 \layout Standard
15015
15016 _modsint.c
15017 \end_inset 
15018 </cell>
15019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15020 \begin_inset Text
15021
15022 \layout Standard
15023
15024 signed 16 bit modulus (calls _moduint)
15025 \end_inset 
15026 </cell>
15027 </row>
15028 <row topline="true">
15029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15030 \begin_inset Text
15031
15032 \layout Standard
15033
15034 _moduint.c
15035 \end_inset 
15036 </cell>
15037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15038 \begin_inset Text
15039
15040 \layout Standard
15041
15042 unsigned 16 bit modulus
15043 \end_inset 
15044 </cell>
15045 </row>
15046 <row topline="true">
15047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15048 \begin_inset Text
15049
15050 \layout Standard
15051
15052 _mullong.c
15053 \end_inset 
15054 </cell>
15055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15056 \begin_inset Text
15057
15058 \layout Standard
15059
15060 32 bit multiplication
15061 \end_inset 
15062 </cell>
15063 </row>
15064 <row topline="true">
15065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15066 \begin_inset Text
15067
15068 \layout Standard
15069
15070 _divslong.c 
15071 \end_inset 
15072 </cell>
15073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15074 \begin_inset Text
15075
15076 \layout Standard
15077
15078  signed 32 division (calls _divulong)
15079 \end_inset 
15080 </cell>
15081 </row>
15082 <row topline="true">
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15084 \begin_inset Text
15085
15086 \layout Standard
15087
15088 _divulong.c 
15089 \end_inset 
15090 </cell>
15091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15092 \begin_inset Text
15093
15094 \layout Standard
15095
15096 unsigned 32 division
15097 \end_inset 
15098 </cell>
15099 </row>
15100 <row topline="true">
15101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15102 \begin_inset Text
15103
15104 \layout Standard
15105
15106 _modslong.c
15107 \end_inset 
15108 </cell>
15109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15110 \begin_inset Text
15111
15112 \layout Standard
15113
15114  signed 32 bit modulus (calls _modulong)
15115 \end_inset 
15116 </cell>
15117 </row>
15118 <row topline="true" bottomline="true">
15119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15120 \begin_inset Text
15121
15122 \layout Standard
15123
15124 _modulong.c
15125 \end_inset 
15126 </cell>
15127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15128 \begin_inset Text
15129
15130 \layout Standard
15131
15132 unsigned 32 bit modulus
15133 \end_inset 
15134 </cell>
15135 </row>
15136 </lyxtabular>
15137
15138 \end_inset 
15139
15140
15141 \newline 
15142
15143 \layout Standard
15144
15145 Since they are compiled as 
15146 \emph on 
15147 non-reentrant
15148 \emph default 
15149
15150 \begin_inset LatexCommand \index{reentrant}
15151
15152 \end_inset 
15153
15154 , interrupt
15155 \begin_inset LatexCommand \index{interrupt}
15156
15157 \end_inset 
15158
15159  service routines should not do any of the above operations.
15160  If this is unavoidable then the above routines will need to be compiled
15161  with the 
15162 \emph on 
15163 -
15164 \begin_inset ERT
15165 status Collapsed
15166
15167 \layout Standard
15168
15169 \backslash 
15170 /
15171 \end_inset 
15172
15173 -stack-auto
15174 \begin_inset LatexCommand \index{-\/-stack-auto}
15175
15176 \end_inset 
15177
15178
15179 \emph default 
15180  option, after which the source program will have to be compiled with 
15181 \emph on 
15182 -
15183 \begin_inset ERT
15184 status Collapsed
15185
15186 \layout Standard
15187
15188 \backslash 
15189 /
15190 \end_inset 
15191
15192 -int-long-reent
15193 \begin_inset LatexCommand \index{-\/-int-long-reent}
15194
15195 \end_inset 
15196
15197
15198 \emph default 
15199  option.
15200  Notice that you don't have to call these routines directly.
15201  The compiler will use them automatically every time an integer operation
15202  is required.
15203 \layout Section
15204
15205 Floating Point Support
15206 \begin_inset LatexCommand \index{Floating point support}
15207
15208 \end_inset 
15209
15210
15211 \layout Standard
15212
15213 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15214  The floating point support routines are derived from gcc's floatlib.c and
15215  consist of the following routines:
15216 \newline 
15217
15218 \layout Standard
15219 \align center 
15220
15221 \size footnotesize 
15222
15223 \begin_inset  Tabular
15224 <lyxtabular version="3" rows="17" columns="2">
15225 <features>
15226 <column alignment="left" valignment="top" leftline="true" width="0">
15227 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15228 <row topline="true" bottomline="true">
15229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15230 \begin_inset Text
15231
15232 \layout Standard
15233
15234
15235 \family roman 
15236 \series medium 
15237 \shape up 
15238 \size normal 
15239 \emph off 
15240 \bar no 
15241 \noun off 
15242 \color none
15243 Function 
15244 \end_inset 
15245 </cell>
15246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15247 \begin_inset Text
15248
15249 \layout Standard
15250
15251 Description
15252 \end_inset 
15253 </cell>
15254 </row>
15255 <row topline="true">
15256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15257 \begin_inset Text
15258
15259 \layout Standard
15260
15261
15262 \family roman 
15263 \series medium 
15264 \shape up 
15265 \size normal 
15266 \emph off 
15267 \bar no 
15268 \noun off 
15269 \color none
15270 _fsadd.c
15271 \end_inset 
15272 </cell>
15273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15274 \begin_inset Text
15275
15276 \layout Standard
15277
15278
15279 \family roman 
15280 \series medium 
15281 \shape up 
15282 \size normal 
15283 \emph off 
15284 \bar no 
15285 \noun off 
15286 \color none
15287 add floating point numbers
15288 \end_inset 
15289 </cell>
15290 </row>
15291 <row topline="true">
15292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15293 \begin_inset Text
15294
15295 \layout Standard
15296
15297
15298 \family roman 
15299 \series medium 
15300 \shape up 
15301 \size normal 
15302 \emph off 
15303 \bar no 
15304 \noun off 
15305 \color none
15306 _fssub.c 
15307 \end_inset 
15308 </cell>
15309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15310 \begin_inset Text
15311
15312 \layout Standard
15313
15314
15315 \family roman 
15316 \series medium 
15317 \shape up 
15318 \size normal 
15319 \emph off 
15320 \bar no 
15321 \noun off 
15322 \color none
15323 subtract floating point numbers 
15324 \end_inset 
15325 </cell>
15326 </row>
15327 <row topline="true">
15328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15329 \begin_inset Text
15330
15331 \layout Standard
15332
15333
15334 \family roman 
15335 \series medium 
15336 \shape up 
15337 \size normal 
15338 \emph off 
15339 \bar no 
15340 \noun off 
15341 \color none
15342 _fsdiv.c 
15343 \end_inset 
15344 </cell>
15345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15346 \begin_inset Text
15347
15348 \layout Standard
15349
15350
15351 \family roman 
15352 \series medium 
15353 \shape up 
15354 \size normal 
15355 \emph off 
15356 \bar no 
15357 \noun off 
15358 \color none
15359 divide floating point numbers 
15360 \end_inset 
15361 </cell>
15362 </row>
15363 <row topline="true">
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15365 \begin_inset Text
15366
15367 \layout Standard
15368
15369
15370 \family roman 
15371 \series medium 
15372 \shape up 
15373 \size normal 
15374 \emph off 
15375 \bar no 
15376 \noun off 
15377 \color none
15378 _fsmul.c 
15379 \end_inset 
15380 </cell>
15381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15382 \begin_inset Text
15383
15384 \layout Standard
15385
15386
15387 \family roman 
15388 \series medium 
15389 \shape up 
15390 \size normal 
15391 \emph off 
15392 \bar no 
15393 \noun off 
15394 \color none
15395 multiply floating point numbers 
15396 \end_inset 
15397 </cell>
15398 </row>
15399 <row topline="true">
15400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15401 \begin_inset Text
15402
15403 \layout Standard
15404
15405
15406 \family roman 
15407 \series medium 
15408 \shape up 
15409 \size normal 
15410 \emph off 
15411 \bar no 
15412 \noun off 
15413 \color none
15414 _fs2uchar.c
15415 \end_inset 
15416 </cell>
15417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15418 \begin_inset Text
15419
15420 \layout Standard
15421
15422
15423 \family roman 
15424 \series medium 
15425 \shape up 
15426 \size normal 
15427 \emph off 
15428 \bar no 
15429 \noun off 
15430 \color none
15431 convert floating point to unsigned char
15432 \end_inset 
15433 </cell>
15434 </row>
15435 <row topline="true">
15436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15437 \begin_inset Text
15438
15439 \layout Standard
15440
15441
15442 \family roman 
15443 \series medium 
15444 \shape up 
15445 \size normal 
15446 \emph off 
15447 \bar no 
15448 \noun off 
15449 \color none
15450 _fs2char.c
15451 \end_inset 
15452 </cell>
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15454 \begin_inset Text
15455
15456 \layout Standard
15457
15458
15459 \family roman 
15460 \series medium 
15461 \shape up 
15462 \size normal 
15463 \emph off 
15464 \bar no 
15465 \noun off 
15466 \color none
15467 convert floating point to signed char
15468 \end_inset 
15469 </cell>
15470 </row>
15471 <row topline="true">
15472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15473 \begin_inset Text
15474
15475 \layout Standard
15476
15477
15478 \family roman 
15479 \series medium 
15480 \shape up 
15481 \size normal 
15482 \emph off 
15483 \bar no 
15484 \noun off 
15485 \color none
15486 _fs2uint.c
15487 \end_inset 
15488 </cell>
15489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15490 \begin_inset Text
15491
15492 \layout Standard
15493
15494
15495 \family roman 
15496 \series medium 
15497 \shape up 
15498 \size normal 
15499 \emph off 
15500 \bar no 
15501 \noun off 
15502 \color none
15503 convert floating point to unsigned int
15504 \end_inset 
15505 </cell>
15506 </row>
15507 <row topline="true">
15508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15509 \begin_inset Text
15510
15511 \layout Standard
15512
15513
15514 \family roman 
15515 \series medium 
15516 \shape up 
15517 \size normal 
15518 \emph off 
15519 \bar no 
15520 \noun off 
15521 \color none
15522 _fs2int.c
15523 \end_inset 
15524 </cell>
15525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15526 \begin_inset Text
15527
15528 \layout Standard
15529
15530
15531 \family roman 
15532 \series medium 
15533 \shape up 
15534 \size normal 
15535 \emph off 
15536 \bar no 
15537 \noun off 
15538 \color none
15539 convert floating point to signed int
15540 \end_inset 
15541 </cell>
15542 </row>
15543 <row topline="true">
15544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15545 \begin_inset Text
15546
15547 \layout Standard
15548
15549
15550 \family roman 
15551 \series medium 
15552 \shape up 
15553 \size normal 
15554 \emph off 
15555 \bar no 
15556 \noun off 
15557 \color none
15558 _fs2ulong.
15559 \family default 
15560 \series default 
15561 \shape default 
15562 \size default 
15563 \emph default 
15564 \bar default 
15565 \noun default 
15566 \color default
15567 c
15568 \end_inset 
15569 </cell>
15570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15571 \begin_inset Text
15572
15573 \layout Standard
15574
15575
15576 \family roman 
15577 \series medium 
15578 \shape up 
15579 \size normal 
15580 \emph off 
15581 \bar no 
15582 \noun off 
15583 \color none
15584 convert floating point to unsigned long
15585 \end_inset 
15586 </cell>
15587 </row>
15588 <row topline="true">
15589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15590 \begin_inset Text
15591
15592 \layout Standard
15593
15594
15595 \family roman 
15596 \series medium 
15597 \shape up 
15598 \size normal 
15599 \emph off 
15600 \bar no 
15601 \noun off 
15602 \color none
15603 _fs2long.c
15604 \end_inset 
15605 </cell>
15606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15607 \begin_inset Text
15608
15609 \layout Standard
15610
15611
15612 \family roman 
15613 \series medium 
15614 \shape up 
15615 \size normal 
15616 \emph off 
15617 \bar no 
15618 \noun off 
15619 \color none
15620 convert floating point to signed long
15621 \end_inset 
15622 </cell>
15623 </row>
15624 <row topline="true">
15625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15626 \begin_inset Text
15627
15628 \layout Standard
15629
15630
15631 \family roman 
15632 \series medium 
15633 \shape up 
15634 \size normal 
15635 \emph off 
15636 \bar no 
15637 \noun off 
15638 \color none
15639 _uchar2fs.c
15640 \end_inset 
15641 </cell>
15642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15643 \begin_inset Text
15644
15645 \layout Standard
15646
15647
15648 \family roman 
15649 \series medium 
15650 \shape up 
15651 \size normal 
15652 \emph off 
15653 \bar no 
15654 \noun off 
15655 \color none
15656 convert unsigned char to floating point
15657 \end_inset 
15658 </cell>
15659 </row>
15660 <row topline="true">
15661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15662 \begin_inset Text
15663
15664 \layout Standard
15665
15666
15667 \family roman 
15668 \series medium 
15669 \shape up 
15670 \size normal 
15671 \emph off 
15672 \bar no 
15673 \noun off 
15674 \color none
15675 _char2fs.c
15676 \end_inset 
15677 </cell>
15678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15679 \begin_inset Text
15680
15681 \layout Standard
15682
15683
15684 \family roman 
15685 \series medium 
15686 \shape up 
15687 \size normal 
15688 \emph off 
15689 \bar no 
15690 \noun off 
15691 \color none
15692 convert char to floating point number
15693 \end_inset 
15694 </cell>
15695 </row>
15696 <row topline="true">
15697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15698 \begin_inset Text
15699
15700 \layout Standard
15701
15702
15703 \family roman 
15704 \series medium 
15705 \shape up 
15706 \size normal 
15707 \emph off 
15708 \bar no 
15709 \noun off 
15710 \color none
15711 _uint2fs.c
15712 \end_inset 
15713 </cell>
15714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15715 \begin_inset Text
15716
15717 \layout Standard
15718
15719
15720 \family roman 
15721 \series medium 
15722 \shape up 
15723 \size normal 
15724 \emph off 
15725 \bar no 
15726 \noun off 
15727 \color none
15728 convert unsigned int to floating point
15729 \end_inset 
15730 </cell>
15731 </row>
15732 <row topline="true">
15733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15734 \begin_inset Text
15735
15736 \layout Standard
15737
15738
15739 \family roman 
15740 \series medium 
15741 \shape up 
15742 \size normal 
15743 \emph off 
15744 \bar no 
15745 \noun off 
15746 \color none
15747 _int2fs.c
15748 \end_inset 
15749 </cell>
15750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15751 \begin_inset Text
15752
15753 \layout Standard
15754
15755
15756 \family roman 
15757 \series medium 
15758 \shape up 
15759 \size normal 
15760 \emph off 
15761 \bar no 
15762 \noun off 
15763 \color none
15764 convert int to floating point numbers
15765 \end_inset 
15766 </cell>
15767 </row>
15768 <row topline="true">
15769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15770 \begin_inset Text
15771
15772 \layout Standard
15773
15774
15775 \family roman 
15776 \series medium 
15777 \shape up 
15778 \size normal 
15779 \emph off 
15780 \bar no 
15781 \noun off 
15782 \color none
15783 _ulong2fs.c
15784 \end_inset 
15785 </cell>
15786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15787 \begin_inset Text
15788
15789 \layout Standard
15790
15791
15792 \family roman 
15793 \series medium 
15794 \shape up 
15795 \size normal 
15796 \emph off 
15797 \bar no 
15798 \noun off 
15799 \color none
15800 convert unsigned long to floating point number
15801 \end_inset 
15802 </cell>
15803 </row>
15804 <row topline="true" bottomline="true">
15805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15806 \begin_inset Text
15807
15808 \layout Standard
15809
15810
15811 \family roman 
15812 \series medium 
15813 \shape up 
15814 \size normal 
15815 \emph off 
15816 \bar no 
15817 \noun off 
15818 \color none
15819 _long2fs.c
15820 \end_inset 
15821 </cell>
15822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15823 \begin_inset Text
15824
15825 \layout Standard
15826
15827
15828 \family roman 
15829 \series medium 
15830 \shape up 
15831 \size normal 
15832 \emph off 
15833 \bar no 
15834 \noun off 
15835 \color none
15836 convert long to floating point number
15837 \end_inset 
15838 </cell>
15839 </row>
15840 </lyxtabular>
15841
15842 \end_inset 
15843
15844
15845 \newline 
15846
15847 \layout Standard
15848 \added_space_bottom bigskip 
15849 These support routines are developed in ANSI-C so there is room for space
15850  and speed improvement
15851 \begin_inset Foot
15852 collapsed false
15853
15854 \layout Standard
15855
15856 These floating point routines (
15857 \emph on 
15858 not
15859 \emph default 
15860  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15861  
15862 \end_inset 
15863
15864 .
15865  Note if all these routines are used simultaneously the data space might
15866  overflow.
15867  For serious floating point usage the large model might be needed.
15868  Also notice that you don't have to call this routines directly.
15869  The compiler will use them automatically every time a floating point operation
15870  is required.
15871 \layout Section
15872
15873 Library Routines
15874 \begin_inset LatexCommand \index{Libraries}
15875
15876 \end_inset 
15877
15878
15879 \layout Standard
15880
15881
15882 \emph on 
15883 <pending: this is messy and incomplete - a little more information is in
15884  sdcc/doc/libdoc.txt
15885 \emph default 
15886  >
15887 \layout Subsection
15888
15889 Compiler support routines (_gptrget, _mulint etc.)
15890 \layout Subsection
15891
15892 Stdclib functions (puts, printf, strcat etc.)
15893 \layout Subsubsection
15894
15895 <stdio.h>
15896 \layout Standard
15897
15898
15899 \begin_inset LatexCommand \index{<stdio.h>}
15900
15901 \end_inset 
15902
15903 As usual on embedded systems you have to provide your own 
15904 \family typewriter 
15905 getchar()
15906 \begin_inset LatexCommand \index{getchar()}
15907
15908 \end_inset 
15909
15910  
15911 \family default 
15912 and 
15913 \family typewriter 
15914 putchar()
15915 \begin_inset LatexCommand \index{putchar()}
15916
15917 \end_inset 
15918
15919
15920 \family default 
15921  routines.
15922  SDCC does not know whether the system connects to a serial line with or
15923  without handshake, LCD, keyboard or other device.
15924  And whether a 
15925 \family typewriter 
15926 lf
15927 \family default 
15928  to 
15929 \family typewriter 
15930 crlf
15931 \family default 
15932  conversion within 
15933 \family typewriter 
15934 putchar()
15935 \family default 
15936  is intended.
15937  You'll find examples for serial routines f.e.
15938  in sdcc/device/lib.
15939 \layout Standard
15940
15941 The default
15942 \family typewriter 
15943  printf()
15944 \begin_inset LatexCommand \index{printf()}
15945
15946 \end_inset 
15947
15948
15949 \family default 
15950 implementation in
15951 \family typewriter 
15952  printf_large.c
15953 \family default 
15954  does not support float (except on ds390).
15955  To enable this recompile it with the option 
15956 \emph on 
15957 -
15958 \begin_inset ERT
15959 status Collapsed
15960
15961 \layout Standard
15962
15963 \backslash 
15964 /
15965 \end_inset 
15966
15967 DUSE_FLOATS=1
15968 \begin_inset LatexCommand \index{USE\_FLOATS}
15969
15970 \end_inset 
15971
15972
15973 \emph default 
15974  on the command line.
15975  Use
15976 \emph on 
15977  -
15978 \begin_inset ERT
15979 status Collapsed
15980
15981 \layout Standard
15982
15983 \backslash 
15984 /
15985 \end_inset 
15986
15987 -model-large
15988 \begin_inset LatexCommand \index{-\/-model-large}
15989
15990 \end_inset 
15991
15992
15993 \emph default 
15994  for the mcs51 port, since this uses a lot of memory.
15995 \layout Standard
15996
15997 If you're short on memory you might want to use 
15998 \family typewriter 
15999 printf_small()
16000 \begin_inset LatexCommand \index{printf\_small()}
16001
16002 \end_inset 
16003
16004
16005 \family default 
16006  
16007 \emph on 
16008 instead
16009 \emph default 
16010  of
16011 \family typewriter 
16012  printf().
16013
16014 \family default 
16015  For the mcs51 there additionally are assembly versions 
16016 \family typewriter 
16017 printf_tiny()
16018 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16019
16020 \end_inset 
16021
16022
16023 \family default 
16024  (subset of printf using less than 270 bytes) and 
16025 \family typewriter 
16026 printf_fast()
16027 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16028
16029 \end_inset 
16030
16031  
16032 \family default 
16033 and
16034 \family typewriter 
16035  printf_fast_f()
16036 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16037
16038 \end_inset 
16039
16040
16041 \family default 
16042  (floating-point aware version of printf_fast) which should fit the requirements
16043  of many embedded systems (printf_fast() can be customized by unsetting
16044  #defines to 
16045 \emph on 
16046 not
16047 \emph default 
16048  support long variables and field widths).
16049 \layout Subsubsection
16050
16051 <malloc.h>
16052 \begin_inset LatexCommand \index{malloc.h}
16053
16054 \end_inset 
16055
16056
16057 \layout Standard
16058
16059 Before using dynamic memory allocation
16060 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16061
16062 \end_inset 
16063
16064  with SDCC, you have to provide heap
16065 \begin_inset LatexCommand \index{heap (malloc)}
16066
16067 \end_inset 
16068
16069  space for malloc to allocate memory from
16070 \family typewriter 
16071 .
16072  
16073 \family default 
16074 You can acomplish this by including the following code into your source:
16075 \layout Verse
16076
16077
16078 \family typewriter 
16079 #include <malloc.h>
16080 \begin_inset LatexCommand \index{malloc.h}
16081
16082 \end_inset 
16083
16084  /* calloc
16085 \begin_inset LatexCommand \index{calloc}
16086
16087 \end_inset 
16088
16089 , malloc
16090 \begin_inset LatexCommand \index{malloc}
16091
16092 \end_inset 
16093
16094 , realloc
16095 \begin_inset LatexCommand \index{realloc}
16096
16097 \end_inset 
16098
16099 , and free
16100 \begin_inset LatexCommand \index{free (malloc)}
16101
16102 \end_inset 
16103
16104  */ 
16105 \newline 
16106
16107 \newline 
16108 #define HEAPSIZE 0x1000 /* Adjust depending on available memory */ 
16109 \newline 
16110 unsigned char xdata myheap[HEAPSIZE]; /* The actual heap for dynamic memory
16111  */ 
16112 \newline 
16113
16114 \newline 
16115 void main (void) 
16116 \newline 
16117
16118 \newline 
16119 \SpecialChar ~
16120 \SpecialChar ~
16121 \SpecialChar ~
16122 /* Your variable declarations come here*/
16123 \newline 
16124 \SpecialChar ~
16125 \SpecialChar ~
16126 \SpecialChar ~
16127 ...
16128 \newline 
16129 \SpecialChar ~
16130 \SpecialChar ~
16131 \SpecialChar ~
16132 init_dynamic_memory((MEMHEADER xdata *)myheap, HEAPSIZE);
16133 \newline 
16134 \SpecialChar ~
16135 \SpecialChar ~
16136 \SpecialChar ~
16137 ...
16138  /* Rest of your code*/
16139 \newline 
16140
16141 \newline 
16142
16143 \layout Subsection
16144
16145 Math functions (sinf, powf, sqrtf etc.)
16146 \layout Subsubsection
16147
16148 <math.h>
16149 \layout Standard
16150
16151 See definitions in file <math.h>.
16152 \layout Subsection
16153
16154 Other libraries
16155 \layout Standard
16156
16157 Libraries
16158 \begin_inset LatexCommand \index{Libraries}
16159
16160 \end_inset 
16161
16162  included in SDCC should have a license at least as liberal as the GNU Lesser
16163  General Public License
16164 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16165
16166 \end_inset 
16167
16168  
16169 \emph on 
16170 LGPL
16171 \emph default 
16172 .
16173 \layout Comment
16174
16175 license statements for the libraries are missing.
16176  sdcc/device/lib/ser_ir.c
16177 \layout Comment
16178
16179 or _decdptr f.e.
16180  come with a GPL (as opposed to LGPL) License - this will not be liberal
16181  enough for many embedded programmers.
16182 \layout Standard
16183
16184 If you have ported some library or want to share experience about some code
16185  which f.e.
16186  falls into any of these categories Busses (I
16187 \begin_inset Formula $^{\textrm{2}}$
16188 \end_inset 
16189
16190 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16191  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16192  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16193 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16194
16195 \end_inset 
16196
16197 \SpecialChar ~
16198 would certainly like to hear about it.
16199 \layout Standard
16200 \added_space_bottom bigskip 
16201 Programmers coding for embedded systems are not especially famous for being
16202  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16203 e these references are very valuable.
16204  Let's help to create a climate where information is shared.
16205 \layout Section
16206
16207 Memory Models
16208 \layout Subsection
16209
16210 MCS51 Memory Models
16211 \begin_inset LatexCommand \index{Memory model}
16212
16213 \end_inset 
16214
16215
16216 \begin_inset LatexCommand \index{MCS51 memory model}
16217
16218 \end_inset 
16219
16220
16221 \layout Subsubsection
16222
16223 Small, Medium and Large
16224 \layout Standard
16225
16226 SDCC allows three memory models for MCS51 code, 
16227 \shape slanted 
16228 small, medium
16229 \shape default 
16230  and 
16231 \shape slanted 
16232 large
16233 \shape default 
16234 .
16235  Modules compiled with different memory models should 
16236 \emph on 
16237 never
16238 \emph default 
16239  be combined together or the results would be unpredictable.
16240  The library routines supplied with the compiler are compiled as small,
16241  medium and large.
16242  The compiled library modules are contained in separate directories as small,
16243  medium and large so that you can link to the appropriate set.
16244 \layout Standard
16245
16246 When the medium or large model is used all variables declared without a
16247  storage class will be allocated into the external ram, this includes all
16248  parameters and local variables (for non-reentrant
16249 \begin_inset LatexCommand \index{reentrant}
16250
16251 \end_inset 
16252
16253  functions).
16254  When the small model is used variables without storage class are allocated
16255  in the internal ram.
16256 \layout Standard
16257
16258 Judicious usage of the processor specific storage classes
16259 \begin_inset LatexCommand \index{Storage class}
16260
16261 \end_inset 
16262
16263  and the 'reentrant' function type will yield much more efficient code,
16264  than using the large model.
16265  Several optimizations are disabled when the program is compiled using the
16266  large model, it is therefore recommended that the small model be used unless
16267  absolutely required.
16268 \layout Subsubsection
16269
16270 External Stack
16271 \begin_inset LatexCommand \label{sub:External-Stack}
16272
16273 \end_inset 
16274
16275
16276 \begin_inset LatexCommand \index{stack}
16277
16278 \end_inset 
16279
16280
16281 \begin_inset LatexCommand \index{External stack (mcs51)}
16282
16283 \end_inset 
16284
16285
16286 \layout Standard
16287
16288 The external stack (-
16289 \begin_inset ERT
16290 status Collapsed
16291
16292 \layout Standard
16293
16294 \backslash 
16295 /
16296 \end_inset 
16297
16298 -xstack option
16299 \begin_inset LatexCommand \index{-\/-xstack}
16300
16301 \end_inset 
16302
16303 ) is located in pdata
16304 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16305
16306 \end_inset 
16307
16308  memory (usually at the start of the external ram segment) and uses all
16309  unused space in pdata (max.
16310  256 bytes).
16311  When -
16312 \begin_inset ERT
16313 status Collapsed
16314
16315 \layout Standard
16316
16317 \backslash 
16318 /
16319 \end_inset 
16320
16321 -xstack option is used to compile the program, the parameters and local
16322  variables
16323 \begin_inset LatexCommand \index{local variables}
16324
16325 \end_inset 
16326
16327  of all reentrant functions are allocated in this area.
16328  This option is provided for programs with large stack space requirements.
16329  When used with the -
16330 \begin_inset ERT
16331 status Collapsed
16332
16333 \layout Standard
16334
16335 \backslash 
16336 /
16337 \end_inset 
16338
16339 -stack-auto
16340 \begin_inset LatexCommand \index{-\/-stack-auto}
16341
16342 \end_inset 
16343
16344  option, all parameters and local variables are allocated on the external
16345  stack (note: support libraries will need to be recompiled with the same
16346  options.
16347  There is a predefined target in the library makefile).
16348 \layout Standard
16349
16350 The compiler outputs the higher order address byte of the external ram segment
16351  into port P2
16352 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16353
16354 \end_inset 
16355
16356  (see also section 
16357 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16358
16359 \end_inset 
16360
16361 ), therefore when using the External Stack option, this port 
16362 \emph on 
16363 may not
16364 \emph default 
16365  be used by the application program.
16366 \layout Subsection
16367
16368 DS390 Memory Model
16369 \begin_inset LatexCommand \index{Memory model}
16370
16371 \end_inset 
16372
16373
16374 \begin_inset LatexCommand \index{DS390 memory model}
16375
16376 \end_inset 
16377
16378
16379 \layout Standard
16380
16381 The only model supported is Flat 24
16382 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16383
16384 \end_inset 
16385
16386 .
16387  This generates code for the 24 bit contiguous addressing mode of the Dallas
16388  DS80C390 part.
16389  In this mode, up to four meg of external RAM or code space can be directly
16390  addressed.
16391  See the data sheets at www.dalsemi.com for further information on this part.
16392 \newline 
16393
16394 \newline 
16395 Note that the compiler does not generate any code to place the processor
16396  into 24 bitmode (although 
16397 \emph on 
16398 tinibios
16399 \emph default 
16400  in the ds390 libraries will do that for you).
16401  If you don't use 
16402 \emph on 
16403 tinibios
16404 \emph default 
16405
16406 \begin_inset LatexCommand \index{Tinibios (DS390)}
16407
16408 \end_inset 
16409
16410 , the boot loader or similar code must ensure that the processor is in 24
16411  bit contiguous addressing mode before calling the SDCC startup code.
16412 \newline 
16413
16414 \newline 
16415 Like the 
16416 \emph on 
16417 -
16418 \begin_inset ERT
16419 status Collapsed
16420
16421 \layout Standard
16422
16423 \backslash 
16424 /
16425 \end_inset 
16426
16427 -model-large
16428 \emph default 
16429  option, variables will by default be placed into the XDATA segment.
16430  
16431 \newline 
16432
16433 \newline 
16434 Segments may be placed anywhere in the 4 meg address space using the usual
16435  -
16436 \begin_inset ERT
16437 status Collapsed
16438
16439 \layout Standard
16440
16441 \backslash 
16442 /
16443 \end_inset 
16444
16445 -*-loc options.
16446  Note that if any segments are located above 64K, the -r flag must be passed
16447  to the linker to generate the proper segment relocations, and the Intel
16448  HEX output format must be used.
16449  The -r flag can be passed to the linker by using the option 
16450 \emph on 
16451 -Wl-r
16452 \emph default 
16453  on the SDCC command line.
16454  However, currently the linker can not handle code segments > 64k.
16455 \layout Section
16456
16457 Pragmas
16458 \begin_inset LatexCommand \label{sec:Pragmas}
16459
16460 \end_inset 
16461
16462
16463 \begin_inset LatexCommand \index{Pragmas}
16464
16465 \end_inset 
16466
16467
16468 \layout Standard
16469
16470 SDCC supports the following #pragma directives:
16471 \layout Itemize
16472
16473
16474 \series bold 
16475 save
16476 \series default 
16477
16478 \begin_inset LatexCommand \index{\#pragma save}
16479
16480 \end_inset 
16481
16482  - this will save most current options to the save/restore stack.
16483  See #pragma\SpecialChar ~
16484 restore.
16485 \layout Itemize
16486
16487
16488 \series bold 
16489 restore
16490 \series default 
16491
16492 \begin_inset LatexCommand \index{\#pragma restore}
16493
16494 \end_inset 
16495
16496  - will restore saved options from the last save.
16497  saves & restores can be nested.
16498  SDCC uses a save/restore stack: save pushes current options to the stack,
16499  restore pulls current options from the stack.
16500  See #pragma\SpecialChar ~
16501 save.
16502 \newline 
16503
16504 \layout Itemize
16505
16506
16507 \series bold 
16508 callee_saves
16509 \series default 
16510
16511 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16512
16513 \end_inset 
16514
16515
16516 \begin_inset LatexCommand \index{function prologue}
16517
16518 \end_inset 
16519
16520  function1[,function2[,function3...]] - The compiler by default uses a caller
16521  saves convention for register saving across function calls, however this
16522  can cause unnecessary register pushing & popping
16523 \begin_inset LatexCommand \index{push/pop}
16524
16525 \end_inset 
16526
16527  when calling small functions from larger functions.
16528  This option can be used to switch off the register saving convention for
16529  the function names specified.
16530  The compiler will not save registers when calling these functions, extra
16531  code need to be manually inserted at the entry & exit for these functions
16532  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16533  reduce code & improve run time performance of the generated code.
16534  In the future the compiler (with inter procedural analysis) may be able
16535  to determine the appropriate scheme to use for each function call.
16536  If -
16537 \begin_inset ERT
16538 status Collapsed
16539
16540 \layout Standard
16541
16542 \backslash 
16543 /
16544 \end_inset 
16545
16546 -callee-saves command line option is used, the function names specified
16547  in #pragma\SpecialChar ~
16548 callee_saves
16549 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16550
16551 \end_inset 
16552
16553  is appended to the list of functions specified in the command line.
16554 \layout Itemize
16555
16556
16557 \series bold 
16558 exclude
16559 \series default 
16560
16561 \begin_inset LatexCommand \index{\#pragma exclude}
16562
16563 \end_inset 
16564
16565  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16566  of pairs of push/pop
16567 \begin_inset LatexCommand \index{push/pop}
16568
16569 \end_inset 
16570
16571  instructions in 
16572 \emph on 
16573 I
16574 \emph default 
16575 nterrupt
16576 \begin_inset LatexCommand \index{interrupt}
16577
16578 \end_inset 
16579
16580  
16581 \emph on 
16582 S
16583 \emph default 
16584 ervice 
16585 \emph on 
16586 R
16587 \emph default 
16588 outines.
16589  The directive should be placed immediately before the ISR function definition
16590  and it affects ALL ISR functions following it.
16591  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16592 exclude\SpecialChar ~
16593 none
16594 \begin_inset LatexCommand \index{\#pragma exclude}
16595
16596 \end_inset 
16597
16598 .
16599  See also the related keyword _naked
16600 \begin_inset LatexCommand \index{\_naked}
16601
16602 \end_inset 
16603
16604
16605 \begin_inset LatexCommand \index{\_\_naked}
16606
16607 \end_inset 
16608
16609 .
16610 \layout Itemize
16611
16612
16613 \series bold 
16614 less_pedantic
16615 \series default 
16616
16617 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16618
16619 \end_inset 
16620
16621  - the compiler will not warn you anymore for obvious mistakes, you'r on
16622  your own now ;-(
16623 \layout Itemize
16624
16625
16626 \series bold 
16627 disable_warning
16628 \series default 
16629  <nnnn>
16630 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16631
16632 \end_inset 
16633
16634  - the compiler will not warn you anymore about warning number <nnnn>.
16635 \layout Itemize
16636
16637
16638 \series bold 
16639 nogcse
16640 \series default 
16641
16642 \begin_inset LatexCommand \index{\#pragma nogcse}
16643
16644 \end_inset 
16645
16646  - will stop global common subexpression elimination.
16647 \layout Itemize
16648
16649
16650 \series bold 
16651 noinduction
16652 \series default 
16653
16654 \begin_inset LatexCommand \index{\#pragma noinduction}
16655
16656 \end_inset 
16657
16658  - will stop loop induction optimizations.
16659 \layout Itemize
16660
16661
16662 \series bold 
16663 noinvariant
16664 \series default 
16665
16666 \begin_inset LatexCommand \index{\#pragma noinvariant}
16667
16668 \end_inset 
16669
16670  - will not do loop invariant optimizations.
16671  For more details see Loop Invariants in section
16672 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16673
16674 \end_inset 
16675
16676 .
16677 \layout Itemize
16678
16679
16680 \series bold 
16681 noiv
16682 \series default 
16683
16684 \begin_inset LatexCommand \index{\#pragma noiv}
16685
16686 \end_inset 
16687
16688  - Do not generate interrupt
16689 \begin_inset LatexCommand \index{interrupt}
16690
16691 \end_inset 
16692
16693  vector table
16694 \begin_inset LatexCommand \index{interrupt vector table}
16695
16696 \end_inset 
16697
16698  entries for all ISR functions defined after the pragma.
16699  This is useful in cases where the interrupt vector table must be defined
16700  manually, or when there is a secondary, manually defined interrupt vector
16701  table (e.g.
16702  for the autovector feature of the Cypress EZ-USB FX2).
16703  More elegantly this can be achieved by obmitting the optional interrupt
16704  number after the interrupt keyword, see section 
16705 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16706
16707 \end_inset 
16708
16709 \SpecialChar ~
16710 about interrupts.
16711 \layout Itemize
16712
16713
16714 \series bold 
16715 nojtbound
16716 \series default 
16717
16718 \begin_inset LatexCommand \index{\#pragma nojtbound}
16719
16720 \end_inset 
16721
16722  - will not generate code for boundary value checking, when switch statements
16723  are turned into jump-tables (dangerous).
16724  For more details see section 
16725 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16726
16727 \end_inset 
16728
16729 .
16730 \layout Itemize
16731
16732
16733 \series bold 
16734 noloopreverse
16735 \series default 
16736
16737 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16738
16739 \end_inset 
16740
16741  - Will not do loop reversal optimization
16742 \layout Itemize
16743
16744
16745 \series bold 
16746 nooverlay
16747 \series default 
16748
16749 \begin_inset LatexCommand \index{\#pragma nooverlay}
16750
16751 \end_inset 
16752
16753  - the compiler will not overlay the parameters and local variables of a
16754  function.
16755 \layout Itemize
16756
16757
16758 \series bold 
16759 stackauto
16760 \series default 
16761
16762 \begin_inset LatexCommand \index{\#pragma stackauto}
16763
16764 \end_inset 
16765
16766 - See option -
16767 \begin_inset ERT
16768 status Collapsed
16769
16770 \layout Standard
16771
16772 \backslash 
16773 /
16774 \end_inset 
16775
16776 -stack-auto
16777 \begin_inset LatexCommand \index{-\/-stack-auto}
16778
16779 \end_inset 
16780
16781  and section 
16782 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16783
16784 \end_inset 
16785
16786  Parameters and Local Variables.
16787 \layout Itemize
16788
16789
16790 \series bold 
16791 opt_code_speed
16792 \series default 
16793  
16794 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16795
16796 \end_inset 
16797
16798 - The compiler will optimize code generation towards fast code, possibly
16799  at the expense of code size.
16800  Currently this has little effect.
16801 \layout Itemize
16802
16803
16804 \series bold 
16805 opt_code_size
16806 \series default 
16807  
16808 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16809
16810 \end_inset 
16811
16812 - The compiler will optimize code generation towards compact code, possibly
16813  at the expense of code speed.
16814  Currently this has little effect.
16815 \layout Itemize
16816
16817
16818 \series bold 
16819 opt_code_balanced
16820 \series default 
16821  
16822 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16823
16824 \end_inset 
16825
16826 - The compiler will attempt to generate code that is both compact and fast,
16827  as long as meeting one goal is not a detriment to the other (this is the
16828  default).
16829  
16830 \layout Itemize
16831
16832
16833 \series bold 
16834 std_sdcc89
16835 \series default 
16836  
16837 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16838
16839 \end_inset 
16840
16841 - Generally follow the C89 standard, but allow SDCC features that conflict
16842  with the standard (default).
16843 \layout Itemize
16844
16845
16846 \series bold 
16847 std_c89
16848 \series default 
16849  
16850 \begin_inset LatexCommand \index{\#pragma std\_c89}
16851
16852 \end_inset 
16853
16854 - Follow the C89 standard and disable SDCC features that conflict with the
16855  standard.
16856 \layout Itemize
16857
16858
16859 \series bold 
16860 std_sdcc99
16861 \series default 
16862  
16863 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16864
16865 \end_inset 
16866
16867 - Generally follow the C99 standard, but allow SDCC features that conflict
16868  with the standard (incomplete support).
16869 \layout Itemize
16870
16871
16872 \series bold 
16873 std_c99
16874 \series default 
16875  
16876 \begin_inset LatexCommand \index{\#pragma std\_c99}
16877
16878 \end_inset 
16879
16880 - Follow the C99 standard and disable SDCC features that conflict with the
16881  standard (incomplete support).
16882 \layout Itemize
16883
16884
16885 \series bold 
16886 codeseg
16887 \series default 
16888  <name>
16889 \begin_inset LatexCommand \index{\#pragma codeseg}
16890
16891 \end_inset 
16892
16893 - Use this name (max.
16894  8 characters) for the code segment.
16895  See option -
16896 \begin_inset ERT
16897 status Collapsed
16898
16899 \layout Standard
16900
16901 \backslash 
16902 /
16903 \end_inset 
16904
16905 -codeseg.
16906 \layout Itemize
16907
16908
16909 \series bold 
16910 constseg
16911 \series default 
16912  <name>
16913 \begin_inset LatexCommand \index{\#pragma constseg}
16914
16915 \end_inset 
16916
16917 - Use this name (max.
16918  8 characters) for the const segment.
16919  See option -
16920 \begin_inset ERT
16921 status Collapsed
16922
16923 \layout Standard
16924
16925 \backslash 
16926 /
16927 \end_inset 
16928
16929 -constseg.
16930 \layout Standard
16931
16932 The preprocessor SDCPP
16933 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16934
16935 \end_inset 
16936
16937  supports the following #pragma directives:
16938 \layout Itemize
16939
16940
16941 \series bold 
16942 preproc_asm
16943 \series default 
16944
16945 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16946
16947 \end_inset 
16948
16949  (+ | -) - switch _asm _endasm block preprocessing on / off.
16950  Default is on.
16951  You use this prama to define multilines of assembly code.
16952  This will prevent the preprocessor from changing the formating required
16953  by assembly code.
16954  Below is an example on how to use this pragma.
16955 \layout Verse
16956
16957
16958 \family typewriter 
16959 #pragma preproc_asm -
16960 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16961
16962 \end_inset 
16963
16964
16965 \newline 
16966 #define MYDELAY _asm
16967 \newline 
16968 \SpecialChar ~
16969 \SpecialChar ~
16970 \SpecialChar ~
16971 nop ;my assembly comment...
16972 \newline 
16973 \SpecialChar ~
16974 \SpecialChar ~
16975 \SpecialChar ~
16976 nop
16977 \newline 
16978 \SpecialChar ~
16979 \SpecialChar ~
16980 \SpecialChar ~
16981 nop
16982 \newline 
16983 _endasm
16984 \newline 
16985 #pragma preproc_asm +
16986 \newline 
16987
16988 \newline 
16989 void foo (void) 
16990 \newline 
16991
16992 \newline 
16993 \SpecialChar ~
16994 \SpecialChar ~
16995 \SpecialChar ~
16996  ...
16997  
16998 \newline 
16999 \SpecialChar ~
17000 \SpecialChar ~
17001 \SpecialChar ~
17002  MYDELAY;
17003 \newline 
17004 \SpecialChar ~
17005 \SpecialChar ~
17006 \SpecialChar ~
17007  ...
17008  
17009 \newline 
17010
17011 \newline 
17012
17013 \layout Standard
17014
17015 The pragma's are intended to be used to turn-on or off certain optimizations
17016  which might cause the compiler to generate extra stack / data space to
17017  store compiler generated temporary variables.
17018  This usually happens in large functions.
17019  Pragma directives should be used as shown in the following example, they
17020  are used to control options & optimizations for a given function; pragmas
17021  should be placed before and/or after a function, placing pragma's inside
17022  a function body could have unpredictable results.
17023 \layout Verse
17024
17025
17026 \family typewriter 
17027 #pragma save
17028 \begin_inset LatexCommand \index{\#pragma save}
17029
17030 \end_inset 
17031
17032  \SpecialChar ~
17033 \SpecialChar ~
17034 \SpecialChar ~
17035 \SpecialChar ~
17036 \SpecialChar ~
17037 \SpecialChar ~
17038 \SpecialChar ~
17039 /* save the current settings */ 
17040 \newline 
17041 #pragma nogcse
17042 \begin_inset LatexCommand \index{\#pragma nogcse}
17043
17044 \end_inset 
17045
17046  \SpecialChar ~
17047 \SpecialChar ~
17048 \SpecialChar ~
17049 \SpecialChar ~
17050 \SpecialChar ~
17051 /* turnoff global subexpression elimination */ 
17052 \newline 
17053 #pragma noinduction
17054 \begin_inset LatexCommand \index{\#pragma noinduction}
17055
17056 \end_inset 
17057
17058  /* turn off induction optimizations */ 
17059 \newline 
17060 int foo () 
17061 \newline 
17062
17063 \newline 
17064 \SpecialChar ~
17065  \SpecialChar ~
17066  ...
17067  
17068 \newline 
17069 \SpecialChar ~
17070  \SpecialChar ~
17071  /* large code */ 
17072 \newline 
17073 \SpecialChar ~
17074  \SpecialChar ~
17075  ...
17076  
17077 \newline 
17078
17079 \newline 
17080 #pragma restore
17081 \begin_inset LatexCommand \index{\#pragma restore}
17082
17083 \end_inset 
17084
17085  /* turn the optimizations back on */
17086 \layout Standard
17087
17088 The compiler will generate a warning message when extra space is allocated.
17089  It is strongly recommended that the save and restore pragma's be used when
17090  changing options for a function.
17091 \newline 
17092
17093 \newline 
17094
17095 \newline 
17096
17097 \layout Section
17098
17099 Defines Created by the Compiler
17100 \layout Standard
17101
17102 The compiler creates the following #defines
17103 \begin_inset LatexCommand \index{\#defines}
17104
17105 \end_inset 
17106
17107
17108 \begin_inset LatexCommand \index{Defines created by the compiler}
17109
17110 \end_inset 
17111
17112 :
17113 \newline 
17114
17115 \layout Standard
17116
17117
17118 \begin_inset  Tabular
17119 <lyxtabular version="3" rows="11" columns="2">
17120 <features>
17121 <column alignment="left" valignment="top" leftline="true" width="3in">
17122 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17123 <row topline="true" bottomline="true">
17124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17125 \begin_inset Text
17126
17127 \layout Standard
17128
17129
17130 \series bold 
17131 #define
17132 \end_inset 
17133 </cell>
17134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17135 \begin_inset Text
17136
17137 \layout Standard
17138
17139
17140 \series bold 
17141 Description
17142 \end_inset 
17143 </cell>
17144 </row>
17145 <row topline="true">
17146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17147 \begin_inset Text
17148
17149 \layout Standard
17150
17151 SDCC
17152 \begin_inset LatexCommand \index{SDCC}
17153
17154 \end_inset 
17155
17156  
17157 \end_inset 
17158 </cell>
17159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17160 \begin_inset Text
17161
17162 \layout Standard
17163
17164 Always defined.
17165  Since version 2.5.6 the version number as an int (ex.
17166  256)
17167 \end_inset 
17168 </cell>
17169 </row>
17170 <row topline="true">
17171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17172 \begin_inset Text
17173
17174 \layout Standard
17175
17176 SDCC_mcs51
17177 \begin_inset LatexCommand \index{SDCC\_mcs51}
17178
17179 \end_inset 
17180
17181  or SDCC_ds390
17182 \begin_inset LatexCommand \index{SDCC\_ds390}
17183
17184 \end_inset 
17185
17186  or SDCC_z80
17187 \begin_inset LatexCommand \index{SDCC\_z80}
17188
17189 \end_inset 
17190
17191 , etc.
17192 \end_inset 
17193 </cell>
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17195 \begin_inset Text
17196
17197 \layout Standard
17198
17199 depending on the model used (e.g.: -mds390)
17200 \end_inset 
17201 </cell>
17202 </row>
17203 <row topline="true">
17204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17205 \begin_inset Text
17206
17207 \layout Standard
17208
17209 __mcs51
17210 \begin_inset LatexCommand \index{\_\_mcs51}
17211
17212 \end_inset 
17213
17214 , __ds390
17215 \begin_inset LatexCommand \index{\_\_ds390}
17216
17217 \end_inset 
17218
17219 , __hc08
17220 \begin_inset LatexCommand \index{\_\_hc08}
17221
17222 \end_inset 
17223
17224 , __z80
17225 \begin_inset LatexCommand \index{\_\_z80}
17226
17227 \end_inset 
17228
17229 , etc
17230 \end_inset 
17231 </cell>
17232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17233 \begin_inset Text
17234
17235 \layout Standard
17236
17237 depending on the model used (e.g.
17238  -mz80)
17239 \end_inset 
17240 </cell>
17241 </row>
17242 <row topline="true">
17243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17244 \begin_inset Text
17245
17246 \layout Standard
17247
17248 SDCC_STACK_AUTO
17249 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17250
17251 \end_inset 
17252
17253
17254 \end_inset 
17255 </cell>
17256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17257 \begin_inset Text
17258
17259 \layout Standard
17260
17261 when 
17262 \emph on 
17263 -
17264 \begin_inset ERT
17265 status Collapsed
17266
17267 \layout Standard
17268
17269 \backslash 
17270 /
17271 \end_inset 
17272
17273 -stack-auto
17274 \emph default 
17275  option is used
17276 \end_inset 
17277 </cell>
17278 </row>
17279 <row topline="true">
17280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17281 \begin_inset Text
17282
17283 \layout Standard
17284
17285 SDCC_MODEL_SMALL
17286 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17287
17288 \end_inset 
17289
17290
17291 \end_inset 
17292 </cell>
17293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17294 \begin_inset Text
17295
17296 \layout Standard
17297
17298 when 
17299 \emph on 
17300 -
17301 \begin_inset ERT
17302 status Collapsed
17303
17304 \layout Standard
17305
17306 \backslash 
17307 /
17308 \end_inset 
17309
17310 -model-small
17311 \emph default 
17312  is used
17313 \end_inset 
17314 </cell>
17315 </row>
17316 <row topline="true">
17317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17318 \begin_inset Text
17319
17320 \layout Standard
17321
17322 SDCC_MODEL_MEDIUM
17323 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17324
17325 \end_inset 
17326
17327
17328 \end_inset 
17329 </cell>
17330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17331 \begin_inset Text
17332
17333 \layout Standard
17334
17335 when 
17336 \emph on 
17337 -
17338 \begin_inset ERT
17339 status Collapsed
17340
17341 \layout Standard
17342
17343 \backslash 
17344 /
17345 \end_inset 
17346
17347 -model-medium
17348 \emph default 
17349  is used
17350 \end_inset 
17351 </cell>
17352 </row>
17353 <row topline="true">
17354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17355 \begin_inset Text
17356
17357 \layout Standard
17358
17359 SDCC_MODEL_LARGE
17360 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17361
17362 \end_inset 
17363
17364
17365 \end_inset 
17366 </cell>
17367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17368 \begin_inset Text
17369
17370 \layout Standard
17371
17372 when 
17373 \emph on 
17374 -
17375 \begin_inset ERT
17376 status Collapsed
17377
17378 \layout Standard
17379
17380 \backslash 
17381 /
17382 \end_inset 
17383
17384 -model-large
17385 \emph default 
17386  is used
17387 \end_inset 
17388 </cell>
17389 </row>
17390 <row topline="true">
17391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17392 \begin_inset Text
17393
17394 \layout Standard
17395
17396 SDCC_USE_XSTACK
17397 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17398
17399 \end_inset 
17400
17401
17402 \end_inset 
17403 </cell>
17404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17405 \begin_inset Text
17406
17407 \layout Standard
17408
17409 when 
17410 \emph on 
17411 -
17412 \begin_inset ERT
17413 status Collapsed
17414
17415 \layout Standard
17416
17417 \backslash 
17418 /
17419 \end_inset 
17420
17421 -xstack
17422 \emph default 
17423  option is used
17424 \end_inset 
17425 </cell>
17426 </row>
17427 <row topline="true">
17428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17429 \begin_inset Text
17430
17431 \layout Standard
17432
17433 SDCC_STACK_TENBIT
17434 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17435
17436 \end_inset 
17437
17438  
17439 \end_inset 
17440 </cell>
17441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17442 \begin_inset Text
17443
17444 \layout Standard
17445
17446 when 
17447 \emph on 
17448 -mds390
17449 \emph default 
17450  is used
17451 \end_inset 
17452 </cell>
17453 </row>
17454 <row topline="true" bottomline="true">
17455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17456 \begin_inset Text
17457
17458 \layout Standard
17459
17460 SDCC_MODEL_FLAT24
17461 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17462
17463 \end_inset 
17464
17465
17466 \end_inset 
17467 </cell>
17468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17469 \begin_inset Text
17470
17471 \layout Standard
17472
17473 when 
17474 \emph on 
17475 -mds390
17476 \emph default 
17477  is used
17478 \end_inset 
17479 </cell>
17480 </row>
17481 </lyxtabular>
17482
17483 \end_inset 
17484
17485
17486 \layout Chapter
17487
17488 Notes on supported Processors
17489 \layout Section
17490
17491 MCS51 variants
17492 \begin_inset LatexCommand \label{sub:MCS51-variants}
17493
17494 \end_inset 
17495
17496
17497 \begin_inset LatexCommand \index{MCS51 variants}
17498
17499 \end_inset 
17500
17501
17502 \layout Standard
17503
17504 MCS51 processors are available from many vendors and come in many different
17505  flavours.
17506  While they might differ considerably in respect to Special Function Registers
17507  the core MCS51 is usually not modified or is kept compatible.
17508  
17509 \layout Subsection
17510
17511 pdata access by SFR 
17512 \layout Standard
17513
17514 With the upcome of devices with internal xdata and flash memory devices
17515  using port P2
17516 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17517
17518 \end_inset 
17519
17520  as dedicated I/O port is becoming more popular.
17521  Switching the high byte for pdata
17522 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17523
17524 \end_inset 
17525
17526  access which was formerly done by port P2 is then achieved by a Special
17527  Function Register
17528 \begin_inset LatexCommand \index{sfr}
17529
17530 \end_inset 
17531
17532 .
17533  In well-established MCS51 tradition the address of this 
17534 \emph on 
17535 sfr
17536 \emph default 
17537  is where the chip designers decided to put it.
17538  Needless to say that they didn't agree on a common name either.
17539  So that the startup code can correctly initialize xdata variables, you
17540  should define an sfr with the name _XPAGE
17541 \family typewriter 
17542
17543 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17544
17545 \end_inset 
17546
17547
17548 \family default 
17549  at the appropriate location if the default, port P2, is not used for this.
17550  Some examples are:
17551 \layout Verse
17552
17553
17554 \family typewriter 
17555 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17556 \layout Verse
17557
17558
17559 \family typewriter 
17560 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17561 \layout Verse
17562
17563
17564 \family typewriter 
17565 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17566 \layout Standard
17567
17568 For more exotic implementations further customizations may be needed.
17569  See section 
17570 \begin_inset LatexCommand \ref{sub:Startup-Code}
17571
17572 \end_inset 
17573
17574  for other possibilities.
17575 \layout Subsection
17576
17577 Other Features available by SFR
17578 \layout Standard
17579 \added_space_bottom bigskip 
17580 Some MCS51 variants offer features like Double DPTR
17581 \begin_inset LatexCommand \index{DPTR}
17582
17583 \end_inset 
17584
17585 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17586  These are currently not used for the MCS51 port.
17587  If you absolutely need them you can fall back to inline assembly or submit
17588  a patch to SDCC.
17589 \layout Section
17590
17591 DS400 port
17592 \layout Standard
17593 \added_space_bottom bigskip 
17594 The DS80C400
17595 \begin_inset LatexCommand \index{DS80C400}
17596
17597 \end_inset 
17598
17599
17600 \begin_inset LatexCommand \index{DS400}
17601
17602 \end_inset 
17603
17604  microcontroller has a rich set of peripherals.
17605  In its built-in ROM library it includes functions to access some of the
17606  features, among them is a TCP stack with IP4 and IP6 support.
17607  Library headers (currently in beta status) and other files are provided
17608  at 
17609 \size footnotesize 
17610
17611 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17612
17613 \end_inset 
17614
17615 .
17616  
17617 \layout Section
17618
17619 The Z80 and gbz80 port
17620 \layout Standard
17621
17622 SDCC can target both the Zilog Z80
17623 \begin_inset LatexCommand \index{Z80}
17624
17625 \end_inset 
17626
17627  and the Nintendo Gameboy's Z80-like gbz80
17628 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17629
17630 \end_inset 
17631
17632 .
17633  The Z80 port is passed through the same 
17634 \emph on 
17635 regressions tests
17636 \begin_inset LatexCommand \index{Regression test}
17637
17638 \end_inset 
17639
17640
17641 \emph default 
17642  (see section 
17643 \begin_inset LatexCommand \ref{sec:Quality-control}
17644
17645 \end_inset 
17646
17647 ) as the MCS51 and DS390 ports, so floating point support, support for long
17648  variables and bitfield support is fine.
17649  See mailing lists and forums about interrupt routines.
17650 \layout Standard
17651 \added_space_bottom bigskip 
17652 As always, the code is the authoritative reference - see z80/ralloc.c and
17653  z80/gen.c.
17654  The stack
17655 \begin_inset LatexCommand \index{Z80!stack}
17656
17657 \end_inset 
17658
17659  frame is similar to that generated by the IAR Z80 compiler.
17660  IX is used as the base pointer, HL and IY are used as a temporary registers,
17661  and BC and DE are available for holding variables.
17662  Return values
17663 \begin_inset LatexCommand \index{Z80!return value}
17664
17665 \end_inset 
17666
17667  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17668  bytes).
17669  The gbz80 port use the same set of registers for the return values, but
17670  in a different order of significance: E (one byte), DE (two bytes), or
17671  HLDE (four bytes).
17672 \layout Section
17673
17674 The HC08 port
17675 \layout Standard
17676
17677 The port to the Freescale/Motorola HC08
17678 \begin_inset LatexCommand \index{HC08}
17679
17680 \end_inset 
17681
17682  family has been added in October 2003, and is still undergoing some basic
17683  development.
17684  The code generator is complete, but the register allocation is still quite
17685  unoptimized.
17686  Some of the SDCC's standard C library functions have embedded non-HC08
17687  inline assembly and so are not yet usable.
17688 \layout Standard
17689 \added_space_bottom bigskip 
17690 The HC08 port passes the regression test suite (see section 
17691 \begin_inset LatexCommand \ref{sec:Quality-control}
17692
17693 \end_inset 
17694
17695 ).
17696 \layout Section
17697 \pagebreak_top 
17698 The PIC14 port
17699 \layout Standard
17700
17701 The 14bit PIC
17702 \begin_inset LatexCommand \index{PIC14}
17703
17704 \end_inset 
17705
17706  port still requires a major effort from the development community.
17707  However it can work for simple code.
17708  It passes its (smaller set of) regression tests
17709 \begin_inset LatexCommand \index{Regression test (PIC14)}
17710
17711 \end_inset 
17712
17713  in the directory 
17714 \shape italic 
17715 sdcc/src/regression
17716 \shape default 
17717 .
17718 \layout Subsection
17719
17720 C code and 14bit PIC code page
17721 \begin_inset LatexCommand \index{code page (pic14)}
17722
17723 \end_inset 
17724
17725  and RAM banks
17726 \begin_inset LatexCommand \index{RAM bank (pic14)}
17727
17728 \end_inset 
17729
17730
17731 \layout Standard
17732
17733 The linker organizes allocation for the code page and RAM banks.
17734  It does not have intimate knowledge of the code flow.
17735  It will put all the code section of a single asm file into a single code
17736  page.
17737  In order to make use of multiple code pages, separate asm files must be
17738  used.
17739  The compiler treats all functions of a single C file as being in the same
17740  code page unless it is non static.
17741  The compiler treats all local variables of a single C file as being in
17742  the same RAM bank unless it is an extern.
17743 \newline 
17744
17745 \newline 
17746 To get the best follow these guide lines:
17747 \layout Enumerate
17748
17749 make local functions static, as non static functions require code page selection
17750  overhead.
17751 \layout Enumerate
17752
17753 Make local variables static as extern variables require RAM bank selection
17754  overhead.
17755 \layout Enumerate
17756
17757 For devices that have multiple code pages it is more efficient to use the
17758  same number of files as pages, i.e.
17759  for the 16F877 use 4 separate files and i.e.
17760  for the 16F874 use 2 separate files.
17761  This way the linker can put the code for each file into different code
17762  pages and the compiler can allocate reusable variables more efficiently
17763  and there's less page selection overhead.
17764  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17765  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17766 \layout Subsection
17767
17768 Creating a device include file 
17769 \layout Standard
17770
17771 For generating a device include file
17772 \begin_inset LatexCommand \index{PIC14!Header files}
17773
17774 \end_inset 
17775
17776  use the support perl script inc2h.pl kept in directory support/script.
17777 \layout Subsection
17778
17779 Interrupt code
17780 \layout Standard
17781
17782 For the interrupt function, use the keyword 'interrupt'
17783 \begin_inset LatexCommand \index{PIC14!interrupt}
17784
17785 \end_inset 
17786
17787  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17788  there to avoid a syntax error - it ought to be fixed).
17789  E.g.:
17790 \layout Verse
17791
17792
17793 \family typewriter 
17794 void Intr(void) interrupt 0
17795 \newline 
17796 {
17797 \newline 
17798 \SpecialChar ~
17799 \SpecialChar ~
17800 T0IF = 0; /* Clear timer interrupt */
17801 \newline 
17802 }
17803 \layout Subsection
17804
17805 Linking and assembling
17806 \layout Standard
17807
17808 For assembling you can use either GPUTILS'
17809 \begin_inset LatexCommand \index{gputils (pic tools)}
17810
17811 \end_inset 
17812
17813  gpasm.exe or MPLAB's mpasmwin.exe.
17814  GPUTILS is available from 
17815 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17816
17817 \end_inset 
17818
17819 .
17820  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17821  If you use MPLAB and an interrupt function then the linker script file
17822  vectors section will need to be enlarged to link with mplink.
17823 \newline 
17824
17825 \newline 
17826 Here is a 
17827 \family typewriter 
17828 Makefile
17829 \family default 
17830  using GPUTILS:
17831 \layout Verse
17832
17833
17834 \family typewriter 
17835 .c.o:
17836 \newline 
17837 \SpecialChar ~
17838 \SpecialChar ~
17839 \SpecialChar ~
17840 \SpecialChar ~
17841 \SpecialChar ~
17842 \SpecialChar ~
17843 \SpecialChar ~
17844 \SpecialChar ~
17845 sdcc -S -V -mpic14 -p16F877 $< 
17846 \newline 
17847 \SpecialChar ~
17848 \SpecialChar ~
17849 \SpecialChar ~
17850 \SpecialChar ~
17851 \SpecialChar ~
17852 \SpecialChar ~
17853 \SpecialChar ~
17854 \SpecialChar ~
17855 gpasm -c $*.asm
17856 \newline 
17857
17858 \newline 
17859 $(PRJ).hex: $(OBJS) 
17860 \newline 
17861 \SpecialChar ~
17862 \SpecialChar ~
17863 \SpecialChar ~
17864 \SpecialChar ~
17865 \SpecialChar ~
17866 \SpecialChar ~
17867 \SpecialChar ~
17868 \SpecialChar ~
17869 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17870 \layout Standard
17871
17872 Here is a 
17873 \family typewriter 
17874 Makefile
17875 \family default 
17876  using MPLAB:
17877 \layout Verse
17878
17879
17880 \family typewriter 
17881 .c.o: 
17882 \newline 
17883 \SpecialChar ~
17884 \SpecialChar ~
17885 \SpecialChar ~
17886 \SpecialChar ~
17887 \SpecialChar ~
17888 \SpecialChar ~
17889 \SpecialChar ~
17890 \SpecialChar ~
17891 sdcc -S -V -mpic14 -p16F877 $< 
17892 \newline 
17893 \SpecialChar ~
17894 \SpecialChar ~
17895 \SpecialChar ~
17896 \SpecialChar ~
17897 \SpecialChar ~
17898 \SpecialChar ~
17899 \SpecialChar ~
17900 \SpecialChar ~
17901 mpasmwin /q /o $*.asm
17902 \newline 
17903
17904 \newline 
17905 $(PRJ).hex: $(OBJS) 
17906 \newline 
17907 \SpecialChar ~
17908 \SpecialChar ~
17909 \SpecialChar ~
17910 \SpecialChar ~
17911 \SpecialChar ~
17912 \SpecialChar ~
17913 \SpecialChar ~
17914 \SpecialChar ~
17915 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17916 \layout Standard
17917
17918 Please note that indentations within a
17919 \family typewriter 
17920  Makefile
17921 \family default 
17922  have to be done with a tabulator character.
17923 \layout Subsection
17924
17925 Command-line options
17926 \layout Standard
17927
17928 Besides the switches common to all SDCC backends, the PIC14 port accepts
17929  the following options (for an updated list see sdcc -
17930 \begin_inset ERT
17931 status Collapsed
17932
17933 \layout Standard
17934
17935 \backslash 
17936 /
17937 \end_inset 
17938
17939 -help):
17940 \layout List
17941 \labelwidthstring 00.00.0000
17942
17943 -
17944 \begin_inset ERT
17945 status Collapsed
17946
17947 \layout Standard
17948
17949 \backslash 
17950 /
17951 \end_inset 
17952
17953 -debug-extra
17954 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
17955
17956 \end_inset 
17957
17958  emit debug info in assembly output
17959 \layout List
17960 \labelwidthstring 00.00.0000
17961
17962 -
17963 \begin_inset ERT
17964 status Collapsed
17965
17966 \layout Standard
17967
17968 \backslash 
17969 /
17970 \end_inset 
17971
17972 -no-pcode-opt
17973 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
17974
17975 \end_inset 
17976
17977  disable (slightly faulty) optimization on pCode
17978 \layout Subsection
17979
17980 The library
17981 \layout Subsubsection
17982
17983 error: missing definition for symbol 
17984 \begin_inset Quotes sld
17985 \end_inset 
17986
17987 __gptrget1
17988 \begin_inset Quotes srd
17989 \end_inset 
17990
17991
17992 \layout Standard
17993
17994 The PIC14 port uses library routines to provide more complex operations
17995  like multiplication, division/modulus and (generic) pointer dereferencing.
17996  In order to add these routines to your project, you must link with PIC14's
17997  
17998 \family typewriter 
17999 libsdcc.lib
18000 \family default 
18001 .
18002  For single source file projects this is done automatically, more complex
18003  projects must add 
18004 \family typewriter 
18005 libsdcc.lib
18006 \family default 
18007  to the linker's arguments.
18008  Make sure you also add an include path for the library (using the -I switch
18009  to the linker)!
18010 \layout Subsubsection
18011
18012 Processor mismatch in file 
18013 \begin_inset Quotes sld
18014 \end_inset 
18015
18016 XXX
18017 \begin_inset Quotes srd
18018 \end_inset 
18019
18020 .
18021 \layout Standard
18022
18023 This warning can usually be ignored due to the very good compatibility amongst
18024  14 bit PIC
18025 \begin_inset LatexCommand \index{PIC14}
18026
18027 \end_inset 
18028
18029  devices.
18030 \layout Standard
18031
18032 You might also consider recompiling the library for your specific device
18033  by changing the ARCH=p16f877 (default target) entry in 
18034 \family typewriter 
18035 device/lib/pic/Makefile.in
18036 \family default 
18037  and 
18038 \family typewriter 
18039 device/lib/pic/Makefile
18040 \family default 
18041  to reflect your device.
18042  This might even improve performance for smaller devices as unneccesary
18043  BANKSELs migth be removed.
18044 \layout Subsection
18045
18046 Known bugs
18047 \layout Subsubsection
18048
18049 initialized data
18050 \layout Standard
18051
18052 Currently, data can only be initialized if it resides in the source file
18053  together with 
18054 \emph on 
18055 main()
18056 \emph default 
18057 .
18058  Data in other source files will silently 
18059 \series bold 
18060 not
18061 \series default 
18062  be initialized.
18063 \family typewriter 
18064 \size footnotesize 
18065
18066 \begin_inset Marginal
18067 collapsed true
18068
18069 \layout Standard
18070
18071
18072 \series bold 
18073 \SpecialChar ~
18074 !
18075 \end_inset 
18076
18077
18078 \layout Section
18079 \pagebreak_top 
18080 The PIC16
18081 \begin_inset LatexCommand \index{PIC16}
18082
18083 \end_inset 
18084
18085  port
18086 \layout Standard
18087
18088 The PIC16
18089 \begin_inset LatexCommand \index{PIC16}
18090
18091 \end_inset 
18092
18093  port is the portion of SDCC that is responsible to produce code for the
18094  Microchip
18095 \begin_inset LatexCommand \index{Microchip}
18096
18097 \end_inset 
18098
18099 (TM) microcontrollers with 16 bit core.
18100  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18101  Currently supported devices are:
18102 \layout Standard
18103 \align center 
18104
18105 \begin_inset  Tabular
18106 <lyxtabular version="3" rows="4" columns="6">
18107 <features>
18108 <column alignment="center" valignment="top" leftline="true" width="0">
18109 <column alignment="center" valignment="top" leftline="true" width="0">
18110 <column alignment="center" valignment="top" leftline="true" width="0">
18111 <column alignment="center" valignment="top" leftline="true" width="0">
18112 <column alignment="center" valignment="top" leftline="true" width="0">
18113 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18114 <row topline="true">
18115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18116 \begin_inset Text
18117
18118 \layout Standard
18119
18120 18F242
18121 \end_inset 
18122 </cell>
18123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18124 \begin_inset Text
18125
18126 \layout Standard
18127
18128 18F248
18129 \end_inset 
18130 </cell>
18131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18132 \begin_inset Text
18133
18134 \layout Standard
18135
18136 18F252
18137 \end_inset 
18138 </cell>
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18140 \begin_inset Text
18141
18142 \layout Standard
18143
18144 18F258
18145 \end_inset 
18146 </cell>
18147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18148 \begin_inset Text
18149
18150 \layout Standard
18151
18152 18F442
18153 \end_inset 
18154 </cell>
18155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18156 \begin_inset Text
18157
18158 \layout Standard
18159
18160 18F448
18161 \end_inset 
18162 </cell>
18163 </row>
18164 <row topline="true">
18165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18166 \begin_inset Text
18167
18168 \layout Standard
18169
18170 18F452
18171 \end_inset 
18172 </cell>
18173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18174 \begin_inset Text
18175
18176 \layout Standard
18177
18178 18F458
18179 \end_inset 
18180 </cell>
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18182 \begin_inset Text
18183
18184 \layout Standard
18185
18186 18F1220
18187 \end_inset 
18188 </cell>
18189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18190 \begin_inset Text
18191
18192 \layout Standard
18193
18194 18F2220
18195 \end_inset 
18196 </cell>
18197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18198 \begin_inset Text
18199
18200 \layout Standard
18201
18202 18F2550
18203 \end_inset 
18204 </cell>
18205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18206 \begin_inset Text
18207
18208 \layout Standard
18209
18210 18F4331
18211 \end_inset 
18212 </cell>
18213 </row>
18214 <row topline="true">
18215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18216 \begin_inset Text
18217
18218 \layout Standard
18219
18220 18F4455
18221 \end_inset 
18222 </cell>
18223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18224 \begin_inset Text
18225
18226 \layout Standard
18227
18228 18F6520
18229 \end_inset 
18230 </cell>
18231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18232 \begin_inset Text
18233
18234 \layout Standard
18235
18236 18F6620
18237 \end_inset 
18238 </cell>
18239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18240 \begin_inset Text
18241
18242 \layout Standard
18243
18244 18F6680
18245 \end_inset 
18246 </cell>
18247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18248 \begin_inset Text
18249
18250 \layout Standard
18251
18252 18F6720
18253 \end_inset 
18254 </cell>
18255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18256 \begin_inset Text
18257
18258 \layout Standard
18259
18260 18F8520
18261 \end_inset 
18262 </cell>
18263 </row>
18264 <row topline="true" bottomline="true">
18265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18266 \begin_inset Text
18267
18268 \layout Standard
18269
18270 18F8620
18271 \end_inset 
18272 </cell>
18273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18274 \begin_inset Text
18275
18276 \layout Standard
18277
18278 18F8680
18279 \end_inset 
18280 </cell>
18281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18282 \begin_inset Text
18283
18284 \layout Standard
18285
18286 18F8720
18287 \end_inset 
18288 </cell>
18289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18290 \begin_inset Text
18291
18292 \layout Standard
18293
18294 \end_inset 
18295 </cell>
18296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18297 \begin_inset Text
18298
18299 \layout Standard
18300
18301 \end_inset 
18302 </cell>
18303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18304 \begin_inset Text
18305
18306 \layout Standard
18307
18308 \end_inset 
18309 </cell>
18310 </row>
18311 </lyxtabular>
18312
18313 \end_inset 
18314
18315
18316 \layout Subsection
18317
18318 Global Options
18319 \layout Standard
18320
18321 PIC16 port supports the standard command line arguments as supposed, with
18322  the exception of certain cases that will be mentioned in the following
18323  list:
18324 \layout List
18325 \labelwidthstring 00.00.0000
18326
18327 -
18328 \begin_inset ERT
18329 status Collapsed
18330
18331 \layout Standard
18332
18333 \backslash 
18334 /
18335 \end_inset 
18336
18337 -callee-saves
18338 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18339
18340 \end_inset 
18341
18342  See -
18343 \begin_inset ERT
18344 status Collapsed
18345
18346 \layout Standard
18347
18348 \backslash 
18349 /
18350 \end_inset 
18351
18352 -all-callee-saves
18353 \layout List
18354 \labelwidthstring 00.00.0000
18355
18356 -
18357 \begin_inset ERT
18358 status Collapsed
18359
18360 \layout Standard
18361
18362 \backslash 
18363 /
18364 \end_inset 
18365
18366 -all-callee-saves
18367 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18368
18369 \end_inset 
18370
18371  All function arguments are passed on stack by default.
18372  
18373 \emph on 
18374 There is no need to specify this in the command line.
18375 \layout List
18376 \labelwidthstring 00.00.0000
18377
18378 -
18379 \begin_inset ERT
18380 status Collapsed
18381
18382 \layout Standard
18383
18384 \backslash 
18385 /
18386 \end_inset 
18387
18388 -fommit-frame-pointer
18389 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18390
18391 \end_inset 
18392
18393  Frame pointer will be omitted when the function uses no local variables.
18394 \layout Subsection
18395
18396 Port Specific Options
18397 \begin_inset LatexCommand \index{Options PIC16}
18398
18399 \end_inset 
18400
18401
18402 \layout Standard
18403
18404 The port specific options appear after the global options in the sdcc --help
18405  output.
18406 \layout Subsubsection
18407
18408 General Options
18409 \layout Standard
18410
18411 General options enable certain port features and optimizations.
18412 \layout List
18413 \labelwidthstring 00.00.0000
18414
18415 -
18416 \begin_inset ERT
18417 status Collapsed
18418
18419 \layout Standard
18420
18421 \backslash 
18422 /
18423 \end_inset 
18424
18425 -stack-model=[model] Used in conjuction with the command above.
18426  Defines the stack model to be used, valid stack models are : 
18427 \begin_deeper 
18428 \layout List
18429 \labelwidthstring 00.00.0000
18430
18431
18432 \emph on 
18433 small
18434 \emph default 
18435  Selects small stack model.
18436  8 bit stack and frame pointers.
18437  Supports 256 bytes stack size.
18438 \layout List
18439 \labelwidthstring 00.00.0000
18440
18441
18442 \emph on 
18443 large
18444 \emph default 
18445  Selects large stack model.
18446  16 bit stack and frame pointers.
18447  Supports 65536 bytes stack size.
18448 \end_deeper 
18449 \layout List
18450 \labelwidthstring 00.00.0000
18451
18452 -
18453 \begin_inset ERT
18454 status Collapsed
18455
18456 \layout Standard
18457
18458 \backslash 
18459 /
18460 \end_inset 
18461
18462 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18463  unitialized data variables with [kword].
18464  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18465 \layout List
18466 \labelwidthstring 00.00.0000
18467
18468 -
18469 \begin_inset ERT
18470 status Collapsed
18471
18472 \layout Standard
18473
18474 \backslash 
18475 /
18476 \end_inset 
18477
18478 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18479  Useful for bootloaders.
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 -asm= sets the full path and name of an external assembler to call.
18494 \layout List
18495 \labelwidthstring 00.00.0000
18496
18497 -
18498 \begin_inset ERT
18499 status Collapsed
18500
18501 \layout Standard
18502
18503 \backslash 
18504 /
18505 \end_inset 
18506
18507 -link= sets the full path and name of an external linker to call.
18508 \layout List
18509 \labelwidthstring 00.00.0000
18510
18511 -
18512 \begin_inset ERT
18513 status Collapsed
18514
18515 \layout Standard
18516
18517 \backslash 
18518 /
18519 \end_inset 
18520
18521 -mplab-comp MPLAB
18522 \begin_inset LatexCommand \index{PIC16!MPLAB}
18523
18524 \end_inset 
18525
18526  compatibility option.
18527  Currently only suppresses special gpasm directives.
18528 \layout Subsubsection
18529
18530 Optimization Options
18531 \layout List
18532 \labelwidthstring 00.00.0000
18533
18534 -
18535 \begin_inset ERT
18536 status Collapsed
18537
18538 \layout Standard
18539
18540 \backslash 
18541 /
18542 \end_inset 
18543
18544 -optimize-goto Try to use (conditional) BRA instead of GOTO
18545 \layout List
18546 \labelwidthstring 00.00.0000
18547
18548 -
18549 \begin_inset ERT
18550 status Collapsed
18551
18552 \layout Standard
18553
18554 \backslash 
18555 /
18556 \end_inset 
18557
18558 -optimize-cmp Try to optimize some compares.
18559 \layout List
18560 \labelwidthstring 00.00.0000
18561
18562 -
18563 \begin_inset ERT
18564 status Collapsed
18565
18566 \layout Standard
18567
18568 \backslash 
18569 /
18570 \end_inset 
18571
18572 -optimize-df Analyze the dataflow of the generated code and improve it.
18573 \layout List
18574 \labelwidthstring 00.00.0000
18575
18576 -
18577 \begin_inset ERT
18578 status Collapsed
18579
18580 \layout Standard
18581
18582 \backslash 
18583 /
18584 \end_inset 
18585
18586 -obanksel=nn Set optimization level for inserting BANKSELs.
18587 \newline 
18588
18589 \begin_deeper 
18590 \layout List
18591 \labelwidthstring 00.00.0000
18592
18593 0 no optimization
18594 \layout List
18595 \labelwidthstring 00.00.0000
18596
18597 1 checks previous used register and if it is the same then does not emit
18598  BANKSEL, accounts only for labels.
18599 \layout List
18600 \labelwidthstring 00.00.0000
18601
18602 2 tries to check the location of (even different) symbols and removes BANKSELs
18603  if they are in the same bank.
18604  
18605 \newline 
18606
18607 \emph on 
18608 Important: There might be problems if the linker script has data sections
18609  across bank borders!
18610 \end_deeper 
18611 \layout Subsubsection
18612
18613 Linking Options
18614 \layout List
18615 \labelwidthstring 00.00.0000
18616
18617 -
18618 \begin_inset ERT
18619 status Collapsed
18620
18621 \layout Standard
18622
18623 \backslash 
18624 /
18625 \end_inset 
18626
18627 -nodefaultlibs do not link default libraries when linking
18628 \layout List
18629 \labelwidthstring 00.00.0000
18630
18631 -
18632 \begin_inset ERT
18633 status Collapsed
18634
18635 \layout Standard
18636
18637 \backslash 
18638 /
18639 \end_inset 
18640
18641 -no-crt Don't link the default run-time modules
18642 \layout List
18643 \labelwidthstring 00.00.0000
18644
18645 -
18646 \begin_inset ERT
18647 status Collapsed
18648
18649 \layout Standard
18650
18651 \backslash 
18652 /
18653 \end_inset 
18654
18655 -use-crt= Use a custom run-time module instead of the defaults.
18656 \layout Subsubsection
18657
18658 Debugging Options
18659 \layout Standard
18660
18661 Debugging options enable extra debugging information in the output files.
18662 \layout List
18663 \labelwidthstring 00.00.0000
18664
18665 -
18666 \begin_inset ERT
18667 status Collapsed
18668
18669 \layout Standard
18670
18671 \backslash 
18672 /
18673 \end_inset 
18674
18675 -debug-xtra Similar to -
18676 \begin_inset ERT
18677 status Collapsed
18678
18679 \layout Standard
18680
18681 \backslash 
18682 /
18683 \end_inset 
18684
18685 -debug
18686 \begin_inset LatexCommand \index{-\/-debug}
18687
18688 \end_inset 
18689
18690 , but dumps more information.
18691 \layout List
18692 \labelwidthstring 00.00.0000
18693
18694 -
18695 \begin_inset ERT
18696 status Collapsed
18697
18698 \layout Standard
18699
18700 \backslash 
18701 /
18702 \end_inset 
18703
18704 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18705  information.
18706  <source> is the name of the file compiled.
18707 \layout List
18708 \labelwidthstring 00.00.0000
18709
18710 -
18711 \begin_inset ERT
18712 status Collapsed
18713
18714 \layout Standard
18715
18716 \backslash 
18717 /
18718 \end_inset 
18719
18720 -pcode-verbose Enable pcode debugging information in translation.
18721 \layout List
18722 \labelwidthstring 00.00.0000
18723
18724 -
18725 \begin_inset ERT
18726 status Collapsed
18727
18728 \layout Standard
18729
18730 \backslash 
18731 /
18732 \end_inset 
18733
18734 -denable-peeps Force the usage of peepholes.
18735  Use with care.
18736 \layout List
18737 \labelwidthstring 00.00.0000
18738
18739 -
18740 \begin_inset ERT
18741 status Collapsed
18742
18743 \layout Standard
18744
18745 \backslash 
18746 /
18747 \end_inset 
18748
18749 -gstack Trace push/pops for stack pointer overflow
18750 \layout List
18751 \labelwidthstring 00.00.0000
18752
18753 -
18754 \begin_inset ERT
18755 status Collapsed
18756
18757 \layout Standard
18758
18759 \backslash 
18760 /
18761 \end_inset 
18762
18763 -call-tree dump call tree in .calltree file
18764 \layout Subsection
18765
18766 Enviromental Variables
18767 \layout Standard
18768
18769 There is a number of enviromental variables that can be used when running
18770  SDCC to enable certain optimizations or force a specific program behaviour.
18771  these variables are primarily for debugging purposes so they can be enabled/dis
18772 abled at will.
18773 \layout Standard
18774
18775 Currently there is only two such variables available:
18776 \layout List
18777 \labelwidthstring 00.00.0000
18778
18779 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18780  bitfields is optimized by directly loading FSR0 with the address of the
18781  bitfield structure.
18782  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18783  then load FSR0.
18784  This step saves data ram and code space for functions that perform heavy
18785  use of bitfields.
18786  (ie.
18787  80 bytes of code space are saved when compiling malloc.c with this option).
18788  
18789 \layout List
18790 \labelwidthstring 00.00.0000
18791
18792 NO_REG_OPT do not perform pCode registers optimization.
18793  This should be used for debugging purposes.
18794  In some where bugs in the pcode optimizer are found, users can benefit
18795  from temporarily disabling the optimizer until the bug is fixed.
18796 \layout Subsection
18797
18798 Preprocessor Macros
18799 \layout Standard
18800
18801 PIC16
18802 \begin_inset LatexCommand \index{PIC16}
18803
18804 \end_inset 
18805
18806  port defines the following preprocessor macros while translating a source.
18807 \layout Standard
18808 \align center 
18809
18810 \begin_inset  Tabular
18811 <lyxtabular version="3" rows="6" columns="2">
18812 <features>
18813 <column alignment="center" valignment="top" leftline="true" width="0">
18814 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18815 <row topline="true" bottomline="true">
18816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18817 \begin_inset Text
18818
18819 \layout Standard
18820
18821 Macro
18822 \end_inset 
18823 </cell>
18824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18825 \begin_inset Text
18826
18827 \layout Standard
18828
18829 Description
18830 \end_inset 
18831 </cell>
18832 </row>
18833 <row topline="true">
18834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18835 \begin_inset Text
18836
18837 \layout Standard
18838
18839 SDCC_pic16
18840 \end_inset 
18841 </cell>
18842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18843 \begin_inset Text
18844
18845 \layout Standard
18846
18847 Port identification
18848 \end_inset 
18849 </cell>
18850 </row>
18851 <row topline="true">
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18853 \begin_inset Text
18854
18855 \layout Standard
18856
18857 _
18858 \begin_inset ERT
18859 status Collapsed
18860
18861 \layout Standard
18862
18863 \backslash 
18864 /
18865 \end_inset 
18866
18867 _pic16
18868 \end_inset 
18869 </cell>
18870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18871 \begin_inset Text
18872
18873 \layout Standard
18874
18875 Port identification (same as above)
18876 \end_inset 
18877 </cell>
18878 </row>
18879 <row topline="true">
18880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18881 \begin_inset Text
18882
18883 \layout Standard
18884
18885 pic18fxxxx
18886 \end_inset 
18887 </cell>
18888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18889 \begin_inset Text
18890
18891 \layout Standard
18892
18893 MCU Identification.
18894  
18895 \emph on 
18896 xxxx
18897 \emph default 
18898  is the microcontrol identification number, i.e.
18899  452, 6620, etc
18900 \end_inset 
18901 </cell>
18902 </row>
18903 <row topline="true">
18904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18905 \begin_inset Text
18906
18907 \layout Standard
18908
18909 _
18910 \begin_inset ERT
18911 status Collapsed
18912
18913 \layout Standard
18914
18915 \backslash 
18916 /
18917 \end_inset 
18918
18919 _18Fxxxx
18920 \end_inset 
18921 </cell>
18922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18923 \begin_inset Text
18924
18925 \layout Standard
18926
18927 MCU Identification (same as above)
18928 \end_inset 
18929 </cell>
18930 </row>
18931 <row topline="true" bottomline="true">
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18933 \begin_inset Text
18934
18935 \layout Standard
18936
18937 STACK_MODEL_nnn
18938 \end_inset 
18939 </cell>
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18941 \begin_inset Text
18942
18943 \layout Standard
18944
18945 nnn = SMALL or LARGE respectively according to the stack model used
18946 \end_inset 
18947 </cell>
18948 </row>
18949 </lyxtabular>
18950
18951 \end_inset 
18952
18953
18954 \layout Standard
18955
18956 In addition the following macros are defined when calling assembler:
18957 \layout Standard
18958 \align center 
18959
18960 \begin_inset  Tabular
18961 <lyxtabular version="3" rows="4" columns="2">
18962 <features>
18963 <column alignment="center" valignment="top" leftline="true" width="0">
18964 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18965 <row topline="true" bottomline="true">
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18967 \begin_inset Text
18968
18969 \layout Standard
18970
18971 Macro
18972 \end_inset 
18973 </cell>
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18975 \begin_inset Text
18976
18977 \layout Standard
18978
18979 Description
18980 \end_inset 
18981 </cell>
18982 </row>
18983 <row topline="true">
18984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18985 \begin_inset Text
18986
18987 \layout Standard
18988
18989 __18Fxxxx
18990 \end_inset 
18991 </cell>
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \layout Standard
18996
18997 MCU Identification.
18998  
18999 \emph on 
19000 xxxx
19001 \emph default 
19002  is the microcontrol identification number, i.e.
19003  452, 6620, etc
19004 \end_inset 
19005 </cell>
19006 </row>
19007 <row topline="true">
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19009 \begin_inset Text
19010
19011 \layout Standard
19012
19013 SDCC_MODEL_nnn
19014 \end_inset 
19015 </cell>
19016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19017 \begin_inset Text
19018
19019 \layout Standard
19020
19021 nnn = SMALL or LARGE respectively according to the memory model used for
19022  SDCC
19023 \end_inset 
19024 </cell>
19025 </row>
19026 <row topline="true" bottomline="true">
19027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19028 \begin_inset Text
19029
19030 \layout Standard
19031
19032 STACK_MODEL_nnn
19033 \end_inset 
19034 </cell>
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19036 \begin_inset Text
19037
19038 \layout Standard
19039
19040 nnn = SMALL or LARGE respectively according to the stack model used
19041 \end_inset 
19042 </cell>
19043 </row>
19044 </lyxtabular>
19045
19046 \end_inset 
19047
19048
19049 \layout Subsection
19050
19051 Directories
19052 \layout Standard
19053
19054 PIC16
19055 \begin_inset LatexCommand \index{PIC16}
19056
19057 \end_inset 
19058
19059  port uses the following directories for searching header files and libraries.
19060 \layout Standard
19061 \align center 
19062
19063 \begin_inset  Tabular
19064 <lyxtabular version="3" rows="3" columns="4">
19065 <features>
19066 <column alignment="center" valignment="top" leftline="true" width="0">
19067 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19068 <column alignment="center" valignment="top" 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 Directory
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 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19088 \begin_inset Text
19089
19090 \layout Standard
19091
19092 Target
19093 \end_inset 
19094 </cell>
19095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19096 \begin_inset Text
19097
19098 \layout Standard
19099
19100 Command prefix
19101 \end_inset 
19102 </cell>
19103 </row>
19104 <row topline="true">
19105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19106 \begin_inset Text
19107
19108 \layout Standard
19109
19110 PREFIX/sdcc/include/pic16
19111 \end_inset 
19112 </cell>
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19114 \begin_inset Text
19115
19116 \layout Standard
19117
19118 PIC16 specific headers
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 Compiler
19127 \end_inset 
19128 </cell>
19129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19130 \begin_inset Text
19131
19132 \layout Standard
19133
19134 -I
19135 \end_inset 
19136 </cell>
19137 </row>
19138 <row topline="true" bottomline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19140 \begin_inset Text
19141
19142 \layout Standard
19143
19144 PREFIX/sdcc/lib/pic16
19145 \end_inset 
19146 </cell>
19147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19148 \begin_inset Text
19149
19150 \layout Standard
19151
19152 PIC16 specific libraries
19153 \end_inset 
19154 </cell>
19155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19156 \begin_inset Text
19157
19158 \layout Standard
19159
19160 Linker
19161 \end_inset 
19162 </cell>
19163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19164 \begin_inset Text
19165
19166 \layout Standard
19167
19168 -L
19169 \end_inset 
19170 </cell>
19171 </row>
19172 </lyxtabular>
19173
19174 \end_inset 
19175
19176
19177 \layout Subsection
19178
19179 Pragmas
19180 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19181
19182 \end_inset 
19183
19184
19185 \layout Standard
19186
19187 PIC16
19188 \begin_inset LatexCommand \index{PIC16}
19189
19190 \end_inset 
19191
19192  port currently supports the following pragmas:
19193 \layout List
19194 \labelwidthstring 00.00.0000
19195
19196 stack
19197 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19198
19199 \end_inset 
19200
19201  pragma stack
19202 \begin_inset LatexCommand \index{PIC16!stack}
19203
19204 \end_inset 
19205
19206  forces the code generator to initialize the stack & frame pointers at a
19207  specific address.
19208  This is an adhoc solution for cases where no STACK directive is available
19209  in the linker script or gplink is not instructed to create a stack section.
19210 \newline 
19211 The stack pragma should be used only once in a project.
19212  Multiple pragmas may result in indeterminate behaviour of the program.
19213 \begin_inset Foot
19214 collapsed false
19215
19216 \layout Standard
19217
19218 The old format (ie.
19219  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19220  cross page boundaries (or even exceed the available data RAM) and crash
19221  the program.
19222  Make sure that stack does not cross page boundaries when using the SMALL
19223  stack model.
19224 \end_inset 
19225
19226
19227 \newline 
19228 The format is as follows:
19229 \layout LyX-Code
19230
19231 #pragma stack bottom_address [stack_size]
19232 \layout Standard
19233
19234
19235 \emph on 
19236 bottom_address
19237 \emph default 
19238  is the lower bound of the stack section.
19239  The stack pointer initially will point at address (bottom_address+stack_size-1).
19240 \layout LyX-Code
19241
19242 Example:
19243 \layout LyX-Code
19244
19245 \layout LyX-Code
19246
19247 /* initializes stack of 100 bytes at RAM address 0x200 */
19248 \layout LyX-Code
19249
19250 #pragma stack 0x200 100
19251 \layout Standard
19252
19253 If the stack_size field is omitted then a stack is created with the default
19254  size of 64.
19255  This size might be enough for most programs, but its not enough for operations
19256  with deep function nesting or excessive stack usage.
19257 \layout List
19258 \labelwidthstring 00.00.0000
19259
19260 wparam 
19261 \emph on 
19262 This pragma is deprecated.
19263  Its use will cause a warning message to be issued.
19264 \emph default 
19265
19266 \newline 
19267
19268 \layout List
19269 \labelwidthstring 00.00.0000
19270
19271 code
19272 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19273
19274 \end_inset 
19275
19276  place a function symbol at static FLASH address
19277 \layout LyX-Code
19278
19279 Example:
19280 \layout LyX-Code
19281
19282 \layout LyX-Code
19283
19284 /* place function test_func at 0x4000 */
19285 \layout LyX-Code
19286
19287 #pragma code test_func 0x4000
19288 \layout LyX-Code
19289
19290 \layout List
19291 \labelwidthstring 00.00.0000
19292
19293 library instructs the linker to use a library module.
19294 \newline 
19295 Usage:
19296 \layout LyX-Code
19297
19298 #pragma library module_name
19299 \layout Standard
19300
19301
19302 \emph on 
19303 module_name
19304 \emph default 
19305  can be any library or object file (including its path).
19306  Note that there are four reserved keywords which have special meaning.
19307  These are:
19308 \layout Standard
19309 \align center 
19310
19311 \begin_inset  Tabular
19312 <lyxtabular version="3" rows="6" columns="3">
19313 <features>
19314 <column alignment="center" valignment="top" leftline="true" width="0">
19315 <column alignment="block" valignment="top" leftline="true" width="20page%">
19316 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19317 <row topline="true" bottomline="true">
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \layout Standard
19322
19323 Keyword
19324 \end_inset 
19325 </cell>
19326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19327 \begin_inset Text
19328
19329 \layout Standard
19330
19331 Description
19332 \end_inset 
19333 </cell>
19334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19335 \begin_inset Text
19336
19337 \layout Standard
19338
19339 Module to link
19340 \end_inset 
19341 </cell>
19342 </row>
19343 <row topline="true">
19344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19345 \begin_inset Text
19346
19347 \layout Standard
19348
19349
19350 \series bold 
19351 ignore
19352 \end_inset 
19353 </cell>
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19355 \begin_inset Text
19356
19357 \layout Standard
19358
19359 ignore all library pragmas
19360 \end_inset 
19361 </cell>
19362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19363 \begin_inset Text
19364
19365 \layout Standard
19366
19367
19368 \emph on 
19369 (none)
19370 \end_inset 
19371 </cell>
19372 </row>
19373 <row topline="true">
19374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19375 \begin_inset Text
19376
19377 \layout Standard
19378
19379
19380 \series bold 
19381 c
19382 \end_inset 
19383 </cell>
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19385 \begin_inset Text
19386
19387 \layout Standard
19388
19389 link the C library
19390 \end_inset 
19391 </cell>
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \layout Standard
19396
19397
19398 \emph on 
19399 libc18f
19400 \emph default 
19401 .lib
19402 \end_inset 
19403 </cell>
19404 </row>
19405 <row topline="true">
19406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_inset Text
19408
19409 \layout Standard
19410
19411
19412 \series bold 
19413 math
19414 \end_inset 
19415 </cell>
19416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19417 \begin_inset Text
19418
19419 \layout Standard
19420
19421 link the Math libarary
19422 \end_inset 
19423 </cell>
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19425 \begin_inset Text
19426
19427 \layout Standard
19428
19429
19430 \emph on 
19431 libm18f
19432 \emph default 
19433 .lib
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 io
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 link the I/O library
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 libio18f*
19464 \emph default 
19465 .lib
19466 \end_inset 
19467 </cell>
19468 </row>
19469 <row topline="true" bottomline="true">
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \layout Standard
19474
19475
19476 \series bold 
19477 debug
19478 \end_inset 
19479 </cell>
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \layout Standard
19484
19485 link the debug library
19486 \end_inset 
19487 </cell>
19488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19489 \begin_inset Text
19490
19491 \layout Standard
19492
19493
19494 \emph on 
19495 libdebug
19496 \emph default 
19497 .lib
19498 \end_inset 
19499 </cell>
19500 </row>
19501 </lyxtabular>
19502
19503 \end_inset 
19504
19505
19506 \newline 
19507 * is the device number, i.e.
19508  452 for PIC18F452 MCU.
19509 \layout Standard
19510
19511 This feature allows for linking with specific libraries withoug having to
19512  explicit name them in the command line.
19513  Note that the 
19514 \noun on 
19515 ignore
19516 \noun default 
19517  keyword will reject all modules specified by the library pragma.
19518 \layout List
19519 \labelwidthstring 00.00.0000
19520
19521 udata pragma udata instructs the compiler to emit code so that linker will
19522  place a variable at a specific memory bank
19523 \layout LyX-Code
19524
19525 Example:
19526 \layout LyX-Code
19527
19528 \layout LyX-Code
19529
19530 /* places variable foo at bank2 */
19531 \layout LyX-Code
19532
19533 #pragma udata bank2 foo
19534 \layout LyX-Code
19535
19536 char foo;
19537 \layout Standard
19538
19539 In order for this pragma to work extra SECTION directives should be added
19540  in the .lkr script.
19541  In the following example a sample .lkr file is shown:
19542 \layout LyX-Code
19543
19544 \layout LyX-Code
19545
19546 // Sample linker script for the PIC18F452 processor
19547 \layout LyX-Code
19548
19549 LIBPATH .
19550 \layout LyX-Code
19551
19552 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19553 \layout LyX-Code
19554
19555 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19556 \layout LyX-Code
19557
19558 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19559 \layout LyX-Code
19560
19561 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19562 \layout LyX-Code
19563
19564 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19565 \layout LyX-Code
19566
19567 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19568 \layout LyX-Code
19569
19570 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19571 \layout LyX-Code
19572
19573 \layout LyX-Code
19574
19575 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19576 \layout LyX-Code
19577
19578 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19579 \layout LyX-Code
19580
19581 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19582 \layout LyX-Code
19583
19584 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19585 \layout LyX-Code
19586
19587 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19588 \layout LyX-Code
19589
19590 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19591 \layout LyX-Code
19592
19593 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19594 \layout LyX-Code
19595
19596 \layout LyX-Code
19597
19598 SECTION    NAME=CONFIG     ROM=config
19599 \layout LyX-Code
19600
19601 \layout LyX-Code
19602
19603 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19604 \layout LyX-Code
19605
19606 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19607 \layout LyX-Code
19608
19609 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19610 \layout LyX-Code
19611
19612 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19613 \layout LyX-Code
19614
19615 SECTION    NAME=bank4      RAM=gpr4
19616 \layout LyX-Code
19617
19618 SECTION    NAME=bank5      RAM=gpr5
19619 \layout Standard
19620
19621 The linker will recognise the section name set in the pragma statement and
19622  will position the variable at the memory bank set with the RAM field at
19623  the SECTION line in the linker script file.
19624 \layout Subsection
19625
19626 Header Files
19627 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19628
19629 \end_inset 
19630
19631
19632 \layout Standard
19633
19634 There is one main header file
19635 \begin_inset LatexCommand \index{PIC16!Header files}
19636
19637 \end_inset 
19638
19639  that can be included to the source files using the pic16
19640 \begin_inset LatexCommand \index{PIC16}
19641
19642 \end_inset 
19643
19644  port.
19645  That file is the 
19646 \series bold 
19647 pic18fregs.h
19648 \series default 
19649 .
19650  This header file contains the definitions for the processor special registers,
19651  so it is necessary if the source accesses them.
19652  It can be included by adding the following line in the beginning of the
19653  file:
19654 \layout LyX-Code
19655
19656 #include <pic18fregs.h>
19657 \layout Standard
19658
19659 The specific microcontroller is selected within the pic18fregs.h automatically,
19660  so the same source can be used with a variety of devices.
19661 \layout Subsection
19662
19663 Libraries
19664 \layout Standard
19665
19666 The libraries
19667 \begin_inset LatexCommand \index{PIC16!Libraries}
19668
19669 \end_inset 
19670
19671  that PIC16
19672 \begin_inset LatexCommand \index{PIC16}
19673
19674 \end_inset 
19675
19676  port depends on are the microcontroller device libraries which contain
19677  the symbol definitions for the microcontroller special function registers.
19678  These libraries have the format pic18fxxxx.lib, where 
19679 \emph on 
19680 xxxx
19681 \emph default 
19682  is the microcontroller identification number.
19683  The specific library is selected automatically by the compiler at link
19684  stage according to the selected device.
19685 \layout Standard
19686
19687 Libraries are created with gplib which is part of the gputils package 
19688 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19689
19690 \end_inset 
19691
19692 .
19693 \layout Subsubsection*
19694
19695 Building the libraries
19696 \layout Standard
19697
19698 Before using SDCC/pic16 there are some libraries that need to be compiled.
19699  This process is not done automatically by SDCC since not all users use
19700  SDCC for pic16 projects.
19701  So each user should compile the libraries separately.
19702 \layout Standard
19703
19704 The steps to compile the pic16 libraries under Linux are:
19705 \layout LyX-Code
19706
19707 cd device/lib/pic16
19708 \layout LyX-Code
19709
19710 ./configure
19711 \layout LyX-Code
19712
19713 make
19714 \layout LyX-Code
19715
19716 cd ..
19717 \layout LyX-Code
19718
19719 make model-pic16
19720 \layout LyX-Code
19721
19722 su -c 'make install'     # install the libraries, you need the root password
19723 \layout Standard
19724
19725 If you need to install the headers too, do:
19726 \layout LyX-Code
19727
19728 cd device/include
19729 \layout LyX-Code
19730
19731 su -c 'make install'     # install the headers, you need the root password
19732 \layout Standard
19733
19734 There exist a special target to build the I/O libraries.
19735  This target is not automatically build because it will build the I/O library
19736  for 
19737 \emph on 
19738 every
19739 \emph default 
19740  supported device.
19741  This way building will take quite a lot of time.
19742  Users are advised to edit the 
19743 \series bold 
19744 device/lib/pic16/pics.build
19745 \series default 
19746  file and then execute:
19747 \layout LyX-Code
19748
19749 make lib-io
19750 \layout Subsection
19751
19752 Memory Models
19753 \layout Standard
19754
19755 The following memory models are supported by the PIC16 port:
19756 \layout Itemize
19757
19758 small model
19759 \layout Itemize
19760
19761 large model
19762 \layout Standard
19763
19764 Memory model affects the default size of pointers within the source.
19765  The sizes are shown in the next table:
19766 \layout Standard
19767 \align center 
19768
19769 \begin_inset  Tabular
19770 <lyxtabular version="3" rows="3" columns="3">
19771 <features>
19772 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19773 <column alignment="center" valignment="top" leftline="true" width="0">
19774 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19775 <row topline="true" bottomline="true">
19776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19777 \begin_inset Text
19778
19779 \layout Standard
19780
19781 Pointer sizes according to memory model
19782 \end_inset 
19783 </cell>
19784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19785 \begin_inset Text
19786
19787 \layout Standard
19788
19789 small model
19790 \end_inset 
19791 </cell>
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19793 \begin_inset Text
19794
19795 \layout Standard
19796
19797 large model
19798 \end_inset 
19799 </cell>
19800 </row>
19801 <row topline="true" bottomline="true">
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \layout Standard
19806
19807 code pointers
19808 \end_inset 
19809 </cell>
19810 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19811 \begin_inset Text
19812
19813 \layout Standard
19814
19815 16-bits
19816 \end_inset 
19817 </cell>
19818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19819 \begin_inset Text
19820
19821 \layout Standard
19822
19823 24-bits
19824 \end_inset 
19825 </cell>
19826 </row>
19827 <row topline="true" bottomline="true">
19828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19829 \begin_inset Text
19830
19831 \layout Standard
19832
19833 data pointers
19834 \end_inset 
19835 </cell>
19836 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19837 \begin_inset Text
19838
19839 \layout Standard
19840
19841 16-bits
19842 \end_inset 
19843 </cell>
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19845 \begin_inset Text
19846
19847 \layout Standard
19848
19849 16-bits
19850 \end_inset 
19851 </cell>
19852 </row>
19853 </lyxtabular>
19854
19855 \end_inset 
19856
19857
19858 \layout Standard
19859
19860 It is advisable that all sources within a project are compiled with the
19861  same memory model.
19862  If one wants to override the default memory model, this can be done by
19863  declaring a pointer as 
19864 \series bold 
19865 far
19866 \series default 
19867  or 
19868 \series bold 
19869 near
19870 \series default 
19871 .
19872  Far selects large memory model's pointers, while near selects small memory
19873  model's pointers.
19874 \layout Standard
19875
19876 The standard device libraries (see 
19877 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19878
19879 \end_inset 
19880
19881 ) contain no reference to pointers, so they can be used with both memory
19882  models.
19883 \layout Subsection
19884
19885 Stack
19886 \layout Standard
19887
19888 The stack
19889 \begin_inset LatexCommand \index{PIC16!stack}
19890
19891 \end_inset 
19892
19893  implementation for the PIC16 port uses two indirect registers, FSR1 and
19894  FSR2.
19895 \layout List
19896 \labelwidthstring 00.00.0000
19897
19898 FSR1 is assigned as stack pointer
19899 \layout List
19900 \labelwidthstring 00.00.0000
19901
19902 FSR2 is assigned as frame pointer
19903 \layout Standard
19904
19905 The following stack models are supported by the PIC16 port
19906 \layout Itemize
19907
19908
19909 \noun on 
19910 small
19911 \noun default 
19912  model
19913 \layout Itemize
19914
19915
19916 \noun on 
19917 large
19918 \noun default 
19919  model
19920 \layout Standard
19921
19922
19923 \noun on 
19924 Small
19925 \noun default 
19926  model means that only the FSRxL byte is used to access stack and frame,
19927  while 
19928 \emph on 
19929 \noun on 
19930 large
19931 \emph default 
19932 \noun default 
19933  uses both FSRxL and FSRxH registers.
19934  The following table shows the stack/frame pointers sizes according to stack
19935  model and the maximum space they can address:
19936 \layout Standard
19937 \align center 
19938
19939 \begin_inset  Tabular
19940 <lyxtabular version="3" rows="3" columns="3">
19941 <features>
19942 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19943 <column alignment="center" valignment="top" leftline="true" width="0">
19944 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19945 <row topline="true" bottomline="true">
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19947 \begin_inset Text
19948
19949 \layout Standard
19950
19951 Stack & Frame pointer sizes according to stack model
19952 \end_inset 
19953 </cell>
19954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19955 \begin_inset Text
19956
19957 \layout Standard
19958
19959 small
19960 \end_inset 
19961 </cell>
19962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19963 \begin_inset Text
19964
19965 \layout Standard
19966
19967 large
19968 \end_inset 
19969 </cell>
19970 </row>
19971 <row topline="true">
19972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19973 \begin_inset Text
19974
19975 \layout Standard
19976
19977 Stack pointer FSR1
19978 \end_inset 
19979 </cell>
19980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19981 \begin_inset Text
19982
19983 \layout Standard
19984
19985 8-bits
19986 \end_inset 
19987 </cell>
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_inset Text
19990
19991 \layout Standard
19992
19993 16-bits
19994 \end_inset 
19995 </cell>
19996 </row>
19997 <row topline="true" bottomline="true">
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19999 \begin_inset Text
20000
20001 \layout Standard
20002
20003 Frame pointer FSR2
20004 \end_inset 
20005 </cell>
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_inset Text
20008
20009 \layout Standard
20010
20011 8-bits
20012 \end_inset 
20013 </cell>
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_inset Text
20016
20017 \layout Standard
20018
20019 16-bits
20020 \end_inset 
20021 </cell>
20022 </row>
20023 </lyxtabular>
20024
20025 \end_inset 
20026
20027
20028 \layout Standard
20029
20030
20031 \noun on 
20032 Large 
20033 \noun default 
20034 stack model is currently not working properly throughout the code generator.
20035  So its use is not advised.
20036  Also there are some other points that need special care:
20037 \newline 
20038
20039 \layout Enumerate
20040
20041 Do not create stack sections with size more than one physical bank (that
20042  is 256 bytes)
20043 \layout Enumerate
20044
20045 Stack sections should no cross physical bank limits (i.e.
20046  #pragma stack 0x50 0x100)
20047 \layout Standard
20048
20049 These limitations are caused by the fact that only FSRxL is modified when
20050  using SMALL stack model, so no more than 256 bytes of stack can be used.
20051  This problem will disappear after LARGE model is fully implemented.
20052 \layout Subsection
20053
20054 Functions
20055 \layout Standard
20056
20057 In addition to the standard SDCC function keywords, PIC16
20058 \begin_inset LatexCommand \index{PIC16}
20059
20060 \end_inset 
20061
20062  port makes available two more:
20063 \layout List
20064 \labelwidthstring 00.00.0000
20065
20066 wparam
20067 \begin_inset LatexCommand \index{PIC16!wparam}
20068
20069 \end_inset 
20070
20071  Use the WREG to pass one byte of the first function argument.
20072  This improves speed but you may not use this for functions with arguments
20073  that are called via function pointers, otherwise the first byte of the
20074  first parameter will get lost.
20075  Usage:
20076 \layout LyX-Code
20077
20078 void func_wparam(int a) wparam
20079 \layout LyX-Code
20080
20081 {
20082 \layout LyX-Code
20083
20084     /* WREG hold the lower part of a */
20085 \layout LyX-Code
20086
20087     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20088  */
20089 \layout LyX-Code
20090
20091 ...
20092 \layout LyX-Code
20093
20094 }
20095 \layout Standard
20096
20097 This keyword replaces the deprecated wparam pragma.
20098 \layout List
20099 \labelwidthstring 00.00.0000
20100
20101 shadowregs
20102 \begin_inset LatexCommand \index{PIC16!shadowregs}
20103
20104 \end_inset 
20105
20106  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20107  hardware shadow registers which hold the values of WREG, STATUS and BSR
20108  registers.
20109  This can be done by adding the keyword 
20110 \emph on 
20111 shadowregs
20112 \emph default 
20113  before the 
20114 \emph on 
20115 interrupt
20116 \emph default 
20117  keyword in the function's header.
20118 \layout LyX-Code
20119
20120 void isr_shadow(void) shadowregs interrupt 1
20121 \layout LyX-Code
20122
20123 {
20124 \layout LyX-Code
20125
20126 ...
20127 \layout LyX-Code
20128
20129 }
20130 \layout Standard
20131
20132
20133 \emph on 
20134 shadowregs
20135 \emph default 
20136  instructs the code generator not to store/restore WREG, STATUS, BSR when
20137  entering/exiting the ISR.
20138 \layout Subsection
20139
20140 Function return values
20141 \layout Standard
20142
20143 Return values from functions are placed to the appropriate registers following
20144  a modified Microchip policy optimized for SDCC.
20145  The following table shows these registers:
20146 \layout Standard
20147 \align center 
20148
20149 \begin_inset  Tabular
20150 <lyxtabular version="3" rows="6" columns="2">
20151 <features>
20152 <column alignment="center" valignment="top" leftline="true" width="0">
20153 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20154 <row topline="true" bottomline="true">
20155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20156 \begin_inset Text
20157
20158 \layout Standard
20159
20160 size
20161 \end_inset 
20162 </cell>
20163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20164 \begin_inset Text
20165
20166 \layout Standard
20167
20168 destination register
20169 \end_inset 
20170 </cell>
20171 </row>
20172 <row topline="true">
20173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20174 \begin_inset Text
20175
20176 \layout Standard
20177
20178 8 bits
20179 \end_inset 
20180 </cell>
20181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20182 \begin_inset Text
20183
20184 \layout Standard
20185
20186 WREG
20187 \end_inset 
20188 </cell>
20189 </row>
20190 <row topline="true">
20191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20192 \begin_inset Text
20193
20194 \layout Standard
20195
20196 16 bits
20197 \end_inset 
20198 </cell>
20199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20200 \begin_inset Text
20201
20202 \layout Standard
20203
20204 PRODL:WREG
20205 \end_inset 
20206 </cell>
20207 </row>
20208 <row topline="true">
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20210 \begin_inset Text
20211
20212 \layout Standard
20213
20214 24 bits
20215 \end_inset 
20216 </cell>
20217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20218 \begin_inset Text
20219
20220 \layout Standard
20221
20222 PRODH:PRODL:WREG
20223 \end_inset 
20224 </cell>
20225 </row>
20226 <row topline="true">
20227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20228 \begin_inset Text
20229
20230 \layout Standard
20231
20232 32 bits
20233 \end_inset 
20234 </cell>
20235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20236 \begin_inset Text
20237
20238 \layout Standard
20239
20240 FSR0L:PRODH:PRODL:WREG
20241 \end_inset 
20242 </cell>
20243 </row>
20244 <row topline="true" bottomline="true">
20245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20246 \begin_inset Text
20247
20248 \layout Standard
20249
20250 >32 bits
20251 \end_inset 
20252 </cell>
20253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20254 \begin_inset Text
20255
20256 \layout Standard
20257
20258 on stack, FSR0 points to the beginning
20259 \end_inset 
20260 </cell>
20261 </row>
20262 </lyxtabular>
20263
20264 \end_inset 
20265
20266
20267 \layout Subsection
20268
20269 Interrupts
20270 \layout Standard
20271
20272 An interrupt
20273 \begin_inset LatexCommand \index{PIC16!interrupt}
20274
20275 \end_inset 
20276
20277  service routine (ISR) is declared using the 
20278 \emph on 
20279 interrupt
20280 \emph default 
20281  keyword.
20282 \layout LyX-Code
20283
20284 void isr(void) interrupt 
20285 \emph on 
20286 n
20287 \layout LyX-Code
20288
20289 {
20290 \layout LyX-Code
20291
20292 ...
20293 \layout LyX-Code
20294
20295 }
20296 \layout Standard
20297
20298
20299 \emph on 
20300 n
20301 \emph default 
20302  is the interrupt number, which for PIC18F devices can be:
20303 \layout Standard
20304 \align center 
20305
20306 \begin_inset  Tabular
20307 <lyxtabular version="3" rows="4" columns="3">
20308 <features>
20309 <column alignment="center" valignment="top" leftline="true" width="0">
20310 <column alignment="center" valignment="top" leftline="true" width="0">
20311 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20312 <row topline="true" bottomline="true">
20313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20314 \begin_inset Text
20315
20316 \layout Standard
20317
20318
20319 \emph on 
20320 n
20321 \end_inset 
20322 </cell>
20323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20324 \begin_inset Text
20325
20326 \layout Standard
20327
20328 Interrupt Vector
20329 \end_inset 
20330 </cell>
20331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20332 \begin_inset Text
20333
20334 \layout Standard
20335
20336 Interrupt Vector Address
20337 \end_inset 
20338 </cell>
20339 </row>
20340 <row topline="true">
20341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20342 \begin_inset Text
20343
20344 \layout Standard
20345
20346 0
20347 \end_inset 
20348 </cell>
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20350 \begin_inset Text
20351
20352 \layout Standard
20353
20354 RESET vector
20355 \end_inset 
20356 </cell>
20357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20358 \begin_inset Text
20359
20360 \layout Standard
20361
20362 0x000000
20363 \end_inset 
20364 </cell>
20365 </row>
20366 <row topline="true">
20367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20368 \begin_inset Text
20369
20370 \layout Standard
20371
20372
20373 \family roman 
20374 \series medium 
20375 \shape up 
20376 \size normal 
20377 \emph off 
20378 \bar no 
20379 \noun off 
20380 \color none
20381 1
20382 \end_inset 
20383 </cell>
20384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20385 \begin_inset Text
20386
20387 \layout Standard
20388
20389
20390 \family roman 
20391 \series medium 
20392 \shape up 
20393 \size normal 
20394 \emph off 
20395 \bar no 
20396 \noun off 
20397 \color none
20398 HIGH priority interrupts
20399 \end_inset 
20400 </cell>
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20402 \begin_inset Text
20403
20404 \layout Standard
20405
20406 0x000008
20407 \end_inset 
20408 </cell>
20409 </row>
20410 <row topline="true" bottomline="true">
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20412 \begin_inset Text
20413
20414 \layout Standard
20415
20416 2
20417 \end_inset 
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \layout Standard
20423
20424 LOW priority interrupts
20425 \end_inset 
20426 </cell>
20427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20428 \begin_inset Text
20429
20430 \layout Standard
20431
20432 0x000018
20433 \end_inset 
20434 </cell>
20435 </row>
20436 </lyxtabular>
20437
20438 \end_inset 
20439
20440
20441 \layout Standard
20442
20443 When generating assembly code for ISR the code generator places a 
20444 \noun on 
20445 goto 
20446 \noun default 
20447 instruction at the 
20448 \emph on 
20449 Interrupt Vector Address
20450 \emph default 
20451  which points at the genetated ISR.
20452  This single GOTO instruction is part of an automatically generated 
20453 \emph on 
20454 interrupt entry point
20455 \emph default 
20456  function.
20457  The actuall ISR code is placed as normally would in the code space.
20458  Upon interrupt request, the GOTO instruction is executed which jumps to
20459  the ISR code.
20460  When declaring interrupt functions as _naked this GOTO instruction is 
20461 \series bold 
20462 not
20463 \series default 
20464  generated.
20465  The whole interrupt functions is therefore placed at the Interrupt Vector
20466  Address of the specific interrupt.
20467  This is not a problem for the LOW priority interrupts, but it is a problem
20468  for the RESET and the HIGH priority interrupts because code may be written
20469  at the next interrupt´s vector address and cause undeterminate program
20470  behaviour if that interrupt is raised.
20471 \begin_inset Foot
20472 collapsed false
20473
20474 \layout Standard
20475
20476 This is not a problem when
20477 \layout Enumerate
20478
20479 this is a HIGH interrupt ISR and LOW interrupts are 
20480 \emph on 
20481 disabled
20482 \emph default 
20483  or not used.
20484 \layout Enumerate
20485
20486 when the ISR is small enough not to reach the next interrupt´s vector address.
20487 \end_inset 
20488
20489
20490 \layout Standard
20491
20492
20493 \emph on 
20494 n
20495 \emph default 
20496  is possible to be omitted.
20497  This way a function is generated similar to an ISR, but it is not assigned
20498  to any interrupt.
20499 \layout Standard
20500
20501 When entering an interrupt, currently the PIC16
20502 \begin_inset LatexCommand \index{PIC16}
20503
20504 \end_inset 
20505
20506  port automatically saves the following registers:
20507 \layout Itemize
20508
20509 WREG
20510 \layout Itemize
20511
20512 STATUS
20513 \layout Itemize
20514
20515 BSR
20516 \layout Itemize
20517
20518 PROD (PRODL and PRODH)
20519 \layout Itemize
20520
20521 FSR0 (FSR0L and FSR0H)
20522 \layout Standard
20523
20524 These registers are restored upon return from the interrupt routine.
20525 \begin_inset Foot
20526 collapsed false
20527
20528 \layout Standard
20529
20530 NOTE that when the _naked attribute is specified for an interrupt routine,
20531  then NO registers are stored or restored.
20532 \end_inset 
20533
20534
20535 \layout Subsection
20536
20537 Generic Pointers
20538 \layout Standard
20539
20540 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20541  There are 3 types of generic pointers currently implemented data, code
20542  and eeprom pointers.
20543  They are differentiated by the value of the 7th and 6th bits of the upper
20544  byte:
20545 \layout Standard
20546 \align center 
20547
20548 \begin_inset  Tabular
20549 <lyxtabular version="3" rows="5" columns="5">
20550 <features>
20551 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20552 <column alignment="center" valignment="top" width="0">
20553 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20554 <column alignment="center" valignment="top" width="0">
20555 <column alignment="left" valignment="top" rightline="true" width="0">
20556 <row topline="true" bottomline="true">
20557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20558 \begin_inset Text
20559
20560 \layout Standard
20561
20562 pointer type
20563 \end_inset 
20564 </cell>
20565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20566 \begin_inset Text
20567
20568 \layout Standard
20569
20570 7th bit
20571 \end_inset 
20572 </cell>
20573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20574 \begin_inset Text
20575
20576 \layout Standard
20577
20578 6th bit
20579 \end_inset 
20580 </cell>
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20582 \begin_inset Text
20583
20584 \layout Standard
20585
20586 rest of the pointer
20587 \end_inset 
20588 </cell>
20589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20590 \begin_inset Text
20591
20592 \layout Standard
20593
20594 description
20595 \end_inset 
20596 </cell>
20597 </row>
20598 <row topline="true" bottomline="true">
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20600 \begin_inset Text
20601
20602 \layout Standard
20603
20604 data 
20605 \end_inset 
20606 </cell>
20607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20608 \begin_inset Text
20609
20610 \layout Standard
20611
20612 1
20613 \end_inset 
20614 </cell>
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20616 \begin_inset Text
20617
20618 \layout Standard
20619
20620 0
20621 \end_inset 
20622 </cell>
20623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20624 \begin_inset Text
20625
20626 \layout Standard
20627
20628
20629 \family typewriter 
20630 \shape slanted 
20631 \emph on 
20632 uuuuuu uuuuxxxx xxxxxxxx
20633 \end_inset 
20634 </cell>
20635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20636 \begin_inset Text
20637
20638 \layout Standard
20639
20640 a 12-bit data pointer in data RAM memory
20641 \end_inset 
20642 </cell>
20643 </row>
20644 <row bottomline="true">
20645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20646 \begin_inset Text
20647
20648 \layout Standard
20649
20650 code
20651 \end_inset 
20652 </cell>
20653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_inset Text
20655
20656 \layout Standard
20657
20658 0
20659 \end_inset 
20660 </cell>
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20662 \begin_inset Text
20663
20664 \layout Standard
20665
20666 0
20667 \end_inset 
20668 </cell>
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20670 \begin_inset Text
20671
20672 \layout Standard
20673
20674
20675 \family typewriter 
20676 \shape slanted 
20677 \emph on 
20678 uxxxxx xxxxxxxx xxxxxxxx
20679 \end_inset 
20680 </cell>
20681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20682 \begin_inset Text
20683
20684 \layout Standard
20685
20686 a 21-bit code pointer in FLASH memory
20687 \end_inset 
20688 </cell>
20689 </row>
20690 <row bottomline="true">
20691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20692 \begin_inset Text
20693
20694 \layout Standard
20695
20696 eeprom
20697 \end_inset 
20698 </cell>
20699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20700 \begin_inset Text
20701
20702 \layout Standard
20703
20704 0
20705 \end_inset 
20706 </cell>
20707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20708 \begin_inset Text
20709
20710 \layout Standard
20711
20712 1
20713 \end_inset 
20714 </cell>
20715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20716 \begin_inset Text
20717
20718 \layout Standard
20719
20720
20721 \family typewriter 
20722 \shape slanted 
20723 \emph on 
20724 uuuuuu uuuuuuxx xxxxxxxx
20725 \end_inset 
20726 </cell>
20727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20728 \begin_inset Text
20729
20730 \layout Standard
20731
20732 a 10-bit eeprom pointer in EEPROM memory
20733 \end_inset 
20734 </cell>
20735 </row>
20736 <row bottomline="true">
20737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20738 \begin_inset Text
20739
20740 \layout Standard
20741
20742 (unimplemented)
20743 \end_inset 
20744 </cell>
20745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20746 \begin_inset Text
20747
20748 \layout Standard
20749
20750 1
20751 \end_inset 
20752 </cell>
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20754 \begin_inset Text
20755
20756 \layout Standard
20757
20758 1
20759 \end_inset 
20760 </cell>
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20762 \begin_inset Text
20763
20764 \layout Standard
20765
20766
20767 \family typewriter 
20768 \shape slanted 
20769 \emph on 
20770 xxxxxx xxxxxxxx xxxxxxxx
20771 \end_inset 
20772 </cell>
20773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20774 \begin_inset Text
20775
20776 \layout Standard
20777
20778 unimplemented pointer type
20779 \end_inset 
20780 </cell>
20781 </row>
20782 </lyxtabular>
20783
20784 \end_inset 
20785
20786
20787 \layout Standard
20788
20789 Generic pointer are read and written with a set of library functions which
20790  read/write 1, 2, 3, 4 bytes.
20791 \layout Subsection
20792
20793 PIC16 C Libraries
20794 \layout Subsubsection
20795
20796 Standard I/O Streams
20797 \layout Standard
20798
20799 In the 
20800 \emph on 
20801 stdio.h
20802 \emph default 
20803  the type FILE is defined as:
20804 \layout LyX-Code
20805
20806 typedef char * FILE;
20807 \layout Standard
20808
20809 This type is the stream type implemented I/O in the PIC18F devices.
20810  Also the standard input and output streams are declared in stdio.h:
20811 \layout LyX-Code
20812
20813 extern FILE * stdin;
20814 \layout LyX-Code
20815
20816 extern FILE * stdout;
20817 \layout Standard
20818
20819 The FILE type is actually a generic pointer which defines one more type
20820  of generic pointers, the 
20821 \emph on 
20822 stream 
20823 \emph default 
20824 pointer.
20825  This new type has the format:
20826 \layout Standard
20827 \align center 
20828
20829 \begin_inset  Tabular
20830 <lyxtabular version="3" rows="2" columns="7">
20831 <features>
20832 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20833 <column alignment="center" valignment="top" width="0">
20834 <column alignment="center" valignment="top" leftline="true" width="0">
20835 <column alignment="center" valignment="top" leftline="true" width="0">
20836 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20837 <column alignment="center" valignment="top" width="0">
20838 <column alignment="left" valignment="top" rightline="true" width="0">
20839 <row topline="true" bottomline="true">
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \layout Standard
20844
20845 pointer type
20846 \end_inset 
20847 </cell>
20848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20849 \begin_inset Text
20850
20851 \layout Standard
20852
20853 <7:6>
20854 \end_inset 
20855 </cell>
20856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20857 \begin_inset Text
20858
20859 \layout Standard
20860
20861 <5>
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 <4>
20870 \end_inset 
20871 </cell>
20872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20873 \begin_inset Text
20874
20875 \layout Standard
20876
20877 <3:0>
20878 \end_inset 
20879 </cell>
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20881 \begin_inset Text
20882
20883 \layout Standard
20884
20885 rest of the pointer
20886 \end_inset 
20887 </cell>
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20889 \begin_inset Text
20890
20891 \layout Standard
20892
20893 descrption
20894 \end_inset 
20895 </cell>
20896 </row>
20897 <row topline="true" bottomline="true">
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20899 \begin_inset Text
20900
20901 \layout Standard
20902
20903 stream
20904 \end_inset 
20905 </cell>
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20907 \begin_inset Text
20908
20909 \layout Standard
20910
20911 00
20912 \end_inset 
20913 </cell>
20914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20915 \begin_inset Text
20916
20917 \layout Standard
20918
20919 1
20920 \end_inset 
20921 </cell>
20922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20923 \begin_inset Text
20924
20925 \layout Standard
20926
20927 0
20928 \end_inset 
20929 </cell>
20930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20931 \begin_inset Text
20932
20933 \layout Standard
20934
20935 nnnn
20936 \end_inset 
20937 </cell>
20938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20939 \begin_inset Text
20940
20941 \layout Standard
20942
20943
20944 \family typewriter 
20945 \shape slanted 
20946 \emph on 
20947 uuuuuuuu uuuuuuuu
20948 \end_inset 
20949 </cell>
20950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20951 \begin_inset Text
20952
20953 \layout Standard
20954
20955 upper byte high nubble is 0x2n, the rest are zeroes
20956 \end_inset 
20957 </cell>
20958 </row>
20959 </lyxtabular>
20960
20961 \end_inset 
20962
20963
20964 \layout Standard
20965
20966 Currently implemented there are 3 types of streams defined:
20967 \layout Standard
20968 \align center 
20969
20970 \begin_inset  Tabular
20971 <lyxtabular version="3" rows="4" columns="4">
20972 <features>
20973 <column alignment="center" valignment="top" leftline="true" width="0">
20974 <column alignment="center" valignment="top" leftline="true" width="0">
20975 <column alignment="center" valignment="top" leftline="true" width="0">
20976 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20977 <row topline="true" bottomline="true">
20978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20979 \begin_inset Text
20980
20981 \layout Standard
20982
20983 stream type
20984 \end_inset 
20985 </cell>
20986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20987 \begin_inset Text
20988
20989 \layout Standard
20990
20991 value
20992 \end_inset 
20993 </cell>
20994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20995 \begin_inset Text
20996
20997 \layout Standard
20998
20999 module
21000 \end_inset 
21001 </cell>
21002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21003 \begin_inset Text
21004
21005 \layout Standard
21006
21007 description
21008 \end_inset 
21009 </cell>
21010 </row>
21011 <row topline="true">
21012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21013 \begin_inset Text
21014
21015 \layout Standard
21016
21017 STREAM_USART
21018 \end_inset 
21019 </cell>
21020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21021 \begin_inset Text
21022
21023 \layout Standard
21024
21025
21026 \family typewriter 
21027 0x200000UL
21028 \end_inset 
21029 </cell>
21030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21031 \begin_inset Text
21032
21033 \layout Standard
21034
21035 USART
21036 \end_inset 
21037 </cell>
21038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21039 \begin_inset Text
21040
21041 \layout Standard
21042
21043 Writes/Reads characters via the USART peripheral
21044 \end_inset 
21045 </cell>
21046 </row>
21047 <row topline="true">
21048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21049 \begin_inset Text
21050
21051 \layout Standard
21052
21053 STREAM_MSSP
21054 \end_inset 
21055 </cell>
21056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21057 \begin_inset Text
21058
21059 \layout Standard
21060
21061
21062 \family typewriter 
21063 0x210000UL
21064 \end_inset 
21065 </cell>
21066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21067 \begin_inset Text
21068
21069 \layout Standard
21070
21071 MSSP
21072 \end_inset 
21073 </cell>
21074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21075 \begin_inset Text
21076
21077 \layout Standard
21078
21079 Writes/Reads characters via the MSSP peripheral
21080 \end_inset 
21081 </cell>
21082 </row>
21083 <row topline="true" bottomline="true">
21084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21085 \begin_inset Text
21086
21087 \layout Standard
21088
21089 STREAM_USER
21090 \end_inset 
21091 </cell>
21092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21093 \begin_inset Text
21094
21095 \layout Standard
21096
21097
21098 \family typewriter 
21099 0x2f0000UL
21100 \end_inset 
21101 </cell>
21102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21103 \begin_inset Text
21104
21105 \layout Standard
21106
21107 (none)
21108 \end_inset 
21109 </cell>
21110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21111 \begin_inset Text
21112
21113 \layout Standard
21114
21115 Writes/Reads characters via used defined functions
21116 \end_inset 
21117 </cell>
21118 </row>
21119 </lyxtabular>
21120
21121 \end_inset 
21122
21123
21124 \layout Standard
21125
21126 The stream identifiers are declared as macros in the stdio.h header.
21127 \layout Standard
21128
21129 In the libc library there exist the functions that are used to write to
21130  each of the above streams.
21131  These are
21132 \layout List
21133 \labelwidthstring 00.00.0000
21134
21135 _
21136 \begin_inset ERT
21137 status Collapsed
21138
21139 \layout Standard
21140
21141 \backslash 
21142 /
21143 \end_inset 
21144
21145 _stream_usart_putchar writes a character at the USART stream
21146 \layout List
21147 \labelwidthstring 00.00.0000
21148
21149 _
21150 \begin_inset ERT
21151 status Collapsed
21152
21153 \layout Standard
21154
21155 \backslash 
21156 /
21157 \end_inset 
21158
21159 _stream_mssp_putchar writes a character at the MSSP stream
21160 \layout List
21161 \labelwidthstring 00.00.0000
21162
21163 putchar dummy function.
21164  This writes a character to a user specified manner.
21165 \layout Standard
21166
21167 In order to increase performance 
21168 \emph on 
21169 putchar 
21170 \emph default 
21171 is declared in stdio.h as having its parameter in WREG (it has the wparam
21172  keyword).
21173  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21174  in a user-friendly way.
21175  
21176 \emph on 
21177 arg
21178 \emph default 
21179  is the name of the variable that holds the character to print.
21180  An example follows:
21181 \layout LyX-Code
21182
21183 #include <pic18fregs.h>
21184 \newline 
21185 #include <stdio.h>
21186 \newline 
21187
21188 \newline 
21189 PUTCHAR( c )
21190 \layout LyX-Code
21191
21192 {
21193 \layout LyX-Code
21194
21195     PORTA = c;    /* dump character c to PORTA */
21196 \layout LyX-Code
21197
21198
21199 \newline 
21200
21201 \newline 
21202 void main(void)
21203 \layout LyX-Code
21204
21205 {
21206 \layout LyX-Code
21207
21208     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21209 \layout LyX-Code
21210
21211                               * by default to STREAM_USER */
21212 \layout LyX-Code
21213
21214     printf (¨This is a printf test
21215 \backslash 
21216 n¨);
21217 \layout LyX-Code
21218
21219 }
21220 \layout LyX-Code
21221
21222 \layout Subsubsection
21223
21224 Printing functions
21225 \layout Standard
21226
21227 PIC16 contains an implementation of the printf-family of functions.
21228  There exist the following functions:
21229 \layout LyX-Code
21230
21231 extern unsigned int sprintf(char *buf, char *fmt, ...);
21232 \layout LyX-Code
21233
21234 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21235 \layout LyX-Code
21236
21237 \layout LyX-Code
21238
21239 extern unsigned int printf(char *fmt, ...);
21240 \layout LyX-Code
21241
21242 extern unsigned int vprintf(char *fmt, va_lista ap);
21243 \layout LyX-Code
21244
21245 \layout LyX-Code
21246
21247 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21248 \layout LyX-Code
21249
21250 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21251 \layout Standard
21252
21253 For sprintf and vsprintf 
21254 \emph on 
21255 buf 
21256 \emph default 
21257 should normally be a data pointer where the resulting string will be placed.
21258  No range checking is done so the user should allocate the necessery buffer.
21259  For fprintf and vfprintf 
21260 \emph on 
21261 fp
21262 \emph default 
21263  should be a stream pointer (i.e.
21264  stdout, STREAM_MSSP, etc...).
21265 \layout Subsubsection
21266
21267 Signals
21268 \layout Standard
21269
21270 The PIC18F family of microcontrollers supports a number of interrupt sources.
21271  A list of these interrupts is shown in the following table:
21272 \layout Standard
21273 \align center 
21274
21275 \begin_inset  Tabular
21276 <lyxtabular version="3" rows="11" columns="4">
21277 <features>
21278 <column alignment="left" valignment="top" leftline="true" width="0">
21279 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21280 <column alignment="left" valignment="top" leftline="true" width="0">
21281 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21282 <row topline="true" bottomline="true">
21283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21284 \begin_inset Text
21285
21286 \layout Standard
21287
21288 signal name
21289 \end_inset 
21290 </cell>
21291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21292 \begin_inset Text
21293
21294 \layout Standard
21295
21296 description
21297 \end_inset 
21298 </cell>
21299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21300 \begin_inset Text
21301
21302 \layout Standard
21303
21304 signal name
21305 \end_inset 
21306 </cell>
21307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21308 \begin_inset Text
21309
21310 \layout Standard
21311
21312 descritpion
21313 \end_inset 
21314 </cell>
21315 </row>
21316 <row topline="true">
21317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21318 \begin_inset Text
21319
21320 \layout Standard
21321
21322 SIG_RB
21323 \end_inset 
21324 </cell>
21325 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21326 \begin_inset Text
21327
21328 \layout Standard
21329
21330 PORTB change interrupt
21331 \end_inset 
21332 </cell>
21333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21334 \begin_inset Text
21335
21336 \layout Standard
21337
21338 SIG_EE
21339 \end_inset 
21340 </cell>
21341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21342 \begin_inset Text
21343
21344 \layout Standard
21345
21346 EEPROM/FLASH write complete interrupt
21347 \end_inset 
21348 </cell>
21349 </row>
21350 <row topline="true">
21351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21352 \begin_inset Text
21353
21354 \layout Standard
21355
21356 SIG_INT0
21357 \end_inset 
21358 </cell>
21359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21360 \begin_inset Text
21361
21362 \layout Standard
21363
21364 INT0 external interrupt
21365 \end_inset 
21366 </cell>
21367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21368 \begin_inset Text
21369
21370 \layout Standard
21371
21372 SIG_BCOL
21373 \end_inset 
21374 </cell>
21375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21376 \begin_inset Text
21377
21378 \layout Standard
21379
21380 Bus collision interrupt
21381 \end_inset 
21382 </cell>
21383 </row>
21384 <row topline="true">
21385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21386 \begin_inset Text
21387
21388 \layout Standard
21389
21390 SIG_INT1
21391 \end_inset 
21392 </cell>
21393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21394 \begin_inset Text
21395
21396 \layout Standard
21397
21398 INT1 external interrupt
21399 \end_inset 
21400 </cell>
21401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21402 \begin_inset Text
21403
21404 \layout Standard
21405
21406 SIG_LVD
21407 \end_inset 
21408 </cell>
21409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21410 \begin_inset Text
21411
21412 \layout Standard
21413
21414 Low voltage detect interrupt
21415 \end_inset 
21416 </cell>
21417 </row>
21418 <row topline="true">
21419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21420 \begin_inset Text
21421
21422 \layout Standard
21423
21424 SIG_INT2
21425 \end_inset 
21426 </cell>
21427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21428 \begin_inset Text
21429
21430 \layout Standard
21431
21432 INT2 external interrupt
21433 \end_inset 
21434 </cell>
21435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21436 \begin_inset Text
21437
21438 \layout Standard
21439
21440 SIG_PSP
21441 \end_inset 
21442 </cell>
21443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21444 \begin_inset Text
21445
21446 \layout Standard
21447
21448 Parallel slave port interrupt
21449 \end_inset 
21450 </cell>
21451 </row>
21452 <row topline="true">
21453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21454 \begin_inset Text
21455
21456 \layout Standard
21457
21458 SIG_CCP1
21459 \end_inset 
21460 </cell>
21461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21462 \begin_inset Text
21463
21464 \layout Standard
21465
21466 CCP1 module interrupt
21467 \end_inset 
21468 </cell>
21469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21470 \begin_inset Text
21471
21472 \layout Standard
21473
21474 SIG_AD
21475 \end_inset 
21476 </cell>
21477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21478 \begin_inset Text
21479
21480 \layout Standard
21481
21482 AD convertion complete interrupt
21483 \end_inset 
21484 </cell>
21485 </row>
21486 <row topline="true">
21487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21488 \begin_inset Text
21489
21490 \layout Standard
21491
21492 SIG_CCP2
21493 \end_inset 
21494 </cell>
21495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21496 \begin_inset Text
21497
21498 \layout Standard
21499
21500 CCP2 module interrupt
21501 \end_inset 
21502 </cell>
21503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21504 \begin_inset Text
21505
21506 \layout Standard
21507
21508 SIG_RC
21509 \end_inset 
21510 </cell>
21511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21512 \begin_inset Text
21513
21514 \layout Standard
21515
21516 USART receive interrupt
21517 \end_inset 
21518 </cell>
21519 </row>
21520 <row topline="true">
21521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21522 \begin_inset Text
21523
21524 \layout Standard
21525
21526 SIG_TMR0
21527 \end_inset 
21528 </cell>
21529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21530 \begin_inset Text
21531
21532 \layout Standard
21533
21534 TMR0 overflow interrupt
21535 \end_inset 
21536 </cell>
21537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21538 \begin_inset Text
21539
21540 \layout Standard
21541
21542 SIG_TX
21543 \end_inset 
21544 </cell>
21545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21546 \begin_inset Text
21547
21548 \layout Standard
21549
21550 USART transmit interrupt
21551 \end_inset 
21552 </cell>
21553 </row>
21554 <row topline="true">
21555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21556 \begin_inset Text
21557
21558 \layout Standard
21559
21560 SIG_TMR1
21561 \end_inset 
21562 </cell>
21563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21564 \begin_inset Text
21565
21566 \layout Standard
21567
21568 TMR1 overflow interrupt
21569 \end_inset 
21570 </cell>
21571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21572 \begin_inset Text
21573
21574 \layout Standard
21575
21576 SIG_MSSP
21577 \end_inset 
21578 </cell>
21579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21580 \begin_inset Text
21581
21582 \layout Standard
21583
21584 SSP receive/transmit interrupt
21585 \end_inset 
21586 </cell>
21587 </row>
21588 <row topline="true">
21589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21590 \begin_inset Text
21591
21592 \layout Standard
21593
21594 SIG_TMR2
21595 \end_inset 
21596 </cell>
21597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21598 \begin_inset Text
21599
21600 \layout Standard
21601
21602 TMR2 matches PR2 interrupt
21603 \end_inset 
21604 </cell>
21605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21606 \begin_inset Text
21607
21608 \layout Standard
21609
21610 \end_inset 
21611 </cell>
21612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21613 \begin_inset Text
21614
21615 \layout Standard
21616
21617 \end_inset 
21618 </cell>
21619 </row>
21620 <row topline="true" bottomline="true">
21621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21622 \begin_inset Text
21623
21624 \layout Standard
21625
21626 SIG_TMR3
21627 \end_inset 
21628 </cell>
21629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21630 \begin_inset Text
21631
21632 \layout Standard
21633
21634 TMR3 overflow interrupt
21635 \end_inset 
21636 </cell>
21637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21638 \begin_inset Text
21639
21640 \layout Standard
21641
21642 \end_inset 
21643 </cell>
21644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21645 \begin_inset Text
21646
21647 \layout Standard
21648
21649 \end_inset 
21650 </cell>
21651 </row>
21652 </lyxtabular>
21653
21654 \end_inset 
21655
21656
21657 \layout Standard
21658
21659 The prototypes for these names are defined in the header file 
21660 \emph on 
21661 signal.h
21662 \emph default 
21663  .
21664 \layout Standard
21665
21666 In order to simplify signal handling, a number of macros is provided:
21667 \layout List
21668 \labelwidthstring 00.00.0000
21669
21670 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21671  high priority interrupts.
21672  
21673 \emph on 
21674 name
21675 \emph default 
21676  is the function name to use.
21677 \layout List
21678 \labelwidthstring 00.00.0000
21679
21680 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21681  low priority interrupt.
21682  
21683 \emph on 
21684 name
21685 \emph default 
21686  is the function name to use.
21687 \layout List
21688 \labelwidthstring 00.00.0000
21689
21690 DEF_HANDLER(sig,handler) define a handler for signal 
21691 \emph on 
21692 sig.
21693 \layout List
21694 \labelwidthstring 00.00.0000
21695
21696 END_DEF end the declaration of the dispatch table.
21697 \layout Standard
21698
21699 Additionally there are two more macros to simplify the declaration of the
21700  signal handler:
21701 \layout List
21702 \labelwidthstring 00.00.0000
21703
21704
21705 \series medium 
21706 SIGHANDLER(handler) 
21707 \series default 
21708 this declares the function prototype for the 
21709 \emph on 
21710 handler
21711 \emph default 
21712  function.
21713 \layout List
21714 \labelwidthstring 00.00.0000
21715
21716 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21717 \layout Standard
21718
21719 An example of using the macros above is shown below:
21720 \layout LyX-Code
21721
21722 #include <pic18fregs.h>
21723 \layout LyX-Code
21724
21725 #include <signal.h>
21726 \newline 
21727
21728 \newline 
21729 DEF_INTHIGH(high_int)
21730 \layout LyX-Code
21731
21732 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21733 \layout LyX-Code
21734
21735 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21736 \layout LyX-Code
21737
21738 END_DEF
21739 \newline 
21740
21741 \newline 
21742 SIGHANDLER(_tmr0_handler)
21743 \layout LyX-Code
21744
21745 {
21746 \layout LyX-Code
21747
21748   /* action to be taken when timer 0 overflows */
21749 \layout LyX-Code
21750
21751 }
21752 \newline 
21753
21754 \newline 
21755 SIGHANDLERNAKED(_bcol_handler)
21756 \layout LyX-Code
21757
21758 {
21759 \layout LyX-Code
21760
21761   _asm
21762 \layout LyX-Code
21763
21764     /* action to be taken when bus collision occurs */
21765 \layout LyX-Code
21766
21767     retfie
21768 \layout LyX-Code
21769
21770  _endasm;
21771 \layout LyX-Code
21772
21773 }
21774 \layout Standard
21775
21776
21777 \series bold 
21778 NOTES:
21779 \series default 
21780  Special care should be taken when using the above scheme:
21781 \layout Itemize
21782
21783 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21784 \layout Itemize
21785
21786 when declaring SIGHANDLERNAKED handler never forget to use 
21787 \emph on 
21788 retfie
21789 \emph default 
21790  for proper returning.
21791 \layout Subsection
21792
21793 PIC16 Port -- Tips
21794 \layout Standard
21795
21796 Here you can find some general tips for compiling programs with SDCC/pic16.
21797 \layout Subsubsection
21798
21799 Stack size
21800 \layout Standard
21801
21802 The default stack
21803 \begin_inset LatexCommand \index{PIC16!stack}
21804
21805 \end_inset 
21806
21807  size (that is 64 bytes) probably is enough for many programs.
21808  One must take care that when there are many levels of function nesting,
21809  or there is excessive usage of stack, its size should be extended.
21810  An example of such a case is the printf/sprintf family of functions.
21811  If you encounter problems like not being able to print integers, then you
21812  need to set the stack size around the maximum (256 for small stack model).
21813  The following diagram shows what happens when calling printf to print an
21814  integer:
21815 \layout LyX-Code
21816
21817 printf () --> ltoa () --> ultoa () --> divschar ()
21818 \layout Standard
21819
21820 It is should be understood that stack is easily consumed when calling complicate
21821 d functions.
21822  Using command line arguments like -
21823 \begin_inset ERT
21824 status Collapsed
21825
21826 \layout Standard
21827
21828 \backslash 
21829 /
21830 \end_inset 
21831
21832 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21833  stack frames.
21834  Other ways to reduce stack usage may exist.
21835 \layout Subsection
21836
21837 Known bugs
21838 \layout Standard
21839
21840 The PIC16 Port currently does not pass SDCC's regression test
21841 \begin_inset LatexCommand \index{Regression test (PIC16)}
21842
21843 \end_inset 
21844
21845  suite (see section 
21846 \begin_inset LatexCommand \ref{sec:Quality-control}
21847
21848 \end_inset 
21849
21850 ) and thus the nightly regression tests for the PIC16 target are currently
21851  disabled for all hosts except for 
21852 \emph on 
21853 Linux on Opteron.
21854
21855 \emph default 
21856  This means you can see the result of the PIC16 regression tests f.e.
21857  by checking the log files in 
21858 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
21859
21860 \end_inset 
21861
21862  (pick the most up to date file there, scroll down, lend a hand).
21863 \layout Chapter
21864
21865 Debugging
21866 \layout Standard
21867
21868 There are several approaches to debugging your code.
21869  This chapter is meant to show your options and to give detail on some of
21870  them:
21871 \newline 
21872
21873 \newline 
21874 When writing your code:
21875 \layout Itemize
21876
21877 write your code with debugging in mind (avoid duplicating code, put conceptually
21878  similar variables into structs, use structured code, have strategic points
21879  within your code where all variables are consistent, ...)
21880 \layout Itemize
21881
21882 run a syntax-checking tool like splint
21883 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21884
21885 \end_inset 
21886
21887
21888 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21889
21890 \end_inset 
21891
21892  (see -
21893 \begin_inset ERT
21894 status Collapsed
21895
21896 \layout Standard
21897
21898 \backslash 
21899 /
21900 \end_inset 
21901
21902 -more-pedantic 
21903 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21904
21905 \end_inset 
21906
21907 ) over the code.
21908 \layout Itemize
21909
21910 for the high level code use a C-compiler (like f.e.
21911  GCC) to compile run and debug the code on your host.
21912  See (see -
21913 \begin_inset ERT
21914 status Collapsed
21915
21916 \layout Standard
21917
21918 \backslash 
21919 /
21920 \end_inset 
21921
21922 -more-pedantic 
21923 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21924
21925 \end_inset 
21926
21927  ) on howto handle syntax extensions like __xdata, __at(), ...
21928  
21929 \layout Itemize
21930
21931 use another C-compiler to compile code for your target.
21932  Always an option but not recommended:) And not very likely to help you.
21933  If you seriously consider walking this path you should at least occasionally
21934  check portability of your code.
21935  Most commercial compiler vendors will offer an evaluation version so you
21936  can test compile your code or snippets of your code.
21937 \layout Standard
21938
21939 Debugging on a simulator:
21940 \layout Itemize
21941
21942 there is a separate section about SDCDB (section 
21943 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21944
21945 \end_inset 
21946
21947 ) below.
21948 \layout Itemize
21949
21950 or (8051 specific) use a freeware/commercial simulator which interfaces
21951  to the AOMF
21952 \begin_inset LatexCommand \index{AOMF, AOMF51}
21953
21954 \end_inset 
21955
21956  file (see 
21957 \begin_inset LatexCommand \ref{OMF file}
21958
21959 \end_inset 
21960
21961 ) optionally generated by SDCC.
21962 \layout Standard
21963
21964 Debugging On-target: 
21965 \layout Itemize
21966
21967 use a MCU port pin to serially output debug data to the RS232 port of your
21968  host.
21969  You'll probably want some level shifting device typically involving a MAX232
21970  or similar IC.
21971  If the hardware serial port of the MCU is not available search for 'Software
21972  UART' in your favourite search machine.
21973 \layout Itemize
21974
21975 use an on-target monitor.
21976  In this context a monitor is a small program which usually accepts commands
21977  via a serial line and allows to set program counter, to single step through
21978  a program and read/write memory locations.
21979  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21980  
21981 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21982
21983 \end_inset 
21984
21985 ).
21986 \layout Itemize
21987
21988 toggle MCU port pins at strategic points within your code and use an oscilloscop
21989 e.
21990  A 
21991 \emph on 
21992 digital oscilloscope
21993 \emph default 
21994
21995 \begin_inset LatexCommand \index{Oscilloscope}
21996
21997 \end_inset 
21998
21999  with deep trace memory is really helpful especially if you have to debug
22000  a realtime application.
22001  If you need to monitor more pins than your oscilloscope provides you can
22002  sometimes get away with a small R-2R network.
22003  On a single channel oscilloscope you could f.e.
22004  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22005 k
22006 \begin_inset Formula $\Omega$
22007 \end_inset 
22008
22009  resistor and the other one by a 5\SpecialChar ~
22010 k
22011 \begin_inset Formula $\Omega$
22012 \end_inset 
22013
22014  resistor to the oscilloscope probe (check output drive capability of the
22015  pins you want to monitor).
22016  If you need to monitor many more pins a 
22017 \emph on 
22018 logic analyzer
22019 \emph default 
22020  will be handy.
22021 \layout Itemize
22022
22023 use an ICE (
22024 \emph on 
22025 i
22026 \emph default 
22027
22028 \emph on 
22029 c
22030 \emph default 
22031 ircuit 
22032 \emph on 
22033 e
22034 \emph default 
22035 mulator
22036 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22037
22038 \end_inset 
22039
22040 ).
22041  Usually very expensive.
22042  And very nice to have too.
22043  And usually locks you (for years...) to the devices the ICE can emulate.
22044  
22045 \layout Itemize
22046
22047 use a remote debugger.
22048  In most 8-bit systems the symbol information is not available on the target,
22049  and a complete debugger is too bulky for the target system.
22050  Therefore usually a debugger on the host system connects to an on-target
22051  debugging stub which accepts only primitive commands.
22052  
22053 \newline 
22054 Terms to enter into your favourite search engine could be 'remote debugging',
22055  'gdb stub' or 'inferior debugger'.
22056  (is there one?)
22057 \layout Itemize
22058
22059 use an on target hardware debugger.
22060  Some of the more modern MCUs include hardware support for setting break
22061  points and monitoring/changing variables by using dedicated hardware pins.
22062  This facility doesn't require additional code to run on the target and
22063  
22064 \emph on 
22065 usually
22066 \emph default 
22067  doesn't affect runtime behaviour until a breakpoint is hit.
22068  For the mcs51 most hardware debuggers use the AOMF
22069 \begin_inset LatexCommand \index{AOMF, AOMF51}
22070
22071 \end_inset 
22072
22073  file (see 
22074 \begin_inset LatexCommand \ref{OMF file}
22075
22076 \end_inset 
22077
22078 ) as input file.
22079  
22080 \layout Standard
22081
22082 Last not least:
22083 \layout Itemize
22084
22085 if you are not familiar with any of the following terms you're likely to
22086  run into problems rather sooner than later: 
22087 \emph on 
22088 volatile
22089 \emph default 
22090
22091 \emph on 
22092 atomic
22093 \emph default 
22094
22095 \emph on 
22096 memory map
22097 \emph default 
22098
22099 \emph on 
22100 overlay
22101 \emph default 
22102 .
22103  As an embedded programmer you 
22104 \emph on 
22105 have
22106 \emph default 
22107  to know them so why not look them up 
22108 \emph on 
22109 before
22110 \emph default 
22111  you have problems?)
22112 \layout Itemize
22113
22114 tell someone else about your problem (actually this is a surprisingly effective
22115  means to hunt down the bug even if the listener is not familiar with your
22116  environment).
22117  As 'failure to communicate' is probably one of the job-induced deformations
22118  of an embedded programmer this is highly encouraged.
22119 \layout Section
22120
22121 Debugging with SDCDB
22122 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22123
22124 \end_inset 
22125
22126
22127 \begin_inset LatexCommand \index{SDCDB (debugger)}
22128
22129 \end_inset 
22130
22131  
22132 \layout Standard
22133
22134 SDCC is distributed with a source level debugger
22135 \begin_inset LatexCommand \index{Debugger}
22136
22137 \end_inset 
22138
22139 .
22140  The debugger uses a command line interface, the command repertoire of the
22141  debugger has been kept as close to gdb
22142 \begin_inset LatexCommand \index{gdb}
22143
22144 \end_inset 
22145
22146  (the GNU debugger) as possible.
22147  The configuration and build process is part of the standard compiler installati
22148 on, which also builds and installs the debugger in the target directory
22149  specified during configuration.
22150  The debugger allows you debug BOTH at the C source and at the ASM source
22151  level.
22152 \layout Subsection
22153
22154 Compiling for Debugging
22155 \layout Standard
22156
22157 The -
22158 \begin_inset ERT
22159 status Collapsed
22160
22161 \layout Standard
22162
22163 \backslash 
22164 /
22165 \end_inset 
22166
22167 -debug
22168 \begin_inset LatexCommand \index{-\/-debug}
22169
22170 \end_inset 
22171
22172  option must be specified for all files for which debug information is to
22173  be generated.
22174  The compiler generates a .adb file for each of these files.
22175  The linker creates the .cdb
22176 \begin_inset LatexCommand \index{<file>.cdb}
22177
22178 \end_inset 
22179
22180  file from the .adb
22181 \begin_inset LatexCommand \index{<file>.adb}
22182
22183 \end_inset 
22184
22185  files and the address information.
22186  This .cdb is used by the debugger.
22187 \layout Subsection
22188
22189 How the Debugger Works
22190 \layout Standard
22191
22192 When the -
22193 \begin_inset ERT
22194 status Collapsed
22195
22196 \layout Standard
22197
22198 \backslash 
22199 /
22200 \end_inset 
22201
22202 -debug option is specified the compiler generates extra symbol information
22203  some of which are put into the assembler source and some are put into the
22204  .adb file.
22205  Then the linker creates the .cdb file from the individual .adb files with
22206  the address information for the symbols.
22207  The debugger reads the symbolic information generated by the compiler &
22208  the address information generated by the linker.
22209  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22210  execution is controlled by the debugger.
22211  When a command is issued for the debugger, it translates it into appropriate
22212  commands for the simulator.
22213  (Currently SDCDM only connects to the simulator but 
22214 \emph on 
22215 newcdb
22216 \emph default 
22217  at 
22218 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22219
22220 \end_inset 
22221
22222  is an effort to connect directly to the hardware.) 
22223 \layout Subsection
22224
22225 Starting the Debugger SDCDB
22226 \layout Standard
22227
22228 The debugger can be started using the following command line.
22229  (Assume the file you are debugging has the file name foo).
22230 \newline 
22231
22232 \newline 
22233
22234 \family sans 
22235 \series bold 
22236 sdcdb foo
22237 \newline 
22238
22239 \family default 
22240 \series default 
22241
22242 \newline 
22243 The debugger will look for the following files.
22244 \layout Itemize
22245
22246 foo.c - the source file.
22247 \layout Itemize
22248
22249 foo.cdb - the debugger symbol information file.
22250 \layout Itemize
22251
22252 foo.ihx - the Intel hex format
22253 \begin_inset LatexCommand \index{Intel hex format}
22254
22255 \end_inset 
22256
22257  object file.
22258 \layout Subsection
22259
22260 SDCDB Command Line Options
22261 \layout Itemize
22262
22263 -
22264 \begin_inset ERT
22265 status Collapsed
22266
22267 \layout Standard
22268
22269 \backslash 
22270 /
22271 \end_inset 
22272
22273 -directory=<source file directory> this option can used to specify the directory
22274  search list.
22275  The debugger will look into the directory list specified for source, cdb
22276  & ihx files.
22277  The items in the directory list must be separated by ':', e.g.
22278  if the source files can be in the directories /home/src1 and /home/src2,
22279  the -
22280 \begin_inset ERT
22281 status Collapsed
22282
22283 \layout Standard
22284
22285 \backslash 
22286 /
22287 \end_inset 
22288
22289 -directory option should be -
22290 \begin_inset ERT
22291 status Collapsed
22292
22293 \layout Standard
22294
22295 \backslash 
22296 /
22297 \end_inset 
22298
22299 -directory=/home/src1:/home/src2.
22300  Note there can be no spaces in the option.
22301  
22302 \layout Itemize
22303
22304 -cd <directory> - change to the <directory>.
22305 \layout Itemize
22306
22307 -fullname - used by GUI front ends.
22308 \layout Itemize
22309
22310 -cpu <cpu-type> - this argument is passed to the simulator please see the
22311  simulator docs for details.
22312 \layout Itemize
22313
22314 -X <Clock frequency > this options is passed to the simulator please see
22315  the simulator docs for details.
22316 \layout Itemize
22317
22318 -s <serial port file> passed to simulator see the simulator docs for details.
22319 \layout Itemize
22320
22321 -S <serial in,out> passed to simulator see the simulator docs for details.
22322 \layout Itemize
22323
22324 -k <port number> passed to simulator see the simulator docs for details.
22325 \layout Subsection
22326
22327 SDCDB Debugger Commands
22328 \layout Standard
22329
22330 As mentioned earlier the command interface for the debugger has been deliberatel
22331 y kept as close the GNU debugger gdb, as possible.
22332  This will help the integration with existing graphical user interfaces
22333  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22334  If you use a graphical user interface for the debugger you can skip this
22335  section.
22336 \layout Subsubsection*
22337
22338 break [line | file:line | function | file:function]
22339 \layout Standard
22340
22341 Set breakpoint at specified line or function:
22342 \newline 
22343
22344 \newline 
22345
22346 \family sans 
22347 \series bold 
22348 sdcdb>break 100 
22349 \newline 
22350 sdcdb>break foo.c:100
22351 \newline 
22352 sdcdb>break funcfoo
22353 \newline 
22354 sdcdb>break foo.c:funcfoo
22355 \layout Subsubsection*
22356
22357 clear [line | file:line | function | file:function ]
22358 \layout Standard
22359
22360 Clear breakpoint at specified line or function:
22361 \newline 
22362
22363 \newline 
22364
22365 \family sans 
22366 \series bold 
22367 sdcdb>clear 100
22368 \newline 
22369 sdcdb>clear foo.c:100
22370 \newline 
22371 sdcdb>clear funcfoo
22372 \newline 
22373 sdcdb>clear foo.c:funcfoo
22374 \layout Subsubsection*
22375
22376 continue
22377 \layout Standard
22378
22379 Continue program being debugged, after breakpoint.
22380 \layout Subsubsection*
22381
22382 finish
22383 \layout Standard
22384
22385 Execute till the end of the current function.
22386 \layout Subsubsection*
22387
22388 delete [n]
22389 \layout Standard
22390
22391 Delete breakpoint number 'n'.
22392  If used without any option clear ALL user defined break points.
22393 \layout Subsubsection*
22394
22395 info [break | stack | frame | registers ]
22396 \layout Itemize
22397
22398 info break - list all breakpoints
22399 \layout Itemize
22400
22401 info stack - show the function call stack.
22402 \layout Itemize
22403
22404 info frame - show information about the current execution frame.
22405 \layout Itemize
22406
22407 info registers - show content of all registers.
22408 \layout Subsubsection*
22409
22410 step
22411 \layout Standard
22412
22413 Step program until it reaches a different source line.
22414  Note: pressing <return> repeats the last command.
22415 \layout Subsubsection*
22416
22417 next
22418 \layout Standard
22419
22420 Step program, proceeding through subroutine calls.
22421 \layout Subsubsection*
22422
22423 run
22424 \layout Standard
22425
22426 Start debugged program.
22427 \layout Subsubsection*
22428
22429 ptype variable 
22430 \layout Standard
22431
22432 Print type information of the variable.
22433 \layout Subsubsection*
22434
22435 print variable
22436 \layout Standard
22437
22438 print value of variable.
22439 \layout Subsubsection*
22440
22441 file filename
22442 \layout Standard
22443
22444 load the given file name.
22445  Note this is an alternate method of loading file for debugging.
22446 \layout Subsubsection*
22447
22448 frame
22449 \layout Standard
22450
22451 print information about current frame.
22452 \layout Subsubsection*
22453
22454 set srcmode
22455 \layout Standard
22456
22457 Toggle between C source & assembly source.
22458 \layout Subsubsection*
22459
22460 ! simulator command
22461 \layout Standard
22462
22463 Send the string following '!' to the simulator, the simulator response is
22464  displayed.
22465  Note the debugger does not interpret the command being sent to the simulator,
22466  so if a command like 'go' is sent the debugger can loose its execution
22467  context and may display incorrect values.
22468 \layout Subsubsection*
22469
22470 quit
22471 \layout Standard
22472
22473 "Watch me now.
22474  Iam going Down.
22475  My name is Bobby Brown"
22476 \layout Subsection
22477
22478 Interfacing SDCDB with DDD
22479 \layout Comment
22480
22481 The screenshot was converted from png to eps with: 
22482 \begin_inset Quotes sld
22483 \end_inset 
22484
22485 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22486 \begin_inset Quotes srd
22487 \end_inset 
22488
22489  which produces a pretty compact eps file which is free from compression
22490  artifacts.
22491 \layout Comment
22492
22493 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22494  as this broke the build system on Sourceforge (pdf-file was broken.
22495  pdflatex does not accept eps files).
22496 \layout Standard
22497
22498 The 
22499 \emph on 
22500 p
22501 \emph default 
22502 ortable 
22503 \emph on 
22504 n
22505 \emph default 
22506 etwork 
22507 \emph on 
22508 g
22509 \emph default 
22510 raphics File 
22511 \size footnotesize 
22512
22513 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22514
22515 \end_inset 
22516
22517
22518 \size default 
22519  shows a screenshot of a debugging session with DDD
22520 \begin_inset LatexCommand \index{DDD (debugger)}
22521
22522 \end_inset 
22523
22524  (Unix only) on a simulated 8032.
22525  The debugging session might not run as smoothly as the screenshot suggests.
22526  The debugger allows setting of breakpoints, displaying and changing variables,
22527  single stepping through C and assembler code.
22528  
22529 \newline 
22530 The source was compiled with 
22531 \family sans 
22532 \series bold 
22533
22534 \newline 
22535
22536 \newline 
22537 sdcc -
22538 \family default 
22539 \series default 
22540
22541 \begin_inset ERT
22542 status Collapsed
22543
22544 \layout Standard
22545
22546 \backslash 
22547 /
22548 \end_inset 
22549
22550
22551 \family sans 
22552 \series bold 
22553 -debug ddd_example.c
22554 \family default 
22555 \series default 
22556  
22557 \family sans 
22558 \series bold 
22559
22560 \newline 
22561
22562 \family default 
22563 \series default 
22564
22565 \newline 
22566 and DDD was invoked with 
22567 \family sans 
22568 \series bold 
22569
22570 \newline 
22571
22572 \newline 
22573 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22574 \layout Subsection
22575
22576 Interfacing SDCDB with XEmacs
22577 \begin_inset LatexCommand \index{XEmacs}
22578
22579 \end_inset 
22580
22581
22582 \begin_inset LatexCommand \index{Emacs}
22583
22584 \end_inset 
22585
22586
22587 \layout Standard
22588
22589 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22590  sdcdb.el and sdcdbsrc.el.
22591  These two files can be found in the $(prefix)/bin directory after the installat
22592 ion is complete.
22593  These files need to be loaded into XEmacs for the interface to work.
22594  This can be done at XEmacs startup time by inserting the following into
22595  your '.xemacs' file (which can be found in your HOME directory): 
22596 \newline 
22597
22598 \newline 
22599
22600 \family typewriter 
22601 (load-file sdcdbsrc.el) 
22602 \family default 
22603
22604 \newline 
22605
22606 \newline 
22607 .xemacs is a lisp file so the () around the command is REQUIRED.
22608  The files can also be loaded dynamically while XEmacs is running, set the
22609  environment variable 'EMACSLOADPATH' to the installation bin directory
22610  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22611  To start the interface enter the following command: 
22612 \newline 
22613
22614 \newline 
22615
22616 \family sans 
22617 \series bold 
22618 ESC-x sdcdbsrc
22619 \family default 
22620 \series default 
22621
22622 \newline 
22623
22624 \newline 
22625 You will prompted to enter the file name to be debugged.
22626  
22627 \newline 
22628
22629 \newline 
22630 The command line options that are passed to the simulator directly are bound
22631  to default values in the file sdcdbsrc.el.
22632  The variables are listed below, these values maybe changed as required.
22633 \layout Itemize
22634
22635 sdcdbsrc-cpu-type '51
22636 \layout Itemize
22637
22638 sdcdbsrc-frequency '11059200
22639 \layout Itemize
22640
22641 sdcdbsrc-serial nil
22642 \layout Standard
22643
22644 The following is a list of key mapping for the debugger interface.
22645 \layout Standard
22646
22647 \SpecialChar ~
22648
22649 \family typewriter 
22650
22651 \newline 
22652 ;;\SpecialChar ~
22653 Current Listing :: 
22654 \newline 
22655 ;;key\SpecialChar ~
22656 \SpecialChar ~
22657 \SpecialChar ~
22658 \SpecialChar ~
22659 \SpecialChar ~
22660 \SpecialChar ~
22661 \SpecialChar ~
22662 \SpecialChar ~
22663 \SpecialChar ~
22664 \SpecialChar ~
22665 \SpecialChar ~
22666 \SpecialChar ~
22667 \SpecialChar ~
22668 \SpecialChar ~
22669 binding\SpecialChar ~
22670 \SpecialChar ~
22671 \SpecialChar ~
22672 \SpecialChar ~
22673 \SpecialChar ~
22674 \SpecialChar ~
22675 \SpecialChar ~
22676 \SpecialChar ~
22677 \SpecialChar ~
22678 \SpecialChar ~
22679 \SpecialChar ~
22680 \SpecialChar ~
22681 \SpecialChar ~
22682 \SpecialChar ~
22683 \SpecialChar ~
22684 \SpecialChar ~
22685 \SpecialChar ~
22686 \SpecialChar ~
22687 \SpecialChar ~
22688 \SpecialChar ~
22689 \SpecialChar ~
22690 \SpecialChar ~
22691 Comment 
22692 \newline 
22693 ;;---\SpecialChar ~
22694 \SpecialChar ~
22695 \SpecialChar ~
22696 \SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 \SpecialChar ~
22702 \SpecialChar ~
22703 \SpecialChar ~
22704 \SpecialChar ~
22705 \SpecialChar ~
22706 \SpecialChar ~
22707 -------\SpecialChar ~
22708 \SpecialChar ~
22709 \SpecialChar ~
22710 \SpecialChar ~
22711 \SpecialChar ~
22712 \SpecialChar ~
22713 \SpecialChar ~
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 \SpecialChar ~
22717 \SpecialChar ~
22718 \SpecialChar ~
22719 \SpecialChar ~
22720 \SpecialChar ~
22721 \SpecialChar ~
22722 \SpecialChar ~
22723 \SpecialChar ~
22724 \SpecialChar ~
22725 \SpecialChar ~
22726 \SpecialChar ~
22727 \SpecialChar ~
22728 \SpecialChar ~
22729 -------
22730 \newline 
22731 ;; 
22732 \newline 
22733 ;;\SpecialChar ~
22734 n\SpecialChar ~
22735 \SpecialChar ~
22736 \SpecialChar ~
22737 \SpecialChar ~
22738 \SpecialChar ~
22739 \SpecialChar ~
22740 \SpecialChar ~
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 \SpecialChar ~
22746 \SpecialChar ~
22747 \SpecialChar ~
22748 \SpecialChar ~
22749 sdcdb-next-from-src\SpecialChar ~
22750 \SpecialChar ~
22751 \SpecialChar ~
22752 \SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 SDCDB next command 
22760 \newline 
22761 ;;\SpecialChar ~
22762 b\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 sdcdb-back-from-src\SpecialChar ~
22778 \SpecialChar ~
22779 \SpecialChar ~
22780 \SpecialChar ~
22781 \SpecialChar ~
22782 \SpecialChar ~
22783 \SpecialChar ~
22784 \SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 SDCDB back command 
22788 \newline 
22789 ;;\SpecialChar ~
22790 c\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 sdcdb-cont-from-src\SpecialChar ~
22806 \SpecialChar ~
22807 \SpecialChar ~
22808 \SpecialChar ~
22809 \SpecialChar ~
22810 \SpecialChar ~
22811 \SpecialChar ~
22812 \SpecialChar ~
22813 \SpecialChar ~
22814 \SpecialChar ~
22815 SDCDB continue command
22816 \newline 
22817 ;;\SpecialChar ~
22818 s\SpecialChar ~
22819 \SpecialChar ~
22820 \SpecialChar ~
22821 \SpecialChar ~
22822 \SpecialChar ~
22823 \SpecialChar ~
22824 \SpecialChar ~
22825 \SpecialChar ~
22826 \SpecialChar ~
22827 \SpecialChar ~
22828 \SpecialChar ~
22829 \SpecialChar ~
22830 \SpecialChar ~
22831 \SpecialChar ~
22832 \SpecialChar ~
22833 sdcdb-step-from-src\SpecialChar ~
22834 \SpecialChar ~
22835 \SpecialChar ~
22836 \SpecialChar ~
22837 \SpecialChar ~
22838 \SpecialChar ~
22839 \SpecialChar ~
22840 \SpecialChar ~
22841 \SpecialChar ~
22842 \SpecialChar ~
22843 SDCDB step command 
22844 \newline 
22845 ;;\SpecialChar ~
22846 ?\SpecialChar ~
22847 \SpecialChar ~
22848 \SpecialChar ~
22849 \SpecialChar ~
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 \SpecialChar ~
22853 \SpecialChar ~
22854 \SpecialChar ~
22855 \SpecialChar ~
22856 \SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 sdcdb-whatis-c-sexp\SpecialChar ~
22862 \SpecialChar ~
22863 \SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 SDCDB ptypecommand for data at 
22872 \newline 
22873 ;;\SpecialChar ~
22874 \SpecialChar ~
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 \SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 \SpecialChar ~
22886 \SpecialChar ~
22887 \SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 \SpecialChar ~
22902 \SpecialChar ~
22903 \SpecialChar ~
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 \SpecialChar ~
22907 \SpecialChar ~
22908 \SpecialChar ~
22909 \SpecialChar ~
22910 \SpecialChar ~
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 \SpecialChar ~
22914 \SpecialChar ~
22915 \SpecialChar ~
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 \SpecialChar ~
22920 buffer point 
22921 \newline 
22922 ;;\SpecialChar ~
22923 x\SpecialChar ~
22924 \SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 \SpecialChar ~
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 \SpecialChar ~
22938 sdcdbsrc-delete\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 Delete all breakpoints if no arg 
22953 \newline 
22954 ;;\SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 \SpecialChar ~
22960 \SpecialChar ~
22961 \SpecialChar ~
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 \SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 \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 given or delete arg (C-u arg x) 
23002 \newline 
23003 ;;\SpecialChar ~
23004 m\SpecialChar ~
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 \SpecialChar ~
23008 \SpecialChar ~
23009 \SpecialChar ~
23010 \SpecialChar ~
23011 \SpecialChar ~
23012 \SpecialChar ~
23013 \SpecialChar ~
23014 \SpecialChar ~
23015 \SpecialChar ~
23016 \SpecialChar ~
23017 \SpecialChar ~
23018 \SpecialChar ~
23019 sdcdbsrc-frame\SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 \SpecialChar ~
23025 \SpecialChar ~
23026 \SpecialChar ~
23027 \SpecialChar ~
23028 \SpecialChar ~
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 \SpecialChar ~
23032 \SpecialChar ~
23033 \SpecialChar ~
23034 SDCDB Display current frame if no arg, 
23035 \newline 
23036 ;;\SpecialChar ~
23037 \SpecialChar ~
23038 \SpecialChar ~
23039 \SpecialChar ~
23040 \SpecialChar ~
23041 \SpecialChar ~
23042 \SpecialChar ~
23043 \SpecialChar ~
23044 \SpecialChar ~
23045 \SpecialChar ~
23046 \SpecialChar ~
23047 \SpecialChar ~
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 \SpecialChar ~
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 \SpecialChar ~
23056 \SpecialChar ~
23057 \SpecialChar ~
23058 \SpecialChar ~
23059 \SpecialChar ~
23060 \SpecialChar ~
23061 \SpecialChar ~
23062 \SpecialChar ~
23063 \SpecialChar ~
23064 \SpecialChar ~
23065 \SpecialChar ~
23066 \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 given or display frame arg 
23084 \newline 
23085 ;;\SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 \SpecialChar ~
23092 \SpecialChar ~
23093 \SpecialChar ~
23094 \SpecialChar ~
23095 \SpecialChar ~
23096 \SpecialChar ~
23097 \SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 \SpecialChar ~
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 \SpecialChar ~
23125 \SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 buffer point 
23133 \newline 
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 sdcdbsrc-goto-sdcdb\SpecialChar ~
23151 \SpecialChar ~
23152 \SpecialChar ~
23153 \SpecialChar ~
23154 \SpecialChar ~
23155 \SpecialChar ~
23156 \SpecialChar ~
23157 \SpecialChar ~
23158 \SpecialChar ~
23159 \SpecialChar ~
23160 Goto the SDCDB output buffer 
23161 \newline 
23162 ;;\SpecialChar ~
23163 p\SpecialChar ~
23164 \SpecialChar ~
23165 \SpecialChar ~
23166 \SpecialChar ~
23167 \SpecialChar ~
23168 \SpecialChar ~
23169 \SpecialChar ~
23170 \SpecialChar ~
23171 \SpecialChar ~
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 \SpecialChar ~
23175 \SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 sdcdb-print-c-sexp\SpecialChar ~
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 \SpecialChar ~
23186 \SpecialChar ~
23187 \SpecialChar ~
23188 \SpecialChar ~
23189 SDCDB print command for data at 
23190 \newline 
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 \SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226 \SpecialChar ~
23227 \SpecialChar ~
23228 \SpecialChar ~
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235 \SpecialChar ~
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 buffer point 
23239 \newline 
23240 ;;\SpecialChar ~
23241 g\SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249 \SpecialChar ~
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 \SpecialChar ~
23253 \SpecialChar ~
23254 \SpecialChar ~
23255 \SpecialChar ~
23256 sdcdbsrc-goto-sdcdb\SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 \SpecialChar ~
23260 \SpecialChar ~
23261 \SpecialChar ~
23262 \SpecialChar ~
23263 \SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 Goto the SDCDB output buffer 
23267 \newline 
23268 ;;\SpecialChar ~
23269 t\SpecialChar ~
23270 \SpecialChar ~
23271 \SpecialChar ~
23272 \SpecialChar ~
23273 \SpecialChar ~
23274 \SpecialChar ~
23275 \SpecialChar ~
23276 \SpecialChar ~
23277 \SpecialChar ~
23278 \SpecialChar ~
23279 \SpecialChar ~
23280 \SpecialChar ~
23281 \SpecialChar ~
23282 \SpecialChar ~
23283 \SpecialChar ~
23284 sdcdbsrc-mode\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 Toggles Sdcdbsrc mode (turns it off) 
23301 \newline 
23302 ;; 
23303 \newline 
23304 ;;\SpecialChar ~
23305 C-c\SpecialChar ~
23306 C-f\SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 sdcdb-finish-from-src\SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 SDCDB finish command 
23324 \newline 
23325 ;; 
23326 \newline 
23327 ;;\SpecialChar ~
23328 C-x\SpecialChar ~
23329 SPC\SpecialChar ~
23330 \SpecialChar ~
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 \SpecialChar ~
23334 \SpecialChar ~
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 sdcdb-break\SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 \SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 \SpecialChar ~
23355 \SpecialChar ~
23356 Set break for line with point 
23357 \newline 
23358 ;;\SpecialChar ~
23359 ESC\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 sdcdbsrc-mode\SpecialChar ~
23372 \SpecialChar ~
23373 \SpecialChar ~
23374 \SpecialChar ~
23375 \SpecialChar ~
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 \SpecialChar ~
23379 \SpecialChar ~
23380 \SpecialChar ~
23381 \SpecialChar ~
23382 \SpecialChar ~
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 \SpecialChar ~
23386 \SpecialChar ~
23387 Toggle Sdcdbsrc mode 
23388 \newline 
23389 ;;\SpecialChar ~
23390 ESC\SpecialChar ~
23391 m\SpecialChar ~
23392 \SpecialChar ~
23393 \SpecialChar ~
23394 \SpecialChar ~
23395 \SpecialChar ~
23396 \SpecialChar ~
23397 \SpecialChar ~
23398 \SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 sdcdbsrc-srcmode\SpecialChar ~
23403 \SpecialChar ~
23404 \SpecialChar ~
23405 \SpecialChar ~
23406 \SpecialChar ~
23407 \SpecialChar ~
23408 \SpecialChar ~
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 \SpecialChar ~
23414 \SpecialChar ~
23415 Toggle list mode 
23416 \newline 
23417 ;; 
23418 \newline 
23419
23420 \layout Chapter
23421 \pagebreak_top 
23422 TIPS
23423 \layout Standard
23424
23425 Here are a few guidelines that will help the compiler generate more efficient
23426  code, some of the tips are specific to this compiler others are generally
23427  good programming practice.
23428 \layout Itemize
23429
23430 Use the smallest data type to represent your data-value.
23431  If it is known in advance that the value is going to be less than 256 then
23432  use an 'unsigned char' instead of a 'short' or 'int'.
23433  Please note, that ANSI C requires both signed and unsigned chars to be
23434  promoted to 'signed int'
23435 \begin_inset LatexCommand \index{promotion to signed int}
23436
23437 \end_inset 
23438
23439
23440 \begin_inset Marginal
23441 collapsed true
23442
23443 \layout Standard
23444
23445
23446 \series bold 
23447 \SpecialChar ~
23448 !
23449 \end_inset 
23450
23451  before doing any operation.
23452  This promotion
23453 \begin_inset LatexCommand \index{type promotion}
23454
23455 \end_inset 
23456
23457
23458 \begin_inset LatexCommand \label{type promotion}
23459
23460 \end_inset 
23461
23462  can be omitted, if the result is the same.
23463  The effect of the promotion rules together with the sign-extension is often
23464  surprising:
23465 \begin_deeper 
23466 \layout Verse
23467
23468
23469 \family typewriter 
23470 unsigned char uc = 0xfe;
23471 \newline 
23472 if (uc * uc < 0) /* this is true! */
23473 \newline 
23474 {
23475 \newline 
23476 \SpecialChar ~
23477 \SpecialChar ~
23478 \SpecialChar ~
23479 \SpecialChar ~
23480 ....
23481 \newline 
23482 }
23483 \layout Standard
23484
23485
23486 \family typewriter 
23487 uc * uc
23488 \family default 
23489  is evaluated as 
23490 \family typewriter 
23491 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23492 \family default 
23493 .
23494  
23495 \newline 
23496 Another one:
23497 \layout Verse
23498
23499
23500 \family typewriter 
23501 (unsigned char) -12 / (signed char) -3 = ...
23502 \layout Standard
23503
23504 No, the result is not 4:
23505 \layout Verse
23506
23507
23508 \family typewriter 
23509 (int) (unsigned char) -12 / (int) (signed char) -3 =
23510 \newline 
23511 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23512 \newline 
23513 (int) 0x00f4 / (int) 0xfffd =
23514 \newline 
23515 (int) 0x00f4 / (int) 0xfffd =
23516 \newline 
23517 (int) 244 / (int) -3 =
23518 \newline 
23519 (int) -81 = (int) 0xffaf;
23520 \layout Standard
23521
23522 Don't complain, that gcc gives you a different result.
23523  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23524  Therefore the results are different.
23525 \newline 
23526 From 
23527 \begin_inset Quotes sld
23528 \end_inset 
23529
23530 comp.lang.c FAQ
23531 \begin_inset Quotes srd
23532 \end_inset 
23533
23534 :
23535 \layout Quote
23536
23537
23538 \emph on 
23539 If well-defined overflow characteristics are important and negative values
23540  are not, or if you want to steer clear of sign-extension problems when
23541  manipulating bits or bytes, use one of the corresponding unsigned types.
23542  (Beware when mixing signed and unsigned values in expressions, though.)
23543 \newline 
23544 Although character types (especially unsigned char) can be used as "tiny"
23545  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23546 ble sign extension and increased code size.
23547 \end_deeper 
23548 \layout Itemize
23549
23550 Use unsigned when it is known in advance that the value is not going to
23551  be negative.
23552  This helps especially if you are doing division or multiplication, bit-shifting
23553  or are using an array index.
23554 \layout Itemize
23555
23556 NEVER jump into a LOOP.
23557 \layout Itemize
23558
23559 Declare the variables to be local
23560 \begin_inset LatexCommand \index{local variables}
23561
23562 \end_inset 
23563
23564  whenever possible, especially loop control variables (induction).
23565 \layout Itemize
23566
23567 Since the compiler does not always do implicit integral promotion, the programme
23568 r should do an explicit cast when integral promotion is required.
23569 \layout Itemize
23570
23571 Reducing the size of division, multiplication & modulus operations can reduce
23572  code size substantially.
23573  Take the following code for example.
23574 \begin_deeper 
23575 \layout Verse
23576
23577
23578 \family typewriter 
23579 foobar(unsigned int p1, unsigned char ch)
23580 \newline 
23581 {
23582 \newline 
23583 \SpecialChar ~
23584 \SpecialChar ~
23585 \SpecialChar ~
23586 \SpecialChar ~
23587 unsigned char ch1 = p1 % ch ;
23588 \newline 
23589 \SpecialChar ~
23590 \SpecialChar ~
23591 \SpecialChar ~
23592 \SpecialChar ~
23593 ....
23594 \newline 
23595 }
23596 \layout Standard
23597
23598 For the modulus operation the variable ch will be promoted to unsigned int
23599  first then the modulus operation will be performed (this will lead to a
23600  call to support routine _moduint()), and the result will be casted to a
23601  char.
23602  If the code is changed to 
23603 \layout Verse
23604
23605
23606 \family typewriter 
23607 foobar(unsigned int p1, unsigned char ch)
23608 \newline 
23609 {
23610 \newline 
23611 \SpecialChar ~
23612 \SpecialChar ~
23613 \SpecialChar ~
23614 \SpecialChar ~
23615 unsigned char ch1 = (unsigned char)p1 % ch ;
23616 \newline 
23617 \SpecialChar ~
23618 \SpecialChar ~
23619 \SpecialChar ~
23620 \SpecialChar ~
23621 ....
23622 \newline 
23623 }
23624 \layout Standard
23625
23626 It would substantially reduce the code generated (future versions of the
23627  compiler will be smart enough to detect such optimization opportunities).
23628 \end_deeper 
23629 \layout Itemize
23630
23631 Have a look at the assembly listing to get a 
23632 \begin_inset Quotes sld
23633 \end_inset 
23634
23635 feeling
23636 \begin_inset Quotes srd
23637 \end_inset 
23638
23639  for the code generation.
23640 \layout Section
23641
23642 Porting code from or to other compilers
23643 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23644
23645 \end_inset 
23646
23647
23648 \layout Itemize
23649
23650 check whether endianness of the compilers differs and adapt where needed.
23651 \layout Itemize
23652
23653 check the device specific header files
23654 \begin_inset LatexCommand \index{Header files}
23655
23656 \end_inset 
23657
23658
23659 \begin_inset LatexCommand \index{Include files}
23660
23661 \end_inset 
23662
23663  for compiler specific syntax.
23664  Eventually include the file <compiler.h
23665 \begin_inset LatexCommand \index{compiler.h (include file)}
23666
23667 \end_inset 
23668
23669
23670 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23671
23672 \end_inset 
23673
23674  to allow using common header files.
23675  (see f.e.
23676  cc2510fx.h 
23677 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23678
23679 \end_inset 
23680
23681 ).
23682 \layout Itemize
23683
23684 check whether the startup code contains the correct initialization (watchdog,
23685  peripherals).
23686 \layout Itemize
23687
23688 check whether the sizes of short, int, long match.
23689 \layout Itemize
23690
23691 check if some 16 or 32 bit hardware registers require a specific addressing
23692  order (least significant or most significant byte first) and adapt if needed
23693  (
23694 \emph on 
23695 first
23696 \emph default 
23697  and 
23698 \emph on 
23699 last
23700 \emph default 
23701  relate to time and not to lower/upper memory location here, so this is
23702  
23703 \emph on 
23704 not
23705 \emph default 
23706  the same as endianness).
23707 \layout Itemize
23708
23709 check whether the keyword 
23710 \emph on 
23711 volatile
23712 \emph default 
23713  is used where needed.
23714  The compilers might differ in their optimization characteristics (as different
23715  versions of the same compiler might also use more clever optimizations
23716  this is good idea anyway).
23717  See section 
23718 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23719
23720 \end_inset 
23721
23722 .
23723 \layout Itemize
23724
23725 check that the compilers are not told to supress warnings.
23726 \layout Itemize
23727
23728 check and convert compiler specific extensions (interrupts, memory areas,
23729  pragmas etc.).
23730 \layout Itemize
23731
23732 check for differences in type promotion.
23733  Especially check for math operations on 
23734 \family typewriter 
23735 char
23736 \family default 
23737  or 
23738 \family typewriter 
23739 unsigned char
23740 \family default 
23741  variables.
23742  For the sake of C99 compatibility SDCC will probably promote these to 
23743 \family typewriter 
23744 int
23745 \family default 
23746  more often than other compilers.
23747  Eventually insert explicit casts to 
23748 \family typewriter 
23749 (char) 
23750 \family default 
23751 or
23752 \family typewriter 
23753  (unsigned char)
23754 \family default 
23755 .
23756  Also check that the ~\SpecialChar ~
23757 operator
23758 \begin_inset LatexCommand \index{\~\/ Operator}
23759
23760 \end_inset 
23761
23762  is not used on 
23763 \family typewriter 
23764 bit
23765 \begin_inset LatexCommand \index{bit}
23766
23767 \end_inset 
23768
23769
23770 \family default 
23771  variables, use the !\SpecialChar ~
23772 operator instead.
23773  See sections 
23774 \begin_inset LatexCommand \ref{type promotion}
23775
23776 \end_inset 
23777
23778  and 
23779 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23780
23781 \end_inset 
23782
23783 .
23784 \layout Itemize
23785
23786 check the assembly code generated for interrupt routines (f.e.
23787  for calls to possibly non-reentrant library functions).
23788 \layout Itemize
23789
23790 check whether timing loops result in proper timing (or preferably consider
23791  a rewrite of the code with timer based delays instead).
23792 \layout Itemize
23793
23794 check for differences in printf parameters (some compilers push (va_arg
23795 \begin_inset LatexCommand \index{vararg, va\_arg}
23796
23797 \end_inset 
23798
23799 ) char variables as 
23800 \family typewriter 
23801 int
23802 \family default 
23803  others push them as 
23804 \family typewriter 
23805 char
23806 \family default 
23807 .
23808  See section 
23809 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23810
23811 \end_inset 
23812
23813 ).
23814 \layout Itemize
23815
23816 check the resulting memory map
23817 \begin_inset LatexCommand \index{Memory map}
23818
23819 \end_inset 
23820
23821 .
23822  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23823 ly idata, pdata, xdata).
23824  Eventually check if unexpected library functions are included.
23825 \layout Section
23826
23827 Tools
23828 \begin_inset LatexCommand \index{Tools}
23829
23830 \end_inset 
23831
23832  included in the distribution
23833 \layout Standard
23834 \align left 
23835
23836 \begin_inset  Tabular
23837 <lyxtabular version="3" rows="12" columns="3">
23838 <features>
23839 <column alignment="left" valignment="top" leftline="true" width="0pt">
23840 <column alignment="left" valignment="top" leftline="true" width="0pt">
23841 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23842 <row topline="true" bottomline="true">
23843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23844 \begin_inset Text
23845
23846 \layout Standard
23847
23848 Name
23849 \end_inset 
23850 </cell>
23851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23852 \begin_inset Text
23853
23854 \layout Standard
23855
23856 Purpose
23857 \end_inset 
23858 </cell>
23859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23860 \begin_inset Text
23861
23862 \layout Standard
23863
23864 Directory
23865 \end_inset 
23866 </cell>
23867 </row>
23868 <row topline="true">
23869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23870 \begin_inset Text
23871
23872 \layout Standard
23873
23874 ucSsim
23875 \end_inset 
23876 </cell>
23877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23878 \begin_inset Text
23879
23880 \layout Standard
23881
23882 Simulator for various architectures
23883 \end_inset 
23884 </cell>
23885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23886 \begin_inset Text
23887
23888 \layout Standard
23889
23890 sdcc/sim/ucsim
23891 \end_inset 
23892 </cell>
23893 </row>
23894 <row topline="true">
23895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23896 \begin_inset Text
23897
23898 \layout Standard
23899
23900 keil2sdcc.pl
23901 \end_inset 
23902 </cell>
23903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23904 \begin_inset Text
23905
23906 \layout Standard
23907
23908 header file
23909 \begin_inset LatexCommand \index{Header files}
23910
23911 \end_inset 
23912
23913
23914 \begin_inset LatexCommand \index{Include files}
23915
23916 \end_inset 
23917
23918  conversion
23919 \end_inset 
23920 </cell>
23921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23922 \begin_inset Text
23923
23924 \layout Standard
23925
23926 sdcc/support/scripts
23927 \end_inset 
23928 </cell>
23929 </row>
23930 <row topline="true">
23931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23932 \begin_inset Text
23933
23934 \layout Standard
23935
23936 mh2h.c
23937 \end_inset 
23938 </cell>
23939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23940 \begin_inset Text
23941
23942 \layout Standard
23943
23944 header file conversion
23945 \end_inset 
23946 </cell>
23947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23948 \begin_inset Text
23949
23950 \layout Standard
23951
23952 sdcc/support/scripts
23953 \end_inset 
23954 </cell>
23955 </row>
23956 <row topline="true">
23957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23958 \begin_inset Text
23959
23960 \layout Standard
23961
23962 as-gbz80
23963 \end_inset 
23964 </cell>
23965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23966 \begin_inset Text
23967
23968 \layout Standard
23969
23970 Assembler
23971 \end_inset 
23972 </cell>
23973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23974 \begin_inset Text
23975
23976 \layout Standard
23977
23978
23979 \family roman 
23980 \series medium 
23981 \shape up 
23982 \size normal 
23983 \emph off 
23984 \bar no 
23985 \noun off 
23986 \color none
23987 sdcc/bin
23988 \end_inset 
23989 </cell>
23990 </row>
23991 <row topline="true">
23992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23993 \begin_inset Text
23994
23995 \layout Standard
23996
23997 as-z80
23998 \end_inset 
23999 </cell>
24000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24001 \begin_inset Text
24002
24003 \layout Standard
24004
24005 Assembler
24006 \end_inset 
24007 </cell>
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24009 \begin_inset Text
24010
24011 \layout Standard
24012
24013
24014 \family roman 
24015 \series medium 
24016 \shape up 
24017 \size normal 
24018 \emph off 
24019 \bar no 
24020 \noun off 
24021 \color none
24022 sdcc/bin
24023 \end_inset 
24024 </cell>
24025 </row>
24026 <row topline="true">
24027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24028 \begin_inset Text
24029
24030 \layout Standard
24031
24032 asx8051
24033 \end_inset 
24034 </cell>
24035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24036 \begin_inset Text
24037
24038 \layout Standard
24039
24040 Assembler
24041 \end_inset 
24042 </cell>
24043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24044 \begin_inset Text
24045
24046 \layout Standard
24047
24048
24049 \family roman 
24050 \series medium 
24051 \shape up 
24052 \size normal 
24053 \emph off 
24054 \bar no 
24055 \noun off 
24056 \color none
24057 sdcc/bin
24058 \end_inset 
24059 </cell>
24060 </row>
24061 <row topline="true">
24062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24063 \begin_inset Text
24064
24065 \layout Standard
24066
24067 SDCDB
24068 \end_inset 
24069 </cell>
24070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24071 \begin_inset Text
24072
24073 \layout Standard
24074
24075 Simulator
24076 \end_inset 
24077 </cell>
24078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24079 \begin_inset Text
24080
24081 \layout Standard
24082
24083
24084 \family roman 
24085 \series medium 
24086 \shape up 
24087 \size normal 
24088 \emph off 
24089 \bar no 
24090 \noun off 
24091 \color none
24092 sdcc/bin
24093 \end_inset 
24094 </cell>
24095 </row>
24096 <row topline="true">
24097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24098 \begin_inset Text
24099
24100 \layout Standard
24101
24102 aslink
24103 \end_inset 
24104 </cell>
24105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24106 \begin_inset Text
24107
24108 \layout Standard
24109
24110 Linker
24111 \end_inset 
24112 </cell>
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24114 \begin_inset Text
24115
24116 \layout Standard
24117
24118
24119 \family roman 
24120 \series medium 
24121 \shape up 
24122 \size normal 
24123 \emph off 
24124 \bar no 
24125 \noun off 
24126 \color none
24127 sdcc/bin
24128 \end_inset 
24129 </cell>
24130 </row>
24131 <row topline="true">
24132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24133 \begin_inset Text
24134
24135 \layout Standard
24136
24137 link-z80
24138 \end_inset 
24139 </cell>
24140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24141 \begin_inset Text
24142
24143 \layout Standard
24144
24145 Linker
24146 \end_inset 
24147 </cell>
24148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24149 \begin_inset Text
24150
24151 \layout Standard
24152
24153
24154 \family roman 
24155 \series medium 
24156 \shape up 
24157 \size normal 
24158 \emph off 
24159 \bar no 
24160 \noun off 
24161 \color none
24162 sdcc/bin
24163 \end_inset 
24164 </cell>
24165 </row>
24166 <row topline="true">
24167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24168 \begin_inset Text
24169
24170 \layout Standard
24171
24172 link-gbz80
24173 \end_inset 
24174 </cell>
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24176 \begin_inset Text
24177
24178 \layout Standard
24179
24180 Linker
24181 \end_inset 
24182 </cell>
24183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24184 \begin_inset Text
24185
24186 \layout Standard
24187
24188
24189 \family roman 
24190 \series medium 
24191 \shape up 
24192 \size normal 
24193 \emph off 
24194 \bar no 
24195 \noun off 
24196 \color none
24197 sdcc/bin
24198 \end_inset 
24199 </cell>
24200 </row>
24201 <row topline="true" bottomline="true">
24202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24203 \begin_inset Text
24204
24205 \layout Standard
24206
24207 packihx
24208 \end_inset 
24209 </cell>
24210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24211 \begin_inset Text
24212
24213 \layout Standard
24214
24215 Intel Hex packer 
24216 \begin_inset LatexCommand \index{packihx (tool)}
24217
24218 \end_inset 
24219
24220
24221 \end_inset 
24222 </cell>
24223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24224 \begin_inset Text
24225
24226 \layout Standard
24227
24228
24229 \family roman 
24230 \series medium 
24231 \shape up 
24232 \size normal 
24233 \emph off 
24234 \bar no 
24235 \noun off 
24236 \color none
24237 sdcc/bin
24238 \end_inset 
24239 </cell>
24240 </row>
24241 </lyxtabular>
24242
24243 \end_inset 
24244
24245
24246 \newline 
24247
24248 \layout Section
24249
24250 Documentation
24251 \begin_inset LatexCommand \index{Documentation}
24252
24253 \end_inset 
24254
24255  included in the distribution
24256 \layout Standard
24257 \align left 
24258
24259 \begin_inset  Tabular
24260 <lyxtabular version="3" rows="10" columns="2">
24261 <features>
24262 <column alignment="left" valignment="top" leftline="true" width="0">
24263 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24264 <row topline="true" bottomline="true">
24265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24266 \begin_inset Text
24267
24268 \layout Standard
24269
24270 Subject / Title
24271 \end_inset 
24272 </cell>
24273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24274 \begin_inset Text
24275
24276 \layout Standard
24277
24278 Where to get / filename
24279 \end_inset 
24280 </cell>
24281 </row>
24282 <row topline="true">
24283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24284 \begin_inset Text
24285
24286 \layout Standard
24287
24288 SDCC Compiler User Guide
24289 \end_inset 
24290 </cell>
24291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24292 \begin_inset Text
24293
24294 \layout Standard
24295
24296 You're reading it right now
24297 \end_inset 
24298 </cell>
24299 </row>
24300 <row topline="true">
24301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24302 \begin_inset Text
24303
24304 \layout Standard
24305
24306 Changelog of SDCC
24307 \end_inset 
24308 </cell>
24309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24310 \begin_inset Text
24311
24312 \layout Standard
24313
24314 sdcc/Changelog
24315 \end_inset 
24316 </cell>
24317 </row>
24318 <row topline="true">
24319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24320 \begin_inset Text
24321
24322 \layout Standard
24323
24324 ASXXXX
24325 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24326
24327 \end_inset 
24328
24329
24330 \begin_inset LatexCommand \index{Assembler documentation}
24331
24332 \end_inset 
24333
24334  Assemblers and ASLINK
24335 \begin_inset LatexCommand \index{aslink}
24336
24337 \end_inset 
24338
24339
24340 \begin_inset LatexCommand \index{Linker documentation}
24341
24342 \end_inset 
24343
24344  Relocating Linker
24345 \end_inset 
24346 </cell>
24347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24348 \begin_inset Text
24349
24350 \layout Standard
24351
24352 sdcc/as/doc/asxhtm.html
24353 \end_inset 
24354 </cell>
24355 </row>
24356 <row topline="true">
24357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24358 \begin_inset Text
24359
24360 \layout Standard
24361
24362 SDCC regression test
24363 \begin_inset LatexCommand \index{Regression test}
24364
24365 \end_inset 
24366
24367
24368 \end_inset 
24369 </cell>
24370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24371 \begin_inset Text
24372
24373 \layout Standard
24374
24375 sdcc/doc/test_suite_spec.pdf
24376 \end_inset 
24377 </cell>
24378 </row>
24379 <row topline="true">
24380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24381 \begin_inset Text
24382
24383 \layout Standard
24384
24385 Various notes
24386 \end_inset 
24387 </cell>
24388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24389 \begin_inset Text
24390
24391 \layout Standard
24392
24393 sdcc/doc/*
24394 \end_inset 
24395 </cell>
24396 </row>
24397 <row topline="true">
24398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24399 \begin_inset Text
24400
24401 \layout Standard
24402
24403 Notes on debugging with SDCDB
24404 \begin_inset LatexCommand \index{SDCDB (debugger)}
24405
24406 \end_inset 
24407
24408
24409 \end_inset 
24410 </cell>
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24412 \begin_inset Text
24413
24414 \layout Standard
24415
24416 sdcc/debugger/README
24417 \end_inset 
24418 </cell>
24419 </row>
24420 <row topline="true">
24421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24422 \begin_inset Text
24423
24424 \layout Standard
24425
24426 Software simulator for microcontrollers
24427 \end_inset 
24428 </cell>
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24430 \begin_inset Text
24431
24432 \layout Standard
24433
24434
24435 \family roman 
24436 \series medium 
24437 \shape up 
24438 \size normal 
24439 \emph off 
24440 \bar no 
24441 \noun off 
24442 \color none
24443 sdcc/sim/ucsim/doc
24444 \family default 
24445 \series default 
24446 \shape default 
24447 \size default 
24448 \emph default 
24449 \bar default 
24450 \noun default 
24451 \color default
24452 /index.html
24453 \end_inset 
24454 </cell>
24455 </row>
24456 <row topline="true">
24457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24458 \begin_inset Text
24459
24460 \layout Standard
24461
24462 Temporary notes on the pic16
24463 \begin_inset LatexCommand \index{PIC16}
24464
24465 \end_inset 
24466
24467  port
24468 \end_inset 
24469 </cell>
24470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24471 \begin_inset Text
24472
24473 \layout Standard
24474
24475 sdcc/src/pic16/NOTES
24476 \end_inset 
24477 </cell>
24478 </row>
24479 <row topline="true" bottomline="true">
24480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24481 \begin_inset Text
24482
24483 \layout Standard
24484
24485 SDCC internal documentation (debugging file format)
24486 \end_inset 
24487 </cell>
24488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24489 \begin_inset Text
24490
24491 \layout Standard
24492
24493 sdcc/doc/
24494 \family roman 
24495 \series medium 
24496 \shape up 
24497 \size normal 
24498 \emph off 
24499 \bar no 
24500 \noun off 
24501 \color none
24502 cdbfileformat.pd
24503 \family default 
24504 \series default 
24505 \shape default 
24506 \size default 
24507 \emph default 
24508 \bar default 
24509 \noun default 
24510 \color default
24511 f
24512 \end_inset 
24513 </cell>
24514 </row>
24515 </lyxtabular>
24516
24517 \end_inset 
24518
24519
24520 \newline 
24521
24522 \layout Section
24523
24524 Related open source tools
24525 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24526
24527 \end_inset 
24528
24529
24530 \begin_inset LatexCommand \index{Related tools}
24531
24532 \end_inset 
24533
24534
24535 \layout Standard
24536 \align left 
24537
24538 \begin_inset  Tabular
24539 <lyxtabular version="3" rows="14" columns="3">
24540 <features>
24541 <column alignment="left" valignment="top" leftline="true" width="0pt">
24542 <column alignment="block" valignment="top" leftline="true" width="30line%">
24543 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24544 <row topline="true" bottomline="true">
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24546 \begin_inset Text
24547
24548 \layout Standard
24549
24550 Name
24551 \end_inset 
24552 </cell>
24553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24554 \begin_inset Text
24555
24556 \layout Standard
24557
24558 Purpose
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 Where to get
24567 \end_inset 
24568 </cell>
24569 </row>
24570 <row topline="true">
24571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24572 \begin_inset Text
24573
24574 \layout Standard
24575
24576 gpsim
24577 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24578
24579 \end_inset 
24580
24581
24582 \end_inset 
24583 </cell>
24584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24585 \begin_inset Text
24586
24587 \layout Standard
24588
24589 PIC simulator
24590 \end_inset 
24591 </cell>
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24593 \begin_inset Text
24594
24595 \layout Standard
24596
24597
24598 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24599
24600 \end_inset 
24601
24602
24603 \end_inset 
24604 </cell>
24605 </row>
24606 <row topline="true">
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24608 \begin_inset Text
24609
24610 \layout Standard
24611
24612 gputils
24613 \begin_inset LatexCommand \index{gputils (pic tools)}
24614
24615 \end_inset 
24616
24617
24618 \end_inset 
24619 </cell>
24620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24621 \begin_inset Text
24622
24623 \layout Standard
24624
24625 GNU PIC utilities
24626 \end_inset 
24627 </cell>
24628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24629 \begin_inset Text
24630
24631 \layout Standard
24632
24633
24634 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24635
24636 \end_inset 
24637
24638
24639 \end_inset 
24640 </cell>
24641 </row>
24642 <row topline="true">
24643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24644 \begin_inset Text
24645
24646 \layout Standard
24647
24648 flP5
24649 \end_inset 
24650 </cell>
24651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24652 \begin_inset Text
24653
24654 \layout Standard
24655
24656 PIC programmer
24657 \end_inset 
24658 </cell>
24659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24660 \begin_inset Text
24661
24662 \layout Standard
24663
24664
24665 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24666
24667 \end_inset 
24668
24669
24670 \end_inset 
24671 </cell>
24672 </row>
24673 <row topline="true">
24674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24675 \begin_inset Text
24676
24677 \layout Standard
24678
24679 ec2drv/newcdb
24680 \end_inset 
24681 </cell>
24682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24683 \begin_inset Text
24684
24685 \layout Standard
24686
24687 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24688  (Unix only)
24689 \end_inset 
24690 </cell>
24691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24692 \begin_inset Text
24693
24694 \layout Standard
24695
24696
24697 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24698
24699 \end_inset 
24700
24701
24702 \end_inset 
24703 </cell>
24704 </row>
24705 <row topline="true">
24706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24707 \begin_inset Text
24708
24709 \layout Standard
24710
24711 indent
24712 \begin_inset LatexCommand \index{indent (source formatting tool)}
24713
24714 \end_inset 
24715
24716
24717 \end_inset 
24718 </cell>
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24720 \begin_inset Text
24721
24722 \layout Standard
24723
24724 Formats C source - Master of the white spaces
24725 \end_inset 
24726 </cell>
24727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24728 \begin_inset Text
24729
24730 \layout Standard
24731
24732
24733 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24734
24735 \end_inset 
24736
24737
24738 \end_inset 
24739 </cell>
24740 </row>
24741 <row topline="true">
24742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24743 \begin_inset Text
24744
24745 \layout Standard
24746
24747 srecord
24748 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24749
24750 \end_inset 
24751
24752
24753 \end_inset 
24754 </cell>
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24756 \begin_inset Text
24757
24758 \layout Standard
24759
24760 Object file conversion, checksumming, ...
24761 \end_inset 
24762 </cell>
24763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24764 \begin_inset Text
24765
24766 \layout Standard
24767
24768
24769 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24770
24771 \end_inset 
24772
24773
24774 \end_inset 
24775 </cell>
24776 </row>
24777 <row topline="true">
24778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24779 \begin_inset Text
24780
24781 \layout Standard
24782
24783 objdump
24784 \begin_inset LatexCommand \index{objdump (tool)}
24785
24786 \end_inset 
24787
24788
24789 \end_inset 
24790 </cell>
24791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24792 \begin_inset Text
24793
24794 \layout Standard
24795
24796 Object file conversion, ...
24797 \end_inset 
24798 </cell>
24799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24800 \begin_inset Text
24801
24802 \layout Standard
24803
24804 Part of binutils (should be there anyway)
24805 \end_inset 
24806 </cell>
24807 </row>
24808 <row topline="true">
24809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24810 \begin_inset Text
24811
24812 \layout Standard
24813
24814 cmon51
24815 \end_inset 
24816 </cell>
24817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24818 \begin_inset Text
24819
24820 \layout Standard
24821
24822 8051 monitor (hex up-/download, single step, disassemble)
24823 \end_inset 
24824 </cell>
24825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24826 \begin_inset Text
24827
24828 \layout Standard
24829
24830
24831 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24832
24833 \end_inset 
24834
24835
24836 \end_inset 
24837 </cell>
24838 </row>
24839 <row topline="true">
24840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24841 \begin_inset Text
24842
24843 \layout Standard
24844
24845 doxygen
24846 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24847
24848 \end_inset 
24849
24850
24851 \end_inset 
24852 </cell>
24853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24854 \begin_inset Text
24855
24856 \layout Standard
24857
24858 Source code documentation system
24859 \end_inset 
24860 </cell>
24861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24862 \begin_inset Text
24863
24864 \layout Standard
24865
24866
24867 \begin_inset LatexCommand \url{http://www.doxygen.org}
24868
24869 \end_inset 
24870
24871
24872 \end_inset 
24873 </cell>
24874 </row>
24875 <row topline="true">
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24877 \begin_inset Text
24878
24879 \layout Standard
24880
24881 kdevelop
24882 \end_inset 
24883 </cell>
24884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24885 \begin_inset Text
24886
24887 \layout Standard
24888
24889 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24890 \end_inset 
24891 </cell>
24892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24893 \begin_inset Text
24894
24895 \layout Standard
24896
24897
24898 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24899
24900 \end_inset 
24901
24902
24903 \end_inset 
24904 </cell>
24905 </row>
24906 <row topline="true">
24907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24908 \begin_inset Text
24909
24910 \layout Standard
24911
24912 paulmon
24913 \end_inset 
24914 </cell>
24915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24916 \begin_inset Text
24917
24918 \layout Standard
24919
24920 8051 monitor (hex up-/download, single step, disassemble)
24921 \end_inset 
24922 </cell>
24923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24924 \begin_inset Text
24925
24926 \layout Standard
24927
24928
24929 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24930
24931 \end_inset 
24932
24933
24934 \end_inset 
24935 </cell>
24936 </row>
24937 <row topline="true">
24938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24939 \begin_inset Text
24940
24941 \layout Standard
24942
24943 splint
24944 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24945
24946 \end_inset 
24947
24948
24949 \end_inset 
24950 </cell>
24951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24952 \begin_inset Text
24953
24954 \layout Standard
24955
24956 Statically checks c sources (see 
24957 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24958
24959 \end_inset 
24960
24961 )
24962 \end_inset 
24963 </cell>
24964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24965 \begin_inset Text
24966
24967 \layout Standard
24968
24969
24970 \begin_inset LatexCommand \url{http://www.splint.org}
24971
24972 \end_inset 
24973
24974
24975 \end_inset 
24976 </cell>
24977 </row>
24978 <row topline="true" bottomline="true">
24979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24980 \begin_inset Text
24981
24982 \layout Standard
24983
24984 ddd
24985 \begin_inset LatexCommand \index{DDD (debugger)}
24986
24987 \end_inset 
24988
24989
24990 \end_inset 
24991 </cell>
24992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24993 \begin_inset Text
24994
24995 \layout Standard
24996
24997 Debugger, serves nicely as GUI to SDCDB
24998 \begin_inset LatexCommand \index{SDCDB (debugger)}
24999
25000 \end_inset 
25001
25002  (Unix only)
25003 \end_inset 
25004 </cell>
25005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25006 \begin_inset Text
25007
25008 \layout Standard
25009
25010
25011 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
25012
25013 \end_inset 
25014
25015
25016 \end_inset 
25017 </cell>
25018 </row>
25019 </lyxtabular>
25020
25021 \end_inset 
25022
25023
25024 \newline 
25025
25026 \layout Section
25027
25028 Related documentation / recommended reading
25029 \layout Standard
25030 \align left 
25031
25032 \begin_inset  Tabular
25033 <lyxtabular version="3" rows="7" columns="3">
25034 <features>
25035 <column alignment="left" valignment="top" leftline="true" width="0pt">
25036 <column alignment="center" valignment="top" leftline="true" width="0">
25037 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25038 <row topline="true" bottomline="true">
25039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25040 \begin_inset Text
25041
25042 \layout Standard
25043
25044 Name
25045 \end_inset 
25046 </cell>
25047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25048 \begin_inset Text
25049
25050 \layout Standard
25051
25052 Subject / Title
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 Where to get
25061 \end_inset 
25062 </cell>
25063 </row>
25064 <row topline="true">
25065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25066 \begin_inset Text
25067
25068 \layout Standard
25069
25070
25071 \family roman 
25072 \series medium 
25073 \shape up 
25074 \size normal 
25075 \emph off 
25076 \bar no 
25077 \noun off 
25078 \color none
25079 c-refcard.pdf
25080 \end_inset 
25081 </cell>
25082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25083 \begin_inset Text
25084
25085 \layout Standard
25086
25087 C Reference Card
25088 \begin_inset LatexCommand \index{C Reference card}
25089
25090 \end_inset 
25091
25092 , 2 pages
25093 \end_inset 
25094 </cell>
25095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25096 \begin_inset Text
25097
25098 \layout Standard
25099
25100
25101 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25102
25103 \end_inset 
25104
25105
25106 \end_inset 
25107 </cell>
25108 </row>
25109 <row topline="true">
25110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25111 \begin_inset Text
25112
25113 \layout Standard
25114
25115 c-faq
25116 \end_inset 
25117 </cell>
25118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25119 \begin_inset Text
25120
25121 \layout Standard
25122
25123 C-FAQ
25124 \begin_inset LatexCommand \index{C FAQ}
25125
25126 \end_inset 
25127
25128
25129 \end_inset 
25130 </cell>
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25132 \begin_inset Text
25133
25134 \layout Standard
25135
25136
25137 \begin_inset LatexCommand \url{http://www.c-faq.com}
25138
25139 \end_inset 
25140
25141
25142 \end_inset 
25143 </cell>
25144 </row>
25145 <row topline="true">
25146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25147 \begin_inset Text
25148
25149 \layout Standard
25150
25151 ISO/IEC 9899:TC2
25152 \end_inset 
25153 </cell>
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25155 \begin_inset Text
25156
25157 \layout Standard
25158
25159
25160 \begin_inset Quotes sld
25161 \end_inset 
25162
25163 C-Standard
25164 \begin_inset Quotes srd
25165 \end_inset 
25166
25167
25168 \end_inset 
25169 </cell>
25170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25171 \begin_inset Text
25172
25173 \layout Standard
25174
25175
25176 \size footnotesize 
25177
25178 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25179
25180 \end_inset 
25181
25182
25183 \end_inset 
25184 </cell>
25185 </row>
25186 <row topline="true">
25187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25188 \begin_inset Text
25189
25190 \layout Standard
25191
25192 ISO/IEC DTR 18037
25193 \end_inset 
25194 </cell>
25195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25196 \begin_inset Text
25197
25198 \layout Standard
25199
25200
25201 \begin_inset Quotes sld
25202 \end_inset 
25203
25204 Extensions for Embedded C
25205 \begin_inset Quotes srd
25206 \end_inset 
25207
25208
25209 \end_inset 
25210 </cell>
25211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25212 \begin_inset Text
25213
25214 \layout Standard
25215
25216
25217 \size footnotesize 
25218
25219 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25220
25221 \end_inset 
25222
25223
25224 \end_inset 
25225 </cell>
25226 </row>
25227 <row topline="true">
25228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25229 \begin_inset Text
25230
25231 \layout Standard
25232
25233 \end_inset 
25234 </cell>
25235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25236 \begin_inset Text
25237
25238 \layout Standard
25239
25240 Latest datasheet of target CPU
25241 \end_inset 
25242 </cell>
25243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25244 \begin_inset Text
25245
25246 \layout Standard
25247
25248 vendor
25249 \end_inset 
25250 </cell>
25251 </row>
25252 <row topline="true" bottomline="true">
25253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25254 \begin_inset Text
25255
25256 \layout Standard
25257
25258 \end_inset 
25259 </cell>
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25261 \begin_inset Text
25262
25263 \layout Standard
25264
25265 Revision history of datasheet
25266 \end_inset 
25267 </cell>
25268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25269 \begin_inset Text
25270
25271 \layout Standard
25272
25273 vendor
25274 \end_inset 
25275 </cell>
25276 </row>
25277 </lyxtabular>
25278
25279 \end_inset 
25280
25281
25282 \newline 
25283
25284 \layout Section
25285
25286 Application notes specifically for SDCC
25287 \layout Standard
25288
25289 SDCC makes no claims about the completeness of this list and about up-to-datenes
25290 s or correctness of the application notes
25291 \begin_inset LatexCommand \index{Application notes}
25292
25293 \end_inset 
25294
25295 .
25296 \layout Standard
25297 \align left 
25298
25299 \size footnotesize 
25300
25301 \begin_inset  Tabular
25302 <lyxtabular version="3" rows="7" columns="3">
25303 <features>
25304 <column alignment="block" valignment="top" leftline="true" width="17col%">
25305 <column alignment="block" valignment="top" leftline="true" width="27col%">
25306 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25307 <row topline="true" bottomline="true">
25308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25309 \begin_inset Text
25310
25311 \layout Standard
25312
25313
25314 \size footnotesize 
25315 Vendor
25316 \end_inset 
25317 </cell>
25318 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25319 \begin_inset Text
25320
25321 \layout Standard
25322
25323
25324 \size footnotesize 
25325 Subject / Title
25326 \end_inset 
25327 </cell>
25328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25329 \begin_inset Text
25330
25331 \layout Standard
25332
25333
25334 \size footnotesize 
25335 Where to get
25336 \end_inset 
25337 </cell>
25338 </row>
25339 <row topline="true">
25340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25341 \begin_inset Text
25342
25343 \layout Standard
25344
25345
25346 \size footnotesize 
25347 Maxim / Dallas
25348 \end_inset 
25349 </cell>
25350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25351 \begin_inset Text
25352
25353 \layout Standard
25354
25355
25356 \size footnotesize 
25357 Using the SDCC Compiler for the DS80C400
25358 \begin_inset LatexCommand \index{DS80C400}
25359
25360 \end_inset 
25361
25362
25363 \end_inset 
25364 </cell>
25365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25366 \begin_inset Text
25367
25368 \layout Standard
25369
25370
25371 \size footnotesize 
25372
25373 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25374
25375 \end_inset 
25376
25377
25378 \end_inset 
25379 </cell>
25380 </row>
25381 <row topline="true">
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25383 \begin_inset Text
25384
25385 \layout Standard
25386
25387
25388 \size footnotesize 
25389 Maxim / Dallas
25390 \end_inset 
25391 </cell>
25392 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25393 \begin_inset Text
25394
25395 \layout Standard
25396
25397
25398 \size footnotesize 
25399 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25400 \begin_inset LatexCommand \index{DS89C4x0}
25401
25402 \end_inset 
25403
25404  Family of Microcontrollers
25405 \end_inset 
25406 </cell>
25407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25408 \begin_inset Text
25409
25410 \layout Standard
25411
25412
25413 \size footnotesize 
25414
25415 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25416
25417 \end_inset 
25418
25419
25420 \end_inset 
25421 </cell>
25422 </row>
25423 <row topline="true">
25424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25425 \begin_inset Text
25426
25427 \layout Standard
25428
25429
25430 \size footnotesize 
25431 Silicon Laboratories / Cygnal
25432 \end_inset 
25433 </cell>
25434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25435 \begin_inset Text
25436
25437 \layout Standard
25438
25439
25440 \size footnotesize 
25441 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25442 \begin_inset LatexCommand \index{IDE}
25443
25444 \end_inset 
25445
25446
25447 \end_inset 
25448 </cell>
25449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25450 \begin_inset Text
25451
25452 \layout Standard
25453
25454
25455 \size footnotesize 
25456
25457 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25458
25459 \end_inset 
25460
25461
25462 \end_inset 
25463 </cell>
25464 </row>
25465 <row topline="true">
25466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25467 \begin_inset Text
25468
25469 \layout Standard
25470
25471
25472 \size footnotesize 
25473 Ramtron / Goal Semiconductor
25474 \end_inset 
25475 </cell>
25476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25477 \begin_inset Text
25478
25479 \layout Standard
25480
25481
25482 \size footnotesize 
25483 Interfacing SDCC to Syn and Textpad
25484 \end_inset 
25485 </cell>
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25487 \begin_inset Text
25488
25489 \layout Standard
25490
25491
25492 \size footnotesize 
25493
25494 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25495
25496 \end_inset 
25497
25498
25499 \end_inset 
25500 </cell>
25501 </row>
25502 <row topline="true">
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25504 \begin_inset Text
25505
25506 \layout Standard
25507
25508
25509 \size footnotesize 
25510 Ramtron / Goal Semiconductor
25511 \end_inset 
25512 </cell>
25513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25514 \begin_inset Text
25515
25516 \layout Standard
25517
25518
25519 \size footnotesize 
25520 Installing and Configuring SDCC and Crimson Editor 
25521 \end_inset 
25522 </cell>
25523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25524 \begin_inset Text
25525
25526 \layout Standard
25527
25528
25529 \size footnotesize 
25530
25531 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25532
25533 \end_inset 
25534
25535
25536 \end_inset 
25537 </cell>
25538 </row>
25539 <row topline="true" bottomline="true">
25540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25541 \begin_inset Text
25542
25543 \layout Standard
25544
25545
25546 \size footnotesize 
25547 Texas Instruments
25548 \end_inset 
25549 </cell>
25550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25551 \begin_inset Text
25552
25553 \layout Standard
25554
25555
25556 \size footnotesize 
25557 MSC12xx Programming with SDCC
25558 \end_inset 
25559 </cell>
25560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25561 \begin_inset Text
25562
25563 \layout Standard
25564
25565
25566 \size footnotesize 
25567
25568 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25569
25570 \end_inset 
25571
25572
25573 \end_inset 
25574 </cell>
25575 </row>
25576 </lyxtabular>
25577
25578 \end_inset 
25579
25580
25581 \layout Section
25582
25583 Some Questions
25584 \layout Standard
25585
25586 Some questions answered, some pointers given - it might be time to in turn
25587  ask 
25588 \emph on 
25589 you
25590 \emph default 
25591  some questions: 
25592 \layout Itemize
25593
25594 can you solve your project with the selected microcontroller? Would you
25595  find out early or rather late that your target is too small/slow/whatever?
25596  Can you switch to a slightly better device if it doesn't fit?
25597 \layout Itemize
25598
25599 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25600  and/or another programming language be more adequate? Would an operating
25601  system on the target device help?
25602 \layout Itemize
25603
25604 if you solved the problem, will the marketing department be happy?
25605 \layout Itemize
25606
25607 if the marketing department is happy, will customers be happy?
25608 \layout Itemize
25609
25610 if you're the project manager, marketing department and maybe even the customer
25611  in one person, have you tried to see the project from the outside?
25612 \layout Itemize
25613
25614 is the project done if you think it is done? Or is just that other interface/pro
25615 tocol/feature/configuration/option missing? How about website, manual(s),
25616  internationali(z|s)ation, packaging, labels, 2nd source for components,
25617  electromagnetic compatability/interference, documentation for production,
25618  production test software, update mechanism, patent issues?
25619 \layout Itemize
25620
25621 is your project adequately positioned in that magic triangle: fame, fortune,
25622  fun?
25623 \layout Standard
25624
25625 Maybe not all answers to these questions are known and some answers may
25626  even be 
25627 \emph on 
25628 no
25629 \emph default 
25630 , nevertheless knowing these questions may help you to avoid burnout
25631 \begin_inset Foot
25632 collapsed false
25633
25634 \layout Standard
25635
25636 burnout is bad for electronic devices, programmers and motorcycle tyres
25637 \end_inset 
25638
25639 .
25640  Chances are you didn't want to hear some of them...
25641 \layout Chapter
25642
25643 Support
25644 \begin_inset LatexCommand \index{Support}
25645
25646 \end_inset 
25647
25648
25649 \layout Standard
25650
25651 SDCC has grown to be a large project.
25652  The compiler alone (without the preprocessor, assembler and linker) is
25653  well over 150,000 lines of code (blank stripped).
25654  The open source nature of this project is a key to its continued growth
25655  and support.
25656  You gain the benefit and support of many active software developers and
25657  end users.
25658  Is SDCC perfect? No, that's why we need your help.
25659  The developers take pride in fixing reported bugs.
25660  You can help by reporting the bugs and helping other SDCC users.
25661  There are lots of ways to contribute, and we encourage you to take part
25662  in making SDCC a great software package.
25663  
25664 \layout Standard
25665
25666 The SDCC project is hosted on the SDCC sourceforge site at 
25667 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25668
25669 \end_inset 
25670
25671 .
25672  You'll find the complete set of mailing lists
25673 \begin_inset LatexCommand \index{Mailing list(s)}
25674
25675 \end_inset 
25676
25677 , forums, bug reporting system, patch submission
25678 \begin_inset LatexCommand \index{Patch submission}
25679
25680 \end_inset 
25681
25682  system, download
25683 \begin_inset LatexCommand \index{download}
25684
25685 \end_inset 
25686
25687  area and Subversion code repository
25688 \begin_inset LatexCommand \index{Subversion code repository}
25689
25690 \end_inset 
25691
25692  there.
25693 \layout Section
25694
25695 Reporting Bugs
25696 \begin_inset LatexCommand \index{Bug reporting}
25697
25698 \end_inset 
25699
25700
25701 \begin_inset LatexCommand \index{Reporting bugs}
25702
25703 \end_inset 
25704
25705
25706 \layout Standard
25707
25708 The recommended way of reporting bugs is using the infrastructure of the
25709  sourceforge site.
25710  You can follow the status of bug reports there and have an overview about
25711  the known bugs.
25712 \layout Standard
25713
25714 Bug reports are automatically forwarded to the developer mailing list and
25715  will be fixed ASAP.
25716  When reporting a bug, it is very useful to include a small test program
25717  (the smaller the better) which reproduces the problem.
25718  If you can isolate the problem by looking at the generated assembly code,
25719  this can be very helpful.
25720  Compiling your program with the -
25721 \begin_inset ERT
25722 status Collapsed
25723
25724 \layout Standard
25725
25726 \backslash 
25727 /
25728 \end_inset 
25729
25730 -dumpall
25731 \begin_inset LatexCommand \index{-\/-dumpall}
25732
25733 \end_inset 
25734
25735  option can sometimes be useful in locating optimization problems.
25736  When reporting a bug please make sure you:
25737 \layout Enumerate
25738
25739 Attach the code you are compiling with SDCC.
25740  
25741 \layout Enumerate
25742
25743 Specify the exact command you use to run SDCC, or attach your Makefile.
25744  
25745 \layout Enumerate
25746
25747 Specify the SDCC version (type "
25748 \family sans 
25749 \series bold 
25750 sdcc -v
25751 \family default 
25752 \series default 
25753 "), your platform, and operating system.
25754  
25755 \layout Enumerate
25756
25757 Provide an exact copy of any error message or incorrect output.
25758  
25759 \layout Enumerate
25760
25761 Put something meaningful in the subject of your message.
25762 \layout Standard
25763
25764 Please attempt to include these 5 important parts, as applicable, in all
25765  requests for support or when reporting any problems or bugs with SDCC.
25766  Though this will make your message lengthy, it will greatly improve your
25767  chance that SDCC users and developers will be able to help you.
25768  Some SDCC developers are frustrated by bug reports without code provided
25769  that they can use to reproduce and ultimately fix the problem, so please
25770  be sure to provide sample code if you are reporting a bug! 
25771 \layout Standard
25772
25773 Please have a short check that you are using a recent version of SDCC and
25774  the bug is not yet known.
25775  This is the link for reporting bugs: 
25776 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25777
25778 \end_inset 
25779
25780 .
25781  With SDCC on average having more than 200 downloads
25782 \begin_inset LatexCommand \index{download}
25783
25784 \end_inset 
25785
25786  on sourceforge per day
25787 \begin_inset Foot
25788 collapsed false
25789
25790 \layout Standard
25791
25792 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25793  between 2002 and 2005.
25794  This does not include other methods of distribution.
25795 \end_inset 
25796
25797  there must be some users.
25798  So it's not exactly easy to find a new bug.
25799  If you find one we need it: 
25800 \emph on 
25801 reporting bugs is good
25802 \emph default 
25803 .
25804 \layout Section
25805
25806 Requesting Features
25807 \begin_inset LatexCommand \label{sub:Requesting-Features}
25808
25809 \end_inset 
25810
25811
25812 \begin_inset LatexCommand \index{Feature request}
25813
25814 \end_inset 
25815
25816
25817 \begin_inset LatexCommand \index{Requesting features}
25818
25819 \end_inset 
25820
25821
25822 \layout Standard
25823
25824 Like bug reports feature requests are forwarded to the developer mailing
25825  list.
25826  This is the link for requesting features: 
25827 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25828
25829 \end_inset 
25830
25831 .
25832 \layout Section
25833
25834 Submitting patches
25835 \layout Standard
25836
25837 Like bug reports contributed patches are forwarded to the developer mailing
25838  list.
25839  This is the link for submitting patches
25840 \begin_inset LatexCommand \index{Patch submission}
25841
25842 \end_inset 
25843
25844
25845 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25846
25847 \end_inset 
25848
25849 .
25850 \layout Standard
25851
25852 You need to specify some parameters to the 
25853 \family typewriter 
25854 diff
25855 \family default 
25856  command for the patches to be useful.
25857  If you modified more than one file a patch created f.e.
25858  with 
25859 \family sans 
25860 \series bold 
25861
25862 \begin_inset Quotes sld
25863 \end_inset 
25864
25865 diff -Naur unmodified_directory modified_directory >my_changes.patch
25866 \begin_inset Quotes srd
25867 \end_inset 
25868
25869
25870 \family default 
25871 \series default 
25872  will be fine, otherwise 
25873 \family sans 
25874 \series bold 
25875
25876 \begin_inset Quotes sld
25877 \end_inset 
25878
25879 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25880 \begin_inset Quotes srd
25881 \end_inset 
25882
25883
25884 \series default 
25885  
25886 \family default 
25887 will do.
25888 \layout Section
25889
25890 Getting Help
25891 \layout Standard
25892
25893 These links should take you directly to the 
25894 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25895
25896 \end_inset 
25897
25898
25899 \begin_inset Foot
25900 collapsed false
25901
25902 \layout Standard
25903
25904 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25905  automated messages (mid 2003)
25906 \end_inset 
25907
25908  and the 
25909 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25910
25911 \end_inset 
25912
25913 , lists
25914 \begin_inset LatexCommand \index{Mailing list(s)}
25915
25916 \end_inset 
25917
25918  and forums are archived and searchable so if you are lucky someone already
25919  had a similar problem.
25920  While mails to the lists themselves are delivered promptly their web front
25921  end on sourceforge sometimes shows a severe time lag (up to several weeks),
25922  if you're seriously using SDCC please consider subscribing to the lists.
25923 \layout Section
25924
25925 ChangeLog
25926 \layout Standard
25927
25928 You can follow the status of the Subversion version
25929 \begin_inset LatexCommand \index{version}
25930
25931 \end_inset 
25932
25933  of SDCC by watching the Changelog
25934 \begin_inset LatexCommand \index{Changelog}
25935
25936 \end_inset 
25937
25938  in the Subversion repository
25939 \size footnotesize 
25940  
25941 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25942
25943 \end_inset 
25944
25945 .
25946 \layout Section
25947
25948 Subversion Source Code Repository
25949 \layout Standard
25950
25951 The output of 
25952 \family sans 
25953 \series bold 
25954 sdcc --version
25955 \family default 
25956 \series default 
25957  or the filenames of the snapshot versions of SDCC include date and its
25958  Subversion
25959 \begin_inset LatexCommand \index{Subversion code repository}
25960
25961 \end_inset 
25962
25963  number.
25964  Subversion allows to download the source of recent or previous versions
25965  
25966 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25967
25968 \end_inset 
25969
25970  (by number or by date).
25971  An on-line source code browser and detailled instructions are also available
25972  there.
25973  SDCC versions starting from 1999 up to now are available (currently the
25974  versions prior to the conversion from cvs
25975 \begin_inset LatexCommand \index{cvs|see{Subversion}}
25976
25977 \end_inset 
25978
25979  to Subversion (April 2006) are either by accessible by Subversion or by
25980  cvs).
25981 \layout Section
25982
25983 Release policy
25984 \begin_inset LatexCommand \index{Release policy}
25985
25986 \end_inset 
25987
25988
25989 \layout Standard
25990
25991 Historically there often were long delays between official releases and
25992  the sourceforge download area tends to get not updated at all.
25993  Excuses in the past might have referred to problems with live range analysis,
25994  but as this was fixed a while ago, the current problem is that another
25995  excuse has to be found.
25996  Kidding aside, we have to get better there! On the other hand there are
25997  daily snapshots available at 
25998 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
25999
26000 \end_inset 
26001
26002 , and you can always build the very last version (hopefully with many bugs
26003  fixed, and features added) from the source code available at 
26004 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
26005
26006 \end_inset 
26007
26008 .
26009 \layout Section
26010
26011 Examples
26012 \begin_inset LatexCommand \index{Examples}
26013
26014 \end_inset 
26015
26016
26017 \layout Standard
26018
26019 You'll find some small examples in the directory 
26020 \emph on 
26021 sdcc/device/examples/.
26022  
26023 \emph default 
26024 More examples and libraries are available at
26025 \emph on 
26026  The SDCC Open Knowledge Resource 
26027 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
26028
26029 \end_inset 
26030
26031  
26032 \emph default 
26033 web site or at 
26034 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
26035
26036 \end_inset 
26037
26038 .
26039 \layout Comment
26040
26041 I did insert a reference to Paul's web site here although it seems rather
26042  dedicated to a specific 8032 board (I think it's okay because it f.e.
26043  shows LCD/Harddisc interface and has a free 8051 monitor.
26044  Independent 8032 board vendors face hard competition of heavily subsidized
26045  development boards anyway).
26046 \layout Comment
26047
26048 Maybe we should include some links to real world applications.
26049  Preferably pointer to pointers (one for each architecture) so this stays
26050  manageable here?
26051 \layout Section
26052
26053 Quality control
26054 \begin_inset LatexCommand \label{sec:Quality-control}
26055
26056 \end_inset 
26057
26058
26059 \begin_inset LatexCommand \index{Quality control}
26060
26061 \end_inset 
26062
26063
26064 \layout Standard
26065
26066 The compiler is passed through nightly compile and build checks.
26067  The so called 
26068 \shape italic 
26069 regression tests
26070 \shape default 
26071
26072 \begin_inset LatexCommand \index{Regression test}
26073
26074 \end_inset 
26075
26076  check that SDCC itself compiles flawlessly on several host platforms (i386,
26077  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26078  the quality of the code generated by SDCC by running the code for several
26079  target platforms through simulators.
26080  The regression test suite comprises more than 100 files which expand to
26081  more than 500 test cases which include more than 4500 tests.
26082  The results of these tests are published daily on SDCC's snapshot page
26083  (click on the red or green symbols on the right side of 
26084 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26085
26086 \end_inset 
26087
26088 ).
26089 \layout Standard
26090
26091 There is a separate document 
26092 \shape italic 
26093 test_suite.pdf 
26094 \begin_inset LatexCommand \index{Test suite}
26095
26096 \end_inset 
26097
26098
26099 \shape default 
26100  
26101 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26102
26103 \end_inset 
26104
26105  about the regression test suite.
26106 \layout Standard
26107
26108 You'll find the test code in the directory 
26109 \shape italic 
26110 sdcc/support/regression
26111 \shape default 
26112 .
26113  You can run these tests manually by running 
26114 \family sans 
26115 make
26116 \family default 
26117  in this directory (or f.e.
26118  
26119 \family sans 
26120 \series bold 
26121
26122 \begin_inset Quotes sld
26123 \end_inset 
26124
26125 make test-mcs51
26126 \begin_inset Quotes srd
26127 \end_inset 
26128
26129
26130 \family default 
26131 \series default 
26132  if you don't want to run the complete tests).
26133  The test code might also be interesting if you want to look for examples
26134 \begin_inset LatexCommand \index{Examples}
26135
26136 \end_inset 
26137
26138  checking corner cases of SDCC or if you plan to submit patches
26139 \begin_inset LatexCommand \index{Patch submission}
26140
26141 \end_inset 
26142
26143 .
26144 \layout Standard
26145
26146 The 14bit pic port uses a different set of regression tests 
26147 \begin_inset LatexCommand \index{Regression test (PIC14)}
26148
26149 \end_inset 
26150
26151 , you'll find them in the directory 
26152 \shape italic 
26153 sdcc/src/regression
26154 \shape default 
26155 .
26156 \layout Section
26157
26158 Use of SDCC in Education
26159 \layout Standard
26160
26161 In short: 
26162 \emph on 
26163 highly
26164 \emph default 
26165  encouraged
26166 \begin_inset Foot
26167 collapsed false
26168
26169 \layout Standard
26170
26171 the phrase "use in education" might evoke the association "
26172 \emph on 
26173 only
26174 \emph default 
26175  fit for use in education".
26176  This connotation is not intended but nevertheless risked as the licensing
26177  of SDCC makes it difficult to offer educational discounts
26178 \end_inset 
26179
26180 .
26181  If your rationales are to:
26182 \layout Enumerate
26183
26184 give students a chance to understand the 
26185 \emph on 
26186 complete
26187 \emph default 
26188  steps of code generation
26189 \layout Enumerate
26190
26191 have a curriculum that can be extended for years.
26192  Then you could use an fpga board as target and your curriculum will seamlessly
26193  extend from logic synthesis (
26194 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26195
26196 \end_inset 
26197
26198
26199 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26200
26201 \end_inset 
26202
26203 ), over assembly programming, to C to FPGA compilers (
26204 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26205
26206 \end_inset 
26207
26208 ) and to C.
26209 \layout Enumerate
26210
26211 be able to insert excursions about skills like using a revision control
26212  system, submitting/applying patches, using a type-setting (as opposed to
26213  word-processing) engine LyX/LaTeX, using 
26214 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26215
26216 \end_inset 
26217
26218 , following some 
26219 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26220
26221 \end_inset 
26222
26223 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26224  Source Software, CPU simulation, compiler regression tests
26225 \begin_inset LatexCommand \index{Regression test}
26226
26227 \end_inset 
26228
26229 .
26230  
26231 \newline 
26232 And if there should be a shortage of ideas then you can always point students
26233  to the ever-growing feature request list 
26234 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26235
26236 \end_inset 
26237
26238 .
26239 \layout Enumerate
26240
26241 not tie students to a specific host platform and instead allow them to use
26242  a host platform of 
26243 \emph on 
26244 their
26245 \emph default 
26246  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26247  eventually 
26248 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26249
26250 \end_inset 
26251
26252 )
26253 \layout Enumerate
26254
26255 not encourage students to use illegal copies of educational software
26256 \layout Enumerate
26257
26258 be immune to licensing/availability/price changes of the chosen tool chain
26259 \layout Enumerate
26260
26261 be able to change to a new target platform without having to adopt a new
26262  tool chain
26263 \layout Enumerate
26264
26265 have complete control over and insight into the tool chain
26266 \layout Enumerate
26267
26268 make your students aware about the pros and cons of open source software
26269  development
26270 \layout Enumerate
26271
26272 give back to the public as you are probably at least partially publically
26273  funded
26274 \layout Enumerate
26275
26276 give students a chance to publically prove their skills and to possibly
26277  see a world wide impact
26278 \layout Standard
26279
26280 then SDCC is probably among the first choices.
26281  Well, probably SDCC might be the only choice.
26282 \layout Chapter
26283 \pagebreak_top 
26284 SDCC Technical Data
26285 \layout Section
26286
26287 Optimizations
26288 \begin_inset LatexCommand \index{Optimizations}
26289
26290 \end_inset 
26291
26292
26293 \layout Standard
26294
26295 SDCC performs a host of standard optimizations in addition to some MCU specific
26296  optimizations.
26297  
26298 \layout Subsection
26299
26300 Sub-expression Elimination
26301 \begin_inset LatexCommand \index{Subexpression elimination}
26302
26303 \end_inset 
26304
26305
26306 \layout Standard
26307
26308 The compiler does local and 
26309 \emph on 
26310 g
26311 \emph default 
26312 lobal 
26313 \emph on 
26314 c
26315 \emph default 
26316 ommon 
26317 \emph on 
26318 s
26319 \emph default 
26320 ubexpression 
26321 \emph on 
26322 e
26323 \emph default 
26324 limination, e.g.: 
26325 \layout Verse
26326
26327
26328 \family typewriter 
26329 i = x + y + 1; 
26330 \newline 
26331 j = x + y;
26332 \layout Standard
26333
26334 will be translated to
26335 \layout Verse
26336
26337
26338 \family typewriter 
26339 iTemp = x + y; 
26340 \newline 
26341 i = iTemp + 1; 
26342 \newline 
26343 j = iTemp;
26344 \layout Standard
26345
26346 Some subexpressions are not as obvious as the above example, e.g.:
26347 \layout Verse
26348
26349
26350 \family typewriter 
26351 a->b[i].c = 10; 
26352 \newline 
26353 a->b[i].d = 11;
26354 \layout Standard
26355
26356 In this case the address arithmetic a->b[i] will be computed only once;
26357  the equivalent code in C would be.
26358 \layout Verse
26359
26360
26361 \family typewriter 
26362 iTemp = a->b[i]; 
26363 \newline 
26364 iTemp.c = 10; 
26365 \newline 
26366 iTemp.d = 11;
26367 \layout Standard
26368
26369 The compiler will try to keep these temporary variables in registers.
26370 \layout Subsection
26371
26372 Dead-Code Elimination
26373 \begin_inset LatexCommand \index{Dead-code elimination}
26374
26375 \end_inset 
26376
26377
26378 \layout Verse
26379
26380
26381 \family typewriter 
26382 int global;
26383 \newline 
26384
26385 \newline 
26386 void f () { 
26387 \newline 
26388 \SpecialChar ~
26389 \SpecialChar ~
26390 int i; 
26391 \newline 
26392 \SpecialChar ~
26393 \SpecialChar ~
26394 i = 1; \SpecialChar ~
26395 \SpecialChar ~
26396 \SpecialChar ~
26397 \SpecialChar ~
26398 \SpecialChar ~
26399 /* dead store */ 
26400 \newline 
26401 \SpecialChar ~
26402 \SpecialChar ~
26403 global = 1;\SpecialChar ~
26404 /* dead store */ 
26405 \newline 
26406 \SpecialChar ~
26407 \SpecialChar ~
26408 global = 2; 
26409 \newline 
26410 \SpecialChar ~
26411 \SpecialChar ~
26412 return; 
26413 \newline 
26414 \SpecialChar ~
26415 \SpecialChar ~
26416 global = 3;\SpecialChar ~
26417 /* unreachable */ 
26418 \newline 
26419 }
26420 \layout Standard
26421
26422 will be changed to
26423 \layout Verse
26424
26425
26426 \family typewriter 
26427 int global;
26428 \newline 
26429
26430 \newline 
26431 void f () {
26432 \newline 
26433 \SpecialChar ~
26434 \SpecialChar ~
26435 global = 2; 
26436 \newline 
26437 }
26438 \layout Subsection
26439
26440 Copy-Propagation
26441 \begin_inset LatexCommand \index{Copy propagation}
26442
26443 \end_inset 
26444
26445
26446 \layout Verse
26447
26448
26449 \family typewriter 
26450 int f() { 
26451 \newline 
26452 \SpecialChar ~
26453 \SpecialChar ~
26454 int i, j; 
26455 \newline 
26456 \SpecialChar ~
26457 \SpecialChar ~
26458 i = 10; 
26459 \newline 
26460 \SpecialChar ~
26461 \SpecialChar ~
26462 j = i; 
26463 \newline 
26464 \SpecialChar ~
26465 \SpecialChar ~
26466 return j; 
26467 \newline 
26468 }
26469 \layout Standard
26470
26471 will be changed to 
26472 \layout Verse
26473
26474
26475 \family typewriter 
26476 int f() { 
26477 \newline 
26478 \SpecialChar ~
26479 \SpecialChar ~
26480 int i, j; 
26481 \newline 
26482 \SpecialChar ~
26483 \SpecialChar ~
26484 i = 10; 
26485 \newline 
26486 \SpecialChar ~
26487 \SpecialChar ~
26488 j = 10; 
26489 \newline 
26490 \SpecialChar ~
26491 \SpecialChar ~
26492 return 10; 
26493 \newline 
26494 }
26495 \layout Standard
26496
26497 Note: the dead stores created by this copy propagation will be eliminated
26498  by dead-code elimination.
26499 \layout Subsection
26500
26501 Loop Optimizations
26502 \begin_inset LatexCommand \index{Loop optimization}
26503
26504 \end_inset 
26505
26506
26507 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26508
26509 \end_inset 
26510
26511
26512 \layout Standard
26513
26514 Two types of loop optimizations are done by SDCC 
26515 \emph on 
26516 loop invariant
26517 \emph default 
26518  lifting and
26519 \emph on 
26520  strength reduction
26521 \emph default 
26522  of loop induction variables.
26523  In addition to the strength reduction the optimizer marks the induction
26524  variables and the register allocator tries to keep the induction variables
26525  in registers for the duration of the loop.
26526  Because of this preference of the register allocator
26527 \begin_inset LatexCommand \index{Register allocation}
26528
26529 \end_inset 
26530
26531 , loop induction optimization causes an increase in register pressure, which
26532  may cause unwanted spilling of other temporary variables into the stack
26533 \begin_inset LatexCommand \index{stack}
26534
26535 \end_inset 
26536
26537  / data space.
26538  The compiler will generate a warning message when it is forced to allocate
26539  extra space either on the stack or data space.
26540  If this extra space allocation is undesirable then induction optimization
26541  can be eliminated either for the entire source file (with -
26542 \begin_inset ERT
26543 status Collapsed
26544
26545 \layout Standard
26546
26547 \backslash 
26548 /
26549 \end_inset 
26550
26551 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26552 noinduction
26553 \begin_inset LatexCommand \index{\#pragma noinduction}
26554
26555 \end_inset 
26556
26557 .
26558 \newline 
26559
26560 \newline 
26561 Loop Invariant:
26562 \layout Verse
26563
26564
26565 \family typewriter 
26566 for (i = 0 ; i < 100 ; i ++) 
26567 \newline 
26568 \SpecialChar ~
26569 \SpecialChar ~
26570 \SpecialChar ~
26571 \SpecialChar ~
26572 f += k + l;
26573 \layout Standard
26574
26575 changed to
26576 \layout Verse
26577
26578
26579 \family typewriter 
26580 itemp = k + l; 
26581 \newline 
26582 for (i = 0; i < 100; i++) 
26583 \newline 
26584 \SpecialChar ~
26585 \SpecialChar ~
26586 \SpecialChar ~
26587 \SpecialChar ~
26588 f += itemp;
26589 \layout Standard
26590
26591 As mentioned previously some loop invariants are not as apparent, all static
26592  address computations are also moved out of the loop.
26593 \newline 
26594
26595 \newline 
26596 Strength Reduction
26597 \begin_inset LatexCommand \index{Strength reduction}
26598
26599 \end_inset 
26600
26601 , this optimization substitutes an expression by a cheaper expression:
26602 \layout Verse
26603
26604
26605 \family typewriter 
26606 for (i=0;i < 100; i++)
26607 \newline 
26608 \SpecialChar ~
26609 \SpecialChar ~
26610 \SpecialChar ~
26611 \SpecialChar ~
26612 ar[i*5] = i*3;
26613 \layout Standard
26614
26615 changed to
26616 \layout Verse
26617
26618
26619 \family typewriter 
26620 itemp1 = 0; 
26621 \newline 
26622 itemp2 = 0; 
26623 \newline 
26624 for (i=0;i< 100;i++) { 
26625 \newline 
26626 \SpecialChar ~
26627 \SpecialChar ~
26628 \SpecialChar ~
26629 \SpecialChar ~
26630 ar[itemp1] = itemp2; 
26631 \newline 
26632 \SpecialChar ~
26633 \SpecialChar ~
26634 \SpecialChar ~
26635 \SpecialChar ~
26636 itemp1 += 5; 
26637 \newline 
26638 \SpecialChar ~
26639 \SpecialChar ~
26640 \SpecialChar ~
26641 \SpecialChar ~
26642 itemp2 += 3; 
26643 \newline 
26644 }
26645 \layout Standard
26646
26647 The more expensive multiplication
26648 \begin_inset LatexCommand \index{Multiplication}
26649
26650 \end_inset 
26651
26652  is changed to a less expensive addition.
26653 \layout Subsection
26654
26655 Loop Reversing
26656 \begin_inset LatexCommand \index{Loop reversing}
26657
26658 \end_inset 
26659
26660
26661 \layout Standard
26662
26663 This optimization is done to reduce the overhead of checking loop boundaries
26664  for every iteration.
26665  Some simple loops can be reversed and implemented using a 
26666 \begin_inset Quotes eld
26667 \end_inset 
26668
26669 decrement and jump if not zero
26670 \begin_inset Quotes erd
26671 \end_inset 
26672
26673  instruction.
26674  SDCC checks for the following criterion to determine if a loop is reversible
26675  (note: more sophisticated compilers use data-dependency analysis to make
26676  this determination, SDCC uses a more simple minded analysis).
26677 \layout Itemize
26678
26679 The 'for' loop is of the form 
26680 \newline 
26681
26682 \newline 
26683
26684 \family typewriter 
26685 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26686  += 1])
26687 \newline 
26688 \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692 <for body>
26693 \layout Itemize
26694
26695 The <for body> does not contain 
26696 \begin_inset Quotes eld
26697 \end_inset 
26698
26699 continue
26700 \begin_inset Quotes erd
26701 \end_inset 
26702
26703  or 'break
26704 \begin_inset Quotes erd
26705 \end_inset 
26706
26707 .
26708 \layout Itemize
26709
26710 All goto's are contained within the loop.
26711 \layout Itemize
26712
26713 No function calls within the loop.
26714 \layout Itemize
26715
26716 The loop control variable <sym> is not assigned any value within the loop
26717 \layout Itemize
26718
26719 The loop control variable does NOT participate in any arithmetic operation
26720  within the loop.
26721 \layout Itemize
26722
26723 There are NO switch statements in the loop.
26724 \layout Subsection
26725
26726 Algebraic Simplifications
26727 \layout Standard
26728
26729 SDCC does numerous algebraic simplifications, the following is a small sub-set
26730  of these optimizations.
26731 \layout Verse
26732
26733
26734 \family typewriter 
26735 i = j + 0;\SpecialChar ~
26736 \SpecialChar ~
26737 \SpecialChar ~
26738 \SpecialChar ~
26739  /* changed to: */\SpecialChar ~
26740 \SpecialChar ~
26741 \SpecialChar ~
26742 \SpecialChar ~
26743  i = j; 
26744 \newline 
26745 i /= 2;\SpecialChar ~
26746 \SpecialChar ~
26747 \SpecialChar ~
26748 \SpecialChar ~
26749 \SpecialChar ~
26750 \SpecialChar ~
26751 \SpecialChar ~
26752  /* changed to: */\SpecialChar ~
26753 \SpecialChar ~
26754 \SpecialChar ~
26755 \SpecialChar ~
26756  i >>= 1; 
26757 \newline 
26758 i = j - j;\SpecialChar ~
26759 \SpecialChar ~
26760 \SpecialChar ~
26761 \SpecialChar ~
26762  /* changed to: */\SpecialChar ~
26763 \SpecialChar ~
26764 \SpecialChar ~
26765 \SpecialChar ~
26766  i = 0; 
26767 \newline 
26768 i = j / 1;\SpecialChar ~
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772  /* changed to: */\SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776  i = j;
26777 \layout Standard
26778
26779 Note the subexpressions
26780 \begin_inset LatexCommand \index{Subexpression}
26781
26782 \end_inset 
26783
26784  given above are generally introduced by macro expansions or as a result
26785  of copy/constant propagation.
26786 \layout Subsection
26787
26788 'switch' Statements
26789 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26790
26791 \end_inset 
26792
26793
26794 \begin_inset LatexCommand \index{switch statement}
26795
26796 \end_inset 
26797
26798
26799 \layout Standard
26800
26801 SDCC can optimize switch statements to jump tables
26802 \begin_inset LatexCommand \index{jump tables}
26803
26804 \end_inset 
26805
26806 .
26807  It makes the decision based on an estimate of the generated code size.
26808  SDCC is quite liberal in the requirements for jump table generation: 
26809 \layout Itemize
26810
26811 The labels need not be in order, and the starting number need not be one
26812  or zero, the case labels are in numerical sequence or not too many case
26813  labels are missing.
26814 \begin_deeper 
26815 \layout Verse
26816
26817
26818 \family typewriter 
26819 switch(i) {\SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 \SpecialChar ~
26823 \SpecialChar ~
26824 \SpecialChar ~
26825 \SpecialChar ~
26826 \SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832 \SpecialChar ~
26833 \SpecialChar ~
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840 \SpecialChar ~
26841 \SpecialChar ~
26842 \SpecialChar ~
26843 \SpecialChar ~
26844 \SpecialChar ~
26845 switch (i) { 
26846 \newline 
26847 \SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850 case 4: ...\SpecialChar ~
26851 \SpecialChar ~
26852 \SpecialChar ~
26853 \SpecialChar ~
26854 \SpecialChar ~
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 \SpecialChar ~
26859 \SpecialChar ~
26860 \SpecialChar ~
26861 \SpecialChar ~
26862 \SpecialChar ~
26863 \SpecialChar ~
26864 \SpecialChar ~
26865 \SpecialChar ~
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 \SpecialChar ~
26869 \SpecialChar ~
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 \SpecialChar ~
26873 \SpecialChar ~
26874 \SpecialChar ~
26875 \SpecialChar ~
26876 case 0: ...
26877  
26878 \newline 
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 case 5: ...\SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 \SpecialChar ~
26892 \SpecialChar ~
26893 \SpecialChar ~
26894 \SpecialChar ~
26895 \SpecialChar ~
26896 \SpecialChar ~
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 \SpecialChar ~
26906 \SpecialChar ~
26907 \SpecialChar ~
26908 case 1: ...
26909  
26910 \newline 
26911 \SpecialChar ~
26912 \SpecialChar ~
26913 \SpecialChar ~
26914 case 3: ...\SpecialChar ~
26915 \SpecialChar ~
26916 \SpecialChar ~
26917 \SpecialChar ~
26918 \SpecialChar ~
26919 \SpecialChar ~
26920 \SpecialChar ~
26921 \SpecialChar ~
26922 \SpecialChar ~
26923 \SpecialChar ~
26924 \SpecialChar ~
26925 \SpecialChar ~
26926 \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
26941 \newline 
26942 \SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 case 6: ...\SpecialChar ~
26946 \SpecialChar ~
26947 \SpecialChar ~
26948 \SpecialChar ~
26949 \SpecialChar ~
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953 \SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \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 case 3: ...
26972  
26973 \newline 
26974 \SpecialChar ~
26975 \SpecialChar ~
26976 \SpecialChar ~
26977 case 7: ...\SpecialChar ~
26978 \SpecialChar ~
26979 \SpecialChar ~
26980 \SpecialChar ~
26981 \SpecialChar ~
26982 \SpecialChar ~
26983 \SpecialChar ~
26984 \SpecialChar ~
26985 \SpecialChar ~
26986 \SpecialChar ~
26987 \SpecialChar ~
26988 \SpecialChar ~
26989 \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 case 4: ...
27004  
27005 \newline 
27006 \SpecialChar ~
27007 \SpecialChar ~
27008 \SpecialChar ~
27009 case 8: ...\SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 \SpecialChar ~
27013 \SpecialChar ~
27014 \SpecialChar ~
27015 \SpecialChar ~
27016 \SpecialChar ~
27017 \SpecialChar ~
27018 \SpecialChar ~
27019 \SpecialChar ~
27020 \SpecialChar ~
27021 \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 case 5: ...
27036  
27037 \newline 
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 \SpecialChar ~
27041 case 9: ...\SpecialChar ~
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 \SpecialChar ~
27046 \SpecialChar ~
27047 \SpecialChar ~
27048 \SpecialChar ~
27049 \SpecialChar ~
27050 \SpecialChar ~
27051 \SpecialChar ~
27052 \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 case 6: ...
27068  
27069 \newline 
27070 \SpecialChar ~
27071 \SpecialChar ~
27072 \SpecialChar ~
27073 case 10: ...\SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076 \SpecialChar ~
27077 \SpecialChar ~
27078 \SpecialChar ~
27079 \SpecialChar ~
27080 \SpecialChar ~
27081 \SpecialChar ~
27082 \SpecialChar ~
27083 \SpecialChar ~
27084 \SpecialChar ~
27085 \SpecialChar ~
27086 \SpecialChar ~
27087 \SpecialChar ~
27088 \SpecialChar ~
27089 \SpecialChar ~
27090 \SpecialChar ~
27091 \SpecialChar ~
27092 \SpecialChar ~
27093 \SpecialChar ~
27094 \SpecialChar ~
27095 \SpecialChar ~
27096 \SpecialChar ~
27097 \SpecialChar ~
27098 case 7: ...
27099  
27100 \newline 
27101 \SpecialChar ~
27102 \SpecialChar ~
27103 \SpecialChar ~
27104 case 11: ...\SpecialChar ~
27105 \SpecialChar ~
27106 \SpecialChar ~
27107 \SpecialChar ~
27108 \SpecialChar ~
27109 \SpecialChar ~
27110 \SpecialChar ~
27111 \SpecialChar ~
27112 \SpecialChar ~
27113 \SpecialChar ~
27114 \SpecialChar ~
27115 \SpecialChar ~
27116 \SpecialChar ~
27117 \SpecialChar ~
27118 \SpecialChar ~
27119 \SpecialChar ~
27120 \SpecialChar ~
27121 \SpecialChar ~
27122 \SpecialChar ~
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 \SpecialChar ~
27126 \SpecialChar ~
27127 \SpecialChar ~
27128 \SpecialChar ~
27129 case 8: ...
27130  
27131 \newline 
27132 }\SpecialChar ~
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 \SpecialChar ~
27138 \SpecialChar ~
27139 \SpecialChar ~
27140 \SpecialChar ~
27141 \SpecialChar ~
27142 \SpecialChar ~
27143 \SpecialChar ~
27144 \SpecialChar ~
27145 \SpecialChar ~
27146 \SpecialChar ~
27147 \SpecialChar ~
27148 \SpecialChar ~
27149 \SpecialChar ~
27150 \SpecialChar ~
27151 \SpecialChar ~
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 \SpecialChar ~
27155 \SpecialChar ~
27156 \SpecialChar ~
27157 \SpecialChar ~
27158 \SpecialChar ~
27159 \SpecialChar ~
27160 \SpecialChar ~
27161 \SpecialChar ~
27162 \SpecialChar ~
27163 \SpecialChar ~
27164 \SpecialChar ~
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 \SpecialChar ~
27168 }
27169 \layout Standard
27170
27171 Both the above switch statements will be implemented using a jump-table.
27172  The example to the right side is slightly more efficient as the check for
27173  the lower boundary of the jump-table is not needed.
27174 \end_deeper 
27175 \layout Itemize
27176
27177 The number of case labels is not larger than supported by the target architectur
27178 e.
27179 \layout Itemize
27180
27181 If the case labels are not in numerical sequence ('gaps' between cases)
27182  SDCC checks whether a jump table with additionally inserted dummy cases
27183  is still attractive.
27184  
27185 \layout Itemize
27186
27187 If the starting number is not zero and a check for the lower boundary of
27188  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27189  ...
27190  .
27191 \layout Standard
27192
27193 Switch statements which have large gaps in the numeric sequence or those
27194  that have too many case labels can be split into more than one switch statement
27195  for efficient code generation, e.g.:
27196 \layout Verse
27197
27198
27199 \family typewriter 
27200 switch (i) { 
27201 \newline 
27202 \SpecialChar ~
27203 \SpecialChar ~
27204 case 1: ...
27205  
27206 \newline 
27207 \SpecialChar ~
27208 \SpecialChar ~
27209 case 2: ...
27210  
27211 \newline 
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 case 3: ...
27215  
27216 \newline 
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 case 4: ...
27220  
27221 \newline 
27222 \SpecialChar ~
27223 \SpecialChar ~
27224 case 5: ...
27225  
27226 \newline 
27227 \SpecialChar ~
27228 \SpecialChar ~
27229 case 6: ...
27230  
27231 \newline 
27232 \SpecialChar ~
27233 \SpecialChar ~
27234 case 7: ...
27235  
27236 \newline 
27237 \SpecialChar ~
27238 \SpecialChar ~
27239 case 101: ...
27240  
27241 \newline 
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 case 102: ...
27245  
27246 \newline 
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 case 103: ...
27250  
27251 \newline 
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 case 104: ...
27255  
27256 \newline 
27257 \SpecialChar ~
27258 \SpecialChar ~
27259 case 105: ...
27260  
27261 \newline 
27262 \SpecialChar ~
27263 \SpecialChar ~
27264 case 106: ...
27265  
27266 \newline 
27267 \SpecialChar ~
27268 \SpecialChar ~
27269 case 107: ...
27270  
27271 \newline 
27272 }
27273 \layout Standard
27274
27275 If the above switch statement is broken down into two switch statements
27276 \layout Verse
27277
27278
27279 \family typewriter 
27280 switch (i) { 
27281 \newline 
27282 \SpecialChar ~
27283 \SpecialChar ~
27284 case 1: ...
27285  
27286 \newline 
27287 \SpecialChar ~
27288 \SpecialChar ~
27289 case 2: ...
27290  
27291 \newline 
27292 \SpecialChar ~
27293 \SpecialChar ~
27294 case 3: ...
27295  
27296 \newline 
27297 \SpecialChar ~
27298 \SpecialChar ~
27299 case 4: ...
27300  
27301 \newline 
27302 \SpecialChar ~
27303 \SpecialChar ~
27304 case 5: ...
27305  
27306 \newline 
27307 \SpecialChar ~
27308 \SpecialChar ~
27309 case 6: ...
27310  
27311 \newline 
27312 \SpecialChar ~
27313 \SpecialChar ~
27314 case 7: ...
27315  
27316 \newline 
27317 }
27318 \layout Standard
27319
27320 and
27321 \layout Verse
27322
27323
27324 \family typewriter 
27325 switch (i) { 
27326 \newline 
27327 \SpecialChar ~
27328 \SpecialChar ~
27329 case 101: ...
27330  
27331 \newline 
27332 \SpecialChar ~
27333 \SpecialChar ~
27334 case 102: ...
27335  
27336 \newline 
27337 \SpecialChar ~
27338 \SpecialChar ~
27339 case 103: ...
27340  
27341 \newline 
27342 \SpecialChar ~
27343 \SpecialChar ~
27344 case 104: ...
27345  
27346 \newline 
27347 \SpecialChar ~
27348 \SpecialChar ~
27349 case 105: ...
27350  
27351 \newline 
27352 \SpecialChar ~
27353 \SpecialChar ~
27354 case 106: ...
27355  
27356 \newline 
27357 \SpecialChar ~
27358 \SpecialChar ~
27359 case 107: ...
27360  
27361 \newline 
27362 }
27363 \layout Standard
27364
27365 then both the switch statements will be implemented using jump-tables whereas
27366  the unmodified switch statement will not be.
27367 \layout Comment
27368
27369 There might be reasons which SDCC cannot know about to either favour or
27370  not favour jump tables.
27371  If the target system has to be as quick for the last switch case as for
27372  the first (pro jump table), or if the switch argument is known to be zero
27373  in the majority of the cases (contra jump table).
27374 \layout Standard
27375
27376 The pragma nojtbound
27377 \begin_inset LatexCommand \index{\#pragma nojtbound}
27378
27379 \end_inset 
27380
27381  can be used to turn off checking the 
27382 \emph on 
27383 j
27384 \emph default 
27385 ump 
27386 \emph on 
27387 t
27388 \emph default 
27389 able 
27390 \emph on 
27391 bound
27392 \emph default 
27393 aries.
27394  It has no effect if a default label is supplied.
27395  Use of this pragma is dangerous: if the switch
27396 \begin_inset LatexCommand \index{switch statement}
27397
27398 \end_inset 
27399
27400  argument is not matched by a case statement the processor will happily
27401  jump into Nirvana.
27402 \layout Subsection
27403
27404 Bit-shifting Operations
27405 \begin_inset LatexCommand \index{Bit shifting}
27406
27407 \end_inset 
27408
27409 .
27410 \layout Standard
27411
27412 Bit shifting is one of the most frequently used operation in embedded programmin
27413 g.
27414  SDCC tries to implement bit-shift operations in the most efficient way
27415  possible, e.g.:
27416 \layout Verse
27417
27418
27419 \family typewriter 
27420 unsigned char i;
27421 \newline 
27422 ...
27423  
27424 \newline 
27425 i >>= 4; 
27426 \newline 
27427 ...
27428 \layout Standard
27429
27430 generates the following code:
27431 \layout Verse
27432
27433
27434 \family typewriter 
27435 mov\SpecialChar ~
27436  a,_i 
27437 \newline 
27438 swap a 
27439 \newline 
27440 anl\SpecialChar ~
27441  a,#0x0f 
27442 \newline 
27443 mov\SpecialChar ~
27444  _i,a
27445 \layout Standard
27446
27447 In general SDCC will never setup a loop if the shift count is known.
27448  Another example:
27449 \layout Verse
27450
27451
27452 \family typewriter 
27453 unsigned int i; 
27454 \newline 
27455 ...
27456  
27457 \newline 
27458 i >>= 9; 
27459 \newline 
27460 ...
27461 \layout Standard
27462
27463 will generate:
27464 \layout Verse
27465
27466
27467 \family typewriter 
27468 mov\SpecialChar ~
27469 \SpecialChar ~
27470 a,(_i + 1) 
27471 \newline 
27472 mov\SpecialChar ~
27473 \SpecialChar ~
27474 (_i + 1),#0x00 
27475 \newline 
27476 clr\SpecialChar ~
27477 \SpecialChar ~
27478
27479 \newline 
27480 rrc\SpecialChar ~
27481 \SpecialChar ~
27482
27483 \newline 
27484 mov\SpecialChar ~
27485 \SpecialChar ~
27486 _i,a
27487 \layout Subsection
27488
27489 Bit-rotation
27490 \begin_inset LatexCommand \index{Bit rotation}
27491
27492 \end_inset 
27493
27494
27495 \layout Standard
27496
27497 A special case of the bit-shift operation is bit rotation
27498 \begin_inset LatexCommand \index{rotating bits}
27499
27500 \end_inset 
27501
27502 , SDCC recognizes the following expression to be a left bit-rotation:
27503 \layout Verse
27504
27505
27506 \family typewriter 
27507 \series bold 
27508 unsigned
27509 \series default 
27510 \SpecialChar ~
27511 \SpecialChar ~
27512 char i;\SpecialChar ~
27513 \SpecialChar ~
27514 \SpecialChar ~
27515 \SpecialChar ~
27516 \SpecialChar ~
27517 \SpecialChar ~
27518 \SpecialChar ~
27519 \SpecialChar ~
27520 \SpecialChar ~
27521 \SpecialChar ~
27522 \SpecialChar ~
27523 /* unsigned is needed for rotation */ 
27524 \newline 
27525 ...
27526  
27527 \newline 
27528 i = ((i << 1) | (i >> 7)); 
27529 \family default 
27530
27531 \newline 
27532
27533 \family typewriter 
27534 ...
27535 \layout Standard
27536
27537 will generate the following code:
27538 \layout Verse
27539
27540
27541 \family typewriter 
27542 mov\SpecialChar ~
27543 \SpecialChar ~
27544 a,_i 
27545 \newline 
27546 rl\SpecialChar ~
27547 \SpecialChar ~
27548 \SpecialChar ~
27549
27550 \newline 
27551 mov\SpecialChar ~
27552 \SpecialChar ~
27553 _i,a
27554 \layout Standard
27555
27556 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27557 ns of this case will also be recognized as bit-rotation, i.e.: 
27558 \layout Verse
27559
27560
27561 \family typewriter 
27562 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27563 \layout Subsection
27564
27565 Nibble and Byte Swapping
27566 \layout Standard
27567
27568 Other special cases of the bit-shift operations are nibble or byte swapping
27569 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27570
27571 \end_inset 
27572
27573 , SDCC recognizes the following expressions:
27574 \layout Verse
27575
27576
27577 \family typewriter 
27578 \series bold 
27579 unsigned
27580 \series default 
27581 \SpecialChar ~
27582 \SpecialChar ~
27583 char i; 
27584 \newline 
27585
27586 \series bold 
27587 unsigned
27588 \series default 
27589 \SpecialChar ~
27590 \SpecialChar ~
27591 int j; 
27592 \newline 
27593 ...
27594  
27595 \newline 
27596 i = ((i << 4) | (i >> 4)); 
27597 \family default 
27598
27599 \newline 
27600
27601 \family typewriter 
27602 j = ((j << 8) | (j >> 8)); 
27603 \layout Standard
27604
27605 and generates a swap instruction for the nibble swapping
27606 \begin_inset LatexCommand \index{Nibble swapping}
27607
27608 \end_inset 
27609
27610  or move instructions for the byte swapping
27611 \begin_inset LatexCommand \index{Byte swapping}
27612
27613 \end_inset 
27614
27615 .
27616  The 
27617 \begin_inset Quotes sld
27618 \end_inset 
27619
27620 j
27621 \begin_inset Quotes srd
27622 \end_inset 
27623
27624  example can be used to convert from little to big-endian or vice versa.
27625  If you want to change the endianness of a 
27626 \emph on 
27627 signed
27628 \emph default 
27629  integer you have to cast to 
27630 \family typewriter 
27631 (unsigned int)
27632 \family default 
27633  first.
27634 \layout Standard
27635
27636 Note that SDCC stores numbers in little-endian
27637 \begin_inset Foot
27638 collapsed false
27639
27640 \layout Standard
27641
27642 Usually 8-bit processors don't care much about endianness.
27643  This is not the case for the standard 8051 which only has an instruction
27644  to increment its 
27645 \emph on 
27646 dptr
27647 \emph default 
27648
27649 \begin_inset LatexCommand \index{DPTR}
27650
27651 \end_inset 
27652
27653 -datapointer
27654 \emph on 
27655  
27656 \emph default 
27657 so little-endian is the more efficient byte order.
27658 \end_inset 
27659
27660
27661 \begin_inset LatexCommand \index{little-endian}
27662
27663 \end_inset 
27664
27665
27666 \begin_inset LatexCommand \index{Endianness}
27667
27668 \end_inset 
27669
27670  format (i.e.
27671  lowest order first).
27672 \layout Subsection
27673
27674 Highest Order Bit
27675 \begin_inset LatexCommand \index{Highest Order Bit}
27676
27677 \end_inset 
27678
27679  / Any Order Bit
27680 \begin_inset LatexCommand \index{Any Order Bit}
27681
27682 \end_inset 
27683
27684
27685 \layout Standard
27686
27687 It is frequently required to obtain the highest order bit of an integral
27688  type (long, int, short or char types).
27689  Also obtaining any other order bit is not uncommon.
27690  SDCC recognizes the following expressions to yield the highest order bit
27691  and generates optimized code for it, e.g.:
27692 \layout Verse
27693
27694
27695 \family typewriter 
27696 unsigned int gint; 
27697 \newline 
27698
27699 \newline 
27700 foo () { 
27701 \newline 
27702 \SpecialChar ~
27703 \SpecialChar ~
27704 unsigned char hob1, aob1; 
27705 \newline 
27706 \SpecialChar ~
27707 \SpecialChar ~
27708 bit hob2, hob3, aob2, aob3; 
27709 \newline 
27710 \SpecialChar ~
27711 \SpecialChar ~
27712 ...
27713  
27714 \newline 
27715 \SpecialChar ~
27716 \SpecialChar ~
27717 hob1 = (gint >> 15) & 1; 
27718 \newline 
27719 \SpecialChar ~
27720 \SpecialChar ~
27721 hob2 = (gint >> 15) & 1; 
27722 \newline 
27723 \SpecialChar ~
27724 \SpecialChar ~
27725 hob3 = gint & 0x8000; 
27726 \newline 
27727 \SpecialChar ~
27728 \SpecialChar ~
27729 aob1 = (gint >> 9) & 1; 
27730 \newline 
27731 \SpecialChar ~
27732 \SpecialChar ~
27733 aob2 = (gint >> 8) & 1; 
27734 \newline 
27735 \SpecialChar ~
27736 \SpecialChar ~
27737 aob3 = gint & 0x0800; 
27738 \newline 
27739 \SpecialChar ~
27740 \SpecialChar ~
27741 ..
27742  
27743 \newline 
27744 }
27745 \layout Standard
27746
27747 will generate the following code:
27748 \layout Verse
27749
27750
27751 \family typewriter 
27752 \SpecialChar ~
27753 \SpecialChar ~
27754 \SpecialChar ~
27755 \SpecialChar ~
27756 \SpecialChar ~
27757 \SpecialChar ~
27758 \SpecialChar ~
27759 \SpecialChar ~
27760 \SpecialChar ~
27761 \SpecialChar ~
27762 \SpecialChar ~
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 \SpecialChar ~
27766 \SpecialChar ~
27767 \SpecialChar ~
27768 \SpecialChar ~
27769 \SpecialChar ~
27770 \SpecialChar ~
27771 \SpecialChar ~
27772 \SpecialChar ~
27773 \SpecialChar ~
27774 \SpecialChar ~
27775 \SpecialChar ~
27776 \SpecialChar ~
27777  61 ;\SpecialChar ~
27778  hob.c 7 
27779 \newline 
27780 000A E5*01\SpecialChar ~
27781 \SpecialChar ~
27782 \SpecialChar ~
27783 \SpecialChar ~
27784 \SpecialChar ~
27785 \SpecialChar ~
27786 \SpecialChar ~
27787 \SpecialChar ~
27788 \SpecialChar ~
27789 \SpecialChar ~
27790 \SpecialChar ~
27791 \SpecialChar ~
27792 \SpecialChar ~
27793 \SpecialChar ~
27794 \SpecialChar ~
27795  62\SpecialChar ~
27796 \SpecialChar ~
27797 \SpecialChar ~
27798 \SpecialChar ~
27799 \SpecialChar ~
27800 \SpecialChar ~
27801 \SpecialChar ~
27802 \SpecialChar ~
27803  mov\SpecialChar ~
27804 \SpecialChar ~
27805  a,(_gint + 1) 
27806 \newline 
27807 000C 23\SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 \SpecialChar ~
27812 \SpecialChar ~
27813 \SpecialChar ~
27814 \SpecialChar ~
27815 \SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818 \SpecialChar ~
27819 \SpecialChar ~
27820 \SpecialChar ~
27821 \SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825  63\SpecialChar ~
27826 \SpecialChar ~
27827 \SpecialChar ~
27828 \SpecialChar ~
27829 \SpecialChar ~
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833  rl\SpecialChar ~
27834 \SpecialChar ~
27835 \SpecialChar ~
27836  a 
27837 \newline 
27838 000D 54 01\SpecialChar ~
27839 \SpecialChar ~
27840 \SpecialChar ~
27841 \SpecialChar ~
27842 \SpecialChar ~
27843 \SpecialChar ~
27844 \SpecialChar ~
27845 \SpecialChar ~
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 \SpecialChar ~
27849 \SpecialChar ~
27850 \SpecialChar ~
27851 \SpecialChar ~
27852 \SpecialChar ~
27853  64\SpecialChar ~
27854 \SpecialChar ~
27855 \SpecialChar ~
27856 \SpecialChar ~
27857 \SpecialChar ~
27858 \SpecialChar ~
27859 \SpecialChar ~
27860 \SpecialChar ~
27861  anl\SpecialChar ~
27862 \SpecialChar ~
27863  a,#0x01 
27864 \newline 
27865 000F F5*02\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  65\SpecialChar ~
27881 \SpecialChar ~
27882 \SpecialChar ~
27883 \SpecialChar ~
27884 \SpecialChar ~
27885 \SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888  mov\SpecialChar ~
27889 \SpecialChar ~
27890  _foo_hob1_1_1,a 
27891 \newline 
27892 \SpecialChar ~
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 \SpecialChar ~
27909 \SpecialChar ~
27910 \SpecialChar ~
27911 \SpecialChar ~
27912 \SpecialChar ~
27913 \SpecialChar ~
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917  66 ;\SpecialChar ~
27918  hob.c 8 
27919 \newline 
27920 0011 E5*01\SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925 \SpecialChar ~
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935  67\SpecialChar ~
27936 \SpecialChar ~
27937 \SpecialChar ~
27938 \SpecialChar ~
27939 \SpecialChar ~
27940 \SpecialChar ~
27941 \SpecialChar ~
27942 \SpecialChar ~
27943  mov\SpecialChar ~
27944 \SpecialChar ~
27945  a,(_gint + 1) 
27946 \newline 
27947 0013 33\SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950 \SpecialChar ~
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955 \SpecialChar ~
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960 \SpecialChar ~
27961 \SpecialChar ~
27962 \SpecialChar ~
27963 \SpecialChar ~
27964 \SpecialChar ~
27965  68\SpecialChar ~
27966 \SpecialChar ~
27967 \SpecialChar ~
27968 \SpecialChar ~
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 \SpecialChar ~
27972 \SpecialChar ~
27973  rlc\SpecialChar ~
27974 \SpecialChar ~
27975  a 
27976 \newline 
27977 0014 92*00\SpecialChar ~
27978 \SpecialChar ~
27979 \SpecialChar ~
27980 \SpecialChar ~
27981 \SpecialChar ~
27982 \SpecialChar ~
27983 \SpecialChar ~
27984 \SpecialChar ~
27985 \SpecialChar ~
27986 \SpecialChar ~
27987 \SpecialChar ~
27988 \SpecialChar ~
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992  69\SpecialChar ~
27993 \SpecialChar ~
27994 \SpecialChar ~
27995 \SpecialChar ~
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000  mov\SpecialChar ~
28001 \SpecialChar ~
28002  _foo_hob2_1_1,c 
28003 \newline 
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 \SpecialChar ~
28025 \SpecialChar ~
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 \SpecialChar ~
28029  66 ;\SpecialChar ~
28030  hob.c 9 
28031 \newline 
28032 0016 E5*01\SpecialChar ~
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 \SpecialChar ~
28036 \SpecialChar ~
28037 \SpecialChar ~
28038 \SpecialChar ~
28039 \SpecialChar ~
28040 \SpecialChar ~
28041 \SpecialChar ~
28042 \SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045 \SpecialChar ~
28046 \SpecialChar ~
28047  67\SpecialChar ~
28048 \SpecialChar ~
28049 \SpecialChar ~
28050 \SpecialChar ~
28051 \SpecialChar ~
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 \SpecialChar ~
28055  mov\SpecialChar ~
28056 \SpecialChar ~
28057  a,(_gint + 1) 
28058 \newline 
28059 0018 33\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 \SpecialChar ~
28073 \SpecialChar ~
28074 \SpecialChar ~
28075 \SpecialChar ~
28076 \SpecialChar ~
28077  68\SpecialChar ~
28078 \SpecialChar ~
28079 \SpecialChar ~
28080 \SpecialChar ~
28081 \SpecialChar ~
28082 \SpecialChar ~
28083 \SpecialChar ~
28084 \SpecialChar ~
28085  rlc\SpecialChar ~
28086 \SpecialChar ~
28087  a 
28088 \newline 
28089 0019 92*01\SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 \SpecialChar ~
28099 \SpecialChar ~
28100 \SpecialChar ~
28101 \SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104  69\SpecialChar ~
28105 \SpecialChar ~
28106 \SpecialChar ~
28107 \SpecialChar ~
28108 \SpecialChar ~
28109 \SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112  mov\SpecialChar ~
28113 \SpecialChar ~
28114  _foo_hob3_1_1,c 
28115 \newline 
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 \SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141  70 ;\SpecialChar ~
28142  hob.c 10 
28143 \newline 
28144 001B E5*01\SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147 \SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150 \SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159  71\SpecialChar ~
28160 \SpecialChar ~
28161 \SpecialChar ~
28162 \SpecialChar ~
28163 \SpecialChar ~
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167  mov\SpecialChar ~
28168 \SpecialChar ~
28169  a,(_gint + 1) 
28170 \newline 
28171 001D 03\SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182 \SpecialChar ~
28183 \SpecialChar ~
28184 \SpecialChar ~
28185 \SpecialChar ~
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189  72\SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192 \SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197  rr\SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200  a 
28201 \newline 
28202 001E 54 01\SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211 \SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214 \SpecialChar ~
28215 \SpecialChar ~
28216 \SpecialChar ~
28217  73\SpecialChar ~
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225  anl\SpecialChar ~
28226 \SpecialChar ~
28227  a,#0x01 
28228 \newline 
28229 0020 F5*03\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  74\SpecialChar ~
28245 \SpecialChar ~
28246 \SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249 \SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252  mov\SpecialChar ~
28253 \SpecialChar ~
28254  _foo_aob1_1_1,a 
28255 \newline 
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259 \SpecialChar ~
28260 \SpecialChar ~
28261 \SpecialChar ~
28262 \SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274 \SpecialChar ~
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 \SpecialChar ~
28278 \SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281  75 ;\SpecialChar ~
28282  hob.c 11 
28283 \newline 
28284 0022 E5*01\SpecialChar ~
28285 \SpecialChar ~
28286 \SpecialChar ~
28287 \SpecialChar ~
28288 \SpecialChar ~
28289 \SpecialChar ~
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294 \SpecialChar ~
28295 \SpecialChar ~
28296 \SpecialChar ~
28297 \SpecialChar ~
28298 \SpecialChar ~
28299  76\SpecialChar ~
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 \SpecialChar ~
28303 \SpecialChar ~
28304 \SpecialChar ~
28305 \SpecialChar ~
28306 \SpecialChar ~
28307  mov\SpecialChar ~
28308 \SpecialChar ~
28309  a,(_gint + 1) 
28310 \newline 
28311 0024 13\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 \SpecialChar ~
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329  77\SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337  rrc\SpecialChar ~
28338 \SpecialChar ~
28339  a 
28340 \newline 
28341 0025 92*02\SpecialChar ~
28342 \SpecialChar ~
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 \SpecialChar ~
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 \SpecialChar ~
28353 \SpecialChar ~
28354 \SpecialChar ~
28355 \SpecialChar ~
28356  78\SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 \SpecialChar ~
28362 \SpecialChar ~
28363 \SpecialChar ~
28364  mov\SpecialChar ~
28365 \SpecialChar ~
28366  _foo_aob2_1_1,c 
28367 \newline 
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 \SpecialChar ~
28389 \SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393  79 ;\SpecialChar ~
28394  hob.c 12 
28395 \newline 
28396 0027 E5*01\SpecialChar ~
28397 \SpecialChar ~
28398 \SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410 \SpecialChar ~
28411  80\SpecialChar ~
28412 \SpecialChar ~
28413 \SpecialChar ~
28414 \SpecialChar ~
28415 \SpecialChar ~
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 \SpecialChar ~
28419  mov\SpecialChar ~
28420 \SpecialChar ~
28421  a,(_gint + 1) 
28422 \newline 
28423 0029 A2 E3\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 \SpecialChar ~
28437 \SpecialChar ~
28438  81\SpecialChar ~
28439 \SpecialChar ~
28440 \SpecialChar ~
28441 \SpecialChar ~
28442 \SpecialChar ~
28443 \SpecialChar ~
28444 \SpecialChar ~
28445 \SpecialChar ~
28446  mov\SpecialChar ~
28447 \SpecialChar ~
28448  c,acc[3] 
28449 \newline 
28450 002B 92*03\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 \SpecialChar ~
28464 \SpecialChar ~
28465  82\SpecialChar ~
28466 \SpecialChar ~
28467 \SpecialChar ~
28468 \SpecialChar ~
28469 \SpecialChar ~
28470 \SpecialChar ~
28471 \SpecialChar ~
28472 \SpecialChar ~
28473  mov\SpecialChar ~
28474 \SpecialChar ~
28475  _foo_aob3_1_1,c 
28476 \layout Standard
28477
28478 Other variations of these cases however will 
28479 \emph on 
28480 not
28481 \emph default 
28482  be recognized.
28483  They are standard C expressions, so I heartily recommend these be the only
28484  way to get the highest order bit, (it is portable).
28485  Of course it will be recognized even if it is embedded in other expressions,
28486  e.g.:
28487 \layout Verse
28488
28489
28490 \family typewriter 
28491 xyz = gint + ((gint >> 15) & 1);
28492 \layout Standard
28493
28494 will still be recognized.
28495 \layout Subsection
28496
28497 Higher Order Byte
28498 \begin_inset LatexCommand \index{Higher Order Byte}
28499
28500 \end_inset 
28501
28502  / Higher Order Word
28503 \begin_inset LatexCommand \index{Higher Order Word}
28504
28505 \end_inset 
28506
28507
28508 \layout Standard
28509
28510 It is also frequently required to obtain a higher order byte or word of
28511  a larger integral type (long, int or short types).
28512  SDCC recognizes the following expressions to yield the higher order byte
28513  or word and generates optimized code for it, e.g.:
28514 \layout Verse
28515
28516
28517 \family typewriter 
28518 unsigned int gint; 
28519 \newline 
28520 unsigned long int glong; 
28521 \newline 
28522
28523 \newline 
28524 foo () { 
28525 \newline 
28526 \SpecialChar ~
28527 \SpecialChar ~
28528 unsigned char hob1, hob2; 
28529 \newline 
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 unsigned int how1, how2; 
28533 \newline 
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 ...
28537  
28538 \newline 
28539 \SpecialChar ~
28540 \SpecialChar ~
28541 hob1 = (gint >> 8) & 0xFF; 
28542 \newline 
28543 \SpecialChar ~
28544 \SpecialChar ~
28545 hob2 = glong >> 24; 
28546 \newline 
28547 \SpecialChar ~
28548 \SpecialChar ~
28549 how1 = (glong >> 16) & 0xFFFF; 
28550 \newline 
28551 \SpecialChar ~
28552 \SpecialChar ~
28553 how2 = glong >> 8; 
28554 \newline 
28555 \SpecialChar ~
28556 \SpecialChar ~
28557 ..
28558  
28559 \newline 
28560 }
28561 \layout Standard
28562
28563 will generate the following code:
28564 \layout Verse
28565
28566
28567 \family typewriter 
28568 \SpecialChar ~
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 \SpecialChar ~
28572 \SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580 \SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 \SpecialChar ~
28591 \SpecialChar ~
28592 \SpecialChar ~
28593  91 ;\SpecialChar ~
28594  hob.c 15 
28595 \newline 
28596 0037 85*01*06\SpecialChar ~
28597 \SpecialChar ~
28598 \SpecialChar ~
28599 \SpecialChar ~
28600 \SpecialChar ~
28601 \SpecialChar ~
28602 \SpecialChar ~
28603 \SpecialChar ~
28604 \SpecialChar ~
28605 \SpecialChar ~
28606 \SpecialChar ~
28607 \SpecialChar ~
28608  92\SpecialChar ~
28609 \SpecialChar ~
28610 \SpecialChar ~
28611 \SpecialChar ~
28612 \SpecialChar ~
28613 \SpecialChar ~
28614 \SpecialChar ~
28615 \SpecialChar ~
28616  mov\SpecialChar ~
28617 \SpecialChar ~
28618  _foo_hob1_1_1,(_gint + 1) 
28619 \newline 
28620 \SpecialChar ~
28621 \SpecialChar ~
28622 \SpecialChar ~
28623 \SpecialChar ~
28624 \SpecialChar ~
28625 \SpecialChar ~
28626 \SpecialChar ~
28627 \SpecialChar ~
28628 \SpecialChar ~
28629 \SpecialChar ~
28630 \SpecialChar ~
28631 \SpecialChar ~
28632 \SpecialChar ~
28633 \SpecialChar ~
28634 \SpecialChar ~
28635 \SpecialChar ~
28636 \SpecialChar ~
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 \SpecialChar ~
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 \SpecialChar ~
28644 \SpecialChar ~
28645  93 ;\SpecialChar ~
28646  hob.c 16 
28647 \newline 
28648 003A 85*05*07\SpecialChar ~
28649 \SpecialChar ~
28650 \SpecialChar ~
28651 \SpecialChar ~
28652 \SpecialChar ~
28653 \SpecialChar ~
28654 \SpecialChar ~
28655 \SpecialChar ~
28656 \SpecialChar ~
28657 \SpecialChar ~
28658 \SpecialChar ~
28659 \SpecialChar ~
28660  94\SpecialChar ~
28661 \SpecialChar ~
28662 \SpecialChar ~
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 \SpecialChar ~
28667 \SpecialChar ~
28668  mov\SpecialChar ~
28669 \SpecialChar ~
28670  _foo_hob2_1_1,(_glong + 3) 
28671 \newline 
28672 \SpecialChar ~
28673 \SpecialChar ~
28674 \SpecialChar ~
28675 \SpecialChar ~
28676 \SpecialChar ~
28677 \SpecialChar ~
28678 \SpecialChar ~
28679 \SpecialChar ~
28680 \SpecialChar ~
28681 \SpecialChar ~
28682 \SpecialChar ~
28683 \SpecialChar ~
28684 \SpecialChar ~
28685 \SpecialChar ~
28686 \SpecialChar ~
28687 \SpecialChar ~
28688 \SpecialChar ~
28689 \SpecialChar ~
28690 \SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693 \SpecialChar ~
28694 \SpecialChar ~
28695 \SpecialChar ~
28696 \SpecialChar ~
28697  95 ;\SpecialChar ~
28698  hob.c 17 
28699 \newline 
28700 003D 85*04*08\SpecialChar ~
28701 \SpecialChar ~
28702 \SpecialChar ~
28703 \SpecialChar ~
28704 \SpecialChar ~
28705 \SpecialChar ~
28706 \SpecialChar ~
28707 \SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710 \SpecialChar ~
28711 \SpecialChar ~
28712  96\SpecialChar ~
28713 \SpecialChar ~
28714 \SpecialChar ~
28715 \SpecialChar ~
28716 \SpecialChar ~
28717 \SpecialChar ~
28718 \SpecialChar ~
28719 \SpecialChar ~
28720  mov\SpecialChar ~
28721 \SpecialChar ~
28722  _foo_how1_1_1,(_glong + 2) 
28723 \newline 
28724 0040 85*05*09\SpecialChar ~
28725 \SpecialChar ~
28726 \SpecialChar ~
28727 \SpecialChar ~
28728 \SpecialChar ~
28729 \SpecialChar ~
28730 \SpecialChar ~
28731 \SpecialChar ~
28732 \SpecialChar ~
28733 \SpecialChar ~
28734 \SpecialChar ~
28735 \SpecialChar ~
28736  97\SpecialChar ~
28737 \SpecialChar ~
28738 \SpecialChar ~
28739 \SpecialChar ~
28740 \SpecialChar ~
28741 \SpecialChar ~
28742 \SpecialChar ~
28743 \SpecialChar ~
28744  mov\SpecialChar ~
28745 \SpecialChar ~
28746  (_foo_how1_1_1 + 1),(_glong + 3) 
28747 \newline 
28748 0043 85*03*0A\SpecialChar ~
28749 \SpecialChar ~
28750 \SpecialChar ~
28751 \SpecialChar ~
28752 \SpecialChar ~
28753 \SpecialChar ~
28754 \SpecialChar ~
28755 \SpecialChar ~
28756 \SpecialChar ~
28757 \SpecialChar ~
28758 \SpecialChar ~
28759 \SpecialChar ~
28760  98\SpecialChar ~
28761 \SpecialChar ~
28762 \SpecialChar ~
28763 \SpecialChar ~
28764 \SpecialChar ~
28765 \SpecialChar ~
28766 \SpecialChar ~
28767 \SpecialChar ~
28768  mov\SpecialChar ~
28769 \SpecialChar ~
28770  _foo_how2_1_1,(_glong + 1) 
28771 \newline 
28772 0046 85*04*0B\SpecialChar ~
28773 \SpecialChar ~
28774 \SpecialChar ~
28775 \SpecialChar ~
28776 \SpecialChar ~
28777 \SpecialChar ~
28778 \SpecialChar ~
28779 \SpecialChar ~
28780 \SpecialChar ~
28781 \SpecialChar ~
28782 \SpecialChar ~
28783 \SpecialChar ~
28784  99\SpecialChar ~
28785 \SpecialChar ~
28786 \SpecialChar ~
28787 \SpecialChar ~
28788 \SpecialChar ~
28789 \SpecialChar ~
28790 \SpecialChar ~
28791 \SpecialChar ~
28792  mov\SpecialChar ~
28793 \SpecialChar ~
28794  (_foo_how2_1_1 + 1),(_glong + 2) 
28795 \layout Standard
28796
28797 Again, variations of these cases may 
28798 \emph on 
28799 not
28800 \emph default 
28801  be recognized.
28802  They are standard C expressions, so I heartily recommend these be the only
28803  way to get the higher order byte/word, (it is portable).
28804  Of course it will be recognized even if it is embedded in other expressions,
28805  e.g.:
28806 \layout Verse
28807
28808
28809 \family typewriter 
28810 xyz = gint + ((gint >> 8) & 0xFF);
28811 \layout Standard
28812
28813 will still be recognized.
28814 \layout Subsection
28815
28816 Peephole Optimizer
28817 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28818
28819 \end_inset 
28820
28821
28822 \begin_inset LatexCommand \index{Peephole optimizer}
28823
28824 \end_inset 
28825
28826
28827 \layout Standard
28828
28829 The compiler uses a rule based, pattern matching and re-writing mechanism
28830  for peep-hole optimization.
28831  It is inspired by 
28832 \emph on 
28833 copt
28834 \emph default 
28835  a peep-hole optimizer by Christopher W.
28836  Fraser (cwfraser\SpecialChar ~
28837 @\SpecialChar ~
28838 microsoft.com).
28839  A default set of rules are compiled into the compiler, additional rules
28840  may be added with the 
28841 \emph on 
28842 -
28843 \begin_inset ERT
28844 status Collapsed
28845
28846 \layout Standard
28847
28848 \backslash 
28849 /
28850 \end_inset 
28851
28852 -peep-file
28853 \begin_inset LatexCommand \index{-\/-peep-file}
28854
28855 \end_inset 
28856
28857  <filename>
28858 \emph default 
28859  option.
28860  The rule language is best illustrated with examples.
28861 \layout Verse
28862
28863
28864 \family typewriter 
28865 replace { 
28866 \newline 
28867 \SpecialChar ~
28868 \SpecialChar ~
28869 mov %1,a 
28870 \newline 
28871 \SpecialChar ~
28872 \SpecialChar ~
28873 mov a,%1
28874 \newline 
28875 } by {
28876 \newline 
28877 \SpecialChar ~
28878 \SpecialChar ~
28879 mov %1,a
28880 \newline 
28881 }
28882 \layout Standard
28883
28884 The above rule will change the following assembly
28885 \begin_inset LatexCommand \index{Assembler routines}
28886
28887 \end_inset 
28888
28889  sequence:
28890 \layout Verse
28891
28892
28893 \family typewriter 
28894 mov r1,a 
28895 \newline 
28896 mov a,r1
28897 \layout Standard
28898
28899 to
28900 \layout Verse
28901
28902
28903 \family typewriter 
28904 mov r1,a
28905 \layout Standard
28906
28907 Note: All occurrences of a 
28908 \emph on 
28909 %n
28910 \emph default 
28911  (pattern variable) must denote the same string.
28912  With the above rule, the assembly sequence:
28913 \layout Verse
28914
28915
28916 \family typewriter 
28917 mov r1,a 
28918 \newline 
28919 mov a,r2
28920 \layout Standard
28921
28922 will remain unmodified.
28923 \newline 
28924
28925 \newline 
28926 Other special case optimizations may be added by the user (via 
28927 \emph on 
28928 -
28929 \begin_inset ERT
28930 status Collapsed
28931
28932 \layout Standard
28933
28934 \backslash 
28935 /
28936 \end_inset 
28937
28938 -peep-file option
28939 \emph default 
28940 ).
28941  E.g.
28942  some variants of the 8051 MCU
28943 \begin_inset LatexCommand \index{MCS51 variants}
28944
28945 \end_inset 
28946
28947  allow only 
28948 \family typewriter 
28949 ajmp
28950 \family default 
28951  and 
28952 \family typewriter 
28953 acall
28954 \family default 
28955 .
28956  The following two rules will change all 
28957 \family typewriter 
28958 ljmp
28959 \family default 
28960  and 
28961 \family typewriter 
28962 lcall
28963 \family default 
28964  to 
28965 \family typewriter 
28966 ajmp
28967 \family default 
28968  and 
28969 \family typewriter 
28970 acall
28971 \layout Verse
28972
28973
28974 \family typewriter 
28975 replace { lcall %1 } by { acall %1 } 
28976 \newline 
28977 replace { ljmp %1 } by { ajmp %1 }
28978 \layout Standard
28979
28980 The 
28981 \emph on 
28982 inline-assembler code
28983 \emph default 
28984  is also passed through the peep hole optimizer, thus the peephole optimizer
28985  can also be used as an assembly level macro expander.
28986  The rules themselves are MCU dependent whereas the rule language infra-structur
28987 e is MCU independent.
28988  Peephole optimization rules for other MCU can be easily programmed using
28989  the rule language.
28990 \newline 
28991
28992 \newline 
28993 The syntax for a rule is as follows:
28994 \layout Verse
28995
28996
28997 \family typewriter 
28998 rule := replace [ restart ] '{' <assembly sequence> '
28999 \backslash 
29000 n' 
29001 \newline 
29002 \SpecialChar ~
29003  \SpecialChar ~
29004  \SpecialChar ~
29005  \SpecialChar ~
29006  \SpecialChar ~
29007  \SpecialChar ~
29008  \SpecialChar ~
29009  \SpecialChar ~
29010  \SpecialChar ~
29011  \SpecialChar ~
29012  \SpecialChar ~
29013  \SpecialChar ~
29014  \SpecialChar ~
29015  \SpecialChar ~
29016  '}' by '{' '
29017 \backslash 
29018 n' 
29019 \newline 
29020 \SpecialChar ~
29021  \SpecialChar ~
29022  \SpecialChar ~
29023  \SpecialChar ~
29024  \SpecialChar ~
29025  \SpecialChar ~
29026  \SpecialChar ~
29027  \SpecialChar ~
29028  \SpecialChar ~
29029  \SpecialChar ~
29030  \SpecialChar ~
29031  \SpecialChar ~
29032  \SpecialChar ~
29033  \SpecialChar ~
29034  \SpecialChar ~
29035  \SpecialChar ~
29036  <assembly sequence> '
29037 \backslash 
29038 n' 
29039 \newline 
29040 \SpecialChar ~
29041  \SpecialChar ~
29042  \SpecialChar ~
29043  \SpecialChar ~
29044  \SpecialChar ~
29045  \SpecialChar ~
29046  \SpecialChar ~
29047  \SpecialChar ~
29048  \SpecialChar ~
29049  \SpecialChar ~
29050  \SpecialChar ~
29051  \SpecialChar ~
29052  \SpecialChar ~
29053  \SpecialChar ~
29054  '}' [if <functionName> ] '
29055 \backslash 
29056 n' 
29057 \layout Standard
29058
29059 <assembly sequence> := assembly instruction (each instruction including
29060  labels must be on a separate line).
29061 \newline 
29062
29063 \newline 
29064 The optimizer will apply to the rules one by one from the top in the sequence
29065  of their appearance, it will terminate when all rules are exhausted.
29066  If the 'restart' option is specified, then the optimizer will start matching
29067  the rules again from the top, this option for a rule is expensive (performance)
29068 , it is intended to be used in situations where a transformation will trigger
29069  the same rule again.
29070  An example of this (not a good one, it has side effects) is the following
29071  rule:
29072 \layout Verse
29073
29074
29075 \family typewriter 
29076 replace restart { 
29077 \newline 
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 pop %1 
29081 \newline 
29082 \SpecialChar ~
29083 \SpecialChar ~
29084 push %1 } by { 
29085 \newline 
29086 \SpecialChar ~
29087 \SpecialChar ~
29088 ; nop 
29089 \newline 
29090 }
29091 \layout Standard
29092
29093 Note that the replace pattern cannot be a blank, but can be a comment line.
29094  Without the 'restart' option only the innermost 'pop' 'push' pair would
29095  be eliminated, i.e.:
29096 \layout Verse
29097
29098
29099 \family typewriter 
29100 pop ar1 
29101 \newline 
29102 pop ar2 
29103 \newline 
29104 push ar2 
29105 \newline 
29106 push ar1
29107 \layout Standard
29108
29109 would result in:
29110 \layout Verse
29111
29112
29113 \family typewriter 
29114 pop ar1 
29115 \newline 
29116 ; nop 
29117 \newline 
29118 push ar1
29119 \layout Standard
29120
29121
29122 \emph on 
29123 with
29124 \emph default 
29125  the restart option the rule will be applied again to the resulting code
29126  and then all the pop-push pairs will be eliminated to yield:
29127 \layout Verse
29128
29129
29130 \family typewriter 
29131 ; nop 
29132 \newline 
29133 ; nop
29134 \layout Standard
29135
29136 A conditional function can be attached to a rule.
29137  Attaching rules are somewhat more involved, let me illustrate this with
29138  an example.
29139 \layout Verse
29140
29141
29142 \family typewriter 
29143 replace { 
29144 \newline 
29145 \SpecialChar ~
29146  \SpecialChar ~
29147  \SpecialChar ~
29148 ljmp %5 
29149 \newline 
29150 %2:
29151 \newline 
29152 } by { 
29153 \newline 
29154 \SpecialChar ~
29155  \SpecialChar ~
29156  \SpecialChar ~
29157 sjmp %5 
29158 \newline 
29159 %2:
29160 \newline 
29161 } if labelInRange
29162 \layout Standard
29163
29164 The optimizer does a look-up of a function name table defined in function
29165  
29166 \emph on 
29167 callFuncByName
29168 \emph default 
29169  in the source file SDCCpeeph.c, with the name 
29170 \emph on 
29171 labelInRange
29172 \emph default 
29173 .
29174  If it finds a corresponding entry the function is called.
29175  Note there can be no parameters specified for these functions, in this
29176  case the use of 
29177 \emph on 
29178 %5
29179 \emph default 
29180  is crucial, since the function 
29181 \emph on 
29182 labelInRange
29183 \emph default 
29184  expects to find the label in that particular variable (the hash table containin
29185 g the variable bindings is passed as a parameter).
29186  If you want to code more such functions, take a close look at the function
29187  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29188  Currently implemented are 
29189 \emph on 
29190 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29191  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29192 \emph default 
29193 and
29194 \emph on 
29195  notVolatile
29196 \emph default 
29197 .
29198 \layout Standard
29199
29200 I know this whole thing is a little kludgey, but maybe some day we will
29201  have some better means.
29202  If you are looking at this file, you will see the default rules that are
29203  compiled into the compiler, you can add your own rules in the default set
29204  there if you get tired of specifying the -
29205 \begin_inset ERT
29206 status Collapsed
29207
29208 \layout Standard
29209
29210 \backslash 
29211 /
29212 \end_inset 
29213
29214 -peep-file option.
29215 \layout Section
29216
29217 ANSI-Compliance
29218 \begin_inset LatexCommand \index{ANSI-compliance}
29219
29220 \end_inset 
29221
29222
29223 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29224
29225 \end_inset 
29226
29227
29228 \layout Standard
29229
29230 The latest publically available version of the standard 
29231 \emph on 
29232 ISO/IEC 9899 - Programming languages - C
29233 \emph default 
29234  should be available at: 
29235 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29236
29237 \end_inset 
29238
29239 .
29240 \newline 
29241
29242 \layout Standard
29243
29244 Deviations from the compliance:
29245 \layout Itemize
29246
29247 functions are not reentrant
29248 \begin_inset LatexCommand \index{reentrant}
29249
29250 \end_inset 
29251
29252  unless explicitly declared as such or the 
29253 \series bold 
29254 -
29255 \begin_inset ERT
29256 status Collapsed
29257
29258 \layout Standard
29259
29260 \backslash 
29261 /
29262 \end_inset 
29263
29264 -stack-auto
29265 \begin_inset LatexCommand \index{-\/-stack-auto}
29266
29267 \end_inset 
29268
29269
29270 \series default 
29271  command line option is specified.
29272 \layout Itemize
29273
29274 structures
29275 \begin_inset LatexCommand \index{struct}
29276
29277 \end_inset 
29278
29279  and unions
29280 \begin_inset LatexCommand \index{union}
29281
29282 \end_inset 
29283
29284  cannot be assigned values directly, cannot be passed as function parameters
29285  or assigned to each other and cannot be a return value
29286 \begin_inset LatexCommand \index{return value}
29287
29288 \end_inset 
29289
29290  from a function, e.g.:
29291 \begin_deeper 
29292 \layout Verse
29293
29294
29295 \family typewriter 
29296 struct s { ...
29297  }; 
29298 \newline 
29299 struct s s1, s2; 
29300 \newline 
29301 foo() 
29302 \newline 
29303
29304 \newline 
29305 \SpecialChar ~
29306 \SpecialChar ~
29307 \SpecialChar ~
29308 \SpecialChar ~
29309 ...
29310  
29311 \newline 
29312 \SpecialChar ~
29313 \SpecialChar ~
29314 \SpecialChar ~
29315 \SpecialChar ~
29316 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29317 \newline 
29318 \SpecialChar ~
29319 \SpecialChar ~
29320 \SpecialChar ~
29321 \SpecialChar ~
29322 ...
29323  
29324 \newline 
29325 }
29326 \newline 
29327
29328 \series bold 
29329 struct
29330 \series default 
29331  s foo1 (
29332 \series bold 
29333 struct
29334 \series default 
29335  s parms) /* invalid in SDCC although allowed in ANSI */
29336 \newline 
29337
29338 \newline 
29339 \SpecialChar ~
29340 \SpecialChar ~
29341 \SpecialChar ~
29342 \SpecialChar ~
29343 struct s rets; 
29344 \newline 
29345 \SpecialChar ~
29346 \SpecialChar ~
29347 \SpecialChar ~
29348 \SpecialChar ~
29349 ...
29350  
29351 \newline 
29352 \SpecialChar ~
29353 \SpecialChar ~
29354 \SpecialChar ~
29355 \SpecialChar ~
29356 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29357 \newline 
29358 }
29359 \end_deeper 
29360 \layout Itemize
29361
29362 initialization of structure arrays must be fully braced.
29363 \begin_deeper 
29364 \layout Verse
29365
29366
29367 \family typewriter 
29368 struct s { char x } a[] = {1, 2};\SpecialChar ~
29369 \SpecialChar ~
29370 \SpecialChar ~
29371 \SpecialChar ~
29372 \SpecialChar ~
29373 /* invalid in SDCC */
29374 \newline 
29375 struct s { char x } a[] = {{1}, {2}}; /* OK */
29376 \end_deeper 
29377 \layout Itemize
29378
29379 'long long
29380 \begin_inset LatexCommand \index{long long (not supported)}
29381
29382 \end_inset 
29383
29384 ' (64 bit integers
29385 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29386
29387 \end_inset 
29388
29389 ) not supported.
29390 \layout Itemize
29391
29392 'double
29393 \begin_inset LatexCommand \index{double (not supported)}
29394
29395 \end_inset 
29396
29397 ' precision floating point 
29398 \begin_inset LatexCommand \index{Floating point support}
29399
29400 \end_inset 
29401
29402 not supported.
29403 \layout Itemize
29404
29405 Old K&R style
29406 \begin_inset LatexCommand \index{K\&R style}
29407
29408 \end_inset 
29409
29410  function declarations are NOT allowed.
29411 \begin_deeper 
29412 \layout Verse
29413
29414
29415 \family typewriter 
29416 foo(i,j) /* this old style of function declarations */ 
29417 \newline 
29418 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29419 \newline 
29420
29421 \newline 
29422 \SpecialChar ~
29423 \SpecialChar ~
29424 \SpecialChar ~
29425 \SpecialChar ~
29426 ...
29427  
29428 \newline 
29429 }
29430 \end_deeper 
29431 \layout Itemize
29432
29433 Most enhancements in C99 are not supported, f.e.:
29434 \begin_deeper 
29435 \layout Verse
29436
29437
29438 \family typewriter 
29439 \series bold 
29440 inline
29441 \begin_inset LatexCommand \index{inline (not supported)}
29442
29443 \end_inset 
29444
29445
29446 \series default 
29447  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29448  in C99.
29449  An empty define 
29450 \emph on 
29451 #define inline
29452 \emph default 
29453  can be used as a work around */
29454 \newline 
29455
29456 \newline 
29457 for (
29458 \series bold 
29459 int
29460 \series default 
29461  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29462 \end_deeper 
29463 \layout Itemize
29464
29465 Certain words that are valid identifiers in the standard may be reserved
29466  words in SDCC unless the 
29467 \series bold 
29468 -
29469 \begin_inset ERT
29470 status Collapsed
29471
29472 \layout Standard
29473
29474 \backslash 
29475 /
29476 \end_inset 
29477
29478 -std-c89
29479 \begin_inset LatexCommand \index{-\/-std-c89}
29480
29481 \end_inset 
29482
29483  or -
29484 \begin_inset ERT
29485 status Collapsed
29486
29487 \layout Standard
29488
29489 \backslash 
29490 /
29491 \end_inset 
29492
29493 -std-c99
29494 \begin_inset LatexCommand \index{-\/-std-c99}
29495
29496 \end_inset 
29497
29498
29499 \series default 
29500  command line options are used.
29501  These may include (depending on the selected processor): 'at', 'banked',
29502  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29503 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29504  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29505  '_naked'.
29506  Compliant equivalents of these keywords are always available in a form
29507  that begin with two underscores
29508 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29509
29510 \end_inset 
29511
29512 , f.e.
29513  '__data' instead of 'data'.
29514 \layout Section
29515
29516 Cyclomatic Complexity
29517 \begin_inset LatexCommand \index{Cyclomatic complexity}
29518
29519 \end_inset 
29520
29521
29522 \layout Standard
29523
29524 Cyclomatic complexity of a function is defined as the number of independent
29525  paths the program can take during execution of the function.
29526  This is an important number since it defines the number test cases you
29527  have to generate to validate the function.
29528  The accepted industry standard for complexity number is 10, if the cyclomatic
29529  complexity reported by SDCC exceeds 10 you should think about simplification
29530  of the function logic.
29531  Note that the complexity level is not related to the number of lines of
29532  code in a function.
29533  Large functions can have low complexity, and small functions can have large
29534  complexity levels.
29535  
29536 \newline 
29537
29538 \newline 
29539 SDCC uses the following formula to compute the complexity:
29540 \newline 
29541
29542 \layout Standard
29543
29544 complexity = (number of edges in control flow graph) - (number of nodes
29545  in control flow graph) + 2;
29546 \newline 
29547
29548 \newline 
29549 Having said that the industry standard is 10, you should be aware that in
29550  some cases it be may unavoidable to have a complexity level of less than
29551  10.
29552  For example if you have switch statement with more than 10 case labels,
29553  each case label adds one to the complexity level.
29554  The complexity level is by no means an absolute measure of the algorithmic
29555  complexity of the function, it does however provide a good starting point
29556  for which functions you might look at for further optimization.
29557 \layout Section
29558
29559 Retargetting for other Processors
29560 \layout Standard
29561
29562 The issues for retargetting the compiler are far too numerous to be covered
29563  by this document.
29564  What follows is a brief description of each of the seven phases of the
29565  compiler and its MCU dependency.
29566 \layout Itemize
29567
29568 Parsing the source and building the annotated parse tree.
29569  This phase is largely MCU independent (except for the language extensions).
29570  Syntax & semantic checks are also done in this phase, along with some initial
29571  optimizations like back patching labels and the pattern matching optimizations
29572  like bit-rotation etc.
29573 \layout Itemize
29574
29575 The second phase involves generating an intermediate code which can be easy
29576  manipulated during the later phases.
29577  This phase is entirely MCU independent.
29578  The intermediate code generation assumes the target machine has unlimited
29579  number of registers, and designates them with the name iTemp.
29580  The compiler can be made to dump a human readable form of the code generated
29581  by using the -
29582 \begin_inset ERT
29583 status Collapsed
29584
29585 \layout Standard
29586
29587 \backslash 
29588 /
29589 \end_inset 
29590
29591 -dumpraw option.
29592 \layout Itemize
29593
29594 This phase does the bulk of the standard optimizations and is also MCU independe
29595 nt.
29596  This phase can be broken down into several sub-phases:
29597 \newline 
29598
29599 \newline 
29600 Break down intermediate code (iCode) into basic blocks.
29601 \newline 
29602 Do control flow & data flow analysis on the basic blocks.
29603 \newline 
29604 Do local common subexpression elimination, then global subexpression elimination
29605 \newline 
29606 Dead code elimination
29607 \newline 
29608 Loop optimizations
29609 \newline 
29610 If loop optimizations caused any changes then do 'global subexpression eliminati
29611 on' and 'dead code elimination' again.
29612 \layout Itemize
29613
29614 This phase determines the live-ranges; by live range I mean those iTemp
29615  variables defined by the compiler that still survive after all the optimization
29616 s.
29617  Live range analysis
29618 \begin_inset LatexCommand \index{Live range analysis}
29619
29620 \end_inset 
29621
29622  is essential for register allocation, since these computation determines
29623  which of these iTemps will be assigned to registers, and for how long.
29624 \layout Itemize
29625
29626 Phase five is register allocation.
29627  There are two parts to this process.
29628 \newline 
29629
29630 \newline 
29631 The first part I call 'register packing' (for lack of a better term).
29632  In this case several MCU specific expression folding is done to reduce
29633  register pressure.
29634 \newline 
29635
29636 \newline 
29637 The second part is more MCU independent and deals with allocating registers
29638  to the remaining live ranges.
29639  A lot of MCU specific code does creep into this phase because of the limited
29640  number of index registers available in the 8051.
29641 \layout Itemize
29642
29643 The Code generation phase is (unhappily), entirely MCU dependent and very
29644  little (if any at all) of this code can be reused for other MCU.
29645  However the scheme for allocating a homogenized assembler operand for each
29646  iCode operand may be reused.
29647 \layout Itemize
29648
29649 As mentioned in the optimization section the peep-hole optimizer is rule
29650  based system, which can reprogrammed for other MCUs.
29651 \layout Chapter
29652
29653 Compiler internals
29654 \begin_inset LatexCommand \index{Compiler internals}
29655
29656 \end_inset 
29657
29658
29659 \layout Section
29660
29661 The anatomy of the compiler
29662 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29663
29664 \end_inset 
29665
29666
29667 \layout Standard
29668
29669
29670 \shape italic 
29671 This is an excerpt from an article published in Circuit Cellar Magazine
29672  in 
29673 \series bold 
29674 August 2000
29675 \series default 
29676 .
29677  It's a little outdated (the compiler is much more efficient now and user/develo
29678 per friendly), but pretty well exposes the guts of it all.
29679 \shape default 
29680
29681 \newline 
29682
29683 \newline 
29684 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29685  It is fairly easy to retarget for other 8-bit MCU.
29686  Here we take a look at some of the internals of the compiler.
29687  
29688 \layout Paragraph*
29689
29690 Parsing
29691 \begin_inset LatexCommand \index{Parsing}
29692
29693 \end_inset 
29694
29695  
29696 \layout Standard
29697
29698 Parsing the input source file and creating an AST (Annotated Syntax Tree
29699 \begin_inset LatexCommand \index{Annotated syntax tree}
29700
29701 \end_inset 
29702
29703 ).
29704  This phase also involves propagating types (annotating each node of the
29705  parse tree with type information) and semantic analysis.
29706  There are some MCU specific parsing rules.
29707  For example the storage classes, the extended storage classes are MCU specific
29708  while there may be a xdata storage class for 8051 there is no such storage
29709  class for z80 or Atmel AVR.
29710  SDCC allows MCU specific storage class extensions, i.e.
29711  xdata will be treated as a storage class specifier when parsing 8051 C
29712  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29713  C code.
29714 \layout Paragraph*
29715
29716 Generating iCode
29717 \begin_inset LatexCommand \index{iCode}
29718
29719 \end_inset 
29720
29721
29722 \layout Standard
29723
29724 Intermediate code generation.
29725  In this phase the AST is broken down into three-operand form (iCode).
29726  These three operand forms are represented as doubly linked lists.
29727  ICode is the term given to the intermediate form generated by the compiler.
29728  ICode example section shows some examples of iCode generated for some simple
29729  C source functions.
29730 \layout Paragraph*
29731
29732 Optimizations
29733 \begin_inset LatexCommand \index{Optimizations}
29734
29735 \end_inset 
29736
29737 .
29738 \layout Standard
29739
29740 Bulk of the target independent optimizations is performed in this phase.
29741  The optimizations include constant propagation, common sub-expression eliminati
29742 on, loop invariant code movement, strength reduction of loop induction variables
29743  and dead-code elimination.
29744 \layout Paragraph*
29745
29746 Live range analysis
29747 \begin_inset LatexCommand \index{Live range analysis}
29748
29749 \end_inset 
29750
29751
29752 \layout Standard
29753
29754 During intermediate code generation phase, the compiler assumes the target
29755  machine has infinite number of registers and generates a lot of temporary
29756  variables.
29757  The live range computation determines the lifetime of each of these compiler-ge
29758 nerated temporaries.
29759  A picture speaks a thousand words.
29760  ICode example sections show the live range annotations for each of the
29761  operand.
29762  It is important to note here, each iCode is assigned a number in the order
29763  of its execution in the function.
29764  The live ranges are computed in terms of these numbers.
29765  The from number is the number of the iCode which first defines the operand
29766  and the to number signifies the iCode which uses this operand last.
29767 \layout Paragraph*
29768
29769 Register Allocation
29770 \begin_inset LatexCommand \index{Register allocation}
29771
29772 \end_inset 
29773
29774
29775 \layout Standard
29776
29777 The register allocation determines the type and number of registers needed
29778  by each operand.
29779  In most MCUs only a few registers can be used for indirect addressing.
29780  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29781  address the internal ram and DPTR to indirectly address the external ram.
29782  The compiler will try to allocate the appropriate register to pointer variables
29783  if it can.
29784  ICode example section shows the operands annotated with the registers assigned
29785  to them.
29786  The compiler will try to keep operands in registers as much as possible;
29787  there are several schemes the compiler uses to do achieve this.
29788  When the compiler runs out of registers the compiler will check to see
29789  if there are any live operands which is not used or defined in the current
29790  basic block being processed, if there are any found then it will push that
29791  operand and use the registers in this block, the operand will then be popped
29792  at the end of the basic block.
29793  
29794 \layout Standard
29795
29796 There are other MCU specific considerations in this phase.
29797  Some MCUs have an accumulator; very short-lived operands could be assigned
29798  to the accumulator instead of a general-purpose register.
29799 \layout Paragraph*
29800
29801 Code generation
29802 \layout Standard
29803
29804 Figure II gives a table of iCode operations supported by the compiler.
29805  The code generation involves translating these operations into corresponding
29806  assembly code for the processor.
29807  This sounds overly simple but that is the essence of code generation.
29808  Some of the iCode operations are generated on a MCU specific manner for
29809  example, the z80 port does not use registers to pass parameters so the
29810  SEND and RECV iCode operations will not be generated, and it also does
29811  not support JUMPTABLES.
29812  
29813 \newline 
29814
29815 \series bold 
29816 \shape italic 
29817 \color red
29818 <Where is Figure II?>
29819 \layout Comment
29820
29821 In the original article Figure II was announced to be downloadable on 
29822 \shape italic 
29823 Circuit Cellar
29824 \shape default 
29825 's web site.
29826  Unfortunately it never seemed to have shown up there, so: where is Figure
29827  II?
29828 \layout Paragraph*
29829
29830 ICode Example
29831 \begin_inset LatexCommand \index{iCode}
29832
29833 \end_inset 
29834
29835
29836 \layout Standard
29837
29838 This section shows some details of iCode.
29839  The example C code does not do anything useful; it is used as an example
29840  to illustrate the intermediate code generated by the compiler.
29841 \layout Verse
29842
29843
29844 \family typewriter 
29845 1.\SpecialChar ~
29846 xdata int * p;
29847 \newline 
29848 2.\SpecialChar ~
29849 int gint;
29850 \newline 
29851 3.\SpecialChar ~
29852 /* This function does nothing useful.
29853  It is used
29854 \newline 
29855 4.\SpecialChar ~
29856 \SpecialChar ~
29857 \SpecialChar ~
29858 \SpecialChar ~
29859 for the purpose of explaining iCode */
29860 \newline 
29861 5.\SpecialChar ~
29862 short function (data int *x)
29863 \newline 
29864 6.\SpecialChar ~
29865 {
29866 \newline 
29867 7.\SpecialChar ~
29868 \SpecialChar ~
29869 \SpecialChar ~
29870 short i=10; \SpecialChar ~
29871 \SpecialChar ~
29872 /* dead initialization eliminated */
29873 \newline 
29874 8.\SpecialChar ~
29875 \SpecialChar ~
29876 \SpecialChar ~
29877 short sum=10; /* dead initialization eliminated */
29878 \newline 
29879 9.\SpecialChar ~
29880 \SpecialChar ~
29881 \SpecialChar ~
29882 short mul;
29883 \newline 
29884 10.\SpecialChar ~
29885 \SpecialChar ~
29886 int j ;
29887 \newline 
29888 11.\SpecialChar ~
29889 \SpecialChar ~
29890 while (*x) *x++ = *p++; 
29891 \newline 
29892 12.\SpecialChar ~
29893 \SpecialChar ~
29894 \SpecialChar ~
29895 \SpecialChar ~
29896 sum = 0 ; 
29897 \newline 
29898 13.\SpecialChar ~
29899 \SpecialChar ~
29900 mul = 0;
29901 \newline 
29902 14.\SpecialChar ~
29903 \SpecialChar ~
29904 /* compiler detects i,j to be induction variables */
29905 \newline 
29906 15.\SpecialChar ~
29907 \SpecialChar ~
29908 for (i = 0, j = 10 ; i < 10 ; i++, j
29909 \family default 
29910 -
29911 \begin_inset ERT
29912 status Collapsed
29913
29914 \layout Standard
29915
29916 \backslash 
29917 /
29918 \end_inset 
29919
29920 -
29921 \family typewriter 
29922 ) {
29923 \newline 
29924 16.\SpecialChar ~
29925 \SpecialChar ~
29926 \SpecialChar ~
29927 \SpecialChar ~
29928 sum += i;
29929 \newline 
29930 17.\SpecialChar ~
29931 \SpecialChar ~
29932 \SpecialChar ~
29933 \SpecialChar ~
29934 mul += i * 3; \SpecialChar ~
29935 \SpecialChar ~
29936 /* this multiplication remains */
29937 \newline 
29938 18.\SpecialChar ~
29939 \SpecialChar ~
29940 \SpecialChar ~
29941 \SpecialChar ~
29942 gint += j * 3;\SpecialChar ~
29943 \SpecialChar ~
29944 /* this multiplication changed to addition */
29945 \newline 
29946 19.\SpecialChar ~
29947 \SpecialChar ~
29948 }
29949 \newline 
29950 20.\SpecialChar ~
29951 \SpecialChar ~
29952 return sum+mul;
29953 \newline 
29954 21.\SpecialChar ~
29955 }
29956 \layout Standard
29957
29958 In addition to the operands each iCode contains information about the filename
29959  and line it corresponds to in the source file.
29960  The first field in the listing should be interpreted as follows:
29961 \newline 
29962
29963 \shape italic 
29964 \size footnotesize 
29965 Filename(linenumber: iCode Execution sequence number : ICode hash table
29966  key : loop depth of the iCode).
29967 \shape default 
29968 \size default 
29969
29970 \newline 
29971 Then follows the human readable form of the ICode operation.
29972  Each operand of this triplet form can be of three basic types a) compiler
29973  generated temporary b) user defined variable c) a constant value.
29974  Note that local variables and parameters are replaced by compiler generated
29975  temporaries.
29976  Live ranges
29977 \begin_inset LatexCommand \index{Live range analysis}
29978
29979 \end_inset 
29980
29981  are computed only for temporaries (i.e.
29982  live ranges are not computed for global variables).
29983  Registers
29984 \begin_inset LatexCommand \index{Register allocation}
29985
29986 \end_inset 
29987
29988  are allocated for temporaries only.
29989  Operands are formatted in the following manner:
29990 \newline 
29991
29992 \shape italic 
29993 \size footnotesize 
29994 Operand Name [lr live-from : live-to ] { type information } [ registers
29995  allocated ].
29996 \shape default 
29997 \size default 
29998
29999 \newline 
30000 As mentioned earlier the live ranges are computed in terms of the execution
30001  sequence number of the iCodes, for example 
30002 \newline 
30003 the iTemp0 is live from (i.e.
30004  first defined in iCode with execution sequence number 3, and is last used
30005  in the iCode with sequence number 5).
30006  For induction variables such as iTemp21 the live range computation extends
30007  the lifetime from the start to the end of the loop.
30008 \newline 
30009 The register allocator used the live range information to allocate registers,
30010  the same registers may be used for different temporaries if their live
30011  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
30012  iTemp17 since their live ranges do not overlap.
30013  In addition the allocator also takes into consideration the type and usage
30014  of a temporary, for example itemp6 is a pointer to near space and is used
30015  as to fetch data from (i.e.
30016  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
30017  Some short lived temporaries are allocated to special registers which have
30018  meaning to the code generator e.g.
30019  iTemp13 is allocated to a pseudo register CC which tells the back end that
30020  the temporary is used only for a conditional jump the code generation makes
30021  use of this information to optimize a compare and jump ICode.
30022 \newline 
30023 There are several loop optimizations
30024 \begin_inset LatexCommand \index{Loop optimization}
30025
30026 \end_inset 
30027
30028  performed by the compiler.
30029  It can detect induction variables iTemp21(i) and iTemp23(j).
30030  Also note the compiler does selective strength reduction
30031 \begin_inset LatexCommand \index{Strength reduction}
30032
30033 \end_inset 
30034
30035 , i.e.
30036  the multiplication of an induction variable in line 18 (gint = j * 3) is
30037  changed to addition, a new temporary iTemp17 is allocated and assigned
30038  a initial value, a constant 3 is then added for each iteration of the loop.
30039  The compiler does not change the multiplication
30040 \begin_inset LatexCommand \index{Multiplication}
30041
30042 \end_inset 
30043
30044  in line 17 however since the processor does support an 8 * 8 bit multiplication.
30045 \newline 
30046 Note the dead code elimination
30047 \begin_inset LatexCommand \index{Dead-code elimination}
30048
30049 \end_inset 
30050
30051  optimization eliminated the dead assignments in line 7 & 8 to I and sum
30052  respectively.
30053 \newline 
30054
30055 \layout Standard
30056
30057
30058 \size footnotesize 
30059 Sample.c (5:1:0:0) _entry($9) :
30060 \layout Standard
30061
30062
30063 \size footnotesize 
30064 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
30065 \layout Standard
30066
30067
30068 \size footnotesize 
30069 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
30070 \layout Standard
30071
30072
30073 \size footnotesize 
30074 Sample.c(11:4:53:0) preHeaderLbl0($11) :
30075 \layout Standard
30076
30077
30078 \size footnotesize 
30079 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
30080  * int}[r2]
30081 \layout Standard
30082
30083
30084 \size footnotesize 
30085 Sample.c(11:6:5:1) _whilecontinue_0($1) :
30086 \layout Standard
30087
30088
30089 \size footnotesize 
30090 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
30091  int}[r0]]
30092 \layout Standard
30093
30094
30095 \size footnotesize 
30096 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30097 \layout Standard
30098
30099
30100 \size footnotesize 
30101 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
30102  * int}
30103 \layout Standard
30104
30105
30106 \size footnotesize 
30107 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
30108  {short}
30109 \layout Standard
30110
30111
30112 \size footnotesize 
30113 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
30114  * int}[DPTR]]
30115 \layout Standard
30116
30117
30118 \size footnotesize 
30119 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
30120 }[r2 r3]
30121 \layout Standard
30122
30123
30124 \size footnotesize 
30125 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
30126  * int}[r0] + 0x2 {short}
30127 \layout Standard
30128
30129
30130 \size footnotesize 
30131 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
30132 \layout Standard
30133
30134
30135 \size footnotesize 
30136 Sample.c(11:17:21:0)_whilebreak_0($3) :
30137 \layout Standard
30138
30139
30140 \size footnotesize 
30141 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30142 \layout Standard
30143
30144
30145 \size footnotesize 
30146 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30147 \layout Standard
30148
30149
30150 \size footnotesize 
30151 Sample.c(15:20:54:0)preHeaderLbl1($13) :
30152 \layout Standard
30153
30154
30155 \size footnotesize 
30156 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30157 \layout Standard
30158
30159
30160 \size footnotesize 
30161 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30162 \layout Standard
30163
30164
30165 \size footnotesize 
30166 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30167 \layout Standard
30168
30169
30170 \size footnotesize 
30171 Sample.c(15:24:26:1)_forcond_0($4) :
30172 \layout Standard
30173
30174
30175 \size footnotesize 
30176 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
30177  < 0xa {short}
30178 \layout Standard
30179
30180
30181 \size footnotesize 
30182 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30183 \layout Standard
30184
30185
30186 \size footnotesize 
30187 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
30188  + ITemp21 [lr21:38]{short}[r4]
30189 \layout Standard
30190
30191
30192 \size footnotesize 
30193 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
30194  * 0x3 {short}
30195 \layout Standard
30196
30197
30198 \size footnotesize 
30199 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
30200  + iTemp15 [lr29:30]{short}[r1]
30201 \layout Standard
30202
30203
30204 \size footnotesize 
30205 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
30206  r0]- 0x3 {short}
30207 \layout Standard
30208
30209
30210 \size footnotesize 
30211 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
30212 int}[r7 r0]
30213 \layout Standard
30214
30215
30216 \size footnotesize 
30217 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
30218  + 0x1 {short}
30219 \layout Standard
30220
30221
30222 \size footnotesize 
30223 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
30224  r6]- 0x1 {short}
30225 \layout Standard
30226
30227
30228 \size footnotesize 
30229 Sample.c(19:38:47:1) goto _forcond_0($4)
30230 \layout Standard
30231
30232
30233 \size footnotesize 
30234 Sample.c(19:39:48:0)_forbreak_0($7) :
30235 \layout Standard
30236
30237
30238 \size footnotesize 
30239 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
30240  + ITemp11 [lr19:40]{short}[r3]
30241 \layout Standard
30242
30243
30244 \size footnotesize 
30245 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
30246 \layout Standard
30247
30248
30249 \size footnotesize 
30250 Sample.c(20:42:51:0)_return($8) :
30251 \layout Standard
30252
30253
30254 \size footnotesize 
30255 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
30256 \size default 
30257
30258 \newline 
30259
30260 \newline 
30261 Finally the code generated for this function:
30262 \newline 
30263
30264 \layout Standard
30265
30266
30267 \size footnotesize 
30268 .area DSEG (DATA)
30269 \layout Standard
30270
30271
30272 \size footnotesize 
30273 _p::
30274 \layout Standard
30275
30276
30277 \size footnotesize 
30278 \SpecialChar ~
30279 \SpecialChar ~
30280 .ds 2
30281 \layout Standard
30282
30283
30284 \size footnotesize 
30285 _gint::
30286 \layout Standard
30287
30288
30289 \size footnotesize 
30290 \SpecialChar ~
30291 \SpecialChar ~
30292 .ds 2
30293 \layout Standard
30294
30295
30296 \size footnotesize 
30297 ; sample.c 5
30298 \layout Standard
30299
30300
30301 \size footnotesize 
30302 ; ----------------------------------------------
30303 \layout Standard
30304
30305
30306 \size footnotesize 
30307 ; function function
30308 \layout Standard
30309
30310
30311 \size footnotesize 
30312 ; ----------------------------------------------
30313 \layout Standard
30314
30315
30316 \size footnotesize 
30317 _function:
30318 \layout Standard
30319
30320
30321 \size footnotesize 
30322 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
30323 \layout Standard
30324
30325
30326 \size footnotesize 
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 mov r2,dpl
30330 \layout Standard
30331
30332
30333 \size footnotesize 
30334 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
30335 \layout Standard
30336
30337
30338 \size footnotesize 
30339 \SpecialChar ~
30340 \SpecialChar ~
30341 mov ar0,r2
30342 \layout Standard
30343
30344
30345 \size footnotesize 
30346 ;_whilecontinue_0($1) :
30347 \layout Standard
30348
30349
30350 \size footnotesize 
30351 00101$:
30352 \layout Standard
30353
30354
30355 \size footnotesize 
30356 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
30357 \layout Standard
30358
30359
30360 \size footnotesize 
30361 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30362 \layout Standard
30363
30364
30365 \size footnotesize 
30366 \SpecialChar ~
30367 \SpecialChar ~
30368 mov ar2,@r0
30369 \layout Standard
30370
30371
30372 \size footnotesize 
30373 \SpecialChar ~
30374 \SpecialChar ~
30375 inc r0
30376 \layout Standard
30377
30378
30379 \size footnotesize 
30380 \SpecialChar ~
30381 \SpecialChar ~
30382 mov ar3,@r0
30383 \layout Standard
30384
30385
30386 \size footnotesize 
30387 \SpecialChar ~
30388 \SpecialChar ~
30389 dec r0
30390 \layout Standard
30391
30392
30393 \size footnotesize 
30394 \SpecialChar ~
30395 \SpecialChar ~
30396 mov a,r2
30397 \layout Standard
30398
30399
30400 \size footnotesize 
30401 \SpecialChar ~
30402 \SpecialChar ~
30403 orl a,r3
30404 \layout Standard
30405
30406
30407 \size footnotesize 
30408 \SpecialChar ~
30409 \SpecialChar ~
30410 jz 00103$
30411 \layout Standard
30412
30413
30414 \size footnotesize 
30415 00114$:
30416 \layout Standard
30417
30418
30419 \size footnotesize 
30420 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
30421 \layout Standard
30422
30423
30424 \size footnotesize 
30425 \SpecialChar ~
30426 \SpecialChar ~
30427 mov dpl,_p
30428 \layout Standard
30429
30430
30431 \size footnotesize 
30432 \SpecialChar ~
30433 \SpecialChar ~
30434 mov dph,(_p + 1)
30435 \layout Standard
30436
30437
30438 \size footnotesize 
30439 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
30440 \layout Standard
30441
30442
30443 \size footnotesize 
30444 \SpecialChar ~
30445 \SpecialChar ~
30446 mov a,#0x02
30447 \layout Standard
30448
30449
30450 \size footnotesize 
30451 \SpecialChar ~
30452 \SpecialChar ~
30453 add a,_p
30454 \layout Standard
30455
30456
30457 \size footnotesize 
30458 \SpecialChar ~
30459 \SpecialChar ~
30460 mov _p,a
30461 \layout Standard
30462
30463
30464 \size footnotesize 
30465 \SpecialChar ~
30466 \SpecialChar ~
30467 clr a
30468 \layout Standard
30469
30470
30471 \size footnotesize 
30472 \SpecialChar ~
30473 \SpecialChar ~
30474 addc a,(_p + 1)
30475 \layout Standard
30476
30477
30478 \size footnotesize 
30479 \SpecialChar ~
30480 \SpecialChar ~
30481 mov (_p + 1),a
30482 \layout Standard
30483
30484
30485 \size footnotesize 
30486 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
30487 \layout Standard
30488
30489
30490 \size footnotesize 
30491 \SpecialChar ~
30492 \SpecialChar ~
30493 movx a,@dptr
30494 \layout Standard
30495
30496
30497 \size footnotesize 
30498 \SpecialChar ~
30499 \SpecialChar ~
30500 mov r2,a
30501 \layout Standard
30502
30503
30504 \size footnotesize 
30505 \SpecialChar ~
30506 \SpecialChar ~
30507 inc dptr
30508 \layout Standard
30509
30510
30511 \size footnotesize 
30512 \SpecialChar ~
30513 \SpecialChar ~
30514 movx a,@dptr
30515 \layout Standard
30516
30517
30518 \size footnotesize 
30519 \SpecialChar ~
30520 \SpecialChar ~
30521 mov r3,a
30522 \layout Standard
30523
30524
30525 \size footnotesize 
30526 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
30527 \layout Standard
30528
30529
30530 \size footnotesize 
30531 \SpecialChar ~
30532 \SpecialChar ~
30533 mov @r0,ar2
30534 \layout Standard
30535
30536
30537 \size footnotesize 
30538 \SpecialChar ~
30539 \SpecialChar ~
30540 inc r0
30541 \layout Standard
30542
30543
30544 \size footnotesize 
30545 \SpecialChar ~
30546 \SpecialChar ~
30547 mov @r0,ar3
30548 \layout Standard
30549
30550
30551 \size footnotesize 
30552 ; iTemp6 [lr5:16]{_near * int}[r0] = 
30553 \layout Standard
30554
30555
30556 \size footnotesize 
30557 ; iTemp6 [lr5:16]{_near * int}[r0] + 
30558 \layout Standard
30559
30560
30561 \size footnotesize 
30562 ; 0x2 {short}
30563 \layout Standard
30564
30565
30566 \size footnotesize 
30567 \SpecialChar ~
30568 \SpecialChar ~
30569 inc r0
30570 \layout Standard
30571
30572
30573 \size footnotesize 
30574 ; goto _whilecontinue_0($1)
30575 \layout Standard
30576
30577
30578 \size footnotesize 
30579 \SpecialChar ~
30580 \SpecialChar ~
30581 sjmp 00101$
30582 \layout Standard
30583
30584
30585 \size footnotesize 
30586 ; _whilebreak_0($3) :
30587 \layout Standard
30588
30589
30590 \size footnotesize 
30591 00103$:
30592 \layout Standard
30593
30594
30595 \size footnotesize 
30596 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30597 \layout Standard
30598
30599
30600 \size footnotesize 
30601 \SpecialChar ~
30602 \SpecialChar ~
30603 mov r2,#0x00
30604 \layout Standard
30605
30606
30607 \size footnotesize 
30608 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30609 \layout Standard
30610
30611
30612 \size footnotesize 
30613 \SpecialChar ~
30614 \SpecialChar ~
30615 mov r3,#0x00
30616 \layout Standard
30617
30618
30619 \size footnotesize 
30620 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30621 \layout Standard
30622
30623
30624 \size footnotesize 
30625 \SpecialChar ~
30626 \SpecialChar ~
30627 mov r4,#0x00
30628 \layout Standard
30629
30630
30631 \size footnotesize 
30632 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30633 \layout Standard
30634
30635
30636 \size footnotesize 
30637 \SpecialChar ~
30638 \SpecialChar ~
30639 mov r5,#0x0A
30640 \layout Standard
30641
30642
30643 \size footnotesize 
30644 \SpecialChar ~
30645 \SpecialChar ~
30646 mov r6,#0x00
30647 \layout Standard
30648
30649
30650 \size footnotesize 
30651 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30652 \layout Standard
30653
30654
30655 \size footnotesize 
30656 \SpecialChar ~
30657 \SpecialChar ~
30658 mov r7,#0x1E
30659 \layout Standard
30660
30661
30662 \size footnotesize 
30663 \SpecialChar ~
30664 \SpecialChar ~
30665 mov r0,#0x00
30666 \layout Standard
30667
30668
30669 \size footnotesize 
30670 ; _forcond_0($4) :
30671 \layout Standard
30672
30673
30674 \size footnotesize 
30675 00104$:
30676 \layout Standard
30677
30678
30679 \size footnotesize 
30680 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
30681 \layout Standard
30682
30683
30684 \size footnotesize 
30685 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30686 \layout Standard
30687
30688
30689 \size footnotesize 
30690 \SpecialChar ~
30691 \SpecialChar ~
30692 clr c
30693 \layout Standard
30694
30695
30696 \size footnotesize 
30697 \SpecialChar ~
30698 \SpecialChar ~
30699 mov a,r4
30700 \layout Standard
30701
30702
30703 \size footnotesize 
30704 \SpecialChar ~
30705 \SpecialChar ~
30706 xrl a,#0x80
30707 \layout Standard
30708
30709
30710 \size footnotesize 
30711 \SpecialChar ~
30712 \SpecialChar ~
30713 subb a,#0x8a
30714 \layout Standard
30715
30716
30717 \size footnotesize 
30718 \SpecialChar ~
30719 \SpecialChar ~
30720 jnc 00107$
30721 \layout Standard
30722
30723
30724 \size footnotesize 
30725 00115$:
30726 \layout Standard
30727
30728
30729 \size footnotesize 
30730 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
30731 \layout Standard
30732
30733
30734 \size footnotesize 
30735 ; iTemp21 [lr21:38]{short}[r4]
30736 \layout Standard
30737
30738
30739 \size footnotesize 
30740 \SpecialChar ~
30741 \SpecialChar ~
30742 mov a,r4
30743 \layout Standard
30744
30745
30746 \size footnotesize 
30747 \SpecialChar ~
30748 \SpecialChar ~
30749 add a,r2
30750 \layout Standard
30751
30752
30753 \size footnotesize 
30754 \SpecialChar ~
30755 \SpecialChar ~
30756 mov r2,a
30757 \layout Standard
30758
30759
30760 \size footnotesize 
30761 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
30762 \layout Standard
30763
30764
30765 \size footnotesize 
30766 \SpecialChar ~
30767 \SpecialChar ~
30768 mov b,#0x03
30769 \layout Standard
30770
30771
30772 \size footnotesize 
30773 \SpecialChar ~
30774 \SpecialChar ~
30775 mov a,r4
30776 \layout Standard
30777
30778
30779 \size footnotesize 
30780 \SpecialChar ~
30781 \SpecialChar ~
30782 mul ab
30783 \layout Standard
30784
30785
30786 \size footnotesize 
30787 \SpecialChar ~
30788 \SpecialChar ~
30789 mov r1,a
30790 \layout Standard
30791
30792
30793 \size footnotesize 
30794 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
30795 \layout Standard
30796
30797
30798 \size footnotesize 
30799 ; iTemp15 [lr29:30]{short}[r1]
30800 \layout Standard
30801
30802
30803 \size footnotesize 
30804 \SpecialChar ~
30805 \SpecialChar ~
30806 add a,r3
30807 \layout Standard
30808
30809
30810 \size footnotesize 
30811 \SpecialChar ~
30812 \SpecialChar ~
30813 mov r3,a
30814 \layout Standard
30815
30816
30817 \size footnotesize 
30818 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
30819 \layout Standard
30820
30821
30822 \size footnotesize 
30823 \SpecialChar ~
30824 \SpecialChar ~
30825 mov a,r7
30826 \layout Standard
30827
30828
30829 \size footnotesize 
30830 \SpecialChar ~
30831 \SpecialChar ~
30832 add a,#0xfd
30833 \layout Standard
30834
30835
30836 \size footnotesize 
30837 \SpecialChar ~
30838 \SpecialChar ~
30839 mov r7,a
30840 \layout Standard
30841
30842
30843 \size footnotesize 
30844 \SpecialChar ~
30845 \SpecialChar ~
30846 mov a,r0
30847 \layout Standard
30848
30849
30850 \size footnotesize 
30851 \SpecialChar ~
30852 \SpecialChar ~
30853 addc a,#0xff
30854 \layout Standard
30855
30856
30857 \size footnotesize 
30858 \SpecialChar ~
30859 \SpecialChar ~
30860 mov r0,a
30861 \layout Standard
30862
30863
30864 \size footnotesize 
30865 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
30866 \layout Standard
30867
30868
30869 \size footnotesize 
30870 \SpecialChar ~
30871 \SpecialChar ~
30872 mov a,r7
30873 \layout Standard
30874
30875
30876 \size footnotesize 
30877 \SpecialChar ~
30878 \SpecialChar ~
30879 add a,_gint
30880 \layout Standard
30881
30882
30883 \size footnotesize 
30884 \SpecialChar ~
30885 \SpecialChar ~
30886 mov _gint,a
30887 \layout Standard
30888
30889
30890 \size footnotesize 
30891 \SpecialChar ~
30892 \SpecialChar ~
30893 mov a,r0
30894 \layout Standard
30895
30896
30897 \size footnotesize 
30898 \SpecialChar ~
30899 \SpecialChar ~
30900 addc a,(_gint + 1)
30901 \layout Standard
30902
30903
30904 \size footnotesize 
30905 \SpecialChar ~
30906 \SpecialChar ~
30907 mov (_gint + 1),a
30908 \layout Standard
30909
30910
30911 \size footnotesize 
30912 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
30913 \layout Standard
30914
30915
30916 \size footnotesize 
30917 \SpecialChar ~
30918 \SpecialChar ~
30919 inc r4
30920 \layout Standard
30921
30922
30923 \size footnotesize 
30924 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
30925 \layout Standard
30926
30927
30928 \size footnotesize 
30929 \SpecialChar ~
30930 \SpecialChar ~
30931 dec r5
30932 \layout Standard
30933
30934
30935 \size footnotesize 
30936 \SpecialChar ~
30937 \SpecialChar ~
30938 cjne r5,#0xff,00104$
30939 \layout Standard
30940
30941
30942 \size footnotesize 
30943 \SpecialChar ~
30944 \SpecialChar ~
30945 dec r6
30946 \layout Standard
30947
30948
30949 \size footnotesize 
30950 ; goto _forcond_0($4)
30951 \layout Standard
30952
30953
30954 \size footnotesize 
30955 \SpecialChar ~
30956 \SpecialChar ~
30957 sjmp 00104$
30958 \layout Standard
30959
30960
30961 \size footnotesize 
30962 ; _forbreak_0($7) :
30963 \layout Standard
30964
30965
30966 \size footnotesize 
30967 00107$:
30968 \layout Standard
30969
30970
30971 \size footnotesize 
30972 ; ret iTemp24 [lr40:41]{short}
30973 \layout Standard
30974
30975
30976 \size footnotesize 
30977 \SpecialChar ~
30978 \SpecialChar ~
30979 mov a,r3
30980 \layout Standard
30981
30982
30983 \size footnotesize 
30984 \SpecialChar ~
30985 \SpecialChar ~
30986 add a,r2
30987 \layout Standard
30988
30989
30990 \size footnotesize 
30991 \SpecialChar ~
30992 \SpecialChar ~
30993 mov dpl,a
30994 \layout Standard
30995
30996
30997 \size footnotesize 
30998 ; _return($8) :
30999 \layout Standard
31000
31001
31002 \size footnotesize 
31003 00108$:
31004 \layout Standard
31005
31006
31007 \size footnotesize 
31008 \SpecialChar ~
31009 \SpecialChar ~
31010 ret
31011 \newline 
31012
31013 \layout Section
31014
31015 A few words about basic block successors, predecessors and dominators
31016 \layout Standard
31017
31018 Successors are basic blocks
31019 \begin_inset LatexCommand \index{Basic blocks}
31020
31021 \end_inset 
31022
31023  that might execute after this basic block.
31024 \newline 
31025 Predecessors are basic blocks that might execute before reaching this basic
31026  block.
31027 \newline 
31028 Dominators are basic blocks that WILL execute before reaching this basic
31029  block.
31030 \newline 
31031
31032 \layout Standard
31033
31034 [basic block 1]
31035 \layout Standard
31036
31037 if (something)
31038 \layout Standard
31039
31040 \SpecialChar ~
31041 \SpecialChar ~
31042 \SpecialChar ~
31043 \SpecialChar ~
31044 [basic block 2]
31045 \layout Standard
31046
31047 else
31048 \layout Standard
31049
31050 \SpecialChar ~
31051 \SpecialChar ~
31052 \SpecialChar ~
31053 \SpecialChar ~
31054 [basic block 3]
31055 \layout Standard
31056
31057 [basic block 4]
31058 \newline 
31059
31060 \layout Standard
31061
31062 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
31063 \layout Standard
31064
31065 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
31066 \layout Standard
31067
31068 c) domVect of [BB4] = BB1 ...
31069  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
31070  was executed.
31071 \layout Chapter
31072
31073 Acknowledgments
31074 \layout Standard
31075
31076
31077 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
31078
31079 \end_inset 
31080
31081
31082 \newline 
31083
31084 \newline 
31085
31086 \emph on 
31087 Thanks to all the other volunteer developers who have helped with coding,
31088  testing, web-page creation, distribution sets, etc.
31089  You know who you are :-)
31090 \emph default 
31091
31092 \newline 
31093
31094 \newline 
31095
31096 \emph on 
31097 Also thanks to Sourceforge 
31098 \begin_inset LatexCommand \url{http://www.sf.net}
31099
31100 \end_inset 
31101
31102  which has hosted the project since 1999 and donates significant download
31103  bandwidth and probably more than 
31104 \begin_inset ERT
31105 status Collapsed
31106
31107 \layout Standard
31108 $10^{13}$
31109 \end_inset 
31110
31111 CPU cycles per day.
31112 \newline 
31113  
31114 \begin_inset Note
31115 collapsed false
31116
31117 \layout Standard
31118
31119 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
31120  minutes for (configure+make+regression test), and there is (i386, amd64,
31121  alpha, ppc64, (mingw32), sparc, macosx).
31122  
31123 \end_inset 
31124
31125
31126 \layout Standard
31127
31128 This document was initially written by Sandeep Dutta
31129 \layout Standard
31130
31131 All product names mentioned herein may be trademarks
31132 \begin_inset LatexCommand \index{Trademarks}
31133
31134 \end_inset 
31135
31136  of their respective companies.
31137  
31138 \layout Section*
31139
31140 Alphabetical index
31141 \layout Standard
31142
31143 To avoid confusion, the installation and building options for SDCC itself
31144  (chapter 2) are not part of the index.
31145 \layout Standard
31146
31147
31148 \begin_inset LatexCommand \printindex{}
31149
31150 \end_inset 
31151
31152
31153 \the_end