* src/SDCCglobl.h,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.1 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 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \papercolumns 1
43 \papersides 1
44 \paperpagestyle fancy
45
46 \layout Standard
47 \begin_inset Note
48 collapsed true
49
50 \layout Standard
51 Please note: double dashed longoptions (e.g.
52  --version) are written this way: -
53 \begin_inset ERT
54 status Collapsed
55
56 \layout Standard
57
58
59 \backslash
60 /
61
62 \end_inset
63
64 -
65
66 \layout Standard
67 Two resp.
68  three consecutive dashes simply result in a long resp.
69  extra long dash.
70
71 \layout Standard
72 Architecture specific stuff (like memory models, code examples) should maybe
73  later go
74
75 \layout Standard
76 into seperate sections/chapters/appendices (it is hard to document PIC or
77  Z80 in 
78
79 \layout Standard
80 a 8051 centered document) - for now simply add.
81
82 \end_inset
83
84
85
86 \layout Title
87 SDCC Compiler User Guide
88
89 \layout Date
90
91 \size normal
92 SDCC 2.6.4
93 \size footnotesize
94
95 \newline
96 $Date::            $ 
97 \newline
98 $Revision$
99
100 \layout Standard
101 \begin_inset Note
102 collapsed true
103
104 \layout Standard
105 The above strings enclosed in $ are automatically updated by Subversion
106
107 \end_inset
108
109
110
111 \layout Standard
112 \begin_inset LatexCommand \tableofcontents{}
113
114 \end_inset
115
116
117
118 \layout Chapter
119 Introduction
120
121 \layout Section
122 About SDCC
123
124 \layout Standard
125
126 \series bold
127 SDCC
128 \series default
129  (
130 \emph on
131 S
132 \emph default
133 mall 
134 \emph on
135 D
136 \emph default
137 evice 
138 \emph on
139 C
140 \emph default
141  
142 \emph on
143 C
144 \emph default
145 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
146  
147 \series bold
148 Sandeep Dutta
149 \series default
150  designed for 8 bit Microprocessors.
151  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
152  8051, 8052
153 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
154
155 \end_inset
156
157 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
158  Zilog Z80 based MCUs.
159  It can be retargeted for other microprocessors, support for Microchip PIC,
160  Atmel AVR is under development.
161  The entire source code for the compiler is distributed under GPL.
162  SDCC uses ASXXXX
163 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
164
165 \end_inset
166
167  & ASLINK
168 \begin_inset LatexCommand \index{aslink}
169
170 \end_inset
171
172 , an open source retargetable assembler & linker.
173  SDCC has extensive language extensions suitable for utilizing various microcont
174 rollers and underlying hardware effectively.
175  
176 \newline
177
178 \newline
179 In addition to the MCU specific optimizations SDCC also does a host of
180  standard optimizations like:
181
182 \layout Itemize
183 global sub expression elimination, 
184
185 \layout Itemize
186 loop optimizations (loop invariant, strength reduction of induction variables
187  and loop reversing), 
188
189 \layout Itemize
190 constant folding & propagation, 
191
192 \layout Itemize
193 copy propagation, 
194
195 \layout Itemize
196 dead code elimination 
197
198 \layout Itemize
199 jump tables for 
200 \emph on
201 switch
202 \emph default
203  statements.
204
205 \layout Standard
206 For the back-end SDCC uses a global register allocation scheme which should
207  be well suited for other 8 bit MCUs.
208  
209 \newline
210
211 \newline
212 The peep hole optimizer uses a rule based substitution mechanism which
213  is MCU independent.
214  
215 \newline
216
217 \newline
218 Supported data-types are:
219
220 \layout Standard
221 \begin_inset Tabular
222 <lyxtabular version="3" rows="8" columns="5">
223 <features>
224 <column alignment="center" valignment="top" leftline="true" width="0">
225 <column alignment="center" valignment="top" leftline="true" width="0">
226 <column alignment="center" valignment="top" leftline="true" width="0">
227 <column alignment="center" valignment="top" leftline="true" width="0">
228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
229 <row topline="true" bottomline="true">
230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
231 \begin_inset Text
232
233 \layout Standard
234 type
235
236 \end_inset
237 </cell>
238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
239 \begin_inset Text
240
241 \layout Standard
242 width
243
244 \end_inset
245 </cell>
246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
247 \begin_inset Text
248
249 \layout Standard
250 default
251
252 \end_inset
253 </cell>
254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
255 \begin_inset Text
256
257 \layout Standard
258 signed range
259
260 \end_inset
261 </cell>
262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
263 \begin_inset Text
264
265 \layout Standard
266 unsigned range
267
268 \end_inset
269 </cell>
270 </row>
271 <row topline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
273 \begin_inset Text
274
275 \layout Standard
276 bool
277
278 \end_inset
279 </cell>
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
281 \begin_inset Text
282
283 \layout Standard
284 1 bit
285
286 \end_inset
287 </cell>
288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_inset Text
290
291 \layout Standard
292 unsigned
293
294 \end_inset
295 </cell>
296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
297 \begin_inset Text
298
299 \layout Standard
300 -
301
302 \end_inset
303 </cell>
304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
305 \begin_inset Text
306
307 \layout Standard
308 0, 1
309
310 \end_inset
311 </cell>
312 </row>
313 <row topline="true">
314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
315 \begin_inset Text
316
317 \layout Standard
318 char
319
320 \end_inset
321 </cell>
322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
323 \begin_inset Text
324
325 \layout Standard
326 8 bits, 1 byte
327
328 \end_inset
329 </cell>
330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_inset Text
332
333 \layout Standard
334 signed
335
336 \end_inset
337 </cell>
338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
339 \begin_inset Text
340
341 \layout Standard
342 -128, +127
343
344 \end_inset
345 </cell>
346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
347 \begin_inset Text
348
349 \layout Standard
350 0, +255
351
352 \end_inset
353 </cell>
354 </row>
355 <row topline="true">
356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
357 \begin_inset Text
358
359 \layout Standard
360 short
361
362 \end_inset
363 </cell>
364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_inset Text
366
367 \layout Standard
368 16 bits, 2 bytes
369
370 \end_inset
371 </cell>
372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
373 \begin_inset Text
374
375 \layout Standard
376 signed
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \layout Standard
384 -32.768, +32.767
385
386 \end_inset
387 </cell>
388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
389 \begin_inset Text
390
391 \layout Standard
392 0, +65.535
393
394 \end_inset
395 </cell>
396 </row>
397 <row topline="true">
398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
399 \begin_inset Text
400
401 \layout Standard
402 int
403
404 \end_inset
405 </cell>
406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
407 \begin_inset Text
408
409 \layout Standard
410 16 bits, 2 bytes
411
412 \end_inset
413 </cell>
414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
415 \begin_inset Text
416
417 \layout Standard
418 signed
419
420 \end_inset
421 </cell>
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
423 \begin_inset Text
424
425 \layout Standard
426 -32.768, +32.767
427
428 \end_inset
429 </cell>
430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
431 \begin_inset Text
432
433 \layout Standard
434 0, +65.535
435
436 \end_inset
437 </cell>
438 </row>
439 <row topline="true" bottomline="true">
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
441 \begin_inset Text
442
443 \layout Standard
444 long
445
446 \end_inset
447 </cell>
448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
449 \begin_inset Text
450
451 \layout Standard
452 32 bits, 4 bytes
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \layout Standard
460 signed
461
462 \end_inset
463 </cell>
464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
465 \begin_inset Text
466
467 \layout Standard
468 -2.147.483.648, +2.147.483.647
469
470 \end_inset
471 </cell>
472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
473 \begin_inset Text
474
475 \layout Standard
476 0, +4.294.967.295
477
478 \end_inset
479 </cell>
480 </row>
481 <row topline="true" bottomline="true">
482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
483 \begin_inset Text
484
485 \layout Standard
486 float
487
488 \end_inset
489 </cell>
490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
491 \begin_inset Text
492
493 \layout Standard
494 4 bytes IEEE 754
495
496 \end_inset
497 </cell>
498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
499 \begin_inset Text
500
501 \layout Standard
502 signed
503
504 \end_inset
505 </cell>
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
507 \begin_inset Text
508
509 \layout Standard
510
511
512 \end_inset
513 </cell>
514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
515 \begin_inset Text
516
517 \layout Standard
518 1.175494351E-38, 
519 \family roman
520 \series medium
521 \shape up
522 \size normal
523 \emph off
524 \bar no
525 \noun off
526 \color none
527 3.402823466E+38
528
529 \end_inset
530 </cell>
531 </row>
532 <row topline="true" bottomline="true">
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537 pointer
538
539 \end_inset
540 </cell>
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \layout Standard
545 1, 2, 3 or 4 bytes
546
547 \end_inset
548 </cell>
549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
550 \begin_inset Text
551
552 \layout Standard
553 generic
554
555 \end_inset
556 </cell>
557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
558 \begin_inset Text
559
560 \layout Standard
561
562
563 \end_inset
564 </cell>
565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
566 \begin_inset Text
567
568 \layout Standard
569
570
571 \end_inset
572 </cell>
573 </row>
574 </lyxtabular>
575
576 \end_inset
577
578
579 \newline
580 The compiler also allows 
581 \emph on
582 inline assembler code
583 \emph default
584  to be embedded anywhere in a function.
585  In addition, routines developed in assembly can also be called.
586 \newline
587
588 \newline
589 SDCC also
590  provides an option (-
591 \begin_inset ERT
592 status Collapsed
593
594 \layout Standard
595
596
597 \backslash
598 /
599
600 \end_inset
601
602 -cyclomatic) to report the relative complexity of a function.
603  These functions can then be further optimized, or hand coded in assembly
604  if needed.
605  
606 \newline
607
608 \newline
609 SDCC also comes with a companion source level debugger SDCDB, the debugger
610  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
611 \newline
612
613 \newline
614
615 The latest version can be downloaded from 
616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
617
618 \end_inset
619
620 .
621
622 \series bold
623  
624 \series default
625 \emph on
626 Please note: the compiler will probably always be some steps ahead of this
627  documentation
628 \series bold
629 \emph default
630
631 \begin_inset LatexCommand \index{Status of documentation}
632
633 \end_inset
634
635
636 \begin_inset Foot
637 collapsed false
638
639 \layout Standard
640 Obviously this has pros and cons
641
642 \end_inset
643
644 .
645
646 \layout Section
647 Open Source
648
649 \layout Standard
650 All packages used in this compiler system are 
651 \emph on
652 open source
653 \emph default
654  and 
655 \emph on
656 freeware
657 \emph default
658 ; source code for all the sub-packages (pre-processor, assemblers, linkers
659  etc) is distributed with the package.
660  This documentation is maintained using a freeware word processor (LyX).
661 \newline
662 This
663  program is free software; you can redistribute it and/or modify it under
664  the terms of the GNU General Public License
665 \begin_inset LatexCommand \index{GNU General Public License, GPL}
666
667 \end_inset
668
669  as published by the Free Software Foundation; either version 2, or (at
670  your option) any later version.
671  This program is distributed in the hope that it will be useful, but WITHOUT
672  ANY WARRANTY; without even the implied warranty
673 \begin_inset LatexCommand \index{warranty}
674
675 \end_inset
676
677  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
678  See the GNU General Public License for more details.
679  You should have received a copy of the GNU General Public License along
680  with this program; if not, write to the Free Software Foundation, 59 Temple
681  Place - Suite 330, Boston, MA 02111-1307, USA.
682  In other words, you are welcome to use, share and improve this program.
683  You are forbidden to forbid anyone else to use, share and improve what
684  you give them.
685  Help stamp out software-hoarding! 
686
687 \layout Section
688 Typographic conventions
689 \begin_inset LatexCommand \index{Typographic conventions}
690
691 \end_inset
692
693
694
695 \layout Standard
696 Throughout this manual, we will use the following convention.
697  Commands you have to type in are printed in 
698 \family sans
699 \series bold
700 "sans serif"
701 \series default
702 .
703
704 \family default
705  Code samples are printed in 
706 \family typewriter
707 typewriter font.
708
709 \family default
710  Interesting items and new terms are printed in 
711 \emph on
712 italic.
713
714 \layout Section
715 Compatibility
716 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
717
718 \end_inset
719
720  with previous versions
721 \begin_inset LatexCommand \index{Compatibility with previous versions}
722
723 \end_inset
724
725
726
727 \layout Standard
728 This version has numerous bug fixes compared with the previous version.
729  But we also introduced some incompatibilities with older versions.
730  Not just for the fun of it, but to make the compiler more stable, efficient
731  and ANSI compliant
732 \begin_inset LatexCommand \index{ANSI-compliance}
733
734 \end_inset
735
736  (see section 
737 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
738
739 \end_inset
740
741  for ANSI-Compliance).
742  
743 \newline
744
745
746 \layout Itemize
747 short is now equivalent to int (16 bits), it used to be equivalent to char
748  (8 bits) which is not ANSI compliant.
749
750 \layout Itemize
751 the default directory for gcc-builds where include, library and documentation
752  files are stored is now in /usr/local/share.
753
754 \layout Itemize
755 char type parameters to vararg
756 \begin_inset LatexCommand \index{vararg, va\_arg}
757
758 \end_inset
759
760  functions are casted to int unless explicitly casted
761 \begin_inset Marginal
762 collapsed true
763
764 \layout Standard
765
766 \series bold
767 \SpecialChar ~
768 !
769
770 \end_inset
771
772 , e.g.: 
773 \newline
774
775 \family typewriter
776 \SpecialChar ~
777 \SpecialChar ~
778 char a=3;
779 \newline
780 \SpecialChar ~
781 \SpecialChar ~
782 printf ("%d %c
783 \backslash
784 n", a, (char)a);
785 \family default
786
787 \newline
788  will push a as an int and as a char resp.
789
790 \layout Itemize
791 option -
792 \begin_inset ERT
793 status Collapsed
794
795 \layout Standard
796
797
798 \backslash
799 /
800
801 \end_inset
802
803 -regextend has been removed.
804
805 \layout Itemize
806 option -
807 \begin_inset ERT
808 status Collapsed
809
810 \layout Standard
811
812
813 \backslash
814 /
815
816 \end_inset
817
818 -noregparms has been removed.
819
820 \layout Itemize
821 option -
822 \begin_inset ERT
823 status Collapsed
824
825 \layout Standard
826
827
828 \backslash
829 /
830
831 \end_inset
832
833 -stack-after-data has been removed.
834
835 \layout Itemize
836 bit
837 \begin_inset LatexCommand \index{bit}
838
839 \end_inset
840
841  and sbit
842 \begin_inset LatexCommand \index{sbit}
843
844 \end_inset
845
846
847 \begin_inset LatexCommand \index{\_\_sbit}
848
849 \end_inset
850
851  types now consistently behave like the C99 _Bool type with respect to type
852  conversion
853 \begin_inset LatexCommand \index{type conversion}
854
855 \end_inset
856
857
858 \begin_inset LatexCommand \index{type promotion}
859
860 \end_inset
861
862 .
863  The most common incompatibility resulting from this change is related to
864  bit toggling
865 \begin_inset LatexCommand \index{Bit toggling}
866
867 \end_inset
868
869  idioms, e.g.:
870 \newline
871
872 \family typewriter
873 \SpecialChar ~
874 \SpecialChar ~
875 bit b;
876 \newline
877 \SpecialChar ~
878 \SpecialChar ~
879 b = ~
880 \begin_inset LatexCommand \index{\~\/ Operator}
881
882 \end_inset
883
884 b; /* equivalent to b=1 instead of toggling b */
885 \begin_inset Marginal
886 collapsed true
887
888 \layout Standard
889
890 \series bold
891 \SpecialChar ~
892 !
893
894 \end_inset
895
896
897 \newline
898 \SpecialChar ~
899 \SpecialChar ~
900 b = !b; /* toggles b */
901 \newline
902
903 \family default
904 In previous versions, both forms would have toggled the bit.
905
906 \layout Standard
907
908 \emph on
909 <pending: more incompatibilities?>
910
911 \layout Section
912 System Requirements
913
914 \layout Standard
915 What do you need before you start installation of SDCC? A computer, and
916  a desire to compute.
917  The preferred method of installation is to compile SDCC from source using
918  GNU gcc and make.
919  For Windows some pre-compiled binary distributions are available for your
920  convenience.
921  You should have some experience with command line tools and compiler use.
922
923 \layout Section
924 Other Resources
925
926 \layout Standard
927 The SDCC home page at 
928 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
929
930 \end_inset
931
932  is a great place to find distribution sets.
933  You can also find links to the user mailing lists that offer help or discuss
934  SDCC with other SDCC users.
935  Web links to other SDCC related sites can also be found here.
936  This document can be found in the DOC directory of the source package as
937  a text or HTML file.
938  A pdf version of this document is available at 
939 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
940
941 \end_inset
942
943 .
944  Some of the other tools (simulator and assembler) included with SDCC contain
945  their own documentation and can be found in the source distribution.
946  If you want the latest unreleased software, the complete source package
947  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
948 /trunk/sdcc.
949
950 \layout Section
951 Wishes for the future
952
953 \layout Standard
954 There are (and always will be) some things that could be done.
955  Here are some I can think of:
956 \newline
957
958
959 \layout Standard
960
961 \family typewriter
962 char KernelFunction3(char p) at 0x340;
963 \newline
964
965
966 \layout Standard
967
968 \family typewriter
969 better code banking
970 \begin_inset LatexCommand \index{code banking (limited support)}
971
972 \end_inset
973
974  support for mcs51
975 \newline
976
977 \newline
978
979 \family default
980 If you can think of some more, please see the section 
981 \begin_inset LatexCommand \ref{sub:Requesting-Features}
982
983 \end_inset
984
985  about filing feature requests
986 \begin_inset LatexCommand \index{Requesting features}
987
988 \end_inset
989
990
991 \begin_inset LatexCommand \index{Feature request}
992
993 \end_inset
994
995 .
996 \newline
997
998
999 \layout Chapter
1000 Installing SDCC
1001 \begin_inset LatexCommand \index{Installation}
1002
1003 \end_inset
1004
1005
1006
1007 \layout Standard
1008 For most users it is sufficient to skip to either section 
1009 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1010
1011 \end_inset
1012
1013  (Unix) or section 
1014 \begin_inset LatexCommand \ref{sub:Windows-Install}
1015
1016 \end_inset
1017
1018  (Windows).
1019  More detailed instructions follow below.
1020
1021 \layout Section
1022 Configure Options
1023 \begin_inset LatexCommand \index{Options SDCC configuration}
1024
1025 \end_inset
1026
1027
1028
1029 \layout Standard
1030 The install paths, search paths and other options are defined when running
1031  'configure'.
1032  The defaults can be overridden by:
1033
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036 -
1037 \begin_inset ERT
1038 status Collapsed
1039
1040 \layout Standard
1041
1042
1043 \backslash
1044 /
1045
1046 \end_inset
1047
1048 -prefix see table below
1049
1050 \layout List
1051 \labelwidthstring 00.00.0000
1052 -
1053 \begin_inset ERT
1054 status Collapsed
1055
1056 \layout Standard
1057
1058
1059 \backslash
1060 /
1061
1062 \end_inset
1063
1064 -exec_prefix see table below
1065
1066 \layout List
1067 \labelwidthstring 00.00.0000
1068 -
1069 \begin_inset ERT
1070 status Collapsed
1071
1072 \layout Standard
1073
1074
1075 \backslash
1076 /
1077
1078 \end_inset
1079
1080 -bindir see table below
1081
1082 \layout List
1083 \labelwidthstring 00.00.0000
1084 -
1085 \begin_inset ERT
1086 status Collapsed
1087
1088 \layout Standard
1089
1090
1091 \backslash
1092 /
1093
1094 \end_inset
1095
1096 -datadir see table below
1097
1098 \layout List
1099 \labelwidthstring 00.00.0000
1100 -
1101 \begin_inset ERT
1102 status Collapsed
1103
1104 \layout Standard
1105
1106
1107 \backslash
1108 /
1109
1110 \end_inset
1111
1112 -datarootdir see table below
1113 \newline
1114
1115
1116 \layout List
1117 \labelwidthstring 00.00.0000
1118 \SpecialChar ~
1119 \SpecialChar ~
1120 docdir environment variable, see table below
1121
1122 \layout List
1123 \labelwidthstring 00.00.0000
1124 \SpecialChar ~
1125 \SpecialChar ~
1126 include_dir_suffix environment variable, see table below
1127
1128 \layout List
1129 \labelwidthstring 00.00.0000
1130 \SpecialChar ~
1131 \SpecialChar ~
1132 lib_dir_suffix environment variable, see table below
1133
1134 \layout List
1135 \labelwidthstring 00.00.0000
1136 \SpecialChar ~
1137 \SpecialChar ~
1138 sdccconf_h_dir_separator environment variable, either / or 
1139 \backslash
1140
1141 \backslash
1142  makes sense here.
1143  This character will only be used in sdccconf.h; don't forget it's a C-header,
1144  therefore a double-backslash is needed there.
1145 \newline
1146
1147
1148 \layout List
1149 \labelwidthstring 00.00.0000
1150 -
1151 \begin_inset ERT
1152 status Collapsed
1153
1154 \layout Standard
1155
1156
1157 \backslash
1158 /
1159
1160 \end_inset
1161
1162 -disable-mcs51-port Excludes the Intel mcs51 port
1163
1164 \layout List
1165 \labelwidthstring 00.00.0000
1166 -
1167 \begin_inset ERT
1168 status Collapsed
1169
1170 \layout Standard
1171
1172
1173 \backslash
1174 /
1175
1176 \end_inset
1177
1178 -disable-gbz80-port Excludes the Gameboy gbz80 port
1179
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182 -
1183 \begin_inset ERT
1184 status Collapsed
1185
1186 \layout Standard
1187
1188
1189 \backslash
1190 /
1191
1192 \end_inset
1193
1194 -disable-z80-port Excludes the z80 port
1195
1196 \layout List
1197 \labelwidthstring 00.00.0000
1198 -
1199 \begin_inset ERT
1200 status Collapsed
1201
1202 \layout Standard
1203
1204
1205 \backslash
1206 /
1207
1208 \end_inset
1209
1210 -disable-avr-port Excludes the AVR port
1211
1212 \layout List
1213 \labelwidthstring 00.00.0000
1214 -
1215 \begin_inset ERT
1216 status Collapsed
1217
1218 \layout Standard
1219
1220
1221 \backslash
1222 /
1223
1224 \end_inset
1225
1226 -disable-ds390-port Excludes the DS390 port
1227
1228 \layout List
1229 \labelwidthstring 00.00.0000
1230 -
1231 \begin_inset ERT
1232 status Collapsed
1233
1234 \layout Standard
1235
1236
1237 \backslash
1238 /
1239
1240 \end_inset
1241
1242 -disable-hc08-port Excludes the HC08 port
1243
1244 \layout List
1245 \labelwidthstring 00.00.0000
1246 -
1247 \begin_inset ERT
1248 status Collapsed
1249
1250 \layout Standard
1251
1252
1253 \backslash
1254 /
1255
1256 \end_inset
1257
1258 -disable-pic-port Excludes the PIC port
1259
1260 \layout List
1261 \labelwidthstring 00.00.0000
1262 -
1263 \begin_inset ERT
1264 status Collapsed
1265
1266 \layout Standard
1267
1268
1269 \backslash
1270 /
1271
1272 \end_inset
1273
1274 -disable-xa51-port Excludes the XA51 port
1275
1276 \layout List
1277 \labelwidthstring 00.00.0000
1278 -
1279 \begin_inset ERT
1280 status Collapsed
1281
1282 \layout Standard
1283
1284
1285 \backslash
1286 /
1287
1288 \end_inset
1289
1290 -disable-ucsim Disables configuring and building of ucsim
1291
1292 \layout List
1293 \labelwidthstring 00.00.0000
1294 -
1295 \begin_inset ERT
1296 status Collapsed
1297
1298 \layout Standard
1299
1300
1301 \backslash
1302 /
1303
1304 \end_inset
1305
1306 -disable-device-lib Disables automatically building device libraries
1307
1308 \layout List
1309 \labelwidthstring 00.00.0000
1310 -
1311 \begin_inset ERT
1312 status Collapsed
1313
1314 \layout Standard
1315
1316
1317 \backslash
1318 /
1319
1320 \end_inset
1321
1322 -disable-packihx Disables building packihx
1323 \newline
1324
1325
1326 \layout List
1327 \labelwidthstring 00.00.0000
1328 -
1329 \begin_inset ERT
1330 status Collapsed
1331
1332 \layout Standard
1333
1334
1335 \backslash
1336 /
1337
1338 \end_inset
1339
1340 -enable-doc Build pdf, html and txt files from the lyx sources
1341
1342 \layout List
1343 \labelwidthstring 00.00.0000
1344 -
1345 \begin_inset ERT
1346 status Collapsed
1347
1348 \layout Standard
1349
1350
1351 \backslash
1352 /
1353
1354 \end_inset
1355
1356 -enable-libgc Use the Bohem memory allocator.
1357  Lower runtime footprint.
1358
1359 \layout Standard
1360 Furthermore the environment variables CC, CFLAGS, ...
1361  the tools and their arguments can be influenced.
1362  Please see `configure -
1363 \begin_inset ERT
1364 status Collapsed
1365
1366 \layout Standard
1367
1368
1369 \backslash
1370 /
1371
1372 \end_inset
1373
1374 -help` and the man/info pages of `configure` for details.
1375 \newline
1376
1377 \newline
1378 The names of the
1379  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1380 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1381  SDCC_LIB_NAME are defined by `configure` too.
1382  At the moment it's not possible to change the default settings (it was
1383  simply never required).
1384 \newline
1385
1386 \newline
1387 These configure options are compiled into the binaries,
1388  and can only be changed by rerunning 'configure' and recompiling SDCC.
1389  The configure options are written in 
1390 \emph on
1391 italics
1392 \emph default
1393  to distinguish them from run time environment variables (see section search
1394  paths).
1395 \newline
1396
1397 \newline
1398 The settings for 
1399 \begin_inset Quotes sld
1400 \end_inset
1401
1402 Win32 builds
1403 \begin_inset Quotes srd
1404 \end_inset
1405
1406  are used by the SDCC team to build the official Win32 binaries.
1407  The SDCC team uses Mingw32 to build the official Windows binaries, because
1408  it's
1409
1410 \layout Enumerate
1411 open source, 
1412
1413 \layout Enumerate
1414 a gcc compiler and last but not least
1415
1416 \layout Enumerate
1417 the binaries can be built by cross compiling on Sourceforge's compile farm.
1418
1419 \layout Standard
1420 See the examples, how to pass the Win32 settings to 'configure'.
1421  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1422  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1423  for Win32.
1424 \newline
1425
1426 \newline
1427 These defaults are:
1428 \newline
1429
1430
1431 \layout Standard
1432 \align center
1433 \begin_inset Tabular
1434 <lyxtabular version="3" rows="9" columns="3">
1435 <features>
1436 <column alignment="block" valignment="top" leftline="true" width="0in">
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1439 <row topline="true" bottomline="true">
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1441 \begin_inset Text
1442
1443 \layout Standard
1444 Variable
1445
1446 \end_inset
1447 </cell>
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452 default
1453
1454 \end_inset
1455 </cell>
1456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1457 \begin_inset Text
1458
1459 \layout Standard
1460 Win32 builds
1461
1462 \end_inset
1463 </cell>
1464 </row>
1465 <row topline="true">
1466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1467 \begin_inset Text
1468
1469 \layout Standard
1470
1471 \emph on
1472 PREFIX
1473
1474 \end_inset
1475 </cell>
1476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1477 \begin_inset Text
1478
1479 \layout Standard
1480 /usr/local
1481
1482 \end_inset
1483 </cell>
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1485 \begin_inset Text
1486
1487 \layout Standard
1488
1489 \backslash
1490 sdcc
1491
1492 \end_inset
1493 </cell>
1494 </row>
1495 <row topline="true">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501 \emph on
1502 EXEC_PREFIX
1503
1504 \end_inset
1505 </cell>
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1507 \begin_inset Text
1508
1509 \layout Standard
1510
1511 \emph on
1512 $PREFIX
1513
1514 \end_inset
1515 </cell>
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1517 \begin_inset Text
1518
1519 \layout Standard
1520
1521 \emph on
1522 $PREFIX
1523
1524 \end_inset
1525 </cell>
1526 </row>
1527 <row topline="true">
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1529 \begin_inset Text
1530
1531 \layout Standard
1532
1533 \emph on
1534 BINDIR
1535
1536 \end_inset
1537 </cell>
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1539 \begin_inset Text
1540
1541 \layout Standard
1542
1543 \emph on
1544 $EXEC_PREFIX
1545 \emph default
1546 /bin
1547
1548 \end_inset
1549 </cell>
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1551 \begin_inset Text
1552
1553 \layout Standard
1554
1555 \emph on
1556 $EXEC_PREFIX
1557 \emph default
1558
1559 \backslash
1560 bin
1561
1562 \end_inset
1563 </cell>
1564 </row>
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1567 \begin_inset Text
1568
1569 \layout Standard
1570
1571 \emph on
1572 DATADIR
1573
1574 \end_inset
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581 \emph on
1582 $DATAROOTDIR
1583
1584 \end_inset
1585 </cell>
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1587 \begin_inset Text
1588
1589 \layout Standard
1590
1591 \emph on
1592 $DATAROOTDIR
1593
1594 \end_inset
1595 </cell>
1596 </row>
1597 <row topline="true">
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1599 \begin_inset Text
1600
1601 \layout Standard
1602
1603 \emph on
1604 DATAROOTDIR
1605
1606 \end_inset
1607 </cell>
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1609 \begin_inset Text
1610
1611 \layout Standard
1612
1613 \emph on
1614 $PREFIX
1615 \emph default
1616 /share
1617
1618 \end_inset
1619 </cell>
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1621 \begin_inset Text
1622
1623 \layout Standard
1624
1625 \emph on
1626 $PREFIX
1627
1628 \end_inset
1629 </cell>
1630 </row>
1631 <row topline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_inset Text
1634
1635 \layout Standard
1636
1637 \emph on
1638 DOCDIR
1639
1640 \end_inset
1641 </cell>
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1643 \begin_inset Text
1644
1645 \layout Standard
1646
1647 \emph on
1648 $DATAROOTDIR
1649 \emph default
1650 /sdcc/doc
1651
1652 \end_inset
1653 </cell>
1654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1655 \begin_inset Text
1656
1657 \layout Standard
1658
1659 \emph on
1660 $DATAROOTDIR
1661 \emph default
1662
1663 \backslash
1664 doc
1665
1666 \end_inset
1667 </cell>
1668 </row>
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_inset Text
1672
1673 \layout Standard
1674
1675 \emph on
1676 INCLUDE_DIR_SUFFIX
1677
1678 \end_inset
1679 </cell>
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1681 \begin_inset Text
1682
1683 \layout Standard
1684 sdcc/include
1685
1686 \end_inset
1687 </cell>
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1689 \begin_inset Text
1690
1691 \layout Standard
1692 include
1693
1694 \end_inset
1695 </cell>
1696 </row>
1697 <row topline="true" bottomline="true">
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 \begin_inset Text
1700
1701 \layout Standard
1702
1703 \emph on
1704 LIB_DIR_SUFFIX
1705
1706 \end_inset
1707 </cell>
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 \begin_inset Text
1710
1711 \layout Standard
1712 sdcc/lib
1713
1714 \end_inset
1715 </cell>
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1717 \begin_inset Text
1718
1719 \layout Standard
1720 lib
1721
1722 \end_inset
1723 </cell>
1724 </row>
1725 </lyxtabular>
1726
1727 \end_inset
1728
1729
1730 \newline
1731
1732
1733 \layout Standard
1734 \noindent
1735 'configure' also computes relative paths.
1736  This is needed for full relocatability of a binary package and to complete
1737  search paths (see section search paths below):
1738 \newline
1739  
1740
1741 \layout Standard
1742 \align center
1743 \begin_inset Tabular
1744 <lyxtabular version="3" rows="4" columns="3">
1745 <features>
1746 <column alignment="block" valignment="top" leftline="true" width="0in">
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1749 <row topline="true" bottomline="true">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1751 \begin_inset Text
1752
1753 \layout Standard
1754 Variable (computed)
1755
1756 \end_inset
1757 </cell>
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 \begin_inset Text
1760
1761 \layout Standard
1762 default
1763
1764 \end_inset
1765 </cell>
1766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1767 \begin_inset Text
1768
1769 \layout Standard
1770 Win32 builds
1771
1772 \end_inset
1773 </cell>
1774 </row>
1775 <row topline="true" bottomline="true">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_inset Text
1778
1779 \layout Standard
1780
1781 \emph on
1782 BIN2DATA_DIR
1783
1784 \end_inset
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790 ../share
1791
1792 \end_inset
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \layout Standard
1798 ..
1799
1800 \end_inset
1801 </cell>
1802 </row>
1803 <row bottomline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1805 \begin_inset Text
1806
1807 \layout Standard
1808
1809 \emph on
1810 PREFIX2BIN_DIR
1811
1812 \end_inset
1813 </cell>
1814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_inset Text
1816
1817 \layout Standard
1818 bin
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \layout Standard
1826 bin
1827
1828 \end_inset
1829 </cell>
1830 </row>
1831 <row bottomline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 \begin_inset Text
1834
1835 \layout Standard
1836
1837 \emph on
1838 PREFIX2DATA_DIR
1839
1840 \end_inset
1841 </cell>
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1843 \begin_inset Text
1844
1845 \layout Standard
1846 share/sdcc
1847
1848 \end_inset
1849 </cell>
1850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1851 \begin_inset Text
1852
1853 \layout Standard
1854
1855
1856 \end_inset
1857 </cell>
1858 </row>
1859 </lyxtabular>
1860
1861 \end_inset
1862
1863
1864 \newline
1865
1866
1867 \layout Standard
1868 \noindent
1869 Examples:
1870
1871 \layout LyX-Code
1872 ./configure
1873 \newline
1874 ./configure -
1875 \begin_inset ERT
1876 status Collapsed
1877
1878 \layout Standard
1879
1880
1881 \backslash
1882 /
1883
1884 \end_inset
1885
1886 -prefix=
1887 \begin_inset Quotes srd
1888 \end_inset
1889
1890 /usr/bin
1891 \begin_inset Quotes srd
1892 \end_inset
1893
1894  -
1895 \begin_inset ERT
1896 status Collapsed
1897
1898 \layout Standard
1899
1900
1901 \backslash
1902 /
1903
1904 \end_inset
1905
1906 -datarootdir=
1907 \begin_inset Quotes srd
1908 \end_inset
1909
1910 /usr/share
1911 \begin_inset Quotes srd
1912 \end_inset
1913
1914
1915 \newline
1916 ./configure -
1917 \begin_inset ERT
1918 status Collapsed
1919
1920 \layout Standard
1921
1922
1923 \backslash
1924 /
1925
1926 \end_inset
1927
1928 -disable-avr-port -
1929 \begin_inset ERT
1930 status Collapsed
1931
1932 \layout Standard
1933
1934
1935 \backslash
1936 /
1937
1938 \end_inset
1939
1940 -disable-xa51-port
1941
1942 \layout Standard
1943 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1944 32'):
1945
1946 \layout LyX-Code
1947 ./configure 
1948 \backslash
1949
1950 \newline
1951 CC=
1952 \begin_inset Quotes srd
1953 \end_inset
1954
1955 i586-mingw32msvc-gcc
1956 \begin_inset Quotes srd
1957 \end_inset
1958
1959  CXX=
1960 \begin_inset Quotes srd
1961 \end_inset
1962
1963 i586-mingw32msvc-g++
1964 \begin_inset Quotes srd
1965 \end_inset
1966
1967  
1968 \backslash
1969  
1970 \newline
1971 RANLIB=
1972 \begin_inset Quotes srd
1973 \end_inset
1974
1975 i586-mingw32msvc-ranlib
1976 \begin_inset Quotes srd
1977 \end_inset
1978
1979  
1980 \backslash
1981
1982 \newline
1983 STRIP=
1984 \begin_inset Quotes srd
1985 \end_inset
1986
1987 i586-mingw32msvc-strip
1988 \begin_inset Quotes srd
1989 \end_inset
1990
1991  
1992 \backslash
1993
1994 \newline
1995 -
1996 \begin_inset ERT
1997 status Collapsed
1998
1999 \layout Standard
2000
2001
2002 \backslash
2003 /
2004
2005 \end_inset
2006
2007 -prefix=
2008 \begin_inset Quotes srd
2009 \end_inset
2010
2011 /sdcc
2012 \begin_inset Quotes srd
2013 \end_inset
2014
2015  
2016 \backslash
2017
2018 \newline
2019 -
2020 \begin_inset ERT
2021 status Collapsed
2022
2023 \layout Standard
2024
2025
2026 \backslash
2027 /
2028
2029 \end_inset
2030
2031 -datarootdir=
2032 \begin_inset Quotes srd
2033 \end_inset
2034
2035 /sdcc
2036 \begin_inset Quotes srd
2037 \end_inset
2038
2039  
2040 \backslash
2041
2042 \newline
2043 docdir=
2044 \begin_inset Quotes srd
2045 \end_inset
2046
2047
2048 \backslash
2049 ${datarootdir}/doc
2050 \begin_inset Quotes srd
2051 \end_inset
2052
2053  
2054 \backslash
2055
2056 \newline
2057 include_dir_suffix=
2058 \begin_inset Quotes srd
2059 \end_inset
2060
2061 include
2062 \begin_inset Quotes srd
2063 \end_inset
2064
2065  
2066 \backslash
2067
2068 \newline
2069 lib_dir_suffix=
2070 \begin_inset Quotes srd
2071 \end_inset
2072
2073 lib
2074 \begin_inset Quotes srd
2075 \end_inset
2076
2077  
2078 \backslash
2079
2080 \newline
2081 sdccconf_h_dir_separator=
2082 \begin_inset Quotes srd
2083 \end_inset
2084
2085
2086 \backslash
2087
2088 \backslash
2089
2090 \backslash
2091
2092 \backslash
2093
2094 \begin_inset Quotes srd
2095 \end_inset
2096
2097  
2098 \backslash
2099
2100 \newline
2101 -
2102 \begin_inset ERT
2103 status Collapsed
2104
2105 \layout Standard
2106
2107
2108 \backslash
2109 /
2110
2111 \end_inset
2112
2113 -disable-device-lib
2114 \backslash
2115
2116 \newline
2117 -
2118 \begin_inset ERT
2119 status Collapsed
2120
2121 \layout Standard
2122
2123
2124 \backslash
2125 /
2126
2127 \end_inset
2128
2129 -host=i586-mingw32msvc
2130 \backslash
2131
2132 \newline
2133 -
2134 \begin_inset ERT
2135 status Collapsed
2136
2137 \layout Standard
2138
2139
2140 \backslash
2141 /
2142
2143 \end_inset
2144
2145 -build=unknown-unknown-linux-gnu
2146
2147 \layout Standard
2148 To 
2149 \begin_inset Quotes sld
2150 \end_inset
2151
2152 cross
2153 \begin_inset Quotes srd
2154 \end_inset
2155
2156 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2157 ):
2158
2159 \layout LyX-Code
2160 ./configure -C 
2161 \backslash
2162
2163 \newline
2164 -
2165 \begin_inset ERT
2166 status Collapsed
2167
2168 \layout Standard
2169
2170
2171 \backslash
2172 /
2173
2174 \end_inset
2175
2176 -prefix=
2177 \begin_inset Quotes srd
2178 \end_inset
2179
2180 /sdcc
2181 \begin_inset Quotes srd
2182 \end_inset
2183
2184  
2185 \backslash
2186
2187 \newline
2188 -
2189 \begin_inset ERT
2190 status Collapsed
2191
2192 \layout Standard
2193
2194
2195 \backslash
2196 /
2197
2198 \end_inset
2199
2200 -datarootdir=
2201 \begin_inset Quotes srd
2202 \end_inset
2203
2204 /sdcc
2205 \begin_inset Quotes srd
2206 \end_inset
2207
2208  
2209 \backslash
2210
2211 \newline
2212 docdir=
2213 \begin_inset Quotes srd
2214 \end_inset
2215
2216
2217 \backslash
2218 ${datarootdir}/doc
2219 \begin_inset Quotes srd
2220 \end_inset
2221
2222  
2223 \backslash
2224  
2225 \newline
2226 include_dir_suffix=
2227 \begin_inset Quotes srd
2228 \end_inset
2229
2230 include
2231 \begin_inset Quotes srd
2232 \end_inset
2233
2234  
2235 \backslash
2236
2237 \newline
2238 lib_dir_suffix=
2239 \begin_inset Quotes srd
2240 \end_inset
2241
2242 lib
2243 \begin_inset Quotes srd
2244 \end_inset
2245
2246  
2247 \backslash
2248
2249 \newline
2250 sdccconf_h_dir_separator=
2251 \begin_inset Quotes srd
2252 \end_inset
2253
2254
2255 \backslash
2256
2257 \backslash
2258
2259 \backslash
2260
2261 \backslash
2262
2263 \begin_inset Quotes srd
2264 \end_inset
2265
2266  
2267 \backslash
2268
2269 \newline
2270 CC=
2271 \begin_inset Quotes srd
2272 \end_inset
2273
2274 gcc -mno-cygwin
2275 \begin_inset Quotes srd
2276 \end_inset
2277
2278  
2279 \backslash
2280
2281 \newline
2282 CXX=
2283 \begin_inset Quotes srd
2284 \end_inset
2285
2286 g++ -mno-cygwin
2287 \begin_inset Quotes srd
2288 \end_inset
2289
2290  
2291
2292 \layout Standard
2293 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2294  The option '-
2295 \begin_inset ERT
2296 status Collapsed
2297
2298 \layout Standard
2299
2300
2301 \backslash
2302 /
2303
2304 \end_inset
2305
2306 -C' turns on caching, which gives a little bit extra speed.
2307  However if options are changed, it can be necessary to delete the config.cache
2308  file.
2309
2310 \layout Section
2311 Install paths
2312 \added_space_bottom medskip 
2313 \begin_inset LatexCommand \label{sub:Install-paths}
2314
2315 \end_inset
2316
2317
2318 \begin_inset LatexCommand \index{Install paths}
2319
2320 \end_inset
2321
2322
2323
2324
2325 \layout Standard
2326 \align center
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="5" columns="4">
2329 <features>
2330 <column alignment="left" valignment="top" leftline="true" width="0">
2331 <column alignment="left" valignment="top" leftline="true" width="0">
2332 <column alignment="left" valignment="top" leftline="true" width="0">
2333 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2334 <row topline="true" bottomline="true">
2335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2336 \begin_inset Text
2337
2338 \layout Standard
2339
2340 \series bold
2341 Description
2342
2343 \end_inset
2344 </cell>
2345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_inset Text
2347
2348 \layout Standard
2349
2350 \series bold
2351 Path
2352
2353 \end_inset
2354 </cell>
2355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2356 \begin_inset Text
2357
2358 \layout Standard
2359
2360 \series bold
2361 Default
2362
2363 \end_inset
2364 </cell>
2365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2366 \begin_inset Text
2367
2368 \layout Standard
2369
2370 \series bold
2371 Win32 builds
2372
2373 \end_inset
2374 </cell>
2375 </row>
2376 <row topline="true">
2377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2378 \begin_inset Text
2379
2380 \layout Standard
2381 Binary files*
2382
2383 \end_inset
2384 </cell>
2385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2386 \begin_inset Text
2387
2388 \layout Standard
2389
2390 \emph on
2391 $EXEC_PREFIX
2392
2393 \end_inset
2394 </cell>
2395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2396 \begin_inset Text
2397
2398 \layout Standard
2399 /usr/local/bin
2400
2401 \end_inset
2402 </cell>
2403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2404 \begin_inset Text
2405
2406 \layout Standard
2407
2408 \backslash
2409 sdcc
2410 \backslash
2411 bin
2412
2413 \end_inset
2414 </cell>
2415 </row>
2416 <row topline="true">
2417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2418 \begin_inset Text
2419
2420 \layout Standard
2421 Include files
2422
2423 \end_inset
2424 </cell>
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2426 \begin_inset Text
2427
2428 \layout Standard
2429
2430 \emph on
2431 $DATADIR/ $INCLUDE_DIR_SUFFIX
2432
2433 \end_inset
2434 </cell>
2435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2436 \begin_inset Text
2437
2438 \layout Standard
2439 /usr/local/share/sdcc/include
2440
2441 \end_inset
2442 </cell>
2443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2444 \begin_inset Text
2445
2446 \layout Standard
2447
2448 \backslash
2449 sdcc
2450 \backslash
2451 include
2452
2453 \end_inset
2454 </cell>
2455 </row>
2456 <row topline="true">
2457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2458 \begin_inset Text
2459
2460 \layout Standard
2461 Library file**
2462
2463 \end_inset
2464 </cell>
2465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2466 \begin_inset Text
2467
2468 \layout Standard
2469
2470 \emph on
2471 $DATADIR/$LIB_DIR_SUFFIX
2472
2473 \end_inset
2474 </cell>
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479 /usr/local/share/sdcc/lib
2480
2481 \end_inset
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 \backslash
2489 sdcc
2490 \backslash
2491 lib
2492
2493 \end_inset
2494 </cell>
2495 </row>
2496 <row topline="true" bottomline="true">
2497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2498 \begin_inset Text
2499
2500 \layout Standard
2501 Documentation
2502
2503 \end_inset
2504 </cell>
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2506 \begin_inset Text
2507
2508 \layout Standard
2509
2510 \emph on
2511 $DOCDIR
2512
2513 \end_inset
2514 </cell>
2515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2516 \begin_inset Text
2517
2518 \layout Standard
2519 /usr/local/share/sdcc/doc
2520
2521 \end_inset
2522 </cell>
2523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2524 \begin_inset Text
2525
2526 \layout Standard
2527
2528 \backslash
2529 sdcc
2530 \backslash
2531 doc
2532
2533 \end_inset
2534 </cell>
2535 </row>
2536 </lyxtabular>
2537
2538 \end_inset
2539
2540
2541
2542 \layout Verse
2543
2544 \size footnotesize
2545 *compiler, preprocessor, assembler, and linker
2546 \newline
2547 **the 
2548 \shape italic
2549 model
2550 \shape default
2551  is auto-appended by the compiler, e.g.
2552  small, large, z80, ds390 etc
2553
2554 \layout Standard
2555 \noindent
2556 The install paths can still be changed during `make install` with e.g.:
2557
2558 \layout LyX-Code
2559 make install prefix=$(HOME)/local/sdcc
2560
2561 \layout Standard
2562 Of course this doesn't change the search paths compiled into the binaries.
2563 \newline
2564
2565 \newline
2566 Moreove
2567 r the install path can be changed by defining DESTDIR
2568 \begin_inset LatexCommand \index{DESTDIR}
2569
2570 \end_inset
2571
2572 :
2573
2574 \layout LyX-Code
2575 make install DESTDIR=$(HOME)/sdcc.rpm/
2576
2577 \layout Standard
2578 Please note that DESTDIR must have a trailing slash!
2579
2580 \layout Section
2581 Search Paths
2582 \begin_inset LatexCommand \label{sub:Search-Paths}
2583
2584 \end_inset
2585
2586
2587 \begin_inset LatexCommand \index{Search path}
2588
2589 \end_inset
2590
2591
2592
2593 \layout Standard
2594 Some search paths or parts of them are determined by configure variables
2595  (in 
2596 \emph on
2597 italics
2598 \emph default
2599 , see section above).
2600  Further search paths are determined by environment variables during runtime.
2601  
2602 \newline
2603 The paths searched when running the compiler are as follows (the first
2604  catch wins):
2605 \newline
2606
2607 \newline
2608 1.
2609  Binary files (preprocessor, assembler and linker)
2610 \newline
2611
2612
2613 \layout Standard
2614 \align center
2615 \begin_inset Tabular
2616 <lyxtabular version="3" rows="4" columns="3">
2617 <features>
2618 <column alignment="block" valignment="top" leftline="true" width="0in">
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2621 <row topline="true" bottomline="true">
2622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2623 \begin_inset Text
2624
2625 \layout Standard
2626 Search path
2627
2628 \end_inset
2629 </cell>
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634 default
2635
2636 \end_inset
2637 </cell>
2638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2639 \begin_inset Text
2640
2641 \layout Standard
2642 Win32 builds
2643
2644 \end_inset
2645 </cell>
2646 </row>
2647 <row topline="true">
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652 $SDCC_HOME/
2653 \emph on
2654 $PPREFIX2BIN_DIR
2655
2656 \end_inset
2657 </cell>
2658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_inset Text
2660
2661 \layout Standard
2662 $SDCC_HOME/bin
2663
2664 \end_inset
2665 </cell>
2666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2667 \begin_inset Text
2668
2669 \layout Standard
2670 $SDCC_HOME
2671 \backslash
2672 bin
2673
2674 \end_inset
2675 </cell>
2676 </row>
2677 <row topline="true">
2678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2679 \begin_inset Text
2680
2681 \layout Standard
2682 Path of argv[0] (if available)
2683
2684 \end_inset
2685 </cell>
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2687 \begin_inset Text
2688
2689 \layout Standard
2690 Path of argv[0]
2691
2692 \end_inset
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698 Path of argv[0]
2699
2700 \end_inset
2701 </cell>
2702 </row>
2703 <row topline="true" bottomline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2705 \begin_inset Text
2706
2707 \layout Standard
2708 $PATH
2709
2710 \end_inset
2711 </cell>
2712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2713 \begin_inset Text
2714
2715 \layout Standard
2716 $PATH
2717
2718 \end_inset
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \layout Standard
2724 $PATH
2725
2726 \end_inset
2727 </cell>
2728 </row>
2729 </lyxtabular>
2730
2731 \end_inset
2732
2733  
2734 \newline
2735
2736
2737 \layout Standard
2738 \noindent
2739 2.
2740  Include files
2741 \newline
2742
2743
2744 \layout Standard
2745 \align center
2746 \begin_inset Tabular
2747 <lyxtabular version="3" rows="6" columns="3">
2748 <features>
2749 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2752 <row topline="true" bottomline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2754 \begin_inset Text
2755
2756 \layout Standard
2757 Search path
2758
2759 \end_inset
2760 </cell>
2761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2762 \begin_inset Text
2763
2764 \layout Standard
2765 default
2766
2767 \end_inset
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \layout Standard
2773 Win32 builds
2774
2775 \end_inset
2776 </cell>
2777 </row>
2778 <row topline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2780 \begin_inset Text
2781
2782 \layout Standard
2783 -
2784 \begin_inset ERT
2785 status Collapsed
2786
2787 \layout Standard
2788
2789
2790 \backslash
2791 /
2792
2793 \end_inset
2794
2795 -I dir
2796
2797 \end_inset
2798 </cell>
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 \begin_inset Text
2801
2802 \layout Standard
2803 -
2804 \begin_inset ERT
2805 status Collapsed
2806
2807 \layout Standard
2808
2809
2810 \backslash
2811 /
2812
2813 \end_inset
2814
2815 -I dir
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 \begin_inset ERT
2825 status Collapsed
2826
2827 \layout Standard
2828
2829
2830 \backslash
2831 /
2832
2833 \end_inset
2834
2835 -I dir
2836
2837 \end_inset
2838 </cell>
2839 </row>
2840 <row topline="true">
2841 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2842 \begin_inset Text
2843
2844 \layout Standard
2845 $SDCC_INCLUDE
2846
2847 \end_inset
2848 </cell>
2849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2850 \begin_inset Text
2851
2852 \layout Standard
2853 $SDCC_INCLUDE
2854
2855 \end_inset
2856 </cell>
2857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2858 \begin_inset Text
2859
2860 \layout Standard
2861 $SDCC_INCLUDE
2862
2863 \end_inset
2864 </cell>
2865 </row>
2866 <row topline="true">
2867 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2868 \begin_inset Text
2869
2870 \layout Standard
2871 $SDCC_HOME/
2872 \newline
2873
2874 \emph on
2875 $PREFIX2DATA_DIR/
2876 \newline
2877 $INCLUDE_DIR_SUFFIX
2878
2879 \end_inset
2880 </cell>
2881 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2882 \begin_inset Text
2883
2884 \layout Standard
2885 $SDCC_ HOME/
2886 \newline
2887 share/sdcc/
2888 \newline
2889 include
2890
2891 \end_inset
2892 </cell>
2893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2894 \begin_inset Text
2895
2896 \layout Standard
2897 $SDCC_HOME
2898 \backslash
2899 include
2900
2901 \end_inset
2902 </cell>
2903 </row>
2904 <row topline="true">
2905 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \layout Standard
2909 path(argv[0])/
2910 \newline
2911
2912 \emph on
2913 $BIN2DATADIR/
2914 \emph default
2915
2916 \newline
2917
2918 \emph on
2919 $INCLUDE_DIR_SUFFIX
2920
2921 \end_inset
2922 </cell>
2923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2924 \begin_inset Text
2925
2926 \layout Standard
2927 path(argv[0])/
2928 \newline
2929 ../sdcc/include
2930 \newline
2931 \SpecialChar ~
2932 \SpecialChar ~
2933 \SpecialChar ~
2934 \SpecialChar ~
2935 \SpecialChar ~
2936 \SpecialChar ~
2937 \SpecialChar ~
2938 \SpecialChar ~
2939 \SpecialChar ~
2940 \SpecialChar ~
2941 \SpecialChar ~
2942 \SpecialChar ~
2943 \SpecialChar ~
2944 \SpecialChar ~
2945 \SpecialChar ~
2946 \SpecialChar ~
2947 \SpecialChar ~
2948 \SpecialChar ~
2949 \SpecialChar ~
2950 \SpecialChar ~
2951 \SpecialChar ~
2952 \SpecialChar ~
2953 \SpecialChar ~
2954 \SpecialChar ~
2955 \SpecialChar ~
2956 \SpecialChar ~
2957 \SpecialChar ~
2958 \SpecialChar ~
2959 \SpecialChar ~
2960 \SpecialChar ~
2961 \SpecialChar ~
2962 \SpecialChar ~
2963 \SpecialChar ~
2964 \SpecialChar ~
2965 \SpecialChar ~
2966 \SpecialChar ~
2967 \SpecialChar ~
2968 \SpecialChar ~
2969
2970
2971 \end_inset
2972 </cell>
2973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2974 \begin_inset Text
2975
2976 \layout Standard
2977 path(argv[0])
2978 \backslash
2979 ..
2980 \backslash
2981 include
2982
2983 \end_inset
2984 </cell>
2985 </row>
2986 <row topline="true" bottomline="true">
2987 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \layout Standard
2991
2992 \emph on
2993 $DATADIR/
2994 \emph default
2995
2996 \newline
2997
2998 \emph on
2999 $INCLUDE_DIR_SUFFIX
3000
3001 \end_inset
3002 </cell>
3003 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3004 \begin_inset Text
3005
3006 \layout Standard
3007 /usr/local/share/sdcc/
3008 \newline
3009 include
3010
3011 \end_inset
3012 </cell>
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3014 \begin_inset Text
3015
3016 \layout Standard
3017 (not on Win32)
3018
3019 \end_inset
3020 </cell>
3021 </row>
3022 </lyxtabular>
3023
3024 \end_inset
3025
3026  
3027 \newline
3028
3029
3030 \layout Standard
3031 \noindent
3032 The option -
3033 \begin_inset ERT
3034 status Collapsed
3035
3036 \layout Standard
3037
3038
3039 \backslash
3040 /
3041
3042 \end_inset
3043
3044 -nostdinc disables the last two search paths.
3045 \newline
3046
3047 \newline
3048 3.
3049  Library files 
3050 \newline
3051
3052
3053 \layout Standard
3054 With the exception of 
3055 \begin_inset Quotes sld
3056 \end_inset
3057
3058 -
3059 \begin_inset ERT
3060 status Collapsed
3061
3062 \layout Standard
3063
3064
3065 \backslash
3066 /
3067
3068 \end_inset
3069
3070 -L dir
3071 \begin_inset Quotes srd
3072 \end_inset
3073
3074  the 
3075 \shape italic
3076 model
3077 \shape default
3078  is auto-appended by the compiler (e.g.
3079  small, large, z80, ds390 etc.).
3080  
3081 \newline
3082
3083
3084 \layout Standard
3085 \align center
3086 \begin_inset Tabular
3087 <lyxtabular version="3" rows="6" columns="3">
3088 <features>
3089 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3090 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3091 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3092 <row topline="true" bottomline="true">
3093 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_inset Text
3095
3096 \layout Standard
3097 Search path
3098
3099 \end_inset
3100 </cell>
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3102 \begin_inset Text
3103
3104 \layout Standard
3105 default
3106
3107 \end_inset
3108 </cell>
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3110 \begin_inset Text
3111
3112 \layout Standard
3113 Win32 builds
3114
3115 \end_inset
3116 </cell>
3117 </row>
3118 <row topline="true">
3119 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3120 \begin_inset Text
3121
3122 \layout Standard
3123 -
3124 \begin_inset ERT
3125 status Collapsed
3126
3127 \layout Standard
3128
3129
3130 \backslash
3131 /
3132
3133 \end_inset
3134
3135 -L dir
3136
3137 \end_inset
3138 </cell>
3139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_inset Text
3141
3142 \layout Standard
3143 -
3144 \begin_inset ERT
3145 status Collapsed
3146
3147 \layout Standard
3148
3149
3150 \backslash
3151 /
3152
3153 \end_inset
3154
3155 -L dir
3156
3157 \end_inset
3158 </cell>
3159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3160 \begin_inset Text
3161
3162 \layout Standard
3163 -
3164 \begin_inset ERT
3165 status Collapsed
3166
3167 \layout Standard
3168
3169
3170 \backslash
3171 /
3172
3173 \end_inset
3174
3175 -L dir
3176
3177 \end_inset
3178 </cell>
3179 </row>
3180 <row topline="true">
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3182 \begin_inset Text
3183
3184 \layout Standard
3185 $SDCC_LIB/
3186 \newline
3187
3188 \emph on
3189 <model>
3190
3191 \end_inset
3192 </cell>
3193 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3194 \begin_inset Text
3195
3196 \layout Standard
3197 $SDCC_LIB/
3198 \newline
3199
3200 \emph on
3201 <model>
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \layout Standard
3209 $SDCC_LIB
3210 \backslash
3211
3212 \newline
3213
3214 \emph on
3215 <model>
3216
3217 \end_inset
3218 </cell>
3219 </row>
3220 <row topline="true">
3221 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3222 \begin_inset Text
3223
3224 \layout Standard
3225 $SDCC_HOME/
3226 \newline
3227
3228 \emph on
3229 $PREFIX2DATA_DIR/
3230 \newline
3231 $LIB_DIR_SUFFIX/<model>
3232
3233 \end_inset
3234 </cell>
3235 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3236 \begin_inset Text
3237
3238 \layout Standard
3239 $SDCC_HOME/
3240 \newline
3241 share/sdcc/
3242 \newline
3243 lib/
3244 \emph on
3245 <model>
3246
3247 \end_inset
3248 </cell>
3249 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3250 \begin_inset Text
3251
3252 \layout Standard
3253 $SDCC_HOME
3254 \backslash
3255 lib
3256 \backslash
3257
3258 \emph on
3259
3260 \newline
3261 <model>
3262
3263 \end_inset
3264 </cell>
3265 </row>
3266 <row topline="true">
3267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3268 \begin_inset Text
3269
3270 \layout Standard
3271 path(argv[0])/
3272 \newline
3273
3274 \emph on
3275 $BIN2DATADIR/
3276 \emph default
3277
3278 \newline
3279
3280 \emph on
3281 $LIB_DIR_SUFFIX/<model>
3282
3283 \end_inset
3284 </cell>
3285 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3286 \begin_inset Text
3287
3288 \layout Standard
3289 path(argv[0])/
3290 \newline
3291 ../sdcc/lib/
3292 \emph on
3293 <model>
3294 \newline
3295 \SpecialChar ~
3296 \SpecialChar ~
3297 \SpecialChar ~
3298 \SpecialChar ~
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 \SpecialChar ~
3302 \SpecialChar ~
3303 \SpecialChar ~
3304 \SpecialChar ~
3305 \SpecialChar ~
3306 \SpecialChar ~
3307 \SpecialChar ~
3308 \SpecialChar ~
3309 \SpecialChar ~
3310 \SpecialChar ~
3311 \SpecialChar ~
3312 \SpecialChar ~
3313 \SpecialChar ~
3314 \SpecialChar ~
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 \SpecialChar ~
3318 \SpecialChar ~
3319 \SpecialChar ~
3320 \SpecialChar ~
3321 \SpecialChar ~
3322 \SpecialChar ~
3323 \SpecialChar ~
3324 \SpecialChar ~
3325 \SpecialChar ~
3326 \SpecialChar ~
3327 \SpecialChar ~
3328 \SpecialChar ~
3329 \SpecialChar ~
3330 \SpecialChar ~
3331 \SpecialChar ~
3332 \SpecialChar ~
3333 \SpecialChar ~
3334
3335
3336 \end_inset
3337 </cell>
3338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3339 \begin_inset Text
3340
3341 \layout Standard
3342 path(argv[0])
3343 \backslash
3344
3345 \newline
3346 ..
3347 \backslash
3348 lib
3349 \backslash
3350
3351 \emph on
3352 <model>
3353 \newline
3354 \SpecialChar ~
3355 \SpecialChar ~
3356 \SpecialChar ~
3357 \SpecialChar ~
3358 \SpecialChar ~
3359 \SpecialChar ~
3360 \SpecialChar ~
3361 \SpecialChar ~
3362 \SpecialChar ~
3363 \SpecialChar ~
3364 \SpecialChar ~
3365 \SpecialChar ~
3366 \SpecialChar ~
3367 \SpecialChar ~
3368 \SpecialChar ~
3369 \SpecialChar ~
3370 \SpecialChar ~
3371 \SpecialChar ~
3372 \SpecialChar ~
3373 \SpecialChar ~
3374 \SpecialChar ~
3375 \SpecialChar ~
3376 \SpecialChar ~
3377 \SpecialChar ~
3378 \SpecialChar ~
3379 \SpecialChar ~
3380 \SpecialChar ~
3381 \SpecialChar ~
3382 \SpecialChar ~
3383 \SpecialChar ~
3384 \SpecialChar ~
3385 \SpecialChar ~
3386 \SpecialChar ~
3387 \SpecialChar ~
3388 \SpecialChar ~
3389
3390
3391 \end_inset
3392 </cell>
3393 </row>
3394 <row topline="true" bottomline="true">
3395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3396 \begin_inset Text
3397
3398 \layout Standard
3399
3400 \emph on
3401 $DATADIR/
3402 \newline
3403 $LIB_DIR_SUFFIX/<model>
3404
3405 \end_inset
3406 </cell>
3407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \layout Standard
3411 /usr/local/share/sdcc/
3412 \newline
3413 lib/
3414 \emph on
3415 <model>
3416
3417 \end_inset
3418 </cell>
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3420 \begin_inset Text
3421
3422 \layout Standard
3423 (not on Win32)
3424
3425 \end_inset
3426 </cell>
3427 </row>
3428 </lyxtabular>
3429
3430 \end_inset
3431
3432
3433 \newline
3434
3435
3436 \layout Standard
3437 \begin_inset Note
3438 collapsed true
3439
3440 \layout Standard
3441 Don't delete any of the stray spaces in the table above without checking
3442  the HTML output (last line)!
3443
3444 \end_inset
3445
3446
3447
3448 \layout Standard
3449 \SpecialChar ~
3450
3451 \newline
3452 The option -
3453 \begin_inset ERT
3454 status Collapsed
3455
3456 \layout Standard
3457
3458
3459 \backslash
3460 /
3461
3462 \end_inset
3463
3464 -nostdlib disables the last two search paths.
3465
3466 \layout Section
3467 Building SDCC
3468 \begin_inset LatexCommand \index{Building SDCC}
3469
3470 \end_inset
3471
3472
3473
3474 \layout Subsection
3475 Building SDCC on Linux
3476 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3477
3478 \end_inset
3479
3480
3481
3482 \layout Enumerate
3483
3484 \series medium
3485 Download the source package
3486 \series default
3487  either from the SDCC Subversion repository or from the nightly snapshots
3488 \series medium
3489 , it will be named something like sdcc
3490 \series default
3491 .src
3492 \series medium
3493 .t
3494 \series default
3495 ar.
3496 \series medium
3497 gz
3498 \series default
3499  
3500 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3501
3502 \end_inset
3503
3504 .
3505
3506 \layout Enumerate
3507
3508 \series medium
3509 Bring up a command line terminal, such as xterm.
3510
3511 \layout Enumerate
3512
3513 \series medium
3514 Unpack the file using a command like: 
3515 \family sans
3516 \series bold
3517 "tar -xvzf sdcc.src.tar.gz
3518 \family default
3519 \series default
3520 "
3521 \series medium
3522 , this will create a sub-directory called sdcc with all of the sources.
3523
3524 \layout Enumerate
3525 Change directory into the main SDCC directory, for example type: 
3526 \family sans
3527 \series bold
3528 "cd sdcc
3529 \series default
3530 ".
3531
3532 \layout Enumerate
3533
3534 \series medium
3535 Type 
3536 \family sans
3537 \series bold
3538 "./configure
3539 \family default
3540 \series default
3541 ".
3542  This configures the package for compilation on your system.
3543
3544 \layout Enumerate
3545
3546 \series medium
3547 Type 
3548 \family sans
3549 \series bold
3550 "make
3551 \family default
3552 \series default
3553 "
3554 \series medium
3555 .
3556
3557 \series default
3558  All of the source packages will compile, this can take a while.
3559
3560 \layout Enumerate
3561
3562 \series medium
3563 Type 
3564 \family sans
3565 \series bold
3566 "make install"
3567 \family default
3568 \series default
3569  as root
3570 \series medium
3571 .
3572
3573 \series default
3574  This copies the binary executables, the include files, the libraries and
3575  the documentation to the install directories.
3576  Proceed with section 
3577 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3578
3579 \end_inset
3580
3581 .
3582
3583 \layout Subsection
3584 Building SDCC on OSX 2.x
3585
3586 \layout Standard
3587 Follow the instruction for Linux.
3588 \newline
3589
3590 \newline
3591 On OSX 2.x it was reported, that the default
3592  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3593  Fortunately there's also gcc 2.9.x installed, which works fine.
3594  This compiler can be selected by running 'configure' with:
3595
3596 \layout LyX-Code
3597 ./configure CC=gcc2 CXX=g++2
3598
3599 \layout Subsection
3600 Cross compiling SDCC on Linux for Windows
3601
3602 \layout Standard
3603 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3604  See section 'Configure Options'.
3605
3606 \layout Subsection
3607 Building SDCC using Cygwin and Mingw32
3608
3609 \layout Standard
3610 For building and installing a Cygwin executable follow the instructions
3611  for Linux.
3612 \newline
3613
3614 \newline
3615 On Cygwin a 
3616 \begin_inset Quotes sld
3617 \end_inset
3618
3619 native
3620 \begin_inset Quotes srd
3621 \end_inset
3622
3623  Win32-binary can be built, which will not need the Cygwin-DLL.
3624  For the necessary 'configure' options see section 'configure options' or
3625  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3626 \newline
3627
3628 \newline
3629 In order to install
3630  Cygwin on Windows download setup.exe from 
3631 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3632
3633 \end_inset
3634
3635 .
3636  Run it, set the 
3637 \begin_inset Quotes sld
3638 \end_inset
3639
3640 default text file type
3641 \begin_inset Quotes srd
3642 \end_inset
3643
3644  to 
3645 \begin_inset Quotes sld
3646 \end_inset
3647
3648 unix
3649 \begin_inset Quotes srd
3650 \end_inset
3651
3652  and download/install at least the following packages.
3653  Some packages are selected by default, others will be automatically selected
3654  because of dependencies with the manually selected packages.
3655  Never deselect these packages!
3656
3657 \layout Itemize
3658 flex
3659
3660 \layout Itemize
3661 bison
3662
3663 \layout Itemize
3664 gcc ; version 3.x is fine, no need to use the old 2.9x
3665
3666 \layout Itemize
3667 binutils ; selected with gcc
3668
3669 \layout Itemize
3670 make
3671
3672 \layout Itemize
3673 rxvt ; a nice console, which makes life much easier under windoze (see below)
3674
3675 \layout Itemize
3676 man ; not really needed for building SDCC, but you'll miss it sooner or
3677  later
3678
3679 \layout Itemize
3680 less ; not really needed for building SDCC, but you'll miss it sooner or
3681  later
3682
3683 \layout Itemize
3684 svn ; only if you use Subversion access
3685
3686 \layout Standard
3687 If you want to develop something you'll need:
3688
3689 \layout Itemize
3690 python ; for the regression tests
3691
3692 \layout Itemize
3693 gdb ; the gnu debugger, together with the nice GUI 
3694 \begin_inset Quotes sld
3695 \end_inset
3696
3697 insight
3698 \begin_inset Quotes srd
3699 \end_inset
3700
3701
3702
3703 \layout Itemize
3704 openssh ; to access the CF or commit changes
3705
3706 \layout Itemize
3707 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3708  use autoconf-stable!
3709
3710 \layout Standard
3711 rxvt is a nice console with history.
3712  Replace in your cygwin.bat the line
3713
3714 \layout LyX-Code
3715 bash -
3716 \begin_inset ERT
3717 status Collapsed
3718
3719 \layout Standard
3720
3721
3722 \backslash
3723 /
3724
3725 \end_inset
3726
3727 -login -i 
3728
3729 \layout Standard
3730 with (one line):
3731
3732 \layout LyX-Code
3733 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3734
3735 \layout LyX-Code
3736      -bg black -fg white -geometry 100x65 -e bash -
3737 \begin_inset ERT
3738 status Collapsed
3739
3740 \layout Standard
3741
3742
3743 \backslash
3744 /
3745
3746 \end_inset
3747
3748 -login
3749
3750 \layout Standard
3751 Text selected with the mouse is automatically copied to the clipboard, pasting
3752  works with shift-insert.
3753 \newline
3754
3755 \newline
3756 The other good tip is to make sure you have no //c/-styl
3757 e paths anywhere, use /cygdrive/c/ instead.
3758  Using // invokes a network lookup which is very slow.
3759  If you think 
3760 \begin_inset Quotes sld
3761 \end_inset
3762
3763 cygdrive
3764 \begin_inset Quotes srd
3765 \end_inset
3766
3767  is too long, you can change it with e.g.
3768
3769 \layout LyX-Code
3770 mount -s -u -c /mnt
3771
3772 \layout Standard
3773 SDCC sources use the unix line ending LF.
3774  Life is much easier, if you store the source tree on a drive which is mounted
3775  in binary mode.
3776  And use an editor which can handle LF-only line endings.
3777  Make sure not to commit files with windows line endings.
3778  The tabulator spacing
3779 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3780
3781 \end_inset
3782
3783  used in the project is 8.
3784  Although a tabulator spacing of 8 is a sensible choice for programmers
3785  (it's a power of 2 and allows to display 8/16 bit signed variables without
3786  loosing columns) the plan is to move towards using only spaces in the source.
3787
3788 \layout Subsection
3789 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3790
3791 \layout Standard
3792
3793 \series medium
3794 Download the source package
3795 \series default
3796  either from the SDCC Subversion repository or from the 
3797 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3798
3799 \end_inset
3800
3801
3802 \series medium
3803 , it will be named something like sdcc
3804 \series default
3805 .src
3806 \series medium
3807 .tgz.
3808
3809 \series default
3810  SDCC is distributed with all the projects, workspaces, and files you need
3811  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3812  The workspace name is 'sdcc.dsw'.
3813  Please note that as it is now, all the executables are created in a folder
3814  called sdcc
3815 \backslash
3816 bin_vc.
3817  Once built you need to copy the executables from sdcc
3818 \backslash
3819 bin_vc to sdcc
3820 \backslash
3821 bin before running SDCC.
3822  
3823 \newline
3824
3825 \newline
3826 WARNING: Visual studio is very picky with line terminations; it expects
3827  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3828  When using the Subversion repository it's easiest to configure the svn
3829  client to convert automatically for you.
3830  If however you are getting a message such as "This makefile was not generated
3831  by Developer Studio etc.
3832  etc.
3833 \begin_inset Quotes srd
3834 \end_inset
3835
3836  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3837  need to convert the Unix style line endings to DOS style line endings.
3838  To do so you can use the 
3839 \begin_inset Quotes sld
3840 \end_inset
3841
3842 unix2dos
3843 \begin_inset Quotes srd
3844 \end_inset
3845
3846  utility freely available on the internet.
3847  Doug Hawkins reported in the sdcc-user list that this works:
3848 \newline
3849
3850 \newline
3851 C:
3852 \backslash
3853 Programming
3854 \backslash
3855 SDCC> unix2dos sdcc.dsw
3856 \newline
3857 C:
3858 \backslash
3859 Programming
3860 \backslash
3861 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3862 \newline
3863
3864 \newline
3865 In order to build SDCC with MSVC
3866  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3867  One good place to get them is 
3868 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3869
3870 \end_inset
3871
3872
3873 \newline
3874
3875 \newline
3876 Download the file UnxUtils
3877 \begin_inset LatexCommand \index{UnxUtils}
3878
3879 \end_inset
3880
3881 .zip.
3882  Now you have to install the utilities and setup MSVC so it can locate the
3883  required programs.
3884  Here there are two alternatives (choose one!):
3885
3886 \layout Enumerate
3887 The easy way:
3888 \newline
3889
3890 \newline
3891 a) Extract UnxUtils.zip to your C:
3892 \backslash
3893  hard disk PRESERVING the original paths, otherwise bison won't work.
3894  (If you are using WinZip make certain that 'Use folder names' is selected)
3895 \newline
3896
3897 \newline
3898 b)
3899  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3900  'Show directories for:' select 'Executable files', and in the directories
3901  window add a new path: 'C:
3902 \backslash
3903 user
3904 \backslash
3905 local
3906 \backslash
3907 wbin', click ok.
3908 \newline
3909
3910 \newline
3911 (As a side effect, you get a bunch of Unix utilities that
3912  could be useful, such as diff and patch.)
3913
3914 \layout Enumerate
3915 A more compact way:
3916 \newline
3917
3918 \newline
3919 This one avoids extracting a bunch of files you may not
3920  use, but requires some extra work:
3921 \newline
3922
3923 \newline
3924 a) Create a directory were to put the
3925  tools needed, or use a directory already present.
3926  Say for example 'C:
3927 \backslash
3928 util'.
3929 \newline
3930
3931 \newline
3932 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3933  gawk.exe to such directory WITHOUT preserving the original paths.
3934  (If you are using WinZip make certain that 'Use folder names' is not selected)
3935 \newline
3936
3937 \newline
3938 c
3939 ) Rename bison.exe to '_bison.exe'.
3940 \newline
3941
3942 \newline
3943 d) Create a batch file 'bison.bat' in 'C:
3944 \backslash
3945 util
3946 \backslash
3947 ' and add these lines: 
3948 \newline
3949 \SpecialChar ~
3950 \SpecialChar ~
3951 set BISON_SIMPLE=C:
3952 \backslash
3953 util
3954 \backslash
3955 bison.simple 
3956 \newline
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 set BISON_HAIRY=C:
3960 \backslash
3961 util
3962 \backslash
3963 bison.hairy
3964 \newline
3965 \SpecialChar ~
3966 \SpecialChar ~
3967 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3968 \newline
3969
3970 \newline
3971 Steps 'c' and 'd' are needed
3972  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3973  reside in some weird Unix directory, '/usr/local/share/' I think.
3974  So it is necessary to tell bison where those files are located if they
3975  are not in such directory.
3976  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3977 \newline
3978
3979 \newline
3980 e
3981 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3982  in 'Show directories for:' select 'Executable files', and in the directories
3983  window add a new path: 'c:
3984 \backslash
3985 util', click ok.
3986  Note that you can use any other path instead of 'c:
3987 \backslash
3988 util', even the path where the Visual C++ tools are, probably: 'C:
3989 \backslash
3990 Program Files
3991 \backslash
3992 Microsoft Visual Studio
3993 \backslash
3994 Common
3995 \backslash
3996 Tools'.
3997  So you don't have to execute step 'e' :)
3998
3999 \layout Standard
4000 That is it.
4001  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4002  the executables from sdcc
4003 \backslash
4004 bin_vc to sdcc
4005 \backslash
4006 bin, and you can compile using SDCC.
4007
4008 \layout Subsection
4009 Building SDCC Using Borland
4010
4011 \layout Enumerate
4012 From the sdcc directory, run the command "make -f Makefile.bcc".
4013  This should regenerate all the .exe files in the bin directory except for
4014  SDCDB and ucSim.
4015
4016 \layout Enumerate
4017 If you modify any source files and need to rebuild, be aware that the dependenci
4018 es may not be correctly calculated.
4019  The safest option is to delete all .obj files and run the build again.
4020  From a Cygwin BASH prompt, this can easily be done with the command (be
4021  sure you are in the sdcc directory):
4022 \newline
4023
4024 \newline
4025
4026 \family sans
4027 \series bold
4028 find .
4029  
4030 \backslash
4031 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4032 \backslash
4033 ) -print -exec rm {} 
4034 \backslash
4035 ;
4036 \family default
4037 \series default
4038
4039 \newline
4040
4041 \newline
4042 or on Windows NT/2000/XP from the command prompt with the command:
4043 \newline
4044
4045 \family sans
4046 \series bold
4047
4048 \newline
4049 del /s *.obj *.lib *.rul
4050 \family default
4051 \series default
4052  from the sdcc directory.
4053
4054 \layout Subsection
4055 Windows Install Using a ZIP Package
4056
4057 \layout Enumerate
4058 Download the binary zip package from 
4059 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4060
4061 \end_inset
4062
4063  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4064  This should unpack to a group of sub-directories.
4065  An example directory structure after unpacking the mingw32 package is:
4066  c:
4067 \backslash
4068 sdcc
4069 \backslash
4070 bin for the executables, c:
4071 \backslash
4072 sdcc
4073 \backslash
4074 include and c:
4075 \backslash
4076 sdcc
4077 \backslash
4078 lib for the include and libraries.
4079
4080 \layout Enumerate
4081 Adjust your environment variable PATH to include the location of the bin
4082  directory or start sdcc using the full path.
4083
4084 \layout Subsection
4085 Windows Install Using the Setup Program
4086 \begin_inset LatexCommand \label{sub:Windows-Install}
4087
4088 \end_inset
4089
4090
4091
4092 \layout Standard
4093 Download the setup program 
4094 \emph on
4095 sdcc-x.y.z-setup.exe
4096 \emph default
4097  for an official release from 
4098 \newline
4099
4100 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4101
4102 \end_inset
4103
4104  or a setup program for one of the snapshots 
4105 \emph on
4106 sdcc-yyyymmdd-xxxx-setup.exe
4107 \emph default
4108  from 
4109 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4110
4111 \end_inset
4112
4113  and execute it.
4114  A windows typical installer will guide you through the installation process.
4115
4116 \layout Subsection
4117 VPATH
4118 \begin_inset LatexCommand \index{VPATH}
4119
4120 \end_inset
4121
4122  feature
4123
4124 \layout Standard
4125 SDCC supports the VPATH feature provided by configure and make.
4126  It allows to separate the source and build trees.
4127  Here's an example:
4128
4129 \layout Standard
4130
4131 \family typewriter
4132 cd ~\SpecialChar ~
4133 \SpecialChar ~
4134 \SpecialChar ~
4135 \SpecialChar ~
4136 \SpecialChar ~
4137 \SpecialChar ~
4138 \SpecialChar ~
4139 \SpecialChar ~
4140 \SpecialChar ~
4141 \SpecialChar ~
4142 \SpecialChar ~
4143 \SpecialChar ~
4144 \SpecialChar ~
4145 \SpecialChar ~
4146 \SpecialChar ~
4147 \SpecialChar ~
4148 \SpecialChar ~
4149 \SpecialChar ~
4150 \SpecialChar ~
4151 \SpecialChar ~
4152 \SpecialChar ~
4153 # cd $HOME
4154
4155 \layout Standard
4156
4157 \family typewriter
4158 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4159 # extract source to directory sdcc
4160
4161 \layout Standard
4162
4163 \family typewriter
4164 mkdir sdcc.build\SpecialChar ~
4165 \SpecialChar ~
4166 \SpecialChar ~
4167 \SpecialChar ~
4168 \SpecialChar ~
4169 \SpecialChar ~
4170 \SpecialChar ~
4171 \SpecialChar ~
4172 \SpecialChar ~
4173 # put output in sdcc.build
4174
4175 \layout Standard
4176
4177 \family typewriter
4178 cd sdcc.build
4179
4180 \layout Standard
4181
4182 \family typewriter
4183 ../sdcc/configure\SpecialChar ~
4184 \SpecialChar ~
4185 \SpecialChar ~
4186 \SpecialChar ~
4187 \SpecialChar ~
4188 \SpecialChar ~
4189 \SpecialChar ~
4190 \SpecialChar ~
4191 # configure is doing all the magic!
4192
4193 \layout Standard
4194
4195 \family typewriter
4196 make
4197
4198 \layout Standard
4199 \noindent
4200 That's it! 
4201 \series bold
4202 configure
4203 \series default
4204  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4205  It automagically computes the variables srcdir, top_srcdir and top_buildir
4206  for each directory.
4207  After running 
4208 \series bold
4209 make
4210 \series default
4211  the generated files will be in ~/sdcc.build, while the source files stay
4212  in ~/sdcc.
4213 \newline
4214 This is not only usefull for building different binaries, e.g.
4215  when cross compiling.
4216  It also gives you a much better overview in the source tree when all the
4217  generated files are not scattered between the source files.
4218  And the best thing is: if you want to change a file you can leave the original
4219  file untouched in the source directory.
4220  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4221  Makefile.dep` and `make`.
4222  
4223 \series bold
4224 make
4225 \series default
4226  will do the rest for you!
4227
4228 \layout Section
4229 Building the Documentation
4230
4231 \layout Standard
4232 Add -
4233 \begin_inset ERT
4234 status Collapsed
4235
4236 \layout Standard
4237
4238
4239 \backslash
4240 /
4241
4242 \end_inset
4243
4244 -enable-doc to the configure arguments to build the documentation together
4245  with all the other stuff.
4246  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4247  dvips and makeindex) to get the job done.
4248  Another possibility is to change to the doc directory and to type 
4249 \family sans
4250 \series bold
4251
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255 make
4256 \begin_inset Quotes srd
4257 \end_inset
4258
4259
4260 \family default
4261 \series default
4262  there.
4263  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4264 x).
4265  Using LyX 
4266 \begin_inset LatexCommand \url{http://www.lyx.org}
4267
4268 \end_inset
4269
4270  as editor is straightforward.
4271  Prebuilt documentation in html and pdf format is available from 
4272 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4273
4274 \end_inset
4275
4276 .
4277
4278 \layout Section
4279 Reading the Documentation
4280 \begin_inset LatexCommand \index{Documentation}
4281
4282 \end_inset
4283
4284
4285
4286 \layout Standard
4287 Currently reading the document in pdf format is recommended, as for unknown
4288  reason the hyperlinks are working there whereas in the html version they
4289  are not
4290 \begin_inset Foot
4291 collapsed false
4292
4293 \layout Standard
4294 If you should know why please drop us a note
4295
4296 \end_inset
4297
4298 .
4299  
4300 \newline
4301 You'll find the pdf version
4302 \begin_inset LatexCommand \index{PDF version of this document}
4303
4304 \end_inset
4305
4306  at 
4307 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4308
4309 \end_inset
4310
4311 .
4312  
4313 \newline
4314 A html version
4315 \begin_inset LatexCommand \index{HTML version of this document}
4316
4317 \end_inset
4318
4319  should be online at 
4320 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4321
4322 \end_inset
4323
4324 .
4325 \newline
4326 This documentation is in some aspects different from a commercial documentation:
4327  
4328
4329 \layout Itemize
4330 It tries to document SDCC for several processor architectures in one document
4331  (commercially these probably would be separate documents/products).
4332  This document
4333 \begin_inset LatexCommand \index{Status of documentation}
4334
4335 \end_inset
4336
4337  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4338 on about f.e.
4339  Z80, PIC14, PIC16 and HC08.
4340
4341 \layout Itemize
4342 There are many references pointing away from this documentation.
4343  Don't let this distract you.
4344  If there f.e.
4345  was a reference like 
4346 \begin_inset LatexCommand \url{http://www.opencores.org}
4347
4348 \end_inset
4349
4350  together with a statement 
4351 \begin_inset Quotes sld
4352 \end_inset
4353
4354 some processors which are targetted by SDCC can be implemented in a 
4355 \emph on
4356 f
4357 \emph default
4358 ield 
4359 \emph on
4360 p
4361 \emph default
4362 rogrammable 
4363 \emph on
4364 g
4365 \emph default
4366 ate 
4367 \emph on
4368 a
4369 \emph default
4370 rray
4371 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4372
4373 \end_inset
4374
4375
4376 \begin_inset Quotes srd
4377 \end_inset
4378
4379  or 
4380 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4381
4382 \end_inset
4383
4384
4385 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4386
4387 \end_inset
4388
4389  
4390 \begin_inset Quotes sld
4391 \end_inset
4392
4393 have you ever heard of an open source compiler that compiles a subset of
4394  C for an FPGA?
4395 \begin_inset Quotes srd
4396 \end_inset
4397
4398  we expect you to have a quick look there and come back.
4399  If you read this you are on the right track.
4400
4401 \layout Itemize
4402 Some sections attribute more space to problems, restrictions and warnings
4403  than to the solution.
4404
4405 \layout Itemize
4406 The installation section and the section about the debugger is intimidating.
4407
4408 \layout Itemize
4409 There are still lots of typos and there are more different writing styles
4410  than pictures.
4411
4412 \layout Section
4413 Testing the SDCC Compiler
4414 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4415
4416 \end_inset
4417
4418
4419
4420 \layout Standard
4421 The first thing you should do after installing your SDCC compiler is to
4422  see if it runs.
4423  Type 
4424 \family sans
4425 \series bold
4426 "sdcc -
4427 \begin_inset ERT
4428 status Collapsed
4429
4430 \layout Standard
4431
4432
4433 \backslash
4434 /
4435
4436 \end_inset
4437
4438 -version"
4439 \begin_inset LatexCommand \index{version}
4440
4441 \end_inset
4442
4443
4444 \family default
4445 \series default
4446  at the prompt, and the program should run and output its version like:
4447  
4448 \newline
4449
4450 \family typewriter
4451 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4452  (UNIX)
4453
4454 \layout Standard
4455 If it doesn't run, or gives a message about not finding sdcc program, then
4456  you need to check over your installation.
4457  Make sure that the sdcc bin directory is in your executable search path
4458  defined by the PATH environment setting (
4459 \series medium
4460 see 
4461 \series default
4462 section 
4463 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4464
4465 \end_inset
4466
4467 \SpecialChar ~
4468
4469 \series medium
4470 Install trouble-shooting for suggestions
4471 \series default
4472 ).
4473  Make sure that the sdcc program is in the bin folder, if not perhaps something
4474  did not install correctly.
4475 \newline
4476
4477 \newline
4478
4479 \series medium
4480 SDCC 
4481 \series default
4482 is commonly installed as described in section 
4483 \begin_inset Quotes sld
4484 \end_inset
4485
4486 Install and search paths
4487 \begin_inset Quotes srd
4488 \end_inset
4489
4490 .
4491 \newline
4492
4493 \newline
4494
4495 \series medium
4496 Make sure the compiler works on a very simple example.
4497  Type in the following test.c program using your favorite 
4498 \series default
4499 ASCII 
4500 \series medium
4501 editor:
4502
4503 \layout Verse
4504
4505 \family typewriter
4506 char test;
4507 \newline
4508
4509 \newline
4510 void main(void) {
4511 \newline
4512 \SpecialChar ~
4513 \SpecialChar ~
4514 \SpecialChar ~
4515 \SpecialChar ~
4516 test=0;
4517 \newline
4518 }
4519
4520 \layout Standard
4521
4522 \series medium
4523 Compile this using the following command: 
4524 \family sans
4525 \series bold
4526 "sdcc -c test.c".
4527
4528 \family default
4529 \series default
4530  
4531 \series medium
4532 If all goes well, the compiler will generate a test.asm and test.rel file.
4533  Congratulations, you've just compiled your first program with SDCC.
4534  We used the -c option to tell SDCC not to link the generated code, just
4535  to keep things simple for this step.
4536 \series default
4537
4538 \newline
4539
4540 \newline
4541
4542 \series medium
4543 The next step is to try it with the linker.
4544  Type in 
4545 \family sans
4546 \series bold
4547 "sdcc test.c
4548 \family default
4549 \series default
4550 "
4551 \series medium
4552 .
4553  If all goes well the compiler will link with the libraries and produce
4554  a test.ihx output file.
4555  If this step fails
4556 \series default
4557  
4558 \series medium
4559 (no test.ihx, and the linker generates warnings), then the problem is most
4560  likely that 
4561 \series default
4562 SDCC
4563 \series medium
4564  cannot find the 
4565 \series default
4566 /
4567 \series medium
4568 usr/local/share/sdcc/lib directory
4569 \series default
4570  
4571 \series medium
4572 (see 
4573 \series default
4574 section 
4575 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4576
4577 \end_inset
4578
4579 \SpecialChar ~
4580
4581 \series medium
4582 Install trouble-shooting for suggestions).
4583 \series default
4584
4585 \newline
4586
4587 \newline
4588
4589 \series medium
4590 The final test is to ensure 
4591 \series default
4592 SDCC
4593 \series medium
4594  can use the 
4595 \series default
4596 standard
4597 \series medium
4598  header files and libraries.
4599  Edit test.c and change it to the following:
4600
4601 \layout Verse
4602
4603 \family typewriter
4604 #include <string.h>
4605 \newline
4606
4607 \newline
4608 char str1[10];
4609 \newline
4610
4611 \newline
4612 void main(void) {
4613 \newline
4614 \SpecialChar ~
4615 \SpecialChar ~
4616 strcpy(str1, "testing");
4617 \newline
4618 }
4619
4620 \layout Standard
4621
4622 \series medium
4623 Compile this by typing 
4624 \family sans
4625 \series bold
4626 "sdcc test.c"
4627 \family default
4628 \series medium
4629 .
4630  This should generate a test.ihx output file, and it should give no warnings
4631  such as not finding the string.h file.
4632  If it cannot find the string.h file, then the problem is that 
4633 \series default
4634 SDCC
4635 \series medium
4636  cannot find the /usr/local/share/sdcc/include directory
4637 \series default
4638  
4639 \series medium
4640 (see the 
4641 \series default
4642 section 
4643 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4644
4645 \end_inset
4646
4647 \SpecialChar ~
4648
4649 \series medium
4650 Install trouble-shooting section for suggestions).
4651
4652 \series default
4653  Use option 
4654 \series bold
4655 -
4656 \begin_inset ERT
4657 status Collapsed
4658
4659 \layout Standard
4660
4661
4662 \backslash
4663 /
4664
4665 \end_inset
4666
4667 -print-search-dirs
4668 \series default
4669
4670 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4671
4672 \end_inset
4673
4674  to find exactly where SDCC is looking for the include and lib files.
4675
4676 \layout Section
4677 Install Trouble-shooting
4678 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4679
4680 \end_inset
4681
4682
4683 \begin_inset LatexCommand \index{Install trouble-shooting}
4684
4685 \end_inset
4686
4687
4688
4689 \layout Subsection
4690 If SDCC does not build correctly
4691
4692 \layout Standard
4693 A thing to try is starting from scratch by unpacking the .tgz source package
4694  again in an empty directory.
4695  Configure it like:
4696 \newline
4697
4698 \newline
4699
4700 \family sans
4701 \series bold
4702 ./configure 2>&1 | tee configure.log
4703 \family default
4704 \series default
4705
4706 \newline
4707
4708 \newline
4709 and build it like:
4710 \newline
4711
4712 \newline
4713
4714 \family sans
4715 \series bold
4716 make 2>&1 | tee make.log
4717 \family default
4718 \series default
4719
4720 \newline
4721
4722 \newline
4723 If anything goes wrong, you can review the log files to locate the problem.
4724  Or a relevant part of this can be attached to an email that could be helpful
4725  when requesting help from the mailing list.
4726
4727 \layout Subsection
4728 What the 
4729 \begin_inset Quotes sld
4730 \end_inset
4731
4732 ./configure
4733 \begin_inset Quotes srd
4734 \end_inset
4735
4736  does
4737
4738 \layout Standard
4739 The 
4740 \begin_inset Quotes sld
4741 \end_inset
4742
4743 ./configure
4744 \begin_inset Quotes srd
4745 \end_inset
4746
4747  command is a script that analyzes your system and performs some configuration
4748  to ensure the source package compiles on your system.
4749  It will take a few minutes to run, and will compile a few tests to determine
4750  what compiler features are installed.
4751
4752 \layout Subsection
4753 What the 
4754 \begin_inset Quotes sld
4755 \end_inset
4756
4757 make
4758 \begin_inset Quotes srd
4759 \end_inset
4760
4761  does
4762
4763 \layout Standard
4764 This runs the GNU make tool, which automatically compiles all the source
4765  packages into the final installed binary executables.
4766
4767 \layout Subsection
4768 What the 
4769 \begin_inset Quotes sld
4770 \end_inset
4771
4772 make install
4773 \begin_inset Quotes erd
4774 \end_inset
4775
4776  command does.
4777
4778 \layout Standard
4779 This will install the compiler, other executables libraries and include
4780  files into the appropriate directories.
4781  See sections 
4782 \begin_inset LatexCommand \ref{sub:Install-paths}
4783
4784 \end_inset
4785
4786 ,\SpecialChar ~
4787
4788 \begin_inset LatexCommand \ref{sub:Search-Paths}
4789
4790 \end_inset
4791
4792 \SpecialChar ~
4793 about install and search paths.
4794 \newline
4795 On most systems you will need super-user privilege
4796 s to do this.
4797
4798 \layout Section
4799 Components of SDCC
4800
4801 \layout Standard
4802 SDCC is not just a compiler, but a collection of tools by various developers.
4803  These include linkers, assemblers, simulators and other components.
4804  Here is a summary of some of the components.
4805  Note that the included simulator and assembler have separate documentation
4806  which you can find in the source package in their respective directories.
4807  As SDCC grows to include support for other processors, other packages from
4808  various developers are included and may have their own sets of documentation.
4809 \newline
4810
4811 \newline
4812 You
4813  might want to look at the files which are installed in <installdir>.
4814  At the time of this writing, we find the following programs for gcc-builds:
4815 \newline
4816
4817  
4818 \newline
4819 In <installdir>/bin:
4820
4821 \layout Itemize
4822 sdcc - The compiler.
4823
4824 \layout Itemize
4825 sdcpp - The C preprocessor.
4826
4827 \layout Itemize
4828 asx8051 - The assembler for 8051 type processors.
4829
4830 \layout Itemize
4831 as-z80
4832 \series bold
4833
4834 \series default
4835 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4836
4837 \layout Itemize
4838 aslink -The linker for 8051 type processors.
4839
4840 \layout Itemize
4841 link-z80
4842 \series bold
4843
4844 \series default
4845 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4846
4847 \layout Itemize
4848 s51 - The ucSim 8051 simulator.
4849
4850 \layout Itemize
4851 sdcdb - The source debugger.
4852
4853 \layout Itemize
4854 packihx - A tool to pack (compress) Intel hex files.
4855
4856 \layout Standard
4857 In <installdir>/share/sdcc/include
4858
4859 \layout Itemize
4860 the include files
4861
4862 \layout Standard
4863 In <installdir>/share/sdcc/lib
4864
4865 \layout Itemize
4866 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4867  relocatables.
4868
4869 \layout Standard
4870 In <installdir>/share/sdcc/doc
4871
4872 \layout Itemize
4873 the documentation
4874
4875 \layout Standard
4876 As development for other processors proceeds, this list will expand to include
4877  executables to support processors like AVR, PIC, etc.
4878
4879 \layout Subsection
4880 sdcc - The Compiler
4881
4882 \layout Standard
4883 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4884  the assembler and linkage editor.
4885
4886 \layout Subsection
4887 sdcpp - The C-Preprocessor
4888
4889 \layout Standard
4890 The preprocessor
4891 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4892
4893 \end_inset
4894
4895  is a modified version of the GNU cpp
4896 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4897
4898 \end_inset
4899
4900  preprocessor 
4901 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4902
4903 \end_inset
4904
4905 .
4906  The C preprocessor is used to pull in #include sources, process #ifdef
4907  statements, #defines and so on.
4908
4909 \layout Subsection
4910 as
4911 \emph on
4912 xxxx
4913 \emph default
4914 , aslink, link-
4915 \emph on
4916 xxx
4917 \emph default
4918  - The Assemblers and Linkage Editors
4919
4920 \layout Standard
4921 This is retargettable assembler & linkage editor, it was developed by Alan
4922  Baldwin.
4923  John Hartman created the version for 8051, and I (Sandeep) have made some
4924  enhancements and bug fixes for it to work properly with SDCC.
4925
4926 \layout Subsection
4927 s51 - The Simulator
4928
4929 \layout Standard
4930 S51
4931 \begin_inset LatexCommand \index{s51}
4932
4933 \end_inset
4934
4935  is a freeware, opensource simulator developed by Daniel Drotos.
4936  The simulator is built as part of the build process.
4937  For more information visit Daniel's web site at: 
4938 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4939
4940 \end_inset
4941
4942 .
4943  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4944  XA51 family.
4945
4946 \layout Subsection
4947 sdcdb - Source Level Debugger
4948
4949 \layout Standard
4950 SDCDB
4951 \begin_inset LatexCommand \index{SDCDB (debugger)}
4952
4953 \end_inset
4954
4955  is the companion source level debugger.
4956  More about SDCDB in section 
4957 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4958
4959 \end_inset
4960
4961 .
4962  The current version of the debugger uses Daniel's Simulator S51
4963 \begin_inset LatexCommand \index{s51}
4964
4965 \end_inset
4966
4967 , but can be easily changed to use other simulators.
4968
4969 \layout Chapter
4970 Using SDCC
4971
4972 \layout Section
4973 Compiling
4974
4975 \layout Subsection
4976 Single Source File Projects
4977
4978 \layout Standard
4979 For single source file 8051 projects the process is very simple.
4980  Compile your programs with the following command 
4981 \family sans
4982 \series bold
4983 "sdcc sourcefile.c".
4984
4985 \family default
4986 \series default
4987  This will compile, assemble and link your source file.
4988  Output files are as follows:
4989
4990 \layout Itemize
4991 sourcefile.asm
4992 \begin_inset LatexCommand \index{<file>.asm}
4993
4994 \end_inset
4995
4996  - Assembler source
4997 \begin_inset LatexCommand \index{Assembler source}
4998
4999 \end_inset
5000
5001  file created by the compiler
5002
5003 \layout Itemize
5004 sourcefile.lst
5005 \begin_inset LatexCommand \index{<file>.lst}
5006
5007 \end_inset
5008
5009  - Assembler listing
5010 \begin_inset LatexCommand \index{Assembler listing}
5011
5012 \end_inset
5013
5014  file created by the Assembler
5015
5016 \layout Itemize
5017 sourcefile.rst
5018 \begin_inset LatexCommand \index{<file>.rst}
5019
5020 \end_inset
5021
5022  - Assembler listing
5023 \begin_inset LatexCommand \index{Assembler listing}
5024
5025 \end_inset
5026
5027  file updated with linkedit information, created by linkage editor
5028
5029 \layout Itemize
5030 sourcefile.sym
5031 \begin_inset LatexCommand \index{<file>.sym}
5032
5033 \end_inset
5034
5035  - symbol listing
5036 \begin_inset LatexCommand \index{Symbol listing}
5037
5038 \end_inset
5039
5040  for the sourcefile, created by the assembler
5041
5042 \layout Itemize
5043 sourcefile.rel
5044 \begin_inset LatexCommand \index{<file>.rel}
5045
5046 \end_inset
5047
5048  or sourcefile.o
5049 \begin_inset LatexCommand \index{<file>.o}
5050
5051 \end_inset
5052
5053  - Object file
5054 \begin_inset LatexCommand \index{Object file}
5055
5056 \end_inset
5057
5058  created by the assembler, input to Linkage editor
5059
5060 \layout Itemize
5061 sourcefile.map
5062 \begin_inset LatexCommand \index{<file>.map}
5063
5064 \end_inset
5065
5066  - The memory map
5067 \begin_inset LatexCommand \index{Memory map}
5068
5069 \end_inset
5070
5071  for the load module, created by the Linker
5072
5073 \layout Itemize
5074 sourcefile.mem
5075 \begin_inset LatexCommand \index{<file>.mem}
5076
5077 \end_inset
5078
5079  - A file with a summary of the memory usage
5080
5081 \layout Itemize
5082 sourcefile.ihx
5083 \begin_inset LatexCommand \index{<file>.ihx}
5084
5085 \end_inset
5086
5087  - The load module in Intel hex format
5088 \begin_inset LatexCommand \index{Intel hex format}
5089
5090 \end_inset
5091
5092  (you can select the Motorola S19 format
5093 \begin_inset LatexCommand \index{Motorola S19 format}
5094
5095 \end_inset
5096
5097  with -
5098 \begin_inset ERT
5099 status Collapsed
5100
5101 \layout Standard
5102
5103
5104 \backslash
5105 /
5106
5107 \end_inset
5108
5109 -out-fmt-s19
5110 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5111
5112 \end_inset
5113
5114 .
5115  If you need another format you might want to use 
5116 \family sans
5117 \shape italic
5118 objdump
5119 \family default
5120 \shape default
5121
5122 \begin_inset LatexCommand \index{objdump (tool)}
5123
5124 \end_inset
5125
5126  or
5127 \family sans
5128 \shape italic
5129  srecord
5130 \family default
5131 \shape default
5132
5133 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5134
5135 \end_inset
5136
5137 ).
5138  Both formats are documented in the documentation of srecord
5139 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5140
5141 \end_inset
5142
5143
5144
5145 \layout Itemize
5146 sourcefile.adb
5147 \begin_inset LatexCommand \index{<file>.adb}
5148
5149 \end_inset
5150
5151  - An intermediate file containing debug information needed to create the
5152  .cdb file (with -
5153 \begin_inset ERT
5154 status Collapsed
5155
5156 \layout Standard
5157
5158
5159 \backslash
5160 /
5161
5162 \end_inset
5163
5164 -debug
5165 \begin_inset LatexCommand \index{-\/-debug}
5166
5167 \end_inset
5168
5169
5170
5171 \layout Itemize
5172 sourcefile.cdb
5173 \begin_inset LatexCommand \index{<file>.cdb}
5174
5175 \end_inset
5176
5177  - An optional file (with -
5178 \begin_inset ERT
5179 status Collapsed
5180
5181 \layout Standard
5182
5183
5184 \backslash
5185 /
5186
5187 \end_inset
5188
5189 -debug) containing debug information.
5190  The format is documented in cdbfileformat.pdf
5191
5192 \layout Itemize
5193 sourcefile.
5194  - (no extension)
5195 \begin_inset LatexCommand \index{<file> (no extension)}
5196
5197 \end_inset
5198
5199  An optional AOMF or AOMF51
5200 \begin_inset LatexCommand \index{AOMF, AOMF51}
5201
5202 \end_inset
5203
5204  
5205 \begin_inset LatexCommand \label{OMF file}
5206
5207 \end_inset
5208
5209 file containing debug information (generated with option -
5210 \begin_inset ERT
5211 status Collapsed
5212
5213 \layout Standard
5214
5215
5216 \backslash
5217 /
5218
5219 \end_inset
5220
5221 -debug).
5222  The (Intel)
5223 \emph on
5224  a
5225 \emph default
5226 bsolute 
5227 \emph on
5228 o
5229 \emph default
5230 bject 
5231 \emph on
5232 m
5233 \emph default
5234 odule 
5235 \emph on
5236 f
5237 \emph default
5238 ormat is commonly used by third party tools (debuggers
5239 \begin_inset LatexCommand \index{Debugger}
5240
5241 \end_inset
5242
5243 , simulators, emulators)
5244
5245 \layout Itemize
5246 sourcefile.dump*
5247 \begin_inset LatexCommand \index{<file>.dump*}
5248
5249 \end_inset
5250
5251  - Dump file to debug the compiler it self (generated with option -
5252 \begin_inset ERT
5253 status Collapsed
5254
5255 \layout Standard
5256
5257
5258 \backslash
5259 /
5260
5261 \end_inset
5262
5263 -dumpall) (see section 
5264 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5265
5266 \end_inset
5267
5268 \SpecialChar ~
5269  and section 
5270 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5271
5272 \end_inset
5273
5274 \SpecialChar ~
5275
5276 \begin_inset Quotes sld
5277 \end_inset
5278
5279 Anatomy of the compiler
5280 \begin_inset Quotes srd
5281 \end_inset
5282
5283 ).
5284
5285 \layout Subsection
5286 Postprocessing the Intel Hex
5287 \begin_inset LatexCommand \index{Intel hex format}
5288
5289 \end_inset
5290
5291  file
5292
5293 \layout Standard
5294 In most cases this won't be needed but the Intel Hex file
5295 \begin_inset LatexCommand \index{<file>.ihx}
5296
5297 \end_inset
5298
5299  which is generated by SDCC might include lines of varying length and the
5300  addresses within the file are not guaranteed to be strictly ascending.
5301  If your toolchain or a bootloader does not like this you can use the tool
5302  
5303 \family typewriter
5304 packihx
5305 \family default
5306
5307 \begin_inset LatexCommand \index{packihx (tool)}
5308
5309 \end_inset
5310
5311  which is part of the SDCC distribution: 
5312 \newline
5313
5314 \newline
5315
5316 \family sans
5317 \series bold
5318  packihx sourcefile.ihx >sourcefile.hex
5319 \family default
5320 \series default
5321
5322 \newline
5323
5324 \newline
5325 The separately available
5326 \emph on
5327  srecord
5328 \emph default
5329
5330 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5331
5332 \end_inset
5333
5334  package additionally allows to set undefined locations to a predefined
5335  value, to insert checksums
5336 \begin_inset LatexCommand \index{checksum}
5337
5338 \end_inset
5339
5340  of various flavours (crc, add, xor) and to perform other manipulations
5341  (convert, split, crop, offset, ...).
5342  
5343 \newline
5344
5345 \newline
5346
5347 \family sans
5348 \series bold
5349 srec_cat\SpecialChar ~
5350 \SpecialChar ~
5351 sourcefile.ihx -intel\SpecialChar ~
5352 \SpecialChar ~
5353 -o sourcefile.hex -intel
5354 \newline
5355
5356 \newline
5357
5358 \family default
5359 \series default
5360 An example for a more complex command line
5361 \begin_inset Foot
5362 collapsed false
5363
5364 \layout Standard
5365 the command backfills
5366 \begin_inset LatexCommand \index{backfill unused memory}
5367
5368 \end_inset
5369
5370  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5371  block is zero.
5372  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5373  will be interpreted as an 
5374 \family typewriter
5375 lcall
5376 \family default
5377  to address 
5378 \family typewriter
5379 0x1212
5380 \family default
5381  (where an emergency routine could sit).
5382
5383 \end_inset
5384
5385  could look like:
5386 \newline
5387
5388 \newline
5389
5390 \family sans
5391 \series bold
5392 \size footnotesize
5393 srec_cat\SpecialChar ~
5394 sourcefile.ihx -intel\SpecialChar ~
5395 \SpecialChar ~
5396 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5397 -little-endian-checksum-nega
5398 tive 0xfffe 0x02 0x02\SpecialChar ~
5399 \SpecialChar ~
5400 -o sourcefile.hex -intel
5401 \size default
5402
5403 \newline
5404
5405 \newline
5406
5407 \family default
5408 \series default
5409 The srecord package is available at 
5410 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5411
5412 \end_inset
5413
5414  .
5415
5416 \layout Subsection
5417 Projects with Multiple Source Files
5418
5419 \layout Standard
5420 SDCC can compile only ONE file at a time.
5421  Let us for example assume that you have a project containing the following
5422  files:
5423 \newline
5424
5425 \newline
5426 foo1.c (contains some functions)
5427 \newline
5428 foo2.c (contains some more functions)
5429 \newline
5430 foomai
5431 n.c (contains more functions and the function main)
5432 \newline
5433
5434 \size footnotesize
5435
5436 \newline
5437
5438 \size default
5439 The first two files will need to be compiled separately with the commands:
5440 \size footnotesize
5441  
5442 \size default
5443
5444 \newline
5445
5446 \newline
5447
5448 \family sans
5449 \series bold
5450 sdcc\SpecialChar ~
5451 -c\SpecialChar ~
5452 foo1.c
5453 \family default
5454 \series default
5455 \size footnotesize
5456
5457 \newline
5458
5459 \family sans
5460 \series bold
5461 \size default
5462 sdcc\SpecialChar ~
5463 -c\SpecialChar ~
5464 foo2.c
5465 \family default
5466 \series default
5467
5468 \newline
5469
5470 \newline
5471 Then compile the source file containing the 
5472 \emph on
5473 main()
5474 \emph default
5475  function and link
5476 \begin_inset LatexCommand \index{Linker}
5477
5478 \end_inset
5479
5480  the files together with the following command: 
5481 \newline
5482
5483 \newline
5484
5485 \family sans
5486 \series bold
5487 sdcc\SpecialChar ~
5488 foomain.c\SpecialChar ~
5489 foo1.rel\SpecialChar ~
5490 foo2.rel
5491 \family default
5492 \series default
5493
5494 \begin_inset LatexCommand \index{<file>.rel}
5495
5496 \end_inset
5497
5498
5499 \newline
5500
5501 \newline
5502 Alternatively, 
5503 \emph on
5504 foomain.c 
5505 \emph default
5506 can be separately compiled as well: 
5507 \family sans
5508 \series bold
5509
5510 \newline
5511
5512 \newline
5513 sdcc\SpecialChar ~
5514 -c\SpecialChar ~
5515 foomain.c
5516 \newline
5517 sdcc foomain.rel foo1.rel foo2.rel
5518 \newline
5519
5520 \newline
5521
5522 \family default
5523 \series default
5524 The file containing the 
5525 \emph on
5526 main()
5527 \emph default
5528  function
5529 \emph on
5530  
5531 \emph default
5532 \noun on
5533 must
5534 \noun default
5535  be the 
5536 \noun on
5537 first
5538 \noun default
5539  file specified in the command line, since the linkage editor processes
5540  file in the order they are presented to it.
5541  The linker is invoked from SDCC using a script file with extension .lnk
5542 \begin_inset LatexCommand \index{<file>.lnk}
5543
5544 \end_inset
5545
5546 .
5547  You can view this file to troubleshoot linking problems such as those arising
5548  from missing libraries.
5549
5550 \layout Subsection
5551 Projects with Additional Libraries
5552 \begin_inset LatexCommand \index{Libraries}
5553
5554 \end_inset
5555
5556
5557
5558 \layout Standard
5559 Some reusable routines may be compiled into a library, see the documentation
5560  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5561  for how to create a 
5562 \emph on
5563 .lib
5564 \begin_inset LatexCommand \index{<file>.lib}
5565
5566 \end_inset
5567
5568
5569 \emph default
5570  library file.
5571  Libraries created in this manner can be included in the command line.
5572  Make sure you include the -L <library-path> option to tell the linker where
5573  to look for these files if they are not in the current directory.
5574  Here is an example, assuming you have the source file 
5575 \emph on
5576 foomain.c
5577 \emph default
5578  and a library
5579 \emph on
5580  foolib.lib
5581 \emph default
5582  in the directory 
5583 \emph on
5584 mylib
5585 \emph default
5586  (if that is not the same as your current project):
5587 \newline
5588
5589 \newline
5590
5591 \family sans
5592 \series bold
5593 sdcc foomain.c foolib.lib -L mylib
5594 \newline
5595
5596 \newline
5597
5598 \family default
5599 \series default
5600 Note here that
5601 \emph on
5602  mylib
5603 \emph default
5604  must be an absolute path name.
5605 \newline
5606
5607 \newline
5608 The most efficient way to use libraries is
5609  to keep separate modules in separate source files.
5610  The lib file now should name all the modules.rel
5611 \begin_inset LatexCommand \index{<file>.rel}
5612
5613 \end_inset
5614
5615  files.
5616  For an example see the standard library file 
5617 \emph on
5618 libsdcc.lib
5619 \emph default
5620  in the directory <installdir>/share/lib/small.
5621
5622 \layout Subsection
5623 Using sdcclib to Create and Manage Libraries
5624 \begin_inset LatexCommand \index{sdcclib}
5625
5626 \end_inset
5627
5628
5629
5630 \layout Standard
5631 Alternatively, instead of having a .rel file for each entry on the library
5632  file as described in the preceding section, sdcclib can be used to embed
5633  all the modules belonging to such library in the library file itself.
5634  This results in a larger library file, but it greatly reduces the number
5635  of disk files accessed by the linker.
5636   Additionally, the packed library file contains an index of all include
5637  modules and symbols that significantly speeds up the linking process.
5638  To display a list of options supported by sdcclib type:
5639 \newline
5640
5641
5642 \layout Standard
5643
5644 \family sans
5645 \series bold
5646 sdcclib -?
5647 \begin_inset LatexCommand \index{sdcclib}
5648
5649 \end_inset
5650
5651
5652 \newline
5653
5654 \newline
5655
5656 \family default
5657 \series default
5658 To create a new library file, start by compiling all the required modules.
5659  For example:
5660 \newline
5661
5662
5663 \layout Standard
5664
5665 \family sans
5666 \series bold
5667 sdcc -c _divsint.c
5668
5669 \layout Standard
5670
5671 \family sans
5672 \series bold
5673 sdcc -c _divuint.c
5674
5675 \layout Standard
5676
5677 \family sans
5678 \series bold
5679 sdcc -c _modsint.c
5680
5681 \layout Standard
5682
5683 \family sans
5684 \series bold
5685 sdcc -c _moduint.c
5686
5687 \layout Standard
5688
5689 \family sans
5690 \series bold
5691 sdcc -c _mulint.c
5692 \newline
5693
5694
5695 \layout Standard
5696 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5697  and _mulint.rel.
5698  The next step is to add the .rel files to the library file:
5699 \newline
5700
5701
5702 \layout Standard
5703
5704 \family sans
5705 \series bold
5706 sdcclib libint.lib _divsint.rel
5707 \family default
5708
5709 \begin_inset LatexCommand \index{sdcclib}
5710
5711 \end_inset
5712
5713
5714
5715 \layout Standard
5716
5717 \family sans
5718 \series bold
5719 sdcclib libint.lib _divuint.rel
5720
5721 \layout Standard
5722
5723 \family sans
5724 \series bold
5725 sdcclib libint.lib _modsint.rel
5726
5727 \layout Standard
5728
5729 \family sans
5730 \series bold
5731 sdcclib libint.lib _moduint.rel
5732
5733 \layout Standard
5734
5735 \family sans
5736 \series bold
5737 sdcclib libint.lib _mulint.rel
5738 \series default
5739
5740 \newline
5741
5742
5743 \layout Standard
5744 If the file already exists in the library, it will be replaced.
5745  To see what modules and symbols are included in the library, options -s
5746  and -m are available.
5747  For example:
5748 \newline
5749
5750 \newline
5751
5752 \family sans
5753 \series bold
5754 sdcclib -s libint.lib
5755 \family default
5756
5757 \begin_inset LatexCommand \index{sdcclib}
5758
5759 \end_inset
5760
5761
5762 \newline
5763
5764 \family typewriter
5765 \series default
5766 _divsint.rel:
5767
5768 \layout Standard
5769
5770 \family typewriter
5771 __divsint_a_1_1
5772
5773 \layout Standard
5774
5775 \family typewriter
5776 __divsint_PARM_2
5777
5778 \layout Standard
5779
5780 \family typewriter
5781 __divsint
5782 \newline
5783 _divuint.rel:
5784
5785 \layout Standard
5786
5787 \family typewriter
5788 __divuint_a_1_1
5789
5790 \layout Standard
5791
5792 \family typewriter
5793 __divuint_PARM_2
5794
5795 \layout Standard
5796
5797 \family typewriter
5798 __divuint_reste_1_1
5799
5800 \layout Standard
5801
5802 \family typewriter
5803 __divuint_count_1_1
5804
5805 \layout Standard
5806
5807 \family typewriter
5808 __divuint
5809 \newline
5810 _modsint.rel:
5811
5812 \layout Standard
5813
5814 \family typewriter
5815 __modsint_a_1_1
5816
5817 \layout Standard
5818
5819 \family typewriter
5820 __modsint_PARM_2
5821
5822 \layout Standard
5823
5824 \family typewriter
5825 __modsint
5826 \newline
5827 _moduint.rel:
5828
5829 \layout Standard
5830
5831 \family typewriter
5832 __moduint_a_1_1
5833
5834 \layout Standard
5835
5836 \family typewriter
5837 __moduint_PARM_2
5838
5839 \layout Standard
5840
5841 \family typewriter
5842 __moduint_count_1_1
5843
5844 \layout Standard
5845
5846 \family typewriter
5847 __moduint
5848 \newline
5849 _mulint.rel:
5850
5851 \layout Standard
5852
5853 \family typewriter
5854 __mulint_PARM_2
5855
5856 \layout Standard
5857
5858 \family typewriter
5859 __mulint
5860 \family default
5861 \series bold
5862
5863 \newline
5864
5865
5866 \layout Standard
5867 \added_space_bottom bigskip 
5868 If the source files are compiled using -
5869 \begin_inset ERT
5870 status Collapsed
5871
5872 \layout Standard
5873
5874
5875 \backslash
5876 /
5877
5878 \end_inset
5879
5880 -debug
5881 \begin_inset LatexCommand \index{-\/-debug}
5882
5883 \end_inset
5884
5885 , the corresponding debug information file .adb will be include in the library
5886  file as well.
5887  The library files created with sdcclib are plain text files, so they can
5888  be viewed with a text editor.
5889  It is not recomended to modify a library file created with sdcclib using
5890  a text editor, as there are file indexes numbers located accross the file
5891  used by the linker to quickly locate the required module to link.
5892  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5893  it can be safely deleted, since all the information required for linking
5894  is embedded in the library file itself.
5895  Library files created using sdcclib are used as described in the preceding
5896  sections.
5897
5898
5899
5900 \layout Section
5901 Command Line Options
5902 \begin_inset LatexCommand \index{Command Line Options}
5903
5904 \end_inset
5905
5906
5907
5908 \layout Subsection
5909 Processor Selection Options
5910 \begin_inset LatexCommand \index{Options processor selection}
5911
5912 \end_inset
5913
5914
5915 \begin_inset LatexCommand \index{Processor selection options}
5916
5917 \end_inset
5918
5919
5920
5921 \layout List
5922 \labelwidthstring 00.00.0000
5923
5924 \series bold
5925 -mmcs51
5926 \begin_inset LatexCommand \index{-mmcs51}
5927
5928 \end_inset
5929
5930
5931 \series default
5932  Generate code for the Intel MCS51
5933 \begin_inset LatexCommand \index{MCS51}
5934
5935 \end_inset
5936
5937  family of processors.
5938  This is the default processor target.
5939
5940 \layout List
5941 \labelwidthstring 00.00.0000
5942
5943 \series bold
5944 -mds390
5945 \begin_inset LatexCommand \index{-mds390}
5946
5947 \end_inset
5948
5949
5950 \series default
5951  Generate code for the Dallas DS80C390
5952 \begin_inset LatexCommand \index{DS80C390}
5953
5954 \end_inset
5955
5956  processor.
5957
5958 \layout List
5959 \labelwidthstring 00.00.0000
5960
5961 \series bold
5962 -mds400
5963 \begin_inset LatexCommand \index{-mds400}
5964
5965 \end_inset
5966
5967
5968 \series default
5969  Generate code for the Dallas DS80C400
5970 \begin_inset LatexCommand \index{DS80C400}
5971
5972 \end_inset
5973
5974  processor.
5975
5976 \layout List
5977 \labelwidthstring 00.00.0000
5978
5979 \series bold
5980 -mhc08
5981 \begin_inset LatexCommand \index{-mhc08}
5982
5983 \end_inset
5984
5985
5986 \series default
5987  Generate code for the Freescale/Motorola HC08
5988 \begin_inset LatexCommand \index{HC08}
5989
5990 \end_inset
5991
5992  family of processors.
5993
5994 \layout List
5995 \labelwidthstring 00.00.0000
5996
5997 \series bold
5998 -mz80
5999 \begin_inset LatexCommand \index{-mz80}
6000
6001 \end_inset
6002
6003
6004 \series default
6005  Generate code for the Zilog Z80
6006 \begin_inset LatexCommand \index{Z80}
6007
6008 \end_inset
6009
6010  family of processors.
6011
6012 \layout List
6013 \labelwidthstring 00.00.0000
6014
6015 \series bold
6016 -mgbz80
6017 \begin_inset LatexCommand \index{-mgbz80}
6018
6019 \end_inset
6020
6021
6022 \series default
6023  Generate code for the GameBoy Z80
6024 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6025
6026 \end_inset
6027
6028  processor (Not actively maintained).
6029
6030 \layout List
6031 \labelwidthstring 00.00.0000
6032
6033 \series bold
6034 -mavr
6035 \begin_inset LatexCommand \index{-mavr}
6036
6037 \end_inset
6038
6039
6040 \series default
6041  Generate code for the Atmel AVR
6042 \begin_inset LatexCommand \index{AVR}
6043
6044 \end_inset
6045
6046  processor (Not maintained, not complete).
6047  AVR users should probably have a look at winavr 
6048 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6049
6050 \end_inset
6051
6052  or 
6053 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6054
6055 \end_inset
6056
6057 .
6058
6059 \layout Standard
6060 \begin_inset Note
6061 collapsed true
6062
6063 \layout Standard
6064 I think it is fair to direct users there for now.
6065  Open source is also about avoiding unnecessary work .
6066  But I didn't find the 'official' link.
6067
6068 \end_inset
6069
6070
6071
6072 \layout List
6073 \labelwidthstring 00.00.0000
6074
6075 \series bold
6076 -mpic14
6077 \begin_inset LatexCommand \index{-mpic14}
6078
6079 \end_inset
6080
6081
6082 \series default
6083  Generate code for the Microchip PIC 14
6084 \begin_inset LatexCommand \index{PIC14}
6085
6086 \end_inset
6087
6088 -bit processors (p16f84 and variants.
6089  In development, not complete).
6090
6091 \layout Standard
6092 \begin_inset Note
6093 collapsed true
6094
6095 \layout Standard
6096 p16f627 p16f628 p16f84 p16f873 p16f877?
6097
6098 \end_inset
6099
6100
6101
6102 \layout List
6103 \labelwidthstring 00.00.0000
6104
6105 \series bold
6106 -mpic16
6107 \begin_inset LatexCommand \index{-mpic16}
6108
6109 \end_inset
6110
6111
6112 \series default
6113  Generate code for the Microchip PIC 16
6114 \begin_inset LatexCommand \index{PIC16}
6115
6116 \end_inset
6117
6118 -bit processors (p18f452 and variants.
6119  In development, not complete).
6120
6121 \layout List
6122 \labelwidthstring 00.00.0000
6123
6124 \series bold
6125 -mtlcs900h
6126 \series default
6127  Generate code for the Toshiba TLCS-900H
6128 \begin_inset LatexCommand \index{TLCS-900H}
6129
6130 \end_inset
6131
6132  processor (Not maintained, not complete).
6133
6134 \layout List
6135 \labelwidthstring 00.00.0000
6136 \added_space_bottom bigskip 
6137
6138 \series bold
6139 -mxa51
6140 \begin_inset LatexCommand \index{-mxa51}
6141
6142 \end_inset
6143
6144
6145 \series default
6146  Generate code for the Phillips XA51
6147 \begin_inset LatexCommand \index{XA51}
6148
6149 \end_inset
6150
6151  processor (Not maintained, not complete).
6152
6153
6154 \layout Subsection
6155 Preprocessor Options
6156 \begin_inset LatexCommand \index{Options preprocessor}
6157
6158 \end_inset
6159
6160
6161 \begin_inset LatexCommand \index{Preprocessor options}
6162
6163 \end_inset
6164
6165
6166 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6167
6168 \end_inset
6169
6170
6171
6172 \layout List
6173 \labelwidthstring 00.00.0000
6174
6175 \series bold
6176 -I<path>
6177 \begin_inset LatexCommand \index{-I<path>}
6178
6179 \end_inset
6180
6181
6182 \series default
6183  The additional location where the pre processor will look for <..h> or 
6184 \begin_inset Quotes eld
6185 \end_inset
6186
6187 ..h
6188 \begin_inset Quotes erd
6189 \end_inset
6190
6191  files.
6192
6193 \layout List
6194 \labelwidthstring 00.00.0000
6195
6196 \series bold
6197 -D<macro[=value]>
6198 \begin_inset LatexCommand \index{-D<macro[=value]>}
6199
6200 \end_inset
6201
6202
6203 \series default
6204  Command line definition of macros.
6205  Passed to the preprocessor.
6206
6207 \layout List
6208 \labelwidthstring 00.00.0000
6209
6210 \series bold
6211 -M
6212 \begin_inset LatexCommand \index{-M}
6213
6214 \end_inset
6215
6216
6217 \series default
6218  Tell the preprocessor to output a rule suitable for make describing the
6219  dependencies of each object file.
6220  For each source file, the preprocessor outputs one make-rule whose target
6221  is the object file name for that source file and whose dependencies are
6222  all the files `#include'd in it.
6223  This rule may be a single line or may be continued with `
6224 \backslash
6225 '-newline if it is long.
6226  The list of rules is printed on standard output instead of the preprocessed
6227  C program.
6228  `-M' implies `-E
6229 \begin_inset LatexCommand \index{-E}
6230
6231 \end_inset
6232
6233 '.
6234
6235 \layout List
6236 \labelwidthstring 00.00.0000
6237
6238 \series bold
6239 -C
6240 \begin_inset LatexCommand \index{-C}
6241
6242 \end_inset
6243
6244
6245 \series default
6246  Tell the preprocessor not to discard comments.
6247  Used with the `-E' option.
6248
6249 \layout List
6250 \labelwidthstring 00.00.0000
6251
6252 \series bold
6253 -MM
6254 \begin_inset LatexCommand \index{-MM}
6255
6256 \end_inset
6257
6258
6259 \size large
6260 \bar under
6261  
6262 \series default
6263 \size default
6264 \bar default
6265 Like `-M' but the output mentions only the user header files included with
6266  `#include 
6267 \begin_inset Quotes eld
6268 \end_inset
6269
6270 file"'.
6271  System header files included with `#include <file>' are omitted.
6272
6273 \layout List
6274 \labelwidthstring 00.00.0000
6275
6276 \series bold
6277 -Aquestion(answer)
6278 \begin_inset LatexCommand \index{-Aquestion(answer)}
6279
6280 \end_inset
6281
6282
6283 \series default
6284  Assert the answer answer for question, in case it is tested with a preprocessor
6285  conditional such as `#if #question(answer)'.
6286  `-A-' disables the standard assertions that normally describe the target
6287  machine.
6288
6289 \layout List
6290 \labelwidthstring 00.00.0000
6291
6292 \series bold
6293 -Umacro
6294 \begin_inset LatexCommand \index{-Umacro}
6295
6296 \end_inset
6297
6298
6299 \series default
6300  Undefine macro macro.
6301  `-U' options are evaluated after all `-D' options, but before any `-include'
6302  and `-imacros' options.
6303
6304 \layout List
6305 \labelwidthstring 00.00.0000
6306
6307 \series bold
6308 -dM
6309 \begin_inset LatexCommand \index{-dM}
6310
6311 \end_inset
6312
6313
6314 \series default
6315  Tell the preprocessor to output only a list of the macro definitions that
6316  are in effect at the end of preprocessing.
6317  Used with the `-E' option.
6318
6319 \layout List
6320 \labelwidthstring 00.00.0000
6321
6322 \series bold
6323 -dD
6324 \begin_inset LatexCommand \index{-dD}
6325
6326 \end_inset
6327
6328
6329 \series default
6330  Tell the preprocessor to pass all macro definitions into the output, in
6331  their proper sequence in the rest of the output.
6332
6333 \layout List
6334 \labelwidthstring 00.00.0000
6335
6336 \series bold
6337 -dN
6338 \begin_inset LatexCommand \index{-dN}
6339
6340 \end_inset
6341
6342
6343 \size large
6344 \bar under
6345  
6346 \series default
6347 \size default
6348 \bar default
6349 Like `-dD' except that the macro arguments and contents are omitted.
6350  Only `#define name' is included in the output.
6351
6352 \layout List
6353 \labelwidthstring 00.00.0000
6354
6355 \series bold
6356 -pedantic-parse-number
6357 \begin_inset LatexCommand \index{-pedantic-parse-number}
6358
6359 \end_inset
6360
6361
6362 \size large
6363 \bar under
6364  
6365 \series default
6366 \size default
6367 \bar default
6368 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6369  and the macro LO_B(3) gets expanded.
6370  See also #pragma pedantic_parse_number in section
6371 \begin_inset LatexCommand \ref{sec:Pragmas}
6372
6373 \end_inset
6374
6375  
6376 \emph on
6377 Note: this functionality is not in conformance with standard!
6378
6379 \layout List
6380 \labelwidthstring 00.00.0000
6381 \added_space_bottom bigskip 
6382
6383 \series bold
6384 -Wp\SpecialChar ~
6385 preprocessorOption[,preprocessorOption]
6386 \series default
6387
6388 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6389
6390 \end_inset
6391
6392 ...
6393  Pass the preprocessorOption to the preprocessor 
6394 \family typewriter
6395 sdcpp
6396 \family default
6397
6398 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6399
6400 \end_inset
6401
6402 .
6403  SDCC uses an adapted version of the preprocessor 
6404 \emph on
6405 cpp
6406 \emph default
6407  of the GNU Compiler Collection
6408 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6409
6410 \end_inset
6411
6412  (
6413 \emph on
6414 gcc
6415 \emph default
6416  
6417 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6418
6419 \end_inset
6420
6421 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6422 4.1.1\SpecialChar ~
6423 CPP\SpecialChar ~
6424 Manual
6425  at 
6426 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6427
6428 \end_inset
6429
6430 .
6431
6432
6433 \layout Subsection
6434 Linker Options
6435 \begin_inset LatexCommand \index{Options linker}
6436
6437 \end_inset
6438
6439
6440 \begin_inset LatexCommand \index{Linker options}
6441
6442 \end_inset
6443
6444
6445
6446 \layout List
6447 \labelwidthstring 00.00.0000
6448
6449 \series bold
6450 -L\SpecialChar ~
6451 -
6452 \series default
6453
6454 \begin_inset ERT
6455 status Collapsed
6456
6457 \layout Standard
6458
6459
6460 \backslash
6461 /
6462
6463 \end_inset
6464
6465
6466 \series bold
6467 -lib-path
6468 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6469
6470 \end_inset
6471
6472
6473 \begin_inset LatexCommand \index{-L -\/-lib-path}
6474
6475 \end_inset
6476
6477
6478 \series default
6479 \SpecialChar ~
6480 <absolute path to additional libraries> This option is passed to the linkage
6481  editor's additional libraries
6482 \begin_inset LatexCommand \index{Libraries}
6483
6484 \end_inset
6485
6486  search path.
6487  The path name must be absolute.
6488  Additional library files may be specified in the command line.
6489  See section Compiling programs for more details.
6490
6491 \layout List
6492 \labelwidthstring 00.00.0000
6493
6494 \series bold
6495 -
6496 \begin_inset ERT
6497 status Collapsed
6498
6499 \layout Standard
6500
6501
6502 \backslash
6503 /
6504
6505 \end_inset
6506
6507 -xram-loc
6508 \series default
6509
6510 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6511
6512 \end_inset
6513
6514 \SpecialChar ~
6515 <Value> The start location of the external ram
6516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6517
6518 \end_inset
6519
6520 , default value is 0.
6521  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6522 \begin_inset ERT
6523 status Collapsed
6524
6525 \layout Standard
6526
6527
6528 \backslash
6529 /
6530
6531 \end_inset
6532
6533 -xram-loc 0x8000 or -
6534 \begin_inset ERT
6535 status Collapsed
6536
6537 \layout Standard
6538
6539
6540 \backslash
6541 /
6542
6543 \end_inset
6544
6545 -xram-loc 32768.
6546
6547 \layout List
6548 \labelwidthstring 00.00.0000
6549
6550 \series bold
6551 -
6552 \begin_inset ERT
6553 status Collapsed
6554
6555 \layout Standard
6556
6557
6558 \backslash
6559 /
6560
6561 \end_inset
6562
6563 -code-loc
6564 \series default
6565
6566 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6567
6568 \end_inset
6569
6570 \SpecialChar ~
6571 <Value> The start location of the code
6572 \begin_inset LatexCommand \index{code}
6573
6574 \end_inset
6575
6576  segment, default value 0.
6577  Note when this option is used the interrupt vector table
6578 \begin_inset LatexCommand \index{interrupt vector table}
6579
6580 \end_inset
6581
6582  is also relocated to the given address.
6583  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6584 \begin_inset ERT
6585 status Collapsed
6586
6587 \layout Standard
6588
6589
6590 \backslash
6591 /
6592
6593 \end_inset
6594
6595 -code-loc 0x8000 or -
6596 \begin_inset ERT
6597 status Collapsed
6598
6599 \layout Standard
6600
6601
6602 \backslash
6603 /
6604
6605 \end_inset
6606
6607 -code-loc 32768.
6608
6609 \layout List
6610 \labelwidthstring 00.00.0000
6611
6612 \series bold
6613 -
6614 \begin_inset ERT
6615 status Collapsed
6616
6617 \layout Standard
6618
6619
6620 \backslash
6621 /
6622
6623 \end_inset
6624
6625 -stack-loc
6626 \series default
6627
6628 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6629
6630 \end_inset
6631
6632 \SpecialChar ~
6633 <Value> By default the stack
6634 \begin_inset LatexCommand \index{stack}
6635
6636 \end_inset
6637
6638  is placed after the data segment.
6639  Using this option the stack can be placed anywhere in the internal memory
6640  space of the 8051.
6641  The value entered can be in Hexadecimal or Decimal format, e.g.
6642  -
6643 \begin_inset ERT
6644 status Collapsed
6645
6646 \layout Standard
6647
6648
6649 \backslash
6650 /
6651
6652 \end_inset
6653
6654 -stack-loc 0x20 or -
6655 \begin_inset ERT
6656 status Collapsed
6657
6658 \layout Standard
6659
6660
6661 \backslash
6662 /
6663
6664 \end_inset
6665
6666 -stack-loc 32.
6667  Since the sp register is incremented before a push or call, the initial
6668  sp will be set to one byte prior the provided value.
6669  The provided value should not overlap any other memory areas such as used
6670  register banks or the data segment and with enough space for the current
6671  application.
6672  The 
6673 \series bold
6674 -
6675 \begin_inset ERT
6676 status Collapsed
6677
6678 \layout Standard
6679
6680
6681 \backslash
6682 /
6683
6684 \end_inset
6685
6686 -pack-iram
6687 \series default
6688 \SpecialChar ~
6689
6690 \begin_inset LatexCommand \index{-\/-pack-iram}
6691
6692 \end_inset
6693
6694  option (which is now a default setting) will override this setting, so
6695  you should also specify the 
6696 \series bold
6697 -
6698 \begin_inset ERT
6699 status Collapsed
6700
6701 \layout Standard
6702
6703
6704 \backslash
6705 /
6706
6707 \end_inset
6708
6709 -no-pack-iram
6710 \series default
6711 \SpecialChar ~
6712
6713 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6714
6715 \end_inset
6716
6717  option if you need to manually place the stack.
6718
6719 \layout List
6720 \labelwidthstring 00.00.0000
6721
6722 \series bold
6723 -
6724 \begin_inset ERT
6725 status Collapsed
6726
6727 \layout Standard
6728
6729
6730 \backslash
6731 /
6732
6733 \end_inset
6734
6735 -xstack-loc
6736 \series default
6737
6738 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6739
6740 \end_inset
6741
6742 \SpecialChar ~
6743 <Value> By default the external stack
6744 \begin_inset LatexCommand \index{xstack}
6745
6746 \end_inset
6747
6748  is placed after the pdata
6749 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6750
6751 \end_inset
6752
6753  segment.
6754  Using this option the xstack can be placed anywhere in the external memory
6755  space of the 8051.
6756  The value entered can be in Hexadecimal or Decimal format, e.g.
6757  -
6758 \begin_inset ERT
6759 status Collapsed
6760
6761 \layout Standard
6762
6763
6764 \backslash
6765 /
6766
6767 \end_inset
6768
6769 -xstack-loc 0x8000 or -
6770 \begin_inset ERT
6771 status Collapsed
6772
6773 \layout Standard
6774
6775
6776 \backslash
6777 /
6778
6779 \end_inset
6780
6781 -stack-loc 32768.
6782  The provided value should not overlap any other memory areas such as the
6783  pdata or xdata segment and with enough space for the current application.
6784
6785 \layout List
6786 \labelwidthstring 00.00.0000
6787
6788 \series bold
6789 -
6790 \begin_inset ERT
6791 status Collapsed
6792
6793 \layout Standard
6794
6795
6796 \backslash
6797 /
6798
6799 \end_inset
6800
6801 -data-loc
6802 \series default
6803
6804 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6805
6806 \end_inset
6807
6808 \SpecialChar ~
6809 <Value> The start location of the internal ram data
6810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6811
6812 \end_inset
6813
6814  segment.
6815  The value entered can be in Hexadecimal or Decimal format, eg.
6816  -
6817 \begin_inset ERT
6818 status Collapsed
6819
6820 \layout Standard
6821
6822
6823 \backslash
6824 /
6825
6826 \end_inset
6827
6828 -data-loc 0x20 or -
6829 \begin_inset ERT
6830 status Collapsed
6831
6832 \layout Standard
6833
6834
6835 \backslash
6836 /
6837
6838 \end_inset
6839
6840 -data-loc 32.
6841  (By default, the start location of the internal ram data segment  is set
6842  as low as possible in memory, taking into account the used register banks
6843  and the bit segment at address 0x20.
6844  For example if register banks 0 and 1 are used without bit variables, the
6845  data segment will be set, if -
6846 \begin_inset ERT
6847 status Collapsed
6848
6849 \layout Standard
6850
6851
6852 \backslash
6853 /
6854
6855 \end_inset
6856
6857 -data-loc is not used, to location 0x10.)
6858
6859 \layout List
6860 \labelwidthstring 00.00.0000
6861
6862 \series bold
6863 -
6864 \begin_inset ERT
6865 status Collapsed
6866
6867 \layout Standard
6868
6869
6870 \backslash
6871 /
6872
6873 \end_inset
6874
6875 -idata-loc
6876 \series default
6877
6878 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6879
6880 \end_inset
6881
6882 \SpecialChar ~
6883 <Value> The start location of the indirectly addressable internal ram
6884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6885
6886 \end_inset
6887
6888  of the 8051, default value is 0x80.
6889  The value entered can be in Hexadecimal or Decimal format, eg.
6890  -
6891 \begin_inset ERT
6892 status Collapsed
6893
6894 \layout Standard
6895
6896
6897 \backslash
6898 /
6899
6900 \end_inset
6901
6902 -idata-loc 0x88 or -
6903 \begin_inset ERT
6904 status Collapsed
6905
6906 \layout Standard
6907
6908
6909 \backslash
6910 /
6911
6912 \end_inset
6913
6914 -idata-loc 136.
6915
6916 \layout List
6917 \labelwidthstring 00.00.0000
6918
6919 \series bold
6920 -
6921 \begin_inset ERT
6922 status Collapsed
6923
6924 \layout Standard
6925
6926
6927 \backslash
6928 /
6929
6930 \end_inset
6931
6932 -bit-loc
6933 \series default
6934 \SpecialChar ~
6935 <Value> The start location of the bit
6936 \begin_inset LatexCommand \index{bit}
6937
6938 \end_inset
6939
6940  addressable internal ram of the 8051.
6941  This is 
6942 \emph on
6943 not
6944 \emph default
6945  implemented yet.
6946  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6947 -bBSEG=<Value>.
6948
6949 \layout List
6950 \labelwidthstring 00.00.0000
6951
6952 \series bold
6953 -
6954 \begin_inset ERT
6955 status Collapsed
6956
6957 \layout Standard
6958
6959
6960 \backslash
6961 /
6962
6963 \end_inset
6964
6965 -out-fmt-ihx
6966 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6967
6968 \end_inset
6969
6970
6971 \bar under
6972  
6973 \series default
6974 \bar default
6975 The linker output (final object code) is in Intel Hex format.
6976 \begin_inset LatexCommand \index{Intel hex format}
6977
6978 \end_inset
6979
6980  This is the default option.
6981  The format itself is documented in the documentation of srecord
6982 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6983
6984 \end_inset
6985
6986 .
6987
6988 \layout List
6989 \labelwidthstring 00.00.0000
6990
6991 \series bold
6992 -
6993 \begin_inset ERT
6994 status Collapsed
6995
6996 \layout Standard
6997
6998
6999 \backslash
7000 /
7001
7002 \end_inset
7003
7004 -out-fmt-s19
7005 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7006
7007 \end_inset
7008
7009
7010 \bar under
7011  
7012 \series default
7013 \bar default
7014 The linker output (final object code) is in Motorola S19 format
7015 \begin_inset LatexCommand \index{Motorola S19 format}
7016
7017 \end_inset
7018
7019 .
7020  The format itself is documented in the documentation of srecord.
7021
7022 \layout List
7023 \labelwidthstring 00.00.0000
7024
7025 \series bold
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032
7033 \backslash
7034 /
7035
7036 \end_inset
7037
7038 -out-fmt-elf
7039 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7040
7041 \end_inset
7042
7043
7044 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7045
7046 \end_inset
7047
7048
7049 \bar under
7050  
7051 \series default
7052 \bar default
7053 The linker output (final object code) is in ELF format
7054 \begin_inset LatexCommand \index{ELF format}
7055
7056 \end_inset
7057
7058 .
7059  (Currently only supported for the HC08
7060 \begin_inset LatexCommand \index{HC08}
7061
7062 \end_inset
7063
7064  processors)
7065
7066 \layout List
7067 \labelwidthstring 00.00.0000
7068 \added_space_bottom bigskip 
7069
7070 \series bold
7071 -Wl\SpecialChar ~
7072 linkOption[,linkOption]
7073 \series default
7074
7075 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7076
7077 \end_inset
7078
7079 ...
7080  Pass the linkOption to the linker.
7081  If a bootloader is used an option like 
7082 \begin_inset Quotes sld
7083 \end_inset
7084
7085 -Wl\SpecialChar ~
7086 -bCSEG=0x1000
7087 \begin_inset Quotes srd
7088 \end_inset
7089
7090  would be typical to set the start of the code segment.
7091  See also #pragma constseg and #pragma codeseg in section 
7092 \begin_inset LatexCommand \ref{sec:Pragmas}
7093
7094 \end_inset
7095
7096  .
7097  File sdcc/as/doc/asxhtm.html has more on linker options.
7098
7099
7100 \layout Subsection
7101 MCS51 Options
7102 \begin_inset LatexCommand \index{Options MCS51}
7103
7104 \end_inset
7105
7106
7107 \begin_inset LatexCommand \index{MCS51 options}
7108
7109 \end_inset
7110
7111
7112
7113 \layout List
7114 \labelwidthstring 00.00.0000
7115
7116 \series bold
7117 -
7118 \begin_inset ERT
7119 status Collapsed
7120
7121 \layout Standard
7122
7123
7124 \backslash
7125 /
7126
7127 \end_inset
7128
7129 -model-small
7130 \begin_inset LatexCommand \index{-\/-model-small}
7131
7132 \end_inset
7133
7134
7135 \series default
7136 \size large
7137 \emph on
7138  
7139 \size default
7140 \emph default
7141 Generate code for Small Model programs, see section Memory Models for more
7142  details.
7143  This is the default model.
7144
7145 \layout List
7146 \labelwidthstring 00.00.0000
7147
7148 \series bold
7149 -
7150 \begin_inset ERT
7151 status Collapsed
7152
7153 \layout Standard
7154
7155
7156 \backslash
7157 /
7158
7159 \end_inset
7160
7161 -model-medium
7162 \begin_inset LatexCommand \index{-\/-model-medium}
7163
7164 \end_inset
7165
7166
7167 \series default
7168  Generate code for Medium model programs, see section Memory Models for
7169  more details.
7170  If this option is used all source files in the project have to be compiled
7171  with this option.
7172  It must also be used when invoking the linker.
7173
7174 \layout List
7175 \labelwidthstring 00.00.0000
7176
7177 \series bold
7178 -
7179 \begin_inset ERT
7180 status Collapsed
7181
7182 \layout Standard
7183
7184
7185 \backslash
7186 /
7187
7188 \end_inset
7189
7190 -model-large
7191 \begin_inset LatexCommand \index{-\/-model-large}
7192
7193 \end_inset
7194
7195
7196 \series default
7197  Generate code for Large model programs, see section Memory Models for more
7198  details.
7199  If this option is used all source files in the project have to be compiled
7200  with this option.
7201  It must also be used when invoking the linker.
7202
7203 \layout List
7204 \labelwidthstring 00.00.0000
7205
7206 \series bold
7207 -
7208 \begin_inset ERT
7209 status Collapsed
7210
7211 \layout Standard
7212
7213
7214 \backslash
7215 /
7216
7217 \end_inset
7218
7219 -xstack
7220 \begin_inset LatexCommand \index{-\/-xstack}
7221
7222 \end_inset
7223
7224
7225 \series default
7226  Uses a pseudo stack in the pdata
7227 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7228
7229 \end_inset
7230
7231  area (usually the first 256 bytes in the external ram) for allocating variables
7232  and passing parameters.
7233  See section 
7234 \begin_inset LatexCommand \ref{sub:External-Stack}
7235
7236 \end_inset
7237
7238 \SpecialChar ~
7239  External Stack for more details.
7240
7241 \layout List
7242 \labelwidthstring 00.00.0000
7243
7244 \series bold
7245 -
7246 \begin_inset ERT
7247 status Collapsed
7248
7249 \layout Standard
7250
7251
7252 \backslash
7253 /
7254
7255 \end_inset
7256
7257 -iram-size
7258 \series default
7259 \SpecialChar ~
7260 <Value>
7261 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7262
7263 \end_inset
7264
7265  Causes the linker to check if the internal ram usage is within limits of
7266  the given value.
7267
7268 \layout List
7269 \labelwidthstring 00.00.0000
7270
7271 \series bold
7272 -
7273 \begin_inset ERT
7274 status Collapsed
7275
7276 \layout Standard
7277
7278
7279 \backslash
7280 /
7281
7282 \end_inset
7283
7284 -xram-size
7285 \series default
7286 \SpecialChar ~
7287 <Value>
7288 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7289
7290 \end_inset
7291
7292  Causes the linker to check if the external ram usage is within limits of
7293  the given value.
7294
7295 \layout List
7296 \labelwidthstring 00.00.0000
7297
7298 \series bold
7299 -
7300 \begin_inset ERT
7301 status Collapsed
7302
7303 \layout Standard
7304
7305
7306 \backslash
7307 /
7308
7309 \end_inset
7310
7311 -code-size
7312 \series default
7313 \SpecialChar ~
7314 <Value>
7315 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7316
7317 \end_inset
7318
7319  Causes the linker to check if the code memory usage is within limits of
7320  the given value.
7321
7322 \layout List
7323 \labelwidthstring 00.00.0000
7324
7325 \series bold
7326 -
7327 \begin_inset ERT
7328 status Collapsed
7329
7330 \layout Standard
7331
7332
7333 \backslash
7334 /
7335
7336 \end_inset
7337
7338 -stack-size
7339 \series default
7340 \SpecialChar ~
7341 <Value>
7342 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7343
7344 \end_inset
7345
7346  Causes the linker to check if there is at minimum <Value> bytes for stack.
7347
7348 \layout List
7349 \labelwidthstring 00.00.0000
7350
7351 \series bold
7352 -
7353 \begin_inset ERT
7354 status Collapsed
7355
7356 \layout Standard
7357
7358
7359 \backslash
7360 /
7361
7362 \end_inset
7363
7364 -pack-iram
7365 \series default
7366 \SpecialChar ~
7367
7368 \begin_inset LatexCommand \index{-\/-pack-iram}
7369
7370 \end_inset
7371
7372  Causes the linker to use unused register banks for data variables and pack
7373  data, idata and stack together.
7374  This is the default now.
7375
7376 \layout List
7377 \labelwidthstring 00.00.0000
7378 \added_space_bottom bigskip 
7379
7380 \series bold
7381 -
7382 \begin_inset ERT
7383 status Collapsed
7384
7385 \layout Standard
7386
7387
7388 \backslash
7389 /
7390
7391 \end_inset
7392
7393 -no-pack-iram
7394 \series default
7395 \SpecialChar ~
7396
7397 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7398
7399 \end_inset
7400
7401  Causes the linker to use old style for allocating memory areas.
7402
7403
7404 \layout Subsection
7405 DS390 / DS400 Options
7406 \begin_inset LatexCommand \index{Options DS390}
7407
7408 \end_inset
7409
7410
7411 \begin_inset LatexCommand \index{DS390}
7412
7413 \end_inset
7414
7415
7416
7417 \layout List
7418 \labelwidthstring 00.00.0000
7419
7420 \series bold
7421 -
7422 \begin_inset ERT
7423 status Collapsed
7424
7425 \layout Standard
7426
7427
7428 \backslash
7429 /
7430
7431 \end_inset
7432
7433 -model-flat24
7434 \series default
7435
7436 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7437
7438 \end_inset
7439
7440
7441 \size large
7442 \emph on
7443  
7444 \size default
7445 \emph default
7446 Generate 24-bit flat mode code.
7447  This is the one and only that the ds390 code generator supports right now
7448  and is default when using 
7449 \emph on
7450 -mds390
7451 \emph default
7452 .
7453  See section Memory Models for more details.
7454
7455 \layout List
7456 \labelwidthstring 00.00.0000
7457
7458 \series bold
7459 -
7460 \begin_inset ERT
7461 status Collapsed
7462
7463 \layout Standard
7464
7465
7466 \backslash
7467 /
7468
7469 \end_inset
7470
7471 -protect-sp-update
7472 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7473
7474 \end_inset
7475
7476
7477 \series default
7478  disable interrupts during ESP:SP updates.
7479
7480 \layout List
7481 \labelwidthstring 00.00.0000
7482
7483 \series bold
7484 -
7485 \begin_inset ERT
7486 status Collapsed
7487
7488 \layout Standard
7489
7490
7491 \backslash
7492 /
7493
7494 \end_inset
7495
7496 -stack-10bit
7497 \series default
7498
7499 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7500
7501 \end_inset
7502
7503  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7504  This is the one and only that the ds390 code generator supports right now
7505  and is default when using 
7506 \emph on
7507 -mds390
7508 \emph default
7509 .
7510  In this mode, the stack is located in the lower 1K of the internal RAM,
7511  which is mapped to 0x400000.
7512  Note that the support is incomplete, since it still uses a single byte
7513  as the stack pointer.
7514  This means that only the lower 256 bytes of the potential 1K stack space
7515  will actually be used.
7516  However, this does allow you to reclaim the precious 256 bytes of low RAM
7517  for use for the DATA and IDATA segments.
7518  The compiler will not generate any code to put the processor into 10 bit
7519  stack mode.
7520  It is important to ensure that the processor is in this mode before calling
7521  any re-entrant functions compiled with this option.
7522  In principle, this should work with the 
7523 \emph on
7524 -
7525 \begin_inset ERT
7526 status Collapsed
7527
7528 \layout Standard
7529
7530
7531 \backslash
7532 /
7533
7534 \end_inset
7535
7536 -stack-auto
7537 \begin_inset LatexCommand \index{-\/-stack-auto}
7538
7539 \end_inset
7540
7541
7542 \emph default
7543  option, but that has not been tested.
7544  It is incompatible with the 
7545 \emph on
7546 -
7547 \begin_inset ERT
7548 status Collapsed
7549
7550 \layout Standard
7551
7552
7553 \backslash
7554 /
7555
7556 \end_inset
7557
7558 -xstack
7559 \begin_inset LatexCommand \index{-\/-xstack}
7560
7561 \end_inset
7562
7563
7564 \emph default
7565  option.
7566  It also only makes sense if the processor is in 24 bit contiguous addressing
7567  mode (see the 
7568 \emph on
7569 -
7570 \begin_inset ERT
7571 status Collapsed
7572
7573 \layout Standard
7574
7575
7576 \backslash
7577 /
7578
7579 \end_inset
7580
7581 -model-flat24 option
7582 \emph default
7583 ).
7584
7585 \layout List
7586 \labelwidthstring 00.00.0000
7587
7588 \series bold
7589 -
7590 \begin_inset ERT
7591 status Collapsed
7592
7593 \layout Standard
7594
7595
7596 \backslash
7597 /
7598
7599 \end_inset
7600
7601 -stack-probe
7602 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7603
7604 \end_inset
7605
7606
7607 \series default
7608  insert call to function __stack_probe at each function prologue.
7609
7610 \layout List
7611 \labelwidthstring 00.00.0000
7612
7613 \series bold
7614 -
7615 \begin_inset ERT
7616 status Collapsed
7617
7618 \layout Standard
7619
7620
7621 \backslash
7622 /
7623
7624 \end_inset
7625
7626 -tini-libid
7627 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7628
7629 \end_inset
7630
7631
7632 \series default
7633  <nnnn> LibraryID used in -mTININative.
7634  
7635
7636 \layout List
7637 \labelwidthstring 00.00.0000
7638 \added_space_bottom bigskip 
7639
7640 \series bold
7641 -
7642 \begin_inset ERT
7643 status Collapsed
7644
7645 \layout Standard
7646
7647
7648 \backslash
7649 /
7650
7651 \end_inset
7652
7653 -use-accelerator
7654 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7655
7656 \end_inset
7657
7658
7659 \series default
7660  generate code for DS390 Arithmetic Accelerator.
7661  
7662
7663
7664 \layout Subsection
7665 Z80 Options
7666 \begin_inset LatexCommand \index{Options Z80}
7667
7668 \end_inset
7669
7670
7671 \begin_inset LatexCommand \index{Z80}
7672
7673 \end_inset
7674
7675
7676
7677 \layout List
7678 \labelwidthstring 00.00.0000
7679
7680 \series bold
7681 -
7682 \begin_inset ERT
7683 status Collapsed
7684
7685 \layout Standard
7686
7687
7688 \backslash
7689 /
7690
7691 \end_inset
7692
7693 -callee-saves-bc
7694 \series default
7695
7696 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7697
7698 \end_inset
7699
7700
7701 \size large
7702 \emph on
7703  
7704 \size default
7705 \emph default
7706 Force a called function to always save BC.
7707
7708 \layout List
7709 \labelwidthstring 00.00.0000
7710 \added_space_bottom bigskip 
7711
7712 \series bold
7713 -
7714 \begin_inset ERT
7715 status Collapsed
7716
7717 \layout Standard
7718
7719
7720 \backslash
7721 /
7722
7723 \end_inset
7724
7725 -no-std-crt0
7726 \series default
7727
7728 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7729
7730 \end_inset
7731
7732  When linking, skip the standard crt0.o object file.
7733  You must provide your own crt0.o for your system when linking.
7734  
7735
7736
7737 \layout Subsection
7738 Optimization Options
7739 \begin_inset LatexCommand \index{Options optimization}
7740
7741 \end_inset
7742
7743
7744 \begin_inset LatexCommand \index{Optimization options}
7745
7746 \end_inset
7747
7748
7749
7750 \layout List
7751 \labelwidthstring 00.00.0000
7752
7753 \series bold
7754 -
7755 \begin_inset ERT
7756 status Collapsed
7757
7758 \layout Standard
7759
7760
7761 \backslash
7762 /
7763
7764 \end_inset
7765
7766 -nogcse
7767 \begin_inset LatexCommand \index{-\/-nogcse}
7768
7769 \end_inset
7770
7771
7772 \series default
7773  Will not do global subexpression elimination, this option may be used when
7774  the compiler creates undesirably large stack/data spaces to store compiler
7775  temporaries (
7776 \emph on
7777 s
7778 \emph default
7779 pill 
7780 \emph on
7781 loc
7782 \emph default
7783 ations, sloc
7784 \begin_inset LatexCommand \index{sloc (spill location)}
7785
7786 \end_inset
7787
7788 ).
7789  A warning message will be generated when this happens and the compiler
7790  will indicate the number of extra bytes it allocated.
7791  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7792 nogcse
7793 \begin_inset LatexCommand \index{\#pragma nogcse}
7794
7795 \end_inset
7796
7797  can be used to turn off global subexpression elimination
7798 \begin_inset LatexCommand \index{Subexpression elimination}
7799
7800 \end_inset
7801
7802  for a given function only.
7803
7804 \layout List
7805 \labelwidthstring 00.00.0000
7806
7807 \series bold
7808 -
7809 \begin_inset ERT
7810 status Collapsed
7811
7812 \layout Standard
7813
7814
7815 \backslash
7816 /
7817
7818 \end_inset
7819
7820 -noinvariant
7821 \begin_inset LatexCommand \index{-\/-noinvariant}
7822
7823 \end_inset
7824
7825
7826 \series default
7827  Will not do loop invariant optimizations, this may be turned off for reasons
7828  explained for the previous option.
7829  For more details of loop optimizations performed see Loop Invariants in
7830  section 
7831 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7832
7833 \end_inset
7834
7835 .
7836  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7837 noinvariant
7838 \begin_inset LatexCommand \index{\#pragma noinvariant}
7839
7840 \end_inset
7841
7842  can be used to turn off invariant optimizations for a given function only.
7843
7844 \layout List
7845 \labelwidthstring 00.00.0000
7846
7847 \series bold
7848 -
7849 \begin_inset ERT
7850 status Collapsed
7851
7852 \layout Standard
7853
7854
7855 \backslash
7856 /
7857
7858 \end_inset
7859
7860 -noinduction
7861 \begin_inset LatexCommand \index{-\/-noinduction}
7862
7863 \end_inset
7864
7865
7866 \series default
7867  Will not do loop induction optimizations, see section strength reduction
7868  for more details.
7869  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7870 noinduction
7871 \begin_inset LatexCommand \index{\#pragma noinduction}
7872
7873 \end_inset
7874
7875  can be used to turn off induction optimizations for a given function only.
7876
7877 \layout List
7878 \labelwidthstring 00.00.0000
7879
7880 \series bold
7881 -
7882 \begin_inset ERT
7883 status Collapsed
7884
7885 \layout Standard
7886
7887
7888 \backslash
7889 /
7890
7891 \end_inset
7892
7893 -nojtbound
7894 \begin_inset LatexCommand \index{-\/-nojtbound}
7895
7896 \end_inset
7897
7898
7899 \size large
7900 \bar under
7901  
7902 \series default
7903 \size default
7904 \bar default
7905  Will not generate boundary condition check when switch statements
7906 \begin_inset LatexCommand \index{switch statement}
7907
7908 \end_inset
7909
7910  are implemented using jump-tables.
7911  See section 
7912 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7913
7914 \end_inset
7915
7916 \SpecialChar ~
7917 Switch Statements for more details.
7918  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7919 nojtbound
7920 \begin_inset LatexCommand \index{\#pragma nojtbound}
7921
7922 \end_inset
7923
7924  can be used to turn off boundary checking for jump tables for a given function
7925  only.
7926
7927 \layout List
7928 \labelwidthstring 00.00.0000
7929
7930 \series bold
7931 -
7932 \begin_inset ERT
7933 status Collapsed
7934
7935 \layout Standard
7936
7937
7938 \backslash
7939 /
7940
7941 \end_inset
7942
7943 -noloopreverse
7944 \begin_inset LatexCommand \index{-\/-noloopreverse}
7945
7946 \end_inset
7947
7948
7949 \series default
7950 \size large
7951  
7952 \size default
7953 Will not do loop reversal 
7954 \begin_inset LatexCommand \index{Loop reversing}
7955
7956 \end_inset
7957
7958 optimization.
7959
7960 \layout List
7961 \labelwidthstring 00.00.0000
7962 -
7963 \begin_inset ERT
7964 status Collapsed
7965
7966 \layout Standard
7967
7968
7969 \backslash
7970 /
7971
7972 \end_inset
7973
7974 -
7975 \series bold
7976 nolabelopt
7977 \series default
7978  
7979 \begin_inset LatexCommand \index{-\/-nolabelopt }
7980
7981 \end_inset
7982
7983 Will not optimize labels (makes the dumpfiles more readable).
7984
7985 \layout List
7986 \labelwidthstring 00.00.0000
7987
7988 \series bold
7989 -
7990 \begin_inset ERT
7991 status Collapsed
7992
7993 \layout Standard
7994
7995
7996 \backslash
7997 /
7998
7999 \end_inset
8000
8001 -no-xinit-opt
8002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8003
8004 \end_inset
8005
8006
8007 \series default
8008  Will not memcpy initialized data from code space into xdata space.
8009  This saves a few bytes in code space if you don't have initialized data
8010 \begin_inset LatexCommand \index{Variable initialization}
8011
8012 \end_inset
8013
8014 .
8015
8016 \layout List
8017 \labelwidthstring 00.00.0000
8018
8019 \series bold
8020 -
8021 \begin_inset ERT
8022 status Collapsed
8023
8024 \layout Standard
8025
8026
8027 \backslash
8028 /
8029
8030 \end_inset
8031
8032 -nooverlay
8033 \begin_inset LatexCommand \index{-\/-nooverlay}
8034
8035 \end_inset
8036
8037
8038 \series default
8039   The compiler will not overlay parameters and local variables of any function,
8040  see section Parameters and local variables for more details.
8041
8042 \layout List
8043 \labelwidthstring 00.00.0000
8044
8045 \series bold
8046 -
8047 \begin_inset ERT
8048 status Collapsed
8049
8050 \layout Standard
8051
8052
8053 \backslash
8054 /
8055
8056 \end_inset
8057
8058 -no-peep
8059 \begin_inset LatexCommand \index{-\/-no-peep}
8060
8061 \end_inset
8062
8063
8064 \series default
8065  Disable peep-hole optimization with built-in rules.
8066
8067 \layout List
8068 \labelwidthstring 00.00.0000
8069
8070 \series bold
8071 -
8072 \begin_inset ERT
8073 status Collapsed
8074
8075 \layout Standard
8076
8077
8078 \backslash
8079 /
8080
8081 \end_inset
8082
8083 -peep-file
8084 \series default
8085
8086 \begin_inset LatexCommand \index{-\/-peep-file}
8087
8088 \end_inset
8089
8090 \SpecialChar ~
8091 <filename> This option can be used to use additional rules to be used by
8092  the peep hole optimizer.
8093  See section 
8094 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8095
8096 \end_inset
8097
8098 \SpecialChar ~
8099 Peep Hole optimizations for details on how to write these rules.
8100
8101 \layout List
8102 \labelwidthstring 00.00.0000
8103
8104 \series bold
8105 -
8106 \begin_inset ERT
8107 status Collapsed
8108
8109 \layout Standard
8110
8111
8112 \backslash
8113 /
8114
8115 \end_inset
8116
8117 -peep-asm
8118 \begin_inset LatexCommand \index{-\/-peep-asm}
8119
8120 \end_inset
8121
8122
8123 \series default
8124  Pass the inline assembler code through the peep hole optimizer.
8125  This can cause unexpected changes to inline assembler code, please go through
8126  the peephole optimizer
8127 \begin_inset LatexCommand \index{Peephole optimizer}
8128
8129 \end_inset
8130
8131  rules defined in the source file tree '<target>/peeph.def' before using
8132  this option.
8133
8134 \layout List
8135 \labelwidthstring 00.00.0000
8136
8137 \series bold
8138 -
8139 \begin_inset ERT
8140 status Collapsed
8141
8142 \layout Standard
8143
8144
8145 \backslash
8146 /
8147
8148 \end_inset
8149
8150 -opt-code-speed
8151 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8152
8153 \end_inset
8154
8155
8156 \series default
8157  The compiler will optimize code generation towards fast code, possibly
8158  at the expense of code size.
8159
8160 \layout List
8161 \labelwidthstring 00.00.0000
8162 \added_space_bottom bigskip 
8163
8164 \series bold
8165 -
8166 \begin_inset ERT
8167 status Collapsed
8168
8169 \layout Standard
8170
8171
8172 \backslash
8173 /
8174
8175 \end_inset
8176
8177 -opt-code-size
8178 \begin_inset LatexCommand \index{-\/-opt-code-size}
8179
8180 \end_inset
8181
8182
8183 \series default
8184  The compiler will optimize code generation towards compact code, possibly
8185  at the expense of code speed.
8186
8187
8188 \layout Subsection
8189 Other Options
8190 \begin_inset LatexCommand \index{Options other}
8191
8192 \end_inset
8193
8194
8195
8196 \layout List
8197 \labelwidthstring 00.00.0000
8198
8199 \series bold
8200 -c\SpecialChar ~
8201 -
8202 \begin_inset ERT
8203 status Collapsed
8204
8205 \layout Standard
8206
8207
8208 \backslash
8209 /
8210
8211 \end_inset
8212
8213 -compile-only
8214 \begin_inset LatexCommand \index{-\/-compile-only}
8215
8216 \end_inset
8217
8218
8219 \begin_inset LatexCommand \index{-c -\/-compile-only}
8220
8221 \end_inset
8222
8223
8224 \series default
8225  will compile and assemble the source, but will not call the linkage editor.
8226
8227 \layout List
8228 \labelwidthstring 00.00.0000
8229
8230 \series bold
8231 -
8232 \series default
8233
8234 \begin_inset ERT
8235 status Collapsed
8236
8237 \layout Standard
8238
8239
8240 \backslash
8241 /
8242
8243 \end_inset
8244
8245
8246 \series bold
8247 -c1mode
8248 \begin_inset LatexCommand \index{-\/-c1mode}
8249
8250 \end_inset
8251
8252
8253 \series default
8254  reads the preprocessed source from standard input and compiles it.
8255  The file name for the assembler output must be specified using the -o option.
8256
8257 \layout List
8258 \labelwidthstring 00.00.0000
8259
8260 \series bold
8261 -E
8262 \begin_inset LatexCommand \index{-E}
8263
8264 \end_inset
8265
8266
8267 \series default
8268  Run only the C preprocessor.
8269  Preprocess all the C source files specified and output the results to standard
8270  output.
8271
8272 \layout List
8273 \labelwidthstring 00.00.0000
8274
8275 \series bold
8276 -o\SpecialChar ~
8277 <path/file>
8278 \begin_inset LatexCommand \index{-o <path/file>}
8279
8280 \end_inset
8281
8282  
8283 \series default
8284 The output path resp.
8285  file where everything will be placed.
8286  If the parameter is a path, it must have a trailing slash (or backslash
8287  for the Windows binaries) to be recognized as a path.
8288  
8289
8290 \layout List
8291 \labelwidthstring 00.00.0000
8292
8293 \series bold
8294 -
8295 \begin_inset ERT
8296 status Collapsed
8297
8298 \layout Standard
8299
8300
8301 \backslash
8302 /
8303
8304 \end_inset
8305
8306 -stack-auto
8307 \begin_inset LatexCommand \index{-\/-stack-auto}
8308
8309 \end_inset
8310
8311
8312 \series default
8313 \size large
8314 \emph on
8315  
8316 \size default
8317 \emph default
8318 All functions in the source file will be compiled as 
8319 \emph on
8320 reentrant
8321 \emph default
8322
8323 \begin_inset LatexCommand \index{reentrant}
8324
8325 \end_inset
8326
8327 , i.e.
8328  the parameters and local variables will be allocated on the stack
8329 \begin_inset LatexCommand \index{stack}
8330
8331 \end_inset
8332
8333 .
8334  See section 
8335 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8336
8337 \end_inset
8338
8339  Parameters and Local Variables for more details.
8340  If this option is used all source files in the project should be compiled
8341  with this option.
8342  It automatically implies --int-long-reent and --float-reent.
8343  
8344
8345 \layout List
8346 \labelwidthstring 00.00.0000
8347
8348 \series bold
8349 -
8350 \begin_inset ERT
8351 status Collapsed
8352
8353 \layout Standard
8354
8355
8356 \backslash
8357 /
8358
8359 \end_inset
8360
8361 -callee-saves
8362 \begin_inset LatexCommand \index{-\/-callee-saves}
8363
8364 \end_inset
8365
8366  function1[,function2][,function3]....
8367
8368 \series default
8369  The compiler by default uses a caller saves convention for register saving
8370  across function calls, however this can cause unnecessary register pushing
8371  & popping when calling small functions from larger functions.
8372  This option can be used to switch the register saving convention for the
8373  function names specified.
8374  The compiler will not save registers when calling these functions, no extra
8375  code will be generated at the entry & exit (function prologue
8376 \series bold
8377
8378 \begin_inset LatexCommand \index{function prologue}
8379
8380 \end_inset
8381
8382
8383 \series default
8384  & epilogue
8385 \series bold
8386
8387 \begin_inset LatexCommand \index{function epilogue}
8388
8389 \end_inset
8390
8391
8392 \series default
8393 ) for these functions to save & restore the registers used by these functions,
8394  this can SUBSTANTIALLY reduce code & improve run time performance of the
8395  generated code.
8396  In the future the compiler (with inter procedural analysis) will be able
8397  to determine the appropriate scheme to use for each function call.
8398  DO NOT use this option for built-in functions such as _mulint..., if this
8399  option is used for a library function the appropriate library function
8400  needs to be recompiled with the same option.
8401  If the project consists of multiple source files then all the source file
8402  should be compiled with the same -
8403 \begin_inset ERT
8404 status Collapsed
8405
8406 \layout Standard
8407
8408
8409 \backslash
8410 /
8411
8412 \end_inset
8413
8414 -callee-saves option string.
8415  Also see #pragma\SpecialChar ~
8416 callee_saves
8417 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8418
8419 \end_inset
8420
8421 .
8422
8423 \layout List
8424 \labelwidthstring 00.00.0000
8425
8426 \series bold
8427 -
8428 \begin_inset ERT
8429 status Collapsed
8430
8431 \layout Standard
8432
8433
8434 \backslash
8435 /
8436
8437 \end_inset
8438
8439 -debug
8440 \begin_inset LatexCommand \index{-\/-debug}
8441
8442 \end_inset
8443
8444
8445 \bar under
8446  
8447 \series default
8448 \bar default
8449 When this option is used the compiler will generate debug information.
8450  The debug information collected in a file with .cdb extension can be used
8451  with the SDCDB.
8452  For more information see documentation for SDCDB.
8453  Another file with no extension contains debug information in AOMF or AOMF51
8454 \begin_inset LatexCommand \index{AOMF, AOMF51}
8455
8456 \end_inset
8457
8458  format which is commonly used by third party tools.
8459
8460 \layout List
8461 \labelwidthstring 00.00.0000
8462
8463 \series bold
8464 -S
8465 \begin_inset LatexCommand \index{-S}
8466
8467 \end_inset
8468
8469
8470 \size large
8471 \bar under
8472  
8473 \series default
8474 \size default
8475 \bar default
8476 Stop after the stage of compilation proper; do not assemble.
8477  The output is an assembler code file for the input file specified.
8478
8479 \layout List
8480 \labelwidthstring 00.00.0000
8481
8482 \series bold
8483 -
8484 \begin_inset ERT
8485 status Collapsed
8486
8487 \layout Standard
8488
8489
8490 \backslash
8491 /
8492
8493 \end_inset
8494
8495 -int-long-reent
8496 \begin_inset LatexCommand \index{-\/-int-long-reent}
8497
8498 \end_inset
8499
8500
8501 \series default
8502  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8503  Note by default these libraries are compiled as non-reentrant.
8504  See section Installation for more details.
8505
8506 \layout List
8507 \labelwidthstring 00.00.0000
8508
8509 \series bold
8510 -
8511 \begin_inset ERT
8512 status Collapsed
8513
8514 \layout Standard
8515
8516
8517 \backslash
8518 /
8519
8520 \end_inset
8521
8522 -cyclomatic
8523 \begin_inset LatexCommand \index{-\/-cyclomatic}
8524
8525 \end_inset
8526
8527
8528 \bar under
8529  
8530 \series default
8531 \bar default
8532 This option will cause the compiler to generate an information message for
8533  each function in the source file.
8534  The message contains some 
8535 \emph on
8536 important
8537 \emph default
8538  information about the function.
8539  The number of edges and nodes the compiler detected in the control flow
8540  graph of the function, and most importantly the 
8541 \emph on
8542 cyclomatic complexity
8543 \begin_inset LatexCommand \index{Cyclomatic complexity}
8544
8545 \end_inset
8546
8547
8548 \emph default
8549  see section on Cyclomatic Complexity for more details.
8550
8551 \layout List
8552 \labelwidthstring 00.00.0000
8553
8554 \series bold
8555 -
8556 \begin_inset ERT
8557 status Collapsed
8558
8559 \layout Standard
8560
8561
8562 \backslash
8563 /
8564
8565 \end_inset
8566
8567 -float-reent
8568 \begin_inset LatexCommand \index{-\/-float-reent}
8569
8570 \end_inset
8571
8572
8573 \series default
8574  Floating point library is compiled as reentrant
8575 \begin_inset LatexCommand \index{reentrant}
8576
8577 \end_inset
8578
8579 .
8580  See section Installation for more details.
8581
8582 \layout List
8583 \labelwidthstring 00.00.0000
8584
8585 \series bold
8586 -
8587 \begin_inset ERT
8588 status Collapsed
8589
8590 \layout Standard
8591
8592
8593 \backslash
8594 /
8595
8596 \end_inset
8597
8598 -funsigned-char
8599 \begin_inset LatexCommand \index{-\/-funsigned-char}
8600
8601 \end_inset
8602
8603
8604 \series default
8605  The default signedness for every type is
8606 \family typewriter
8607  signed
8608 \family default
8609 .
8610  In some embedded environments the default signedness of
8611 \family typewriter
8612  char
8613 \family default
8614  is
8615 \family typewriter
8616  unsigned
8617 \family default
8618 .
8619  To set the signess for characters to unsigned, use the option --funsigned-char.
8620  If this option is set and no signedness keyword (unsigned/signed) is given,
8621  a char will be signed.
8622  All other types are unaffected.
8623
8624 \layout List
8625 \labelwidthstring 00.00.0000
8626
8627 \series bold
8628 -
8629 \begin_inset ERT
8630 status Collapsed
8631
8632 \layout Standard
8633
8634
8635 \backslash
8636 /
8637
8638 \end_inset
8639
8640 -main-return
8641 \begin_inset LatexCommand \index{-\/-main-return}
8642
8643 \end_inset
8644
8645
8646 \series default
8647  This option can be used if the code generated is called by a monitor program
8648  or if the main routine includes an endless loop.
8649  This option results in slightly smaller code and saves two bytes of stack
8650  space.
8651  The return from the 'main'
8652 \begin_inset LatexCommand \index{main return}
8653
8654 \end_inset
8655
8656  function will return to the function calling main.
8657  The default setting is to lock up i.e.
8658  generate a '
8659 \family typewriter
8660 sjmp .
8661 \family default
8662 '.
8663
8664 \layout List
8665 \labelwidthstring 00.00.0000
8666
8667 \series bold
8668 -
8669 \begin_inset ERT
8670 status Collapsed
8671
8672 \layout Standard
8673
8674
8675 \backslash
8676 /
8677
8678 \end_inset
8679
8680 -nostdinc
8681 \begin_inset LatexCommand \index{-\/-nostdinc}
8682
8683 \end_inset
8684
8685
8686 \series default
8687  This will prevent the compiler from passing on the default include path
8688  to the preprocessor.
8689
8690 \layout List
8691 \labelwidthstring 00.00.0000
8692
8693 \series bold
8694 -
8695 \begin_inset ERT
8696 status Collapsed
8697
8698 \layout Standard
8699
8700
8701 \backslash
8702 /
8703
8704 \end_inset
8705
8706 -nostdlib
8707 \begin_inset LatexCommand \index{-\/-nostdlib}
8708
8709 \end_inset
8710
8711
8712 \series default
8713  This will prevent the compiler from passing on the default library
8714 \begin_inset LatexCommand \index{Libraries}
8715
8716 \end_inset
8717
8718  path to the linker.
8719
8720 \layout List
8721 \labelwidthstring 00.00.0000
8722
8723 \series bold
8724 -
8725 \begin_inset ERT
8726 status Collapsed
8727
8728 \layout Standard
8729
8730
8731 \backslash
8732 /
8733
8734 \end_inset
8735
8736 -verbose
8737 \begin_inset LatexCommand \index{-\/-verbose}
8738
8739 \end_inset
8740
8741
8742 \series default
8743  Shows the various actions the compiler is performing.
8744
8745 \layout List
8746 \labelwidthstring 00.00.0000
8747
8748 \series bold
8749 -V
8750 \begin_inset LatexCommand \index{-V}
8751
8752 \end_inset
8753
8754
8755 \series default
8756  Shows the actual commands the compiler is executing.
8757
8758 \layout List
8759 \labelwidthstring 00.00.0000
8760
8761 \series bold
8762 -
8763 \begin_inset ERT
8764 status Collapsed
8765
8766 \layout Standard
8767
8768
8769 \backslash
8770 /
8771
8772 \end_inset
8773
8774 -no-c-code-in-asm
8775 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8776
8777 \end_inset
8778
8779
8780 \series default
8781  Hides your ugly and inefficient c-code from the asm file, so you can always
8782  blame the compiler :)
8783
8784 \layout List
8785 \labelwidthstring 00.00.0000
8786
8787 \series bold
8788 -
8789 \begin_inset ERT
8790 status Collapsed
8791
8792 \layout Standard
8793
8794
8795 \backslash
8796 /
8797
8798 \end_inset
8799
8800 -no-peep-comments
8801 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8802
8803 \end_inset
8804
8805
8806 \series default
8807  Will not include peep-hole comments in the generated files.
8808
8809 \layout List
8810 \labelwidthstring 00.00.0000
8811
8812 \series bold
8813 -
8814 \begin_inset ERT
8815 status Collapsed
8816
8817 \layout Standard
8818
8819
8820 \backslash
8821 /
8822
8823 \end_inset
8824
8825 -no-gen-comments
8826 \begin_inset LatexCommand \index{-\/-no-gen-comments}
8827
8828 \end_inset
8829
8830
8831 \series default
8832  Will not include code generator comments in the generated files.
8833
8834 \layout List
8835 \labelwidthstring 00.00.0000
8836
8837 \series bold
8838 -
8839 \begin_inset ERT
8840 status Collapsed
8841
8842 \layout Standard
8843
8844
8845 \backslash
8846 /
8847
8848 \end_inset
8849
8850 -i-code-in-asm
8851 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8852
8853 \end_inset
8854
8855
8856 \series default
8857  Include i-codes in the asm file.
8858  Sounds like noise but is most helpful for debugging the compiler itself.
8859
8860 \layout List
8861 \labelwidthstring 00.00.0000
8862
8863 \series bold
8864 -
8865 \begin_inset ERT
8866 status Collapsed
8867
8868 \layout Standard
8869
8870
8871 \backslash
8872 /
8873
8874 \end_inset
8875
8876 -less-pedantic
8877 \begin_inset LatexCommand \index{-\/-less-pedantic}
8878
8879 \end_inset
8880
8881
8882 \series default
8883  Disable some of the more pedantic warnings
8884 \begin_inset LatexCommand \index{Warnings}
8885
8886 \end_inset
8887
8888  (jwk burps: please be more specific here, please!).
8889
8890 \layout List
8891 \labelwidthstring 00.00.0000
8892
8893 \series bold
8894 -
8895 \begin_inset ERT
8896 status Collapsed
8897
8898 \layout Standard
8899
8900
8901 \backslash
8902 /
8903
8904 \end_inset
8905
8906 -disable-warning\SpecialChar ~
8907 <nnnn>
8908 \begin_inset LatexCommand \index{-\/-disable-warning}
8909
8910 \end_inset
8911
8912
8913 \series default
8914  Disable specific warning with number <nnnn>.
8915
8916 \layout List
8917 \labelwidthstring 00.00.0000
8918
8919 \series bold
8920 -
8921 \begin_inset ERT
8922 status Collapsed
8923
8924 \layout Standard
8925
8926
8927 \backslash
8928 /
8929
8930 \end_inset
8931
8932 -print-search-dirs
8933 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8934
8935 \end_inset
8936
8937
8938 \series default
8939  Display the directories in the compiler's search path
8940
8941 \layout List
8942 \labelwidthstring 00.00.0000
8943
8944 \series bold
8945 -
8946 \begin_inset ERT
8947 status Collapsed
8948
8949 \layout Standard
8950
8951
8952 \backslash
8953 /
8954
8955 \end_inset
8956
8957 -vc
8958 \begin_inset LatexCommand \index{-\/-vc}
8959
8960 \end_inset
8961
8962
8963 \series default
8964  Display errors and warnings using MSVC style, so you can use SDCC with
8965  the visual studio IDE
8966 \begin_inset LatexCommand \index{IDE}
8967
8968 \end_inset
8969
8970 .
8971  With SDCC both offering a GCC-like (the default) and a MSVC-like
8972 \begin_inset LatexCommand \index{MSVC output style}
8973
8974 \end_inset
8975
8976  output style, integration into most programming editors should be straightforwa
8977 rd.
8978
8979 \layout List
8980 \labelwidthstring 00.00.0000
8981
8982 \series bold
8983 -
8984 \begin_inset ERT
8985 status Collapsed
8986
8987 \layout Standard
8988
8989
8990 \backslash
8991 /
8992
8993 \end_inset
8994
8995 -use-stdout
8996 \begin_inset LatexCommand \index{-\/-use-stdout}
8997
8998 \end_inset
8999
9000
9001 \series default
9002  Send errors and warnings to stdout instead of stderr.
9003
9004 \layout List
9005 \labelwidthstring 00.00.0000
9006
9007 \series bold
9008 -Wa\SpecialChar ~
9009 asmOption[,asmOption]
9010 \series default
9011
9012 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9013
9014 \end_inset
9015
9016 ...
9017  Pass the asmOption to the assembler
9018 \begin_inset LatexCommand \index{Options assembler}
9019
9020 \end_inset
9021
9022
9023 \begin_inset LatexCommand \index{Assembler options}
9024
9025 \end_inset
9026
9027 .
9028  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9029
9030 \layout List
9031 \labelwidthstring 00.00.0000
9032
9033 \series bold
9034 -
9035 \begin_inset ERT
9036 status Collapsed
9037
9038 \layout Standard
9039
9040
9041 \backslash
9042 /
9043
9044 \end_inset
9045
9046 -std-sdcc89
9047 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9048
9049 \end_inset
9050
9051
9052 \series default
9053  Generally follow the C89 standard, but allow SDCC features that conflict
9054  with the standard (default).
9055
9056 \layout List
9057 \labelwidthstring 00.00.0000
9058
9059 \series bold
9060 -
9061 \begin_inset ERT
9062 status Collapsed
9063
9064 \layout Standard
9065
9066
9067 \backslash
9068 /
9069
9070 \end_inset
9071
9072 -std-c89
9073 \begin_inset LatexCommand \index{-\/-std-c89}
9074
9075 \end_inset
9076
9077
9078 \series default
9079  Follow the C89 standard and disable SDCC features that conflict with the
9080  standard.
9081
9082 \layout List
9083 \labelwidthstring 00.00.0000
9084
9085 \series bold
9086 -
9087 \begin_inset ERT
9088 status Collapsed
9089
9090 \layout Standard
9091
9092
9093 \backslash
9094 /
9095
9096 \end_inset
9097
9098 -std-sdcc99
9099 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9100
9101 \end_inset
9102
9103
9104 \series default
9105  Generally follow the C99 standard, but allow SDCC features that conflict
9106  with the standard (incomplete support).
9107
9108 \layout List
9109 \labelwidthstring 00.00.0000
9110
9111 \series bold
9112 -
9113 \begin_inset ERT
9114 status Collapsed
9115
9116 \layout Standard
9117
9118
9119 \backslash
9120 /
9121
9122 \end_inset
9123
9124 -std-c99
9125 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9126
9127 \end_inset
9128
9129
9130 \series default
9131  Follow the C99 standard and disable SDCC features that conflict with the
9132  standard (incomplete support).
9133
9134 \layout List
9135 \labelwidthstring 00.00.0000
9136
9137 \series bold
9138 -
9139 \begin_inset ERT
9140 status Collapsed
9141
9142 \layout Standard
9143
9144
9145 \backslash
9146 /
9147
9148 \end_inset
9149
9150 -codeseg
9151 \series default
9152
9153 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9154
9155 \end_inset
9156
9157 \SpecialChar ~
9158 <Name> The name to be used for the code
9159 \begin_inset LatexCommand \index{code}
9160
9161 \end_inset
9162
9163  segment, default CSEG.
9164  This is useful if you need to tell the compiler to put the code in a special
9165  segment so you can later on tell the linker to put this segment in a special
9166  place in memory.
9167  Can be used for instance when using bank switching to put the code in a
9168  bank.
9169
9170 \layout List
9171 \labelwidthstring 00.00.0000
9172
9173 \series bold
9174 -
9175 \begin_inset ERT
9176 status Collapsed
9177
9178 \layout Standard
9179
9180
9181 \backslash
9182 /
9183
9184 \end_inset
9185
9186 -constseg
9187 \series default
9188
9189 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9190
9191 \end_inset
9192
9193 \SpecialChar ~
9194 <Name> The name to be used for the const
9195 \begin_inset LatexCommand \index{code}
9196
9197 \end_inset
9198
9199  segment, default CONST.
9200  This is useful if you need to tell the compiler to put the const data in
9201  a special segment so you can later on tell the linker to put this segment
9202  in a special place in memory.
9203  Can be used for instance when using bank switching to put the const data
9204  in a bank.
9205
9206 \layout List
9207 \labelwidthstring 00.00.0000
9208
9209 \series bold
9210 -
9211 \begin_inset ERT
9212 status Collapsed
9213
9214 \layout Standard
9215
9216
9217 \backslash
9218 /
9219
9220 \end_inset
9221
9222 -fdollars-in-identifiers
9223 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9224
9225 \end_inset
9226
9227
9228 \series default
9229  Permit '$' as an identifier character
9230
9231 \layout List
9232 \labelwidthstring 00.00.0000
9233 \added_space_bottom bigskip 
9234
9235 \series bold
9236 more-pedantic
9237 \series default
9238  Actually this is 
9239 \series bold
9240 \emph on
9241 not
9242 \series default
9243 \emph default
9244  a SDCC compiler option but if you want 
9245 \emph on
9246 more
9247 \emph default
9248  warnings you can use a separate tool dedicated to syntax checking like
9249  splint
9250 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9251
9252 \end_inset
9253
9254
9255 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9256
9257 \end_inset
9258
9259  
9260 \begin_inset LatexCommand \url{http://www.splint.org}
9261
9262 \end_inset
9263
9264 .
9265  To make your source files parseable by splint you will have to include
9266  
9267 \family sans
9268 lint.h
9269 \family default
9270
9271 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9272
9273 \end_inset
9274
9275  in your source file and add brackets around extended keywords (like 
9276 \family sans
9277
9278 \begin_inset Quotes sld
9279 \end_inset
9280
9281 __at\SpecialChar ~
9282
9283 \series bold
9284 (
9285 \series default
9286 0xab
9287 \series bold
9288 )
9289 \series default
9290
9291 \begin_inset Quotes srd
9292 \end_inset
9293
9294
9295 \family default
9296  and 
9297 \family sans
9298
9299 \begin_inset Quotes sld
9300 \end_inset
9301
9302 __interrupt\SpecialChar ~
9303 (2)
9304 \begin_inset Quotes srd
9305 \end_inset
9306
9307
9308 \family default
9309 ).
9310  
9311 \newline
9312 Splint has an excellent on line manual at 
9313 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9314
9315 \end_inset
9316
9317  and it's capabilities go beyond pure syntax checking.
9318  You'll need to tell splint the location of SDCC's include files so a typical
9319  command line could look like this: 
9320 \newline
9321
9322 \family sans
9323 splint\SpecialChar ~
9324 -I\SpecialChar ~
9325 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9326 \SpecialChar ~
9327 myprogram.c
9328
9329
9330 \layout Subsection
9331 Intermediate Dump Options
9332 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9333
9334 \end_inset
9335
9336
9337 \begin_inset LatexCommand \index{Options intermediate dump}
9338
9339 \end_inset
9340
9341
9342 \begin_inset LatexCommand \index{Intermediate dump options}
9343
9344 \end_inset
9345
9346
9347
9348 \layout Standard
9349 The following options are provided for the purpose of retargetting and debugging
9350  the compiler.
9351  They provide a means to dump the intermediate code (iCode
9352 \begin_inset LatexCommand \index{iCode}
9353
9354 \end_inset
9355
9356 ) generated by the compiler in human readable form at various stages of
9357  the compilation process.
9358  More on iCodes see chapter 
9359 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9360
9361 \end_inset
9362
9363  
9364 \begin_inset Quotes srd
9365 \end_inset
9366
9367 The anatomy of the compiler
9368 \begin_inset Quotes srd
9369 \end_inset
9370
9371 .
9372
9373 \layout List
9374 \labelwidthstring 00.00.0000
9375
9376 \series bold
9377 -
9378 \begin_inset ERT
9379 status Collapsed
9380
9381 \layout Standard
9382
9383
9384 \backslash
9385 /
9386
9387 \end_inset
9388
9389 -dumpraw
9390 \begin_inset LatexCommand \index{-\/-dumpraw}
9391
9392 \end_inset
9393
9394
9395 \series default
9396  This option will cause the compiler to dump the intermediate code into
9397  a file of named 
9398 \emph on
9399 <source filename>.dumpraw
9400 \emph default
9401  just after the intermediate code has been generated for a function, i.e.
9402  before any optimizations are done.
9403  The basic blocks
9404 \begin_inset LatexCommand \index{Basic blocks}
9405
9406 \end_inset
9407
9408  at this stage ordered in the depth first number, so they may not be in
9409  sequence of execution.
9410
9411 \layout List
9412 \labelwidthstring 00.00.0000
9413
9414 \series bold
9415 -
9416 \begin_inset ERT
9417 status Collapsed
9418
9419 \layout Standard
9420
9421
9422 \backslash
9423 /
9424
9425 \end_inset
9426
9427 -dumpgcse
9428 \begin_inset LatexCommand \index{-\/-dumpgcse}
9429
9430 \end_inset
9431
9432
9433 \series default
9434  Will create a dump of iCode's, after global subexpression elimination
9435 \begin_inset LatexCommand \index{Global subexpression elimination}
9436
9437 \end_inset
9438
9439 , into a file named 
9440 \emph on
9441 <source filename>.dumpgcse.
9442
9443 \layout List
9444 \labelwidthstring 00.00.0000
9445
9446 \series bold
9447 -
9448 \begin_inset ERT
9449 status Collapsed
9450
9451 \layout Standard
9452
9453
9454 \backslash
9455 /
9456
9457 \end_inset
9458
9459 -dumpdeadcode
9460 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9461
9462 \end_inset
9463
9464
9465 \series default
9466  Will create a dump of iCode's, after deadcode elimination
9467 \begin_inset LatexCommand \index{Dead-code elimination}
9468
9469 \end_inset
9470
9471 , into a file named 
9472 \emph on
9473 <source filename>.dumpdeadcode.
9474
9475 \layout List
9476 \labelwidthstring 00.00.0000
9477
9478 \series bold
9479 -
9480 \begin_inset ERT
9481 status Collapsed
9482
9483 \layout Standard
9484
9485
9486 \backslash
9487 /
9488
9489 \end_inset
9490
9491 -dumploop
9492 \begin_inset LatexCommand \index{-\/-dumploop}
9493
9494 \end_inset
9495
9496
9497 \series default
9498 \size large
9499  
9500 \size default
9501 Will create a dump of iCode's, after loop optimizations
9502 \begin_inset LatexCommand \index{Loop optimization}
9503
9504 \end_inset
9505
9506 , into a file named 
9507 \emph on
9508 <source filename>.dumploop.
9509
9510 \layout List
9511 \labelwidthstring 00.00.0000
9512
9513 \series bold
9514 -
9515 \begin_inset ERT
9516 status Collapsed
9517
9518 \layout Standard
9519
9520
9521 \backslash
9522 /
9523
9524 \end_inset
9525
9526 -dumprange
9527 \begin_inset LatexCommand \index{-\/-dumprange}
9528
9529 \end_inset
9530
9531
9532 \series default
9533 \size large
9534  
9535 \size default
9536 Will create a dump of iCode's, after live range analysis
9537 \begin_inset LatexCommand \index{Live range analysis}
9538
9539 \end_inset
9540
9541 , into a file named 
9542 \emph on
9543 <source filename>.dumprange.
9544
9545 \layout List
9546 \labelwidthstring 00.00.0000
9547
9548 \series bold
9549 -
9550 \begin_inset ERT
9551 status Collapsed
9552
9553 \layout Standard
9554
9555
9556 \backslash
9557 /
9558
9559 \end_inset
9560
9561 -dumlrange
9562 \begin_inset LatexCommand \index{-\/-dumlrange}
9563
9564 \end_inset
9565
9566
9567 \series default
9568  Will dump the life ranges
9569 \begin_inset LatexCommand \index{Live range analysis}
9570
9571 \end_inset
9572
9573  for all symbols.
9574
9575 \layout List
9576 \labelwidthstring 00.00.0000
9577
9578 \series bold
9579 -
9580 \begin_inset ERT
9581 status Collapsed
9582
9583 \layout Standard
9584
9585
9586 \backslash
9587 /
9588
9589 \end_inset
9590
9591 -dumpregassign
9592 \begin_inset LatexCommand \index{-\/-dumpregassign}
9593
9594 \end_inset
9595
9596
9597 \bar under
9598  
9599 \series default
9600 \bar default
9601 Will create a dump of iCode's, after register assignment
9602 \begin_inset LatexCommand \index{Register assignment}
9603
9604 \end_inset
9605
9606 , into a file named 
9607 \emph on
9608 <source filename>.dumprassgn.
9609
9610 \layout List
9611 \labelwidthstring 00.00.0000
9612
9613 \series bold
9614 -
9615 \begin_inset ERT
9616 status Collapsed
9617
9618 \layout Standard
9619
9620
9621 \backslash
9622 /
9623
9624 \end_inset
9625
9626 -dumplrange
9627 \begin_inset LatexCommand \index{-\/-dumplrange}
9628
9629 \end_inset
9630
9631
9632 \series default
9633  Will create a dump of the live ranges of iTemp's
9634
9635 \layout List
9636 \labelwidthstring 00.00.0000
9637 \added_space_bottom bigskip 
9638
9639 \series bold
9640 -
9641 \begin_inset ERT
9642 status Collapsed
9643
9644 \layout Standard
9645
9646
9647 \backslash
9648 /
9649
9650 \end_inset
9651
9652 -dumpall
9653 \begin_inset LatexCommand \index{-\/-dumpall}
9654
9655 \end_inset
9656
9657
9658 \size large
9659 \bar under
9660  
9661 \series default
9662 \size default
9663 \bar default
9664 Will cause all the above mentioned dumps to be created.
9665
9666
9667 \layout Subsection
9668 Redirecting output on Windows Shells
9669
9670 \layout Standard
9671 \added_space_bottom bigskip 
9672 By default SDCC writes it's error messages to 
9673 \begin_inset Quotes sld
9674 \end_inset
9675
9676 standard error
9677 \begin_inset Quotes srd
9678 \end_inset
9679
9680 .
9681  To force all messages to 
9682 \begin_inset Quotes sld
9683 \end_inset
9684
9685 standard output
9686 \begin_inset Quotes srd
9687 \end_inset
9688
9689  use 
9690 \series bold
9691 -
9692 \series default
9693 \emph on
9694
9695 \begin_inset ERT
9696 status Collapsed
9697
9698 \layout Standard
9699
9700
9701 \backslash
9702 /
9703
9704 \end_inset
9705
9706
9707 \series bold
9708 \emph default
9709 -
9710 \series default
9711 use-stdout
9712 \begin_inset LatexCommand \index{-\/-use-stdout}
9713
9714 \end_inset
9715
9716 .
9717  Additionally, if you happen to have visual studio installed in your windows
9718  machine, you can use it to compile your sources using a custom build and
9719  the SDCC -
9720 \emph on
9721
9722 \begin_inset ERT
9723 status Collapsed
9724
9725 \layout Standard
9726
9727
9728 \backslash
9729 /
9730
9731 \end_inset
9732
9733
9734 \emph default
9735 -vc
9736 \begin_inset LatexCommand \index{-\/-vc}
9737
9738 \end_inset
9739
9740  option.
9741  Something like this should work:
9742 \newline
9743
9744 \newline
9745
9746 \series bold
9747 c:
9748 \backslash
9749 sdcc
9750 \backslash
9751 bin
9752 \backslash
9753 sdcc.exe -
9754 \series default
9755 \emph on
9756
9757 \begin_inset ERT
9758 status Collapsed
9759
9760 \layout Standard
9761
9762
9763 \backslash
9764 /
9765
9766 \end_inset
9767
9768
9769 \series bold
9770 \emph default
9771 -vc -
9772 \series default
9773 \emph on
9774
9775 \begin_inset ERT
9776 status Collapsed
9777
9778 \layout Standard
9779
9780
9781 \backslash
9782 /
9783
9784 \end_inset
9785
9786
9787 \series bold
9788 \emph default
9789 -model-large -c $(InputPath)
9790 \series default
9791
9792
9793
9794
9795 \layout Section
9796 Environment variables
9797 \begin_inset LatexCommand \index{Environment variables}
9798
9799 \end_inset
9800
9801
9802
9803 \layout Standard
9804 SDCC recognizes the following environment variables:
9805
9806 \layout List
9807 \labelwidthstring 00.00.0000
9808
9809 \series bold
9810 SDCC_LEAVE_SIGNALS
9811 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9812
9813 \end_inset
9814
9815
9816 \series default
9817  SDCC installs a signal handler
9818 \begin_inset LatexCommand \index{signal handler}
9819
9820 \end_inset
9821
9822  to be able to delete temporary files after an user break (^C) or an exception.
9823  If this environment variable is set, SDCC won't install the signal handler
9824  in order to be able to debug SDCC.
9825
9826 \layout List
9827 \labelwidthstring 00.00.0000
9828
9829 \series bold
9830 TMP,\SpecialChar ~
9831 TEMP,\SpecialChar ~
9832 TMPDIR
9833 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9834
9835 \end_inset
9836
9837
9838 \series default
9839  Path, where temporary files will be created.
9840  The order of the variables is the search order.
9841  In a standard *nix environment these variables are not set, and there's
9842  no need to set them.
9843  On Windows it's recommended to set one of them.
9844
9845 \layout List
9846 \labelwidthstring 00.00.0000
9847
9848 \series bold
9849 SDCC_HOME
9850 \begin_inset LatexCommand \index{SDCC\_HOME}
9851
9852 \end_inset
9853
9854
9855 \series default
9856  Path, see section 
9857 \begin_inset LatexCommand \ref{sub:Install-paths}
9858
9859 \end_inset
9860
9861 \SpecialChar ~
9862
9863 \begin_inset Quotes sld
9864 \end_inset
9865
9866  Install Paths
9867 \begin_inset Quotes srd
9868 \end_inset
9869
9870 .
9871
9872 \layout List
9873 \labelwidthstring 00.00.0000
9874
9875 \series bold
9876 SDCC_INCLUDE
9877 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9878
9879 \end_inset
9880
9881
9882 \series default
9883  Path, see section 
9884 \begin_inset LatexCommand \ref{sub:Search-Paths}
9885
9886 \end_inset
9887
9888 \SpecialChar ~
9889
9890 \begin_inset Quotes sld
9891 \end_inset
9892
9893 Search Paths
9894 \begin_inset Quotes srd
9895 \end_inset
9896
9897 .
9898
9899 \layout List
9900 \labelwidthstring 00.00.0000
9901
9902 \series bold
9903 SDCC_LIB
9904 \begin_inset LatexCommand \index{SDCC\_LIB}
9905
9906 \end_inset
9907
9908
9909 \series default
9910  Path, see section 
9911 \begin_inset LatexCommand \ref{sub:Search-Paths}
9912
9913 \end_inset
9914
9915 \SpecialChar ~
9916
9917 \begin_inset Quotes sld
9918 \end_inset
9919
9920 Search Paths
9921 \begin_inset Quotes srd
9922 \end_inset
9923
9924 ..
9925
9926 \layout Standard
9927 \added_space_bottom bigskip 
9928 There are some more environment variables recognized by SDCC, but these
9929  are solely used for debugging purposes.
9930  They can change or disappear very quickly, and will never be documented.
9931
9932
9933
9934 \layout Section
9935 Storage Class Language Extensions
9936
9937 \layout Subsection
9938 MCS51/DS390 Storage Class
9939 \begin_inset LatexCommand \index{Storage class}
9940
9941 \end_inset
9942
9943  Language Extensions
9944
9945 \layout Standard
9946 In addition to the ANSI storage classes SDCC allows the following MCS51
9947  specific storage classes:
9948
9949 \layout Subsubsection
9950 data
9951 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9952
9953 \end_inset
9954
9955
9956 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9957
9958 \end_inset
9959
9960  / near
9961 \begin_inset LatexCommand \index{near (storage class)}
9962
9963 \end_inset
9964
9965
9966 \begin_inset LatexCommand \index{\_\_near (storage class)}
9967
9968 \end_inset
9969
9970
9971
9972 \layout Standard
9973 This is the 
9974 \series bold
9975 default
9976 \series default
9977  storage class for the Small Memory model (
9978 \emph on
9979 data
9980 \emph default
9981  and 
9982 \emph on
9983 near
9984 \emph default
9985  or the more ANSI-C compliant forms 
9986 \emph on
9987 __data
9988 \emph default
9989  and 
9990 \emph on
9991 __near
9992 \emph default
9993  can be used synonymously).
9994  Variables declared with this storage class will be allocated in the directly
9995  addressable portion of the internal RAM of a 8051, e.g.:
9996
9997 \layout Verse
9998
9999 \family typewriter
10000 __data unsigned char test_data;
10001
10002 \layout Standard
10003 Writing 0x01 to this variable generates the assembly code:
10004
10005 \layout Verse
10006
10007 \family typewriter
10008 75*00 01\SpecialChar ~
10009 \SpecialChar ~
10010 \SpecialChar ~
10011 mov\SpecialChar ~
10012 \SpecialChar ~
10013 _test_data,#0x01
10014
10015 \layout Subsubsection
10016 xdata
10017 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10018
10019 \end_inset
10020
10021
10022 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10023
10024 \end_inset
10025
10026  / far
10027 \begin_inset LatexCommand \index{far (storage class)}
10028
10029 \end_inset
10030
10031
10032 \begin_inset LatexCommand \index{\_\_far (storage class)}
10033
10034 \end_inset
10035
10036
10037
10038 \layout Standard
10039 Variables declared with this storage class will be placed in the external
10040  RAM.
10041  This is the 
10042 \series bold
10043 default
10044 \series default
10045  storage class for the Large Memory model, e.g.:
10046
10047 \layout Verse
10048
10049 \family typewriter
10050 __xdata unsigned char test_xdata;
10051
10052 \layout Standard
10053 Writing 0x01 to this variable generates the assembly code:
10054
10055 \layout Verse
10056
10057 \family typewriter
10058 90s00r00\SpecialChar ~
10059 \SpecialChar ~
10060 \SpecialChar ~
10061 mov\SpecialChar ~
10062 \SpecialChar ~
10063 dptr,#_test_xdata 
10064 \newline
10065 74\SpecialChar ~
10066 01\SpecialChar ~
10067 \SpecialChar ~
10068 \SpecialChar ~
10069 \SpecialChar ~
10070 \SpecialChar ~
10071 \SpecialChar ~
10072 mov\SpecialChar ~
10073 \SpecialChar ~
10074 a,#0x01 
10075 \newline
10076 F0\SpecialChar ~
10077 \SpecialChar ~
10078 \SpecialChar ~
10079 \SpecialChar ~
10080 \SpecialChar ~
10081 \SpecialChar ~
10082 \SpecialChar ~
10083 \SpecialChar ~
10084 \SpecialChar ~
10085 movx\SpecialChar ~
10086 @dptr,a 
10087
10088 \layout Subsubsection
10089 idata
10090 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10091
10092 \end_inset
10093
10094
10095 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10096
10097 \end_inset
10098
10099
10100
10101 \layout Standard
10102 Variables declared with this storage class will be allocated into the indirectly
10103  addressable portion of the internal ram of a 8051, e.g.:
10104
10105 \layout Verse
10106
10107 \family typewriter
10108 __idata unsigned char test_idata;
10109
10110 \layout Standard
10111 Writing 0x01 to this variable generates the assembly code:
10112
10113 \layout Verse
10114
10115 \family typewriter
10116 78r00\SpecialChar ~
10117 \SpecialChar ~
10118 \SpecialChar ~
10119 \SpecialChar ~
10120 \SpecialChar ~
10121 \SpecialChar ~
10122 \SpecialChar ~
10123 mov\SpecialChar ~
10124 \SpecialChar ~
10125 r0,#_test_idata
10126 \newline
10127 76\SpecialChar ~
10128 01\SpecialChar ~
10129 \SpecialChar ~
10130 \SpecialChar ~
10131 \SpecialChar ~
10132 \SpecialChar ~
10133 \SpecialChar ~
10134 \SpecialChar ~
10135 mov\SpecialChar ~
10136 \SpecialChar ~
10137 @r0,#0x01
10138
10139 \layout Standard
10140 Please note, the first 128 byte of idata physically access the same RAM
10141  as the data memory.
10142  The original 8051 had 128 byte idata memory, nowadays most devices have
10143  256 byte idata memory.
10144  The stack
10145 \begin_inset LatexCommand \index{stack}
10146
10147 \end_inset
10148
10149  is located in idata memory.
10150
10151 \layout Subsubsection
10152 pdata
10153 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10154
10155 \end_inset
10156
10157
10158 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10159
10160 \end_inset
10161
10162
10163
10164 \layout Standard
10165 Paged xdata access is just as straightforward as using the other addressing
10166  modes of a 8051.
10167  It is typically located at the start of xdata and has a maximum size of
10168  256 bytes.
10169  The following example writes 0x01 to the pdata variable.
10170  Please note, pdata access physically accesses xdata memory.
10171  The high byte of the address is determined by port P2 
10172 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10173
10174 \end_inset
10175
10176 (or in case of some 8051 variants by a separate Special Function Register,
10177  see section 
10178 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10179
10180 \end_inset
10181
10182 ).
10183  This is the 
10184 \series bold
10185 default
10186 \series default
10187  storage class for the Medium Memory model, e.g.:
10188
10189 \layout Verse
10190
10191 \family typewriter
10192 __pdata unsigned char test_pdata;
10193
10194 \layout Standard
10195 Writing 0x01 to this variable generates the assembly code:
10196
10197 \layout Verse
10198
10199 \family typewriter
10200 78r00\SpecialChar ~
10201 \SpecialChar ~
10202 \SpecialChar ~
10203 \SpecialChar ~
10204 \SpecialChar ~
10205 \SpecialChar ~
10206 mov r0,#_test_pdata
10207 \newline
10208 74 01\SpecialChar ~
10209 \SpecialChar ~
10210 \SpecialChar ~
10211 \SpecialChar ~
10212 \SpecialChar ~
10213 \SpecialChar ~
10214 mov a,#0x01 
10215 \newline
10216 F2\SpecialChar ~
10217 \SpecialChar ~
10218 \SpecialChar ~
10219 \SpecialChar ~
10220 \SpecialChar ~
10221 \SpecialChar ~
10222 \SpecialChar ~
10223 \SpecialChar ~
10224 \SpecialChar ~
10225 movx @r0,a
10226
10227 \layout Standard
10228 If the -
10229 \begin_inset ERT
10230 status Collapsed
10231
10232 \layout Standard
10233
10234
10235 \backslash
10236 /
10237
10238 \end_inset
10239
10240 -xstack
10241 \begin_inset LatexCommand \index{-\/-xstack}
10242
10243 \end_inset
10244
10245  option is used the pdata memory area is followed by the xstack memory area
10246  and the sum of their sizes is limited to 256 bytes.
10247
10248 \layout Subsubsection
10249 code
10250 \begin_inset LatexCommand \index{code}
10251
10252 \end_inset
10253
10254
10255 \begin_inset LatexCommand \index{\_\_code}
10256
10257 \end_inset
10258
10259
10260
10261 \layout Standard
10262 'Variables' declared with this storage class will be placed in the code
10263  memory:
10264
10265 \layout Verse
10266
10267 \family typewriter
10268 __code unsigned char test_code;
10269
10270 \layout Standard
10271 Read access to this variable generates the assembly code:
10272
10273 \layout Verse
10274
10275 \family typewriter
10276 90s00r6F\SpecialChar ~
10277 \SpecialChar ~
10278 \SpecialChar ~
10279 mov dptr,#_test_code
10280 \newline
10281 E4\SpecialChar ~
10282 \SpecialChar ~
10283 \SpecialChar ~
10284 \SpecialChar ~
10285 \SpecialChar ~
10286 \SpecialChar ~
10287 \SpecialChar ~
10288 \SpecialChar ~
10289 \SpecialChar ~
10290 clr a
10291 \newline
10292 93\SpecialChar ~
10293 \SpecialChar ~
10294 \SpecialChar ~
10295 \SpecialChar ~
10296 \SpecialChar ~
10297 \SpecialChar ~
10298 \SpecialChar ~
10299 \SpecialChar ~
10300 \SpecialChar ~
10301 movc a,@a+dptr 
10302
10303 \layout Standard
10304
10305 \family typewriter
10306 char
10307 \family default
10308  indexed arrays of characters in code memory can be accessed efficiently:
10309
10310 \layout Verse
10311
10312 \family typewriter
10313 __code char test_array[] = {'c','h','e','a','p'}; 
10314
10315 \layout Standard
10316 Read access to this array using an 8-bit unsigned index generates the assembly
10317  code:
10318
10319 \layout Verse
10320
10321 \family typewriter
10322 E5*00\SpecialChar ~
10323 \SpecialChar ~
10324 \SpecialChar ~
10325 \SpecialChar ~
10326 \SpecialChar ~
10327 \SpecialChar ~
10328 mov a,_index 
10329
10330 \layout Verse
10331
10332 \family typewriter
10333 90s00r41\SpecialChar ~
10334 \SpecialChar ~
10335 \SpecialChar ~
10336 mov dptr,#_test_array
10337
10338 \layout Verse
10339
10340 \family typewriter
10341 93\SpecialChar ~
10342 \SpecialChar ~
10343 \SpecialChar ~
10344 \SpecialChar ~
10345 \SpecialChar ~
10346 \SpecialChar ~
10347 \SpecialChar ~
10348 \SpecialChar ~
10349 \SpecialChar ~
10350 movc a,@a+dptr 
10351
10352 \layout Subsubsection
10353 bit
10354 \begin_inset LatexCommand \index{bit}
10355
10356 \end_inset
10357
10358
10359 \begin_inset LatexCommand \index{\_\_bit}
10360
10361 \end_inset
10362
10363
10364
10365 \layout Standard
10366 This is a data-type and a storage class specifier.
10367  When a variable is declared as a bit, it is allocated into the bit addressable
10368  memory of 8051, e.g.:
10369
10370 \layout Verse
10371
10372 \family typewriter
10373 __bit test_bit;
10374
10375 \layout Standard
10376 Writing 1 to this variable generates the assembly code:
10377
10378 \layout Verse
10379
10380 \family typewriter
10381 D2*00\SpecialChar ~
10382 \SpecialChar ~
10383 \SpecialChar ~
10384 \SpecialChar ~
10385 \SpecialChar ~
10386 \SpecialChar ~
10387 \SpecialChar ~
10388 setb\SpecialChar ~
10389 _test_bit
10390
10391 \layout Standard
10392 The bit addressable memory consists of 128 bits which are located from 0x20
10393  to 0x2f in data memory.
10394  
10395 \newline
10396 Apart from this 8051 specific storage class most architectures support
10397  ANSI-C bitfields
10398 \begin_inset LatexCommand \index{bitfields}
10399
10400 \end_inset
10401
10402
10403 \begin_inset Foot
10404 collapsed false
10405
10406 \layout Standard
10407 Not really meant as examples, but nevertheless showing what bitfields are
10408  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10409
10410 \end_inset
10411
10412 .
10413  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10414  signed modifier are implemented as unsigned.
10415
10416 \layout Subsubsection
10417 sfr
10418 \begin_inset LatexCommand \index{sfr}
10419
10420 \end_inset
10421
10422
10423 \begin_inset LatexCommand \index{\_\_sfr}
10424
10425 \end_inset
10426
10427  / sfr16
10428 \begin_inset LatexCommand \index{sfr16}
10429
10430 \end_inset
10431
10432
10433 \begin_inset LatexCommand \index{\_\_sfr16}
10434
10435 \end_inset
10436
10437  / sfr32
10438 \begin_inset LatexCommand \index{sfr32}
10439
10440 \end_inset
10441
10442
10443 \begin_inset LatexCommand \index{\_\_sfr32}
10444
10445 \end_inset
10446
10447  / sbit
10448 \begin_inset LatexCommand \index{\_\_sbit}
10449
10450 \end_inset
10451
10452
10453 \begin_inset LatexCommand \index{sbit}
10454
10455 \end_inset
10456
10457
10458
10459 \layout Standard
10460 Like the bit keyword, 
10461 \emph on
10462 sfr / sfr16 / sfr32 / sbit 
10463 \emph default
10464 signify both a data-type and storage class, they are used to describe the
10465  
10466 \emph on
10467 s
10468 \emph default
10469 pecial 
10470 \emph on
10471 f
10472 \emph default
10473 unction 
10474 \emph on
10475 r
10476 \emph default
10477 egisters and 
10478 \emph on
10479 s
10480 \emph default
10481 pecial 
10482 \emph on
10483 bit
10484 \emph default
10485  variables of a 8051, eg:
10486
10487 \layout Verse
10488
10489 \family typewriter
10490 __sfr __at
10491 \begin_inset LatexCommand \index{at}
10492
10493 \end_inset
10494
10495
10496 \begin_inset LatexCommand \index{\_\_at}
10497
10498 \end_inset
10499
10500  (0x80) P0;\SpecialChar ~
10501  /* special function register P0 at location 0x80 */
10502 \newline
10503
10504 \newline
10505 /* 16 bit
10506  special function register combination for timer 0
10507 \newline
10508 \SpecialChar ~
10509 \SpecialChar ~
10510  with the high byte at
10511  location 0x8C and the low byte at location 0x8A */
10512 \newline
10513 __sfr16 __at (0x8C8A)
10514  TMR0;
10515 \newline
10516
10517 \newline
10518 __sbit __at
10519 \begin_inset LatexCommand \index{at}
10520
10521 \end_inset
10522
10523
10524 \begin_inset LatexCommand \index{\_\_at}
10525
10526 \end_inset
10527
10528  (0xd7) CY;\SpecialChar ~
10529  /* CY (Carry Flag
10530 \begin_inset LatexCommand \index{Flags}
10531
10532 \end_inset
10533
10534
10535 \begin_inset LatexCommand \index{Carry flag}
10536
10537 \end_inset
10538
10539 ) */
10540
10541 \layout Standard
10542 Special function registers which are located on an address dividable by
10543  8 are bit-addressable, an
10544 \emph on
10545  sbit
10546 \emph default
10547  addresses a specific bit within these sfr.
10548 \newline
10549 16 Bit and 32 bit special function
10550  register combinations which require a certain access order are better not
10551  declared using 
10552 \emph on
10553 sfr16
10554 \emph default
10555  or 
10556 \emph on
10557 sfr32.
10558
10559 \emph default
10560  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10561  this is not guaranteed.
10562 \newline
10563
10564
10565 \layout Standard
10566 Please note, if you use a header file which was written for another compiler
10567  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10568  likely be 
10569 \emph on
10570 not 
10571 \emph default
10572 compatible.
10573  Specifically the syntax 
10574 \family typewriter
10575 \SpecialChar ~
10576 sfr P0 = 0x80;\SpecialChar ~
10577
10578 \family default
10579  is compiled 
10580 \emph on
10581 without warning
10582 \emph default
10583  by SDCC to an assignment of 0x80 to a variable called P0 
10584 \family typewriter
10585
10586 \begin_inset Marginal
10587 collapsed true
10588
10589 \layout Standard
10590
10591 \series bold
10592 \SpecialChar ~
10593 !
10594
10595 \end_inset
10596
10597 .
10598  
10599 \family default
10600 Nevertheless it is possible to write header files
10601 \begin_inset LatexCommand \index{Header files}
10602
10603 \end_inset
10604
10605
10606 \begin_inset LatexCommand \index{Include files}
10607
10608 \end_inset
10609
10610  which can be shared among different compilers (see section 
10611 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10612
10613 \end_inset
10614
10615 ).
10616  
10617
10618 \layout Subsubsection
10619 Pointers
10620 \begin_inset LatexCommand \index{Pointer}
10621
10622 \end_inset
10623
10624  to MCS51/DS390 specific memory spaces
10625
10626 \layout Standard
10627 SDCC allows (via language extensions) pointers to explicitly point to any
10628  of the memory spaces
10629 \begin_inset LatexCommand \index{Memory model}
10630
10631 \end_inset
10632
10633  of the 8051.
10634  In addition to the explicit pointers, the compiler uses (by default) generic
10635  pointers which can be used to point to any of the memory spaces.
10636 \newline
10637
10638 \newline
10639 Pointer
10640  declaration examples:
10641
10642 \layout Verse
10643
10644 \family typewriter
10645 /* pointer physically in internal ram pointing to object in external ram
10646  */ 
10647 \newline
10648 __xdata unsigned char * __data p;
10649 \newline
10650
10651 \newline
10652 /* pointer physically in external ram
10653  pointing to object in internal ram */ 
10654 \newline
10655 __data unsigned char * __xdata p;
10656 \newline
10657
10658 \newline
10659 /*
10660  pointer physically in code rom pointing to data in xdata space */ 
10661 \newline
10662 __xdata
10663  unsigned char * __code p;
10664 \newline
10665
10666 \newline
10667 /* pointer physically in code space pointing to
10668  data in code space */ 
10669 \newline
10670 __code unsigned char * __code p;
10671 \newline
10672
10673 \newline
10674 /* generic pointer
10675  physically located in xdata space */
10676 \newline
10677 unsigned char * __xdata p;
10678 \newline
10679
10680 \newline
10681 /* generic
10682  pointer physically located in default memory space */
10683 \newline
10684 unsigned char * p;
10685 \newline
10686
10687 \newline
10688 /*
10689  the following is a function pointer
10690 \begin_inset LatexCommand \index{function pointer}
10691
10692 \end_inset
10693
10694  physically located in data space */
10695 \newline
10696 char (* __data fp)(void);
10697
10698 \layout Standard
10699 Well you get the idea.
10700  
10701 \newline
10702
10703 \newline
10704 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10705 \emph on
10706 generic
10707 \emph default
10708  pointers.
10709  
10710 \size small
10711
10712 \newline
10713
10714 \newline
10715
10716 \size default
10717 The highest order byte of the 
10718 \emph on
10719 generic
10720 \emph default
10721  pointers contains the data space information.
10722  Assembler support routines are called whenever data is stored or retrieved
10723  using 
10724 \emph on
10725 generic
10726 \emph default
10727  pointers.
10728  These are useful for developing reusable library
10729 \begin_inset LatexCommand \index{Libraries}
10730
10731 \end_inset
10732
10733  routines.
10734  Explicitly specifying the pointer
10735 \begin_inset LatexCommand \index{pointer}
10736
10737 \end_inset
10738
10739  type will generate the most efficient code.
10740
10741 \layout Subsubsection
10742 Notes on MCS51 memory
10743 \begin_inset LatexCommand \index{MCS51 memory}
10744
10745 \end_inset
10746
10747  layout
10748
10749 \layout Standard
10750 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10751  RAM memory which is structured as follows:
10752 \newline
10753
10754 \newline
10755 - Bytes 00-1F - 32 bytes to hold
10756  up to 4 banks of the registers R0 to R7, 
10757 \newline
10758 - Bytes 20-2F - 16 bytes to hold
10759  128 bit
10760 \begin_inset LatexCommand \index{bit}
10761
10762 \end_inset
10763
10764  variables and, 
10765 \newline
10766 - Bytes 30-7F - 80 bytes for general purpose use.
10767 \newline
10768
10769
10770 \layout Standard
10771 Additionally some members of the MCS51 family may have up to 128 bytes of
10772  additional, indirectly addressable, internal RAM memory (
10773 \emph on
10774 idata
10775 \emph default
10776
10777 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10778
10779 \end_inset
10780
10781
10782 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10783
10784 \end_inset
10785
10786 ).
10787  Furthermore, some chips may have some built in external memory (
10788 \emph on
10789 xdata
10790 \emph default
10791
10792 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10793
10794 \end_inset
10795
10796
10797 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10798
10799 \end_inset
10800
10801 ) which should not be confused with the internal, directly addressable RAM
10802  memory (
10803 \emph on
10804 data
10805 \emph default
10806
10807 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10808
10809 \end_inset
10810
10811
10812 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10813
10814 \end_inset
10815
10816 ).
10817  Sometimes this built in 
10818 \emph on
10819 xdata
10820 \emph default
10821  memory has to be activated before using it (you can probably find this
10822  information on the datasheet of the microcontroller your are using, see
10823  also section 
10824 \begin_inset LatexCommand \ref{sub:Startup-Code}
10825
10826 \end_inset
10827
10828 \SpecialChar ~
10829 Startup-Code).
10830
10831 \layout Standard
10832 Normally SDCC will only use the first bank
10833 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10834
10835 \end_inset
10836
10837  of registers (register bank 0), but it is possible to specify that other
10838  banks of registers (keyword 
10839 \emph on
10840 using
10841 \emph default
10842  
10843 \emph on
10844
10845 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10846
10847 \end_inset
10848
10849
10850 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10851
10852 \end_inset
10853
10854
10855 \emph default
10856 ) should be used in interrupt
10857 \begin_inset LatexCommand \index{interrupt}
10858
10859 \end_inset
10860
10861
10862 \begin_inset LatexCommand \index{\_\_interrupt}
10863
10864 \end_inset
10865
10866  routines.
10867  By default, the compiler will place the stack after the last byte of allocated
10868  memory for variables.
10869  For example, if the first 2 banks of registers are used, and only four
10870  bytes are used for 
10871 \emph on
10872 data
10873 \emph default
10874  variables, it will position the base of the internal stack at address 20
10875  (0x14).
10876  This implies that as the stack
10877 \begin_inset LatexCommand \index{stack}
10878
10879 \end_inset
10880
10881  grows, it will use up the remaining register banks, and the 16 bytes used
10882  by the 128 bit variables, and 80 bytes for general purpose use.
10883  If any bit variables are used, the data variables will be placed in unused
10884  register banks and after the byte holding the last bit variable.
10885  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10886  (two bytes used), 
10887 \emph on
10888 data
10889 \emph default
10890  variables will be placed starting from address 0x10 to 0x20 and continue
10891  at address 0x22.
10892  You can also use -
10893 \begin_inset ERT
10894 status Collapsed
10895
10896 \layout Standard
10897
10898
10899 \backslash
10900 /
10901
10902 \end_inset
10903
10904 -data-loc
10905 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10906
10907 \end_inset
10908
10909  to specify the start address of the 
10910 \emph on
10911 data
10912 \emph default
10913  and -
10914 \begin_inset ERT
10915 status Collapsed
10916
10917 \layout Standard
10918
10919
10920 \backslash
10921 /
10922
10923 \end_inset
10924
10925 -iram-size
10926 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10927
10928 \end_inset
10929
10930  to specify the size of the total internal RAM (
10931 \emph on
10932 data
10933 \emph default
10934 +
10935 \emph on
10936 idata
10937 \emph default
10938 ).
10939  
10940 \newline
10941
10942
10943 \layout Standard
10944 By default the 8051 linker will place the stack after the last byte of (i)data
10945  variables.
10946  Option -
10947 \begin_inset ERT
10948 status Collapsed
10949
10950 \layout Standard
10951
10952
10953 \backslash
10954 /
10955
10956 \end_inset
10957
10958 -stack-loc
10959 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10960
10961 \end_inset
10962
10963  allows you to specify the start of the stack, i.e.
10964  you could start it after any data in the general purpose area.
10965  If your microcontroller has additional indirectly addressable internal
10966  RAM (
10967 \emph on
10968 idata
10969 \emph default
10970 ) you can place the stack on it.
10971  You may also need to use -
10972 \begin_inset ERT
10973 status Collapsed
10974
10975 \layout Standard
10976
10977
10978 \backslash
10979 /
10980
10981 \end_inset
10982
10983 -xdata-loc
10984 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10985
10986 \end_inset
10987
10988  to set the start address of the external RAM (
10989 \emph on
10990 xdata
10991 \emph default
10992 ) and -
10993 \begin_inset ERT
10994 status Collapsed
10995
10996 \layout Standard
10997
10998
10999 \backslash
11000 /
11001
11002 \end_inset
11003
11004 -xram-size
11005 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11006
11007 \end_inset
11008
11009  to specify its size.
11010  Same goes for the code memory, using -
11011 \begin_inset ERT
11012 status Collapsed
11013
11014 \layout Standard
11015
11016
11017 \backslash
11018 /
11019
11020 \end_inset
11021
11022 -code-loc
11023 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11024
11025 \end_inset
11026
11027  and -
11028 \begin_inset ERT
11029 status Collapsed
11030
11031 \layout Standard
11032
11033
11034 \backslash
11035 /
11036
11037 \end_inset
11038
11039 -code-size
11040 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11041
11042 \end_inset
11043
11044 .
11045  If in doubt, don't specify any options and see if the resulting memory
11046  layout is appropriate, then you can adjust it.
11047
11048 \layout Standard
11049 \added_space_bottom bigskip 
11050 The linker generates two files with memory allocation information.
11051  The first, with extension .map
11052 \begin_inset LatexCommand \index{<file>.map}
11053
11054 \end_inset
11055
11056  shows all the variables and segments.
11057  The second with extension .mem
11058 \begin_inset LatexCommand \index{<file>.mem}
11059
11060 \end_inset
11061
11062  shows the final memory layout.
11063  The linker will complain either if memory segments overlap, there is not
11064  enough memory, or there is not enough space for stack.
11065  If you get any linking warnings and/or errors related to stack or segments
11066  allocation, take a look at either the .map or .mem files to find out what
11067  the problem is.
11068  The .mem file may even suggest a solution to the problem.
11069
11070
11071
11072 \layout Subsection
11073 Z80/Z180 Storage Class
11074 \begin_inset LatexCommand \index{Z80!Storage class}
11075
11076 \end_inset
11077
11078  Language Extensions
11079
11080 \layout Subsubsection
11081 sfr
11082 \begin_inset LatexCommand \index{sfr}
11083
11084 \end_inset
11085
11086
11087 \begin_inset LatexCommand \index{\_\_sfr}
11088
11089 \end_inset
11090
11091  (in/out to 8-bit addresses)
11092
11093 \layout Standard
11094 The Z80
11095 \begin_inset LatexCommand \index{Z80}
11096
11097 \end_inset
11098
11099  family has separate address spaces for memory and 
11100 \emph on
11101 i
11102 \emph default
11103 nput/
11104 \emph on
11105 o
11106 \emph default
11107 utput memory.
11108  I/O memory
11109 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11110
11111 \end_inset
11112
11113
11114 \begin_inset LatexCommand \index{Z80!I/O memory}
11115
11116 \end_inset
11117
11118
11119 \begin_inset LatexCommand \index{Z180!I/O memory}
11120
11121 \end_inset
11122
11123  is accessed with special instructions, e.g.:
11124
11125 \layout Verse
11126
11127 \family typewriter
11128 sfr at 0x78 IoPort;\SpecialChar ~
11129 \SpecialChar ~
11130 /* define a var in I/O space at 78h called IoPort */
11131  
11132
11133 \layout Standard
11134 Writing 0x01 to this variable generates the assembly code:
11135
11136 \layout Verse
11137
11138 \family typewriter
11139 3E 01\SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 ld a,#0x01
11146 \newline
11147 D3 78\SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 out (_IoPort),a 
11154
11155 \layout Subsubsection
11156 banked sfr
11157 \begin_inset LatexCommand \index{sfr}
11158
11159 \end_inset
11160
11161
11162 \begin_inset LatexCommand \index{\_\_sfr}
11163
11164 \end_inset
11165
11166  (in/out to 16-bit addresses)
11167
11168 \layout Standard
11169 The keyword 
11170 \emph on
11171 banked
11172 \emph default
11173  is used to support 16 bit addresses in I/O memory e.g.:
11174
11175 \layout Verse
11176
11177 \family typewriter
11178 sfr banked at
11179 \begin_inset LatexCommand \index{at}
11180
11181 \end_inset
11182
11183
11184 \begin_inset LatexCommand \index{\_\_at}
11185
11186 \end_inset
11187
11188  0x123 IoPort; 
11189
11190 \layout Standard
11191 Writing 0x01 to this variable generates the assembly code:
11192
11193 \layout Verse
11194
11195 \family typewriter
11196 01 23 01\SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 ld bc,#_IoPort
11200 \newline
11201 3E 01\SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 \SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 ld a,#0x01 
11208 \newline
11209 ED 79\SpecialChar ~
11210 \SpecialChar ~
11211 \SpecialChar ~
11212 \SpecialChar ~
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 out (c),a 
11216
11217 \layout Subsubsection
11218 sfr
11219 \begin_inset LatexCommand \index{sfr}
11220
11221 \end_inset
11222
11223
11224 \begin_inset LatexCommand \index{\_\_sfr}
11225
11226 \end_inset
11227
11228  (in0/out0 to 8 bit addresses on Z180
11229 \begin_inset LatexCommand \index{Z180}
11230
11231 \end_inset
11232
11233 /HD64180
11234 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11235
11236 \end_inset
11237
11238 )
11239
11240 \layout Standard
11241 \added_space_bottom bigskip 
11242 The compiler option -
11243 \begin_inset ERT
11244 status Collapsed
11245
11246 \layout Standard
11247
11248
11249 \backslash
11250 /
11251
11252 \end_inset
11253
11254 -portmode
11255 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11256
11257 \end_inset
11258
11259 =180 (80) and a compiler #pragma\SpecialChar ~
11260 portmode
11261 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11262
11263 \end_inset
11264
11265  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11266 ns 
11267 \family typewriter
11268 in0/out0
11269 \family default
11270  instead of 
11271 \family typewriter
11272 in/out
11273 \family default
11274 .
11275  If you include the file z180.h this will be set automatically.
11276
11277
11278
11279 \layout Subsection
11280 HC08 Storage Class
11281 \begin_inset LatexCommand \index{HC08!Storage class}
11282
11283 \end_inset
11284
11285  Language Extensions
11286
11287 \layout Subsubsection
11288 data
11289 \begin_inset LatexCommand \index{data (hc08 storage class)}
11290
11291 \end_inset
11292
11293
11294 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11295
11296 \end_inset
11297
11298  
11299
11300 \layout Standard
11301 The data storage class declares a variable that resides in the first 256
11302  bytes of memory (the direct page).
11303  The HC08
11304 \begin_inset LatexCommand \index{HC08}
11305
11306 \end_inset
11307
11308  is most efficient at accessing variables (especially pointers) stored here.
11309
11310 \layout Subsubsection
11311 xdata
11312 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11313
11314 \end_inset
11315
11316
11317 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11318
11319 \end_inset
11320
11321  
11322
11323 \layout Standard
11324 \added_space_bottom bigskip 
11325 The xdata storage class declares a variable that can reside anywhere in
11326  memory.
11327  This is the default if no storage class is specified.
11328  
11329
11330
11331
11332 \layout Section
11333 Absolute Addressing
11334 \begin_inset LatexCommand \index{Absolute addressing}
11335
11336 \end_inset
11337
11338
11339
11340 \layout Standard
11341 Data items can be assigned an absolute address with the 
11342 \emph on
11343 at
11344 \begin_inset LatexCommand \index{at}
11345
11346 \end_inset
11347
11348
11349 \begin_inset LatexCommand \index{\_\_at}
11350
11351 \end_inset
11352
11353  <address>
11354 \emph default
11355  keyword, in addition to a storage class, e.g.:
11356
11357 \layout Verse
11358
11359 \family typewriter
11360 xdata
11361 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11362
11363 \end_inset
11364
11365
11366 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11367
11368 \end_inset
11369
11370  at
11371 \begin_inset LatexCommand \index{at}
11372
11373 \end_inset
11374
11375
11376 \begin_inset LatexCommand \index{\_\_at}
11377
11378 \end_inset
11379
11380  0x7ffe unsigned int chksum;
11381
11382 \layout Standard
11383 or, better conforming to ISO/IEC 9899 C:
11384
11385 \layout Verse
11386
11387 \family typewriter
11388 __xdata __at (0x7ffe) unsigned int chksum;
11389
11390 \layout Standard
11391 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11392  of the external ram.
11393  The compiler does 
11394 \emph on
11395 not
11396 \emph default
11397  reserve any space for variables declared in this way
11398 \begin_inset Marginal
11399 collapsed true
11400
11401 \layout Standard
11402
11403 \series bold
11404 \SpecialChar ~
11405 !
11406
11407 \end_inset
11408
11409  (they are implemented with an equate in the assembler).
11410  Thus it is left to the programmer to make sure there are no overlaps with
11411  other variables that are declared without the absolute address.
11412  The assembler listing file (.lst
11413 \begin_inset LatexCommand \index{<file>.lst}
11414
11415 \end_inset
11416
11417 ) and the linker output files (.rst
11418 \begin_inset LatexCommand \index{<file>.rst}
11419
11420 \end_inset
11421
11422 ) and (.map
11423 \begin_inset LatexCommand \index{<file>.map}
11424
11425 \end_inset
11426
11427 ) are good places to look for such overlaps.
11428  Variables with an absolute address are 
11429 \emph on
11430 not
11431 \begin_inset Marginal
11432 collapsed true
11433
11434 \layout Standard
11435
11436 \series bold
11437 \SpecialChar ~
11438 !
11439
11440 \end_inset
11441
11442
11443 \emph default
11444  initialized
11445 \begin_inset LatexCommand \index{Variable initialization}
11446
11447 \end_inset
11448
11449 .
11450
11451 \layout Standard
11452 In case of memory mapped I/O devices the keyword 
11453 \emph on
11454 volatile
11455 \emph default
11456  has to be used to tell the compiler that accesses might not be removed:
11457
11458 \layout Verse
11459
11460 \family typewriter
11461 volatile
11462 \begin_inset LatexCommand \index{volatile}
11463
11464 \end_inset
11465
11466  __xdata
11467 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11468
11469 \end_inset
11470
11471  __at
11472 \begin_inset LatexCommand \index{at}
11473
11474 \end_inset
11475
11476  (0x8000) unsigned char PORTA_8255;
11477
11478 \layout Standard
11479 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11480 r) array
11481 \family typewriter
11482 \size footnotesize
11483
11484 \begin_inset LatexCommand \index{Aligned array}
11485
11486 \end_inset
11487
11488
11489 \family default
11490 \size default
11491  starts at a block (256 byte) boundary
11492 \begin_inset LatexCommand \index{block boundary}
11493
11494 \end_inset
11495
11496  (section 
11497 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11498
11499 \end_inset
11500
11501  has an example).
11502 \newline
11503 Absolute addresses can be specified for variables in all
11504  storage classes, e.g.:
11505
11506 \layout Verse
11507
11508 \family typewriter
11509 __bit
11510 \begin_inset LatexCommand \index{bit}
11511
11512 \end_inset
11513
11514  __at
11515 \begin_inset LatexCommand \index{at}
11516
11517 \end_inset
11518
11519  (0x02) bvar;
11520
11521 \layout Standard
11522 The above example will allocate the variable at offset 0x02 in the bit-addressab
11523 le space.
11524  There is no real advantage to assigning absolute addresses to variables
11525  in this manner, unless you want strict control over all the variables allocated.
11526  One possible use would be to write hardware portable code.
11527  For example, if you have a routine that uses one or more of the microcontroller
11528  I/O pins, and such pins are different for two different hardwares, you
11529  can declare the I/O pins in your routine using:
11530
11531 \layout Verse
11532
11533 \family typewriter
11534 extern volatile
11535 \begin_inset LatexCommand \index{volatile}
11536
11537 \end_inset
11538
11539  __bit MOSI;\SpecialChar ~
11540 \SpecialChar ~
11541 \SpecialChar ~
11542 \SpecialChar ~
11543 /* master out, slave in */
11544 \newline
11545 extern volatile __bit MISO;\SpecialChar ~
11546 \SpecialChar ~
11547 \SpecialChar ~
11548 \SpecialChar ~
11549 /* master
11550  in, slave out */
11551 \newline
11552 extern volatile __bit MCLK;\SpecialChar ~
11553 \SpecialChar ~
11554 \SpecialChar ~
11555 \SpecialChar ~
11556 /* master clock */
11557 \newline
11558
11559 \newline
11560 /* Input and
11561  Output of a byte on a 3-wire serial bus.
11562 \newline
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 \SpecialChar ~
11566 If needed adapt polarity of clock,
11567  polarity of data and bit order
11568 \newline
11569 \SpecialChar ~
11570 */
11571 \newline
11572 unsigned char spi_io(unsigned char out_byte)
11573  
11574 \newline
11575
11576 \newline
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 \SpecialChar ~
11581 unsigned char i=8;
11582 \newline
11583 \SpecialChar ~
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 do { 
11588 \newline
11589 \SpecialChar ~
11590 \SpecialChar ~
11591 \SpecialChar ~
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 \SpecialChar ~
11596 \SpecialChar ~
11597 MOSI = out_byte & 0x80; 
11598 \newline
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 \SpecialChar ~
11602 \SpecialChar ~
11603 \SpecialChar ~
11604 \SpecialChar ~
11605 \SpecialChar ~
11606 \SpecialChar ~
11607 out_byte <<= 1;
11608 \newline
11609 \SpecialChar ~
11610 \SpecialChar ~
11611 \SpecialChar ~
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 \SpecialChar ~
11617 MCLK =
11618  1; 
11619 \newline
11620 \SpecialChar ~
11621 \SpecialChar ~
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 \SpecialChar ~
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 /* _asm nop _endasm; */\SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 \SpecialChar ~
11632 \SpecialChar ~
11633 \SpecialChar ~
11634 \SpecialChar ~
11635 \SpecialChar ~
11636 /* for slow peripherals */
11637 \newline
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 \SpecialChar ~
11642 \SpecialChar ~
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 if(MISO) 
11647 \newline
11648 \SpecialChar ~
11649 \SpecialChar ~
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 \SpecialChar ~
11656 \SpecialChar ~
11657 \SpecialChar ~
11658 \SpecialChar ~
11659 \SpecialChar ~
11660 out_byte +=
11661  1; 
11662 \newline
11663 \SpecialChar ~
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 \SpecialChar ~
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 MCLK = 0; 
11672 \newline
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 \SpecialChar ~
11676 \SpecialChar ~
11677 } while(--i);
11678 \newline
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 \SpecialChar ~
11682 \SpecialChar ~
11683 return out_byte; 
11684 \newline
11685 }
11686
11687 \layout Standard
11688 Then, someplace in the code for the first hardware you would use
11689
11690 \layout Verse
11691
11692 \family typewriter
11693 __bit __at
11694 \begin_inset LatexCommand \index{at}
11695
11696 \end_inset
11697
11698
11699 \begin_inset LatexCommand \index{\_\_at}
11700
11701 \end_inset
11702
11703  (0x80) MOSI;\SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 /* I/O port 0, bit 0 */
11708 \newline
11709 __bit __at (0x81) MISO;\SpecialChar ~
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 \SpecialChar ~
11713 /* I/O port 0,
11714  bit 1 */
11715 \newline
11716 __bit __at (0x82) MCLK;\SpecialChar ~
11717 \SpecialChar ~
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 /* I/O port 0, bit 2 */
11721
11722 \layout Standard
11723 Similarly, for the second hardware you would use
11724
11725 \layout Verse
11726
11727 \family typewriter
11728 __bit __at (0x83) MOSI;\SpecialChar ~
11729 \SpecialChar ~
11730 \SpecialChar ~
11731 \SpecialChar ~
11732 /* I/O port 0, bit 3 */
11733 \newline
11734 __bit __at (0x91) MISO;\SpecialChar ~
11735 \SpecialChar ~
11736 \SpecialChar ~
11737 \SpecialChar ~
11738 /*
11739  I/O port 1, bit 1 */
11740 \newline
11741 __bit
11742 \begin_inset LatexCommand \index{bit}
11743
11744 \end_inset
11745
11746  __at (0x92) MCLK;\SpecialChar ~
11747 \SpecialChar ~
11748 \SpecialChar ~
11749 \SpecialChar ~
11750 /* I/O port 1, bit 2 */
11751
11752 \layout Standard
11753 \added_space_bottom bigskip 
11754 and you can use the same hardware dependent routine without changes, as
11755  for example in a library.
11756  This is somehow similar to sbit, but only one absolute address has to be
11757  specified in the whole project.
11758
11759
11760
11761 \layout Section
11762 Parameters
11763 \begin_inset LatexCommand \index{Parameters}
11764
11765 \end_inset
11766
11767
11768 \begin_inset LatexCommand \index{function parameter}
11769
11770 \end_inset
11771
11772  & Local Variables
11773 \begin_inset LatexCommand \index{local variables}
11774
11775 \end_inset
11776
11777
11778 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11779
11780 \end_inset
11781
11782
11783
11784 \layout Standard
11785 Automatic (local) variables and parameters to functions can either be placed
11786  on the stack or in data-space.
11787  The default action of the compiler is to place these variables in the internal
11788  RAM (for small model) or external RAM (for large model).
11789  This in fact makes them similar to 
11790 \emph on
11791 static
11792 \begin_inset LatexCommand \index{static}
11793
11794 \end_inset
11795
11796
11797 \emph default
11798  so by default functions are non-reentrant
11799 \begin_inset LatexCommand \index{reentrant}
11800
11801 \end_inset
11802
11803 .
11804  
11805 \newline
11806
11807 \newline
11808 They can be placed on the stack
11809 \begin_inset LatexCommand \index{stack}
11810
11811 \end_inset
11812
11813  by using the
11814 \emph on
11815  -
11816 \begin_inset ERT
11817 status Collapsed
11818
11819 \layout Standard
11820
11821
11822 \backslash
11823 /
11824
11825 \end_inset
11826
11827 -stack-auto
11828 \begin_inset LatexCommand \index{-\/-stack-auto}
11829
11830 \end_inset
11831
11832
11833 \emph default
11834  option, by using 
11835 \emph on
11836 #pragma\SpecialChar ~
11837 stackauto
11838 \emph default
11839
11840 \begin_inset LatexCommand \index{\#pragma stackauto}
11841
11842 \end_inset
11843
11844  or by using the 
11845 \emph on
11846 reentrant
11847 \begin_inset LatexCommand \index{reentrant}
11848
11849 \end_inset
11850
11851
11852 \emph default
11853  keyword in the function declaration, e.g.:
11854
11855 \layout Verse
11856
11857 \family typewriter
11858 unsigned char foo(char i) __reentrant 
11859 \newline
11860
11861 \newline
11862 \SpecialChar ~
11863 \SpecialChar ~
11864 \SpecialChar ~
11865 \SpecialChar ~
11866 ...
11867  
11868 \newline
11869 }
11870
11871 \layout Standard
11872 Since stack space on 8051 is limited, the 
11873 \emph on
11874 reentrant 
11875 \emph default
11876 keyword or the
11877 \emph on
11878  -
11879 \begin_inset ERT
11880 status Collapsed
11881
11882 \layout Standard
11883
11884
11885 \backslash
11886 /
11887
11888 \end_inset
11889
11890 -stack-auto
11891 \emph default
11892  option should be used sparingly.
11893  Note that the reentrant keyword just means that the parameters & local
11894  variables will be allocated to the stack, it 
11895 \emph on
11896 does not
11897 \emph default
11898  mean that the function is register bank
11899 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11900
11901 \end_inset
11902
11903  independent.
11904 \newline
11905
11906 \newline
11907 Local variables
11908 \begin_inset LatexCommand \index{local variables}
11909
11910 \end_inset
11911
11912  can be assigned storage classes and absolute
11913 \begin_inset LatexCommand \index{Absolute addressing}
11914
11915 \end_inset
11916
11917  addresses, e.g.: 
11918
11919 \layout Verse
11920
11921 \family typewriter
11922 unsigned char foo() 
11923 \newline
11924 {
11925 \newline
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 __xdata unsigned char i;
11931 \newline
11932 \SpecialChar ~
11933 \SpecialChar ~
11934 \SpecialChar ~
11935 \SpecialChar ~
11936 __bit bvar;
11937 \newline
11938 \SpecialChar ~
11939 \SpecialChar ~
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 __data __at
11943 \begin_inset LatexCommand \index{at}
11944
11945 \end_inset
11946
11947  (0x31) unsigned char j;
11948 \newline
11949 \SpecialChar ~
11950 \SpecialChar ~
11951 \SpecialChar ~
11952 \SpecialChar ~
11953 ...
11954  
11955 \newline
11956 }
11957
11958 \layout Standard
11959 In the above example the variable 
11960 \emph on
11961 i
11962 \emph default
11963  will be allocated in the external ram, 
11964 \emph on
11965 bvar
11966 \emph default
11967  in bit addressable space and
11968 \emph on
11969  j
11970 \emph default
11971  in internal ram.
11972  When compiled with 
11973 \emph on
11974 -
11975 \begin_inset ERT
11976 status Collapsed
11977
11978 \layout Standard
11979
11980
11981 \backslash
11982 /
11983
11984 \end_inset
11985
11986 -stack-auto
11987 \emph default
11988  or when a function is declared as 
11989 \emph on
11990 reentrant
11991 \emph default
11992  this should only be done for static variables.
11993
11994 \layout Standard
11995 Parameters
11996 \begin_inset LatexCommand \index{function parameter}
11997
11998 \end_inset
11999
12000  however are not allowed any storage class
12001 \begin_inset LatexCommand \index{Storage class}
12002
12003 \end_inset
12004
12005 , (storage classes for parameters will be ignored), their allocation is
12006  governed by the memory model in use, and the reentrancy options.
12007
12008 \layout Standard
12009 It is however allowed to use bit parameters in reentrant functions and also
12010  non-static local bit variables are supported.
12011  Efficient use is limited to 8 semi-bitregisters in bit space.
12012  They are pushed and popped to stack
12013 \begin_inset LatexCommand \index{stack}
12014
12015 \end_inset
12016
12017  as a single byte just like the normal registers.
12018
12019 \layout Section
12020 Overlaying
12021 \begin_inset LatexCommand \label{sub:Overlaying}
12022
12023 \end_inset
12024
12025
12026 \begin_inset LatexCommand \index{Overlaying}
12027
12028 \end_inset
12029
12030
12031
12032 \layout Standard
12033 For non-reentrant
12034 \begin_inset LatexCommand \index{reentrant}
12035
12036 \end_inset
12037
12038  functions SDCC will try to reduce internal ram space usage by overlaying
12039  parameters and local variables of a function (if possible).
12040  Parameters and local variables
12041 \begin_inset LatexCommand \index{local variables}
12042
12043 \end_inset
12044
12045  of a function will be allocated to an overlayable segment if the function
12046  has 
12047 \emph on
12048 no other function calls and the function is non-reentrant and the memory
12049  model
12050 \begin_inset LatexCommand \index{Memory model}
12051
12052 \end_inset
12053
12054  is small.
12055
12056 \emph default
12057  If an explicit storage class
12058 \begin_inset LatexCommand \index{Storage class}
12059
12060 \end_inset
12061
12062  is specified for a local variable, it will NOT be overlayed.
12063
12064 \layout Standard
12065 Note that the compiler (not the linkage editor) makes the decision for overlayin
12066 g the data items.
12067  Functions that are called from an interrupt service routine
12068 \begin_inset Marginal
12069 collapsed true
12070
12071 \layout Standard
12072
12073 \series bold
12074 !
12075
12076 \end_inset
12077
12078  should be preceded by a #pragma\SpecialChar ~
12079 nooverlay
12080 \begin_inset LatexCommand \index{\#pragma nooverlay}
12081
12082 \end_inset
12083
12084  if they are not reentrant.
12085
12086 \layout Standard
12087 Also note that the compiler does not do any processing of inline assembler
12088  code, so the compiler might incorrectly assign local variables and parameters
12089  of a function into the overlay segment if the inline assembler code calls
12090  other c-functions that might use the overlay.
12091  In that case the #pragma\SpecialChar ~
12092 nooverlay should be used.
12093
12094 \layout Standard
12095 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12096 tion
12097 \begin_inset LatexCommand \index{Multiplication}
12098
12099 \end_inset
12100
12101  or division
12102 \begin_inset LatexCommand \index{Division}
12103
12104 \end_inset
12105
12106  will NOT be overlayed since these are implemented using external functions,
12107  e.g.:
12108
12109 \layout Verse
12110
12111 \family typewriter
12112 #pragma save 
12113 \newline
12114 #pragma nooverlay
12115 \begin_inset LatexCommand \index{\#pragma nooverlay}
12116
12117 \end_inset
12118
12119  
12120 \newline
12121 void set_error(unsigned char errcd) 
12122 \newline
12123 {
12124 \newline
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 P3 = errcd;
12130 \newline
12131
12132 \newline
12133 #pragma restore 
12134 \newline
12135
12136 \newline
12137 void
12138  some_isr () __interrupt
12139 \begin_inset LatexCommand \index{interrupt}
12140
12141 \end_inset
12142
12143  (2)
12144 \newline
12145 {
12146 \newline
12147 \SpecialChar ~
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 ...
12152 \newline
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 \SpecialChar ~
12157 set_error(10);
12158 \newline
12159 \SpecialChar ~
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 ...
12164  
12165 \newline
12166 }
12167
12168 \layout Standard
12169 \added_space_bottom bigskip 
12170 In the above example the parameter 
12171 \emph on
12172 errcd
12173 \emph default
12174  for the function 
12175 \emph on
12176 set_error
12177 \emph default
12178  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12179 nooverlay was
12180  not present, this could cause unpredictable runtime behavior when called
12181  from an interrupt service routine.
12182  The #pragma\SpecialChar ~
12183 nooverlay ensures that the parameters and local variables for
12184  the function are NOT overlayed.
12185
12186
12187
12188 \layout Section
12189 Interrupt Service Routines
12190 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12191
12192 \end_inset
12193
12194
12195
12196 \layout Subsection
12197 General Information
12198
12199 \layout Standard
12200 SDCC allows 
12201 \emph on
12202 i
12203 \emph default
12204 nterrupt 
12205 \emph on
12206 s
12207 \emph default
12208 ervice 
12209 \emph on
12210 r
12211 \emph default
12212 outines to be coded in C, with some extended keywords.
12213
12214 \layout Verse
12215
12216 \family typewriter
12217 void timer_isr (void) __interrupt (1) __using (1) 
12218 \newline
12219
12220 \newline
12221 \SpecialChar ~
12222 \SpecialChar ~
12223 \SpecialChar ~
12224 \SpecialChar ~
12225 ...
12226  
12227 \newline
12228 }
12229
12230 \layout Standard
12231 The optional number following the 
12232 \emph on
12233 interrupt
12234 \begin_inset LatexCommand \index{interrupt}
12235
12236 \end_inset
12237
12238
12239 \begin_inset LatexCommand \index{\_\_interrupt}
12240
12241 \end_inset
12242
12243
12244 \emph default
12245  keyword is the interrupt number this routine will service.
12246  When present, the compiler will insert a call to this routine in the interrupt
12247  vector table
12248 \begin_inset LatexCommand \index{interrupt vector table}
12249
12250 \end_inset
12251
12252  for the interrupt number specified.
12253  If you have multiple source files in your project, interrupt service routines
12254  can be present in any of them, but a prototype of the isr MUST be present
12255  or included in the file that contains the function 
12256 \emph on
12257 main
12258 \emph default
12259 .
12260  The optional (8051 specific) keyword 
12261 \emph on
12262 using
12263 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12264
12265 \end_inset
12266
12267
12268 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12269
12270 \end_inset
12271
12272
12273 \emph default
12274  can be used to tell the compiler to use the specified register bank when
12275  generating code for this function.
12276  
12277 \newline
12278 Interrupt service routines open the door for some very interesting bugs:
12279
12280 \layout Subsubsection
12281 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12282
12283 \end_inset
12284
12285 Common interrupt pitfall: variable not declared 
12286 \emph on
12287 volatile
12288
12289 \layout Standard
12290 If an interrupt service routine changes variables which are accessed by
12291  other functions these variables have to be declared 
12292 \emph on
12293 volatile
12294 \emph default
12295
12296 \begin_inset LatexCommand \index{volatile}
12297
12298 \end_inset
12299
12300 .
12301  See 
12302 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12303
12304 \end_inset
12305
12306  .
12307
12308 \layout Subsubsection
12309 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12310
12311 \end_inset
12312
12313 Common interrupt pitfall: 
12314 \emph on
12315 non-atomic access
12316
12317 \layout Standard
12318 If the access to these variables is not 
12319 \emph on
12320 atomic
12321 \begin_inset LatexCommand \index{atomic}
12322
12323 \end_inset
12324
12325
12326 \emph default
12327  (i.e.
12328  the processor needs more than one instruction for the access and could
12329  be interrupted while accessing the variable) the interrupt must be disabled
12330  during the access to avoid inconsistent data.
12331  
12332 \newline
12333 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12334  and should be protected by disabling interrupts.
12335  You're not automatically on the safe side if you use 8 bit variables though.
12336  We need an example here: f.e.
12337  on the 8051 the harmless looking 
12338 \begin_inset Quotes srd
12339 \end_inset
12340
12341
12342 \family typewriter
12343 flags\SpecialChar ~
12344 |=\SpecialChar ~
12345 0x80;
12346 \family default
12347
12348 \begin_inset Quotes sld
12349 \end_inset
12350
12351  is not atomic if 
12352 \family typewriter
12353 flags
12354 \family default
12355  resides in xdata.
12356  Setting 
12357 \begin_inset Quotes srd
12358 \end_inset
12359
12360
12361 \family typewriter
12362 flags\SpecialChar ~
12363 |=\SpecialChar ~
12364 0x40;
12365 \family default
12366
12367 \begin_inset Quotes sld
12368 \end_inset
12369
12370  from within an interrupt routine might get lost if the interrupt occurs
12371  at the wrong time.
12372  
12373 \begin_inset Quotes sld
12374 \end_inset
12375
12376
12377 \family typewriter
12378 counter\SpecialChar ~
12379 +=\SpecialChar ~
12380 8;
12381 \family default
12382
12383 \begin_inset Quotes srd
12384 \end_inset
12385
12386  is not atomic on the 8051 even if 
12387 \family typewriter
12388 counter
12389 \family default
12390  is located in data memory.
12391 \newline
12392 Bugs like these are hard to reproduce and can
12393  cause a lot of trouble.
12394  
12395
12396 \layout Subsubsection
12397 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12398
12399 \end_inset
12400
12401 Common interrupt pitfall: 
12402 \emph on
12403 stack overflow
12404
12405 \layout Standard
12406 The return address and the registers used in the interrupt service routine
12407  are saved on the stack
12408 \begin_inset LatexCommand \index{stack}
12409
12410 \end_inset
12411
12412  so there must be sufficient stack space.
12413  If there isn't variables or registers (or even the return address itself)
12414  will be corrupted.
12415  This 
12416 \emph on
12417 stack overflow
12418 \emph default
12419
12420 \begin_inset LatexCommand \index{stack overflow}
12421
12422 \end_inset
12423
12424  is most likely to happen if the interrupt occurs during the 
12425 \begin_inset Quotes sld
12426 \end_inset
12427
12428 deepest
12429 \begin_inset Quotes srd
12430 \end_inset
12431
12432  subroutine when the stack is already in use for f.e.
12433  many return addresses.
12434
12435 \layout Subsubsection
12436 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12437
12438 \end_inset
12439
12440 Common interrupt pitfall: 
12441 \emph on
12442 use of non-reentrant functions
12443
12444 \layout Standard
12445 A special note here, int (16 bit) and long (32 bit) integer division
12446 \begin_inset LatexCommand \index{Division}
12447
12448 \end_inset
12449
12450 , multiplication
12451 \begin_inset LatexCommand \index{Multiplication}
12452
12453 \end_inset
12454
12455  & modulus
12456 \begin_inset LatexCommand \index{Modulus}
12457
12458 \end_inset
12459
12460  and floating-point
12461 \begin_inset LatexCommand \index{Floating point support}
12462
12463 \end_inset
12464
12465  operations are implemented using external support routines.
12466  If an interrupt service routine needs to do any of these operations then
12467  the support routines (as mentioned in a following section) will have to
12468  be recompiled using the
12469 \emph on
12470  -
12471 \begin_inset ERT
12472 status Collapsed
12473
12474 \layout Standard
12475
12476
12477 \backslash
12478 /
12479
12480 \end_inset
12481
12482 -stack-auto
12483 \begin_inset LatexCommand \index{-\/-stack-auto}
12484
12485 \end_inset
12486
12487
12488 \emph default
12489  option and the source file will need to be compiled using the 
12490 \emph on
12491 -
12492 \begin_inset ERT
12493 status Collapsed
12494
12495 \layout Standard
12496
12497
12498 \backslash
12499 /
12500
12501 \end_inset
12502
12503 -int-long-reent
12504 \emph default
12505
12506 \begin_inset LatexCommand \index{-\/-int-long-reent}
12507
12508 \end_inset
12509
12510  compiler option.
12511  
12512 \newline
12513 Note, the type promotion
12514 \begin_inset LatexCommand \index{type promotion}
12515
12516 \end_inset
12517
12518  required by ANSI C can cause 16 bit routines to be used
12519 \begin_inset Marginal
12520 collapsed true
12521
12522 \layout Standard
12523
12524 \series bold
12525 \SpecialChar ~
12526 !
12527
12528 \end_inset
12529
12530  without the programmer being aware of it.
12531  See f.e.
12532  the cast 
12533 \family typewriter
12534 (unsigned char)(tail-1)
12535 \family default
12536  within the if clause in section 
12537 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12538
12539 \end_inset
12540
12541 .
12542
12543 \layout Standard
12544 \added_space_bottom bigskip 
12545 Calling other functions from an interrupt service routine is not recommended,
12546  avoid it if possible.
12547  Note that when some function is called from an interrupt service routine
12548  it should be preceded by a #pragma\SpecialChar ~
12549 nooverlay
12550 \begin_inset LatexCommand \index{\#pragma nooverlay}
12551
12552 \end_inset
12553
12554  if it is not reentrant.
12555  Furthermore nonreentrant functions should not be called from the main program
12556  while the interrupt service routine might be active.
12557  They also must not be called from low priority interrupt service routines
12558  while a high priority interrupt service routine might be active.
12559  You could use semaphores or make the function
12560 \emph on
12561  critical
12562 \emph default
12563  if all parameters are passed in registers.
12564 \newline
12565  Also see section 
12566 \begin_inset LatexCommand \ref{sub:Overlaying}
12567
12568 \end_inset
12569
12570 \SpecialChar ~
12571 about Overlaying and section 
12572 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12573
12574 \end_inset
12575
12576 \SpecialChar ~
12577 about Functions using private register banks.
12578
12579
12580
12581 \layout Subsection
12582 MCS51/DS390 Interrupt Service Routines
12583
12584 \layout Standard
12585 Interrupt
12586 \begin_inset LatexCommand \index{interrupt}
12587
12588 \end_inset
12589
12590  numbers and the corresponding address & descriptions for the Standard 8051/8052
12591  are listed below.
12592  SDCC will automatically adjust the 
12593 \begin_inset LatexCommand \index{interrupt vector table}
12594
12595 \end_inset
12596
12597  to the maximum interrupt number specified.
12598 \newline
12599
12600
12601 \layout Standard
12602 \align center
12603 \begin_inset Tabular
12604 <lyxtabular version="3" rows="9" columns="3">
12605 <features>
12606 <column alignment="center" valignment="top" leftline="true" width="0in">
12607 <column alignment="left" valignment="top" leftline="true" width="0in">
12608 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12609 <row topline="true" bottomline="true">
12610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12611 \begin_inset Text
12612
12613 \layout Standard
12614 Interrupt #
12615
12616 \end_inset
12617 </cell>
12618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12619 \begin_inset Text
12620
12621 \layout Standard
12622 Description
12623
12624 \end_inset
12625 </cell>
12626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12627 \begin_inset Text
12628
12629 \layout Standard
12630 Vector Address
12631
12632 \end_inset
12633 </cell>
12634 </row>
12635 <row topline="true">
12636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12637 \begin_inset Text
12638
12639 \layout Standard
12640 0
12641
12642 \end_inset
12643 </cell>
12644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12645 \begin_inset Text
12646
12647 \layout Standard
12648 External 0
12649
12650 \end_inset
12651 </cell>
12652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12653 \begin_inset Text
12654
12655 \layout Standard
12656 0x0003
12657
12658 \end_inset
12659 </cell>
12660 </row>
12661 <row topline="true">
12662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12663 \begin_inset Text
12664
12665 \layout Standard
12666 1
12667
12668 \end_inset
12669 </cell>
12670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12671 \begin_inset Text
12672
12673 \layout Standard
12674 Timer 0
12675
12676 \end_inset
12677 </cell>
12678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12679 \begin_inset Text
12680
12681 \layout Standard
12682 0x000b
12683
12684 \end_inset
12685 </cell>
12686 </row>
12687 <row topline="true">
12688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12689 \begin_inset Text
12690
12691 \layout Standard
12692 2
12693
12694 \end_inset
12695 </cell>
12696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12697 \begin_inset Text
12698
12699 \layout Standard
12700 External 1
12701
12702 \end_inset
12703 </cell>
12704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12705 \begin_inset Text
12706
12707 \layout Standard
12708 0x0013
12709
12710 \end_inset
12711 </cell>
12712 </row>
12713 <row topline="true">
12714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12715 \begin_inset Text
12716
12717 \layout Standard
12718 3
12719
12720 \end_inset
12721 </cell>
12722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12723 \begin_inset Text
12724
12725 \layout Standard
12726 Timer 1
12727
12728 \end_inset
12729 </cell>
12730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12731 \begin_inset Text
12732
12733 \layout Standard
12734 0x001b
12735
12736 \end_inset
12737 </cell>
12738 </row>
12739 <row topline="true">
12740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12741 \begin_inset Text
12742
12743 \layout Standard
12744 4
12745
12746 \end_inset
12747 </cell>
12748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12749 \begin_inset Text
12750
12751 \layout Standard
12752 Serial
12753
12754 \end_inset
12755 </cell>
12756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12757 \begin_inset Text
12758
12759 \layout Standard
12760 0x0023
12761
12762 \end_inset
12763 </cell>
12764 </row>
12765 <row topline="true">
12766 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12767 \begin_inset Text
12768
12769 \layout Standard
12770 5
12771
12772 \end_inset
12773 </cell>
12774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12775 \begin_inset Text
12776
12777 \layout Standard
12778 Timer 2 (8052)
12779
12780 \end_inset
12781 </cell>
12782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12783 \begin_inset Text
12784
12785 \layout Standard
12786 0x002b
12787
12788 \end_inset
12789 </cell>
12790 </row>
12791 <row topline="true">
12792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12793 \begin_inset Text
12794
12795 \layout Standard
12796 ...
12797
12798 \end_inset
12799 </cell>
12800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12801 \begin_inset Text
12802
12803 \layout Standard
12804
12805
12806 \end_inset
12807 </cell>
12808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12809 \begin_inset Text
12810
12811 \layout Standard
12812 ...
12813
12814 \end_inset
12815 </cell>
12816 </row>
12817 <row topline="true" bottomline="true">
12818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12819 \begin_inset Text
12820
12821 \layout Standard
12822 n
12823
12824 \end_inset
12825 </cell>
12826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12827 \begin_inset Text
12828
12829 \layout Standard
12830
12831
12832 \end_inset
12833 </cell>
12834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12835 \begin_inset Text
12836
12837 \layout Standard
12838 0x0003 + 8*n
12839
12840 \end_inset
12841 </cell>
12842 </row>
12843 </lyxtabular>
12844
12845 \end_inset
12846
12847
12848 \newline
12849
12850
12851 \layout Standard
12852 If the interrupt service routine is defined without 
12853 \emph on
12854 using
12855 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12856
12857 \end_inset
12858
12859
12860 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12861
12862 \end_inset
12863
12864
12865 \emph default
12866  a register bank or with register bank 0 (
12867 \emph on
12868 using
12869 \emph default
12870  0), the compiler will save the registers used by itself on the stack upon
12871  entry and restore them at exit, however if such an interrupt service routine
12872  calls another function then the entire register bank will be saved on the
12873  stack.
12874  This scheme may be advantageous for small interrupt service routines which
12875  have low register usage.
12876
12877 \layout Standard
12878 \added_space_bottom bigskip 
12879 If the interrupt service routine is defined to be using a specific register
12880  bank then only 
12881 \emph on
12882 a, b, dptr
12883 \emph default
12884  & psw are saved and restored, if such an interrupt service routine calls
12885  another function (using another register bank) then the entire register
12886  bank of the called function will be saved on the stack
12887 \begin_inset LatexCommand \index{stack}
12888
12889 \end_inset
12890
12891 .
12892  This scheme is recommended for larger interrupt service routines.
12893
12894
12895
12896 \layout Subsection
12897 HC08
12898 \begin_inset LatexCommand \index{HC08}
12899
12900 \end_inset
12901
12902  Interrupt Service Routines
12903
12904 \layout Standard
12905 \added_space_bottom bigskip 
12906 Since the number of interrupts
12907 \begin_inset LatexCommand \index{HC08!interrupt}
12908
12909 \end_inset
12910
12911  available is chip specific and the interrupt vector table always ends at
12912  the last byte of memory, the interrupt numbers corresponds to the interrupt
12913  vectors in reverse order of address.
12914  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12915  2 will use the interrupt vector at 0xfffa, and so on.
12916  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12917  this way; instead see section 
12918 \begin_inset LatexCommand \ref{sub:Startup-Code}
12919
12920 \end_inset
12921
12922  for details on customizing startup.
12923
12924
12925
12926 \layout Subsection
12927 Z80 Interrupt Service Routines
12928
12929 \layout Standard
12930 The Z80
12931 \begin_inset LatexCommand \index{Z80}
12932
12933 \end_inset
12934
12935  uses several different methods for determining the correct interrupt
12936 \begin_inset LatexCommand \index{Z80!interrupt}
12937
12938 \end_inset
12939
12940  vector depending on the hardware implementation.
12941  Therefore, SDCC ignores the optional interrupt number and does not attempt
12942  to generate an interrupt vector table.
12943
12944 \layout Standard
12945 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12946  instruction to return from the interrupt.
12947  To write an interrupt handler for the non-maskable interrupt, which needs
12948  a RETN instruction instead, add the 
12949 \emph on
12950 critical
12951 \emph default
12952  keyword:
12953
12954 \layout Verse
12955
12956 \family typewriter
12957 void nmi_isr (void) critical interrupt
12958 \newline
12959
12960 \newline
12961 \SpecialChar ~
12962 \SpecialChar ~
12963 \SpecialChar ~
12964 \SpecialChar ~
12965 ...
12966  
12967 \newline
12968 }
12969
12970 \layout Standard
12971 \added_space_bottom bigskip 
12972 However if you need to create a non-interruptable interrupt service routine
12973  you would also require the 
12974 \emph on
12975 critical
12976 \emph default
12977  keyword.
12978  To distinguish between this and an nmi_isr you must provide an interrupt
12979  number.
12980
12981
12982
12983 \layout Section
12984 Enabling and Disabling Interrupts
12985
12986 \layout Subsection
12987 Critical Functions and Critical Statements
12988
12989 \layout Standard
12990 A special keyword may be associated with a block or a function declaring
12991  it as 
12992 \emph on
12993 critical
12994 \emph default
12995 .
12996  SDCC will generate code to disable all interrupts
12997 \begin_inset LatexCommand \index{interrupt}
12998
12999 \end_inset
13000
13001  upon entry to a critical function and restore the interrupt enable to the
13002  previous state before returning.
13003  Nesting critical functions will need one additional byte on the stack
13004 \begin_inset LatexCommand \index{stack}
13005
13006 \end_inset
13007
13008  for each call.
13009
13010 \layout Verse
13011
13012 \family typewriter
13013 int foo () __critical
13014 \begin_inset LatexCommand \index{critical}
13015
13016 \end_inset
13017
13018
13019 \begin_inset LatexCommand \index{\_\_critical}
13020
13021 \end_inset
13022
13023  
13024 \newline
13025
13026 \newline
13027 \SpecialChar ~
13028 \SpecialChar ~
13029 \SpecialChar ~
13030 \SpecialChar ~
13031 ...
13032  
13033 \newline
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 \SpecialChar ~
13038 ...
13039  
13040 \newline
13041 }
13042
13043 \layout Standard
13044 The critical attribute maybe used with other attributes like 
13045 \emph on
13046 reentrant.
13047 \emph default
13048
13049 \newline
13050 The keyword 
13051 \emph on
13052 critical
13053 \emph default
13054  may also be used to disable interrupts more locally:
13055
13056 \layout Verse
13057
13058 \family typewriter
13059 __critical{ i++; }
13060
13061 \layout Standard
13062 More than one statement could have been included in the block.
13063
13064 \layout Subsection
13065 Enabling and Disabling Interrupts directly
13066
13067 \layout Standard
13068 Interrupts
13069 \begin_inset LatexCommand \index{interrupt}
13070
13071 \end_inset
13072
13073  can also be disabled and enabled directly (8051):
13074
13075 \layout Verse
13076
13077 \family typewriter
13078 EA = 0;\SpecialChar ~
13079 \SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 \SpecialChar ~
13085 \SpecialChar ~
13086 \SpecialChar ~
13087 \SpecialChar ~
13088 \SpecialChar ~
13089 \SpecialChar ~
13090 or:\SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 \SpecialChar ~
13097 \SpecialChar ~
13098 \SpecialChar ~
13099 \SpecialChar ~
13100 \SpecialChar ~
13101 EA_SAVE = EA;
13102
13103 \layout Verse
13104
13105 \family typewriter
13106 ...\SpecialChar ~
13107 \SpecialChar ~
13108 \SpecialChar ~
13109 \SpecialChar ~
13110 \SpecialChar ~
13111 \SpecialChar ~
13112 \SpecialChar ~
13113 \SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 \SpecialChar ~
13117 \SpecialChar ~
13118 \SpecialChar ~
13119 \SpecialChar ~
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 \SpecialChar ~
13124 \SpecialChar ~
13125 \SpecialChar ~
13126 \SpecialChar ~
13127 \SpecialChar ~
13128 \SpecialChar ~
13129 \SpecialChar ~
13130 \SpecialChar ~
13131 \SpecialChar ~
13132 \SpecialChar ~
13133 \SpecialChar ~
13134 \SpecialChar ~
13135 \SpecialChar ~
13136 EA = 0;
13137
13138 \layout Verse
13139
13140 \family typewriter
13141 EA = 1;\SpecialChar ~
13142 \SpecialChar ~
13143 \SpecialChar ~
13144 \SpecialChar ~
13145 \SpecialChar ~
13146 \SpecialChar ~
13147 \SpecialChar ~
13148 \SpecialChar ~
13149 \SpecialChar ~
13150 \SpecialChar ~
13151 \SpecialChar ~
13152 \SpecialChar ~
13153 \SpecialChar ~
13154 \SpecialChar ~
13155 \SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 \SpecialChar ~
13162 \SpecialChar ~
13163 \SpecialChar ~
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 ...
13168
13169 \layout Verse
13170
13171 \family typewriter
13172 \SpecialChar ~
13173 \SpecialChar ~
13174 \SpecialChar ~
13175 \SpecialChar ~
13176 \SpecialChar ~
13177 \SpecialChar ~
13178 \SpecialChar ~
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 EA = EA_SAVE;
13206
13207 \layout Standard
13208 On other architectures which have seperate opcodes for enabling and disabling
13209  interrupts you might want to make use of defines with inline assembly
13210 \begin_inset LatexCommand \index{Assembler routines}
13211
13212 \end_inset
13213
13214  (HC08
13215 \begin_inset LatexCommand \index{HC08!interrupt}
13216
13217 \end_inset
13218
13219 ):
13220
13221 \layout Verse
13222
13223 \family typewriter
13224 #define CLI _asm
13225 \begin_inset LatexCommand \index{\_asm}
13226
13227 \end_inset
13228
13229 \SpecialChar ~
13230 \SpecialChar ~
13231 cli\SpecialChar ~
13232 \SpecialChar ~
13233 _endasm
13234 \begin_inset LatexCommand \index{\_endasm}
13235
13236 \end_inset
13237
13238
13239
13240 \layout Verse
13241
13242 \family typewriter
13243 #define SEI _asm\SpecialChar ~
13244 \SpecialChar ~
13245 sei\SpecialChar ~
13246 \SpecialChar ~
13247 _endasm; 
13248
13249 \layout Verse
13250
13251 \family typewriter
13252 ...
13253
13254 \layout Standard
13255 Note: it is sometimes sufficient to disable only a specific interrupt source
13256  like f.e.
13257  a timer or serial interrupt by manipulating an 
13258 \emph on
13259 interrupt mask
13260 \begin_inset LatexCommand \index{interrupt mask}
13261
13262 \end_inset
13263
13264
13265 \emph default
13266  register.
13267  
13268
13269 \layout Standard
13270 Usually the time during which interrupts are disabled should be kept as
13271  short as possible.
13272  This minimizes both 
13273 \emph on
13274 interrupt latency
13275 \emph default
13276
13277 \begin_inset LatexCommand \index{interrupt latency}
13278
13279 \end_inset
13280
13281  (the time between the occurrence of the interrupt and the execution of
13282  the first code in the interrupt routine) and 
13283 \emph on
13284 interrupt jitter
13285 \emph default
13286
13287 \begin_inset LatexCommand \index{interrupt jitter}
13288
13289 \end_inset
13290
13291  (the difference between the shortest and the longest interrupt latency).
13292  These really are something different, f.e.
13293  a serial interrupt has to be served before its buffer overruns so it cares
13294  for the maximum interrupt latency, whereas it does not care about jitter.
13295  On a loudspeaker driven via a digital to analog converter which is fed
13296  by an interrupt a latency of a few milliseconds might be tolerable, whereas
13297  a much smaller jitter will be very audible.
13298
13299 \layout Standard
13300 You can reenable interrupts within an interrupt routine and on some architecture
13301 s you can make use of two (or more) levels of 
13302 \emph on
13303 interrupt priorities
13304 \emph default
13305
13306 \begin_inset LatexCommand \index{interrupt priority}
13307
13308 \end_inset
13309
13310 .
13311  On some architectures which don't support interrupt priorities these can
13312  be implemented by manipulating the interrupt mask and reenabling interrupts
13313  within the interrupt routine.
13314  Check there is sufficient space on the stack
13315 \begin_inset LatexCommand \index{stack}
13316
13317 \end_inset
13318
13319  and don't add complexity unless you have to.
13320  
13321
13322 \layout Subsection
13323 Semaphore
13324 \begin_inset LatexCommand \index{semaphore}
13325
13326 \end_inset
13327
13328  locking (mcs51/ds390)
13329
13330 \layout Standard
13331 Some architectures (mcs51/ds390) have an atomic
13332 \begin_inset LatexCommand \index{atomic}
13333
13334 \end_inset
13335
13336  bit test and
13337 \emph on
13338  
13339 \emph default
13340 clear
13341 \emph on
13342  
13343 \emph default
13344 instruction.
13345  These type of instructions are typically used in preemptive multitasking
13346  systems, where a routine f.e.
13347  claims the use of a data structure ('acquires a lock
13348 \begin_inset LatexCommand \index{lock}
13349
13350 \end_inset
13351
13352  on it'), makes some modifications and then releases the lock when the data
13353  structure is consistent again.
13354  The instruction may also be used if interrupt and non-interrupt code have
13355  to compete for a resource.
13356  With the atomic bit test and clear instruction interrupts
13357 \begin_inset LatexCommand \index{interrupt}
13358
13359 \end_inset
13360
13361  don't have to be disabled for the locking operation.
13362  
13363
13364 \layout Standard
13365 SDCC generates this instruction if the source follows this pattern:
13366
13367 \layout Verse
13368
13369 \family typewriter
13370 volatile
13371 \begin_inset LatexCommand \index{volatile}
13372
13373 \end_inset
13374
13375  bit resource_is_free; 
13376 \newline
13377
13378 \newline
13379 if (resource_is_free) 
13380 \newline
13381 \SpecialChar ~
13382 \SpecialChar ~
13383
13384 \newline
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 resource_is_free=0; 
13390 \newline
13391 \SpecialChar ~
13392 \SpecialChar ~
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 ...
13396  
13397 \newline
13398 \SpecialChar ~
13399 \SpecialChar ~
13400 \SpecialChar ~
13401 \SpecialChar ~
13402 resource_is_free=1;
13403 \newline
13404 \SpecialChar ~
13405 \SpecialChar ~
13406
13407
13408 \layout Standard
13409 Note, mcs51 and ds390 support only an atomic
13410 \begin_inset LatexCommand \index{atomic}
13411
13412 \end_inset
13413
13414  bit test and 
13415 \emph on
13416 clear
13417 \emph default
13418  instruction (as opposed to atomic bit test and 
13419 \emph on
13420 set).
13421
13422 \layout Section
13423 Functions using private register banks
13424 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13425
13426 \end_inset
13427
13428  (mcs51/ds390)
13429
13430 \layout Standard
13431 Some architectures have support for quickly changing register sets.
13432  SDCC supports this feature with the 
13433 \emph on
13434 using
13435 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13436
13437 \end_inset
13438
13439
13440 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13441
13442 \end_inset
13443
13444
13445 \emph default
13446  attribute (which tells the compiler to use a register bank
13447 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13448
13449 \end_inset
13450
13451  other than the default bank zero).
13452  It should only be applied to 
13453 \emph on
13454 interrupt
13455 \begin_inset LatexCommand \index{interrupt}
13456
13457 \end_inset
13458
13459
13460 \emph default
13461  functions (see footnote below).
13462  This will in most circumstances make the generated ISR code more efficient
13463  since it will not have to save registers on the stack.
13464
13465 \layout Standard
13466 The 
13467 \emph on
13468 using
13469 \emph default
13470  attribute will have no effect on the generated code for a 
13471 \emph on
13472 non-interrupt
13473 \emph default
13474  function (but may occasionally be useful anyway
13475 \begin_inset Foot
13476 collapsed false
13477
13478 \layout Standard
13479 possible exception: if a function is called ONLY from 'interrupt' functions
13480  using a particular bank, it can be declared with the same 'using' attribute
13481  as the calling 'interrupt' functions.
13482  For instance, if you have several ISRs using bank one, and all of them
13483  call memcpy(), it might make sense to create a specialized version of memcpy()
13484  'using 1', since this would prevent the ISR from having to save bank zero
13485  to the stack on entry and switch to bank zero before calling the function
13486
13487 \end_inset
13488
13489 ).
13490 \newline
13491
13492 \emph on
13493 (pending: Note, nowadays the 
13494 \emph default
13495 using
13496 \emph on
13497  attribute has an effect on
13498 \emph default
13499  
13500 \emph on
13501 the generated code for a 
13502 \emph default
13503 non-interrupt
13504 \emph on
13505  function
13506 \emph default
13507 .
13508 \emph on
13509 )
13510
13511 \layout Standard
13512 An 
13513 \emph on
13514 interrupt
13515 \emph default
13516  function using a non-zero bank will assume that it can trash that register
13517  bank, and will not save it.
13518  Since high-priority interrupts
13519 \begin_inset LatexCommand \index{interrupts}
13520
13521 \end_inset
13522
13523
13524 \begin_inset LatexCommand \index{interrupt priority}
13525
13526 \end_inset
13527
13528  can interrupt low-priority ones on the 8051 and friends, this means that
13529  if a high-priority ISR 
13530 \emph on
13531 using
13532 \emph default
13533  a particular bank occurs while processing a low-priority ISR 
13534 \emph on
13535 using
13536 \emph default
13537  the same bank, terrible and bad things can happen.
13538  To prevent this, no single register bank should be 
13539 \emph on
13540 used
13541 \emph default
13542  by both a high priority and a low priority ISR.
13543  This is probably most easily done by having all high priority ISRs use
13544  one bank and all low priority ISRs use another.
13545  If you have an ISR which can change priority at runtime, you're on your
13546  own: I suggest using the default bank zero and taking the small performance
13547  hit.
13548
13549 \layout Standard
13550 \added_space_bottom bigskip 
13551 It is most efficient if your ISR calls no other functions.
13552  If your ISR must call other functions, it is most efficient if those functions
13553  use the same bank as the ISR (see note 1 below); the next best is if the
13554  called functions use bank zero.
13555  It is very inefficient to call a function using a different, non-zero bank
13556  from an ISR.
13557  
13558
13559
13560
13561 \layout Section
13562 Startup Code
13563 \begin_inset LatexCommand \label{sub:Startup-Code}
13564
13565 \end_inset
13566
13567
13568 \begin_inset LatexCommand \index{Startup code}
13569
13570 \end_inset
13571
13572
13573
13574 \layout Subsection
13575 MCS51/DS390 Startup Code
13576
13577 \layout Standard
13578 The compiler triggers the linker to link certain initialization modules
13579  from the runtime library
13580 \begin_inset LatexCommand \index{Runtime library}
13581
13582 \end_inset
13583
13584  called crt<something>.
13585  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
13586  GSINIT5) is not linked unless the --xstack option is used.
13587  These modules are highly entangled by the use of special segments/areas,
13588  but a common layout is shown below:
13589
13590 \layout Verse
13591
13592 \family typewriter
13593 \series bold
13594 \size footnotesize
13595 (main.asm)
13596
13597 \layout Verse
13598
13599 \family typewriter
13600 \size footnotesize
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 \SpecialChar ~
13605 \SpecialChar ~
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 .area HOME (CODE)
13610 \newline
13611 __interrupt_vect:
13612 \newline
13613 \SpecialChar ~
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 \SpecialChar ~
13619 \SpecialChar ~
13620 \SpecialChar ~
13621 ljmp __sdcc_gsinit_startup
13622
13623 \layout Verse
13624
13625 \family typewriter
13626 \series bold
13627 \size footnotesize
13628 (crtstart.asm)
13629
13630 \layout Verse
13631
13632 \family typewriter
13633 \size footnotesize
13634 \SpecialChar ~
13635 \SpecialChar ~
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 \SpecialChar ~
13641 \SpecialChar ~
13642 .area GSINIT0 (CODE)
13643 \newline
13644 __sdcc_gsinit_startup::
13645 \newline
13646 \SpecialChar ~
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 \SpecialChar ~
13652 \SpecialChar ~
13653 \SpecialChar ~
13654 mov sp,#__start__stack - 1
13655
13656 \layout Verse
13657
13658 \family typewriter
13659 \series bold
13660 \size footnotesize
13661 (crtxstack.asm)
13662
13663 \layout Verse
13664
13665 \family typewriter
13666 \size footnotesize
13667 \SpecialChar ~
13668 \SpecialChar ~
13669 \SpecialChar ~
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 \SpecialChar ~
13674 \SpecialChar ~
13675 .area GSINIT1 (CODE)
13676 \newline
13677 __sdcc_init_xstack::
13678 \newline
13679 ; Need to initialize in GSINIT1 in
13680  case the user's __sdcc_external_startup uses the xstack.
13681 \newline
13682 \SpecialChar ~
13683 \SpecialChar ~
13684 \SpecialChar ~
13685 \SpecialChar ~
13686 \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 mov __XPAGE,#(__start__x
13691 stack >> 8)
13692 \newline
13693 \SpecialChar ~
13694 \SpecialChar ~
13695 \SpecialChar ~
13696 \SpecialChar ~
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 mov _spx,#__start__xstack
13702
13703 \layout Verse
13704
13705 \family typewriter
13706 \series bold
13707 \size footnotesize
13708 (crtstart.asm)
13709
13710 \layout Verse
13711
13712 \family typewriter
13713 \size footnotesize
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 \SpecialChar ~
13718 \SpecialChar ~
13719 \SpecialChar ~
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 .area GSINIT2 (CODE)
13723 \newline
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 \SpecialChar ~
13729 \SpecialChar ~
13730 \SpecialChar ~
13731 \SpecialChar ~
13732 lcall __sdcc_external_startup
13733 \newline
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 \SpecialChar ~
13739 \SpecialChar ~
13740 \SpecialChar ~
13741 \SpecialChar ~
13742 mov a,dpl
13743 \newline
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 \SpecialChar ~
13751 \SpecialChar ~
13752 jz __sdcc_init_data
13753 \newline
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 ljmp
13763  __sdcc_program_startup
13764 \newline
13765 __sdcc_init_data:
13766
13767 \layout Verse
13768
13769 \family typewriter
13770 \series bold
13771 \size footnotesize
13772 (crtxinit.asm)
13773
13774 \layout Verse
13775
13776 \family typewriter
13777 \size footnotesize
13778 \SpecialChar ~
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 \SpecialChar ~
13786 .area GSINIT3 (CODE)
13787 \newline
13788 __mcs51_genXINIT::
13789 \newline
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 mov r1,#l_XINIT
13799 \newline
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 \SpecialChar ~
13808 mov a,r1
13809 \newline
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 orl a,#(l_XINIT
13819  >> 8)
13820 \newline
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 \SpecialChar ~
13829 jz 00003$
13830 \newline
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 \SpecialChar ~
13838 \SpecialChar ~
13839 mov r2,#((l_XINIT+255) >> 8)
13840 \newline
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 \SpecialChar ~
13849 mov dptr,#s_XINIT
13850 \newline
13851 \SpecialChar ~
13852 \SpecialChar ~
13853 \SpecialChar ~
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 mov r0,#s_XISEG
13860 \newline
13861 \SpecialChar ~
13862 \SpecialChar ~
13863 \SpecialChar ~
13864 \SpecialChar ~
13865 \SpecialChar ~
13866 \SpecialChar ~
13867 \SpecialChar ~
13868 \SpecialChar ~
13869 mov
13870  __XPAGE,#(s_XISEG >> 8)
13871 \newline
13872 00001$:\SpecialChar ~
13873 clr a
13874 \newline
13875 \SpecialChar ~
13876 \SpecialChar ~
13877 \SpecialChar ~
13878 \SpecialChar ~
13879 \SpecialChar ~
13880 \SpecialChar ~
13881 \SpecialChar ~
13882 \SpecialChar ~
13883 movc a,@a+dptr
13884 \newline
13885 \SpecialChar ~
13886 \SpecialChar ~
13887 \SpecialChar ~
13888 \SpecialChar ~
13889 \SpecialChar ~
13890 \SpecialChar ~
13891 \SpecialChar ~
13892 \SpecialChar ~
13893 movx @r0,a
13894 \newline
13895 \SpecialChar ~
13896 \SpecialChar ~
13897 \SpecialChar ~
13898 \SpecialChar ~
13899 \SpecialChar ~
13900 \SpecialChar ~
13901 \SpecialChar ~
13902 \SpecialChar ~
13903 inc dptr
13904 \newline
13905 \SpecialChar ~
13906 \SpecialChar ~
13907 \SpecialChar ~
13908 \SpecialChar ~
13909 \SpecialChar ~
13910 \SpecialChar ~
13911 \SpecialChar ~
13912 \SpecialChar ~
13913 inc
13914  r0
13915 \newline
13916 \SpecialChar ~
13917 \SpecialChar ~
13918 \SpecialChar ~
13919 \SpecialChar ~
13920 \SpecialChar ~
13921 \SpecialChar ~
13922 \SpecialChar ~
13923 \SpecialChar ~
13924 cjne r0,#0,00002$
13925 \newline
13926 \SpecialChar ~
13927 \SpecialChar ~
13928 \SpecialChar ~
13929 \SpecialChar ~
13930 \SpecialChar ~
13931 \SpecialChar ~
13932 \SpecialChar ~
13933 \SpecialChar ~
13934 inc __XPAGE
13935 \newline
13936 00002$:\SpecialChar ~
13937 djnz r1,00001$
13938 \newline
13939 \SpecialChar ~
13940 \SpecialChar ~
13941 \SpecialChar ~
13942 \SpecialChar ~
13943 \SpecialChar ~
13944 \SpecialChar ~
13945 \SpecialChar ~
13946 \SpecialChar ~
13947 djnz r2,00001$
13948 \newline
13949 \SpecialChar ~
13950 \SpecialChar ~
13951 \SpecialChar ~
13952 \SpecialChar ~
13953 \SpecialChar ~
13954 \SpecialChar ~
13955 \SpecialChar ~
13956 \SpecialChar ~
13957 mov __XPAGE,#0
13958 xFF
13959 \newline
13960 00003$:
13961
13962 \layout Verse
13963
13964 \family typewriter
13965 \series bold
13966 \size footnotesize
13967 (crtclear.asm)
13968
13969 \layout Verse
13970
13971 \family typewriter
13972 \size footnotesize
13973 \SpecialChar ~
13974 \SpecialChar ~
13975 \SpecialChar ~
13976 \SpecialChar ~
13977 \SpecialChar ~
13978 \SpecialChar ~
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 .area GSINIT4 (CODE)
13982 \newline
13983 __mcs51_genRAMCLEAR::
13984 \newline
13985 \SpecialChar ~
13986 \SpecialChar ~
13987 \SpecialChar ~
13988 \SpecialChar ~
13989 \SpecialChar ~
13990 \SpecialChar ~
13991 \SpecialChar ~
13992 \SpecialChar ~
13993 clr a
13994 \newline
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 \SpecialChar ~
14000 \SpecialChar ~
14001 \SpecialChar ~
14002 \SpecialChar ~
14003 mov r0,#(l_IRAM-1)
14004 \newline
14005 00004$:\SpecialChar ~
14006 mov
14007  @r0,a
14008 \newline
14009 \SpecialChar ~
14010 \SpecialChar ~
14011 \SpecialChar ~
14012 \SpecialChar ~
14013 \SpecialChar ~
14014 \SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 djnz r0,00004$
14018 \newline
14019 ; _mcs51_genRAMCLEAR() end
14020
14021 \layout Verse
14022
14023 \family typewriter
14024 \series bold
14025 \size footnotesize
14026 (crtxclear.asm)
14027
14028 \layout Verse
14029
14030 \family typewriter
14031 \size footnotesize
14032 \SpecialChar ~
14033 \SpecialChar ~
14034 \SpecialChar ~
14035 \SpecialChar ~
14036 \SpecialChar ~
14037 \SpecialChar ~
14038 \SpecialChar ~
14039 \SpecialChar ~
14040 .area GSINIT4 (CODE)
14041 \newline
14042 __mcs51_genXRAMCLEAR::
14043 \newline
14044 \SpecialChar ~
14045 \SpecialChar ~
14046 \SpecialChar ~
14047 \SpecialChar ~
14048 \SpecialChar ~
14049 \SpecialChar ~
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 mov r0,#l_PSEG
14053 \newline
14054 \SpecialChar ~
14055 \SpecialChar ~
14056 \SpecialChar ~
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 mov a,r0
14063 \newline
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 \SpecialChar ~
14069 \SpecialChar ~
14070 \SpecialChar ~
14071 \SpecialChar ~
14072 jz 00006$
14073 \newline
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 \SpecialChar ~
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 mov
14083  r1,#s_PSEG
14084 \newline
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 \SpecialChar ~
14093 mov __XPAGE,#(s_PSEG >> 8)
14094 \newline
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 \SpecialChar ~
14102 \SpecialChar ~
14103 clr a
14104 \newline
14105 00005$:\SpecialChar ~
14106 movx @r1,a
14107 \newline
14108 \SpecialChar ~
14109 \SpecialChar ~
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 \SpecialChar ~
14115 \SpecialChar ~
14116 inc r1
14117 \newline
14118 \SpecialChar ~
14119 \SpecialChar ~
14120 \SpecialChar ~
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 \SpecialChar ~
14126 djnz r0,00005$
14127 \newline
14128 0
14129 0006$:
14130 \newline
14131 \SpecialChar ~
14132 \SpecialChar ~
14133 \SpecialChar ~
14134 \SpecialChar ~
14135 \SpecialChar ~
14136 \SpecialChar ~
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 mov r0,#l_XSEG
14140 \newline
14141 \SpecialChar ~
14142 \SpecialChar ~
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 \SpecialChar ~
14148 \SpecialChar ~
14149 mov a,r0
14150 \newline
14151 \SpecialChar ~
14152 \SpecialChar ~
14153 \SpecialChar ~
14154 \SpecialChar ~
14155 \SpecialChar ~
14156 \SpecialChar ~
14157 \SpecialChar ~
14158 \SpecialChar ~
14159 orl a,#(l_XSEG >> 8)
14160 \newline
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 \SpecialChar ~
14164 \SpecialChar ~
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 jz 00008$
14170 \newline
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 \SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 mov r1,#((l_XSEG
14180  + 255) >> 8)
14181 \newline
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 \SpecialChar ~
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 mov dptr,#s_XSEG
14191 \newline
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 \SpecialChar ~
14199 \SpecialChar ~
14200 clr a
14201 \newline
14202 00007$:\SpecialChar ~
14203 movx @dptr,a
14204 \newline
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 \SpecialChar ~
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 inc dptr
14214 \newline
14215 \SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 djnz r0,00007$
14224 \newline
14225 \SpecialChar ~
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 \SpecialChar ~
14231 \SpecialChar ~
14232 \SpecialChar ~
14233 djnz
14234  r1,00007$
14235 \newline
14236 00008$:
14237
14238 \layout Verse
14239
14240 \family typewriter
14241 \series bold
14242 \size footnotesize
14243 (crtxstack.asm)
14244
14245 \layout Verse
14246
14247 \family typewriter
14248 \size footnotesize
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 \SpecialChar ~
14253 \SpecialChar ~
14254 \SpecialChar ~
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 .area GSINIT5 (CODE)
14258 \newline
14259 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
14260  modifies __XPAGE
14261 \newline
14262 ; and __mcs51_genRAMCLEAR modifies _spx.
14263 \newline
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 \SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 mov __XPAGE,#(__start__x
14273 stack >> 8)
14274 \newline
14275 \SpecialChar ~
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 \SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 mov _spx,#__start__xstack
14284
14285 \layout Verse
14286
14287 \family typewriter
14288 \series bold
14289 \size footnotesize
14290 (application modules)
14291
14292 \layout Verse
14293
14294 \family typewriter
14295 \size footnotesize
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 \SpecialChar ~
14302 \SpecialChar ~
14303 \SpecialChar ~
14304 .area GSINIT (CODE)
14305
14306 \layout Verse
14307
14308 \family typewriter
14309 \series bold
14310 \size footnotesize
14311 (main.asm)
14312
14313 \layout Verse
14314
14315 \family typewriter
14316 \size footnotesize
14317 \SpecialChar ~
14318 \SpecialChar ~
14319 \SpecialChar ~
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 \SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 .area GSFINAL (CODE)
14326 \newline
14327 \SpecialChar ~
14328 \SpecialChar ~
14329 \SpecialChar ~
14330 \SpecialChar ~
14331 \SpecialChar ~
14332 \SpecialChar ~
14333 \SpecialChar ~
14334 \SpecialChar ~
14335 ljmp __sdcc_program_startup
14336 \newline
14337 ;---------------------------------
14338 -----------------------
14339 \newline
14340 ; Home
14341 \newline
14342 ;--------------------------------------------------
14343 ------
14344 \newline
14345 \SpecialChar ~
14346 \SpecialChar ~
14347 \SpecialChar ~
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 \SpecialChar ~
14351 \SpecialChar ~
14352 \SpecialChar ~
14353 .area HOME (CODE)
14354 \newline
14355 \SpecialChar ~
14356 \SpecialChar ~
14357 \SpecialChar ~
14358 \SpecialChar ~
14359 \SpecialChar ~
14360 \SpecialChar ~
14361 \SpecialChar ~
14362 \SpecialChar ~
14363 .area CSEG (CODE)
14364 \newline
14365 __sdcc_program_startup:
14366 \newline
14367 \SpecialChar ~
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 \SpecialChar ~
14373 \SpecialChar ~
14374 \SpecialChar ~
14375 lcall _main
14376 \newline
14377 ;
14378  return from main will lock up
14379 \newline
14380 \SpecialChar ~
14381 \SpecialChar ~
14382 \SpecialChar ~
14383 \SpecialChar ~
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 sjmp .
14389
14390 \layout Standard
14391 One of these modules (crtstart.asm) contains a call to the C routine 
14392 \emph on
14393 _sdcc_external_startup()
14394 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
14395
14396 \end_inset
14397
14398
14399 \series bold
14400 \emph default
14401  
14402 \series default
14403 at the start of the CODE area.
14404  This routine is also in the runtime library
14405 \begin_inset LatexCommand \index{Runtime library}
14406
14407 \end_inset
14408
14409  and returns 0 by default.
14410  If this routine returns a non-zero value, the static & global variable
14411  initialization will be skipped and the function main will be invoked.
14412  Otherwise static & global variables will be initialized before the function
14413  main is invoked.
14414  You could add an 
14415 \emph on
14416 _sdcc_external_startup()
14417 \emph default
14418  routine to your program to override the default if you need to setup hardware
14419  or perform some other critical operation prior to static & global variable
14420  initialization
14421 \begin_inset LatexCommand \index{Variable initialization}
14422
14423 \end_inset
14424
14425 .
14426  On some mcs51 variants xdata
14427 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
14428
14429 \end_inset
14430
14431  memory has to be explicitly enabled before it can be accessed or if the
14432  watchdog
14433 \begin_inset LatexCommand \index{watchdog}
14434
14435 \end_inset
14436
14437  needs to be disabled, this is the place to do it.
14438  The startup code clears all internal data memory, 256 bytes by default,
14439  but from 0 to n-1 if 
14440 \emph on
14441 -
14442 \begin_inset ERT
14443 status Collapsed
14444
14445 \layout Standard
14446
14447
14448 \backslash
14449 /
14450
14451 \end_inset
14452
14453 -iram-size
14454 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
14455
14456 \end_inset
14457
14458 n
14459 \emph default
14460  is used.
14461  (recommended for Chipcon CC1010).
14462
14463 \layout Standard
14464 \added_space_bottom bigskip 
14465 See also the compiler options 
14466 \emph on
14467 -
14468 \begin_inset ERT
14469 status Collapsed
14470
14471 \layout Standard
14472
14473
14474 \backslash
14475 /
14476
14477 \end_inset
14478
14479 -no-xinit
14480 \emph default
14481 -
14482 \emph on
14483 opt
14484 \emph default
14485
14486 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14487
14488 \end_inset
14489
14490
14491 \emph on
14492 -
14493 \begin_inset ERT
14494 status Collapsed
14495
14496 \layout Standard
14497
14498
14499 \backslash
14500 /
14501
14502 \end_inset
14503
14504 -main-return
14505 \emph default
14506
14507 \begin_inset LatexCommand \index{-\/-main-return}
14508
14509 \end_inset
14510
14511  and section 
14512 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14513
14514 \end_inset
14515
14516  about MCS51-variants.
14517
14518
14519
14520 \layout Subsection
14521 HC08 Startup Code
14522
14523 \layout Standard
14524 \added_space_bottom bigskip 
14525 The HC08
14526 \begin_inset LatexCommand \index{HC08}
14527
14528 \end_inset
14529
14530  startup code follows the same scheme as the MCS51 startup code.
14531
14532
14533
14534 \layout Subsection
14535 Z80 Startup Code
14536
14537 \layout Standard
14538 \added_space_bottom bigskip 
14539 On the Z80
14540 \begin_inset LatexCommand \index{Z80}
14541
14542 \end_inset
14543
14544  the startup code is inserted by linking with crt0.o which is generated from
14545  sdcc/device/lib/z80/crt0.s.
14546  If you need a different startup code you can use the compiler option 
14547 \emph on
14548 -
14549 \series bold
14550 \emph default
14551
14552 \begin_inset ERT
14553 status Collapsed
14554
14555 \layout Standard
14556
14557
14558 \backslash
14559 /
14560
14561 \end_inset
14562
14563
14564 \series default
14565 \emph on
14566 -no-std-crt0
14567 \emph default
14568
14569 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14570
14571 \end_inset
14572
14573  and provide your own crt0.o.
14574  
14575
14576
14577
14578 \layout Section
14579 Inline Assembler Code
14580 \begin_inset LatexCommand \index{Assembler routines}
14581
14582 \end_inset
14583
14584
14585
14586 \layout Subsection
14587 A Step by Step Introduction
14588 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14589
14590 \end_inset
14591
14592
14593
14594 \layout Standard
14595 Starting from a small snippet of c-code this example shows for the MCS51
14596  how to use inline assembly, access variables, a function parameter and
14597  an array in xdata memory.
14598  The example uses an MCS51 here but is easily adapted for other architectures.
14599  This is a buffer routine which should be optimized:
14600
14601 \layout Verse
14602
14603 \family typewriter
14604 \size footnotesize
14605 unsigned char __far
14606 \begin_inset LatexCommand \index{far (storage class)}
14607
14608 \end_inset
14609
14610
14611 \begin_inset LatexCommand \index{\_\_far (storage class)}
14612
14613 \end_inset
14614
14615  __at
14616 \begin_inset LatexCommand \index{at}
14617
14618 \end_inset
14619
14620
14621 \begin_inset LatexCommand \index{\_\_at}
14622
14623 \end_inset
14624
14625 (0x7f00) buf[0x100];
14626 \begin_inset LatexCommand \index{Aligned array}
14627
14628 \end_inset
14629
14630
14631 \newline
14632 unsigned char head, tail;\SpecialChar ~
14633 \SpecialChar ~
14634 \SpecialChar ~
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 \SpecialChar ~
14645 \SpecialChar ~
14646 \SpecialChar ~
14647 \SpecialChar ~
14648 \SpecialChar ~
14649 /* if interrupts
14650 \begin_inset LatexCommand \index{interrupt}
14651
14652 \end_inset
14653
14654  are involved see
14655 \newline
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667 \SpecialChar ~
14668 \SpecialChar ~
14669 \SpecialChar ~
14670 \SpecialChar ~
14671 \SpecialChar ~
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 \SpecialChar ~
14679 \SpecialChar ~
14680 \SpecialChar ~
14681 \SpecialChar ~
14682 \SpecialChar ~
14683 \SpecialChar ~
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 \SpecialChar ~
14693 \SpecialChar ~
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 \SpecialChar ~
14699 \SpecialChar ~
14700 \SpecialChar ~
14701 section 
14702 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14703
14704 \end_inset
14705
14706  about
14707 \series bold
14708  volatile
14709 \series default
14710  */
14711 \newline
14712
14713 \newline
14714 void to_buffer( unsigned char c ) 
14715 \newline
14716 {
14717 \newline
14718 \SpecialChar ~
14719 \SpecialChar ~
14720 \SpecialChar ~
14721 \SpecialChar ~
14722 if( head != (unsigned char)(tail-1)
14723  )\SpecialChar ~
14724 /* cast 
14725 \series bold
14726 needed
14727 \series default
14728  to avoid promotion
14729 \begin_inset LatexCommand \index{promotion to signed int}
14730
14731 \end_inset
14732
14733
14734 \begin_inset LatexCommand \index{type promotion}
14735
14736 \end_inset
14737
14738  to integer */
14739 \begin_inset Marginal
14740 collapsed true
14741
14742 \layout Standard
14743
14744 \series bold
14745 \SpecialChar ~
14746 !
14747
14748 \end_inset
14749
14750
14751 \newline
14752 \SpecialChar ~
14753 \SpecialChar ~
14754 \SpecialChar ~
14755 \SpecialChar ~
14756 \SpecialChar ~
14757 \SpecialChar ~
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 buf[ head++ ] = c;\SpecialChar ~
14761 \SpecialChar ~
14762 \SpecialChar ~
14763 \SpecialChar ~
14764 \SpecialChar ~
14765 \SpecialChar ~
14766 \SpecialChar ~
14767 \SpecialChar ~
14768 \SpecialChar ~
14769 \SpecialChar ~
14770 \SpecialChar ~
14771 \SpecialChar ~
14772 \SpecialChar ~
14773 \SpecialChar ~
14774 \SpecialChar ~
14775 \SpecialChar ~
14776 /* access to a 256 byte aligned array */
14777 \newline
14778
14779
14780 \layout Standard
14781 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14782  then a corresponding buffer.asm file is generated.
14783  We define a new function 
14784 \family typewriter
14785 to_buffer_asm()
14786 \family default
14787  in file buffer.c in which we cut and paste the generated code, removing
14788  unwanted comments and some ':'.
14789  Then add 
14790 \begin_inset Quotes sld
14791 \end_inset
14792
14793 _asm
14794 \begin_inset Quotes srd
14795 \end_inset
14796
14797  and 
14798 \begin_inset Quotes sld
14799 \end_inset
14800
14801 _endasm;
14802 \begin_inset Quotes srd
14803 \end_inset
14804
14805  to the beginning and the end of the function body:
14806
14807 \layout Verse
14808
14809 \family typewriter
14810 \size footnotesize
14811 /* With a cut and paste from the .asm file, we have something to start with.
14812 \newline
14813 \SpecialChar ~
14814 \SpecialChar ~
14815 \SpecialChar ~
14816 The
14817  function is not yet OK! (registers aren't saved) */ 
14818 \newline
14819 void to_buffer_asm(
14820  unsigned char c ) 
14821 \newline
14822
14823 \newline
14824 \SpecialChar ~
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 _asm
14829 \begin_inset LatexCommand \index{\_asm}
14830
14831 \end_inset
14832
14833
14834 \begin_inset LatexCommand \index{\_\_asm}
14835
14836 \end_inset
14837
14838
14839 \newline
14840 \SpecialChar ~
14841 \SpecialChar ~
14842 \SpecialChar ~
14843 \SpecialChar ~
14844 mov\SpecialChar ~
14845 \SpecialChar ~
14846 r2,dpl 
14847 \newline
14848 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14849 /* cast 
14850 \series bold
14851 needed
14852 \series default
14853  to avoid promotion
14854 \begin_inset LatexCommand \index{promotion to signed int}
14855
14856 \end_inset
14857
14858
14859 \begin_inset LatexCommand \index{type promotion}
14860
14861 \end_inset
14862
14863  to integer */
14864 \newline
14865 \SpecialChar ~
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 mov\SpecialChar ~
14870 \SpecialChar ~
14871 a,_tail 
14872 \newline
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 dec\SpecialChar ~
14878 \SpecialChar ~
14879
14880 \newline
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 \SpecialChar ~
14884 \SpecialChar ~
14885 mov\SpecialChar ~
14886 \SpecialChar ~
14887 r3,a 
14888 \newline
14889 \SpecialChar ~
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 mov\SpecialChar ~
14894 \SpecialChar ~
14895 a,_head 
14896 \newline
14897 \SpecialChar ~
14898 \SpecialChar ~
14899 \SpecialChar ~
14900 \SpecialChar ~
14901 cjne a,ar3,00106$ 
14902 \newline
14903 \SpecialChar ~
14904 \SpecialChar ~
14905 \SpecialChar ~
14906 \SpecialChar ~
14907 ret
14908 \newline
14909 00106$:
14910  
14911 \newline
14912 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14913 \begin_inset LatexCommand \index{Aligned array}
14914
14915 \end_inset
14916
14917
14918 \newline
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 mov\SpecialChar ~
14924 \SpecialChar ~
14925 r3,_head 
14926 \newline
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 \SpecialChar ~
14930 \SpecialChar ~
14931 inc\SpecialChar ~
14932 \SpecialChar ~
14933 _head 
14934 \newline
14935 \SpecialChar ~
14936 \SpecialChar ~
14937 \SpecialChar ~
14938 \SpecialChar ~
14939 mov\SpecialChar ~
14940 \SpecialChar ~
14941 dpl,r3 
14942 \newline
14943 \SpecialChar ~
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 mov\SpecialChar ~
14948 \SpecialChar ~
14949 dph,#(_buf >> 8) 
14950 \newline
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 \SpecialChar ~
14954 \SpecialChar ~
14955 mov\SpecialChar ~
14956 \SpecialChar ~
14957 a,r2 
14958 \newline
14959 \SpecialChar ~
14960 \SpecialChar ~
14961 \SpecialChar ~
14962 \SpecialChar ~
14963 movx @dptr,a
14964  
14965 \newline
14966 00103$: 
14967 \newline
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 \SpecialChar ~
14971 \SpecialChar ~
14972 ret
14973 \newline
14974 \SpecialChar ~
14975 \SpecialChar ~
14976 \SpecialChar ~
14977 \SpecialChar ~
14978 _endasm
14979 \begin_inset LatexCommand \index{\_endasm}
14980
14981 \end_inset
14982
14983
14984 \begin_inset LatexCommand \index{\_\_endasm}
14985
14986 \end_inset
14987
14988 ;
14989 \newline
14990
14991
14992 \layout Standard
14993 The new file buffer.c should compile with only one warning about the unreferenced
14994  function argument 'c'.
14995  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14996  (1) and finally have:
14997
14998 \layout Verse
14999
15000 \family typewriter
15001 \size footnotesize
15002 unsigned char __far __at(0x7f00) buf[0x100];
15003 \newline
15004 unsigned char head, tail;
15005 \newline
15006 #define
15007  USE_ASSEMBLY (1)
15008 \newline
15009
15010 \newline
15011 #if !USE_ASSEMBLY
15012 \newline
15013
15014 \newline
15015 void to_buffer( unsigned char c )
15016 \newline
15017 {
15018 \newline
15019 \SpecialChar ~
15020 \SpecialChar ~
15021 \SpecialChar ~
15022 \SpecialChar ~
15023 if(
15024  head != (unsigned char)(tail-1) )
15025 \newline
15026 \SpecialChar ~
15027 \SpecialChar ~
15028 \SpecialChar ~
15029 \SpecialChar ~
15030 \SpecialChar ~
15031 \SpecialChar ~
15032 \SpecialChar ~
15033 \SpecialChar ~
15034 buf[ head++ ] = c;
15035 \newline
15036 }
15037 \newline
15038
15039 \newline
15040 #else
15041 \newline
15042
15043 \newline
15044 void to_buffer(
15045  unsigned char c )
15046 \newline
15047 {
15048 \newline
15049 \SpecialChar ~
15050 \SpecialChar ~
15051 \SpecialChar ~
15052 \SpecialChar ~
15053 c; // to avoid warning: unreferenced function argument
15054 \newline
15055 \SpecialChar ~
15056 \SpecialChar ~
15057 \SpecialChar ~
15058 \SpecialChar ~
15059 _asm
15060 \begin_inset LatexCommand \index{\_asm}
15061
15062 \end_inset
15063
15064
15065 \begin_inset LatexCommand \index{\_\_asm}
15066
15067 \end_inset
15068
15069
15070 \newline
15071 \SpecialChar ~
15072 \SpecialChar ~
15073 \SpecialChar ~
15074 \SpecialChar ~
15075 \SpecialChar ~
15076 \SpecialChar ~
15077 \SpecialChar ~
15078 \SpecialChar ~
15079 ; save used registers here.
15080  
15081 \newline
15082 \SpecialChar ~
15083 \SpecialChar ~
15084 \SpecialChar ~
15085 \SpecialChar ~
15086 \SpecialChar ~
15087 \SpecialChar ~
15088 \SpecialChar ~
15089 \SpecialChar ~
15090 ; If we were still using r2,r3 we would have to push them here.
15091  
15092 \newline
15093 ; if( head != (unsigned char)(tail-1) )
15094 \newline
15095 \SpecialChar ~
15096 \SpecialChar ~
15097 \SpecialChar ~
15098 \SpecialChar ~
15099 \SpecialChar ~
15100 \SpecialChar ~
15101 \SpecialChar ~
15102 \SpecialChar ~
15103 mov\SpecialChar ~
15104  a,_tail
15105 \newline
15106 \SpecialChar ~
15107 \SpecialChar ~
15108 \SpecialChar ~
15109 \SpecialChar ~
15110 \SpecialChar ~
15111 \SpecialChar ~
15112 \SpecialChar ~
15113 \SpecialChar ~
15114 dec\SpecialChar ~
15115  a
15116 \newline
15117 \SpecialChar ~
15118 \SpecialChar ~
15119 \SpecialChar ~
15120 \SpecialChar ~
15121 \SpecialChar ~
15122 \SpecialChar ~
15123 \SpecialChar ~
15124 \SpecialChar ~
15125 xrl\SpecialChar ~
15126  a,_head
15127 \newline
15128 \SpecialChar ~
15129 \SpecialChar ~
15130 \SpecialChar ~
15131 \SpecialChar ~
15132 \SpecialChar ~
15133 \SpecialChar ~
15134 \SpecialChar ~
15135 \SpecialChar ~
15136 ; we
15137  could do an ANL a,#0x0f here to use a smaller buffer (see below)
15138 \newline
15139 \SpecialChar ~
15140 \SpecialChar ~
15141 \SpecialChar ~
15142 \SpecialChar ~
15143 \SpecialChar ~
15144 \SpecialChar ~
15145 \SpecialChar ~
15146 \SpecialChar ~
15147 jz\SpecialChar ~
15148 \SpecialChar ~
15149  t_b_end$
15150 \newline
15151 \SpecialChar ~
15152 \SpecialChar ~
15153 \SpecialChar ~
15154 \SpecialChar ~
15155 \SpecialChar ~
15156 \SpecialChar ~
15157 \SpecialChar ~
15158 \SpecialChar ~
15159 ;
15160 \newline
15161 ;
15162  buf[ head++ ] = c;
15163 \newline
15164 \SpecialChar ~
15165 \SpecialChar ~
15166 \SpecialChar ~
15167 \SpecialChar ~
15168 \SpecialChar ~
15169 \SpecialChar ~
15170 \SpecialChar ~
15171 \SpecialChar ~
15172 mov\SpecialChar ~
15173  a,dpl \SpecialChar ~
15174 \SpecialChar ~
15175 \SpecialChar ~
15176 \SpecialChar ~
15177 \SpecialChar ~
15178 \SpecialChar ~
15179 \SpecialChar ~
15180 ; dpl holds lower byte of function argument
15181 \newline
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 \SpecialChar ~
15186 \SpecialChar ~
15187 \SpecialChar ~
15188 \SpecialChar ~
15189 \SpecialChar ~
15190 mov\SpecialChar ~
15191
15192  dpl,_head \SpecialChar ~
15193 \SpecialChar ~
15194 \SpecialChar ~
15195 ; buf is 0x100 byte aligned so head can be used directly
15196 \newline
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 \SpecialChar ~
15200 \SpecialChar ~
15201 \SpecialChar ~
15202 \SpecialChar ~
15203 \SpecialChar ~
15204 \SpecialChar ~
15205 mov\SpecialChar ~
15206  dph,#(_bu
15207 f>>8)
15208 \newline
15209 \SpecialChar ~
15210 \SpecialChar ~
15211 \SpecialChar ~
15212 \SpecialChar ~
15213 \SpecialChar ~
15214 \SpecialChar ~
15215 \SpecialChar ~
15216 \SpecialChar ~
15217 movx @dptr,a
15218 \newline
15219 \SpecialChar ~
15220 \SpecialChar ~
15221 \SpecialChar ~
15222 \SpecialChar ~
15223 \SpecialChar ~
15224 \SpecialChar ~
15225 \SpecialChar ~
15226 \SpecialChar ~
15227 inc \SpecialChar ~
15228 _head
15229 \newline
15230 \SpecialChar ~
15231 \SpecialChar ~
15232 \SpecialChar ~
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 ; we could do an ANL _head,#0x0f here to use a
15239  smaller buffer (see above)
15240 \newline
15241 t_b_end$:
15242 \newline
15243 \SpecialChar ~
15244 \SpecialChar ~
15245 \SpecialChar ~
15246 \SpecialChar ~
15247 \SpecialChar ~
15248 \SpecialChar ~
15249 \SpecialChar ~
15250 \SpecialChar ~
15251 ; restore used registers here 
15252 \newline
15253 \SpecialChar ~
15254 \SpecialChar ~
15255 \SpecialChar ~
15256 \SpecialChar ~
15257 _endasm
15258 \begin_inset LatexCommand \index{\_endasm}
15259
15260 \end_inset
15261
15262
15263 \begin_inset LatexCommand \index{\_\_endasm}
15264
15265 \end_inset
15266
15267 ;
15268 \newline
15269 }
15270 \newline
15271 #endif
15272
15273 \layout Standard
15274 The inline assembler code can contain any valid code understood by the assembler
15275 , this includes any assembler directives and comment lines.
15276  The assembler does not like some characters like ':' or ''' in comments.
15277  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
15278 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
15279
15280 \end_inset
15281
15282
15283 \begin_inset LatexCommand \index{Assembler documentation}
15284
15285 \end_inset
15286
15287  or online at 
15288 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
15289
15290 \end_inset
15291
15292 \SpecialChar ~
15293 .
15294
15295 \layout Standard
15296 The compiler does not do any validation of the code within the 
15297 \family typewriter
15298 _asm
15299 \begin_inset LatexCommand \index{\_asm}
15300
15301 \end_inset
15302
15303
15304 \begin_inset LatexCommand \index{\_\_asm}
15305
15306 \end_inset
15307
15308  ...
15309  _endasm
15310 \size footnotesize
15311
15312 \begin_inset LatexCommand \index{\_endasm}
15313
15314 \end_inset
15315
15316
15317 \begin_inset LatexCommand \index{\_\_endasm}
15318
15319 \end_inset
15320
15321
15322 \size default
15323 ;
15324 \family default
15325  keyword pair.
15326  Specifically it will not know which registers are used and thus register
15327  pushing/popping
15328 \begin_inset LatexCommand \index{push/pop}
15329
15330 \end_inset
15331
15332  has to be done manually.
15333  
15334
15335 \layout Standard
15336 It is recommended that each assembly instruction (including labels) be placed
15337  in a separate line (as the example shows).
15338  When the -
15339 \begin_inset ERT
15340 status Collapsed
15341
15342 \layout Standard
15343
15344
15345 \backslash
15346 /
15347
15348 \end_inset
15349
15350 -
15351 \emph on
15352 peep-asm
15353 \begin_inset LatexCommand \index{-\/-peep-asm}
15354
15355 \end_inset
15356
15357
15358 \emph default
15359  command line option is used, the inline assembler code will be passed through
15360  the peephole optimizer
15361 \begin_inset LatexCommand \index{Peephole optimizer}
15362
15363 \end_inset
15364
15365 .
15366  There are only a few (if any) cases where this option makes sense, it might
15367  cause some unexpected changes in the inline assembler code.
15368  Please go through the peephole optimizer rules defined in file 
15369 \emph on
15370 SDCCpeeph.def
15371 \emph default
15372  before using this option.
15373
15374 \layout Subsection
15375 Naked Functions
15376 \begin_inset LatexCommand \label{sub:Naked-Functions}
15377
15378 \end_inset
15379
15380
15381 \begin_inset LatexCommand \index{Naked functions}
15382
15383 \end_inset
15384
15385
15386
15387 \layout Standard
15388 A special keyword may be associated with a function declaring it as 
15389 \emph on
15390 _naked
15391 \begin_inset LatexCommand \index{\_naked}
15392
15393 \end_inset
15394
15395
15396 \begin_inset LatexCommand \index{\_\_naked}
15397
15398 \end_inset
15399
15400 .
15401  
15402 \emph default
15403 The 
15404 \emph on
15405 _naked
15406 \emph default
15407  function modifier attribute prevents the compiler from generating prologue
15408 \begin_inset LatexCommand \index{function prologue}
15409
15410 \end_inset
15411
15412  and epilogue
15413 \begin_inset LatexCommand \index{function epilogue}
15414
15415 \end_inset
15416
15417  code for that function.
15418  This means that the user is entirely responsible for such things as saving
15419  any registers that may need to be preserved, selecting the proper register
15420  bank, generating the 
15421 \emph on
15422 return
15423 \emph default
15424  instruction at the end, etc.
15425  Practically, this means that the contents of the function must be written
15426  in inline assembler.
15427  This is particularly useful for interrupt functions, which can have a large
15428  (and often unnecessary) prologue/epilogue.
15429  For example, compare the code generated by these two functions:
15430
15431 \layout Verse
15432
15433 \family typewriter
15434 volatile
15435 \begin_inset LatexCommand \index{volatile}
15436
15437 \end_inset
15438
15439  data unsigned char counter;
15440 \newline
15441
15442 \newline
15443 void simpleInterrupt(void) __interrupt
15444 \begin_inset LatexCommand \index{interrupt}
15445
15446 \end_inset
15447
15448
15449 \begin_inset LatexCommand \index{\_\_interrupt}
15450
15451 \end_inset
15452
15453  (1)
15454 \newline
15455 {
15456 \newline
15457 \SpecialChar ~
15458 \SpecialChar ~
15459 \SpecialChar ~
15460 \SpecialChar ~
15461 counter++;
15462 \newline
15463 }
15464 \newline
15465
15466 \newline
15467 void nakedInterrupt(void) __interrupt (2) __naked
15468 \newline
15469 {
15470 \newline
15471 \SpecialChar ~
15472 \SpecialChar ~
15473 \SpecialChar ~
15474 \SpecialChar ~
15475 _asm
15476 \begin_inset LatexCommand \index{\_asm}
15477
15478 \end_inset
15479
15480
15481 \begin_inset LatexCommand \index{\_\_asm}
15482
15483 \end_inset
15484
15485
15486 \newline
15487 \SpecialChar ~
15488 \SpecialChar ~
15489 \SpecialChar ~
15490 \SpecialChar ~
15491 \SpecialChar ~
15492 \SpecialChar ~
15493 inc\SpecialChar ~
15494 \SpecialChar ~
15495 \SpecialChar ~
15496 \SpecialChar ~
15497 \SpecialChar ~
15498 _counter ; does not change flags, no need to save psw
15499 \newline
15500 \SpecialChar ~
15501 \SpecialChar ~
15502 \SpecialChar ~
15503 \SpecialChar ~
15504 \SpecialChar ~
15505 \SpecialChar ~
15506 reti\SpecialChar ~
15507 \SpecialChar ~
15508 \SpecialChar ~
15509 \SpecialChar ~
15510 ; MUST explicitly
15511  include ret or reti in _naked function.
15512 \newline
15513 \SpecialChar ~
15514 \SpecialChar ~
15515 \SpecialChar ~
15516 \SpecialChar ~
15517 _endasm
15518 \begin_inset LatexCommand \index{\_endasm}
15519
15520 \end_inset
15521
15522
15523 \begin_inset LatexCommand \index{\_\_endasm}
15524
15525 \end_inset
15526
15527 ;
15528 \newline
15529 }
15530
15531 \layout Standard
15532 For an 8051 target, the generated simpleInterrupt looks like:
15533
15534 \layout Verse
15535
15536 \family typewriter
15537 Note, this is an 
15538 \emph on
15539 outdated
15540 \emph default
15541  example, recent versions of SDCC generate
15542 \newline
15543 the 
15544 \emph on
15545 same
15546 \emph default
15547  code for simpleInterrupt() and nakedInterrupt()!
15548 \newline
15549
15550 \newline
15551 _simpleInterrupt:
15552 \newline
15553 \SpecialChar ~
15554 \SpecialChar ~
15555 \SpecialChar ~
15556 \SpecialChar ~
15557 push\SpecialChar ~
15558 \SpecialChar ~
15559 \SpecialChar ~
15560 \SpecialChar ~
15561 acc
15562 \newline
15563 \SpecialChar ~
15564 \SpecialChar ~
15565 \SpecialChar ~
15566 \SpecialChar ~
15567 push\SpecialChar ~
15568 \SpecialChar ~
15569 \SpecialChar ~
15570 \SpecialChar ~
15571 b
15572 \newline
15573 \SpecialChar ~
15574 \SpecialChar ~
15575 \SpecialChar ~
15576 \SpecialChar ~
15577 pu
15578 sh\SpecialChar ~
15579 \SpecialChar ~
15580 \SpecialChar ~
15581 \SpecialChar ~
15582 dpl
15583 \newline
15584 \SpecialChar ~
15585 \SpecialChar ~
15586 \SpecialChar ~
15587 \SpecialChar ~
15588 push\SpecialChar ~
15589 \SpecialChar ~
15590 \SpecialChar ~
15591 \SpecialChar ~
15592 dph
15593 \newline
15594 \SpecialChar ~
15595 \SpecialChar ~
15596 \SpecialChar ~
15597 \SpecialChar ~
15598 push\SpecialChar ~
15599 \SpecialChar ~
15600 \SpecialChar ~
15601 \SpecialChar ~
15602 psw
15603 \newline
15604 \SpecialChar ~
15605 \SpecialChar ~
15606 \SpecialChar ~
15607 \SpecialChar ~
15608 mov\SpecialChar ~
15609 \SpecialChar ~
15610 \SpecialChar ~
15611 \SpecialChar ~
15612 \SpecialChar ~
15613 psw,#0x00
15614 \newline
15615 \SpecialChar ~
15616 \SpecialChar ~
15617 \SpecialChar ~
15618 \SpecialChar ~
15619 inc\SpecialChar ~
15620 \SpecialChar ~
15621 \SpecialChar ~
15622 \SpecialChar ~
15623 \SpecialChar ~
15624 _counter
15625 \newline
15626 \SpecialChar ~
15627 \SpecialChar ~
15628 \SpecialChar ~
15629 \SpecialChar ~
15630 pop\SpecialChar ~
15631 \SpecialChar ~
15632 \SpecialChar ~
15633 \SpecialChar ~
15634 \SpecialChar ~
15635 psw
15636 \newline
15637 \SpecialChar ~
15638 \SpecialChar ~
15639 \SpecialChar ~
15640 \SpecialChar ~
15641 pop\SpecialChar ~
15642 \SpecialChar ~
15643 \SpecialChar ~
15644 \SpecialChar ~
15645 \SpecialChar ~
15646 dph
15647 \newline
15648 \SpecialChar ~
15649 \SpecialChar ~
15650 \SpecialChar ~
15651 \SpecialChar ~
15652 pop\SpecialChar ~
15653 \SpecialChar ~
15654 \SpecialChar ~
15655 \SpecialChar ~
15656 \SpecialChar ~
15657 dpl
15658 \newline
15659 \SpecialChar ~
15660 \SpecialChar ~
15661 \SpecialChar ~
15662 \SpecialChar ~
15663 pop\SpecialChar ~
15664 \SpecialChar ~
15665 \SpecialChar ~
15666 \SpecialChar ~
15667 \SpecialChar ~
15668 b
15669 \newline
15670 \SpecialChar ~
15671 \SpecialChar ~
15672 \SpecialChar ~
15673 \SpecialChar ~
15674 pop\SpecialChar ~
15675 \SpecialChar ~
15676 \SpecialChar ~
15677 \SpecialChar ~
15678 \SpecialChar ~
15679 acc
15680 \newline
15681 \SpecialChar ~
15682 \SpecialChar ~
15683 \SpecialChar ~
15684 \SpecialChar ~
15685 reti
15686
15687 \layout Standard
15688 whereas nakedInterrupt looks like:
15689
15690 \layout Verse
15691
15692 \family typewriter
15693 _nakedInterrupt:
15694 \newline
15695 \SpecialChar ~
15696 \SpecialChar ~
15697 \SpecialChar ~
15698 \SpecialChar ~
15699 inc\SpecialChar ~
15700 \SpecialChar ~
15701 \SpecialChar ~
15702 \SpecialChar ~
15703 _counter ; does not change flags, no need to save psw
15704 \newline
15705 \SpecialChar ~
15706 \SpecialChar ~
15707 \SpecialChar ~
15708 \SpecialChar ~
15709 reti\SpecialChar ~
15710 \SpecialChar ~
15711 \SpecialChar ~
15712 \SpecialChar ~
15713 \SpecialChar ~
15714 \SpecialChar ~
15715 \SpecialChar ~
15716 \SpecialChar ~
15717 \SpecialChar ~
15718 \SpecialChar ~
15719 \SpecialChar ~
15720 \SpecialChar ~
15721 ;
15722  MUST explicitly include ret or reti in _naked function
15723
15724 \layout Standard
15725 The related directive #pragma exclude
15726 \begin_inset LatexCommand \index{\#pragma exclude}
15727
15728 \end_inset
15729
15730  allows a more fine grained control over pushing & popping
15731 \begin_inset LatexCommand \index{push/pop}
15732
15733 \end_inset
15734
15735  the registers.
15736
15737 \layout Standard
15738 While there is nothing preventing you from writing C code inside a 
15739 \family typewriter
15740 _naked
15741 \family default
15742  function, there are many ways to shoot yourself in the foot doing this,
15743  and it is recommended that you stick to inline assembler.
15744
15745 \layout Subsection
15746 Use of Labels within Inline Assembler
15747
15748 \layout Standard
15749 SDCC allows the use of in-line assembler with a few restrictions regarding
15750  labels.
15751  In older versions of the compiler all labels defined within inline assembler
15752  code 
15753 \emph on
15754 had to be
15755 \emph default
15756  of the form 
15757 \emph on
15758 nnnnn$
15759 \emph default
15760  where nnnn is a number less than 100 (which implies a limit of utmost 100
15761  inline assembler labels 
15762 \emph on
15763 per function
15764 \emph default
15765 \noun on
15766 )
15767 \noun default
15768 .
15769  
15770
15771 \layout Verse
15772
15773 \family typewriter
15774 _asm
15775 \begin_inset LatexCommand \index{\_asm}
15776
15777 \end_inset
15778
15779
15780 \begin_inset LatexCommand \index{\_\_asm}
15781
15782 \end_inset
15783
15784  
15785 \newline
15786 \SpecialChar ~
15787 \SpecialChar ~
15788 \SpecialChar ~
15789 \SpecialChar ~
15790 mov\SpecialChar ~
15791 \SpecialChar ~
15792 \SpecialChar ~
15793 \SpecialChar ~
15794 \SpecialChar ~
15795 b,#10 
15796 \newline
15797 00001$: 
15798 \newline
15799 \SpecialChar ~
15800 \SpecialChar ~
15801 \SpecialChar ~
15802 \SpecialChar ~
15803 djnz\SpecialChar ~
15804 \SpecialChar ~
15805 \SpecialChar ~
15806 \SpecialChar ~
15807 b,00001$ 
15808 \newline
15809 _endasm
15810 \begin_inset LatexCommand \index{\_endasm}
15811
15812 \end_inset
15813
15814
15815 \begin_inset LatexCommand \index{\_\_endasm}
15816
15817 \end_inset
15818
15819  ;
15820
15821 \layout Standard
15822 Inline assembler code cannot reference any C-Labels, however it can reference
15823  labels
15824 \begin_inset LatexCommand \index{Labels}
15825
15826 \end_inset
15827
15828  defined by the inline assembler, e.g.:
15829
15830 \layout Verse
15831
15832 \family typewriter
15833 foo() { 
15834 \newline
15835 \SpecialChar ~
15836 \SpecialChar ~
15837 \SpecialChar ~
15838 \SpecialChar ~
15839 /* some c code */ 
15840 \newline
15841 \SpecialChar ~
15842 \SpecialChar ~
15843 \SpecialChar ~
15844 \SpecialChar ~
15845 _asm 
15846 \newline
15847 \SpecialChar ~
15848 \SpecialChar ~
15849 \SpecialChar ~
15850 \SpecialChar ~
15851 \SpecialChar ~
15852 \SpecialChar ~
15853 ; some assembler code 
15854 \newline
15855 \SpecialChar ~
15856 \SpecialChar ~
15857 \SpecialChar ~
15858 \SpecialChar ~
15859 \SpecialChar ~
15860 \SpecialChar ~
15861 ljmp $0003 
15862 \newline
15863 \SpecialChar ~
15864 \SpecialChar ~
15865 \SpecialChar ~
15866 \SpecialChar ~
15867 _endasm;
15868  
15869 \newline
15870 \SpecialChar ~
15871 \SpecialChar ~
15872 \SpecialChar ~
15873 \SpecialChar ~
15874 /* some more c code */ 
15875 \newline
15876 clabel:\SpecialChar ~
15877 \SpecialChar ~
15878 /* inline assembler cannot reference this
15879  label */ 
15880 \newline
15881 \SpecialChar ~
15882 \SpecialChar ~
15883 \SpecialChar ~
15884 \SpecialChar ~
15885 _asm
15886 \newline
15887 \SpecialChar ~
15888 \SpecialChar ~
15889 \SpecialChar ~
15890 \SpecialChar ~
15891 $0003: ;label (can be referenced by inline assembler only)
15892  
15893 \newline
15894 \SpecialChar ~
15895 \SpecialChar ~
15896 \SpecialChar ~
15897 \SpecialChar ~
15898 _endasm
15899 \begin_inset LatexCommand \index{\_endasm}
15900
15901 \end_inset
15902
15903
15904 \begin_inset LatexCommand \index{\_\_endasm}
15905
15906 \end_inset
15907
15908  ; 
15909 \newline
15910 \SpecialChar ~
15911 \SpecialChar ~
15912 \SpecialChar ~
15913 \SpecialChar ~
15914 /* some more c code */
15915 \newline
15916 }
15917
15918 \layout Standard
15919 In other words inline assembly code can access labels defined in inline
15920  assembly within the scope of the function.
15921  The same goes the other way, i.e.
15922  labels defines in inline assembly can not be accessed by C statements.
15923
15924 \layout Section
15925 Interfacing with Assembler Code
15926 \begin_inset LatexCommand \index{Assembler routines}
15927
15928 \end_inset
15929
15930
15931
15932 \layout Subsection
15933 Global Registers used for Parameter Passing
15934 \begin_inset LatexCommand \index{Parameter passing}
15935
15936 \end_inset
15937
15938
15939
15940 \layout Standard
15941 The compiler always uses the global registers 
15942 \emph on
15943 DPL, DPH
15944 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15945
15946 \end_inset
15947
15948
15949 \begin_inset LatexCommand \index{DPTR}
15950
15951 \end_inset
15952
15953 , B
15954 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15955
15956 \end_inset
15957
15958  
15959 \emph default
15960 and
15961 \emph on
15962  ACC
15963 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15964
15965 \end_inset
15966
15967
15968 \emph default
15969  to pass the first parameter to a routine.
15970  The second parameter onwards is either allocated on the stack (for reentrant
15971  routines or if -
15972 \begin_inset ERT
15973 status Collapsed
15974
15975 \layout Standard
15976
15977
15978 \backslash
15979 /
15980
15981 \end_inset
15982
15983 -stack-auto is used) or in data / xdata memory (depending on the memory
15984  model).
15985  
15986
15987 \layout Subsection
15988 Assembler Routine (non-reentrant)
15989
15990 \layout Standard
15991 In the following example
15992 \begin_inset LatexCommand \index{reentrant}
15993
15994 \end_inset
15995
15996
15997 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15998
15999 \end_inset
16000
16001  the function c_func calls an assembler routine asm_func, which takes two
16002  parameters
16003 \begin_inset LatexCommand \index{function parameter}
16004
16005 \end_inset
16006
16007 .
16008
16009 \layout Verse
16010
16011 \family typewriter
16012 extern int asm_func(unsigned char, unsigned char);
16013 \newline
16014
16015 \newline
16016 int c_func (unsigned char
16017  i, unsigned char j)
16018 \newline
16019 {
16020 \newline
16021 \SpecialChar ~
16022 \SpecialChar ~
16023 \SpecialChar ~
16024 \SpecialChar ~
16025 return asm_func(i,j);
16026 \newline
16027 }
16028 \newline
16029
16030 \newline
16031 int main()
16032 \newline
16033 {
16034 \newline
16035 \SpecialChar ~
16036 \SpecialChar ~
16037 \SpecialChar ~
16038 \SpecialChar ~
16039 return c_func(10,9);
16040 \newline
16041 }
16042
16043 \layout Standard
16044 The corresponding assembler function is:
16045
16046 \layout Verse
16047
16048 \family typewriter
16049 .globl _asm_func_PARM_2 
16050 \newline
16051 \SpecialChar ~
16052 \SpecialChar ~
16053 \SpecialChar ~
16054 \SpecialChar ~
16055 \SpecialChar ~
16056 \SpecialChar ~
16057 \SpecialChar ~
16058 \SpecialChar ~
16059 .globl _asm_func 
16060 \newline
16061 \SpecialChar ~
16062 \SpecialChar ~
16063 \SpecialChar ~
16064 \SpecialChar ~
16065 \SpecialChar ~
16066 \SpecialChar ~
16067 \SpecialChar ~
16068 \SpecialChar ~
16069 .area OSEG 
16070 \newline
16071 _asm_func_PARM_2:
16072 \newline
16073 \SpecialChar ~
16074 \SpecialChar ~
16075 \SpecialChar ~
16076 \SpecialChar ~
16077 \SpecialChar ~
16078 \SpecialChar ~
16079 \SpecialChar ~
16080 \SpecialChar ~
16081 .ds   
16082  1 
16083 \newline
16084 \SpecialChar ~
16085 \SpecialChar ~
16086 \SpecialChar ~
16087 \SpecialChar ~
16088 \SpecialChar ~
16089 \SpecialChar ~
16090 \SpecialChar ~
16091 \SpecialChar ~
16092 .area CSEG 
16093 \newline
16094 _asm_func: 
16095 \newline
16096 \SpecialChar ~
16097 \SpecialChar ~
16098 \SpecialChar ~
16099 \SpecialChar ~
16100 \SpecialChar ~
16101 \SpecialChar ~
16102 \SpecialChar ~
16103 \SpecialChar ~
16104 mov\SpecialChar ~
16105 \SpecialChar ~
16106 \SpecialChar ~
16107 \SpecialChar ~
16108 a,dpl 
16109 \newline
16110 \SpecialChar ~
16111 \SpecialChar ~
16112 \SpecialChar ~
16113 \SpecialChar ~
16114 \SpecialChar ~
16115 \SpecialChar ~
16116 \SpecialChar ~
16117 \SpecialChar ~
16118 add\SpecialChar ~
16119 \SpecialChar ~
16120 \SpecialChar ~
16121 \SpecialChar ~
16122 a,_asm_func_PARM_2 
16123 \newline
16124 \SpecialChar ~
16125 \SpecialChar ~
16126 \SpecialChar ~
16127 \SpecialChar ~
16128 \SpecialChar ~
16129 \SpecialChar ~
16130 \SpecialChar ~
16131 \SpecialChar ~
16132 mov\SpecialChar ~
16133 \SpecialChar ~
16134 \SpecialChar ~
16135 \SpecialChar ~
16136 dpl,a 
16137 \newline
16138 \SpecialChar ~
16139 \SpecialChar ~
16140 \SpecialChar ~
16141 \SpecialChar ~
16142 \SpecialChar ~
16143 \SpecialChar ~
16144 \SpecialChar ~
16145 \SpecialChar ~
16146 mov\SpecialChar ~
16147 \SpecialChar ~
16148 \SpecialChar ~
16149 \SpecialChar ~
16150 dph
16151 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16152
16153 \end_inset
16154
16155 ,#0x00 
16156 \newline
16157 \SpecialChar ~
16158 \SpecialChar ~
16159 \SpecialChar ~
16160 \SpecialChar ~
16161 \SpecialChar ~
16162 \SpecialChar ~
16163 \SpecialChar ~
16164 \SpecialChar ~
16165 ret
16166
16167 \layout Standard
16168 Note here that the return values
16169 \begin_inset LatexCommand \index{return value}
16170
16171 \end_inset
16172
16173  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
16174  two byte values.
16175  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
16176 b' & 'acc' for four byte values.
16177
16178 \layout Standard
16179 The parameter naming convention is _<function_name>_PARM_<n>, where n is
16180  the parameter number starting from 1, and counting from the left.
16181  The first parameter is passed in 
16182 \begin_inset Quotes eld
16183 \end_inset
16184
16185 dpl
16186 \begin_inset Quotes erd
16187 \end_inset
16188
16189  for a one byte parameter, 
16190 \begin_inset Quotes eld
16191 \end_inset
16192
16193 dptr
16194 \begin_inset Quotes erd
16195 \end_inset
16196
16197  for two bytes, 
16198 \begin_inset Quotes eld
16199 \end_inset
16200
16201 b,dptr
16202 \begin_inset Quotes erd
16203 \end_inset
16204
16205  for three bytes and 
16206 \begin_inset Quotes eld
16207 \end_inset
16208
16209 acc,b,dptr
16210 \begin_inset Quotes erd
16211 \end_inset
16212
16213  for a four bytes parameter.
16214  The variable name for the second parameter will be _<function_name>_PARM_2.
16215 \newline
16216
16217 \newline
16218 Assem
16219 ble the assembler routine with the following command:
16220 \newline
16221
16222 \newline
16223
16224 \family sans
16225 \series bold
16226 asx8051 -losg asmfunc.asm
16227 \newline
16228
16229 \newline
16230
16231 \family default
16232 \series default
16233 Then compile and link the assembler routine to the C source file with the
16234  following command:
16235 \newline
16236
16237 \newline
16238
16239 \family sans
16240 \series bold
16241 sdcc cfunc.c asmfunc.rel
16242
16243 \layout Subsection
16244 Assembler Routine (reentrant)
16245
16246 \layout Standard
16247 In this case
16248 \begin_inset LatexCommand \index{reentrant}
16249
16250 \end_inset
16251
16252
16253 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
16254
16255 \end_inset
16256
16257  the second parameter
16258 \begin_inset LatexCommand \index{function parameter}
16259
16260 \end_inset
16261
16262  onwards will be passed on the stack, the parameters are pushed from right
16263  to left i.e.
16264  after the call the leftmost parameter will be on the top of the stack.
16265  Here is an example:
16266
16267 \layout Verse
16268
16269 \family typewriter
16270 extern int asm_func(unsigned char, unsigned char);
16271 \newline
16272
16273 \newline
16274 int c_func (unsigned char
16275  i, unsigned char j) reentrant 
16276 \newline
16277
16278 \newline
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 \SpecialChar ~
16282 \SpecialChar ~
16283 return asm_func(i,j); 
16284 \newline
16285
16286 \newline
16287
16288 \newline
16289 int main() 
16290 \newline
16291
16292 \newline
16293 \SpecialChar ~
16294 \SpecialChar ~
16295 \SpecialChar ~
16296 \SpecialChar ~
16297 return
16298  c_func(10,9); 
16299 \newline
16300 }
16301
16302 \layout Standard
16303 The corresponding assembler routine is:
16304
16305 \layout Verse
16306
16307 \family typewriter
16308 .globl _asm_func 
16309 \newline
16310 _asm_func: 
16311 \newline
16312 \SpecialChar ~
16313 \SpecialChar ~
16314 \SpecialChar ~
16315 \SpecialChar ~
16316 push  _bp 
16317 \newline
16318 \SpecialChar ~
16319 \SpecialChar ~
16320 \SpecialChar ~
16321 \SpecialChar ~
16322 mov _bp,sp 
16323 \newline
16324 \SpecialChar ~
16325 \SpecialChar ~
16326 \SpecialChar ~
16327 \SpecialChar ~
16328 mov r2,dpl
16329 \newline
16330 \SpecialChar ~
16331 \SpecialChar ~
16332 \SpecialChar ~
16333 \SpecialChar ~
16334 mov a,_bp 
16335 \newline
16336 \SpecialChar ~
16337 \SpecialChar ~
16338 \SpecialChar ~
16339 \SpecialChar ~
16340 add
16341  a,#0xfd 
16342 \newline
16343 \SpecialChar ~
16344 \SpecialChar ~
16345 \SpecialChar ~
16346 \SpecialChar ~
16347 mov r0,a 
16348 \newline
16349 \SpecialChar ~
16350 \SpecialChar ~
16351 \SpecialChar ~
16352 \SpecialChar ~
16353 add  a,#0xfc ;?
16354 \newline
16355 \SpecialChar ~
16356 \SpecialChar ~
16357 \SpecialChar ~
16358 \SpecialChar ~
16359 mov  r1,a 
16360 \newline
16361 \SpecialChar ~
16362 \SpecialChar ~
16363 \SpecialChar ~
16364 \SpecialChar ~
16365 mov  a,@r0 
16366 \newline
16367 \SpecialChar ~
16368 \SpecialChar ~
16369 \SpecialChar ~
16370 \SpecialChar ~
16371 add  a,r2 ;?
16372 \newline
16373 \SpecialChar ~
16374 \SpecialChar ~
16375 \SpecialChar ~
16376 \SpecialChar ~
16377 mov  dpl,a
16378  
16379 \newline
16380 \SpecialChar ~
16381 \SpecialChar ~
16382 \SpecialChar ~
16383 \SpecialChar ~
16384 mov  dph,#0x00 
16385 \newline
16386 \SpecialChar ~
16387 \SpecialChar ~
16388 \SpecialChar ~
16389 \SpecialChar ~
16390 mov  sp,_bp 
16391 \newline
16392 \SpecialChar ~
16393 \SpecialChar ~
16394 \SpecialChar ~
16395 \SpecialChar ~
16396 pop  _bp 
16397 \newline
16398 \SpecialChar ~
16399 \SpecialChar ~
16400 \SpecialChar ~
16401 \SpecialChar ~
16402 ret
16403
16404 \layout Standard
16405 \added_space_bottom bigskip 
16406 The compiling and linking procedure remains the same, however note the extra
16407  entry & exit linkage required for the assembler code, _bp is the stack
16408  frame pointer and is used to compute the offset into the stack for parameters
16409  and local variables.
16410
16411
16412
16413 \layout Section
16414 int (16 bit)
16415 \begin_inset LatexCommand \index{int (16 bit)}
16416
16417 \end_inset
16418
16419  and long (32 bit)
16420 \begin_inset LatexCommand \index{long (32 bit)}
16421
16422 \end_inset
16423
16424  Support
16425
16426 \layout Standard
16427 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
16428  multiplication and modulus operations are implemented by support routines.
16429  These support routines are all developed in ANSI-C to facilitate porting
16430  to other MCUs, although some model specific assembler optimizations are
16431  used.
16432  The following files contain the described routines, all of them can be
16433  found in <installdir>/share/sdcc/lib.
16434 \newline
16435
16436
16437 \layout Standard
16438 \align center
16439 \begin_inset Tabular
16440 <lyxtabular version="3" rows="11" columns="2">
16441 <features>
16442 <column alignment="left" valignment="top" leftline="true" width="0">
16443 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16444 <row topline="true" bottomline="true">
16445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16446 \begin_inset Text
16447
16448 \layout Standard
16449
16450 \series bold
16451 Function
16452
16453 \end_inset
16454 </cell>
16455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16456 \begin_inset Text
16457
16458 \layout Standard
16459
16460 \series bold
16461 Description
16462
16463 \end_inset
16464 </cell>
16465 </row>
16466 <row topline="true">
16467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16468 \begin_inset Text
16469
16470 \layout Standard
16471 _mulint.c 
16472
16473 \end_inset
16474 </cell>
16475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16476 \begin_inset Text
16477
16478 \layout Standard
16479 16 bit multiplication
16480
16481 \end_inset
16482 </cell>
16483 </row>
16484 <row topline="true">
16485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16486 \begin_inset Text
16487
16488 \layout Standard
16489 _divsint.c 
16490
16491 \end_inset
16492 </cell>
16493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16494 \begin_inset Text
16495
16496 \layout Standard
16497  signed 16 bit division (calls _divuint)
16498
16499 \end_inset
16500 </cell>
16501 </row>
16502 <row topline="true">
16503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16504 \begin_inset Text
16505
16506 \layout Standard
16507 _divuint.c 
16508
16509 \end_inset
16510 </cell>
16511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16512 \begin_inset Text
16513
16514 \layout Standard
16515  unsigned 16 bit division
16516
16517 \end_inset
16518 </cell>
16519 </row>
16520 <row topline="true">
16521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16522 \begin_inset Text
16523
16524 \layout Standard
16525 _modsint.c
16526
16527 \end_inset
16528 </cell>
16529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16530 \begin_inset Text
16531
16532 \layout Standard
16533 signed 16 bit modulus (calls _moduint)
16534
16535 \end_inset
16536 </cell>
16537 </row>
16538 <row topline="true">
16539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16540 \begin_inset Text
16541
16542 \layout Standard
16543 _moduint.c
16544
16545 \end_inset
16546 </cell>
16547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16548 \begin_inset Text
16549
16550 \layout Standard
16551 unsigned 16 bit modulus
16552
16553 \end_inset
16554 </cell>
16555 </row>
16556 <row topline="true">
16557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16558 \begin_inset Text
16559
16560 \layout Standard
16561 _mullong.c
16562
16563 \end_inset
16564 </cell>
16565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16566 \begin_inset Text
16567
16568 \layout Standard
16569 32 bit multiplication
16570
16571 \end_inset
16572 </cell>
16573 </row>
16574 <row topline="true">
16575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16576 \begin_inset Text
16577
16578 \layout Standard
16579 _divslong.c 
16580
16581 \end_inset
16582 </cell>
16583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16584 \begin_inset Text
16585
16586 \layout Standard
16587  signed 32 division (calls _divulong)
16588
16589 \end_inset
16590 </cell>
16591 </row>
16592 <row topline="true">
16593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16594 \begin_inset Text
16595
16596 \layout Standard
16597 _divulong.c 
16598
16599 \end_inset
16600 </cell>
16601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16602 \begin_inset Text
16603
16604 \layout Standard
16605 unsigned 32 division
16606
16607 \end_inset
16608 </cell>
16609 </row>
16610 <row topline="true">
16611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16612 \begin_inset Text
16613
16614 \layout Standard
16615 _modslong.c
16616
16617 \end_inset
16618 </cell>
16619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16620 \begin_inset Text
16621
16622 \layout Standard
16623  signed 32 bit modulus (calls _modulong)
16624
16625 \end_inset
16626 </cell>
16627 </row>
16628 <row topline="true" bottomline="true">
16629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16630 \begin_inset Text
16631
16632 \layout Standard
16633 _modulong.c
16634
16635 \end_inset
16636 </cell>
16637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16638 \begin_inset Text
16639
16640 \layout Standard
16641 unsigned 32 bit modulus
16642
16643 \end_inset
16644 </cell>
16645 </row>
16646 </lyxtabular>
16647
16648 \end_inset
16649
16650
16651 \newline
16652
16653
16654 \layout Standard
16655 Since they are compiled as 
16656 \emph on
16657 non-reentrant
16658 \emph default
16659
16660 \begin_inset LatexCommand \index{reentrant}
16661
16662 \end_inset
16663
16664 , interrupt
16665 \begin_inset LatexCommand \index{interrupt}
16666
16667 \end_inset
16668
16669  service routines should not do any of the above operations.
16670  If this is unavoidable then the above routines will need to be compiled
16671  with the 
16672 \emph on
16673 -
16674 \begin_inset ERT
16675 status Collapsed
16676
16677 \layout Standard
16678
16679
16680 \backslash
16681 /
16682
16683 \end_inset
16684
16685 -stack-auto
16686 \begin_inset LatexCommand \index{-\/-stack-auto}
16687
16688 \end_inset
16689
16690
16691 \emph default
16692  option, after which the source program will have to be compiled with 
16693 \emph on
16694 -
16695 \begin_inset ERT
16696 status Collapsed
16697
16698 \layout Standard
16699
16700
16701 \backslash
16702 /
16703
16704 \end_inset
16705
16706 -int-long-reent
16707 \begin_inset LatexCommand \index{-\/-int-long-reent}
16708
16709 \end_inset
16710
16711
16712 \emph default
16713  option.
16714  Notice that you don't have to call these routines directly.
16715  The compiler will use them automatically every time an integer operation
16716  is required.
16717
16718 \layout Section
16719 Floating Point Support
16720 \begin_inset LatexCommand \index{Floating point support}
16721
16722 \end_inset
16723
16724
16725
16726 \layout Standard
16727 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16728  The floating point support routines are derived from gcc's floatlib.c and
16729  consist of the following routines:
16730 \newline
16731
16732
16733 \layout Standard
16734 \align center
16735
16736 \size footnotesize
16737 \begin_inset Tabular
16738 <lyxtabular version="3" rows="17" columns="2">
16739 <features>
16740 <column alignment="left" valignment="top" leftline="true" width="0">
16741 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16742 <row topline="true" bottomline="true">
16743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16744 \begin_inset Text
16745
16746 \layout Standard
16747
16748 \family roman
16749 \series medium
16750 \shape up
16751 \size normal
16752 \emph off
16753 \bar no
16754 \noun off
16755 \color none
16756 Function 
16757
16758 \end_inset
16759 </cell>
16760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16761 \begin_inset Text
16762
16763 \layout Standard
16764 Description
16765
16766 \end_inset
16767 </cell>
16768 </row>
16769 <row topline="true">
16770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16771 \begin_inset Text
16772
16773 \layout Standard
16774
16775 \family roman
16776 \series medium
16777 \shape up
16778 \size normal
16779 \emph off
16780 \bar no
16781 \noun off
16782 \color none
16783 _fsadd.c
16784
16785 \end_inset
16786 </cell>
16787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16788 \begin_inset Text
16789
16790 \layout Standard
16791
16792 \family roman
16793 \series medium
16794 \shape up
16795 \size normal
16796 \emph off
16797 \bar no
16798 \noun off
16799 \color none
16800 add floating point numbers
16801
16802 \end_inset
16803 </cell>
16804 </row>
16805 <row topline="true">
16806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16807 \begin_inset Text
16808
16809 \layout Standard
16810
16811 \family roman
16812 \series medium
16813 \shape up
16814 \size normal
16815 \emph off
16816 \bar no
16817 \noun off
16818 \color none
16819 _fssub.c 
16820
16821 \end_inset
16822 </cell>
16823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16824 \begin_inset Text
16825
16826 \layout Standard
16827
16828 \family roman
16829 \series medium
16830 \shape up
16831 \size normal
16832 \emph off
16833 \bar no
16834 \noun off
16835 \color none
16836 subtract floating point numbers 
16837
16838 \end_inset
16839 </cell>
16840 </row>
16841 <row topline="true">
16842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16843 \begin_inset Text
16844
16845 \layout Standard
16846
16847 \family roman
16848 \series medium
16849 \shape up
16850 \size normal
16851 \emph off
16852 \bar no
16853 \noun off
16854 \color none
16855 _fsdiv.c 
16856
16857 \end_inset
16858 </cell>
16859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16860 \begin_inset Text
16861
16862 \layout Standard
16863
16864 \family roman
16865 \series medium
16866 \shape up
16867 \size normal
16868 \emph off
16869 \bar no
16870 \noun off
16871 \color none
16872 divide floating point numbers 
16873
16874 \end_inset
16875 </cell>
16876 </row>
16877 <row topline="true">
16878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16879 \begin_inset Text
16880
16881 \layout Standard
16882
16883 \family roman
16884 \series medium
16885 \shape up
16886 \size normal
16887 \emph off
16888 \bar no
16889 \noun off
16890 \color none
16891 _fsmul.c 
16892
16893 \end_inset
16894 </cell>
16895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16896 \begin_inset Text
16897
16898 \layout Standard
16899
16900 \family roman
16901 \series medium
16902 \shape up
16903 \size normal
16904 \emph off
16905 \bar no
16906 \noun off
16907 \color none
16908 multiply floating point numbers 
16909
16910 \end_inset
16911 </cell>
16912 </row>
16913 <row topline="true">
16914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16915 \begin_inset Text
16916
16917 \layout Standard
16918
16919 \family roman
16920 \series medium
16921 \shape up
16922 \size normal
16923 \emph off
16924 \bar no
16925 \noun off
16926 \color none
16927 _fs2uchar.c
16928
16929 \end_inset
16930 </cell>
16931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16932 \begin_inset Text
16933
16934 \layout Standard
16935
16936 \family roman
16937 \series medium
16938 \shape up
16939 \size normal
16940 \emph off
16941 \bar no
16942 \noun off
16943 \color none
16944 convert floating point to unsigned char
16945
16946 \end_inset
16947 </cell>
16948 </row>
16949 <row topline="true">
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16951 \begin_inset Text
16952
16953 \layout Standard
16954
16955 \family roman
16956 \series medium
16957 \shape up
16958 \size normal
16959 \emph off
16960 \bar no
16961 \noun off
16962 \color none
16963 _fs2char.c
16964
16965 \end_inset
16966 </cell>
16967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16968 \begin_inset Text
16969
16970 \layout Standard
16971
16972 \family roman
16973 \series medium
16974 \shape up
16975 \size normal
16976 \emph off
16977 \bar no
16978 \noun off
16979 \color none
16980 convert floating point to signed char
16981
16982 \end_inset
16983 </cell>
16984 </row>
16985 <row topline="true">
16986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16987 \begin_inset Text
16988
16989 \layout Standard
16990
16991 \family roman
16992 \series medium
16993 \shape up
16994 \size normal
16995 \emph off
16996 \bar no
16997 \noun off
16998 \color none
16999 _fs2uint.c
17000
17001 \end_inset
17002 </cell>
17003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17004 \begin_inset Text
17005
17006 \layout Standard
17007
17008 \family roman
17009 \series medium
17010 \shape up
17011 \size normal
17012 \emph off
17013 \bar no
17014 \noun off
17015 \color none
17016 convert floating point to unsigned int
17017
17018 \end_inset
17019 </cell>
17020 </row>
17021 <row topline="true">
17022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17023 \begin_inset Text
17024
17025 \layout Standard
17026
17027 \family roman
17028 \series medium
17029 \shape up
17030 \size normal
17031 \emph off
17032 \bar no
17033 \noun off
17034 \color none
17035 _fs2int.c
17036
17037 \end_inset
17038 </cell>
17039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17040 \begin_inset Text
17041
17042 \layout Standard
17043
17044 \family roman
17045 \series medium
17046 \shape up
17047 \size normal
17048 \emph off
17049 \bar no
17050 \noun off
17051 \color none
17052 convert floating point to signed int
17053
17054 \end_inset
17055 </cell>
17056 </row>
17057 <row topline="true">
17058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17059 \begin_inset Text
17060
17061 \layout Standard
17062
17063 \family roman
17064 \series medium
17065 \shape up
17066 \size normal
17067 \emph off
17068 \bar no
17069 \noun off
17070 \color none
17071 _fs2ulong.
17072 \family default
17073 \series default
17074 \shape default
17075 \size default
17076 \emph default
17077 \bar default
17078 \noun default
17079 c
17080
17081 \end_inset
17082 </cell>
17083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17084 \begin_inset Text
17085
17086 \layout Standard
17087
17088 \family roman
17089 \series medium
17090 \shape up
17091 \size normal
17092 \emph off
17093 \bar no
17094 \noun off
17095 \color none
17096 convert floating point to unsigned long
17097
17098 \end_inset
17099 </cell>
17100 </row>
17101 <row topline="true">
17102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17103 \begin_inset Text
17104
17105 \layout Standard
17106
17107 \family roman
17108 \series medium
17109 \shape up
17110 \size normal
17111 \emph off
17112 \bar no
17113 \noun off
17114 \color none
17115 _fs2long.c
17116
17117 \end_inset
17118 </cell>
17119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17120 \begin_inset Text
17121
17122 \layout Standard
17123
17124 \family roman
17125 \series medium
17126 \shape up
17127 \size normal
17128 \emph off
17129 \bar no
17130 \noun off
17131 \color none
17132 convert floating point to signed long
17133
17134 \end_inset
17135 </cell>
17136 </row>
17137 <row topline="true">
17138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17139 \begin_inset Text
17140
17141 \layout Standard
17142
17143 \family roman
17144 \series medium
17145 \shape up
17146 \size normal
17147 \emph off
17148 \bar no
17149 \noun off
17150 \color none
17151 _uchar2fs.c
17152
17153 \end_inset
17154 </cell>
17155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17156 \begin_inset Text
17157
17158 \layout Standard
17159
17160 \family roman
17161 \series medium
17162 \shape up
17163 \size normal
17164 \emph off
17165 \bar no
17166 \noun off
17167 \color none
17168 convert unsigned char to floating point
17169
17170 \end_inset
17171 </cell>
17172 </row>
17173 <row topline="true">
17174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17175 \begin_inset Text
17176
17177 \layout Standard
17178
17179 \family roman
17180 \series medium
17181 \shape up
17182 \size normal
17183 \emph off
17184 \bar no
17185 \noun off
17186 \color none
17187 _char2fs.c
17188
17189 \end_inset
17190 </cell>
17191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17192 \begin_inset Text
17193
17194 \layout Standard
17195
17196 \family roman
17197 \series medium
17198 \shape up
17199 \size normal
17200 \emph off
17201 \bar no
17202 \noun off
17203 \color none
17204 convert char to floating point number
17205
17206 \end_inset
17207 </cell>
17208 </row>
17209 <row topline="true">
17210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17211 \begin_inset Text
17212
17213 \layout Standard
17214
17215 \family roman
17216 \series medium
17217 \shape up
17218 \size normal
17219 \emph off
17220 \bar no
17221 \noun off
17222 \color none
17223 _uint2fs.c
17224
17225 \end_inset
17226 </cell>
17227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17228 \begin_inset Text
17229
17230 \layout Standard
17231
17232 \family roman
17233 \series medium
17234 \shape up
17235 \size normal
17236 \emph off
17237 \bar no
17238 \noun off
17239 \color none
17240 convert unsigned int to floating point
17241
17242 \end_inset
17243 </cell>
17244 </row>
17245 <row topline="true">
17246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17247 \begin_inset Text
17248
17249 \layout Standard
17250
17251 \family roman
17252 \series medium
17253 \shape up
17254 \size normal
17255 \emph off
17256 \bar no
17257 \noun off
17258 \color none
17259 _int2fs.c
17260
17261 \end_inset
17262 </cell>
17263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17264 \begin_inset Text
17265
17266 \layout Standard
17267
17268 \family roman
17269 \series medium
17270 \shape up
17271 \size normal
17272 \emph off
17273 \bar no
17274 \noun off
17275 \color none
17276 convert int to floating point numbers
17277
17278 \end_inset
17279 </cell>
17280 </row>
17281 <row topline="true">
17282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17283 \begin_inset Text
17284
17285 \layout Standard
17286
17287 \family roman
17288 \series medium
17289 \shape up
17290 \size normal
17291 \emph off
17292 \bar no
17293 \noun off
17294 \color none
17295 _ulong2fs.c
17296
17297 \end_inset
17298 </cell>
17299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17300 \begin_inset Text
17301
17302 \layout Standard
17303
17304 \family roman
17305 \series medium
17306 \shape up
17307 \size normal
17308 \emph off
17309 \bar no
17310 \noun off
17311 \color none
17312 convert unsigned long to floating point number
17313
17314 \end_inset
17315 </cell>
17316 </row>
17317 <row topline="true" bottomline="true">
17318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17319 \begin_inset Text
17320
17321 \layout Standard
17322
17323 \family roman
17324 \series medium
17325 \shape up
17326 \size normal
17327 \emph off
17328 \bar no
17329 \noun off
17330 \color none
17331 _long2fs.c
17332
17333 \end_inset
17334 </cell>
17335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17336 \begin_inset Text
17337
17338 \layout Standard
17339
17340 \family roman
17341 \series medium
17342 \shape up
17343 \size normal
17344 \emph off
17345 \bar no
17346 \noun off
17347 \color none
17348 convert long to floating point number
17349
17350 \end_inset
17351 </cell>
17352 </row>
17353 </lyxtabular>
17354
17355 \end_inset
17356
17357
17358 \newline
17359
17360
17361 \layout Standard
17362 \added_space_bottom bigskip 
17363 These support routines are developed in ANSI-C so there is room for space
17364  and speed improvement
17365 \begin_inset Foot
17366 collapsed false
17367
17368 \layout Standard
17369 These floating point routines (
17370 \emph on
17371 not
17372 \emph default
17373  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17374  
17375
17376 \end_inset
17377
17378 .
17379  Note if all these routines are used simultaneously the data space might
17380  overflow.
17381  For serious floating point usage the large model might be needed.
17382  Also notice that you don't have to call this routines directly.
17383  The compiler will use them automatically every time a floating point operation
17384  is required.
17385
17386
17387
17388 \layout Section
17389 Library Routines
17390 \begin_inset LatexCommand \index{Libraries}
17391
17392 \end_inset
17393
17394
17395
17396 \layout Standard
17397
17398 \emph on
17399 <pending: this is messy and incomplete - a little more information is in
17400  sdcc/doc/libdoc.txt
17401 \emph default
17402  >
17403
17404 \layout Subsection
17405 Compiler support routines (_gptrget, _mulint etc.)
17406
17407 \layout Subsection
17408 Stdclib functions (puts, printf, strcat etc.)
17409
17410 \layout Subsubsection
17411 <stdio.h>
17412
17413 \layout Paragraph
17414 getchar(), putchar()
17415
17416 \layout Standard
17417 \begin_inset LatexCommand \index{<stdio.h>}
17418
17419 \end_inset
17420
17421 As usual on embedded systems you have to provide your own 
17422 \family typewriter
17423 getchar()
17424 \begin_inset LatexCommand \index{getchar()}
17425
17426 \end_inset
17427
17428  
17429 \family default
17430 and 
17431 \family typewriter
17432 putchar()
17433 \begin_inset LatexCommand \index{putchar()}
17434
17435 \end_inset
17436
17437
17438 \family default
17439  routines.
17440  SDCC does not know whether the system connects to a serial line with or
17441  without handshake, LCD, keyboard or other device.
17442  And whether a 
17443 \family typewriter
17444 lf
17445 \family default
17446  to 
17447 \family typewriter
17448 crlf
17449 \family default
17450  conversion within 
17451 \family typewriter
17452 putchar()
17453 \family default
17454  is intended.
17455  You'll find examples for serial routines f.e.
17456  in sdcc/device/lib.
17457  For the mcs51 this minimalistic polling 
17458 \family typewriter
17459 putchar()
17460 \family default
17461  routine might be a start:
17462
17463 \layout Verse
17464
17465 \family typewriter
17466 void putchar (char c) { 
17467 \newline
17468 \SpecialChar ~
17469 \SpecialChar ~
17470 \SpecialChar ~
17471 \SpecialChar ~
17472 while (!TI)\SpecialChar ~
17473 \SpecialChar ~
17474 \SpecialChar ~
17475  /* assumes UART is initialized */
17476 \newline
17477 \SpecialChar ~
17478 \SpecialChar ~
17479 \SpecialChar ~
17480 \SpecialChar ~
17481 \SpecialChar ~
17482 \SpecialChar ~
17483 \SpecialChar ~
17484 \SpecialChar ~
17485 ;
17486 \newline
17487 \SpecialChar ~
17488 \SpecialChar ~
17489 \SpecialChar ~
17490 \SpecialChar ~
17491 TI
17492  = 0;
17493 \newline
17494 \SpecialChar ~
17495 \SpecialChar ~
17496 \SpecialChar ~
17497 \SpecialChar ~
17498 SBUF = c;
17499 \newline
17500 }
17501
17502 \layout Paragraph
17503 printf()
17504
17505 \layout Standard
17506 The default
17507 \family typewriter
17508  printf()
17509 \begin_inset LatexCommand \index{printf()}
17510
17511 \end_inset
17512
17513
17514 \family default
17515  implementation in
17516 \family typewriter
17517  printf_large.c
17518 \family default
17519  does not support float (except on ds390).
17520  To enable this recompile it with the option 
17521 \emph on
17522 -
17523 \begin_inset ERT
17524 status Collapsed
17525
17526 \layout Standard
17527
17528
17529 \backslash
17530 /
17531
17532 \end_inset
17533
17534 DUSE_FLOATS=1
17535 \begin_inset LatexCommand \index{USE\_FLOATS}
17536
17537 \end_inset
17538
17539
17540 \emph default
17541  on the command line.
17542  Use
17543 \emph on
17544  -
17545 \begin_inset ERT
17546 status Collapsed
17547
17548 \layout Standard
17549
17550
17551 \backslash
17552 /
17553
17554 \end_inset
17555
17556 -model-large
17557 \begin_inset LatexCommand \index{-\/-model-large}
17558
17559 \end_inset
17560
17561
17562 \emph default
17563  for the mcs51 port, since this uses a lot of memory.
17564
17565 \layout Standard
17566 If you're short on code memory you might want to use 
17567 \family typewriter
17568 printf_small()
17569 \begin_inset LatexCommand \index{printf\_small()}
17570
17571 \end_inset
17572
17573
17574 \family default
17575  
17576 \emph on
17577 instead
17578 \emph default
17579  of
17580 \family typewriter
17581  printf().
17582
17583 \family default
17584  For the mcs51 there additionally are assembly versions 
17585 \family typewriter
17586 printf_tiny()
17587 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17588
17589 \end_inset
17590
17591
17592 \family default
17593  (subset of printf using less than 270 bytes) and 
17594 \family typewriter
17595 printf_fast()
17596 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17597
17598 \end_inset
17599
17600  
17601 \family default
17602 and
17603 \family typewriter
17604  printf_fast_f()
17605 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17606
17607 \end_inset
17608
17609
17610 \family default
17611  (floating-point aware version of printf_fast) which should fit the requirements
17612  of many embedded systems (printf_fast() can be customized by unsetting
17613  #defines to 
17614 \emph on
17615 not
17616 \emph default
17617  support long variables and field widths).
17618  Be sure to use only one of these printf options within a project.
17619 \newline
17620
17621
17622 \layout Standard
17623 Feature matrix of different 
17624 \emph on
17625 printf
17626 \emph default
17627  options on mcs51.
17628
17629 \layout Standard
17630 \begin_inset Tabular
17631 <lyxtabular version="3" rows="14" columns="7">
17632 <features islongtable="true">
17633 <column alignment="left" valignment="center" leftline="true" width="14col%">
17634 <column alignment="center" valignment="top" leftline="true" width="0">
17635 <column alignment="center" valignment="top" leftline="true" width="12col%">
17636 <column alignment="center" valignment="top" leftline="true" width="10col%">
17637 <column alignment="center" valignment="top" leftline="true" width="0">
17638 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17639 <column alignment="center" valignment="top" rightline="true" width="0">
17640 <row topline="true" bottomline="true" endhead="true">
17641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17642 \begin_inset Text
17643
17644 \layout Standard
17645
17646 \series bold
17647 \size large
17648 mcs51
17649
17650 \end_inset
17651 </cell>
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17653 \begin_inset Text
17654
17655 \layout Standard
17656 printf
17657 \begin_inset LatexCommand \index{printf}
17658
17659 \end_inset
17660
17661
17662
17663 \end_inset
17664 </cell>
17665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17666 \begin_inset Text
17667
17668 \layout Standard
17669 printf 
17670 \size scriptsize
17671 USE_FLOATS=1
17672
17673 \end_inset
17674 </cell>
17675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17676 \begin_inset Text
17677
17678 \layout Standard
17679 printf_small
17680
17681 \end_inset
17682 </cell>
17683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17684 \begin_inset Text
17685
17686 \layout Standard
17687 printf_fast
17688
17689 \end_inset
17690 </cell>
17691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17692 \begin_inset Text
17693
17694 \layout Standard
17695 printf_fast_f
17696
17697 \end_inset
17698 </cell>
17699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17700 \begin_inset Text
17701
17702 \layout Standard
17703 printf_tiny
17704
17705 \end_inset
17706 </cell>
17707 </row>
17708 <row topline="true" endhead="true">
17709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17710 \begin_inset Text
17711
17712 \layout Standard
17713 filename
17714
17715 \end_inset
17716 </cell>
17717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17718 \begin_inset Text
17719
17720 \layout Standard
17721
17722 \size scriptsize
17723 printf_large.c
17724
17725 \end_inset
17726 </cell>
17727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17728 \begin_inset Text
17729
17730 \layout Standard
17731
17732 \size scriptsize
17733 printf_large.c
17734
17735 \end_inset
17736 </cell>
17737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17738 \begin_inset Text
17739
17740 \layout Standard
17741
17742 \size scriptsize
17743 printfl.c
17744
17745 \end_inset
17746 </cell>
17747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17748 \begin_inset Text
17749
17750 \layout Standard
17751
17752 \size scriptsize
17753 printf_fast.c
17754
17755 \end_inset
17756 </cell>
17757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17758 \begin_inset Text
17759
17760 \layout Standard
17761
17762 \size scriptsize
17763 printf_fast_f.c
17764
17765 \end_inset
17766 </cell>
17767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17768 \begin_inset Text
17769
17770 \layout Standard
17771
17772 \size scriptsize
17773 printf_tiny.c
17774
17775 \end_inset
17776 </cell>
17777 </row>
17778 <row topline="true" endhead="true">
17779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17780 \begin_inset Text
17781
17782 \layout Standard
17783 \begin_inset Quotes sld
17784 \end_inset
17785
17786 Hello World
17787 \begin_inset Quotes srd
17788 \end_inset
17789
17790  size
17791
17792 \layout Standard
17793 small / large
17794
17795 \end_inset
17796 </cell>
17797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17798 \begin_inset Text
17799
17800 \layout Standard
17801 1.7k / 2.4k
17802
17803 \end_inset
17804 </cell>
17805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17806 \begin_inset Text
17807
17808 \layout Standard
17809 4.3k / 5.6k
17810
17811 \end_inset
17812 </cell>
17813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17814 \begin_inset Text
17815
17816 \layout Standard
17817 1.2k / 1.8k
17818
17819 \end_inset
17820 </cell>
17821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17822 \begin_inset Text
17823
17824 \layout Standard
17825 1.3k / 1.3k
17826
17827 \end_inset
17828 </cell>
17829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17830 \begin_inset Text
17831
17832 \layout Standard
17833 1.9k / 1.9k
17834
17835 \end_inset
17836 </cell>
17837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17838 \begin_inset Text
17839
17840 \layout Standard
17841 0.44k / 0.44k
17842
17843 \end_inset
17844 </cell>
17845 </row>
17846 <row topline="true" endhead="true">
17847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17848 \begin_inset Text
17849
17850 \layout Standard
17851 code size
17852
17853 \layout Standard
17854 small / large
17855
17856 \end_inset
17857 </cell>
17858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17859 \begin_inset Text
17860
17861 \layout Standard
17862 1.4k / 2.0k
17863
17864 \end_inset
17865 </cell>
17866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17867 \begin_inset Text
17868
17869 \layout Standard
17870 2.8k / 3.7k
17871
17872 \end_inset
17873 </cell>
17874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17875 \begin_inset Text
17876
17877 \layout Standard
17878 0.45k / 0.47k (+ _ltoa)
17879
17880 \end_inset
17881 </cell>
17882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17883 \begin_inset Text
17884
17885 \layout Standard
17886 1.2k / 1.2k
17887
17888 \end_inset
17889 </cell>
17890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17891 \begin_inset Text
17892
17893 \layout Standard
17894 1.6k / 1.6k
17895
17896 \end_inset
17897 </cell>
17898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17899 \begin_inset Text
17900
17901 \layout Standard
17902 0.26k / 0.26k
17903
17904 \end_inset
17905 </cell>
17906 </row>
17907 <row topline="true">
17908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17909 \begin_inset Text
17910
17911 \layout Standard
17912 formats
17913
17914 \end_inset
17915 </cell>
17916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17917 \begin_inset Text
17918
17919 \layout Standard
17920 cdi
17921 \emph on
17922 o
17923 \emph default
17924 psux
17925
17926 \end_inset
17927 </cell>
17928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17929 \begin_inset Text
17930
17931 \layout Standard
17932
17933 \family roman
17934 \series medium
17935 \shape up
17936 \size normal
17937 \emph off
17938 \bar no
17939 \noun off
17940 \color none
17941 cd
17942 \family default
17943 \series default
17944 \shape default
17945 \size default
17946 \emph default
17947 \bar default
17948 \noun default
17949 f
17950 \family roman
17951 \series medium
17952 \shape up
17953 \size normal
17954 \emph off
17955 \bar no
17956 \noun off
17957 i
17958 \family default
17959 \series default
17960 \shape default
17961 \size default
17962 \emph on
17963 \bar default
17964 \noun default
17965 o
17966 \family roman
17967 \series medium
17968 \shape up
17969 \size normal
17970 \emph off
17971 \bar no
17972 \noun off
17973 psux
17974
17975 \end_inset
17976 </cell>
17977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17978 \begin_inset Text
17979
17980 \layout Standard
17981 c
17982 \family roman
17983 \series medium
17984 \shape up
17985 \size normal
17986 \emph off
17987 \bar no
17988 \noun off
17989 \color none
17990 d
17991 \family default
17992 \series default
17993 \shape default
17994 \size default
17995 \emph on
17996 \bar default
17997 \noun default
17998 o
17999 \family roman
18000 \series medium
18001 \shape up
18002 \size normal
18003 \emph off
18004 \bar no
18005 \noun off
18006 s
18007 \family default
18008 \series default
18009 \shape default
18010 \size default
18011 \emph default
18012 \bar default
18013 \noun default
18014 x
18015
18016 \end_inset
18017 </cell>
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18019 \begin_inset Text
18020
18021 \layout Standard
18022 cdsux
18023
18024 \end_inset
18025 </cell>
18026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18027 \begin_inset Text
18028
18029 \layout Standard
18030 cdfsux
18031
18032 \end_inset
18033 </cell>
18034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18035 \begin_inset Text
18036
18037 \layout Standard
18038 cdsux
18039
18040 \end_inset
18041 </cell>
18042 </row>
18043 <row topline="true">
18044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18045 \begin_inset Text
18046
18047 \layout Standard
18048 long (32 bit) support
18049
18050 \end_inset
18051 </cell>
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18053 \begin_inset Text
18054
18055 \layout Standard
18056 x
18057
18058 \end_inset
18059 </cell>
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18061 \begin_inset Text
18062
18063 \layout Standard
18064 x
18065
18066 \end_inset
18067 </cell>
18068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18069 \begin_inset Text
18070
18071 \layout Standard
18072 x
18073
18074 \end_inset
18075 </cell>
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18077 \begin_inset Text
18078
18079 \layout Standard
18080 x
18081
18082 \end_inset
18083 </cell>
18084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18085 \begin_inset Text
18086
18087 \layout Standard
18088
18089 \family roman
18090 \series medium
18091 \shape up
18092 \size normal
18093 \emph off
18094 \bar no
18095 \noun off
18096 \color none
18097 x
18098
18099 \end_inset
18100 </cell>
18101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18102 \begin_inset Text
18103
18104 \layout Standard
18105 -
18106
18107 \end_inset
18108 </cell>
18109 </row>
18110 <row topline="true">
18111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18112 \begin_inset Text
18113
18114 \layout Standard
18115 byte arguments on stack
18116
18117 \end_inset
18118 </cell>
18119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18120 \begin_inset Text
18121
18122 \layout Standard
18123 b
18124
18125 \end_inset
18126 </cell>
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18128 \begin_inset Text
18129
18130 \layout Standard
18131 b
18132
18133 \end_inset
18134 </cell>
18135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18136 \begin_inset Text
18137
18138 \layout Standard
18139 -
18140
18141 \end_inset
18142 </cell>
18143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18144 \begin_inset Text
18145
18146 \layout Standard
18147 -
18148
18149 \end_inset
18150 </cell>
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18152 \begin_inset Text
18153
18154 \layout Standard
18155 -
18156
18157 \end_inset
18158 </cell>
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18160 \begin_inset Text
18161
18162 \layout Standard
18163 -
18164
18165 \end_inset
18166 </cell>
18167 </row>
18168 <row topline="true">
18169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18170 \begin_inset Text
18171
18172 \layout Standard
18173 float format
18174 \begin_inset LatexCommand \index{Floating point support}
18175
18176 \end_inset
18177
18178
18179
18180 \end_inset
18181 </cell>
18182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18183 \begin_inset Text
18184
18185 \layout Standard
18186 -
18187
18188 \end_inset
18189 </cell>
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18191 \begin_inset Text
18192
18193 \layout Standard
18194 %f
18195
18196 \end_inset
18197 </cell>
18198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18199 \begin_inset Text
18200
18201 \layout Standard
18202 -
18203
18204 \end_inset
18205 </cell>
18206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18207 \begin_inset Text
18208
18209 \layout Standard
18210 -
18211
18212 \end_inset
18213 </cell>
18214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18215 \begin_inset Text
18216
18217 \layout Standard
18218 %f
18219 \begin_inset Foot
18220 collapsed true
18221
18222 \layout Standard
18223 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
18224
18225 \end_inset
18226
18227
18228
18229 \end_inset
18230 </cell>
18231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18232 \begin_inset Text
18233
18234 \layout Standard
18235 -
18236
18237 \end_inset
18238 </cell>
18239 </row>
18240 <row topline="true">
18241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18242 \begin_inset Text
18243
18244 \layout Standard
18245 float formats %e %g
18246
18247 \end_inset
18248 </cell>
18249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18250 \begin_inset Text
18251
18252 \layout Standard
18253 -
18254
18255 \end_inset
18256 </cell>
18257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18258 \begin_inset Text
18259
18260 \layout Standard
18261 -
18262
18263 \end_inset
18264 </cell>
18265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18266 \begin_inset Text
18267
18268 \layout Standard
18269 -
18270
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
18279 \end_inset
18280 </cell>
18281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18282 \begin_inset Text
18283
18284 \layout Standard
18285 -
18286
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
18295 \end_inset
18296 </cell>
18297 </row>
18298 <row topline="true" bottomline="true">
18299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18300 \begin_inset Text
18301
18302 \layout Standard
18303 field width
18304
18305 \end_inset
18306 </cell>
18307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18308 \begin_inset Text
18309
18310 \layout Standard
18311 x
18312
18313 \end_inset
18314 </cell>
18315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18316 \begin_inset Text
18317
18318 \layout Standard
18319 x
18320
18321 \end_inset
18322 </cell>
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18324 \begin_inset Text
18325
18326 \layout Standard
18327 -
18328
18329 \end_inset
18330 </cell>
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18332 \begin_inset Text
18333
18334 \layout Standard
18335 x
18336
18337 \end_inset
18338 </cell>
18339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18340 \begin_inset Text
18341
18342 \layout Standard
18343 x
18344
18345 \end_inset
18346 </cell>
18347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18348 \begin_inset Text
18349
18350 \layout Standard
18351 -
18352
18353 \end_inset
18354 </cell>
18355 </row>
18356 <row bottomline="true">
18357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18358 \begin_inset Text
18359
18360 \layout Standard
18361 string speed
18362 \begin_inset Foot
18363 collapsed true
18364
18365 \layout Standard
18366 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18367 \backslash
18368 r', '
18369 \backslash
18370 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18371
18372 \end_inset
18373
18374 ,
18375
18376 \layout Standard
18377 small / large
18378
18379 \end_inset
18380 </cell>
18381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18382 \begin_inset Text
18383
18384 \layout Standard
18385 1.52 / 2.59 ms
18386
18387 \end_inset
18388 </cell>
18389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18390 \begin_inset Text
18391
18392 \layout Standard
18393 1.53 / 2.62 ms
18394
18395 \end_inset
18396 </cell>
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18398 \begin_inset Text
18399
18400 \layout Standard
18401 0.92 / 0.93 ms
18402
18403 \end_inset
18404 </cell>
18405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18406 \begin_inset Text
18407
18408 \layout Standard
18409 0.45 / 0.45 ms
18410
18411 \end_inset
18412 </cell>
18413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18414 \begin_inset Text
18415
18416 \layout Standard
18417 0.46 / 0.46 ms
18418
18419 \end_inset
18420 </cell>
18421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18422 \begin_inset Text
18423
18424 \layout Standard
18425 0.45 / 0.45 ms
18426
18427 \end_inset
18428 </cell>
18429 </row>
18430 <row bottomline="true">
18431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18432 \begin_inset Text
18433
18434 \layout Standard
18435 int speed
18436 \begin_inset Foot
18437 collapsed true
18438
18439 \layout Standard
18440 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18441  putchar()
18442
18443 \end_inset
18444
18445 ,
18446
18447 \layout Standard
18448 small / large
18449
18450 \end_inset
18451 </cell>
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18453 \begin_inset Text
18454
18455 \layout Standard
18456 3.01 / 3.61 ms
18457
18458 \end_inset
18459 </cell>
18460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18461 \begin_inset Text
18462
18463 \layout Standard
18464 3.01 / 3.61 ms
18465
18466 \end_inset
18467 </cell>
18468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18469 \begin_inset Text
18470
18471 \layout Standard
18472 3.51 / 18.13 ms
18473
18474 \end_inset
18475 </cell>
18476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18477 \begin_inset Text
18478
18479 \layout Standard
18480 0.22 / 0.22 ms
18481
18482 \end_inset
18483 </cell>
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 \begin_inset Text
18486
18487 \layout Standard
18488 0.23 / 0.23 ms
18489
18490 \end_inset
18491 </cell>
18492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18493 \begin_inset Text
18494
18495 \layout Standard
18496 0.25 / 0.25 ms
18497 \begin_inset Foot
18498 collapsed true
18499
18500 \layout Standard
18501 printf_tiny integer speed is data dependent, worst case is 0.33 ms
18502
18503 \end_inset
18504
18505
18506
18507 \end_inset
18508 </cell>
18509 </row>
18510 <row bottomline="true">
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18512 \begin_inset Text
18513
18514 \layout Standard
18515 long speed
18516 \begin_inset Foot
18517 collapsed true
18518
18519 \layout Standard
18520 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18521  empty putchar()
18522
18523 \end_inset
18524
18525 ,
18526
18527 \layout Standard
18528 small / large
18529
18530 \end_inset
18531 </cell>
18532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18533 \begin_inset Text
18534
18535 \layout Standard
18536 5.37 / 6.31 ms
18537
18538 \end_inset
18539 </cell>
18540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18541 \begin_inset Text
18542
18543 \layout Standard
18544 5.37 / 6.31 ms
18545
18546 \end_inset
18547 </cell>
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18549 \begin_inset Text
18550
18551 \layout Standard
18552 8.71 / 40.65 ms
18553
18554 \end_inset
18555 </cell>
18556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18557 \begin_inset Text
18558
18559 \layout Standard
18560 0.40 / 0.40 ms
18561
18562 \end_inset
18563 </cell>
18564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18565 \begin_inset Text
18566
18567 \layout Standard
18568 0.40 / 0.40 ms
18569
18570 \end_inset
18571 </cell>
18572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18573 \begin_inset Text
18574
18575 \layout Standard
18576 -
18577
18578 \end_inset
18579 </cell>
18580 </row>
18581 <row bottomline="true">
18582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18583 \begin_inset Text
18584
18585 \layout Standard
18586 float speed
18587 \begin_inset Foot
18588 collapsed true
18589
18590 \layout Standard
18591 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18592  empty putchar()
18593
18594 \end_inset
18595
18596 ,
18597
18598 \layout Standard
18599 small / large
18600
18601 \end_inset
18602 </cell>
18603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18604 \begin_inset Text
18605
18606 \layout Standard
18607 -
18608
18609 \end_inset
18610 </cell>
18611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18612 \begin_inset Text
18613
18614 \layout Standard
18615 7.49 / 22.47 ms
18616
18617 \end_inset
18618 </cell>
18619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18620 \begin_inset Text
18621
18622 \layout Standard
18623 -
18624
18625 \end_inset
18626 </cell>
18627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18628 \begin_inset Text
18629
18630 \layout Standard
18631 -
18632
18633 \end_inset
18634 </cell>
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18636 \begin_inset Text
18637
18638 \layout Standard
18639 1.04 / 1.04 ms
18640
18641 \end_inset
18642 </cell>
18643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18644 \begin_inset Text
18645
18646 \layout Standard
18647 -
18648
18649 \end_inset
18650 </cell>
18651 </row>
18652 </lyxtabular>
18653
18654 \end_inset
18655
18656
18657
18658 \layout Subsubsection
18659 <malloc.h>
18660 \begin_inset LatexCommand \index{malloc.h}
18661
18662 \end_inset
18663
18664
18665
18666 \layout Standard
18667 As of SDCC 2.6.2 you no longer need to call an initialization routine before
18668  using dynamic memory allocation
18669 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
18670
18671 \end_inset
18672
18673  and a default heap
18674 \begin_inset LatexCommand \index{heap (malloc)}
18675
18676 \end_inset
18677
18678  space of 1024 bytes is provided for malloc to allocate memory from.
18679  If you need a different heap size you need to recompile _heap.c with the
18680  required size defined in HEAP_SIZE.
18681  It is recommended to make a copy of this file into your project directory
18682  and compile it there with:
18683
18684 \layout Verse
18685
18686 \family typewriter
18687 sdcc -c _heap.c -D HEAD_SIZE=2048
18688
18689 \layout Standard
18690 And then link it with:
18691
18692 \layout Verse
18693
18694 \family typewriter
18695 sdcc main.rel _heap.rel
18696
18697 \layout Subsection
18698 Math functions (sinf, powf, sqrtf etc.)
18699
18700 \layout Subsubsection
18701 <math.h>
18702
18703 \layout Standard
18704 See definitions in file <math.h>.
18705
18706 \layout Subsection
18707 Other libraries
18708
18709 \layout Standard
18710 Libraries
18711 \begin_inset LatexCommand \index{Libraries}
18712
18713 \end_inset
18714
18715  included in SDCC should have a license at least as liberal as the GNU Lesser
18716  General Public License
18717 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
18718
18719 \end_inset
18720
18721  
18722 \emph on
18723 LGPL
18724 \emph default
18725 .
18726
18727 \layout Standard
18728 \begin_inset Note
18729 collapsed true
18730
18731 \layout Standard
18732 license statements for the libraries are missing.
18733  sdcc/device/lib/ser_ir.c
18734
18735 \layout Standard
18736 or _decdptr f.e.
18737  come with a GPL (as opposed to LGPL) License - this will not be liberal
18738  enough for many embedded programmers.
18739
18740 \end_inset
18741
18742
18743
18744 \layout Standard
18745 If you have ported some library or want to share experience about some code
18746  which f.e.
18747  falls into any of these categories Busses (I
18748 \begin_inset Formula $^{\textrm{2}}$
18749 \end_inset
18750
18751 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
18752  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
18753  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
18754 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
18755
18756 \end_inset
18757
18758 \SpecialChar ~
18759 would certainly like to hear about it.
18760
18761 \layout Standard
18762 \added_space_bottom bigskip 
18763 Programmers coding for embedded systems are not especially famous for being
18764  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
18765 e these references are very valuable.
18766  Let's help to create a climate where information is shared.
18767
18768
18769
18770 \layout Section
18771 Memory Models
18772
18773 \layout Subsection
18774 MCS51 Memory Models
18775 \begin_inset LatexCommand \index{Memory model}
18776
18777 \end_inset
18778
18779
18780 \begin_inset LatexCommand \index{MCS51 memory model}
18781
18782 \end_inset
18783
18784
18785
18786 \layout Subsubsection
18787 Small, Medium and Large
18788
18789 \layout Standard
18790 SDCC allows three memory models for MCS51 code, 
18791 \shape slanted
18792 small, medium
18793 \shape default
18794  and 
18795 \shape slanted
18796 large
18797 \shape default
18798 .
18799  Modules compiled with different memory models should 
18800 \emph on
18801 never
18802 \emph default
18803  be combined together or the results would be unpredictable.
18804  The library routines supplied with the compiler are compiled as small,
18805  medium and large.
18806  The compiled library modules are contained in separate directories as small,
18807  medium and large so that you can link to the appropriate set.
18808
18809 \layout Standard
18810 When the medium or large model is used all variables declared without a
18811  storage class will be allocated into the external ram, this includes all
18812  parameters and local variables (for non-reentrant
18813 \begin_inset LatexCommand \index{reentrant}
18814
18815 \end_inset
18816
18817  functions).
18818  When the small model is used variables without storage class are allocated
18819  in the internal ram.
18820
18821 \layout Standard
18822 Judicious usage of the processor specific storage classes
18823 \begin_inset LatexCommand \index{Storage class}
18824
18825 \end_inset
18826
18827  and the 'reentrant' function type will yield much more efficient code,
18828  than using the large model.
18829  Several optimizations are disabled when the program is compiled using the
18830  large model, it is therefore recommended that the small model be used unless
18831  absolutely required.
18832
18833 \layout Subsubsection
18834 External Stack
18835 \begin_inset LatexCommand \label{sub:External-Stack}
18836
18837 \end_inset
18838
18839
18840 \begin_inset LatexCommand \index{stack}
18841
18842 \end_inset
18843
18844
18845 \begin_inset LatexCommand \index{External stack (mcs51)}
18846
18847 \end_inset
18848
18849
18850
18851 \layout Standard
18852 The external stack (-
18853 \begin_inset ERT
18854 status Collapsed
18855
18856 \layout Standard
18857
18858
18859 \backslash
18860 /
18861
18862 \end_inset
18863
18864 -xstack option
18865 \begin_inset LatexCommand \index{-\/-xstack}
18866
18867 \end_inset
18868
18869 ) is located in pdata
18870 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18871
18872 \end_inset
18873
18874  memory (usually at the start of the external ram segment) and uses all
18875  unused space in pdata (max.
18876  256 bytes).
18877  When -
18878 \begin_inset ERT
18879 status Collapsed
18880
18881 \layout Standard
18882
18883
18884 \backslash
18885 /
18886
18887 \end_inset
18888
18889 -xstack option is used to compile the program, the parameters and local
18890  variables
18891 \begin_inset LatexCommand \index{local variables}
18892
18893 \end_inset
18894
18895  of all reentrant functions are allocated in this area.
18896  This option is provided for programs with large stack space requirements.
18897  When used with the -
18898 \begin_inset ERT
18899 status Collapsed
18900
18901 \layout Standard
18902
18903
18904 \backslash
18905 /
18906
18907 \end_inset
18908
18909 -stack-auto
18910 \begin_inset LatexCommand \index{-\/-stack-auto}
18911
18912 \end_inset
18913
18914  option, all parameters and local variables are allocated on the external
18915  stack (note: support libraries will need to be recompiled with the same
18916  options.
18917  There is a predefined target in the library makefile).
18918
18919 \layout Standard
18920 The compiler outputs the higher order address byte of the external ram segment
18921  into port P2
18922 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18923
18924 \end_inset
18925
18926  (see also section 
18927 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18928
18929 \end_inset
18930
18931 ), therefore when using the External Stack option, this port 
18932 \emph on
18933 may not
18934 \emph default
18935  be used by the application program.
18936
18937 \layout Subsection
18938 DS390 Memory Model
18939 \begin_inset LatexCommand \index{Memory model}
18940
18941 \end_inset
18942
18943
18944 \begin_inset LatexCommand \index{DS390 memory model}
18945
18946 \end_inset
18947
18948
18949
18950 \layout Standard
18951 The only model supported is Flat 24
18952 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18953
18954 \end_inset
18955
18956 .
18957  This generates code for the 24 bit contiguous addressing mode of the Dallas
18958  DS80C390 part.
18959  In this mode, up to four meg of external RAM or code space can be directly
18960  addressed.
18961  See the data sheets at www.dalsemi.com for further information on this part.
18962 \newline
18963
18964 \newline
18965 Note
18966  that the compiler does not generate any code to place the processor into
18967  24 bitmode (although 
18968 \emph on
18969 tinibios
18970 \emph default
18971  in the ds390 libraries will do that for you).
18972  If you don't use 
18973 \emph on
18974 tinibios
18975 \emph default
18976
18977 \begin_inset LatexCommand \index{Tinibios (DS390)}
18978
18979 \end_inset
18980
18981 , the boot loader or similar code must ensure that the processor is in 24
18982  bit contiguous addressing mode before calling the SDCC startup code.
18983 \newline
18984
18985 \newline
18986 Like
18987  the 
18988 \emph on
18989 -
18990 \begin_inset ERT
18991 status Collapsed
18992
18993 \layout Standard
18994
18995
18996 \backslash
18997 /
18998
18999 \end_inset
19000
19001 -model-large
19002 \emph default
19003  option, variables will by default be placed into the XDATA segment.
19004  
19005 \newline
19006
19007 \newline
19008 Segments may be placed anywhere in the 4 meg address space using the usual
19009  -
19010 \begin_inset ERT
19011 status Collapsed
19012
19013 \layout Standard
19014
19015
19016 \backslash
19017 /
19018
19019 \end_inset
19020
19021 -*-loc options.
19022  Note that if any segments are located above 64K, the -r flag must be passed
19023  to the linker to generate the proper segment relocations, and the Intel
19024  HEX output format must be used.
19025  The -r flag can be passed to the linker by using the option 
19026 \emph on
19027 -Wl-r
19028 \emph default
19029  on the SDCC command line.
19030  However, currently the linker can not handle code segments > 64k.
19031
19032 \layout Section
19033 Pragmas
19034 \begin_inset LatexCommand \label{sec:Pragmas}
19035
19036 \end_inset
19037
19038
19039 \begin_inset LatexCommand \index{Pragmas}
19040
19041 \end_inset
19042
19043
19044
19045 \layout Standard
19046 SDCC supports the following #pragma directives:
19047
19048 \layout Itemize
19049
19050 \series bold
19051 save
19052 \series default
19053
19054 \begin_inset LatexCommand \index{\#pragma save}
19055
19056 \end_inset
19057
19058  - this will save most current options to the save/restore stack.
19059  See #pragma\SpecialChar ~
19060 restore.
19061
19062 \layout Itemize
19063
19064 \series bold
19065 restore
19066 \series default
19067
19068 \begin_inset LatexCommand \index{\#pragma restore}
19069
19070 \end_inset
19071
19072  - will restore saved options from the last save.
19073  saves & restores can be nested.
19074  SDCC uses a save/restore stack: save pushes current options to the stack,
19075  restore pulls current options from the stack.
19076  See #pragma\SpecialChar ~
19077 save.
19078 \newline
19079
19080
19081 \layout Itemize
19082
19083 \series bold
19084 callee_saves
19085 \series default
19086
19087 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19088
19089 \end_inset
19090
19091
19092 \begin_inset LatexCommand \index{function prologue}
19093
19094 \end_inset
19095
19096  function1[,function2[,function3...]] - The compiler by default uses a caller
19097  saves convention for register saving across function calls, however this
19098  can cause unnecessary register pushing & popping
19099 \begin_inset LatexCommand \index{push/pop}
19100
19101 \end_inset
19102
19103  when calling small functions from larger functions.
19104  This option can be used to switch off the register saving convention for
19105  the function names specified.
19106  The compiler will not save registers when calling these functions, extra
19107  code need to be manually inserted at the entry & exit for these functions
19108  to save & restore the registers used by these functions, this can SUBSTANTIALLY
19109  reduce code & improve run time performance of the generated code.
19110  In the future the compiler (with inter procedural analysis) may be able
19111  to determine the appropriate scheme to use for each function call.
19112  If -
19113 \begin_inset ERT
19114 status Collapsed
19115
19116 \layout Standard
19117
19118
19119 \backslash
19120 /
19121
19122 \end_inset
19123
19124 -callee-saves command line option is used, the function names specified
19125  in #pragma\SpecialChar ~
19126 callee_saves
19127 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19128
19129 \end_inset
19130
19131  is appended to the list of functions specified in the command line.
19132
19133 \layout Itemize
19134
19135 \series bold
19136 exclude
19137 \series default
19138
19139 \begin_inset LatexCommand \index{\#pragma exclude}
19140
19141 \end_inset
19142
19143  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19144  of pairs of push/pop
19145 \begin_inset LatexCommand \index{push/pop}
19146
19147 \end_inset
19148
19149  instructions in 
19150 \emph on
19151 I
19152 \emph default
19153 nterrupt
19154 \begin_inset LatexCommand \index{interrupt}
19155
19156 \end_inset
19157
19158  
19159 \emph on
19160 S
19161 \emph default
19162 ervice 
19163 \emph on
19164 R
19165 \emph default
19166 outines.
19167  The directive should be placed immediately before the ISR function definition
19168  and it affects ALL ISR functions following it.
19169  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
19170 exclude\SpecialChar ~
19171 none
19172 \begin_inset LatexCommand \index{\#pragma exclude}
19173
19174 \end_inset
19175
19176 .
19177  See also the related keyword _naked
19178 \begin_inset LatexCommand \index{\_naked}
19179
19180 \end_inset
19181
19182
19183 \begin_inset LatexCommand \index{\_\_naked}
19184
19185 \end_inset
19186
19187 .
19188
19189 \layout Itemize
19190
19191 \series bold
19192 less_pedantic
19193 \series default
19194
19195 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19196
19197 \end_inset
19198
19199  - the compiler will not warn you anymore for obvious mistakes, you'r on
19200  your own now ;-(
19201
19202 \layout Itemize
19203
19204 \series bold
19205 disable_warning
19206 \series default
19207  <nnnn>
19208 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19209
19210 \end_inset
19211
19212  - the compiler will not warn you anymore about warning number <nnnn>.
19213
19214 \layout Itemize
19215
19216 \series bold
19217 nogcse
19218 \series default
19219
19220 \begin_inset LatexCommand \index{\#pragma nogcse}
19221
19222 \end_inset
19223
19224  - will stop global common subexpression elimination.
19225
19226 \layout Itemize
19227
19228 \series bold
19229 noinduction
19230 \series default
19231
19232 \begin_inset LatexCommand \index{\#pragma noinduction}
19233
19234 \end_inset
19235
19236  - will stop loop induction optimizations.
19237
19238 \layout Itemize
19239
19240 \series bold
19241 noinvariant
19242 \series default
19243
19244 \begin_inset LatexCommand \index{\#pragma noinvariant}
19245
19246 \end_inset
19247
19248  - will not do loop invariant optimizations.
19249  For more details see Loop Invariants in section
19250 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19251
19252 \end_inset
19253
19254 .
19255
19256 \layout Itemize
19257
19258 \series bold
19259 noiv
19260 \series default
19261
19262 \begin_inset LatexCommand \index{\#pragma noiv}
19263
19264 \end_inset
19265
19266  - Do not generate interrupt
19267 \begin_inset LatexCommand \index{interrupt}
19268
19269 \end_inset
19270
19271  vector table
19272 \begin_inset LatexCommand \index{interrupt vector table}
19273
19274 \end_inset
19275
19276  entries for all ISR functions defined after the pragma.
19277  This is useful in cases where the interrupt vector table must be defined
19278  manually, or when there is a secondary, manually defined interrupt vector
19279  table (e.g.
19280  for the autovector feature of the Cypress EZ-USB FX2).
19281  More elegantly this can be achieved by obmitting the optional interrupt
19282  number after the interrupt keyword, see section 
19283 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19284
19285 \end_inset
19286
19287 \SpecialChar ~
19288 about interrupts.
19289
19290 \layout Itemize
19291
19292 \series bold
19293 nojtbound
19294 \series default
19295
19296 \begin_inset LatexCommand \index{\#pragma nojtbound}
19297
19298 \end_inset
19299
19300  - will not generate code for boundary value checking, when switch statements
19301  are turned into jump-tables (dangerous).
19302  For more details see section 
19303 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19304
19305 \end_inset
19306
19307 .
19308
19309 \layout Itemize
19310
19311 \series bold
19312 noloopreverse
19313 \series default
19314
19315 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19316
19317 \end_inset
19318
19319  - Will not do loop reversal optimization
19320
19321 \layout Itemize
19322
19323 \series bold
19324 nooverlay
19325 \series default
19326
19327 \begin_inset LatexCommand \index{\#pragma nooverlay}
19328
19329 \end_inset
19330
19331  - the compiler will not overlay the parameters and local variables of a
19332  function.
19333
19334 \layout Itemize
19335
19336 \series bold
19337 stackauto
19338 \series default
19339
19340 \begin_inset LatexCommand \index{\#pragma stackauto}
19341
19342 \end_inset
19343
19344 - See option -
19345 \begin_inset ERT
19346 status Collapsed
19347
19348 \layout Standard
19349
19350
19351 \backslash
19352 /
19353
19354 \end_inset
19355
19356 -stack-auto
19357 \begin_inset LatexCommand \index{-\/-stack-auto}
19358
19359 \end_inset
19360
19361  and section 
19362 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19363
19364 \end_inset
19365
19366  Parameters and Local Variables.
19367
19368 \layout Itemize
19369
19370 \series bold
19371 opt_code_speed
19372 \series default
19373  
19374 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19375
19376 \end_inset
19377
19378 - The compiler will optimize code generation towards fast code, possibly
19379  at the expense of code size.
19380  Currently this has little effect.
19381
19382 \layout Itemize
19383
19384 \series bold
19385 opt_code_size
19386 \series default
19387  
19388 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19389
19390 \end_inset
19391
19392 - The compiler will optimize code generation towards compact code, possibly
19393  at the expense of code speed.
19394  Currently this has little effect.
19395
19396 \layout Itemize
19397
19398 \series bold
19399 opt_code_balanced
19400 \series default
19401  
19402 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19403
19404 \end_inset
19405
19406 - The compiler will attempt to generate code that is both compact and fast,
19407  as long as meeting one goal is not a detriment to the other (this is the
19408  default).
19409  
19410
19411 \layout Itemize
19412
19413 \series bold
19414 std_sdcc89
19415 \series default
19416  
19417 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19418
19419 \end_inset
19420
19421 - Generally follow the C89 standard, but allow SDCC features that conflict
19422  with the standard (default).
19423
19424 \layout Itemize
19425
19426 \series bold
19427 std_c89
19428 \series default
19429  
19430 \begin_inset LatexCommand \index{\#pragma std\_c89}
19431
19432 \end_inset
19433
19434 - Follow the C89 standard and disable SDCC features that conflict with the
19435  standard.
19436
19437 \layout Itemize
19438
19439 \series bold
19440 std_sdcc99
19441 \series default
19442  
19443 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19444
19445 \end_inset
19446
19447 - Generally follow the C99 standard, but allow SDCC features that conflict
19448  with the standard (incomplete support).
19449
19450 \layout Itemize
19451
19452 \series bold
19453 std_c99
19454 \series default
19455  
19456 \begin_inset LatexCommand \index{\#pragma std\_c99}
19457
19458 \end_inset
19459
19460 - Follow the C99 standard and disable SDCC features that conflict with the
19461  standard (incomplete support).
19462
19463 \layout Itemize
19464
19465 \series bold
19466 codeseg
19467 \series default
19468  <name>
19469 \begin_inset LatexCommand \index{\#pragma codeseg}
19470
19471 \end_inset
19472
19473 - Use this name (max.
19474  8 characters) for the code segment.
19475  See option -
19476 \begin_inset ERT
19477 status Collapsed
19478
19479 \layout Standard
19480
19481
19482 \backslash
19483 /
19484
19485 \end_inset
19486
19487 -codeseg.
19488
19489 \layout Itemize
19490
19491 \series bold
19492 constseg
19493 \series default
19494  <name>
19495 \begin_inset LatexCommand \index{\#pragma constseg}
19496
19497 \end_inset
19498
19499 - Use this name (max.
19500  8 characters) for the const segment.
19501  See option -
19502 \begin_inset ERT
19503 status Collapsed
19504
19505 \layout Standard
19506
19507
19508 \backslash
19509 /
19510
19511 \end_inset
19512
19513 -constseg.
19514
19515 \layout Standard
19516 The preprocessor SDCPP
19517 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19518
19519 \end_inset
19520
19521  supports the following #pragma directives:
19522
19523 \layout Itemize
19524
19525 \series bold
19526 pedantic_parse_number
19527 \series default
19528
19529 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19530
19531 \end_inset
19532
19533  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19534  parsed properly and the macro LO_B(3) gets expanded.
19535  Default is off.
19536  Below is an example on how to use this pragma.
19537
19538 \emph on
19539  Note: this functionality is not in conformance with standard!
19540
19541 \layout Verse
19542
19543 \family typewriter
19544 #pragma pedantic_parse_number +
19545 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19546
19547 \end_inset
19548
19549
19550 \newline
19551
19552 \newline
19553 #define LO_B(x) ((x) & 0xff)
19554 \newline
19555
19556 \newline
19557 unsigned char foo(void)
19558 \newline
19559 {
19560 \newline
19561 \SpecialChar ~
19562 \SpecialChar ~
19563 \SpecialChar ~
19564 unsigned char c=0xfe-LO_B(3)
19565 ;
19566 \newline
19567
19568 \newline
19569 \SpecialChar ~
19570 \SpecialChar ~
19571 \SpecialChar ~
19572 return c;
19573 \newline
19574 }
19575 \newline
19576
19577
19578 \layout Itemize
19579
19580 \series bold
19581 preproc_asm
19582 \series default
19583
19584 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19585
19586 \end_inset
19587
19588  (+ | -) - switch _asm _endasm block preprocessing on / off.
19589  Default is on.
19590  You use this prama to define multilines of assembly code.
19591  This will prevent the preprocessor from changing the formating required
19592  by assembly code.
19593  Below is an example on how to use this pragma.
19594
19595 \layout Verse
19596
19597 \family typewriter
19598 #pragma preproc_asm -
19599 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19600
19601 \end_inset
19602
19603
19604 \newline
19605 #define MYDELAY _asm
19606 \newline
19607 \SpecialChar ~
19608 \SpecialChar ~
19609 \SpecialChar ~
19610 nop ;my assembly comment...
19611 \newline
19612 \SpecialChar ~
19613 \SpecialChar ~
19614 \SpecialChar ~
19615 nop
19616 \newline
19617 \SpecialChar ~
19618 \SpecialChar ~
19619 \SpecialChar ~
19620 nop
19621 \newline
19622 _endasm
19623 \newline
19624 #pragma preproc_asm
19625  +
19626 \newline
19627
19628 \newline
19629 void foo (void) 
19630 \newline
19631
19632 \newline
19633 \SpecialChar ~
19634 \SpecialChar ~
19635 \SpecialChar ~
19636  ...
19637  
19638 \newline
19639 \SpecialChar ~
19640 \SpecialChar ~
19641 \SpecialChar ~
19642  MYDELAY;
19643 \newline
19644 \SpecialChar ~
19645 \SpecialChar ~
19646 \SpecialChar ~
19647  ...
19648  
19649 \newline
19650
19651 \newline
19652
19653
19654 \layout Itemize
19655
19656 \series bold
19657 sdcc_hash
19658 \series default
19659
19660 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19661
19662 \end_inset
19663
19664  (+ | -) - Allow "naked" hash in macro definition, for example:
19665 \newline
19666
19667 \family typewriter
19668 #define DIR_LO(x) #(x & 0xff)
19669 \family default
19670
19671 \newline
19672 Default is off.
19673  Below is an example on how to use this pragma.
19674
19675 \layout Verse
19676
19677 \family typewriter
19678 #pragma preproc_asm +
19679 \newline
19680 #pragma sdcc_hash +
19681 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19682
19683 \end_inset
19684
19685
19686 \newline
19687
19688 \newline
19689 #define ROMCALL(x) 
19690 \backslash
19691
19692 \newline
19693 \SpecialChar ~
19694 \SpecialChar ~
19695 \SpecialChar ~
19696 mov R6_B3, #(x & 0xff) 
19697 \backslash
19698
19699 \newline
19700 \SpecialChar ~
19701 \SpecialChar ~
19702 \SpecialChar ~
19703 mov R7_B3, #((x >> 8) & 0xff) 
19704 \backslash
19705
19706 \newline
19707 \SpecialChar ~
19708 \SpecialChar ~
19709 \SpecialChar ~
19710 lcall __romcall
19711 \newline
19712
19713 \newline
19714 ...
19715 \newline
19716 _asm
19717 \newline
19718 ROMCALL(72)
19719 \newline
19720 _endasm;
19721 \newline
19722 ...
19723 \newline
19724
19725
19726 \layout Standard
19727 The pragma's are intended to be used to turn-on or off certain optimizations
19728  which might cause the compiler to generate extra stack / data space to
19729  store compiler generated temporary variables.
19730  This usually happens in large functions.
19731  Pragma directives should be used as shown in the following example, they
19732  are used to control options & optimizations for a given function; pragmas
19733  should be placed before and/or after a function, placing pragma's inside
19734  a function body could have unpredictable results.
19735
19736 \layout Verse
19737
19738 \family typewriter
19739 #pragma save
19740 \begin_inset LatexCommand \index{\#pragma save}
19741
19742 \end_inset
19743
19744  \SpecialChar ~
19745 \SpecialChar ~
19746 \SpecialChar ~
19747 \SpecialChar ~
19748 \SpecialChar ~
19749 \SpecialChar ~
19750 \SpecialChar ~
19751 /* save the current settings */ 
19752 \newline
19753 #pragma nogcse
19754 \begin_inset LatexCommand \index{\#pragma nogcse}
19755
19756 \end_inset
19757
19758  \SpecialChar ~
19759 \SpecialChar ~
19760 \SpecialChar ~
19761 \SpecialChar ~
19762 \SpecialChar ~
19763 /* turnoff global subexpression elimination */ 
19764 \newline
19765 #pragma noinduction
19766 \begin_inset LatexCommand \index{\#pragma noinduction}
19767
19768 \end_inset
19769
19770  /* turn off induction optimizations */ 
19771 \newline
19772 int foo () 
19773 \newline
19774
19775 \newline
19776 \SpecialChar ~
19777  \SpecialChar ~
19778  ...
19779  
19780 \newline
19781 \SpecialChar ~
19782  \SpecialChar ~
19783  /* large code */ 
19784 \newline
19785 \SpecialChar ~
19786  \SpecialChar ~
19787  ...
19788  
19789 \newline
19790
19791 \newline
19792 #pragma restore
19793 \begin_inset LatexCommand \index{\#pragma restore}
19794
19795 \end_inset
19796
19797  /* turn the optimizations back on */
19798
19799 \layout Standard
19800 The compiler will generate a warning message when extra space is allocated.
19801  It is strongly recommended that the save and restore pragma's be used when
19802  changing options for a function.
19803 \newline
19804
19805 \newline
19806
19807 \newline
19808
19809
19810 \layout Section
19811 Defines Created by the Compiler
19812
19813 \layout Standard
19814 The compiler creates the following #defines
19815 \begin_inset LatexCommand \index{\#defines}
19816
19817 \end_inset
19818
19819
19820 \begin_inset LatexCommand \index{Defines created by the compiler}
19821
19822 \end_inset
19823
19824 :
19825 \newline
19826
19827
19828 \layout Standard
19829 \begin_inset Tabular
19830 <lyxtabular version="3" rows="11" columns="2">
19831 <features>
19832 <column alignment="left" valignment="top" leftline="true" width="3in">
19833 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
19834 <row topline="true" bottomline="true">
19835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19836 \begin_inset Text
19837
19838 \layout Standard
19839
19840 \series bold
19841 #define
19842
19843 \end_inset
19844 </cell>
19845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19846 \begin_inset Text
19847
19848 \layout Standard
19849
19850 \series bold
19851 Description
19852
19853 \end_inset
19854 </cell>
19855 </row>
19856 <row topline="true">
19857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19858 \begin_inset Text
19859
19860 \layout Standard
19861 SDCC
19862 \begin_inset LatexCommand \index{SDCC}
19863
19864 \end_inset
19865
19866  
19867
19868 \end_inset
19869 </cell>
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19871 \begin_inset Text
19872
19873 \layout Standard
19874 Always defined.
19875  Since version 2.5.6 the version number as an int (ex.
19876  256)
19877
19878 \end_inset
19879 </cell>
19880 </row>
19881 <row topline="true">
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \layout Standard
19886 SDCC_mcs51
19887 \begin_inset LatexCommand \index{SDCC\_mcs51}
19888
19889 \end_inset
19890
19891  or SDCC_ds390
19892 \begin_inset LatexCommand \index{SDCC\_ds390}
19893
19894 \end_inset
19895
19896  or SDCC_z80
19897 \begin_inset LatexCommand \index{SDCC\_z80}
19898
19899 \end_inset
19900
19901 , etc.
19902
19903 \end_inset
19904 </cell>
19905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19906 \begin_inset Text
19907
19908 \layout Standard
19909 depending on the model used (e.g.: -mds390)
19910
19911 \end_inset
19912 </cell>
19913 </row>
19914 <row topline="true">
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19916 \begin_inset Text
19917
19918 \layout Standard
19919 __mcs51
19920 \begin_inset LatexCommand \index{\_\_mcs51}
19921
19922 \end_inset
19923
19924 , __ds390
19925 \begin_inset LatexCommand \index{\_\_ds390}
19926
19927 \end_inset
19928
19929 , __hc08
19930 \begin_inset LatexCommand \index{\_\_hc08}
19931
19932 \end_inset
19933
19934 , __z80
19935 \begin_inset LatexCommand \index{\_\_z80}
19936
19937 \end_inset
19938
19939 , etc
19940
19941 \end_inset
19942 </cell>
19943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19944 \begin_inset Text
19945
19946 \layout Standard
19947 depending on the model used (e.g.
19948  -mz80)
19949
19950 \end_inset
19951 </cell>
19952 </row>
19953 <row topline="true">
19954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19955 \begin_inset Text
19956
19957 \layout Standard
19958 SDCC_STACK_AUTO
19959 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19960
19961 \end_inset
19962
19963
19964
19965 \end_inset
19966 </cell>
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19968 \begin_inset Text
19969
19970 \layout Standard
19971 when 
19972 \emph on
19973 -
19974 \begin_inset ERT
19975 status Collapsed
19976
19977 \layout Standard
19978
19979
19980 \backslash
19981 /
19982
19983 \end_inset
19984
19985 -stack-auto
19986 \emph default
19987  option is used
19988
19989 \end_inset
19990 </cell>
19991 </row>
19992 <row topline="true">
19993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19994 \begin_inset Text
19995
19996 \layout Standard
19997 SDCC_MODEL_SMALL
19998 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
19999
20000 \end_inset
20001
20002
20003
20004 \end_inset
20005 </cell>
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20007 \begin_inset Text
20008
20009 \layout Standard
20010 when 
20011 \emph on
20012 -
20013 \begin_inset ERT
20014 status Collapsed
20015
20016 \layout Standard
20017
20018
20019 \backslash
20020 /
20021
20022 \end_inset
20023
20024 -model-small
20025 \emph default
20026  is used
20027
20028 \end_inset
20029 </cell>
20030 </row>
20031 <row topline="true">
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20033 \begin_inset Text
20034
20035 \layout Standard
20036 SDCC_MODEL_MEDIUM
20037 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20038
20039 \end_inset
20040
20041
20042
20043 \end_inset
20044 </cell>
20045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20046 \begin_inset Text
20047
20048 \layout Standard
20049 when 
20050 \emph on
20051 -
20052 \begin_inset ERT
20053 status Collapsed
20054
20055 \layout Standard
20056
20057
20058 \backslash
20059 /
20060
20061 \end_inset
20062
20063 -model-medium
20064 \emph default
20065  is used
20066
20067 \end_inset
20068 </cell>
20069 </row>
20070 <row topline="true">
20071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20072 \begin_inset Text
20073
20074 \layout Standard
20075 SDCC_MODEL_LARGE
20076 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20077
20078 \end_inset
20079
20080
20081
20082 \end_inset
20083 </cell>
20084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20085 \begin_inset Text
20086
20087 \layout Standard
20088 when 
20089 \emph on
20090 -
20091 \begin_inset ERT
20092 status Collapsed
20093
20094 \layout Standard
20095
20096
20097 \backslash
20098 /
20099
20100 \end_inset
20101
20102 -model-large
20103 \emph default
20104  is used
20105
20106 \end_inset
20107 </cell>
20108 </row>
20109 <row topline="true">
20110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20111 \begin_inset Text
20112
20113 \layout Standard
20114 SDCC_USE_XSTACK
20115 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20116
20117 \end_inset
20118
20119
20120
20121 \end_inset
20122 </cell>
20123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20124 \begin_inset Text
20125
20126 \layout Standard
20127 when 
20128 \emph on
20129 -
20130 \begin_inset ERT
20131 status Collapsed
20132
20133 \layout Standard
20134
20135
20136 \backslash
20137 /
20138
20139 \end_inset
20140
20141 -xstack
20142 \emph default
20143  option is used
20144
20145 \end_inset
20146 </cell>
20147 </row>
20148 <row topline="true">
20149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20150 \begin_inset Text
20151
20152 \layout Standard
20153 SDCC_STACK_TENBIT
20154 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20155
20156 \end_inset
20157
20158  
20159
20160 \end_inset
20161 </cell>
20162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20163 \begin_inset Text
20164
20165 \layout Standard
20166 when 
20167 \emph on
20168 -mds390
20169 \emph default
20170  is used
20171
20172 \end_inset
20173 </cell>
20174 </row>
20175 <row topline="true" bottomline="true">
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 \begin_inset Text
20178
20179 \layout Standard
20180 SDCC_MODEL_FLAT24
20181 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20182
20183 \end_inset
20184
20185
20186
20187 \end_inset
20188 </cell>
20189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20190 \begin_inset Text
20191
20192 \layout Standard
20193 when 
20194 \emph on
20195 -mds390
20196 \emph default
20197  is used
20198
20199 \end_inset
20200 </cell>
20201 </row>
20202 </lyxtabular>
20203
20204 \end_inset
20205
20206
20207
20208 \layout Chapter
20209 Notes on supported Processors
20210
20211 \layout Section
20212 MCS51 variants
20213 \begin_inset LatexCommand \label{sub:MCS51-variants}
20214
20215 \end_inset
20216
20217
20218 \begin_inset LatexCommand \index{MCS51 variants}
20219
20220 \end_inset
20221
20222
20223
20224 \layout Standard
20225 MCS51 processors are available from many vendors and come in many different
20226  flavours.
20227  While they might differ considerably in respect to Special Function Registers
20228  the core MCS51 is usually not modified or is kept compatible.
20229  
20230
20231 \layout Subsection
20232 pdata access by SFR 
20233
20234 \layout Standard
20235 With the upcome of devices with internal xdata and flash memory devices
20236  using port P2
20237 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20238
20239 \end_inset
20240
20241  as dedicated I/O port is becoming more popular.
20242  Switching the high byte for pdata
20243 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20244
20245 \end_inset
20246
20247  access which was formerly done by port P2 is then achieved by a Special
20248  Function Register
20249 \begin_inset LatexCommand \index{sfr}
20250
20251 \end_inset
20252
20253 .
20254  In well-established MCS51 tradition the address of this 
20255 \emph on
20256 sfr
20257 \emph default
20258  is where the chip designers decided to put it.
20259  Needless to say that they didn't agree on a common name either.
20260  So that the startup code can correctly initialize xdata variables, you
20261  should define an sfr with the name _XPAGE
20262 \family typewriter
20263
20264 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20265
20266 \end_inset
20267
20268
20269 \family default
20270  at the appropriate location if the default, port P2, is not used for this.
20271  Some examples are:
20272
20273 \layout Verse
20274
20275 \family typewriter
20276 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
20277  MPAGE */
20278
20279 \layout Verse
20280
20281 \family typewriter
20282 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
20283  a.k.a.
20284  MPAGE */
20285
20286 \layout Verse
20287
20288 \family typewriter
20289 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
20290  XPAGE */
20291
20292 \layout Verse
20293
20294 \family typewriter
20295 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20296  EMI0CN */
20297
20298 \layout Verse
20299
20300 \family typewriter
20301 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20302  EMI0CN */
20303
20304 \layout Standard
20305 For more exotic implementations further customizations may be needed.
20306  See section 
20307 \begin_inset LatexCommand \ref{sub:Startup-Code}
20308
20309 \end_inset
20310
20311  for other possibilities.
20312
20313 \layout Subsection
20314 Other Features available by SFR
20315
20316 \layout Standard
20317 \added_space_bottom bigskip 
20318 Some MCS51 variants offer features like Double DPTR
20319 \begin_inset LatexCommand \index{DPTR}
20320
20321 \end_inset
20322
20323 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20324  These are currently not used for the MCS51 port.
20325  If you absolutely need them you can fall back to inline assembly or submit
20326  a patch to SDCC.
20327
20328
20329
20330 \layout Section
20331 DS400 port
20332
20333 \layout Standard
20334 \added_space_bottom bigskip 
20335 The DS80C400
20336 \begin_inset LatexCommand \index{DS80C400}
20337
20338 \end_inset
20339
20340
20341 \begin_inset LatexCommand \index{DS400}
20342
20343 \end_inset
20344
20345  microcontroller has a rich set of peripherals.
20346  In its built-in ROM library it includes functions to access some of the
20347  features, among them is a TCP stack with IP4 and IP6 support.
20348  Library headers (currently in beta status) and other files are provided
20349  at 
20350 \size footnotesize
20351
20352 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20353
20354 \end_inset
20355
20356 .
20357  
20358
20359
20360
20361 \layout Section
20362 The Z80 and gbz80 port
20363
20364 \layout Standard
20365 SDCC can target both the Zilog Z80
20366 \begin_inset LatexCommand \index{Z80}
20367
20368 \end_inset
20369
20370  and the Nintendo Gameboy's Z80-like gbz80
20371 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20372
20373 \end_inset
20374
20375 .
20376  The Z80 port is passed through the same 
20377 \emph on
20378 regressions tests
20379 \begin_inset LatexCommand \index{Regression test}
20380
20381 \end_inset
20382
20383
20384 \emph default
20385  (see section 
20386 \begin_inset LatexCommand \ref{sec:Quality-control}
20387
20388 \end_inset
20389
20390 ) as the MCS51 and DS390 ports, so floating point support, support for long
20391  variables and bitfield support is fine.
20392  See mailing lists and forums about interrupt routines.
20393
20394 \layout Standard
20395 \added_space_bottom bigskip 
20396 As always, the code is the authoritative reference - see z80/ralloc.c and
20397  z80/gen.c.
20398  The stack
20399 \begin_inset LatexCommand \index{Z80!stack}
20400
20401 \end_inset
20402
20403  frame is similar to that generated by the IAR Z80 compiler.
20404  IX is used as the base pointer, HL and IY are used as a temporary registers,
20405  and BC and DE are available for holding variables.
20406  Return values
20407 \begin_inset LatexCommand \index{Z80!return value}
20408
20409 \end_inset
20410
20411  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20412  bytes).
20413  The gbz80 port use the same set of registers for the return values, but
20414  in a different order of significance: E (one byte), DE (two bytes), or
20415  HLDE (four bytes).
20416
20417
20418
20419 \layout Section
20420 The HC08 port
20421
20422 \layout Standard
20423 The port to the Freescale/Motorola HC08
20424 \begin_inset LatexCommand \index{HC08}
20425
20426 \end_inset
20427
20428  family has been added in October 2003, and is still undergoing some basic
20429  development.
20430  The code generator is complete, but the register allocation is still quite
20431  unoptimized.
20432  Some of the SDCC's standard C library functions have embedded non-HC08
20433  inline assembly and so are not yet usable.
20434
20435 \layout Standard
20436 \pagebreak_bottom 
20437 \added_space_bottom bigskip 
20438 The HC08 port passes the regression test suite (see section 
20439 \begin_inset LatexCommand \ref{sec:Quality-control}
20440
20441 \end_inset
20442
20443 ).
20444
20445
20446
20447
20448 \layout Section
20449 The PIC14 port
20450
20451 \layout Standard
20452 The 14bit PIC
20453 \begin_inset LatexCommand \index{PIC14}
20454
20455 \end_inset
20456
20457  port still requires a major effort from the development community.
20458  However it can work for simple code.
20459  It passes its (smaller set of) regression tests
20460 \begin_inset LatexCommand \index{Regression test (PIC14)}
20461
20462 \end_inset
20463
20464  in the directory 
20465 \shape italic
20466 sdcc/src/regression
20467 \shape default
20468 .
20469
20470 \layout Subsection
20471 C code and 14bit PIC code page
20472 \begin_inset LatexCommand \index{code page (pic14)}
20473
20474 \end_inset
20475
20476  and RAM banks
20477 \begin_inset LatexCommand \index{RAM bank (pic14)}
20478
20479 \end_inset
20480
20481
20482
20483 \layout Standard
20484 The linker organizes allocation for the code page and RAM banks.
20485  It does not have intimate knowledge of the code flow.
20486  It will put all the code section of a single asm file into a single code
20487  page.
20488  In order to make use of multiple code pages, separate asm files must be
20489  used.
20490  The compiler treats all functions of a single C file as being in the same
20491  code page unless it is non static.
20492 \newline
20493
20494 \newline
20495 To get the best follow these guide lines:
20496
20497 \layout Enumerate
20498 Make local functions static, as non static functions require code page selection
20499  overhead.
20500
20501 \layout Enumerate
20502 For devices that have multiple code pages it is more efficient to use the
20503  same number of files as pages, i.e.
20504  for the 16F877 use 4 separate files and i.e.
20505  for the 16F874 use 2 separate files.
20506  This way the linker can put the code for each file into different code
20507  pages and there's less page selection overhead.
20508
20509 \layout Enumerate
20510 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20511  instruction set), use 'unsigned char' whereever possible instead of 'int'.
20512
20513 \layout Subsection
20514 Creating a device include file 
20515
20516 \layout Standard
20517 For generating a device include file
20518 \begin_inset LatexCommand \index{PIC14!Header files}
20519
20520 \end_inset
20521
20522  use the support perl script inc2h.pl kept in directory support/script.
20523
20524 \layout Subsection
20525 Interrupt code
20526
20527 \layout Standard
20528 For the interrupt function, use the keyword '__interrupt'
20529 \begin_inset LatexCommand \index{PIC14!interrupt}
20530
20531 \end_inset
20532
20533  with level number of 0 (PIC14 only has 1 interrupt so this number is only
20534  there to avoid a syntax error - it ought to be fixed).
20535  E.g.:
20536
20537 \layout Verse
20538
20539 \family typewriter
20540 void Intr(void) __interrupt 0
20541 \newline
20542 {
20543 \newline
20544 \SpecialChar ~
20545 \SpecialChar ~
20546 T0IF = 0; /* Clear timer interrupt */
20547 \newline
20548 }
20549
20550 \layout Subsection
20551 Linking and assembling
20552
20553 \layout Standard
20554 For assembling you can use either GPUTILS'
20555 \begin_inset LatexCommand \index{gputils (pic tools)}
20556
20557 \end_inset
20558
20559  gpasm.exe or MPLAB's mpasmwin.exe.
20560  GPUTILS is available from 
20561 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
20562
20563 \end_inset
20564
20565 .
20566  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
20567  If you use MPLAB and an interrupt function then the linker script file
20568  vectors section will need to be enlarged to link with mplink.
20569 \newline
20570
20571 \newline
20572 Here is a 
20573 \family typewriter
20574 Makefile
20575 \family default
20576  using GPUTILS:
20577
20578 \layout Verse
20579
20580 \family typewriter
20581 .c.o:
20582 \newline
20583 \SpecialChar ~
20584 \SpecialChar ~
20585 \SpecialChar ~
20586 \SpecialChar ~
20587 \SpecialChar ~
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 sdcc -S -V -mpic14 -p16F877 $< 
20592 \newline
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 gpasm -c $*.asm
20602 \newline
20603
20604 \newline
20605 $(PRJ).hex: $(OBJS) 
20606 \newline
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 \SpecialChar ~
20615 gplink
20616  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
20617
20618 \layout Standard
20619 Here is a 
20620 \family typewriter
20621 Makefile
20622 \family default
20623  using MPLAB:
20624
20625 \layout Verse
20626
20627 \family typewriter
20628 .c.o: 
20629 \newline
20630 \SpecialChar ~
20631 \SpecialChar ~
20632 \SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 sdcc -S -V -mpic14 -p16F877 $< 
20639 \newline
20640 \SpecialChar ~
20641 \SpecialChar ~
20642 \SpecialChar ~
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \SpecialChar ~
20646 \SpecialChar ~
20647 \SpecialChar ~
20648 mpasmwin /q /o $*.asm
20649 \newline
20650
20651 \newline
20652 $(PRJ).hex: $(OBJS)
20653  
20654 \newline
20655 \SpecialChar ~
20656 \SpecialChar ~
20657 \SpecialChar ~
20658 \SpecialChar ~
20659 \SpecialChar ~
20660 \SpecialChar ~
20661 \SpecialChar ~
20662 \SpecialChar ~
20663 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
20664
20665 \layout Standard
20666 Please note that indentations within a
20667 \family typewriter
20668  Makefile
20669 \family default
20670  have to be done with a tabulator character.
20671
20672 \layout Subsection
20673 Command-line options
20674
20675 \layout Standard
20676 Besides the switches common to all SDCC backends, the PIC14 port accepts
20677  the following options (for an updated list see sdcc -
20678 \begin_inset ERT
20679 status Collapsed
20680
20681 \layout Standard
20682
20683
20684 \backslash
20685 /
20686
20687 \end_inset
20688
20689 -help):
20690
20691 \layout List
20692 \labelwidthstring 00.00.0000
20693 -
20694 \begin_inset ERT
20695 status Collapsed
20696
20697 \layout Standard
20698
20699
20700 \backslash
20701 /
20702
20703 \end_inset
20704
20705 -debug-extra
20706 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
20707
20708 \end_inset
20709
20710  emit debug info in assembly output
20711
20712 \layout List
20713 \labelwidthstring 00.00.0000
20714 -
20715 \begin_inset ERT
20716 status Collapsed
20717
20718 \layout Standard
20719
20720
20721 \backslash
20722 /
20723
20724 \end_inset
20725
20726 -no-pcode-opt
20727 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
20728
20729 \end_inset
20730
20731  disable (slightly faulty) optimization on pCode
20732
20733 \layout List
20734 \labelwidthstring 00.00.0000
20735 -
20736 \begin_inset ERT
20737 status Collapsed
20738
20739 \layout Standard
20740
20741
20742 \backslash
20743 /
20744
20745 \end_inset
20746
20747 -stack-loc
20748 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
20749
20750 \end_inset
20751
20752  sets the lowest address of the argument passing stack (defaults to a suitably
20753  large shared databank to reduce BANKSEL overhead)
20754
20755 \layout List
20756 \labelwidthstring 00.00.0000
20757 -
20758 \begin_inset ERT
20759 status Collapsed
20760
20761 \layout Standard
20762
20763
20764 \backslash
20765 /
20766
20767 \end_inset
20768
20769 -stack-size
20770 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
20771
20772 \end_inset
20773
20774  sets the size if the argument passing stack (default: 16, minimum: 4)
20775
20776 \layout Subsection
20777 The library
20778
20779 \layout Subsubsection
20780 error: missing definition for symbol 
20781 \begin_inset Quotes sld
20782 \end_inset
20783
20784 __gptrget1
20785 \begin_inset Quotes srd
20786 \end_inset
20787
20788
20789
20790 \layout Standard
20791 The PIC14 port uses library routines to provide more complex operations
20792  like multiplication, division/modulus and (generic) pointer dereferencing.
20793  In order to add these routines to your project, you must link with PIC14's
20794  
20795 \family typewriter
20796 libsdcc.lib
20797 \family default
20798 .
20799  For single source file projects this is done automatically, more complex
20800  projects must add 
20801 \family typewriter
20802 libsdcc.lib
20803 \family default
20804  to the linker's arguments.
20805  Make sure you also add an include path for the library (using the -I switch
20806  to the linker)!
20807
20808 \layout Subsubsection
20809 Processor mismatch in file 
20810 \begin_inset Quotes sld
20811 \end_inset
20812
20813 XXX
20814 \begin_inset Quotes srd
20815 \end_inset
20816
20817 .
20818
20819 \layout Standard
20820 This warning can usually be ignored due to the very good compatibility amongst
20821  14 bit PIC
20822 \begin_inset LatexCommand \index{PIC14}
20823
20824 \end_inset
20825
20826  devices.
20827
20828 \layout Standard
20829 You might also consider recompiling the library for your specific device
20830  by changing the ARCH=p16f877 (default target) entry in 
20831 \family typewriter
20832 device/lib/pic/Makefile.in
20833 \family default
20834  and 
20835 \family typewriter
20836 device/lib/pic/Makefile
20837 \family default
20838  to reflect your device.
20839  This might even improve performance for smaller devices as unneccesary
20840  BANKSELs migth be removed.
20841
20842 \layout Subsection
20843 Known bugs
20844
20845 \layout Subsubsection
20846 initialized data
20847
20848 \layout Standard
20849 \pagebreak_bottom 
20850 Currently, data can only be initialized if it resides in the source file
20851  together with 
20852 \emph on
20853 main()
20854 \emph default
20855 .
20856  Data in other source files will silently 
20857 \series bold
20858 not
20859 \series default
20860  be initialized.
20861 \family typewriter
20862 \size footnotesize
20863
20864 \begin_inset Marginal
20865 collapsed true
20866
20867 \layout Standard
20868
20869 \series bold
20870 \SpecialChar ~
20871 !
20872
20873 \end_inset
20874
20875
20876 \family default
20877
20878
20879
20880 \layout Section
20881 The PIC16
20882 \begin_inset LatexCommand \index{PIC16}
20883
20884 \end_inset
20885
20886  port
20887
20888 \layout Standard
20889 The PIC16
20890 \begin_inset LatexCommand \index{PIC16}
20891
20892 \end_inset
20893
20894  port is the portion of SDCC that is responsible to produce code for the
20895  Microchip
20896 \begin_inset LatexCommand \index{Microchip}
20897
20898 \end_inset
20899
20900 (TM) microcontrollers with 16 bit core.
20901  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20902  Currently supported devices are:
20903
20904 \layout Standard
20905 \align center
20906 \begin_inset Tabular
20907 <lyxtabular version="3" rows="4" columns="6">
20908 <features>
20909 <column alignment="center" valignment="top" leftline="true" width="0">
20910 <column alignment="center" valignment="top" leftline="true" width="0">
20911 <column alignment="center" valignment="top" leftline="true" width="0">
20912 <column alignment="center" valignment="top" leftline="true" width="0">
20913 <column alignment="center" valignment="top" leftline="true" width="0">
20914 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20915 <row topline="true">
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_inset Text
20918
20919 \layout Standard
20920 18F242
20921
20922 \end_inset
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \layout Standard
20928 18F248
20929
20930 \end_inset
20931 </cell>
20932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20933 \begin_inset Text
20934
20935 \layout Standard
20936 18F252
20937
20938 \end_inset
20939 </cell>
20940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20941 \begin_inset Text
20942
20943 \layout Standard
20944 18F258
20945
20946 \end_inset
20947 </cell>
20948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20949 \begin_inset Text
20950
20951 \layout Standard
20952 18F442
20953
20954 \end_inset
20955 </cell>
20956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20957 \begin_inset Text
20958
20959 \layout Standard
20960 18F448
20961
20962 \end_inset
20963 </cell>
20964 </row>
20965 <row topline="true">
20966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20967 \begin_inset Text
20968
20969 \layout Standard
20970 18F452
20971
20972 \end_inset
20973 </cell>
20974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20975 \begin_inset Text
20976
20977 \layout Standard
20978 18F458
20979
20980 \end_inset
20981 </cell>
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20983 \begin_inset Text
20984
20985 \layout Standard
20986 18F1220
20987
20988 \end_inset
20989 </cell>
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \layout Standard
20994 18F2220
20995
20996 \end_inset
20997 </cell>
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20999 \begin_inset Text
21000
21001 \layout Standard
21002 18F2550
21003
21004 \end_inset
21005 </cell>
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21007 \begin_inset Text
21008
21009 \layout Standard
21010 18F4331
21011
21012 \end_inset
21013 </cell>
21014 </row>
21015 <row topline="true">
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21017 \begin_inset Text
21018
21019 \layout Standard
21020 18F4455
21021
21022 \end_inset
21023 </cell>
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21025 \begin_inset Text
21026
21027 \layout Standard
21028 18F6520
21029
21030 \end_inset
21031 </cell>
21032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21033 \begin_inset Text
21034
21035 \layout Standard
21036 18F6620
21037
21038 \end_inset
21039 </cell>
21040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21041 \begin_inset Text
21042
21043 \layout Standard
21044 18F6680
21045
21046 \end_inset
21047 </cell>
21048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21049 \begin_inset Text
21050
21051 \layout Standard
21052 18F6720
21053
21054 \end_inset
21055 </cell>
21056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21057 \begin_inset Text
21058
21059 \layout Standard
21060 18F8520
21061
21062 \end_inset
21063 </cell>
21064 </row>
21065 <row topline="true" bottomline="true">
21066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21067 \begin_inset Text
21068
21069 \layout Standard
21070 18F8620
21071
21072 \end_inset
21073 </cell>
21074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21075 \begin_inset Text
21076
21077 \layout Standard
21078 18F8680
21079
21080 \end_inset
21081 </cell>
21082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21083 \begin_inset Text
21084
21085 \layout Standard
21086 18F8720
21087
21088 \end_inset
21089 </cell>
21090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21091 \begin_inset Text
21092
21093 \layout Standard
21094
21095
21096 \end_inset
21097 </cell>
21098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21099 \begin_inset Text
21100
21101 \layout Standard
21102
21103
21104 \end_inset
21105 </cell>
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21107 \begin_inset Text
21108
21109 \layout Standard
21110
21111
21112 \end_inset
21113 </cell>
21114 </row>
21115 </lyxtabular>
21116
21117 \end_inset
21118
21119
21120
21121 \layout Subsection
21122 Global Options
21123
21124 \layout Standard
21125 PIC16 port supports the standard command line arguments as supposed, with
21126  the exception of certain cases that will be mentioned in the following
21127  list:
21128
21129 \layout List
21130 \labelwidthstring 00.00.0000
21131 -
21132 \begin_inset ERT
21133 status Collapsed
21134
21135 \layout Standard
21136
21137
21138 \backslash
21139 /
21140
21141 \end_inset
21142
21143 -callee-saves
21144 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21145
21146 \end_inset
21147
21148  See -
21149 \begin_inset ERT
21150 status Collapsed
21151
21152 \layout Standard
21153
21154
21155 \backslash
21156 /
21157
21158 \end_inset
21159
21160 -all-callee-saves
21161
21162 \layout List
21163 \labelwidthstring 00.00.0000
21164 -
21165 \begin_inset ERT
21166 status Collapsed
21167
21168 \layout Standard
21169
21170
21171 \backslash
21172 /
21173
21174 \end_inset
21175
21176 -all-callee-saves
21177 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21178
21179 \end_inset
21180
21181  All function arguments are passed on stack by default.
21182  
21183 \emph on
21184 There is no need to specify this in the command line.
21185
21186 \layout List
21187 \labelwidthstring 00.00.0000
21188 -
21189 \begin_inset ERT
21190 status Collapsed
21191
21192 \layout Standard
21193
21194
21195 \backslash
21196 /
21197
21198 \end_inset
21199
21200 -fommit-frame-pointer
21201 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21202
21203 \end_inset
21204
21205  Frame pointer will be omitted when the function uses no local variables.
21206
21207 \layout Subsection
21208 Port Specific Options
21209 \begin_inset LatexCommand \index{Options PIC16}
21210
21211 \end_inset
21212
21213
21214
21215 \layout Standard
21216 The port specific options appear after the global options in the sdcc --help
21217  output.
21218
21219 \layout Subsubsection
21220 General Options
21221
21222 \layout Standard
21223 General options enable certain port features and optimizations.
21224
21225 \layout List
21226 \labelwidthstring 00.00.0000
21227 -
21228 \begin_inset ERT
21229 status Collapsed
21230
21231 \layout Standard
21232
21233
21234 \backslash
21235 /
21236
21237 \end_inset
21238
21239 -pstack-model=[model] Used in conjuction with the command above.
21240  Defines the stack model to be used, valid stack models are : 
21241
21242 \begin_deeper
21243 \layout List
21244 \labelwidthstring 00.00.0000
21245
21246 \emph on
21247 small
21248 \emph default
21249  Selects small stack model.
21250  8 bit stack and frame pointers.
21251  Supports 256 bytes stack size.
21252
21253 \layout List
21254 \labelwidthstring 00.00.0000
21255
21256 \emph on
21257 large
21258 \emph default
21259  Selects large stack model.
21260  16 bit stack and frame pointers.
21261  Supports 65536 bytes stack size.
21262
21263 \end_deeper
21264 \layout List
21265 \labelwidthstring 00.00.0000
21266 -
21267 \begin_inset ERT
21268 status Collapsed
21269
21270 \layout Standard
21271
21272
21273 \backslash
21274 /
21275
21276 \end_inset
21277
21278 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21279  unitialized data variables with [kword].
21280  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21281
21282 \layout List
21283 \labelwidthstring 00.00.0000
21284 -
21285 \begin_inset ERT
21286 status Collapsed
21287
21288 \layout Standard
21289
21290
21291 \backslash
21292 /
21293
21294 \end_inset
21295
21296 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21297  Useful for bootloaders.
21298
21299 \layout List
21300 \labelwidthstring 00.00.0000
21301 -
21302 \begin_inset ERT
21303 status Collapsed
21304
21305 \layout Standard
21306
21307
21308 \backslash
21309 /
21310
21311 \end_inset
21312
21313 -asm= sets the full path and name of an external assembler to call.
21314
21315 \layout List
21316 \labelwidthstring 00.00.0000
21317 -
21318 \begin_inset ERT
21319 status Collapsed
21320
21321 \layout Standard
21322
21323
21324 \backslash
21325 /
21326
21327 \end_inset
21328
21329 -link= sets the full path and name of an external linker to call.
21330
21331 \layout List
21332 \labelwidthstring 00.00.0000
21333 -
21334 \begin_inset ERT
21335 status Collapsed
21336
21337 \layout Standard
21338
21339
21340 \backslash
21341 /
21342
21343 \end_inset
21344
21345 -mplab-comp MPLAB
21346 \begin_inset LatexCommand \index{PIC16!MPLAB}
21347
21348 \end_inset
21349
21350  compatibility option.
21351  Currently only suppresses special gpasm directives.
21352
21353 \layout Subsubsection
21354 Optimization Options
21355
21356 \layout List
21357 \labelwidthstring 00.00.0000
21358 -
21359 \begin_inset ERT
21360 status Collapsed
21361
21362 \layout Standard
21363
21364
21365 \backslash
21366 /
21367
21368 \end_inset
21369
21370 -optimize-goto Try to use (conditional) BRA instead of GOTO
21371
21372 \layout List
21373 \labelwidthstring 00.00.0000
21374 -
21375 \begin_inset ERT
21376 status Collapsed
21377
21378 \layout Standard
21379
21380
21381 \backslash
21382 /
21383
21384 \end_inset
21385
21386 -optimize-cmp Try to optimize some compares.
21387
21388 \layout List
21389 \labelwidthstring 00.00.0000
21390 -
21391 \begin_inset ERT
21392 status Collapsed
21393
21394 \layout Standard
21395
21396
21397 \backslash
21398 /
21399
21400 \end_inset
21401
21402 -optimize-df Analyze the dataflow of the generated code and improve it.
21403
21404 \layout List
21405 \labelwidthstring 00.00.0000
21406 -
21407 \begin_inset ERT
21408 status Collapsed
21409
21410 \layout Standard
21411
21412
21413 \backslash
21414 /
21415
21416 \end_inset
21417
21418 -obanksel=nn Set optimization level for inserting BANKSELs.
21419 \newline
21420
21421
21422 \begin_deeper
21423 \layout List
21424 \labelwidthstring 00.00.0000
21425 0 no optimization
21426
21427 \layout List
21428 \labelwidthstring 00.00.0000
21429 1 checks previous used register and if it is the same then does not emit
21430  BANKSEL, accounts only for labels.
21431
21432 \layout List
21433 \labelwidthstring 00.00.0000
21434 2 tries to check the location of (even different) symbols and removes BANKSELs
21435  if they are in the same bank.
21436  
21437 \newline
21438
21439 \emph on
21440 Important: There might be problems if the linker script has data sections
21441  across bank borders!
21442
21443 \end_deeper
21444 \layout Subsubsection
21445 Linking Options
21446
21447 \layout List
21448 \labelwidthstring 00.00.0000
21449 -
21450 \begin_inset ERT
21451 status Collapsed
21452
21453 \layout Standard
21454
21455
21456 \backslash
21457 /
21458
21459 \end_inset
21460
21461 -nodefaultlibs do not link default libraries when linking
21462
21463 \layout List
21464 \labelwidthstring 00.00.0000
21465 -
21466 \begin_inset ERT
21467 status Collapsed
21468
21469 \layout Standard
21470
21471
21472 \backslash
21473 /
21474
21475 \end_inset
21476
21477 -no-crt Don't link the default run-time modules
21478
21479 \layout List
21480 \labelwidthstring 00.00.0000
21481 -
21482 \begin_inset ERT
21483 status Collapsed
21484
21485 \layout Standard
21486
21487
21488 \backslash
21489 /
21490
21491 \end_inset
21492
21493 -use-crt= Use a custom run-time module instead of the defaults.
21494
21495 \layout Subsubsection
21496 Debugging Options
21497
21498 \layout Standard
21499 Debugging options enable extra debugging information in the output files.
21500
21501 \layout List
21502 \labelwidthstring 00.00.0000
21503 -
21504 \begin_inset ERT
21505 status Collapsed
21506
21507 \layout Standard
21508
21509
21510 \backslash
21511 /
21512
21513 \end_inset
21514
21515 -debug-xtra Similar to -
21516 \begin_inset ERT
21517 status Collapsed
21518
21519 \layout Standard
21520
21521
21522 \backslash
21523 /
21524
21525 \end_inset
21526
21527 -debug
21528 \begin_inset LatexCommand \index{-\/-debug}
21529
21530 \end_inset
21531
21532 , but dumps more information.
21533
21534 \layout List
21535 \labelwidthstring 00.00.0000
21536 -
21537 \begin_inset ERT
21538 status Collapsed
21539
21540 \layout Standard
21541
21542
21543 \backslash
21544 /
21545
21546 \end_inset
21547
21548 -debug-ralloc Force register allocator to dump <source>.d file with debugging
21549  information.
21550  <source> is the name of the file compiled.
21551
21552 \layout List
21553 \labelwidthstring 00.00.0000
21554 -
21555 \begin_inset ERT
21556 status Collapsed
21557
21558 \layout Standard
21559
21560
21561 \backslash
21562 /
21563
21564 \end_inset
21565
21566 -pcode-verbose Enable pcode debugging information in translation.
21567
21568 \layout List
21569 \labelwidthstring 00.00.0000
21570 -
21571 \begin_inset ERT
21572 status Collapsed
21573
21574 \layout Standard
21575
21576
21577 \backslash
21578 /
21579
21580 \end_inset
21581
21582 -denable-peeps Force the usage of peepholes.
21583  Use with care.
21584
21585 \layout List
21586 \labelwidthstring 00.00.0000
21587 -
21588 \begin_inset ERT
21589 status Collapsed
21590
21591 \layout Standard
21592
21593
21594 \backslash
21595 /
21596
21597 \end_inset
21598
21599 -gstack Trace push/pops for stack pointer overflow
21600
21601 \layout List
21602 \labelwidthstring 00.00.0000
21603 -
21604 \begin_inset ERT
21605 status Collapsed
21606
21607 \layout Standard
21608
21609
21610 \backslash
21611 /
21612
21613 \end_inset
21614
21615 -call-tree dump call tree in .calltree file
21616
21617 \layout Subsection
21618 Enviromental Variables
21619
21620 \layout Standard
21621 There is a number of enviromental variables that can be used when running
21622  SDCC to enable certain optimizations or force a specific program behaviour.
21623  these variables are primarily for debugging purposes so they can be enabled/dis
21624 abled at will.
21625
21626 \layout Standard
21627 Currently there is only two such variables available:
21628
21629 \layout List
21630 \labelwidthstring 00.00.0000
21631 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
21632  bitfields is optimized by directly loading FSR0 with the address of the
21633  bitfield structure.
21634  Normally SDCC will cast the bitfield structure to a bitfield pointer and
21635  then load FSR0.
21636  This step saves data ram and code space for functions that perform heavy
21637  use of bitfields.
21638  (ie.
21639  80 bytes of code space are saved when compiling malloc.c with this option).
21640  
21641
21642 \layout List
21643 \labelwidthstring 00.00.0000
21644 NO_REG_OPT do not perform pCode registers optimization.
21645  This should be used for debugging purposes.
21646  In some where bugs in the pcode optimizer are found, users can benefit
21647  from temporarily disabling the optimizer until the bug is fixed.
21648
21649 \layout Subsection
21650 Preprocessor Macros
21651
21652 \layout Standard
21653 PIC16
21654 \begin_inset LatexCommand \index{PIC16}
21655
21656 \end_inset
21657
21658  port defines the following preprocessor macros while translating a source.
21659
21660 \layout Standard
21661 \align center
21662 \begin_inset Tabular
21663 <lyxtabular version="3" rows="6" columns="2">
21664 <features>
21665 <column alignment="center" valignment="top" leftline="true" width="0">
21666 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21667 <row topline="true" bottomline="true">
21668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21669 \begin_inset Text
21670
21671 \layout Standard
21672 Macro
21673
21674 \end_inset
21675 </cell>
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21677 \begin_inset Text
21678
21679 \layout Standard
21680 Description
21681
21682 \end_inset
21683 </cell>
21684 </row>
21685 <row topline="true">
21686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21687 \begin_inset Text
21688
21689 \layout Standard
21690 SDCC_pic16
21691
21692 \end_inset
21693 </cell>
21694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21695 \begin_inset Text
21696
21697 \layout Standard
21698 Port identification
21699
21700 \end_inset
21701 </cell>
21702 </row>
21703 <row topline="true">
21704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21705 \begin_inset Text
21706
21707 \layout Standard
21708 _
21709 \begin_inset ERT
21710 status Collapsed
21711
21712 \layout Standard
21713
21714
21715 \backslash
21716 /
21717
21718 \end_inset
21719
21720 _pic16
21721
21722 \end_inset
21723 </cell>
21724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21725 \begin_inset Text
21726
21727 \layout Standard
21728 Port identification (same as above)
21729
21730 \end_inset
21731 </cell>
21732 </row>
21733 <row topline="true">
21734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21735 \begin_inset Text
21736
21737 \layout Standard
21738 pic18fxxxx
21739
21740 \end_inset
21741 </cell>
21742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21743 \begin_inset Text
21744
21745 \layout Standard
21746 MCU Identification.
21747  
21748 \emph on
21749 xxxx
21750 \emph default
21751  is the microcontrol identification number, i.e.
21752  452, 6620, etc
21753
21754 \end_inset
21755 </cell>
21756 </row>
21757 <row topline="true">
21758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21759 \begin_inset Text
21760
21761 \layout Standard
21762 _
21763 \begin_inset ERT
21764 status Collapsed
21765
21766 \layout Standard
21767
21768
21769 \backslash
21770 /
21771
21772 \end_inset
21773
21774 _18Fxxxx
21775
21776 \end_inset
21777 </cell>
21778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21779 \begin_inset Text
21780
21781 \layout Standard
21782 MCU Identification (same as above)
21783
21784 \end_inset
21785 </cell>
21786 </row>
21787 <row topline="true" bottomline="true">
21788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21789 \begin_inset Text
21790
21791 \layout Standard
21792 STACK_MODEL_nnn
21793
21794 \end_inset
21795 </cell>
21796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21797 \begin_inset Text
21798
21799 \layout Standard
21800 nnn = SMALL or LARGE respectively according to the stack model used
21801
21802 \end_inset
21803 </cell>
21804 </row>
21805 </lyxtabular>
21806
21807 \end_inset
21808
21809
21810
21811 \layout Standard
21812 In addition the following macros are defined when calling assembler:
21813
21814 \layout Standard
21815 \align center
21816 \begin_inset Tabular
21817 <lyxtabular version="3" rows="4" columns="2">
21818 <features>
21819 <column alignment="center" valignment="top" leftline="true" width="0">
21820 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21821 <row topline="true" bottomline="true">
21822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21823 \begin_inset Text
21824
21825 \layout Standard
21826 Macro
21827
21828 \end_inset
21829 </cell>
21830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21831 \begin_inset Text
21832
21833 \layout Standard
21834 Description
21835
21836 \end_inset
21837 </cell>
21838 </row>
21839 <row topline="true">
21840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21841 \begin_inset Text
21842
21843 \layout Standard
21844 __18Fxxxx
21845
21846 \end_inset
21847 </cell>
21848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21849 \begin_inset Text
21850
21851 \layout Standard
21852 MCU Identification.
21853  
21854 \emph on
21855 xxxx
21856 \emph default
21857  is the microcontrol identification number, i.e.
21858  452, 6620, etc
21859
21860 \end_inset
21861 </cell>
21862 </row>
21863 <row topline="true">
21864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21865 \begin_inset Text
21866
21867 \layout Standard
21868 SDCC_MODEL_nnn
21869
21870 \end_inset
21871 </cell>
21872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21873 \begin_inset Text
21874
21875 \layout Standard
21876 nnn = SMALL or LARGE respectively according to the memory model used for
21877  SDCC
21878
21879 \end_inset
21880 </cell>
21881 </row>
21882 <row topline="true" bottomline="true">
21883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21884 \begin_inset Text
21885
21886 \layout Standard
21887 STACK_MODEL_nnn
21888
21889 \end_inset
21890 </cell>
21891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21892 \begin_inset Text
21893
21894 \layout Standard
21895 nnn = SMALL or LARGE respectively according to the stack model used
21896
21897 \end_inset
21898 </cell>
21899 </row>
21900 </lyxtabular>
21901
21902 \end_inset
21903
21904
21905
21906 \layout Subsection
21907 Directories
21908
21909 \layout Standard
21910 PIC16
21911 \begin_inset LatexCommand \index{PIC16}
21912
21913 \end_inset
21914
21915  port uses the following directories for searching header files and libraries.
21916
21917 \layout Standard
21918 \align center
21919 \begin_inset Tabular
21920 <lyxtabular version="3" rows="3" columns="4">
21921 <features>
21922 <column alignment="center" valignment="top" leftline="true" width="0">
21923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21924 <column alignment="center" valignment="top" width="0">
21925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21926 <row topline="true" bottomline="true">
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21928 \begin_inset Text
21929
21930 \layout Standard
21931 Directory
21932
21933 \end_inset
21934 </cell>
21935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21936 \begin_inset Text
21937
21938 \layout Standard
21939 Description
21940
21941 \end_inset
21942 </cell>
21943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21944 \begin_inset Text
21945
21946 \layout Standard
21947 Target
21948
21949 \end_inset
21950 </cell>
21951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21952 \begin_inset Text
21953
21954 \layout Standard
21955 Command prefix
21956
21957 \end_inset
21958 </cell>
21959 </row>
21960 <row topline="true">
21961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21962 \begin_inset Text
21963
21964 \layout Standard
21965 PREFIX/sdcc/include/pic16
21966
21967 \end_inset
21968 </cell>
21969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21970 \begin_inset Text
21971
21972 \layout Standard
21973 PIC16 specific headers
21974
21975 \end_inset
21976 </cell>
21977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21978 \begin_inset Text
21979
21980 \layout Standard
21981 Compiler
21982
21983 \end_inset
21984 </cell>
21985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21986 \begin_inset Text
21987
21988 \layout Standard
21989 -I
21990
21991 \end_inset
21992 </cell>
21993 </row>
21994 <row topline="true" bottomline="true">
21995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21996 \begin_inset Text
21997
21998 \layout Standard
21999 PREFIX/sdcc/lib/pic16
22000
22001 \end_inset
22002 </cell>
22003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22004 \begin_inset Text
22005
22006 \layout Standard
22007 PIC16 specific libraries
22008
22009 \end_inset
22010 </cell>
22011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22012 \begin_inset Text
22013
22014 \layout Standard
22015 Linker
22016
22017 \end_inset
22018 </cell>
22019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22020 \begin_inset Text
22021
22022 \layout Standard
22023 -L
22024
22025 \end_inset
22026 </cell>
22027 </row>
22028 </lyxtabular>
22029
22030 \end_inset
22031
22032
22033
22034 \layout Subsection
22035 Pragmas
22036 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22037
22038 \end_inset
22039
22040
22041
22042 \layout Standard
22043 PIC16
22044 \begin_inset LatexCommand \index{PIC16}
22045
22046 \end_inset
22047
22048  port currently supports the following pragmas:
22049
22050 \layout List
22051 \labelwidthstring 00.00.0000
22052 stack
22053 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22054
22055 \end_inset
22056
22057  pragma stack
22058 \begin_inset LatexCommand \index{PIC16!stack}
22059
22060 \end_inset
22061
22062  forces the code generator to initialize the stack & frame pointers at a
22063  specific address.
22064  This is an adhoc solution for cases where no STACK directive is available
22065  in the linker script or gplink is not instructed to create a stack section.
22066 \newline
22067 The
22068  stack pragma should be used only once in a project.
22069  Multiple pragmas may result in indeterminate behaviour of the program.
22070 \begin_inset Foot
22071 collapsed false
22072
22073 \layout Standard
22074 The old format (ie.
22075  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22076  cross page boundaries (or even exceed the available data RAM) and crash
22077  the program.
22078  Make sure that stack does not cross page boundaries when using the SMALL
22079  stack model.
22080
22081 \end_inset
22082
22083
22084 \newline
22085 The format is as follows:
22086
22087 \layout LyX-Code
22088 #pragma stack bottom_address [stack_size]
22089
22090 \layout Standard
22091
22092 \emph on
22093 bottom_address
22094 \emph default
22095  is the lower bound of the stack section.
22096  The stack pointer initially will point at address (bottom_address+stack_size-1).
22097
22098 \layout LyX-Code
22099 Example:
22100
22101 \layout LyX-Code
22102
22103
22104 \layout LyX-Code
22105 /* initializes stack of 100 bytes at RAM address 0x200 */
22106
22107 \layout LyX-Code
22108 #pragma stack 0x200 100
22109
22110 \layout Standard
22111 If the stack_size field is omitted then a stack is created with the default
22112  size of 64.
22113  This size might be enough for most programs, but its not enough for operations
22114  with deep function nesting or excessive stack usage.
22115
22116 \layout List
22117 \labelwidthstring 00.00.0000
22118 code
22119 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22120
22121 \end_inset
22122
22123  place a function symbol at static FLASH address
22124
22125 \layout LyX-Code
22126 Example:
22127
22128 \layout LyX-Code
22129
22130
22131 \layout LyX-Code
22132 /* place function test_func at 0x4000 */
22133
22134 \layout LyX-Code
22135 #pragma code test_func 0x4000
22136
22137 \layout LyX-Code
22138
22139
22140 \layout List
22141 \labelwidthstring 00.00.0000
22142 library instructs the linker to use a library module.
22143 \newline
22144 Usage:
22145
22146 \layout LyX-Code
22147 #pragma library module_name
22148
22149 \layout Standard
22150
22151 \emph on
22152 module_name
22153 \emph default
22154  can be any library or object file (including its path).
22155  Note that there are four reserved keywords which have special meaning.
22156  These are:
22157
22158 \layout Standard
22159 \align center
22160 \begin_inset Tabular
22161 <lyxtabular version="3" rows="6" columns="3">
22162 <features>
22163 <column alignment="center" valignment="top" leftline="true" width="0">
22164 <column alignment="block" valignment="top" leftline="true" width="20page%">
22165 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22166 <row topline="true" bottomline="true">
22167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22168 \begin_inset Text
22169
22170 \layout Standard
22171 Keyword
22172
22173 \end_inset
22174 </cell>
22175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22176 \begin_inset Text
22177
22178 \layout Standard
22179 Description
22180
22181 \end_inset
22182 </cell>
22183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22184 \begin_inset Text
22185
22186 \layout Standard
22187 Module to link
22188
22189 \end_inset
22190 </cell>
22191 </row>
22192 <row topline="true">
22193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22194 \begin_inset Text
22195
22196 \layout Standard
22197
22198 \series bold
22199 ignore
22200
22201 \end_inset
22202 </cell>
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22204 \begin_inset Text
22205
22206 \layout Standard
22207 ignore all library pragmas
22208
22209 \end_inset
22210 </cell>
22211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22212 \begin_inset Text
22213
22214 \layout Standard
22215
22216 \emph on
22217 (none)
22218
22219 \end_inset
22220 </cell>
22221 </row>
22222 <row topline="true">
22223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22224 \begin_inset Text
22225
22226 \layout Standard
22227
22228 \series bold
22229 c
22230
22231 \end_inset
22232 </cell>
22233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22234 \begin_inset Text
22235
22236 \layout Standard
22237 link the C library
22238
22239 \end_inset
22240 </cell>
22241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22242 \begin_inset Text
22243
22244 \layout Standard
22245
22246 \emph on
22247 libc18f
22248 \emph default
22249 .lib
22250
22251 \end_inset
22252 </cell>
22253 </row>
22254 <row topline="true">
22255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22256 \begin_inset Text
22257
22258 \layout Standard
22259
22260 \series bold
22261 math
22262
22263 \end_inset
22264 </cell>
22265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22266 \begin_inset Text
22267
22268 \layout Standard
22269 link the Math libarary
22270
22271 \end_inset
22272 </cell>
22273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22274 \begin_inset Text
22275
22276 \layout Standard
22277
22278 \emph on
22279 libm18f
22280 \emph default
22281 .lib
22282
22283 \end_inset
22284 </cell>
22285 </row>
22286 <row topline="true">
22287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22288 \begin_inset Text
22289
22290 \layout Standard
22291
22292 \series bold
22293 io
22294
22295 \end_inset
22296 </cell>
22297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22298 \begin_inset Text
22299
22300 \layout Standard
22301 link the I/O library
22302
22303 \end_inset
22304 </cell>
22305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22306 \begin_inset Text
22307
22308 \layout Standard
22309
22310 \emph on
22311 libio18f*
22312 \emph default
22313 .lib
22314
22315 \end_inset
22316 </cell>
22317 </row>
22318 <row topline="true" bottomline="true">
22319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22320 \begin_inset Text
22321
22322 \layout Standard
22323
22324 \series bold
22325 debug
22326
22327 \end_inset
22328 </cell>
22329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22330 \begin_inset Text
22331
22332 \layout Standard
22333 link the debug library
22334
22335 \end_inset
22336 </cell>
22337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22338 \begin_inset Text
22339
22340 \layout Standard
22341
22342 \emph on
22343 libdebug
22344 \emph default
22345 .lib
22346
22347 \end_inset
22348 </cell>
22349 </row>
22350 </lyxtabular>
22351
22352 \end_inset
22353
22354
22355 \newline
22356 * is the device number, i.e.
22357  452 for PIC18F452 MCU.
22358
22359 \layout Standard
22360 This feature allows for linking with specific libraries withoug having to
22361  explicit name them in the command line.
22362  Note that the 
22363 \noun on
22364 ignore
22365 \noun default
22366  keyword will reject all modules specified by the library pragma.
22367
22368 \layout List
22369 \labelwidthstring 00.00.0000
22370 udata pragma udata instructs the compiler to emit code so that linker will
22371  place a variable at a specific memory bank
22372
22373 \layout LyX-Code
22374 Example:
22375
22376 \layout LyX-Code
22377
22378
22379 \layout LyX-Code
22380 /* places variable foo at bank2 */
22381
22382 \layout LyX-Code
22383 #pragma udata bank2 foo
22384
22385 \layout LyX-Code
22386 char foo;
22387
22388 \layout Standard
22389 In order for this pragma to work extra SECTION directives should be added
22390  in the .lkr script.
22391  In the following example a sample .lkr file is shown:
22392
22393 \layout LyX-Code
22394
22395
22396 \layout LyX-Code
22397 // Sample linker script for the PIC18F452 processor
22398
22399 \layout LyX-Code
22400 LIBPATH .
22401
22402 \layout LyX-Code
22403 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
22404
22405 \layout LyX-Code
22406 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
22407
22408 \layout LyX-Code
22409 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
22410
22411 \layout LyX-Code
22412 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
22413
22414 \layout LyX-Code
22415 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
22416
22417 \layout LyX-Code
22418 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
22419
22420 \layout LyX-Code
22421 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
22422
22423 \layout LyX-Code
22424
22425
22426 \layout LyX-Code
22427 DATABANK   NAME=gpr0       START=0x80           END=0xFF
22428
22429 \layout LyX-Code
22430 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
22431
22432 \layout LyX-Code
22433 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
22434
22435 \layout LyX-Code
22436 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
22437
22438 \layout LyX-Code
22439 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
22440
22441 \layout LyX-Code
22442 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
22443
22444 \layout LyX-Code
22445 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
22446
22447 \layout LyX-Code
22448
22449
22450 \layout LyX-Code
22451 SECTION    NAME=CONFIG     ROM=config
22452
22453 \layout LyX-Code
22454
22455
22456 \layout LyX-Code
22457 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
22458
22459 \layout LyX-Code
22460 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
22461
22462 \layout LyX-Code
22463 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
22464
22465 \layout LyX-Code
22466 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
22467
22468 \layout LyX-Code
22469 SECTION    NAME=bank4      RAM=gpr4
22470
22471 \layout LyX-Code
22472 SECTION    NAME=bank5      RAM=gpr5
22473
22474 \layout Standard
22475 The linker will recognise the section name set in the pragma statement and
22476  will position the variable at the memory bank set with the RAM field at
22477  the SECTION line in the linker script file.
22478
22479 \layout Subsection
22480 Header Files
22481 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
22482
22483 \end_inset
22484
22485
22486
22487 \layout Standard
22488 There is one main header file
22489 \begin_inset LatexCommand \index{PIC16!Header files}
22490
22491 \end_inset
22492
22493  that can be included to the source files using the pic16
22494 \begin_inset LatexCommand \index{PIC16}
22495
22496 \end_inset
22497
22498  port.
22499  That file is the 
22500 \series bold
22501 pic18fregs.h
22502 \series default
22503 .
22504  This header file contains the definitions for the processor special registers,
22505  so it is necessary if the source accesses them.
22506  It can be included by adding the following line in the beginning of the
22507  file:
22508
22509 \layout LyX-Code
22510 #include <pic18fregs.h>
22511
22512 \layout Standard
22513 The specific microcontroller is selected within the pic18fregs.h automatically,
22514  so the same source can be used with a variety of devices.
22515
22516 \layout Subsection
22517 Libraries
22518
22519 \layout Standard
22520 The libraries
22521 \begin_inset LatexCommand \index{PIC16!Libraries}
22522
22523 \end_inset
22524
22525  that PIC16
22526 \begin_inset LatexCommand \index{PIC16}
22527
22528 \end_inset
22529
22530  port depends on are the microcontroller device libraries which contain
22531  the symbol definitions for the microcontroller special function registers.
22532  These libraries have the format pic18fxxxx.lib, where 
22533 \emph on
22534 xxxx
22535 \emph default
22536  is the microcontroller identification number.
22537  The specific library is selected automatically by the compiler at link
22538  stage according to the selected device.
22539
22540 \layout Standard
22541 Libraries are created with gplib which is part of the gputils package 
22542 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22543
22544 \end_inset
22545
22546 .
22547
22548 \layout Subsubsection*
22549 Building the libraries
22550
22551 \layout Standard
22552 Before using SDCC/pic16 there are some libraries that need to be compiled.
22553  This process is not done automatically by SDCC since not all users use
22554  SDCC for pic16 projects.
22555  So each user should compile the libraries separately.
22556
22557 \layout Standard
22558 The steps to compile the pic16 libraries under Linux are:
22559
22560 \layout LyX-Code
22561 cd device/lib/pic16
22562
22563 \layout LyX-Code
22564 ./configure
22565
22566 \layout LyX-Code
22567 make
22568
22569 \layout LyX-Code
22570 cd ..
22571
22572 \layout LyX-Code
22573 make model-pic16
22574
22575 \layout LyX-Code
22576 su -c 'make install'     # install the libraries, you need the root password
22577
22578 \layout Standard
22579 If you need to install the headers too, do:
22580
22581 \layout LyX-Code
22582 cd device/include
22583
22584 \layout LyX-Code
22585 su -c 'make install'     # install the headers, you need the root password
22586
22587 \layout Standard
22588 There exist a special target to build the I/O libraries.
22589  This target is not automatically build because it will build the I/O library
22590  for 
22591 \emph on
22592 every
22593 \emph default
22594  supported device.
22595  This way building will take quite a lot of time.
22596  Users are advised to edit the 
22597 \series bold
22598 device/lib/pic16/pics.build
22599 \series default
22600  file and then execute:
22601
22602 \layout LyX-Code
22603 make lib-io
22604
22605 \layout Subsection
22606 Memory Models
22607
22608 \layout Standard
22609 The following memory models are supported by the PIC16 port:
22610
22611 \layout Itemize
22612 small model
22613
22614 \layout Itemize
22615 large model
22616
22617 \layout Standard
22618 Memory model affects the default size of pointers within the source.
22619  The sizes are shown in the next table:
22620
22621 \layout Standard
22622 \align center
22623 \begin_inset Tabular
22624 <lyxtabular version="3" rows="3" columns="3">
22625 <features>
22626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22627 <column alignment="center" valignment="top" leftline="true" width="0">
22628 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22629 <row topline="true" bottomline="true">
22630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22631 \begin_inset Text
22632
22633 \layout Standard
22634 Pointer sizes according to memory model
22635
22636 \end_inset
22637 </cell>
22638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22639 \begin_inset Text
22640
22641 \layout Standard
22642 small model
22643
22644 \end_inset
22645 </cell>
22646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22647 \begin_inset Text
22648
22649 \layout Standard
22650 large model
22651
22652 \end_inset
22653 </cell>
22654 </row>
22655 <row topline="true" bottomline="true">
22656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22657 \begin_inset Text
22658
22659 \layout Standard
22660 code pointers
22661
22662 \end_inset
22663 </cell>
22664 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22665 \begin_inset Text
22666
22667 \layout Standard
22668 16-bits
22669
22670 \end_inset
22671 </cell>
22672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22673 \begin_inset Text
22674
22675 \layout Standard
22676 24-bits
22677
22678 \end_inset
22679 </cell>
22680 </row>
22681 <row topline="true" bottomline="true">
22682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22683 \begin_inset Text
22684
22685 \layout Standard
22686 data pointers
22687
22688 \end_inset
22689 </cell>
22690 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
22691 \begin_inset Text
22692
22693 \layout Standard
22694 16-bits
22695
22696 \end_inset
22697 </cell>
22698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22699 \begin_inset Text
22700
22701 \layout Standard
22702 16-bits
22703
22704 \end_inset
22705 </cell>
22706 </row>
22707 </lyxtabular>
22708
22709 \end_inset
22710
22711
22712
22713 \layout Standard
22714 It is advisable that all sources within a project are compiled with the
22715  same memory model.
22716  If one wants to override the default memory model, this can be done by
22717  declaring a pointer as 
22718 \series bold
22719 far
22720 \series default
22721  or 
22722 \series bold
22723 near
22724 \series default
22725 .
22726  Far selects large memory model's pointers, while near selects small memory
22727  model's pointers.
22728
22729 \layout Standard
22730 The standard device libraries (see 
22731 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
22732
22733 \end_inset
22734
22735 ) contain no reference to pointers, so they can be used with both memory
22736  models.
22737
22738 \layout Subsection
22739 Stack
22740
22741 \layout Standard
22742 The stack
22743 \begin_inset LatexCommand \index{PIC16!stack}
22744
22745 \end_inset
22746
22747  implementation for the PIC16 port uses two indirect registers, FSR1 and
22748  FSR2.
22749
22750 \layout List
22751 \labelwidthstring 00.00.0000
22752 FSR1 is assigned as stack pointer
22753
22754 \layout List
22755 \labelwidthstring 00.00.0000
22756 FSR2 is assigned as frame pointer
22757
22758 \layout Standard
22759 The following stack models are supported by the PIC16 port
22760
22761 \layout Itemize
22762
22763 \noun on
22764 small
22765 \noun default
22766  model
22767
22768 \layout Itemize
22769
22770 \noun on
22771 large
22772 \noun default
22773  model
22774
22775 \layout Standard
22776
22777 \noun on
22778 Small
22779 \noun default
22780  model means that only the FSRxL byte is used to access stack and frame,
22781  while 
22782 \emph on
22783 \noun on
22784 large
22785 \emph default
22786 \noun default
22787  uses both FSRxL and FSRxH registers.
22788  The following table shows the stack/frame pointers sizes according to stack
22789  model and the maximum space they can address:
22790
22791 \layout Standard
22792 \align center
22793 \begin_inset Tabular
22794 <lyxtabular version="3" rows="3" columns="3">
22795 <features>
22796 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22797 <column alignment="center" valignment="top" leftline="true" width="0">
22798 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22799 <row topline="true" bottomline="true">
22800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22801 \begin_inset Text
22802
22803 \layout Standard
22804 Stack & Frame pointer sizes according to stack model
22805
22806 \end_inset
22807 </cell>
22808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22809 \begin_inset Text
22810
22811 \layout Standard
22812 small
22813
22814 \end_inset
22815 </cell>
22816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22817 \begin_inset Text
22818
22819 \layout Standard
22820 large
22821
22822 \end_inset
22823 </cell>
22824 </row>
22825 <row topline="true">
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22827 \begin_inset Text
22828
22829 \layout Standard
22830 Stack pointer FSR1
22831
22832 \end_inset
22833 </cell>
22834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22835 \begin_inset Text
22836
22837 \layout Standard
22838 8-bits
22839
22840 \end_inset
22841 </cell>
22842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22843 \begin_inset Text
22844
22845 \layout Standard
22846 16-bits
22847
22848 \end_inset
22849 </cell>
22850 </row>
22851 <row topline="true" bottomline="true">
22852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22853 \begin_inset Text
22854
22855 \layout Standard
22856 Frame pointer FSR2
22857
22858 \end_inset
22859 </cell>
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22861 \begin_inset Text
22862
22863 \layout Standard
22864 8-bits
22865
22866 \end_inset
22867 </cell>
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22869 \begin_inset Text
22870
22871 \layout Standard
22872 16-bits
22873
22874 \end_inset
22875 </cell>
22876 </row>
22877 </lyxtabular>
22878
22879 \end_inset
22880
22881
22882
22883 \layout Standard
22884
22885 \noun on
22886 Large 
22887 \noun default
22888 stack model is currently not working properly throughout the code generator.
22889  So its use is not advised.
22890  Also there are some other points that need special care:
22891 \newline
22892
22893
22894 \layout Enumerate
22895 Do not create stack sections with size more than one physical bank (that
22896  is 256 bytes)
22897
22898 \layout Enumerate
22899 Stack sections should no cross physical bank limits (i.e.
22900  #pragma stack 0x50 0x100)
22901
22902 \layout Standard
22903 These limitations are caused by the fact that only FSRxL is modified when
22904  using SMALL stack model, so no more than 256 bytes of stack can be used.
22905  This problem will disappear after LARGE model is fully implemented.
22906
22907 \layout Subsection
22908 Functions
22909
22910 \layout Standard
22911 In addition to the standard SDCC function keywords, PIC16
22912 \begin_inset LatexCommand \index{PIC16}
22913
22914 \end_inset
22915
22916  port makes available two more:
22917
22918 \layout List
22919 \labelwidthstring 00.00.0000
22920 wparam
22921 \begin_inset LatexCommand \index{PIC16!wparam}
22922
22923 \end_inset
22924
22925  Use the WREG to pass one byte of the first function argument.
22926  This improves speed but you may not use this for functions with arguments
22927  that are called via function pointers, otherwise the first byte of the
22928  first parameter will get lost.
22929  Usage:
22930
22931 \layout LyX-Code
22932 void func_wparam(int a) wparam
22933
22934 \layout LyX-Code
22935 {
22936
22937 \layout LyX-Code
22938     /* WREG hold the lower part of a */
22939
22940 \layout LyX-Code
22941     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22942  */
22943
22944 \layout LyX-Code
22945 ...
22946
22947 \layout LyX-Code
22948 }
22949
22950 \layout List
22951 \labelwidthstring 00.00.0000
22952 shadowregs
22953 \begin_inset LatexCommand \index{PIC16!shadowregs}
22954
22955 \end_inset
22956
22957  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22958  hardware shadow registers which hold the values of WREG, STATUS and BSR
22959  registers.
22960  This can be done by adding the keyword 
22961 \emph on
22962 shadowregs
22963 \emph default
22964  before the 
22965 \emph on
22966 interrupt
22967 \emph default
22968  keyword in the function's header.
22969
22970 \layout LyX-Code
22971 void isr_shadow(void) shadowregs interrupt 1
22972
22973 \layout LyX-Code
22974 {
22975
22976 \layout LyX-Code
22977 ...
22978
22979 \layout LyX-Code
22980 }
22981
22982 \layout Standard
22983
22984 \emph on
22985 shadowregs
22986 \emph default
22987  instructs the code generator not to store/restore WREG, STATUS, BSR when
22988  entering/exiting the ISR.
22989
22990 \layout Subsection
22991 Function return values
22992
22993 \layout Standard
22994 Return values from functions are placed to the appropriate registers following
22995  a modified Microchip policy optimized for SDCC.
22996  The following table shows these registers:
22997
22998 \layout Standard
22999 \align center
23000 \begin_inset Tabular
23001 <lyxtabular version="3" rows="6" columns="2">
23002 <features>
23003 <column alignment="center" valignment="top" leftline="true" width="0">
23004 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23005 <row topline="true" bottomline="true">
23006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23007 \begin_inset Text
23008
23009 \layout Standard
23010 size
23011
23012 \end_inset
23013 </cell>
23014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23015 \begin_inset Text
23016
23017 \layout Standard
23018 destination register
23019
23020 \end_inset
23021 </cell>
23022 </row>
23023 <row topline="true">
23024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23025 \begin_inset Text
23026
23027 \layout Standard
23028 8 bits
23029
23030 \end_inset
23031 </cell>
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23033 \begin_inset Text
23034
23035 \layout Standard
23036 WREG
23037
23038 \end_inset
23039 </cell>
23040 </row>
23041 <row topline="true">
23042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23043 \begin_inset Text
23044
23045 \layout Standard
23046 16 bits
23047
23048 \end_inset
23049 </cell>
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23051 \begin_inset Text
23052
23053 \layout Standard
23054 PRODL:WREG
23055
23056 \end_inset
23057 </cell>
23058 </row>
23059 <row topline="true">
23060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23061 \begin_inset Text
23062
23063 \layout Standard
23064 24 bits
23065
23066 \end_inset
23067 </cell>
23068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23069 \begin_inset Text
23070
23071 \layout Standard
23072 PRODH:PRODL:WREG
23073
23074 \end_inset
23075 </cell>
23076 </row>
23077 <row topline="true">
23078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23079 \begin_inset Text
23080
23081 \layout Standard
23082 32 bits
23083
23084 \end_inset
23085 </cell>
23086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23087 \begin_inset Text
23088
23089 \layout Standard
23090 FSR0L:PRODH:PRODL:WREG
23091
23092 \end_inset
23093 </cell>
23094 </row>
23095 <row topline="true" bottomline="true">
23096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23097 \begin_inset Text
23098
23099 \layout Standard
23100 >32 bits
23101
23102 \end_inset
23103 </cell>
23104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23105 \begin_inset Text
23106
23107 \layout Standard
23108 on stack, FSR0 points to the beginning
23109
23110 \end_inset
23111 </cell>
23112 </row>
23113 </lyxtabular>
23114
23115 \end_inset
23116
23117
23118
23119 \layout Subsection
23120 Interrupts
23121
23122 \layout Standard
23123 An interrupt
23124 \begin_inset LatexCommand \index{PIC16!interrupt}
23125
23126 \end_inset
23127
23128  service routine (ISR) is declared using the 
23129 \emph on
23130 interrupt
23131 \emph default
23132  keyword.
23133
23134 \layout LyX-Code
23135 void isr(void) interrupt 
23136 \emph on
23137 n
23138
23139 \layout LyX-Code
23140 {
23141
23142 \layout LyX-Code
23143 ...
23144
23145 \layout LyX-Code
23146 }
23147
23148 \layout Standard
23149
23150 \emph on
23151 n
23152 \emph default
23153  is the interrupt number, which for PIC18F devices can be:
23154
23155 \layout Standard
23156 \align center
23157 \begin_inset Tabular
23158 <lyxtabular version="3" rows="4" columns="3">
23159 <features>
23160 <column alignment="center" valignment="top" leftline="true" width="0">
23161 <column alignment="center" valignment="top" leftline="true" width="0">
23162 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23163 <row topline="true" bottomline="true">
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23165 \begin_inset Text
23166
23167 \layout Standard
23168
23169 \emph on
23170 n
23171
23172 \end_inset
23173 </cell>
23174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23175 \begin_inset Text
23176
23177 \layout Standard
23178 Interrupt Vector
23179
23180 \end_inset
23181 </cell>
23182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23183 \begin_inset Text
23184
23185 \layout Standard
23186 Interrupt Vector Address
23187
23188 \end_inset
23189 </cell>
23190 </row>
23191 <row topline="true">
23192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23193 \begin_inset Text
23194
23195 \layout Standard
23196 0
23197
23198 \end_inset
23199 </cell>
23200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23201 \begin_inset Text
23202
23203 \layout Standard
23204 RESET vector
23205
23206 \end_inset
23207 </cell>
23208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23209 \begin_inset Text
23210
23211 \layout Standard
23212 0x000000
23213
23214 \end_inset
23215 </cell>
23216 </row>
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23219 \begin_inset Text
23220
23221 \layout Standard
23222
23223 \family roman
23224 \series medium
23225 \shape up
23226 \size normal
23227 \emph off
23228 \bar no
23229 \noun off
23230 \color none
23231 1
23232
23233 \end_inset
23234 </cell>
23235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23236 \begin_inset Text
23237
23238 \layout Standard
23239
23240 \family roman
23241 \series medium
23242 \shape up
23243 \size normal
23244 \emph off
23245 \bar no
23246 \noun off
23247 \color none
23248 HIGH priority interrupts
23249
23250 \end_inset
23251 </cell>
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23253 \begin_inset Text
23254
23255 \layout Standard
23256 0x000008
23257
23258 \end_inset
23259 </cell>
23260 </row>
23261 <row topline="true" bottomline="true">
23262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23263 \begin_inset Text
23264
23265 \layout Standard
23266 2
23267
23268 \end_inset
23269 </cell>
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23271 \begin_inset Text
23272
23273 \layout Standard
23274 LOW priority interrupts
23275
23276 \end_inset
23277 </cell>
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23279 \begin_inset Text
23280
23281 \layout Standard
23282 0x000018
23283
23284 \end_inset
23285 </cell>
23286 </row>
23287 </lyxtabular>
23288
23289 \end_inset
23290
23291
23292
23293 \layout Standard
23294 When generating assembly code for ISR the code generator places a 
23295 \noun on
23296 goto 
23297 \noun default
23298 instruction at the 
23299 \emph on
23300 Interrupt Vector Address
23301 \emph default
23302  which points at the genetated ISR.
23303  This single GOTO instruction is part of an automatically generated 
23304 \emph on
23305 interrupt entry point
23306 \emph default
23307  function.
23308  The actuall ISR code is placed as normally would in the code space.
23309  Upon interrupt request, the GOTO instruction is executed which jumps to
23310  the ISR code.
23311  When declaring interrupt functions as _naked this GOTO instruction is 
23312 \series bold
23313 not
23314 \series default
23315  generated.
23316  The whole interrupt functions is therefore placed at the Interrupt Vector
23317  Address of the specific interrupt.
23318  This is not a problem for the LOW priority interrupts, but it is a problem
23319  for the RESET and the HIGH priority interrupts because code may be written
23320  at the next interrupt´s vector address and cause undeterminate program
23321  behaviour if that interrupt is raised.
23322 \begin_inset Foot
23323 collapsed false
23324
23325 \layout Standard
23326 This is not a problem when
23327
23328 \layout Enumerate
23329 this is a HIGH interrupt ISR and LOW interrupts are 
23330 \emph on
23331 disabled
23332 \emph default
23333  or not used.
23334
23335 \layout Enumerate
23336 when the ISR is small enough not to reach the next interrupt´s vector address.
23337
23338 \end_inset
23339
23340
23341
23342 \layout Standard
23343
23344 \emph on
23345 n
23346 \emph default
23347  is possible to be omitted.
23348  This way a function is generated similar to an ISR, but it is not assigned
23349  to any interrupt.
23350
23351 \layout Standard
23352 When entering an interrupt, currently the PIC16
23353 \begin_inset LatexCommand \index{PIC16}
23354
23355 \end_inset
23356
23357  port automatically saves the following registers:
23358
23359 \layout Itemize
23360 WREG
23361
23362 \layout Itemize
23363 STATUS
23364
23365 \layout Itemize
23366 BSR
23367
23368 \layout Itemize
23369 PROD (PRODL and PRODH)
23370
23371 \layout Itemize
23372 FSR0 (FSR0L and FSR0H)
23373
23374 \layout Standard
23375 These registers are restored upon return from the interrupt routine.
23376 \begin_inset Foot
23377 collapsed false
23378
23379 \layout Standard
23380 NOTE that when the _naked attribute is specified for an interrupt routine,
23381  then NO registers are stored or restored.
23382
23383 \end_inset
23384
23385
23386
23387 \layout Subsection
23388 Generic Pointers
23389
23390 \layout Standard
23391 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
23392  There are 3 types of generic pointers currently implemented data, code
23393  and eeprom pointers.
23394  They are differentiated by the value of the 7th and 6th bits of the upper
23395  byte:
23396
23397 \layout Standard
23398 \align center
23399 \begin_inset Tabular
23400 <lyxtabular version="3" rows="5" columns="5">
23401 <features>
23402 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23403 <column alignment="center" valignment="top" width="0">
23404 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23405 <column alignment="center" valignment="top" width="0">
23406 <column alignment="left" valignment="top" rightline="true" width="0">
23407 <row topline="true" bottomline="true">
23408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23409 \begin_inset Text
23410
23411 \layout Standard
23412 pointer type
23413
23414 \end_inset
23415 </cell>
23416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23417 \begin_inset Text
23418
23419 \layout Standard
23420 7th bit
23421
23422 \end_inset
23423 </cell>
23424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23425 \begin_inset Text
23426
23427 \layout Standard
23428 6th bit
23429
23430 \end_inset
23431 </cell>
23432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23433 \begin_inset Text
23434
23435 \layout Standard
23436 rest of the pointer
23437
23438 \end_inset
23439 </cell>
23440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23441 \begin_inset Text
23442
23443 \layout Standard
23444 description
23445
23446 \end_inset
23447 </cell>
23448 </row>
23449 <row topline="true" bottomline="true">
23450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23451 \begin_inset Text
23452
23453 \layout Standard
23454 data 
23455
23456 \end_inset
23457 </cell>
23458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23459 \begin_inset Text
23460
23461 \layout Standard
23462 1
23463
23464 \end_inset
23465 </cell>
23466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23467 \begin_inset Text
23468
23469 \layout Standard
23470 0
23471
23472 \end_inset
23473 </cell>
23474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23475 \begin_inset Text
23476
23477 \layout Standard
23478
23479 \family typewriter
23480 \shape slanted
23481 \emph on
23482 uuuuuu uuuuxxxx xxxxxxxx
23483
23484 \end_inset
23485 </cell>
23486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23487 \begin_inset Text
23488
23489 \layout Standard
23490 a 12-bit data pointer in data RAM memory
23491
23492 \end_inset
23493 </cell>
23494 </row>
23495 <row bottomline="true">
23496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23497 \begin_inset Text
23498
23499 \layout Standard
23500 code
23501
23502 \end_inset
23503 </cell>
23504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23505 \begin_inset Text
23506
23507 \layout Standard
23508 0
23509
23510 \end_inset
23511 </cell>
23512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23513 \begin_inset Text
23514
23515 \layout Standard
23516 0
23517
23518 \end_inset
23519 </cell>
23520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23521 \begin_inset Text
23522
23523 \layout Standard
23524
23525 \family typewriter
23526 \shape slanted
23527 \emph on
23528 uxxxxx xxxxxxxx xxxxxxxx
23529
23530 \end_inset
23531 </cell>
23532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23533 \begin_inset Text
23534
23535 \layout Standard
23536 a 21-bit code pointer in FLASH memory
23537
23538 \end_inset
23539 </cell>
23540 </row>
23541 <row bottomline="true">
23542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23543 \begin_inset Text
23544
23545 \layout Standard
23546 eeprom
23547
23548 \end_inset
23549 </cell>
23550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23551 \begin_inset Text
23552
23553 \layout Standard
23554 0
23555
23556 \end_inset
23557 </cell>
23558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23559 \begin_inset Text
23560
23561 \layout Standard
23562 1
23563
23564 \end_inset
23565 </cell>
23566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23567 \begin_inset Text
23568
23569 \layout Standard
23570
23571 \family typewriter
23572 \shape slanted
23573 \emph on
23574 uuuuuu uuuuuuxx xxxxxxxx
23575
23576 \end_inset
23577 </cell>
23578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23579 \begin_inset Text
23580
23581 \layout Standard
23582 a 10-bit eeprom pointer in EEPROM memory
23583
23584 \end_inset
23585 </cell>
23586 </row>
23587 <row bottomline="true">
23588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23589 \begin_inset Text
23590
23591 \layout Standard
23592 (unimplemented)
23593
23594 \end_inset
23595 </cell>
23596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23597 \begin_inset Text
23598
23599 \layout Standard
23600 1
23601
23602 \end_inset
23603 </cell>
23604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23605 \begin_inset Text
23606
23607 \layout Standard
23608 1
23609
23610 \end_inset
23611 </cell>
23612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23613 \begin_inset Text
23614
23615 \layout Standard
23616
23617 \family typewriter
23618 \shape slanted
23619 \emph on
23620 xxxxxx xxxxxxxx xxxxxxxx
23621
23622 \end_inset
23623 </cell>
23624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23625 \begin_inset Text
23626
23627 \layout Standard
23628 unimplemented pointer type
23629
23630 \end_inset
23631 </cell>
23632 </row>
23633 </lyxtabular>
23634
23635 \end_inset
23636
23637
23638
23639 \layout Standard
23640 Generic pointer are read and written with a set of library functions which
23641  read/write 1, 2, 3, 4 bytes.
23642
23643 \layout Subsection
23644 PIC16 C Libraries
23645
23646 \layout Subsubsection
23647 Standard I/O Streams
23648
23649 \layout Standard
23650 In the 
23651 \emph on
23652 stdio.h
23653 \emph default
23654  the type FILE is defined as:
23655
23656 \layout LyX-Code
23657 typedef char * FILE;
23658
23659 \layout Standard
23660 This type is the stream type implemented I/O in the PIC18F devices.
23661  Also the standard input and output streams are declared in stdio.h:
23662
23663 \layout LyX-Code
23664 extern FILE * stdin;
23665
23666 \layout LyX-Code
23667 extern FILE * stdout;
23668
23669 \layout Standard
23670 The FILE type is actually a generic pointer which defines one more type
23671  of generic pointers, the 
23672 \emph on
23673 stream 
23674 \emph default
23675 pointer.
23676  This new type has the format:
23677
23678 \layout Standard
23679 \align center
23680 \begin_inset Tabular
23681 <lyxtabular version="3" rows="2" columns="7">
23682 <features>
23683 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23684 <column alignment="center" valignment="top" width="0">
23685 <column alignment="center" valignment="top" leftline="true" width="0">
23686 <column alignment="center" valignment="top" leftline="true" width="0">
23687 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23688 <column alignment="center" valignment="top" width="0">
23689 <column alignment="left" valignment="top" rightline="true" width="0">
23690 <row topline="true" bottomline="true">
23691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23692 \begin_inset Text
23693
23694 \layout Standard
23695 pointer type
23696
23697 \end_inset
23698 </cell>
23699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23700 \begin_inset Text
23701
23702 \layout Standard
23703 <7:6>
23704
23705 \end_inset
23706 </cell>
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23708 \begin_inset Text
23709
23710 \layout Standard
23711 <5>
23712
23713 \end_inset
23714 </cell>
23715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23716 \begin_inset Text
23717
23718 \layout Standard
23719 <4>
23720
23721 \end_inset
23722 </cell>
23723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23724 \begin_inset Text
23725
23726 \layout Standard
23727 <3:0>
23728
23729 \end_inset
23730 </cell>
23731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23732 \begin_inset Text
23733
23734 \layout Standard
23735 rest of the pointer
23736
23737 \end_inset
23738 </cell>
23739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23740 \begin_inset Text
23741
23742 \layout Standard
23743 descrption
23744
23745 \end_inset
23746 </cell>
23747 </row>
23748 <row topline="true" bottomline="true">
23749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23750 \begin_inset Text
23751
23752 \layout Standard
23753 stream
23754
23755 \end_inset
23756 </cell>
23757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23758 \begin_inset Text
23759
23760 \layout Standard
23761 00
23762
23763 \end_inset
23764 </cell>
23765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23766 \begin_inset Text
23767
23768 \layout Standard
23769 1
23770
23771 \end_inset
23772 </cell>
23773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23774 \begin_inset Text
23775
23776 \layout Standard
23777 0
23778
23779 \end_inset
23780 </cell>
23781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23782 \begin_inset Text
23783
23784 \layout Standard
23785 nnnn
23786
23787 \end_inset
23788 </cell>
23789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23790 \begin_inset Text
23791
23792 \layout Standard
23793
23794 \family typewriter
23795 \shape slanted
23796 \emph on
23797 uuuuuuuu uuuuuuuu
23798
23799 \end_inset
23800 </cell>
23801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23802 \begin_inset Text
23803
23804 \layout Standard
23805 upper byte high nubble is 0x2n, the rest are zeroes
23806
23807 \end_inset
23808 </cell>
23809 </row>
23810 </lyxtabular>
23811
23812 \end_inset
23813
23814
23815
23816 \layout Standard
23817 Currently implemented there are 3 types of streams defined:
23818
23819 \layout Standard
23820 \align center
23821 \begin_inset Tabular
23822 <lyxtabular version="3" rows="4" columns="4">
23823 <features>
23824 <column alignment="center" valignment="top" leftline="true" width="0">
23825 <column alignment="center" valignment="top" leftline="true" width="0">
23826 <column alignment="center" valignment="top" leftline="true" width="0">
23827 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23828 <row topline="true" bottomline="true">
23829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23830 \begin_inset Text
23831
23832 \layout Standard
23833 stream type
23834
23835 \end_inset
23836 </cell>
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23838 \begin_inset Text
23839
23840 \layout Standard
23841 value
23842
23843 \end_inset
23844 </cell>
23845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23846 \begin_inset Text
23847
23848 \layout Standard
23849 module
23850
23851 \end_inset
23852 </cell>
23853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23854 \begin_inset Text
23855
23856 \layout Standard
23857 description
23858
23859 \end_inset
23860 </cell>
23861 </row>
23862 <row topline="true">
23863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23864 \begin_inset Text
23865
23866 \layout Standard
23867 STREAM_USART
23868
23869 \end_inset
23870 </cell>
23871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23872 \begin_inset Text
23873
23874 \layout Standard
23875
23876 \family typewriter
23877 0x200000UL
23878
23879 \end_inset
23880 </cell>
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23882 \begin_inset Text
23883
23884 \layout Standard
23885 USART
23886
23887 \end_inset
23888 </cell>
23889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23890 \begin_inset Text
23891
23892 \layout Standard
23893 Writes/Reads characters via the USART peripheral
23894
23895 \end_inset
23896 </cell>
23897 </row>
23898 <row topline="true">
23899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23900 \begin_inset Text
23901
23902 \layout Standard
23903 STREAM_MSSP
23904
23905 \end_inset
23906 </cell>
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23908 \begin_inset Text
23909
23910 \layout Standard
23911
23912 \family typewriter
23913 0x210000UL
23914
23915 \end_inset
23916 </cell>
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \layout Standard
23921 MSSP
23922
23923 \end_inset
23924 </cell>
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23926 \begin_inset Text
23927
23928 \layout Standard
23929 Writes/Reads characters via the MSSP peripheral
23930
23931 \end_inset
23932 </cell>
23933 </row>
23934 <row topline="true" bottomline="true">
23935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23936 \begin_inset Text
23937
23938 \layout Standard
23939 STREAM_USER
23940
23941 \end_inset
23942 </cell>
23943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23944 \begin_inset Text
23945
23946 \layout Standard
23947
23948 \family typewriter
23949 0x2f0000UL
23950
23951 \end_inset
23952 </cell>
23953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23954 \begin_inset Text
23955
23956 \layout Standard
23957 (none)
23958
23959 \end_inset
23960 </cell>
23961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23962 \begin_inset Text
23963
23964 \layout Standard
23965 Writes/Reads characters via used defined functions
23966
23967 \end_inset
23968 </cell>
23969 </row>
23970 </lyxtabular>
23971
23972 \end_inset
23973
23974
23975
23976 \layout Standard
23977 The stream identifiers are declared as macros in the stdio.h header.
23978
23979 \layout Standard
23980 In the libc library there exist the functions that are used to write to
23981  each of the above streams.
23982  These are
23983
23984 \layout List
23985 \labelwidthstring 00.00.0000
23986 _
23987 \begin_inset ERT
23988 status Collapsed
23989
23990 \layout Standard
23991
23992
23993 \backslash
23994 /
23995
23996 \end_inset
23997
23998 _stream_usart_putchar writes a character at the USART stream
23999
24000 \layout List
24001 \labelwidthstring 00.00.0000
24002 _
24003 \begin_inset ERT
24004 status Collapsed
24005
24006 \layout Standard
24007
24008
24009 \backslash
24010 /
24011
24012 \end_inset
24013
24014 _stream_mssp_putchar writes a character at the MSSP stream
24015
24016 \layout List
24017 \labelwidthstring 00.00.0000
24018 putchar dummy function.
24019  This writes a character to a user specified manner.
24020
24021 \layout Standard
24022 In order to increase performance 
24023 \emph on
24024 putchar 
24025 \emph default
24026 is declared in stdio.h as having its parameter in WREG (it has the wparam
24027  keyword).
24028  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24029  in a user-friendly way.
24030  
24031 \emph on
24032 arg
24033 \emph default
24034  is the name of the variable that holds the character to print.
24035  An example follows:
24036
24037 \layout LyX-Code
24038 #include <pic18fregs.h>
24039 \newline
24040 #include <stdio.h>
24041 \newline
24042
24043 \newline
24044 PUTCHAR( c )
24045
24046 \layout LyX-Code
24047 {
24048
24049 \layout LyX-Code
24050     PORTA = c;    /* dump character c to PORTA */
24051
24052 \layout LyX-Code
24053
24054 \newline
24055
24056 \newline
24057 void main(void)
24058
24059 \layout LyX-Code
24060 {
24061
24062 \layout LyX-Code
24063     stdout = STREAM_USER;    /* this is not necessary, since stdout points
24064
24065 \layout LyX-Code
24066                               * by default to STREAM_USER */
24067
24068 \layout LyX-Code
24069     printf (¨This is a printf test
24070 \backslash
24071 n¨);
24072
24073 \layout LyX-Code
24074 }
24075
24076 \layout LyX-Code
24077
24078
24079 \layout Subsubsection
24080 Printing functions
24081
24082 \layout Standard
24083 PIC16 contains an implementation of the printf-family of functions.
24084  There exist the following functions:
24085
24086 \layout LyX-Code
24087 extern unsigned int sprintf(char *buf, char *fmt, ...);
24088
24089 \layout LyX-Code
24090 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
24091
24092 \layout LyX-Code
24093
24094
24095 \layout LyX-Code
24096 extern unsigned int printf(char *fmt, ...);
24097
24098 \layout LyX-Code
24099 extern unsigned int vprintf(char *fmt, va_lista ap);
24100
24101 \layout LyX-Code
24102
24103
24104 \layout LyX-Code
24105 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
24106
24107 \layout LyX-Code
24108 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
24109
24110 \layout Standard
24111 For sprintf and vsprintf 
24112 \emph on
24113 buf 
24114 \emph default
24115 should normally be a data pointer where the resulting string will be placed.
24116  No range checking is done so the user should allocate the necessery buffer.
24117  For fprintf and vfprintf 
24118 \emph on
24119 fp
24120 \emph default
24121  should be a stream pointer (i.e.
24122  stdout, STREAM_MSSP, etc...).
24123
24124 \layout Subsubsection
24125 Signals
24126
24127 \layout Standard
24128 The PIC18F family of microcontrollers supports a number of interrupt sources.
24129  A list of these interrupts is shown in the following table:
24130
24131 \layout Standard
24132 \align center
24133 \begin_inset Tabular
24134 <lyxtabular version="3" rows="11" columns="4">
24135 <features>
24136 <column alignment="left" valignment="top" leftline="true" width="0">
24137 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24138 <column alignment="left" valignment="top" leftline="true" width="0">
24139 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24140 <row topline="true" bottomline="true">
24141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24142 \begin_inset Text
24143
24144 \layout Standard
24145 signal name
24146
24147 \end_inset
24148 </cell>
24149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24150 \begin_inset Text
24151
24152 \layout Standard
24153 description
24154
24155 \end_inset
24156 </cell>
24157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24158 \begin_inset Text
24159
24160 \layout Standard
24161 signal name
24162
24163 \end_inset
24164 </cell>
24165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24166 \begin_inset Text
24167
24168 \layout Standard
24169 descritpion
24170
24171 \end_inset
24172 </cell>
24173 </row>
24174 <row topline="true">
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24176 \begin_inset Text
24177
24178 \layout Standard
24179 SIG_RB
24180
24181 \end_inset
24182 </cell>
24183 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24184 \begin_inset Text
24185
24186 \layout Standard
24187 PORTB change interrupt
24188
24189 \end_inset
24190 </cell>
24191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24192 \begin_inset Text
24193
24194 \layout Standard
24195 SIG_EE
24196
24197 \end_inset
24198 </cell>
24199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24200 \begin_inset Text
24201
24202 \layout Standard
24203 EEPROM/FLASH write complete interrupt
24204
24205 \end_inset
24206 </cell>
24207 </row>
24208 <row topline="true">
24209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24210 \begin_inset Text
24211
24212 \layout Standard
24213 SIG_INT0
24214
24215 \end_inset
24216 </cell>
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24218 \begin_inset Text
24219
24220 \layout Standard
24221 INT0 external interrupt
24222
24223 \end_inset
24224 </cell>
24225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24226 \begin_inset Text
24227
24228 \layout Standard
24229 SIG_BCOL
24230
24231 \end_inset
24232 </cell>
24233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24234 \begin_inset Text
24235
24236 \layout Standard
24237 Bus collision interrupt
24238
24239 \end_inset
24240 </cell>
24241 </row>
24242 <row topline="true">
24243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24244 \begin_inset Text
24245
24246 \layout Standard
24247 SIG_INT1
24248
24249 \end_inset
24250 </cell>
24251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24252 \begin_inset Text
24253
24254 \layout Standard
24255 INT1 external interrupt
24256
24257 \end_inset
24258 </cell>
24259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24260 \begin_inset Text
24261
24262 \layout Standard
24263 SIG_LVD
24264
24265 \end_inset
24266 </cell>
24267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24268 \begin_inset Text
24269
24270 \layout Standard
24271 Low voltage detect interrupt
24272
24273 \end_inset
24274 </cell>
24275 </row>
24276 <row topline="true">
24277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24278 \begin_inset Text
24279
24280 \layout Standard
24281 SIG_INT2
24282
24283 \end_inset
24284 </cell>
24285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24286 \begin_inset Text
24287
24288 \layout Standard
24289 INT2 external interrupt
24290
24291 \end_inset
24292 </cell>
24293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24294 \begin_inset Text
24295
24296 \layout Standard
24297 SIG_PSP
24298
24299 \end_inset
24300 </cell>
24301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24302 \begin_inset Text
24303
24304 \layout Standard
24305 Parallel slave port interrupt
24306
24307 \end_inset
24308 </cell>
24309 </row>
24310 <row topline="true">
24311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24312 \begin_inset Text
24313
24314 \layout Standard
24315 SIG_CCP1
24316
24317 \end_inset
24318 </cell>
24319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24320 \begin_inset Text
24321
24322 \layout Standard
24323 CCP1 module interrupt
24324
24325 \end_inset
24326 </cell>
24327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24328 \begin_inset Text
24329
24330 \layout Standard
24331 SIG_AD
24332
24333 \end_inset
24334 </cell>
24335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24336 \begin_inset Text
24337
24338 \layout Standard
24339 AD convertion complete interrupt
24340
24341 \end_inset
24342 </cell>
24343 </row>
24344 <row topline="true">
24345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24346 \begin_inset Text
24347
24348 \layout Standard
24349 SIG_CCP2
24350
24351 \end_inset
24352 </cell>
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24354 \begin_inset Text
24355
24356 \layout Standard
24357 CCP2 module interrupt
24358
24359 \end_inset
24360 </cell>
24361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24362 \begin_inset Text
24363
24364 \layout Standard
24365 SIG_RC
24366
24367 \end_inset
24368 </cell>
24369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24370 \begin_inset Text
24371
24372 \layout Standard
24373 USART receive interrupt
24374
24375 \end_inset
24376 </cell>
24377 </row>
24378 <row topline="true">
24379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24380 \begin_inset Text
24381
24382 \layout Standard
24383 SIG_TMR0
24384
24385 \end_inset
24386 </cell>
24387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24388 \begin_inset Text
24389
24390 \layout Standard
24391 TMR0 overflow interrupt
24392
24393 \end_inset
24394 </cell>
24395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24396 \begin_inset Text
24397
24398 \layout Standard
24399 SIG_TX
24400
24401 \end_inset
24402 </cell>
24403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24404 \begin_inset Text
24405
24406 \layout Standard
24407 USART transmit interrupt
24408
24409 \end_inset
24410 </cell>
24411 </row>
24412 <row topline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24414 \begin_inset Text
24415
24416 \layout Standard
24417 SIG_TMR1
24418
24419 \end_inset
24420 </cell>
24421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24422 \begin_inset Text
24423
24424 \layout Standard
24425 TMR1 overflow interrupt
24426
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 SIG_MSSP
24434
24435 \end_inset
24436 </cell>
24437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24438 \begin_inset Text
24439
24440 \layout Standard
24441 SSP receive/transmit interrupt
24442
24443 \end_inset
24444 </cell>
24445 </row>
24446 <row topline="true">
24447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24448 \begin_inset Text
24449
24450 \layout Standard
24451 SIG_TMR2
24452
24453 \end_inset
24454 </cell>
24455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24456 \begin_inset Text
24457
24458 \layout Standard
24459 TMR2 matches PR2 interrupt
24460
24461 \end_inset
24462 </cell>
24463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24464 \begin_inset Text
24465
24466 \layout Standard
24467
24468
24469 \end_inset
24470 </cell>
24471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24472 \begin_inset Text
24473
24474 \layout Standard
24475
24476
24477 \end_inset
24478 </cell>
24479 </row>
24480 <row topline="true" bottomline="true">
24481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24482 \begin_inset Text
24483
24484 \layout Standard
24485 SIG_TMR3
24486
24487 \end_inset
24488 </cell>
24489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24490 \begin_inset Text
24491
24492 \layout Standard
24493 TMR3 overflow interrupt
24494
24495 \end_inset
24496 </cell>
24497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24498 \begin_inset Text
24499
24500 \layout Standard
24501
24502
24503 \end_inset
24504 </cell>
24505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24506 \begin_inset Text
24507
24508 \layout Standard
24509
24510
24511 \end_inset
24512 </cell>
24513 </row>
24514 </lyxtabular>
24515
24516 \end_inset
24517
24518
24519
24520 \layout Standard
24521 The prototypes for these names are defined in the header file 
24522 \emph on
24523 signal.h
24524 \emph default
24525  .
24526
24527 \layout Standard
24528 In order to simplify signal handling, a number of macros is provided:
24529
24530 \layout List
24531 \labelwidthstring 00.00.0000
24532 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
24533  high priority interrupts.
24534  
24535 \emph on
24536 name
24537 \emph default
24538  is the function name to use.
24539
24540 \layout List
24541 \labelwidthstring 00.00.0000
24542 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
24543  low priority interrupt.
24544  
24545 \emph on
24546 name
24547 \emph default
24548  is the function name to use.
24549
24550 \layout List
24551 \labelwidthstring 00.00.0000
24552 DEF_HANDLER(sig,handler) define a handler for signal 
24553 \emph on
24554 sig.
24555
24556 \layout List
24557 \labelwidthstring 00.00.0000
24558 END_DEF end the declaration of the dispatch table.
24559
24560 \layout Standard
24561 Additionally there are two more macros to simplify the declaration of the
24562  signal handler:
24563
24564 \layout List
24565 \labelwidthstring 00.00.0000
24566
24567 \series medium
24568 SIGHANDLER(handler) 
24569 \series default
24570 this declares the function prototype for the 
24571 \emph on
24572 handler
24573 \emph default
24574  function.
24575
24576 \layout List
24577 \labelwidthstring 00.00.0000
24578 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
24579
24580 \layout Standard
24581 An example of using the macros above is shown below:
24582
24583 \layout LyX-Code
24584 #include <pic18fregs.h>
24585
24586 \layout LyX-Code
24587 #include <signal.h>
24588 \newline
24589
24590 \newline
24591 DEF_INTHIGH(high_int)
24592
24593 \layout LyX-Code
24594 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
24595
24596 \layout LyX-Code
24597 DEF_HANDLER(SIG_BCOL, _bcol_handler)
24598
24599 \layout LyX-Code
24600 END_DEF
24601 \newline
24602
24603 \newline
24604 SIGHANDLER(_tmr0_handler)
24605
24606 \layout LyX-Code
24607 {
24608
24609 \layout LyX-Code
24610   /* action to be taken when timer 0 overflows */
24611
24612 \layout LyX-Code
24613 }
24614 \newline
24615
24616 \newline
24617 SIGHANDLERNAKED(_bcol_handler)
24618
24619 \layout LyX-Code
24620 {
24621
24622 \layout LyX-Code
24623   _asm
24624
24625 \layout LyX-Code
24626     /* action to be taken when bus collision occurs */
24627
24628 \layout LyX-Code
24629     retfie
24630
24631 \layout LyX-Code
24632  _endasm;
24633
24634 \layout LyX-Code
24635 }
24636
24637 \layout Standard
24638
24639 \series bold
24640 NOTES:
24641 \series default
24642  Special care should be taken when using the above scheme:
24643
24644 \layout Itemize
24645 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
24646
24647 \layout Itemize
24648 when declaring SIGHANDLERNAKED handler never forget to use 
24649 \emph on
24650 retfie
24651 \emph default
24652  for proper returning.
24653
24654 \layout Subsection
24655 PIC16 Port -- Tips
24656
24657 \layout Standard
24658 Here you can find some general tips for compiling programs with SDCC/pic16.
24659
24660 \layout Subsubsection
24661 Stack size
24662
24663 \layout Standard
24664 The default stack
24665 \begin_inset LatexCommand \index{PIC16!stack}
24666
24667 \end_inset
24668
24669  size (that is 64 bytes) probably is enough for many programs.
24670  One must take care that when there are many levels of function nesting,
24671  or there is excessive usage of stack, its size should be extended.
24672  An example of such a case is the printf/sprintf family of functions.
24673  If you encounter problems like not being able to print integers, then you
24674  need to set the stack size around the maximum (256 for small stack model).
24675  The following diagram shows what happens when calling printf to print an
24676  integer:
24677
24678 \layout LyX-Code
24679 printf () --> ltoa () --> ultoa () --> divschar ()
24680
24681 \layout Standard
24682 It is should be understood that stack is easily consumed when calling complicate
24683 d functions.
24684  Using command line arguments like -
24685 \begin_inset ERT
24686 status Collapsed
24687
24688 \layout Standard
24689
24690
24691 \backslash
24692 /
24693
24694 \end_inset
24695
24696 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
24697  stack frames.
24698  Other ways to reduce stack usage may exist.
24699
24700 \layout Subsection
24701 Known bugs
24702
24703 \layout Standard
24704 The PIC16 Port currently does not pass SDCC's regression test
24705 \begin_inset LatexCommand \index{Regression test (PIC16)}
24706
24707 \end_inset
24708
24709  suite (see section 
24710 \begin_inset LatexCommand \ref{sec:Quality-control}
24711
24712 \end_inset
24713
24714 ) and thus the nightly regression tests for the PIC16 target are currently
24715  disabled for all hosts except for 
24716 \emph on
24717 Linux on Opteron.
24718
24719 \emph default
24720  This means you can see the result of the PIC16 regression tests f.e.
24721  by checking the log files in 
24722 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
24723
24724 \end_inset
24725
24726  (pick the most up to date file there, scroll down, lend a hand).
24727
24728 \layout Chapter
24729 Debugging
24730
24731 \layout Standard
24732 There are several approaches to debugging your code.
24733  This chapter is meant to show your options and to give detail on some of
24734  them:
24735 \newline
24736
24737 \newline
24738 When writing your code:
24739
24740 \layout Itemize
24741 write your code with debugging in mind (avoid duplicating code, put conceptually
24742  similar variables into structs, use structured code, have strategic points
24743  within your code where all variables are consistent, ...)
24744
24745 \layout Itemize
24746 run a syntax-checking tool like splint
24747 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24748
24749 \end_inset
24750
24751
24752 \begin_inset LatexCommand \index{lint (syntax checking tool)}
24753
24754 \end_inset
24755
24756  (see -
24757 \begin_inset ERT
24758 status Collapsed
24759
24760 \layout Standard
24761
24762
24763 \backslash
24764 /
24765
24766 \end_inset
24767
24768 -more-pedantic 
24769 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24770
24771 \end_inset
24772
24773 ) over the code.
24774
24775 \layout Itemize
24776 for the high level code use a C-compiler (like f.e.
24777  GCC) to compile run and debug the code on your host.
24778  See (see -
24779 \begin_inset ERT
24780 status Collapsed
24781
24782 \layout Standard
24783
24784
24785 \backslash
24786 /
24787
24788 \end_inset
24789
24790 -more-pedantic 
24791 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24792
24793 \end_inset
24794
24795  ) on howto handle syntax extensions like __xdata, __at(), ...
24796  
24797
24798 \layout Itemize
24799 use another C-compiler to compile code for your target.
24800  Always an option but not recommended:) And not very likely to help you.
24801  If you seriously consider walking this path you should at least occasionally
24802  check portability of your code.
24803  Most commercial compiler vendors will offer an evaluation version so you
24804  can test compile your code or snippets of your code.
24805
24806 \layout Standard
24807 Debugging on a simulator:
24808
24809 \layout Itemize
24810 there is a separate section about SDCDB (section 
24811 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
24812
24813 \end_inset
24814
24815 ) below.
24816
24817 \layout Itemize
24818 or (8051 specific) use a freeware/commercial simulator which interfaces
24819  to the AOMF
24820 \begin_inset LatexCommand \index{AOMF, AOMF51}
24821
24822 \end_inset
24823
24824  file (see 
24825 \begin_inset LatexCommand \ref{OMF file}
24826
24827 \end_inset
24828
24829 ) optionally generated by SDCC.
24830
24831 \layout Standard
24832 Debugging On-target: 
24833
24834 \layout Itemize
24835 use a MCU port pin to serially output debug data to the RS232 port of your
24836  host.
24837  You'll probably want some level shifting device typically involving a MAX232
24838  or similar IC.
24839  If the hardware serial port of the MCU is not available search for 'Software
24840  UART' in your favourite search machine.
24841
24842 \layout Itemize
24843 use an on-target monitor.
24844  In this context a monitor is a small program which usually accepts commands
24845  via a serial line and allows to set program counter, to single step through
24846  a program and read/write memory locations.
24847  For the 8051 good examples of monitors are paulmon and cmon51 (see section
24848  
24849 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
24850
24851 \end_inset
24852
24853 ).
24854
24855 \layout Itemize
24856 toggle MCU port pins at strategic points within your code and use an oscilloscop
24857 e.
24858  A 
24859 \emph on
24860 digital oscilloscope
24861 \emph default
24862
24863 \begin_inset LatexCommand \index{Oscilloscope}
24864
24865 \end_inset
24866
24867  with deep trace memory is really helpful especially if you have to debug
24868  a realtime application.
24869  If you need to monitor more pins than your oscilloscope provides you can
24870  sometimes get away with a small R-2R network.
24871  On a single channel oscilloscope you could f.e.
24872  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24873 k
24874 \begin_inset Formula $\Omega$
24875 \end_inset
24876
24877  resistor and the other one by a 5\SpecialChar ~
24878 k
24879 \begin_inset Formula $\Omega$
24880 \end_inset
24881
24882  resistor to the oscilloscope probe (check output drive capability of the
24883  pins you want to monitor).
24884  If you need to monitor many more pins a 
24885 \emph on
24886 logic analyzer
24887 \emph default
24888  will be handy.
24889
24890 \layout Itemize
24891 use an ICE (
24892 \emph on
24893 i
24894 \emph default
24895
24896 \emph on
24897 c
24898 \emph default
24899 ircuit 
24900 \emph on
24901 e
24902 \emph default
24903 mulator
24904 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24905
24906 \end_inset
24907
24908 ).
24909  Usually very expensive.
24910  And very nice to have too.
24911  And usually locks you (for years...) to the devices the ICE can emulate.
24912  
24913
24914 \layout Itemize
24915 use a remote debugger.
24916  In most 8-bit systems the symbol information is not available on the target,
24917  and a complete debugger is too bulky for the target system.
24918  Therefore usually a debugger on the host system connects to an on-target
24919  debugging stub which accepts only primitive commands.
24920  
24921 \newline
24922 Terms to enter into your favourite search engine could be 'remote debugging',
24923  'gdb stub' or 'inferior debugger'.
24924  (is there one?)
24925
24926 \layout Itemize
24927 use an on target hardware debugger.
24928  Some of the more modern MCUs include hardware support for setting break
24929  points and monitoring/changing variables by using dedicated hardware pins.
24930  This facility doesn't require additional code to run on the target and
24931  
24932 \emph on
24933 usually
24934 \emph default
24935  doesn't affect runtime behaviour until a breakpoint is hit.
24936  For the mcs51 most hardware debuggers use the AOMF
24937 \begin_inset LatexCommand \index{AOMF, AOMF51}
24938
24939 \end_inset
24940
24941  file (see 
24942 \begin_inset LatexCommand \ref{OMF file}
24943
24944 \end_inset
24945
24946 ) as input file.
24947  
24948
24949 \layout Standard
24950 Last not least:
24951
24952 \layout Itemize
24953 if you are not familiar with any of the following terms you're likely to
24954  run into problems rather sooner than later: 
24955 \emph on
24956 volatile
24957 \emph default
24958
24959 \emph on
24960 atomic
24961 \emph default
24962
24963 \emph on
24964 memory map
24965 \emph default
24966
24967 \emph on
24968 overlay
24969 \emph default
24970 .
24971  As an embedded programmer you 
24972 \emph on
24973 have
24974 \emph default
24975  to know them so why not look them up 
24976 \emph on
24977 before
24978 \emph default
24979  you have problems?)
24980
24981 \layout Itemize
24982 tell someone else about your problem (actually this is a surprisingly effective
24983  means to hunt down the bug even if the listener is not familiar with your
24984  environment).
24985  As 'failure to communicate' is probably one of the job-induced deformations
24986  of an embedded programmer this is highly encouraged.
24987
24988 \layout Section
24989 Debugging with SDCDB
24990 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24991
24992 \end_inset
24993
24994
24995 \begin_inset LatexCommand \index{SDCDB (debugger)}
24996
24997 \end_inset
24998
24999  
25000
25001 \layout Standard
25002 SDCC is distributed with a source level debugger
25003 \begin_inset LatexCommand \index{Debugger}
25004
25005 \end_inset
25006
25007 .
25008  The debugger uses a command line interface, the command repertoire of the
25009  debugger has been kept as close to gdb
25010 \begin_inset LatexCommand \index{gdb}
25011
25012 \end_inset
25013
25014  (the GNU debugger) as possible.
25015  The configuration and build process is part of the standard compiler installati
25016 on, which also builds and installs the debugger in the target directory
25017  specified during configuration.
25018  The debugger allows you debug BOTH at the C source and at the ASM source
25019  level.
25020
25021 \layout Subsection
25022 Compiling for Debugging
25023
25024 \layout Standard
25025 The -
25026 \begin_inset ERT
25027 status Collapsed
25028
25029 \layout Standard
25030
25031
25032 \backslash
25033 /
25034
25035 \end_inset
25036
25037 -debug
25038 \begin_inset LatexCommand \index{-\/-debug}
25039
25040 \end_inset
25041
25042  option must be specified for all files for which debug information is to
25043  be generated.
25044  The compiler generates a .adb file for each of these files.
25045  The linker creates the .cdb
25046 \begin_inset LatexCommand \index{<file>.cdb}
25047
25048 \end_inset
25049
25050  file from the .adb
25051 \begin_inset LatexCommand \index{<file>.adb}
25052
25053 \end_inset
25054
25055  files and the address information.
25056  This .cdb is used by the debugger.
25057
25058 \layout Subsection
25059 How the Debugger Works
25060
25061 \layout Standard
25062 When the -
25063 \begin_inset ERT
25064 status Collapsed
25065
25066 \layout Standard
25067
25068
25069 \backslash
25070 /
25071
25072 \end_inset
25073
25074 -debug option is specified the compiler generates extra symbol information
25075  some of which are put into the assembler source and some are put into the
25076  .adb file.
25077  Then the linker creates the .cdb file from the individual .adb files with
25078  the address information for the symbols.
25079  The debugger reads the symbolic information generated by the compiler &
25080  the address information generated by the linker.
25081  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
25082  execution is controlled by the debugger.
25083  When a command is issued for the debugger, it translates it into appropriate
25084  commands for the simulator.
25085  (Currently SDCDM only connects to the simulator but 
25086 \emph on
25087 newcdb
25088 \emph default
25089  at 
25090 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
25091
25092 \end_inset
25093
25094  is an effort to connect directly to the hardware.) 
25095
25096 \layout Subsection
25097 Starting the Debugger SDCDB
25098
25099 \layout Standard
25100 The debugger can be started using the following command line.
25101  (Assume the file you are debugging has the file name foo).
25102 \newline
25103
25104 \newline
25105
25106 \family sans
25107 \series bold
25108 sdcdb foo
25109 \newline
25110
25111 \family default
25112 \series default
25113
25114 \newline
25115 The debugger will look for the following files.
25116
25117 \layout Itemize
25118 foo.c - the source file.
25119
25120 \layout Itemize
25121 foo.cdb - the debugger symbol information file.
25122
25123 \layout Itemize
25124 foo.ihx - the Intel hex format
25125 \begin_inset LatexCommand \index{Intel hex format}
25126
25127 \end_inset
25128
25129  object file.
25130
25131 \layout Subsection
25132 SDCDB Command Line Options
25133
25134 \layout Itemize
25135 -
25136 \begin_inset ERT
25137 status Collapsed
25138
25139 \layout Standard
25140
25141
25142 \backslash
25143 /
25144
25145 \end_inset
25146
25147 -directory=<source file directory> this option can used to specify the directory
25148  search list.
25149  The debugger will look into the directory list specified for source, cdb
25150  & ihx files.
25151  The items in the directory list must be separated by ':', e.g.
25152  if the source files can be in the directories /home/src1 and /home/src2,
25153  the -
25154 \begin_inset ERT
25155 status Collapsed
25156
25157 \layout Standard
25158
25159
25160 \backslash
25161 /
25162
25163 \end_inset
25164
25165 -directory option should be -
25166 \begin_inset ERT
25167 status Collapsed
25168
25169 \layout Standard
25170
25171
25172 \backslash
25173 /
25174
25175 \end_inset
25176
25177 -directory=/home/src1:/home/src2.
25178  Note there can be no spaces in the option.
25179  
25180
25181 \layout Itemize
25182 -cd <directory> - change to the <directory>.
25183
25184 \layout Itemize
25185 -fullname - used by GUI front ends.
25186
25187 \layout Itemize
25188 -cpu <cpu-type> - this argument is passed to the simulator please see the
25189  simulator docs for details.
25190
25191 \layout Itemize
25192 -X <Clock frequency > this options is passed to the simulator please see
25193  the simulator docs for details.
25194
25195 \layout Itemize
25196 -s <serial port file> passed to simulator see the simulator docs for details.
25197
25198 \layout Itemize
25199 -S <serial in,out> passed to simulator see the simulator docs for details.
25200
25201 \layout Itemize
25202 -k <port number> passed to simulator see the simulator docs for details.
25203
25204 \layout Subsection
25205 SDCDB Debugger Commands
25206
25207 \layout Standard
25208 As mentioned earlier the command interface for the debugger has been deliberatel
25209 y kept as close the GNU debugger gdb, as possible.
25210  This will help the integration with existing graphical user interfaces
25211  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
25212  If you use a graphical user interface for the debugger you can skip this
25213  section.
25214
25215 \layout Subsubsection*
25216 break [line | file:line | function | file:function]
25217
25218 \layout Standard
25219 Set breakpoint at specified line or function:
25220 \newline
25221
25222 \newline
25223
25224 \family sans
25225 \series bold
25226 sdcdb>break 100 
25227 \newline
25228 sdcdb>break foo.c:100
25229 \newline
25230 sdcdb>break funcfoo
25231 \newline
25232 sdcdb>break foo.c:funcfoo
25233
25234 \layout Subsubsection*
25235 clear [line | file:line | function | file:function ]
25236
25237 \layout Standard
25238 Clear breakpoint at specified line or function:
25239 \newline
25240
25241 \newline
25242
25243 \family sans
25244 \series bold
25245 sdcdb>clear 100
25246 \newline
25247 sdcdb>clear foo.c:100
25248 \newline
25249 sdcdb>clear funcfoo
25250 \newline
25251 sdcdb>clear foo.c:funcfoo
25252
25253 \layout Subsubsection*
25254 continue
25255
25256 \layout Standard
25257 Continue program being debugged, after breakpoint.
25258
25259 \layout Subsubsection*
25260 finish
25261
25262 \layout Standard
25263 Execute till the end of the current function.
25264
25265 \layout Subsubsection*
25266 delete [n]
25267
25268 \layout Standard
25269 Delete breakpoint number 'n'.
25270  If used without any option clear ALL user defined break points.
25271
25272 \layout Subsubsection*
25273 info [break | stack | frame | registers ]
25274
25275 \layout Itemize
25276 info break - list all breakpoints
25277
25278 \layout Itemize
25279 info stack - show the function call stack.
25280
25281 \layout Itemize
25282 info frame - show information about the current execution frame.
25283
25284 \layout Itemize
25285 info registers - show content of all registers.
25286
25287 \layout Subsubsection*
25288 step
25289
25290 \layout Standard
25291 Step program until it reaches a different source line.
25292  Note: pressing <return> repeats the last command.
25293
25294 \layout Subsubsection*
25295 next
25296
25297 \layout Standard
25298 Step program, proceeding through subroutine calls.
25299
25300 \layout Subsubsection*
25301 run
25302
25303 \layout Standard
25304 Start debugged program.
25305
25306 \layout Subsubsection*
25307 ptype variable 
25308
25309 \layout Standard
25310 Print type information of the variable.
25311
25312 \layout Subsubsection*
25313 print variable
25314
25315 \layout Standard
25316 print value of variable.
25317
25318 \layout Subsubsection*
25319 file filename
25320
25321 \layout Standard
25322 load the given file name.
25323  Note this is an alternate method of loading file for debugging.
25324
25325 \layout Subsubsection*
25326 frame
25327
25328 \layout Standard
25329 print information about current frame.
25330
25331 \layout Subsubsection*
25332 set srcmode
25333
25334 \layout Standard
25335 Toggle between C source & assembly source.
25336
25337 \layout Subsubsection*
25338 ! simulator command
25339
25340 \layout Standard
25341 Send the string following '!' to the simulator, the simulator response is
25342  displayed.
25343  Note the debugger does not interpret the command being sent to the simulator,
25344  so if a command like 'go' is sent the debugger can loose its execution
25345  context and may display incorrect values.
25346
25347 \layout Subsubsection*
25348 quit
25349
25350 \layout Standard
25351 "Watch me now.
25352  Iam going Down.
25353  My name is Bobby Brown"
25354
25355 \layout Subsection
25356 Interfacing SDCDB with DDD
25357
25358 \layout Standard
25359 \begin_inset Note
25360 collapsed true
25361
25362 \layout Standard
25363 The screenshot was converted from png to eps with: 
25364 \begin_inset Quotes sld
25365 \end_inset
25366
25367 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
25368 \begin_inset Quotes srd
25369 \end_inset
25370
25371  which produces a pretty compact eps file which is free from compression
25372  artifacts.
25373
25374 \layout Standard
25375 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
25376  as this broke the build system on Sourceforge (pdf-file was broken.
25377  pdflatex does not accept eps files).
25378
25379 \end_inset
25380
25381
25382
25383 \layout Standard
25384 The 
25385 \emph on
25386 p
25387 \emph default
25388 ortable 
25389 \emph on
25390 n
25391 \emph default
25392 etwork 
25393 \emph on
25394 g
25395 \emph default
25396 raphics File 
25397 \size footnotesize
25398
25399 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
25400
25401 \end_inset
25402
25403
25404 \size default
25405  shows a screenshot of a debugging session with DDD
25406 \begin_inset LatexCommand \index{DDD (debugger)}
25407
25408 \end_inset
25409
25410  (Unix only) on a simulated 8032.
25411  The debugging session might not run as smoothly as the screenshot suggests.
25412  The debugger allows setting of breakpoints, displaying and changing variables,
25413  single stepping through C and assembler code.
25414  
25415 \newline
25416 The source was compiled with 
25417 \family sans
25418 \series bold
25419
25420 \newline
25421
25422 \newline
25423 sdcc -
25424 \family default
25425 \series default
25426
25427 \begin_inset ERT
25428 status Collapsed
25429
25430 \layout Standard
25431
25432
25433 \backslash
25434 /
25435
25436 \end_inset
25437
25438
25439 \family sans
25440 \series bold
25441 -debug ddd_example.c
25442 \family default
25443 \series default
25444  
25445 \family sans
25446 \series bold
25447
25448 \newline
25449
25450 \family default
25451 \series default
25452
25453 \newline
25454 and DDD was invoked with 
25455 \family sans
25456 \series bold
25457
25458 \newline
25459
25460 \newline
25461 ddd -debugger "sdcdb -cpu 8032 ddd_example"
25462
25463 \layout Standard
25464 \begin_inset Note
25465 collapsed false
25466
25467 \layout Standard
25468 Check that the double quotes or an apostroph within the command line survive
25469  the LyX tool chain.
25470  Previously the apostrophs got slanted in the PDF output so a cut and paste
25471  did not work.
25472
25473 \end_inset
25474
25475
25476
25477 \layout Subsection
25478 Interfacing SDCDB with XEmacs
25479 \begin_inset LatexCommand \index{XEmacs}
25480
25481 \end_inset
25482
25483
25484 \begin_inset LatexCommand \index{Emacs}
25485
25486 \end_inset
25487
25488
25489
25490 \layout Standard
25491 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
25492  sdcdb.el and sdcdbsrc.el.
25493  These two files can be found in the $(prefix)/bin directory after the installat
25494 ion is complete.
25495  These files need to be loaded into XEmacs for the interface to work.
25496  This can be done at XEmacs startup time by inserting the following into
25497  your '.xemacs' file (which can be found in your HOME directory): 
25498 \newline
25499
25500 \newline
25501
25502 \family typewriter
25503 (load-file sdcdbsrc.el) 
25504 \family default
25505
25506 \newline
25507
25508 \newline
25509 .xemacs is a lisp file so the () around the command is REQUIRED.
25510  The files can also be loaded dynamically while XEmacs is running, set the
25511  environment variable 'EMACSLOADPATH' to the installation bin directory
25512  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
25513  To start the interface enter the following command: 
25514 \newline
25515
25516 \newline
25517
25518 \family sans
25519 \series bold
25520 ESC-x sdcdbsrc
25521 \family default
25522 \series default
25523
25524 \newline
25525
25526 \newline
25527 You will prompted to enter the file name to be debugged.
25528  
25529 \newline
25530
25531 \newline
25532 The command line options that are passed to the simulator directly are
25533  bound to default values in the file sdcdbsrc.el.
25534  The variables are listed below, these values maybe changed as required.
25535
25536 \layout Itemize
25537 sdcdbsrc-cpu-type '51
25538
25539 \layout Itemize
25540 sdcdbsrc-frequency '11059200
25541
25542 \layout Itemize
25543 sdcdbsrc-serial nil
25544
25545 \layout Standard
25546 The following is a list of key mapping for the debugger interface.
25547
25548 \layout Standard
25549 \pagebreak_bottom 
25550 \SpecialChar ~
25551
25552 \family typewriter
25553
25554 \newline
25555 ;;\SpecialChar ~
25556 Current Listing :: 
25557 \newline
25558 ;;key\SpecialChar ~
25559 \SpecialChar ~
25560 \SpecialChar ~
25561 \SpecialChar ~
25562 \SpecialChar ~
25563 \SpecialChar ~
25564 \SpecialChar ~
25565 \SpecialChar ~
25566 \SpecialChar ~
25567 \SpecialChar ~
25568 \SpecialChar ~
25569 \SpecialChar ~
25570 \SpecialChar ~
25571 \SpecialChar ~
25572 binding\SpecialChar ~
25573 \SpecialChar ~
25574 \SpecialChar ~
25575 \SpecialChar ~
25576 \SpecialChar ~
25577 \SpecialChar ~
25578 \SpecialChar ~
25579 \SpecialChar ~
25580 \SpecialChar ~
25581 \SpecialChar ~
25582 \SpecialChar ~
25583 \SpecialChar ~
25584 \SpecialChar ~
25585 \SpecialChar ~
25586 \SpecialChar ~
25587 \SpecialChar ~
25588 \SpecialChar ~
25589 \SpecialChar ~
25590 \SpecialChar ~
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 \SpecialChar ~
25594 Comment 
25595 \newline
25596 ;;---\SpecialChar ~
25597 \SpecialChar ~
25598 \SpecialChar ~
25599 \SpecialChar ~
25600 \SpecialChar ~
25601 \SpecialChar ~
25602 \SpecialChar ~
25603 \SpecialChar ~
25604 \SpecialChar ~
25605 \SpecialChar ~
25606 \SpecialChar ~
25607 \SpecialChar ~
25608 \SpecialChar ~
25609 \SpecialChar ~
25610 -------\SpecialChar ~
25611 \SpecialChar ~
25612 \SpecialChar ~
25613 \SpecialChar ~
25614 \SpecialChar ~
25615 \SpecialChar ~
25616 \SpecialChar ~
25617 \SpecialChar ~
25618 \SpecialChar ~
25619 \SpecialChar ~
25620 \SpecialChar ~
25621 \SpecialChar ~
25622 \SpecialChar ~
25623 \SpecialChar ~
25624 \SpecialChar ~
25625 \SpecialChar ~
25626 \SpecialChar ~
25627 \SpecialChar ~
25628 \SpecialChar ~
25629 \SpecialChar ~
25630 \SpecialChar ~
25631 \SpecialChar ~
25632 -------
25633 \newline
25634 ;; 
25635 \newline
25636 ;;\SpecialChar ~
25637 n\SpecialChar ~
25638 \SpecialChar ~
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 \SpecialChar ~
25643 \SpecialChar ~
25644 \SpecialChar ~
25645 \SpecialChar ~
25646 \SpecialChar ~
25647 \SpecialChar ~
25648 \SpecialChar ~
25649 \SpecialChar ~
25650 \SpecialChar ~
25651 \SpecialChar ~
25652 sdcdb-next-fro
25653 m-src\SpecialChar ~
25654 \SpecialChar ~
25655 \SpecialChar ~
25656 \SpecialChar ~
25657 \SpecialChar ~
25658 \SpecialChar ~
25659 \SpecialChar ~
25660 \SpecialChar ~
25661 \SpecialChar ~
25662 \SpecialChar ~
25663 SDCDB next command 
25664 \newline
25665 ;;\SpecialChar ~
25666 b\SpecialChar ~
25667 \SpecialChar ~
25668 \SpecialChar ~
25669 \SpecialChar ~
25670 \SpecialChar ~
25671 \SpecialChar ~
25672 \SpecialChar ~
25673 \SpecialChar ~
25674 \SpecialChar ~
25675 \SpecialChar ~
25676 \SpecialChar ~
25677 \SpecialChar ~
25678 \SpecialChar ~
25679 \SpecialChar ~
25680 \SpecialChar ~
25681 sdcdb-back-from-src\SpecialChar ~
25682 \SpecialChar ~
25683 \SpecialChar ~
25684 \SpecialChar ~
25685 \SpecialChar ~
25686 \SpecialChar ~
25687 \SpecialChar ~
25688 \SpecialChar ~
25689 \SpecialChar ~
25690 \SpecialChar ~
25691 SDCDB back command 
25692 \newline
25693 ;;\SpecialChar ~
25694 c\SpecialChar ~
25695 \SpecialChar ~
25696 \SpecialChar ~
25697 \SpecialChar ~
25698 \SpecialChar ~
25699 \SpecialChar ~
25700 \SpecialChar ~
25701 \SpecialChar ~
25702 \SpecialChar ~
25703 \SpecialChar ~
25704 \SpecialChar ~
25705 \SpecialChar ~
25706 \SpecialChar ~
25707 \SpecialChar ~
25708 \SpecialChar ~
25709 sdcdb-cont-f
25710 rom-src\SpecialChar ~
25711 \SpecialChar ~
25712 \SpecialChar ~
25713 \SpecialChar ~
25714 \SpecialChar ~
25715 \SpecialChar ~
25716 \SpecialChar ~
25717 \SpecialChar ~
25718 \SpecialChar ~
25719 \SpecialChar ~
25720 SDCDB continue command
25721 \newline
25722 ;;\SpecialChar ~
25723 s\SpecialChar ~
25724 \SpecialChar ~
25725 \SpecialChar ~
25726 \SpecialChar ~
25727 \SpecialChar ~
25728 \SpecialChar ~
25729 \SpecialChar ~
25730 \SpecialChar ~
25731 \SpecialChar ~
25732 \SpecialChar ~
25733 \SpecialChar ~
25734 \SpecialChar ~
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 \SpecialChar ~
25738 sdcdb-step-from-src\SpecialChar ~
25739 \SpecialChar ~
25740 \SpecialChar ~
25741 \SpecialChar ~
25742 \SpecialChar ~
25743 \SpecialChar ~
25744 \SpecialChar ~
25745 \SpecialChar ~
25746 \SpecialChar ~
25747 \SpecialChar ~
25748 SDCDB step command 
25749 \newline
25750 ;;\SpecialChar ~
25751 ?\SpecialChar ~
25752 \SpecialChar ~
25753 \SpecialChar ~
25754 \SpecialChar ~
25755 \SpecialChar ~
25756 \SpecialChar ~
25757 \SpecialChar ~
25758 \SpecialChar ~
25759 \SpecialChar ~
25760 \SpecialChar ~
25761 \SpecialChar ~
25762 \SpecialChar ~
25763 \SpecialChar ~
25764 \SpecialChar ~
25765 \SpecialChar ~
25766 sdcdb-w
25767 hatis-c-sexp\SpecialChar ~
25768 \SpecialChar ~
25769 \SpecialChar ~
25770 \SpecialChar ~
25771 \SpecialChar ~
25772 \SpecialChar ~
25773 \SpecialChar ~
25774 \SpecialChar ~
25775 \SpecialChar ~
25776 \SpecialChar ~
25777 SDCDB ptypecommand for data at 
25778 \newline
25779 ;;\SpecialChar ~
25780 \SpecialChar ~
25781 \SpecialChar ~
25782 \SpecialChar ~
25783 \SpecialChar ~
25784 \SpecialChar ~
25785 \SpecialChar ~
25786 \SpecialChar ~
25787 \SpecialChar ~
25788 \SpecialChar ~
25789 \SpecialChar ~
25790 \SpecialChar ~
25791 \SpecialChar ~
25792 \SpecialChar ~
25793 \SpecialChar ~
25794 \SpecialChar ~
25795 \SpecialChar ~
25796 \SpecialChar ~
25797 \SpecialChar ~
25798 \SpecialChar ~
25799 \SpecialChar ~
25800 \SpecialChar ~
25801 \SpecialChar ~
25802 \SpecialChar ~
25803 \SpecialChar ~
25804 \SpecialChar ~
25805 \SpecialChar ~
25806 \SpecialChar ~
25807 \SpecialChar ~
25808 \SpecialChar ~
25809 \SpecialChar ~
25810 \SpecialChar ~
25811 \SpecialChar ~
25812 \SpecialChar ~
25813 \SpecialChar ~
25814 \SpecialChar ~
25815 \SpecialChar ~
25816 \SpecialChar ~
25817 \SpecialChar ~
25818 \SpecialChar ~
25819 \SpecialChar ~
25820 \SpecialChar ~
25821 \SpecialChar ~
25822 \SpecialChar ~
25823 \SpecialChar ~
25824 \SpecialChar ~
25825 \SpecialChar ~
25826 buffer point 
25827 \newline
25828 ;;\SpecialChar ~
25829 x\SpecialChar ~
25830 \SpecialChar ~
25831 \SpecialChar ~
25832 \SpecialChar ~
25833 \SpecialChar ~
25834 \SpecialChar ~
25835 \SpecialChar ~
25836 \SpecialChar ~
25837 \SpecialChar ~
25838 \SpecialChar ~
25839 \SpecialChar ~
25840 \SpecialChar ~
25841 \SpecialChar ~
25842 \SpecialChar ~
25843 \SpecialChar ~
25844 sdcdbsrc-delete\SpecialChar ~
25845 \SpecialChar ~
25846 \SpecialChar ~
25847 \SpecialChar ~
25848 \SpecialChar ~
25849 \SpecialChar ~
25850 \SpecialChar ~
25851 \SpecialChar ~
25852 \SpecialChar ~
25853 \SpecialChar ~
25854 \SpecialChar ~
25855 \SpecialChar ~
25856 \SpecialChar ~
25857 \SpecialChar ~
25858 SDCD
25859 B Delete all breakpoints if no arg 
25860 \newline
25861 ;;\SpecialChar ~
25862 \SpecialChar ~
25863 \SpecialChar ~
25864 \SpecialChar ~
25865 \SpecialChar ~
25866 \SpecialChar ~
25867 \SpecialChar ~
25868 \SpecialChar ~
25869 \SpecialChar ~
25870 \SpecialChar ~
25871 \SpecialChar ~
25872 \SpecialChar ~
25873 \SpecialChar ~
25874 \SpecialChar ~
25875 \SpecialChar ~
25876 \SpecialChar ~
25877 \SpecialChar ~
25878 \SpecialChar ~
25879 \SpecialChar ~
25880 \SpecialChar ~
25881 \SpecialChar ~
25882 \SpecialChar ~
25883 \SpecialChar ~
25884 \SpecialChar ~
25885 \SpecialChar ~
25886 \SpecialChar ~
25887 \SpecialChar ~
25888 \SpecialChar ~
25889 \SpecialChar ~
25890 \SpecialChar ~
25891 \SpecialChar ~
25892 \SpecialChar ~
25893 \SpecialChar ~
25894 \SpecialChar ~
25895 \SpecialChar ~
25896 \SpecialChar ~
25897 \SpecialChar ~
25898 \SpecialChar ~
25899 \SpecialChar ~
25900 \SpecialChar ~
25901 \SpecialChar ~
25902 \SpecialChar ~
25903 \SpecialChar ~
25904 \SpecialChar ~
25905 \SpecialChar ~
25906 \SpecialChar ~
25907 \SpecialChar ~
25908 given or delete arg (C-u arg x) 
25909 \newline
25910 ;;\SpecialChar ~
25911 m\SpecialChar ~
25912 \SpecialChar ~
25913 \SpecialChar ~
25914 \SpecialChar ~
25915 \SpecialChar ~
25916 \SpecialChar ~
25917 \SpecialChar ~
25918 \SpecialChar ~
25919 \SpecialChar ~
25920 \SpecialChar ~
25921 \SpecialChar ~
25922 \SpecialChar ~
25923 \SpecialChar ~
25924 \SpecialChar ~
25925 \SpecialChar ~
25926 sdcdbsrc
25927 -frame\SpecialChar ~
25928 \SpecialChar ~
25929 \SpecialChar ~
25930 \SpecialChar ~
25931 \SpecialChar ~
25932 \SpecialChar ~
25933 \SpecialChar ~
25934 \SpecialChar ~
25935 \SpecialChar ~
25936 \SpecialChar ~
25937 \SpecialChar ~
25938 \SpecialChar ~
25939 \SpecialChar ~
25940 \SpecialChar ~
25941 \SpecialChar ~
25942 SDCDB Display current frame if no arg, 
25943 \newline
25944 ;;\SpecialChar ~
25945 \SpecialChar ~
25946 \SpecialChar ~
25947 \SpecialChar ~
25948 \SpecialChar ~
25949 \SpecialChar ~
25950 \SpecialChar ~
25951 \SpecialChar ~
25952 \SpecialChar ~
25953 \SpecialChar ~
25954 \SpecialChar ~
25955 \SpecialChar ~
25956 \SpecialChar ~
25957 \SpecialChar ~
25958 \SpecialChar ~
25959 \SpecialChar ~
25960 \SpecialChar ~
25961 \SpecialChar ~
25962 \SpecialChar ~
25963 \SpecialChar ~
25964 \SpecialChar ~
25965 \SpecialChar ~
25966 \SpecialChar ~
25967 \SpecialChar ~
25968 \SpecialChar ~
25969 \SpecialChar ~
25970 \SpecialChar ~
25971 \SpecialChar ~
25972 \SpecialChar ~
25973 \SpecialChar ~
25974 \SpecialChar ~
25975 \SpecialChar ~
25976 \SpecialChar ~
25977 \SpecialChar ~
25978 \SpecialChar ~
25979 \SpecialChar ~
25980 \SpecialChar ~
25981 \SpecialChar ~
25982 \SpecialChar ~
25983 \SpecialChar ~
25984 \SpecialChar ~
25985 \SpecialChar ~
25986 \SpecialChar ~
25987 \SpecialChar ~
25988 \SpecialChar ~
25989 \SpecialChar ~
25990 \SpecialChar ~
25991 given or display frame arg
25992  
25993 \newline
25994 ;;\SpecialChar ~
25995 \SpecialChar ~
25996 \SpecialChar ~
25997 \SpecialChar ~
25998 \SpecialChar ~
25999 \SpecialChar ~
26000 \SpecialChar ~
26001 \SpecialChar ~
26002 \SpecialChar ~
26003 \SpecialChar ~
26004 \SpecialChar ~
26005 \SpecialChar ~
26006 \SpecialChar ~
26007 \SpecialChar ~
26008 \SpecialChar ~
26009 \SpecialChar ~
26010 \SpecialChar ~
26011 \SpecialChar ~
26012 \SpecialChar ~
26013 \SpecialChar ~
26014 \SpecialChar ~
26015 \SpecialChar ~
26016 \SpecialChar ~
26017 \SpecialChar ~
26018 \SpecialChar ~
26019 \SpecialChar ~
26020 \SpecialChar ~
26021 \SpecialChar ~
26022 \SpecialChar ~
26023 \SpecialChar ~
26024 \SpecialChar ~
26025 \SpecialChar ~
26026 \SpecialChar ~
26027 \SpecialChar ~
26028 \SpecialChar ~
26029 \SpecialChar ~
26030 \SpecialChar ~
26031 \SpecialChar ~
26032 \SpecialChar ~
26033 \SpecialChar ~
26034 \SpecialChar ~
26035 \SpecialChar ~
26036 \SpecialChar ~
26037 \SpecialChar ~
26038 \SpecialChar ~
26039 \SpecialChar ~
26040 \SpecialChar ~
26041 buffer point 
26042 \newline
26043 ;;\SpecialChar ~
26044 !\SpecialChar ~
26045 \SpecialChar ~
26046 \SpecialChar ~
26047 \SpecialChar ~
26048 \SpecialChar ~
26049 \SpecialChar ~
26050 \SpecialChar ~
26051 \SpecialChar ~
26052 \SpecialChar ~
26053 \SpecialChar ~
26054 \SpecialChar ~
26055 \SpecialChar ~
26056 \SpecialChar ~
26057 \SpecialChar ~
26058 \SpecialChar ~
26059 sdcdbsrc-goto-sdcdb\SpecialChar ~
26060 \SpecialChar ~
26061 \SpecialChar ~
26062 \SpecialChar ~
26063 \SpecialChar ~
26064 \SpecialChar ~
26065 \SpecialChar ~
26066 \SpecialChar ~
26067 \SpecialChar ~
26068 \SpecialChar ~
26069 Goto the SDCDB output buffer 
26070 \newline
26071 ;;\SpecialChar ~
26072 p\SpecialChar ~
26073 \SpecialChar ~
26074 \SpecialChar ~
26075 \SpecialChar ~
26076 \SpecialChar ~
26077 \SpecialChar ~
26078 \SpecialChar ~
26079 \SpecialChar ~
26080 \SpecialChar ~
26081 \SpecialChar ~
26082 \SpecialChar ~
26083 \SpecialChar ~
26084 \SpecialChar ~
26085 \SpecialChar ~
26086 \SpecialChar ~
26087 sdcdb-prin
26088 t-c-sexp\SpecialChar ~
26089 \SpecialChar ~
26090 \SpecialChar ~
26091 \SpecialChar ~
26092 \SpecialChar ~
26093 \SpecialChar ~
26094 \SpecialChar ~
26095 \SpecialChar ~
26096 \SpecialChar ~
26097 \SpecialChar ~
26098 \SpecialChar ~
26099 SDCDB print command for data at 
26100 \newline
26101 ;;\SpecialChar ~
26102 \SpecialChar ~
26103 \SpecialChar ~
26104 \SpecialChar ~
26105 \SpecialChar ~
26106 \SpecialChar ~
26107 \SpecialChar ~
26108 \SpecialChar ~
26109 \SpecialChar ~
26110 \SpecialChar ~
26111 \SpecialChar ~
26112 \SpecialChar ~
26113 \SpecialChar ~
26114 \SpecialChar ~
26115 \SpecialChar ~
26116 \SpecialChar ~
26117 \SpecialChar ~
26118 \SpecialChar ~
26119 \SpecialChar ~
26120 \SpecialChar ~
26121 \SpecialChar ~
26122 \SpecialChar ~
26123 \SpecialChar ~
26124 \SpecialChar ~
26125 \SpecialChar ~
26126 \SpecialChar ~
26127 \SpecialChar ~
26128 \SpecialChar ~
26129 \SpecialChar ~
26130 \SpecialChar ~
26131 \SpecialChar ~
26132 \SpecialChar ~
26133 \SpecialChar ~
26134 \SpecialChar ~
26135 \SpecialChar ~
26136 \SpecialChar ~
26137 \SpecialChar ~
26138 \SpecialChar ~
26139 \SpecialChar ~
26140 \SpecialChar ~
26141 \SpecialChar ~
26142 \SpecialChar ~
26143 \SpecialChar ~
26144 \SpecialChar ~
26145 \SpecialChar ~
26146 \SpecialChar ~
26147 \SpecialChar ~
26148 buffer point 
26149 \newline
26150 ;;\SpecialChar ~
26151 g\SpecialChar ~
26152 \SpecialChar ~
26153 \SpecialChar ~
26154 \SpecialChar ~
26155 \SpecialChar ~
26156 \SpecialChar ~
26157 \SpecialChar ~
26158 \SpecialChar ~
26159 \SpecialChar ~
26160 \SpecialChar ~
26161 \SpecialChar ~
26162 \SpecialChar ~
26163 \SpecialChar ~
26164 \SpecialChar ~
26165 \SpecialChar ~
26166 sdcdbsrc-goto-sdcdb\SpecialChar ~
26167 \SpecialChar ~
26168 \SpecialChar ~
26169 \SpecialChar ~
26170 \SpecialChar ~
26171 \SpecialChar ~
26172 \SpecialChar ~
26173 \SpecialChar ~
26174 \SpecialChar ~
26175 \SpecialChar ~
26176 Got
26177 o the SDCDB output buffer 
26178 \newline
26179 ;;\SpecialChar ~
26180 t\SpecialChar ~
26181 \SpecialChar ~
26182 \SpecialChar ~
26183 \SpecialChar ~
26184 \SpecialChar ~
26185 \SpecialChar ~
26186 \SpecialChar ~
26187 \SpecialChar ~
26188 \SpecialChar ~
26189 \SpecialChar ~
26190 \SpecialChar ~
26191 \SpecialChar ~
26192 \SpecialChar ~
26193 \SpecialChar ~
26194 \SpecialChar ~
26195 sdcdbsrc-mode\SpecialChar ~
26196 \SpecialChar ~
26197 \SpecialChar ~
26198 \SpecialChar ~
26199 \SpecialChar ~
26200 \SpecialChar ~
26201 \SpecialChar ~
26202 \SpecialChar ~
26203 \SpecialChar ~
26204 \SpecialChar ~
26205 \SpecialChar ~
26206 \SpecialChar ~
26207 \SpecialChar ~
26208 \SpecialChar ~
26209 \SpecialChar ~
26210 \SpecialChar ~
26211 Toggles Sdcdbsrc mode (turns it
26212  off) 
26213 \newline
26214 ;; 
26215 \newline
26216 ;;\SpecialChar ~
26217 C-c\SpecialChar ~
26218 C-f\SpecialChar ~
26219 \SpecialChar ~
26220 \SpecialChar ~
26221 \SpecialChar ~
26222 \SpecialChar ~
26223 \SpecialChar ~
26224 \SpecialChar ~
26225 \SpecialChar ~
26226 \SpecialChar ~
26227 sdcdb-finish-from-src\SpecialChar ~
26228 \SpecialChar ~
26229 \SpecialChar ~
26230 \SpecialChar ~
26231 \SpecialChar ~
26232 \SpecialChar ~
26233 \SpecialChar ~
26234 \SpecialChar ~
26235 SDCDB finish command 
26236 \newline
26237 ;; 
26238 \newline
26239 ;;\SpecialChar ~
26240 C-x\SpecialChar ~
26241 SPC\SpecialChar ~
26242 \SpecialChar ~
26243 \SpecialChar ~
26244 \SpecialChar ~
26245 \SpecialChar ~
26246 \SpecialChar ~
26247 \SpecialChar ~
26248 \SpecialChar ~
26249 \SpecialChar ~
26250 sdcdb-brea
26251 k\SpecialChar ~
26252 \SpecialChar ~
26253 \SpecialChar ~
26254 \SpecialChar ~
26255 \SpecialChar ~
26256 \SpecialChar ~
26257 \SpecialChar ~
26258 \SpecialChar ~
26259 \SpecialChar ~
26260 \SpecialChar ~
26261 \SpecialChar ~
26262 \SpecialChar ~
26263 \SpecialChar ~
26264 \SpecialChar ~
26265 \SpecialChar ~
26266 \SpecialChar ~
26267 \SpecialChar ~
26268 \SpecialChar ~
26269 Set break for line with point 
26270 \newline
26271 ;;\SpecialChar ~
26272 ESC\SpecialChar ~
26273 t\SpecialChar ~
26274 \SpecialChar ~
26275 \SpecialChar ~
26276 \SpecialChar ~
26277 \SpecialChar ~
26278 \SpecialChar ~
26279 \SpecialChar ~
26280 \SpecialChar ~
26281 \SpecialChar ~
26282 \SpecialChar ~
26283 \SpecialChar ~
26284 sdcdbsrc-mode\SpecialChar ~
26285 \SpecialChar ~
26286 \SpecialChar ~
26287 \SpecialChar ~
26288 \SpecialChar ~
26289 \SpecialChar ~
26290 \SpecialChar ~
26291 \SpecialChar ~
26292 \SpecialChar ~
26293 \SpecialChar ~
26294 \SpecialChar ~
26295 \SpecialChar ~
26296 \SpecialChar ~
26297 \SpecialChar ~
26298 \SpecialChar ~
26299 \SpecialChar ~
26300 Toggle Sdcdbsrc mode 
26301 \newline
26302 ;;\SpecialChar ~
26303 ESC\SpecialChar ~
26304 m\SpecialChar ~
26305 \SpecialChar ~
26306 \SpecialChar ~
26307 \SpecialChar ~
26308 \SpecialChar ~
26309 \SpecialChar ~
26310 \SpecialChar ~
26311 \SpecialChar ~
26312 \SpecialChar ~
26313 \SpecialChar ~
26314 \SpecialChar ~
26315 sdc
26316 dbsrc-srcmode\SpecialChar ~
26317 \SpecialChar ~
26318 \SpecialChar ~
26319 \SpecialChar ~
26320 \SpecialChar ~
26321 \SpecialChar ~
26322 \SpecialChar ~
26323 \SpecialChar ~
26324 \SpecialChar ~
26325 \SpecialChar ~
26326 \SpecialChar ~
26327 \SpecialChar ~
26328 \SpecialChar ~
26329 Toggle list mode 
26330 \newline
26331 ;; 
26332 \newline
26333
26334 \family default
26335
26336
26337
26338 \layout Chapter
26339 TIPS
26340
26341 \layout Standard
26342 Here are a few guidelines that will help the compiler generate more efficient
26343  code, some of the tips are specific to this compiler others are generally
26344  good programming practice.
26345
26346 \layout Itemize
26347 Use the smallest data type to represent your data-value.
26348  If it is known in advance that the value is going to be less than 256 then
26349  use an 'unsigned char' instead of a 'short' or 'int'.
26350  Please note, that ANSI C requires both signed and unsigned chars to be
26351  promoted to 'signed int'
26352 \begin_inset LatexCommand \index{promotion to signed int}
26353
26354 \end_inset
26355
26356
26357 \begin_inset Marginal
26358 collapsed true
26359
26360 \layout Standard
26361
26362 \series bold
26363 \SpecialChar ~
26364 !
26365
26366 \end_inset
26367
26368  before doing any operation.
26369  This promotion
26370 \begin_inset LatexCommand \index{type promotion}
26371
26372 \end_inset
26373
26374
26375 \begin_inset LatexCommand \label{type promotion}
26376
26377 \end_inset
26378
26379  can be omitted, if the result is the same.
26380  The effect of the promotion rules together with the sign-extension is often
26381  surprising:
26382
26383 \begin_deeper
26384 \layout Verse
26385
26386 \family typewriter
26387 unsigned char uc = 0xfe;
26388 \newline
26389 if (uc * uc < 0) /* this is true! */
26390 \newline
26391 {
26392 \newline
26393 \SpecialChar ~
26394 \SpecialChar ~
26395 \SpecialChar ~
26396 \SpecialChar ~
26397 ....
26398 \newline
26399 }
26400
26401 \layout Standard
26402
26403 \family typewriter
26404 uc * uc
26405 \family default
26406  is evaluated as 
26407 \family typewriter
26408 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
26409 \family default
26410 .
26411  
26412 \newline
26413 Another one:
26414
26415 \layout Verse
26416
26417 \family typewriter
26418 (unsigned char) -12 / (signed char) -3 = ...
26419
26420 \layout Standard
26421 No, the result is not 4:
26422
26423 \layout Verse
26424
26425 \family typewriter
26426 (int) (unsigned char) -12 / (int) (signed char) -3 =
26427 \newline
26428 (int) (unsigned char)
26429  0xf4 / (int) (signed char) 0xfd =
26430 \newline
26431 (int) 0x00f4 / (int) 0xfffd =
26432 \newline
26433 (int) 0x00f4
26434  / (int) 0xfffd =
26435 \newline
26436 (int) 244 / (int) -3 =
26437 \newline
26438 (int) -81 = (int) 0xffaf;
26439
26440 \layout Standard
26441 Don't complain, that gcc gives you a different result.
26442  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
26443  Therefore the results are different.
26444 \newline
26445 From 
26446 \begin_inset Quotes sld
26447 \end_inset
26448
26449 comp.lang.c FAQ
26450 \begin_inset Quotes srd
26451 \end_inset
26452
26453 :
26454
26455 \layout Quote
26456
26457 \emph on
26458 If well-defined overflow characteristics are important and negative values
26459  are not, or if you want to steer clear of sign-extension problems when
26460  manipulating bits or bytes, use one of the corresponding unsigned types.
26461  (Beware when mixing signed and unsigned values in expressions, though.)
26462 \newline
26463 Although
26464  character types (especially unsigned char) can be used as "tiny" integers,
26465  doing so is sometimes more trouble than it's worth, due to unpredictable
26466  sign extension and increased code size.
26467
26468 \end_deeper
26469 \layout Itemize
26470 Use unsigned when it is known in advance that the value is not going to
26471  be negative.
26472  This helps especially if you are doing division or multiplication, bit-shifting
26473  or are using an array index.
26474
26475 \layout Itemize
26476 NEVER jump into a LOOP.
26477
26478 \layout Itemize
26479 Declare the variables to be local
26480 \begin_inset LatexCommand \index{local variables}
26481
26482 \end_inset
26483
26484  whenever possible, especially loop control variables (induction).
26485
26486 \layout Itemize
26487 Have a look at the assembly listing to get a 
26488 \begin_inset Quotes sld
26489 \end_inset
26490
26491 feeling
26492 \begin_inset Quotes srd
26493 \end_inset
26494
26495  for the code generation.
26496
26497 \layout Section
26498 Porting code from or to other compilers
26499 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
26500
26501 \end_inset
26502
26503
26504
26505 \layout Itemize
26506 check whether endianness of the compilers differs and adapt where needed.
26507
26508 \layout Itemize
26509 check the device specific header files
26510 \begin_inset LatexCommand \index{Header files}
26511
26512 \end_inset
26513
26514
26515 \begin_inset LatexCommand \index{Include files}
26516
26517 \end_inset
26518
26519  for compiler specific syntax.
26520  Eventually include the file <compiler.h
26521 \begin_inset LatexCommand \index{compiler.h (include file)}
26522
26523 \end_inset
26524
26525
26526 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
26527
26528 \end_inset
26529
26530  to allow using common header files.
26531  (see f.e.
26532  cc2510fx.h 
26533 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
26534
26535 \end_inset
26536
26537 ).
26538
26539 \layout Itemize
26540 check whether the startup code contains the correct initialization (watchdog,
26541  peripherals).
26542
26543 \layout Itemize
26544 check whether the sizes of short, int, long match.
26545
26546 \layout Itemize
26547 check if some 16 or 32 bit hardware registers require a specific addressing
26548  order (least significant or most significant byte first) and adapt if needed
26549  (
26550 \emph on
26551 first
26552 \emph default
26553  and 
26554 \emph on
26555 last
26556 \emph default
26557  relate to time and not to lower/upper memory location here, so this is
26558  
26559 \emph on
26560 not
26561 \emph default
26562  the same as endianness).
26563
26564 \layout Itemize
26565 check whether the keyword 
26566 \emph on
26567 volatile
26568 \emph default
26569  is used where needed.
26570  The compilers might differ in their optimization characteristics (as different
26571  versions of the same compiler might also use more clever optimizations
26572  this is good idea anyway).
26573  See section 
26574 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
26575
26576 \end_inset
26577
26578 .
26579
26580 \layout Itemize
26581 check that the compilers are not told to supress warnings.
26582
26583 \layout Itemize
26584 check and convert compiler specific extensions (interrupts, memory areas,
26585  pragmas etc.).
26586
26587 \layout Itemize
26588 check for differences in type promotion.
26589  Especially check for math operations on 
26590 \family typewriter
26591 char
26592 \family default
26593  or 
26594 \family typewriter
26595 unsigned char
26596 \family default
26597  variables.
26598  For the sake of C99 compatibility SDCC will probably promote these to 
26599 \family typewriter
26600 int
26601 \family default
26602  more often than other compilers.
26603  Eventually insert explicit casts to 
26604 \family typewriter
26605 (char) 
26606 \family default
26607 or
26608 \family typewriter
26609  (unsigned char)
26610 \family default
26611 .
26612  Also check that the ~\SpecialChar ~
26613 operator
26614 \begin_inset LatexCommand \index{\~\/ Operator}
26615
26616 \end_inset
26617
26618  is not used on 
26619 \family typewriter
26620 bit
26621 \begin_inset LatexCommand \index{bit}
26622
26623 \end_inset
26624
26625
26626 \family default
26627  variables, use the !\SpecialChar ~
26628 operator instead.
26629  See sections 
26630 \begin_inset LatexCommand \ref{type promotion}
26631
26632 \end_inset
26633
26634  and 
26635 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26636
26637 \end_inset
26638
26639 .
26640
26641 \layout Itemize
26642 check the assembly code generated for interrupt routines (f.e.
26643  for calls to possibly non-reentrant library functions).
26644
26645 \layout Itemize
26646 check whether timing loops result in proper timing (or preferably consider
26647  a rewrite of the code with timer based delays instead).
26648
26649 \layout Itemize
26650 check for differences in printf parameters (some compilers push (va_arg
26651 \begin_inset LatexCommand \index{vararg, va\_arg}
26652
26653 \end_inset
26654
26655 ) char variables as 
26656 \family typewriter
26657 int
26658 \family default
26659  others push them as 
26660 \family typewriter
26661 char
26662 \family default
26663 .
26664  See section 
26665 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26666
26667 \end_inset
26668
26669 ).
26670
26671 \layout Itemize
26672 check the resulting memory map
26673 \begin_inset LatexCommand \index{Memory map}
26674
26675 \end_inset
26676
26677 .
26678  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
26679 ly idata, pdata, xdata).
26680  Eventually check if unexpected library functions are included.
26681
26682 \layout Section
26683 Tools
26684 \begin_inset LatexCommand \index{Tools}
26685
26686 \end_inset
26687
26688  included in the distribution
26689
26690 \layout Standard
26691 \align left
26692 \begin_inset Tabular
26693 <lyxtabular version="3" rows="12" columns="3">
26694 <features>
26695 <column alignment="left" valignment="top" leftline="true" width="0pt">
26696 <column alignment="left" valignment="top" leftline="true" width="0pt">
26697 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26698 <row topline="true" bottomline="true">
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26700 \begin_inset Text
26701
26702 \layout Standard
26703
26704 \series bold
26705 Name
26706
26707 \end_inset
26708 </cell>
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_inset Text
26711
26712 \layout Standard
26713
26714 \series bold
26715 Purpose
26716
26717 \end_inset
26718 </cell>
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26720 \begin_inset Text
26721
26722 \layout Standard
26723
26724 \series bold
26725 Directory
26726
26727 \end_inset
26728 </cell>
26729 </row>
26730 <row topline="true">
26731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26732 \begin_inset Text
26733
26734 \layout Standard
26735 uCsim
26736 \begin_inset LatexCommand \index{uCsim}
26737
26738 \end_inset
26739
26740
26741
26742 \end_inset
26743 </cell>
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26745 \begin_inset Text
26746
26747 \layout Standard
26748 Simulator for various architectures
26749
26750 \end_inset
26751 </cell>
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26753 \begin_inset Text
26754
26755 \layout Standard
26756 sdcc/sim/ucsim
26757
26758 \end_inset
26759 </cell>
26760 </row>
26761 <row topline="true">
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26763 \begin_inset Text
26764
26765 \layout Standard
26766 keil2sdcc.pl
26767
26768 \end_inset
26769 </cell>
26770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26771 \begin_inset Text
26772
26773 \layout Standard
26774 header file
26775 \begin_inset LatexCommand \index{Header files}
26776
26777 \end_inset
26778
26779
26780 \begin_inset LatexCommand \index{Include files}
26781
26782 \end_inset
26783
26784  conversion
26785
26786 \end_inset
26787 </cell>
26788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26789 \begin_inset Text
26790
26791 \layout Standard
26792 sdcc/support/scripts
26793
26794 \end_inset
26795 </cell>
26796 </row>
26797 <row topline="true">
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26799 \begin_inset Text
26800
26801 \layout Standard
26802 mh2h.c
26803
26804 \end_inset
26805 </cell>
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26807 \begin_inset Text
26808
26809 \layout Standard
26810 header file conversion
26811
26812 \end_inset
26813 </cell>
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26815 \begin_inset Text
26816
26817 \layout Standard
26818 sdcc/support/scripts
26819
26820 \end_inset
26821 </cell>
26822 </row>
26823 <row topline="true">
26824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26825 \begin_inset Text
26826
26827 \layout Standard
26828 as-gbz80
26829
26830 \end_inset
26831 </cell>
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26833 \begin_inset Text
26834
26835 \layout Standard
26836 Assembler
26837
26838 \end_inset
26839 </cell>
26840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26841 \begin_inset Text
26842
26843 \layout Standard
26844
26845 \family roman
26846 \series medium
26847 \shape up
26848 \size normal
26849 \emph off
26850 \bar no
26851 \noun off
26852 \color none
26853 sdcc/bin
26854
26855 \end_inset
26856 </cell>
26857 </row>
26858 <row topline="true">
26859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26860 \begin_inset Text
26861
26862 \layout Standard
26863 as-z80
26864
26865 \end_inset
26866 </cell>
26867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26868 \begin_inset Text
26869
26870 \layout Standard
26871 Assembler
26872
26873 \end_inset
26874 </cell>
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26876 \begin_inset Text
26877
26878 \layout Standard
26879
26880 \family roman
26881 \series medium
26882 \shape up
26883 \size normal
26884 \emph off
26885 \bar no
26886 \noun off
26887 \color none
26888 sdcc/bin
26889
26890 \end_inset
26891 </cell>
26892 </row>
26893 <row topline="true">
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26895 \begin_inset Text
26896
26897 \layout Standard
26898 asx8051
26899
26900 \end_inset
26901 </cell>
26902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26903 \begin_inset Text
26904
26905 \layout Standard
26906 Assembler
26907
26908 \end_inset
26909 </cell>
26910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26911 \begin_inset Text
26912
26913 \layout Standard
26914
26915 \family roman
26916 \series medium
26917 \shape up
26918 \size normal
26919 \emph off
26920 \bar no
26921 \noun off
26922 \color none
26923 sdcc/bin
26924
26925 \end_inset
26926 </cell>
26927 </row>
26928 <row topline="true">
26929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26930 \begin_inset Text
26931
26932 \layout Standard
26933 SDCDB
26934
26935 \end_inset
26936 </cell>
26937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26938 \begin_inset Text
26939
26940 \layout Standard
26941 Simulator
26942
26943 \end_inset
26944 </cell>
26945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26946 \begin_inset Text
26947
26948 \layout Standard
26949
26950 \family roman
26951 \series medium
26952 \shape up
26953 \size normal
26954 \emph off
26955 \bar no
26956 \noun off
26957 \color none
26958 sdcc/bin
26959
26960 \end_inset
26961 </cell>
26962 </row>
26963 <row topline="true">
26964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26965 \begin_inset Text
26966
26967 \layout Standard
26968 aslink
26969
26970 \end_inset
26971 </cell>
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26973 \begin_inset Text
26974
26975 \layout Standard
26976 Linker
26977
26978 \end_inset
26979 </cell>
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_inset Text
26982
26983 \layout Standard
26984
26985 \family roman
26986 \series medium
26987 \shape up
26988 \size normal
26989 \emph off
26990 \bar no
26991 \noun off
26992 \color none
26993 sdcc/bin
26994
26995 \end_inset
26996 </cell>
26997 </row>
26998 <row topline="true">
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27000 \begin_inset Text
27001
27002 \layout Standard
27003 link-z80
27004
27005 \end_inset
27006 </cell>
27007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27008 \begin_inset Text
27009
27010 \layout Standard
27011 Linker
27012
27013 \end_inset
27014 </cell>
27015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27016 \begin_inset Text
27017
27018 \layout Standard
27019
27020 \family roman
27021 \series medium
27022 \shape up
27023 \size normal
27024 \emph off
27025 \bar no
27026 \noun off
27027 \color none
27028 sdcc/bin
27029
27030 \end_inset
27031 </cell>
27032 </row>
27033 <row topline="true">
27034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27035 \begin_inset Text
27036
27037 \layout Standard
27038 link-gbz80
27039
27040 \end_inset
27041 </cell>
27042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27043 \begin_inset Text
27044
27045 \layout Standard
27046 Linker
27047
27048 \end_inset
27049 </cell>
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27051 \begin_inset Text
27052
27053 \layout Standard
27054
27055 \family roman
27056 \series medium
27057 \shape up
27058 \size normal
27059 \emph off
27060 \bar no
27061 \noun off
27062 \color none
27063 sdcc/bin
27064
27065 \end_inset
27066 </cell>
27067 </row>
27068 <row topline="true" bottomline="true">
27069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27070 \begin_inset Text
27071
27072 \layout Standard
27073 packihx
27074
27075 \end_inset
27076 </cell>
27077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27078 \begin_inset Text
27079
27080 \layout Standard
27081 Intel Hex packer 
27082 \begin_inset LatexCommand \index{packihx (tool)}
27083
27084 \end_inset
27085
27086
27087
27088 \end_inset
27089 </cell>
27090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27091 \begin_inset Text
27092
27093 \layout Standard
27094
27095 \family roman
27096 \series medium
27097 \shape up
27098 \size normal
27099 \emph off
27100 \bar no
27101 \noun off
27102 \color none
27103 sdcc/bin
27104
27105 \end_inset
27106 </cell>
27107 </row>
27108 </lyxtabular>
27109
27110 \end_inset
27111
27112
27113 \newline
27114
27115
27116 \layout Section
27117 Documentation
27118 \begin_inset LatexCommand \index{Documentation}
27119
27120 \end_inset
27121
27122  included in the distribution
27123
27124 \layout Standard
27125 \align left
27126 \begin_inset Tabular
27127 <lyxtabular version="3" rows="10" columns="2">
27128 <features>
27129 <column alignment="block" valignment="top" leftline="true" width="40col%">
27130 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
27131 <row topline="true" bottomline="true" endhead="true">
27132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27133 \begin_inset Text
27134
27135 \layout Standard
27136
27137 \series bold
27138 Subject / Title
27139
27140 \end_inset
27141 </cell>
27142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27143 \begin_inset Text
27144
27145 \layout Standard
27146
27147 \series bold
27148 Filename / Where to get
27149
27150 \end_inset
27151 </cell>
27152 </row>
27153 <row topline="true">
27154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27155 \begin_inset Text
27156
27157 \layout Standard
27158 SDCC Compiler User Guide
27159
27160 \end_inset
27161 </cell>
27162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27163 \begin_inset Text
27164
27165 \layout Standard
27166 You're reading it right now
27167 \emph on
27168  \SpecialChar ~
27169 \SpecialChar ~
27170 \SpecialChar ~
27171
27172 \hfill
27173 online at:
27174 \emph default
27175
27176 \newline
27177
27178 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
27179
27180 \end_inset
27181
27182
27183
27184 \end_inset
27185 </cell>
27186 </row>
27187 <row topline="true">
27188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27189 \begin_inset Text
27190
27191 \layout Standard
27192 Changelog of SDCC
27193
27194 \end_inset
27195 </cell>
27196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27197 \begin_inset Text
27198
27199 \layout Standard
27200 sdcc/Changelog
27201 \emph on
27202  \SpecialChar ~
27203 \SpecialChar ~
27204 \SpecialChar ~
27205
27206 \hfill
27207 online at:
27208 \emph default
27209
27210 \newline
27211
27212 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
27213
27214 \end_inset
27215
27216
27217
27218 \end_inset
27219 </cell>
27220 </row>
27221 <row topline="true">
27222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27223 \begin_inset Text
27224
27225 \layout Standard
27226 ASXXXX
27227 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
27228
27229 \end_inset
27230
27231
27232 \begin_inset LatexCommand \index{Assembler documentation}
27233
27234 \end_inset
27235
27236  Assemblers and
27237 \newline
27238 ASLINK
27239 \begin_inset LatexCommand \index{aslink}
27240
27241 \end_inset
27242
27243
27244 \begin_inset LatexCommand \index{Linker documentation}
27245
27246 \end_inset
27247
27248  Relocating Linker
27249
27250 \end_inset
27251 </cell>
27252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27253 \begin_inset Text
27254
27255 \layout Standard
27256 sdcc/as/doc/asxhtm.html 
27257 \emph on
27258 \SpecialChar ~
27259 \SpecialChar ~
27260 \SpecialChar ~
27261
27262 \hfill
27263 online at:
27264 \emph default
27265
27266 \newline
27267
27268 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
27269
27270 \end_inset
27271
27272
27273
27274 \end_inset
27275 </cell>
27276 </row>
27277 <row topline="true">
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27279 \begin_inset Text
27280
27281 \layout Standard
27282 SDCC regression test
27283 \begin_inset LatexCommand \index{Regression test}
27284
27285 \end_inset
27286
27287
27288
27289 \end_inset
27290 </cell>
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27292 \begin_inset Text
27293
27294 \layout Standard
27295 sdcc/doc/test_suite_spec.pdf 
27296 \emph on
27297 \SpecialChar ~
27298 \SpecialChar ~
27299 \SpecialChar ~
27300
27301 \hfill
27302 online at:
27303 \emph default
27304
27305 \newline
27306
27307 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
27308
27309 \end_inset
27310
27311
27312
27313 \end_inset
27314 </cell>
27315 </row>
27316 <row topline="true">
27317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27318 \begin_inset Text
27319
27320 \layout Standard
27321 Various notes
27322
27323 \end_inset
27324 </cell>
27325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27326 \begin_inset Text
27327
27328 \layout Standard
27329 sdcc/doc/* 
27330 \emph on
27331 \SpecialChar ~
27332 \SpecialChar ~
27333 \SpecialChar ~
27334
27335 \hfill
27336 online at:
27337 \emph default
27338
27339 \newline
27340
27341 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
27342
27343 \end_inset
27344
27345
27346
27347 \end_inset
27348 </cell>
27349 </row>
27350 <row topline="true">
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27352 \begin_inset Text
27353
27354 \layout Standard
27355 Notes on debugging with SDCDB
27356 \begin_inset LatexCommand \index{SDCDB (debugger)}
27357
27358 \end_inset
27359
27360
27361
27362 \end_inset
27363 </cell>
27364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27365 \begin_inset Text
27366
27367 \layout Standard
27368 sdcc/debugger/README 
27369 \emph on
27370 \SpecialChar ~
27371 \SpecialChar ~
27372 \SpecialChar ~
27373
27374 \hfill
27375 online at
27376 \emph default
27377 :
27378 \newline
27379
27380 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
27381
27382 \end_inset
27383
27384
27385
27386 \end_inset
27387 </cell>
27388 </row>
27389 <row topline="true">
27390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27391 \begin_inset Text
27392
27393 \layout Standard
27394 uCsim
27395 \begin_inset LatexCommand \index{uCsim}
27396
27397 \end_inset
27398
27399  Software simulator for microcontrollers
27400
27401 \end_inset
27402 </cell>
27403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27404 \begin_inset Text
27405
27406 \layout Standard
27407
27408 \family roman
27409 \series medium
27410 \shape up
27411 \size normal
27412 \emph off
27413 \bar no
27414 \noun off
27415 \color none
27416 sdcc/sim/ucsim/doc
27417 \family default
27418 \series default
27419 \shape default
27420 \size default
27421 \emph default
27422 \bar default
27423 \noun default
27424 /index.html 
27425 \emph on
27426 \SpecialChar ~
27427 \SpecialChar ~
27428 \SpecialChar ~
27429
27430 \hfill
27431 online at:
27432 \emph default
27433
27434 \newline
27435
27436 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
27437
27438 \end_inset
27439
27440
27441
27442 \end_inset
27443 </cell>
27444 </row>
27445 <row topline="true">
27446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27447 \begin_inset Text
27448
27449 \layout Standard
27450 Temporary notes on the pic16
27451 \begin_inset LatexCommand \index{PIC16}
27452
27453 \end_inset
27454
27455  port
27456
27457 \end_inset
27458 </cell>
27459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27460 \begin_inset Text
27461
27462 \layout Standard
27463 sdcc/src/pic16/NOTES 
27464 \emph on
27465 \SpecialChar ~
27466 \SpecialChar ~
27467 \SpecialChar ~
27468
27469 \hfill
27470 online at:
27471 \newline
27472
27473 \emph default
27474
27475 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
27476
27477 \end_inset
27478
27479
27480
27481 \end_inset
27482 </cell>
27483 </row>
27484 <row topline="true" bottomline="true">
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27486 \begin_inset Text
27487
27488 \layout Standard
27489 SDCC internal documentation (debugging file format)
27490
27491 \end_inset
27492 </cell>
27493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27494 \begin_inset Text
27495
27496 \layout Standard
27497 sdcc/doc/
27498 \family roman
27499 \series medium
27500 \shape up
27501 \size normal
27502 \emph off
27503 \bar no
27504 \noun off
27505 \color none
27506 cdbfileformat.pd
27507 \family default
27508 \series default
27509 \shape default
27510 \size default
27511 \emph default
27512 \bar default
27513 \noun default
27514 f
27515 \emph on
27516  \SpecialChar ~
27517 \SpecialChar ~
27518 \SpecialChar ~
27519
27520 \hfill
27521 online at:
27522 \emph default
27523
27524 \newline
27525
27526 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
27527
27528 \end_inset
27529
27530
27531
27532 \end_inset
27533 </cell>
27534 </row>
27535 </lyxtabular>
27536
27537 \end_inset
27538
27539
27540 \newline
27541
27542
27543 \layout Section
27544 Related open source tools
27545 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
27546
27547 \end_inset
27548
27549
27550 \begin_inset LatexCommand \index{Related tools}
27551
27552 \end_inset
27553
27554
27555
27556 \layout Standard
27557 \align left
27558 \begin_inset Tabular
27559 <lyxtabular version="3" rows="14" columns="3">
27560 <features>
27561 <column alignment="left" valignment="top" leftline="true" width="0pt">
27562 <column alignment="block" valignment="top" leftline="true" width="30line%">
27563 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27564 <row topline="true" bottomline="true">
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27566 \begin_inset Text
27567
27568 \layout Standard
27569
27570 \series bold
27571 Name
27572
27573 \end_inset
27574 </cell>
27575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27576 \begin_inset Text
27577
27578 \layout Standard
27579
27580 \series bold
27581 Purpose
27582
27583 \end_inset
27584 </cell>
27585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27586 \begin_inset Text
27587
27588 \layout Standard
27589
27590 \series bold
27591 Where to get
27592
27593 \end_inset
27594 </cell>
27595 </row>
27596 <row topline="true">
27597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27598 \begin_inset Text
27599
27600 \layout Standard
27601 gpsim
27602 \begin_inset LatexCommand \index{gpsim (pic simulator)}
27603
27604 \end_inset
27605
27606
27607
27608 \end_inset
27609 </cell>
27610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27611 \begin_inset Text
27612
27613 \layout Standard
27614 PIC simulator
27615
27616 \end_inset
27617 </cell>
27618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27619 \begin_inset Text
27620
27621 \layout Standard
27622 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
27623
27624 \end_inset
27625
27626
27627
27628 \end_inset
27629 </cell>
27630 </row>
27631 <row topline="true">
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27633 \begin_inset Text
27634
27635 \layout Standard
27636 gputils
27637 \begin_inset LatexCommand \index{gputils (pic tools)}
27638
27639 \end_inset
27640
27641
27642
27643 \end_inset
27644 </cell>
27645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27646 \begin_inset Text
27647
27648 \layout Standard
27649 GNU PIC utilities
27650
27651 \end_inset
27652 </cell>
27653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27654 \begin_inset Text
27655
27656 \layout Standard
27657 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
27658
27659 \end_inset
27660
27661
27662
27663 \end_inset
27664 </cell>
27665 </row>
27666 <row topline="true">
27667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27668 \begin_inset Text
27669
27670 \layout Standard
27671 flP5
27672
27673 \end_inset
27674 </cell>
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27676 \begin_inset Text
27677
27678 \layout Standard
27679 PIC programmer
27680
27681 \end_inset
27682 </cell>
27683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27684 \begin_inset Text
27685
27686 \layout Standard
27687 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
27688
27689 \end_inset
27690
27691
27692
27693 \end_inset
27694 </cell>
27695 </row>
27696 <row topline="true">
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27698 \begin_inset Text
27699
27700 \layout Standard
27701 ec2drv/newcdb
27702
27703 \end_inset
27704 </cell>
27705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27706 \begin_inset Text
27707
27708 \layout Standard
27709 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
27710  (Unix only)
27711
27712 \end_inset
27713 </cell>
27714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27715 \begin_inset Text
27716
27717 \layout Standard
27718 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
27719
27720 \end_inset
27721
27722
27723
27724 \end_inset
27725 </cell>
27726 </row>
27727 <row topline="true">
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27729 \begin_inset Text
27730
27731 \layout Standard
27732 indent
27733 \begin_inset LatexCommand \index{indent (source formatting tool)}
27734
27735 \end_inset
27736
27737
27738
27739 \end_inset
27740 </cell>
27741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27742 \begin_inset Text
27743
27744 \layout Standard
27745 Formats C source - Master of the white spaces
27746
27747 \end_inset
27748 </cell>
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27750 \begin_inset Text
27751
27752 \layout Standard
27753 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
27754
27755 \end_inset
27756
27757
27758
27759 \end_inset
27760 </cell>
27761 </row>
27762 <row topline="true">
27763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27764 \begin_inset Text
27765
27766 \layout Standard
27767 srecord
27768 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
27769
27770 \end_inset
27771
27772
27773
27774 \end_inset
27775 </cell>
27776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27777 \begin_inset Text
27778
27779 \layout Standard
27780 Object file conversion, checksumming, ...
27781
27782 \end_inset
27783 </cell>
27784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27785 \begin_inset Text
27786
27787 \layout Standard
27788 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
27789
27790 \end_inset
27791
27792
27793
27794 \end_inset
27795 </cell>
27796 </row>
27797 <row topline="true">
27798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27799 \begin_inset Text
27800
27801 \layout Standard
27802 objdump
27803 \begin_inset LatexCommand \index{objdump (tool)}
27804
27805 \end_inset
27806
27807
27808
27809 \end_inset
27810 </cell>
27811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27812 \begin_inset Text
27813
27814 \layout Standard
27815 Object file conversion, ...
27816
27817 \end_inset
27818 </cell>
27819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27820 \begin_inset Text
27821
27822 \layout Standard
27823 Part of binutils (should be there anyway)
27824
27825 \end_inset
27826 </cell>
27827 </row>
27828 <row topline="true">
27829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27830 \begin_inset Text
27831
27832 \layout Standard
27833 cmon51
27834
27835 \end_inset
27836 </cell>
27837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27838 \begin_inset Text
27839
27840 \layout Standard
27841 8051 monitor (hex up-/download, single step, disassemble)
27842
27843 \end_inset
27844 </cell>
27845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27846 \begin_inset Text
27847
27848 \layout Standard
27849 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
27850
27851 \end_inset
27852
27853
27854
27855 \end_inset
27856 </cell>
27857 </row>
27858 <row topline="true">
27859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27860 \begin_inset Text
27861
27862 \layout Standard
27863 doxygen
27864 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27865
27866 \end_inset
27867
27868
27869
27870 \end_inset
27871 </cell>
27872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27873 \begin_inset Text
27874
27875 \layout Standard
27876 Source code documentation system
27877
27878 \end_inset
27879 </cell>
27880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27881 \begin_inset Text
27882
27883 \layout Standard
27884 \begin_inset LatexCommand \url{http://www.doxygen.org}
27885
27886 \end_inset
27887
27888
27889
27890 \end_inset
27891 </cell>
27892 </row>
27893 <row topline="true">
27894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27895 \begin_inset Text
27896
27897 \layout Standard
27898 kdevelop
27899
27900 \end_inset
27901 </cell>
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27903 \begin_inset Text
27904
27905 \layout Standard
27906 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27907
27908 \end_inset
27909 </cell>
27910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27911 \begin_inset Text
27912
27913 \layout Standard
27914 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27915
27916 \end_inset
27917
27918
27919
27920 \end_inset
27921 </cell>
27922 </row>
27923 <row topline="true">
27924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27925 \begin_inset Text
27926
27927 \layout Standard
27928 paulmon
27929
27930 \end_inset
27931 </cell>
27932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27933 \begin_inset Text
27934
27935 \layout Standard
27936 8051 monitor (hex up-/download, single step, disassemble)
27937
27938 \end_inset
27939 </cell>
27940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27941 \begin_inset Text
27942
27943 \layout Standard
27944 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27945
27946 \end_inset
27947
27948
27949
27950 \end_inset
27951 </cell>
27952 </row>
27953 <row topline="true">
27954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27955 \begin_inset Text
27956
27957 \layout Standard
27958 splint
27959 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27960
27961 \end_inset
27962
27963
27964
27965 \end_inset
27966 </cell>
27967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27968 \begin_inset Text
27969
27970 \layout Standard
27971 Statically checks c sources (see 
27972 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27973
27974 \end_inset
27975
27976 )
27977
27978 \end_inset
27979 </cell>
27980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27981 \begin_inset Text
27982
27983 \layout Standard
27984 \begin_inset LatexCommand \url{http://www.splint.org}
27985
27986 \end_inset
27987
27988
27989
27990 \end_inset
27991 </cell>
27992 </row>
27993 <row topline="true" bottomline="true">
27994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27995 \begin_inset Text
27996
27997 \layout Standard
27998 ddd
27999 \begin_inset LatexCommand \index{DDD (debugger)}
28000
28001 \end_inset
28002
28003
28004
28005 \end_inset
28006 </cell>
28007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28008 \begin_inset Text
28009
28010 \layout Standard
28011 Debugger, serves nicely as GUI to SDCDB
28012 \begin_inset LatexCommand \index{SDCDB (debugger)}
28013
28014 \end_inset
28015
28016  (Unix only)
28017
28018 \end_inset
28019 </cell>
28020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28021 \begin_inset Text
28022
28023 \layout Standard
28024 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
28025
28026 \end_inset
28027
28028
28029
28030 \end_inset
28031 </cell>
28032 </row>
28033 </lyxtabular>
28034
28035 \end_inset
28036
28037
28038 \newline
28039
28040
28041 \layout Section
28042 Related documentation / recommended reading
28043
28044 \layout Standard
28045 \align left
28046 \begin_inset Tabular
28047 <lyxtabular version="3" rows="7" columns="3">
28048 <features>
28049 <column alignment="left" valignment="top" leftline="true" width="0pt">
28050 <column alignment="left" valignment="top" leftline="true" width="0">
28051 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28052 <row topline="true" bottomline="true">
28053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28054 \begin_inset Text
28055
28056 \layout Standard
28057
28058 \series bold
28059 Name
28060
28061 \end_inset
28062 </cell>
28063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28064 \begin_inset Text
28065
28066 \layout Standard
28067
28068 \series bold
28069 Subject / Title
28070
28071 \end_inset
28072 </cell>
28073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28074 \begin_inset Text
28075
28076 \layout Standard
28077
28078 \series bold
28079 Where to get
28080
28081 \end_inset
28082 </cell>
28083 </row>
28084 <row topline="true">
28085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28086 \begin_inset Text
28087
28088 \layout Standard
28089
28090 \family roman
28091 \series medium
28092 \shape up
28093 \size normal
28094 \emph off
28095 \bar no
28096 \noun off
28097 \color none
28098 c-refcard.pdf
28099
28100 \end_inset
28101 </cell>
28102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28103 \begin_inset Text
28104
28105 \layout Standard
28106 C Reference Card
28107 \begin_inset LatexCommand \index{C Reference card}
28108
28109 \end_inset
28110
28111 , 2 pages
28112
28113 \end_inset
28114 </cell>
28115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28116 \begin_inset Text
28117
28118 \layout Standard
28119 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
28120
28121 \end_inset
28122
28123
28124
28125 \end_inset
28126 </cell>
28127 </row>
28128 <row topline="true">
28129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28130 \begin_inset Text
28131
28132 \layout Standard
28133 c-faq
28134
28135 \end_inset
28136 </cell>
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28138 \begin_inset Text
28139
28140 \layout Standard
28141 C-FAQ
28142 \begin_inset LatexCommand \index{C FAQ}
28143
28144 \end_inset
28145
28146
28147
28148 \end_inset
28149 </cell>
28150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28151 \begin_inset Text
28152
28153 \layout Standard
28154 \begin_inset LatexCommand \url{http://www.c-faq.com}
28155
28156 \end_inset
28157
28158
28159
28160 \end_inset
28161 </cell>
28162 </row>
28163 <row topline="true">
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28165 \begin_inset Text
28166
28167 \layout Standard
28168 ISO/IEC 9899:TC2
28169
28170 \end_inset
28171 </cell>
28172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28173 \begin_inset Text
28174
28175 \layout Standard
28176 \begin_inset Quotes sld
28177 \end_inset
28178
28179 C-Standard
28180 \begin_inset Quotes srd
28181 \end_inset
28182
28183
28184
28185 \end_inset
28186 </cell>
28187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28188 \begin_inset Text
28189
28190 \layout Standard
28191
28192 \size footnotesize
28193 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
28194
28195 \end_inset
28196
28197
28198
28199 \end_inset
28200 </cell>
28201 </row>
28202 <row topline="true">
28203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28204 \begin_inset Text
28205
28206 \layout Standard
28207 ISO/IEC DTR 18037
28208
28209 \end_inset
28210 </cell>
28211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28212 \begin_inset Text
28213
28214 \layout Standard
28215 \begin_inset Quotes sld
28216 \end_inset
28217
28218 Extensions for Embedded C
28219 \begin_inset Quotes srd
28220 \end_inset
28221
28222
28223
28224 \end_inset
28225 </cell>
28226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28227 \begin_inset Text
28228
28229 \layout Standard
28230
28231 \size footnotesize
28232 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
28233
28234 \end_inset
28235
28236
28237
28238 \end_inset
28239 </cell>
28240 </row>
28241 <row topline="true">
28242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28243 \begin_inset Text
28244
28245 \layout Standard
28246
28247
28248 \end_inset
28249 </cell>
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28251 \begin_inset Text
28252
28253 \layout Standard
28254 Latest datasheet of target CPU
28255
28256 \end_inset
28257 </cell>
28258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28259 \begin_inset Text
28260
28261 \layout Standard
28262 vendor
28263
28264 \end_inset
28265 </cell>
28266 </row>
28267 <row topline="true" bottomline="true">
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28269 \begin_inset Text
28270
28271 \layout Standard
28272
28273
28274 \end_inset
28275 </cell>
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28277 \begin_inset Text
28278
28279 \layout Standard
28280 Revision history of datasheet
28281
28282 \end_inset
28283 </cell>
28284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28285 \begin_inset Text
28286
28287 \layout Standard
28288 vendor
28289
28290 \end_inset
28291 </cell>
28292 </row>
28293 </lyxtabular>
28294
28295 \end_inset
28296
28297
28298 \newline
28299
28300
28301 \layout Section
28302 Application notes specifically for SDCC
28303
28304 \layout Standard
28305 SDCC makes no claims about the completeness of this list and about up-to-datenes
28306 s or correctness of the application notes
28307 \begin_inset LatexCommand \index{Application notes}
28308
28309 \end_inset
28310
28311 .
28312
28313 \layout Standard
28314 \align left
28315
28316 \size footnotesize
28317 \begin_inset Tabular
28318 <lyxtabular version="3" rows="7" columns="3">
28319 <features>
28320 <column alignment="block" valignment="top" leftline="true" width="17col%">
28321 <column alignment="block" valignment="top" leftline="true" width="27col%">
28322 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
28323 <row topline="true" bottomline="true">
28324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28325 \begin_inset Text
28326
28327 \layout Standard
28328
28329 \series bold
28330 \size footnotesize
28331 Vendor
28332
28333 \end_inset
28334 </cell>
28335 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
28336 \begin_inset Text
28337
28338 \layout Standard
28339
28340 \series bold
28341 \size footnotesize
28342 Subject / Title
28343
28344 \end_inset
28345 </cell>
28346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28347 \begin_inset Text
28348
28349 \layout Standard
28350
28351 \series bold
28352 \size footnotesize
28353 Where to get
28354
28355 \end_inset
28356 </cell>
28357 </row>
28358 <row topline="true">
28359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28360 \begin_inset Text
28361
28362 \layout Standard
28363
28364 \size footnotesize
28365 Maxim / Dallas
28366
28367 \end_inset
28368 </cell>
28369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28370 \begin_inset Text
28371
28372 \layout Standard
28373
28374 \size footnotesize
28375 Using the SDCC Compiler for the DS80C400
28376 \begin_inset LatexCommand \index{DS80C400}
28377
28378 \end_inset
28379
28380
28381
28382 \end_inset
28383 </cell>
28384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28385 \begin_inset Text
28386
28387 \layout Standard
28388
28389 \size footnotesize
28390 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
28391
28392 \end_inset
28393
28394
28395
28396 \end_inset
28397 </cell>
28398 </row>
28399 <row topline="true">
28400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28401 \begin_inset Text
28402
28403 \layout Standard
28404
28405 \size footnotesize
28406 Maxim / Dallas
28407
28408 \end_inset
28409 </cell>
28410 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
28411 \begin_inset Text
28412
28413 \layout Standard
28414
28415 \size footnotesize
28416 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
28417 \begin_inset LatexCommand \index{DS89C4x0}
28418
28419 \end_inset
28420
28421  Family of Microcontrollers
28422
28423 \end_inset
28424 </cell>
28425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28426 \begin_inset Text
28427
28428 \layout Standard
28429
28430 \size footnotesize
28431 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
28432
28433 \end_inset
28434
28435
28436
28437 \end_inset
28438 </cell>
28439 </row>
28440 <row topline="true">
28441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28442 \begin_inset Text
28443
28444 \layout Standard
28445
28446 \size footnotesize
28447 Silicon Laboratories / Cygnal
28448
28449 \end_inset
28450 </cell>
28451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28452 \begin_inset Text
28453
28454 \layout Standard
28455
28456 \size footnotesize
28457 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
28458 \begin_inset LatexCommand \index{IDE}
28459
28460 \end_inset
28461
28462
28463
28464 \end_inset
28465 </cell>
28466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28467 \begin_inset Text
28468
28469 \layout Standard
28470
28471 \size footnotesize
28472 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
28473
28474 \end_inset
28475
28476
28477
28478 \end_inset
28479 </cell>
28480 </row>
28481 <row topline="true">
28482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28483 \begin_inset Text
28484
28485 \layout Standard
28486
28487 \size footnotesize
28488 Ramtron / Goal Semiconductor
28489
28490 \end_inset
28491 </cell>
28492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28493 \begin_inset Text
28494
28495 \layout Standard
28496
28497 \size footnotesize
28498 Interfacing SDCC to Syn and Textpad
28499
28500 \end_inset
28501 </cell>
28502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28503 \begin_inset Text
28504
28505 \layout Standard
28506
28507 \size footnotesize
28508 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28509
28510 \end_inset
28511
28512
28513
28514 \end_inset
28515 </cell>
28516 </row>
28517 <row topline="true">
28518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28519 \begin_inset Text
28520
28521 \layout Standard
28522
28523 \size footnotesize
28524 Ramtron / Goal Semiconductor
28525
28526 \end_inset
28527 </cell>
28528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28529 \begin_inset Text
28530
28531 \layout Standard
28532
28533 \size footnotesize
28534 Installing and Configuring SDCC and Crimson Editor 
28535
28536 \end_inset
28537 </cell>
28538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28539 \begin_inset Text
28540
28541 \layout Standard
28542
28543 \size footnotesize
28544 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28545
28546 \end_inset
28547
28548
28549
28550 \end_inset
28551 </cell>
28552 </row>
28553 <row topline="true" bottomline="true">
28554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28555 \begin_inset Text
28556
28557 \layout Standard
28558
28559 \size footnotesize
28560 Texas Instruments
28561
28562 \end_inset
28563 </cell>
28564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28565 \begin_inset Text
28566
28567 \layout Standard
28568
28569 \size footnotesize
28570 MSC12xx Programming with SDCC
28571
28572 \end_inset
28573 </cell>
28574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28575 \begin_inset Text
28576
28577 \layout Standard
28578
28579 \size footnotesize
28580 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
28581
28582 \end_inset
28583
28584
28585
28586 \end_inset
28587 </cell>
28588 </row>
28589 </lyxtabular>
28590
28591 \end_inset
28592
28593
28594
28595 \layout Section
28596 Some Questions
28597
28598 \layout Standard
28599 Some questions answered, some pointers given - it might be time to in turn
28600  ask 
28601 \emph on
28602 you
28603 \emph default
28604  some questions: 
28605
28606 \layout Itemize
28607 can you solve your project with the selected microcontroller? Would you
28608  find out early or rather late that your target is too small/slow/whatever?
28609  Can you switch to a slightly better device if it doesn't fit?
28610
28611 \layout Itemize
28612 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
28613  and/or another programming language be more adequate? Would an operating
28614  system on the target device help?
28615
28616 \layout Itemize
28617 if you solved the problem, will the marketing department be happy?
28618
28619 \layout Itemize
28620 if the marketing department is happy, will customers be happy?
28621
28622 \layout Itemize
28623 if you're the project manager, marketing department and maybe even the customer
28624  in one person, have you tried to see the project from the outside?
28625
28626 \layout Itemize
28627 is the project done if you think it is done? Or is just that other interface/pro
28628 tocol/feature/configuration/option missing? How about website, manual(s),
28629  internationali(z|s)ation, packaging, labels, 2nd source for components,
28630  electromagnetic compatability/interference, documentation for production,
28631  production test software, update mechanism, patent issues?
28632
28633 \layout Itemize
28634 is your project adequately positioned in that magic triangle: fame, fortune,
28635  fun?
28636
28637 \layout Standard
28638 Maybe not all answers to these questions are known and some answers may
28639  even be 
28640 \emph on
28641 no
28642 \emph default
28643 , nevertheless knowing these questions may help you to avoid burnout
28644 \begin_inset Foot
28645 collapsed false
28646
28647 \layout Standard
28648 burnout is bad for electronic devices, programmers and motorcycle tyres
28649
28650 \end_inset
28651
28652 .
28653  Chances are you didn't want to hear some of them...
28654
28655 \layout Chapter
28656 Support
28657 \begin_inset LatexCommand \index{Support}
28658
28659 \end_inset
28660
28661
28662
28663 \layout Standard
28664 SDCC has grown to be a large project.
28665  The compiler alone (without the preprocessor, assembler and linker) is
28666  well over 150,000 lines of code (blank stripped).
28667  The open source nature of this project is a key to its continued growth
28668  and support.
28669  You gain the benefit and support of many active software developers and
28670  end users.
28671  Is SDCC perfect? No, that's why we need your help.
28672  The developers take pride in fixing reported bugs.
28673  You can help by reporting the bugs and helping other SDCC users.
28674  There are lots of ways to contribute, and we encourage you to take part
28675  in making SDCC a great software package.
28676  
28677
28678 \layout Standard
28679 The SDCC project is hosted on the SDCC sourceforge site at 
28680 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
28681
28682 \end_inset
28683
28684 .
28685  You'll find the complete set of mailing lists
28686 \begin_inset LatexCommand \index{Mailing list(s)}
28687
28688 \end_inset
28689
28690 , forums, bug reporting system, patch submission
28691 \begin_inset LatexCommand \index{Patch submission}
28692
28693 \end_inset
28694
28695  system, download
28696 \begin_inset LatexCommand \index{download}
28697
28698 \end_inset
28699
28700  area and Subversion code repository
28701 \begin_inset LatexCommand \index{Subversion code repository}
28702
28703 \end_inset
28704
28705  there.
28706
28707 \layout Section
28708 Reporting Bugs
28709 \begin_inset LatexCommand \index{Bug reporting}
28710
28711 \end_inset
28712
28713
28714 \begin_inset LatexCommand \index{Reporting bugs}
28715
28716 \end_inset
28717
28718
28719
28720 \layout Standard
28721 The recommended way of reporting bugs is using the infrastructure of the
28722  sourceforge site.
28723  You can follow the status of bug reports there and have an overview about
28724  the known bugs.
28725
28726 \layout Standard
28727 Bug reports are automatically forwarded to the developer mailing list and
28728  will be fixed ASAP.
28729  When reporting a bug, it is very useful to include a small test program
28730  (the smaller the better) which reproduces the problem.
28731  If you can isolate the problem by looking at the generated assembly code,
28732  this can be very helpful.
28733  Compiling your program with the -
28734 \begin_inset ERT
28735 status Collapsed
28736
28737 \layout Standard
28738
28739
28740 \backslash
28741 /
28742
28743 \end_inset
28744
28745 -dumpall
28746 \begin_inset LatexCommand \index{-\/-dumpall}
28747
28748 \end_inset
28749
28750  option can sometimes be useful in locating optimization problems.
28751  When reporting a bug please make sure you:
28752
28753 \layout Enumerate
28754 Attach the code you are compiling with SDCC.
28755  
28756
28757 \layout Enumerate
28758 Specify the exact command you use to run SDCC, or attach your Makefile.
28759  
28760
28761 \layout Enumerate
28762 Specify the SDCC version (type "
28763 \family sans
28764 \series bold
28765 sdcc -v
28766 \family default
28767 \series default
28768 "), your platform, and operating system.
28769  
28770
28771 \layout Enumerate
28772 Provide an exact copy of any error message or incorrect output.
28773  
28774
28775 \layout Enumerate
28776 Put something meaningful in the subject of your message.
28777
28778 \layout Standard
28779 Please attempt to include these 5 important parts, as applicable, in all
28780  requests for support or when reporting any problems or bugs with SDCC.
28781  Though this will make your message lengthy, it will greatly improve your
28782  chance that SDCC users and developers will be able to help you.
28783  Some SDCC developers are frustrated by bug reports without code provided
28784  that they can use to reproduce and ultimately fix the problem, so please
28785  be sure to provide sample code if you are reporting a bug! 
28786
28787 \layout Standard
28788 Please have a short check that you are using a recent version of SDCC and
28789  the bug is not yet known.
28790  This is the link for reporting bugs: 
28791 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
28792
28793 \end_inset
28794
28795 .
28796  With SDCC on average having more than 200 downloads
28797 \begin_inset LatexCommand \index{download}
28798
28799 \end_inset
28800
28801  on sourceforge per day
28802 \begin_inset Foot
28803 collapsed false
28804
28805 \layout Standard
28806 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
28807  between 2002 and 2005.
28808  This does not include other methods of distribution.
28809
28810 \end_inset
28811
28812  there must be some users.
28813  So it's not exactly easy to find a new bug.
28814  If you find one we need it: 
28815 \emph on
28816 reporting bugs is good
28817 \emph default
28818 .
28819
28820 \layout Section
28821 Requesting Features
28822 \begin_inset LatexCommand \label{sub:Requesting-Features}
28823
28824 \end_inset
28825
28826
28827 \begin_inset LatexCommand \index{Feature request}
28828
28829 \end_inset
28830
28831
28832 \begin_inset LatexCommand \index{Requesting features}
28833
28834 \end_inset
28835
28836
28837
28838 \layout Standard
28839 Like bug reports feature requests are forwarded to the developer mailing
28840  list.
28841  This is the link for requesting features: 
28842 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28843
28844 \end_inset
28845
28846 .
28847
28848 \layout Section
28849 Submitting patches
28850
28851 \layout Standard
28852 Like bug reports contributed patches are forwarded to the developer mailing
28853  list.
28854  This is the link for submitting patches
28855 \begin_inset LatexCommand \index{Patch submission}
28856
28857 \end_inset
28858
28859
28860 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28861
28862 \end_inset
28863
28864 .
28865
28866 \layout Standard
28867 You need to specify some parameters to the 
28868 \family typewriter
28869 diff
28870 \family default
28871  command for the patches to be useful.
28872  If you modified more than one file a patch created f.e.
28873  with 
28874 \family sans
28875 \series bold
28876
28877 \begin_inset Quotes sld
28878 \end_inset
28879
28880 diff -Naur unmodified_directory modified_directory >my_changes.patch
28881 \begin_inset Quotes srd
28882 \end_inset
28883
28884
28885 \family default
28886 \series default
28887  will be fine, otherwise 
28888 \family sans
28889 \series bold
28890
28891 \begin_inset Quotes sld
28892 \end_inset
28893
28894 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28895 \begin_inset Quotes srd
28896 \end_inset
28897
28898
28899 \series default
28900  
28901 \family default
28902 will do.
28903
28904 \layout Section
28905 Getting Help
28906
28907 \layout Standard
28908 These links should take you directly to the 
28909 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28910
28911 \end_inset
28912
28913
28914 \begin_inset Foot
28915 collapsed false
28916
28917 \layout Standard
28918 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28919  automated messages (mid 2003)
28920
28921 \end_inset
28922
28923  and the 
28924 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28925
28926 \end_inset
28927
28928 , lists
28929 \begin_inset LatexCommand \index{Mailing list(s)}
28930
28931 \end_inset
28932
28933  and forums are archived and searchable so if you are lucky someone already
28934  had a similar problem.
28935  While mails to the lists themselves are delivered promptly their web front
28936  end on sourceforge sometimes shows a severe time lag (up to several weeks),
28937  if you're seriously using SDCC please consider subscribing to the lists.
28938
28939 \layout Section
28940 ChangeLog
28941
28942 \layout Standard
28943 You can follow the status of the Subversion version
28944 \begin_inset LatexCommand \index{version}
28945
28946 \end_inset
28947
28948  of SDCC by watching the Changelog
28949 \begin_inset LatexCommand \index{Changelog}
28950
28951 \end_inset
28952
28953  in the Subversion repository
28954 \size footnotesize
28955  
28956 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28957
28958 \end_inset
28959
28960 .
28961
28962 \layout Section
28963 Subversion Source Code Repository
28964
28965 \layout Standard
28966 The output of 
28967 \family sans
28968 \series bold
28969 sdcc --version
28970 \family default
28971 \series default
28972  or the filenames of the snapshot versions of SDCC include date and its
28973  Subversion
28974 \begin_inset LatexCommand \index{Subversion code repository}
28975
28976 \end_inset
28977
28978  number.
28979  Subversion allows to download the source of recent or previous versions
28980  
28981 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28982
28983 \end_inset
28984
28985  (by number or by date).
28986  An on-line source code browser and detailled instructions are also available
28987  there.
28988  SDCC versions starting from 1999 up to now are available (currently the
28989  versions prior to the conversion from cvs
28990 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28991
28992 \end_inset
28993
28994  to Subversion (April 2006) are either by accessible by Subversion or by
28995  cvs).
28996
28997 \layout Section
28998 Release policy
28999 \begin_inset LatexCommand \index{Release policy}
29000
29001 \end_inset
29002
29003
29004
29005 \layout Standard
29006 Historically there often were long delays between official releases and
29007  the sourceforge download area tends to get not updated at all.
29008  Excuses in the past might have referred to problems with live range analysis,
29009  but as this was fixed a while ago, the current problem is that another
29010  excuse has to be found.
29011  Kidding aside, we have to get better there! On the other hand there are
29012  daily snapshots available at 
29013 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
29014
29015 \end_inset
29016
29017 , and you can always build the very last version (hopefully with many bugs
29018  fixed, and features added) from the source code available at 
29019 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
29020
29021 \end_inset
29022
29023 .
29024  A release wiki
29025 \begin_inset LatexCommand \index{wiki}
29026
29027 \end_inset
29028
29029
29030 \begin_inset LatexCommand \index{Release wiki}
29031
29032 \end_inset
29033
29034  at 
29035 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
29036
29037 \end_inset
29038
29039  also holds some information about past and future releases.
29040
29041 \layout Section
29042 Examples
29043 \begin_inset LatexCommand \index{Examples}
29044
29045 \end_inset
29046
29047
29048
29049 \layout Standard
29050 You'll find some small examples in the directory 
29051 \emph on
29052 sdcc/device/examples/.
29053  
29054 \emph default
29055 More examples and libraries are available at
29056 \emph on
29057  The SDCC Open Knowledge Resource 
29058 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
29059
29060 \end_inset
29061
29062  
29063 \emph default
29064 web site or at 
29065 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
29066
29067 \end_inset
29068
29069 .
29070
29071 \layout Standard
29072 \begin_inset Note
29073 collapsed true
29074
29075 \layout Standard
29076 I did insert a reference to Paul's web site here although it seems rather
29077  dedicated to a specific 8032 board (I think it's okay because it f.e.
29078  shows LCD/Harddisc interface and has a free 8051 monitor.
29079  Independent 8032 board vendors face hard competition of heavily subsidized
29080  development boards anyway).
29081
29082 \layout Standard
29083 Maybe we should include some links to real world applications.
29084  Preferably pointer to pointers (one for each architecture) so this stays
29085  manageable here?
29086
29087 \end_inset
29088
29089
29090
29091 \layout Section
29092 Quality control
29093 \begin_inset LatexCommand \label{sec:Quality-control}
29094
29095 \end_inset
29096
29097
29098 \begin_inset LatexCommand \index{Quality control}
29099
29100 \end_inset
29101
29102
29103
29104 \layout Standard
29105 The compiler is passed through nightly compile and build checks.
29106  The so called 
29107 \shape italic
29108 regression tests
29109 \shape default
29110
29111 \begin_inset LatexCommand \index{Regression test}
29112
29113 \end_inset
29114
29115  check that SDCC itself compiles flawlessly on several host platforms (i386,
29116  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
29117  the quality of the code generated by SDCC by running the code for several
29118  target platforms through simulators.
29119  The regression test suite comprises more than 100 files which expand to
29120  more than 500 test cases which include more than 4500 tests.
29121  The results of these tests are published daily on SDCC's snapshot page
29122  (click on the red or green symbols on the right side of 
29123 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
29124
29125 \end_inset
29126
29127 ).
29128
29129 \layout Standard
29130 There is a separate document 
29131 \shape italic
29132 test_suite.pdf 
29133 \begin_inset LatexCommand \index{Test suite}
29134
29135 \end_inset
29136
29137
29138 \shape default
29139  
29140 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
29141
29142 \end_inset
29143
29144  about the regression test suite.
29145
29146 \layout Standard
29147 You'll find the test code in the directory 
29148 \shape italic
29149 sdcc/support/regression
29150 \shape default
29151 .
29152  You can run these tests manually by running 
29153 \family sans
29154 make
29155 \family default
29156  in this directory (or f.e.
29157  
29158 \family sans
29159 \series bold
29160
29161 \begin_inset Quotes sld
29162 \end_inset
29163
29164 make test-mcs51
29165 \begin_inset Quotes srd
29166 \end_inset
29167
29168
29169 \family default
29170 \series default
29171  if you don't want to run the complete tests).
29172  The test code might also be interesting if you want to look for examples
29173 \begin_inset LatexCommand \index{Examples}
29174
29175 \end_inset
29176
29177  checking corner cases of SDCC or if you plan to submit patches
29178 \begin_inset LatexCommand \index{Patch submission}
29179
29180 \end_inset
29181
29182 .
29183
29184 \layout Standard
29185 The 14bit pic port uses a different set of regression tests 
29186 \begin_inset LatexCommand \index{Regression test (PIC14)}
29187
29188 \end_inset
29189
29190 , you'll find them in the directory 
29191 \shape italic
29192 sdcc/src/regression
29193 \shape default
29194 .
29195
29196 \layout Section
29197 Use of SDCC in Education
29198
29199 \layout Standard
29200 In short: 
29201 \emph on
29202 highly
29203 \emph default
29204  encouraged
29205 \begin_inset Foot
29206 collapsed false
29207
29208 \layout Standard
29209 the phrase "use in education" might evoke the association "
29210 \emph on
29211 only
29212 \emph default
29213  fit for use in education".
29214  This connotation is not intended but nevertheless risked as the licensing
29215  of SDCC makes it difficult to offer educational discounts
29216
29217 \end_inset
29218
29219 .
29220  If your rationales are to:
29221
29222 \layout Enumerate
29223 give students a chance to understand the 
29224 \emph on
29225 complete
29226 \emph default
29227  steps of code generation
29228
29229 \layout Enumerate
29230 have a curriculum that can be extended for years.
29231  Then you could use an fpga board as target and your curriculum will seamlessly
29232  extend from logic synthesis (
29233 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
29234
29235 \end_inset
29236
29237
29238 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
29239
29240 \end_inset
29241
29242 ), over assembly programming, to C to FPGA compilers (
29243 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
29244
29245 \end_inset
29246
29247 ) and to C.
29248
29249 \layout Enumerate
29250 be able to insert excursions about skills like using a revision control
29251  system, submitting/applying patches, using a type-setting (as opposed to
29252  word-processing) engine LyX/LaTeX, using 
29253 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
29254
29255 \end_inset
29256
29257 , following some 
29258 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
29259
29260 \end_inset
29261
29262 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
29263  Source Software, CPU simulation, compiler regression tests
29264 \begin_inset LatexCommand \index{Regression test}
29265
29266 \end_inset
29267
29268 .
29269  
29270 \newline
29271 And if there should be a shortage of ideas then you can always point students
29272  to the ever-growing feature request list 
29273 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
29274
29275 \end_inset
29276
29277 .
29278
29279 \layout Enumerate
29280 not tie students to a specific host platform and instead allow them to use
29281  a host platform of 
29282 \emph on
29283 their
29284 \emph default
29285  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
29286  eventually 
29287 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
29288
29289 \end_inset
29290
29291 )
29292
29293 \layout Enumerate
29294 not encourage students to use illegal copies of educational software
29295
29296 \layout Enumerate
29297 be immune to licensing/availability/price changes of the chosen tool chain
29298
29299 \layout Enumerate
29300 be able to change to a new target platform without having to adopt a new
29301  tool chain
29302
29303 \layout Enumerate
29304 have complete control over and insight into the tool chain
29305
29306 \layout Enumerate
29307 make your students aware about the pros and cons of open source software
29308  development
29309
29310 \layout Enumerate
29311 give back to the public as you are probably at least partially publically
29312  funded
29313
29314 \layout Enumerate
29315 give students a chance to publically prove their skills and to possibly
29316  see a world wide impact
29317
29318 \layout Standard
29319 \pagebreak_bottom 
29320 then SDCC is probably among the first choices.
29321  Well, probably SDCC might be the only choice.
29322
29323
29324 \layout Chapter
29325 SDCC Technical Data
29326
29327 \layout Section
29328 Optimizations
29329 \begin_inset LatexCommand \index{Optimizations}
29330
29331 \end_inset
29332
29333
29334
29335 \layout Standard
29336 SDCC performs a host of standard optimizations in addition to some MCU specific
29337  optimizations.
29338  
29339
29340 \layout Subsection
29341 Sub-expression Elimination
29342 \begin_inset LatexCommand \index{Subexpression elimination}
29343
29344 \end_inset
29345
29346
29347
29348 \layout Standard
29349 The compiler does local and 
29350 \emph on
29351 g
29352 \emph default
29353 lobal 
29354 \emph on
29355 c
29356 \emph default
29357 ommon 
29358 \emph on
29359 s
29360 \emph default
29361 ubexpression 
29362 \emph on
29363 e
29364 \emph default
29365 limination, e.g.: 
29366
29367 \layout Verse
29368
29369 \family typewriter
29370 i = x + y + 1; 
29371 \newline
29372 j = x + y;
29373
29374 \layout Standard
29375 will be translated to
29376
29377 \layout Verse
29378
29379 \family typewriter
29380 iTemp = x + y; 
29381 \newline
29382 i = iTemp + 1; 
29383 \newline
29384 j = iTemp;
29385
29386 \layout Standard
29387 Some subexpressions are not as obvious as the above example, e.g.:
29388
29389 \layout Verse
29390
29391 \family typewriter
29392 a->b[i].c = 10; 
29393 \newline
29394 a->b[i].d = 11;
29395
29396 \layout Standard
29397 In this case the address arithmetic a->b[i] will be computed only once;
29398  the equivalent code in C would be.
29399
29400 \layout Verse
29401
29402 \family typewriter
29403 iTemp = a->b[i]; 
29404 \newline
29405 iTemp.c = 10; 
29406 \newline
29407 iTemp.d = 11;
29408
29409 \layout Standard
29410 The compiler will try to keep these temporary variables in registers.
29411
29412 \layout Subsection
29413 Dead-Code Elimination
29414 \begin_inset LatexCommand \index{Dead-code elimination}
29415
29416 \end_inset
29417
29418
29419
29420 \layout Verse
29421
29422 \family typewriter
29423 int global;
29424 \newline
29425
29426 \newline
29427 void f () { 
29428 \newline
29429 \SpecialChar ~
29430 \SpecialChar ~
29431 int i; 
29432 \newline
29433 \SpecialChar ~
29434 \SpecialChar ~
29435 i = 1; \SpecialChar ~
29436 \SpecialChar ~
29437 \SpecialChar ~
29438 \SpecialChar ~
29439 \SpecialChar ~
29440 /* dead store */ 
29441 \newline
29442 \SpecialChar ~
29443 \SpecialChar ~
29444 global = 1;\SpecialChar ~
29445 /* dead
29446  store */ 
29447 \newline
29448 \SpecialChar ~
29449 \SpecialChar ~
29450 global = 2; 
29451 \newline
29452 \SpecialChar ~
29453 \SpecialChar ~
29454 return; 
29455 \newline
29456 \SpecialChar ~
29457 \SpecialChar ~
29458 global = 3;\SpecialChar ~
29459 /* unreachable */ 
29460 \newline
29461 }
29462
29463 \layout Standard
29464 will be changed to
29465
29466 \layout Verse
29467
29468 \family typewriter
29469 int global;
29470 \newline
29471
29472 \newline
29473 void f () {
29474 \newline
29475 \SpecialChar ~
29476 \SpecialChar ~
29477 global = 2; 
29478 \newline
29479 }
29480
29481 \layout Subsection
29482 Copy-Propagation
29483 \begin_inset LatexCommand \index{Copy propagation}
29484
29485 \end_inset
29486
29487
29488
29489 \layout Verse
29490
29491 \family typewriter
29492 int f() { 
29493 \newline
29494 \SpecialChar ~
29495 \SpecialChar ~
29496 int i, j; 
29497 \newline
29498 \SpecialChar ~
29499 \SpecialChar ~
29500 i = 10; 
29501 \newline
29502 \SpecialChar ~
29503 \SpecialChar ~
29504 j = i; 
29505 \newline
29506 \SpecialChar ~
29507 \SpecialChar ~
29508 return j; 
29509 \newline
29510 }
29511
29512 \layout Standard
29513 will be changed to 
29514
29515 \layout Verse
29516
29517 \family typewriter
29518 int f() { 
29519 \newline
29520 \SpecialChar ~
29521 \SpecialChar ~
29522 int i, j; 
29523 \newline
29524 \SpecialChar ~
29525 \SpecialChar ~
29526 i = 10; 
29527 \newline
29528 \SpecialChar ~
29529 \SpecialChar ~
29530 j = 10; 
29531 \newline
29532 \SpecialChar ~
29533 \SpecialChar ~
29534 return 10; 
29535 \newline
29536 }
29537
29538 \layout Standard
29539 Note: the dead stores created by this copy propagation will be eliminated
29540  by dead-code elimination.
29541
29542 \layout Subsection
29543 Loop Optimizations
29544 \begin_inset LatexCommand \index{Loop optimization}
29545
29546 \end_inset
29547
29548
29549 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
29550
29551 \end_inset
29552
29553
29554
29555 \layout Standard
29556 Two types of loop optimizations are done by SDCC 
29557 \emph on
29558 loop invariant
29559 \emph default
29560  lifting and
29561 \emph on
29562  strength reduction
29563 \emph default
29564  of loop induction variables.
29565  In addition to the strength reduction the optimizer marks the induction
29566  variables and the register allocator tries to keep the induction variables
29567  in registers for the duration of the loop.
29568  Because of this preference of the register allocator
29569 \begin_inset LatexCommand \index{Register allocation}
29570
29571 \end_inset
29572
29573 , loop induction optimization causes an increase in register pressure, which
29574  may cause unwanted spilling of other temporary variables into the stack
29575 \begin_inset LatexCommand \index{stack}
29576
29577 \end_inset
29578
29579  / data space.
29580  The compiler will generate a warning message when it is forced to allocate
29581  extra space either on the stack or data space.
29582  If this extra space allocation is undesirable then induction optimization
29583  can be eliminated either for the entire source file (with -
29584 \begin_inset ERT
29585 status Collapsed
29586
29587 \layout Standard
29588
29589
29590 \backslash
29591 /
29592
29593 \end_inset
29594
29595 -noinduction option) or for a given function only using #pragma\SpecialChar ~
29596 noinduction
29597 \begin_inset LatexCommand \index{\#pragma noinduction}
29598
29599 \end_inset
29600
29601 .
29602 \newline
29603
29604 \newline
29605 Loop Invariant:
29606
29607 \layout Verse
29608
29609 \family typewriter
29610 for (i = 0 ; i < 100 ; i ++) 
29611 \newline
29612 \SpecialChar ~
29613 \SpecialChar ~
29614 \SpecialChar ~
29615 \SpecialChar ~
29616 f += k + l;
29617
29618 \layout Standard
29619 changed to
29620
29621 \layout Verse
29622
29623 \family typewriter
29624 itemp = k + l; 
29625 \newline
29626 for (i = 0; i < 100; i++) 
29627 \newline
29628 \SpecialChar ~
29629 \SpecialChar ~
29630 \SpecialChar ~
29631 \SpecialChar ~
29632 f += itemp;
29633
29634 \layout Standard
29635 As mentioned previously some loop invariants are not as apparent, all static
29636  address computations are also moved out of the loop.
29637 \newline
29638
29639 \newline
29640 Strength Reduction
29641 \begin_inset LatexCommand \index{Strength reduction}
29642
29643 \end_inset
29644
29645 , this optimization substitutes an expression by a cheaper expression:
29646
29647 \layout Verse
29648
29649 \family typewriter
29650 for (i=0;i < 100; i++)
29651 \newline
29652 \SpecialChar ~
29653 \SpecialChar ~
29654 \SpecialChar ~
29655 \SpecialChar ~
29656 ar[i*5] = i*3;
29657
29658 \layout Standard
29659 changed to
29660
29661 \layout Verse
29662
29663 \family typewriter
29664 itemp1 = 0; 
29665 \newline
29666 itemp2 = 0; 
29667 \newline
29668 for (i=0;i< 100;i++) { 
29669 \newline
29670 \SpecialChar ~
29671 \SpecialChar ~
29672 \SpecialChar ~
29673 \SpecialChar ~
29674 ar[itemp1] = itemp2; 
29675 \newline
29676 \SpecialChar ~
29677 \SpecialChar ~
29678 \SpecialChar ~
29679 \SpecialChar ~
29680 itemp1
29681  += 5; 
29682 \newline
29683 \SpecialChar ~
29684 \SpecialChar ~
29685 \SpecialChar ~
29686 \SpecialChar ~
29687 itemp2 += 3; 
29688 \newline
29689 }
29690
29691 \layout Standard
29692 The more expensive multiplication
29693 \begin_inset LatexCommand \index{Multiplication}
29694
29695 \end_inset
29696
29697  is changed to a less expensive addition.
29698
29699 \layout Subsection
29700 Loop Reversing
29701 \begin_inset LatexCommand \index{Loop reversing}
29702
29703 \end_inset
29704
29705
29706
29707 \layout Standard
29708 This optimization is done to reduce the overhead of checking loop boundaries
29709  for every iteration.
29710  Some simple loops can be reversed and implemented using a 
29711 \begin_inset Quotes eld
29712 \end_inset
29713
29714 decrement and jump if not zero
29715 \begin_inset Quotes erd
29716 \end_inset
29717
29718  instruction.
29719  SDCC checks for the following criterion to determine if a loop is reversible
29720  (note: more sophisticated compilers use data-dependency analysis to make
29721  this determination, SDCC uses a more simple minded analysis).
29722
29723 \layout Itemize
29724 The 'for' loop is of the form 
29725 \newline
29726
29727 \newline
29728
29729 \family typewriter
29730 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
29731  += 1])
29732 \newline
29733 \SpecialChar ~
29734 \SpecialChar ~
29735 \SpecialChar ~
29736 \SpecialChar ~
29737 <for body>
29738
29739 \layout Itemize
29740 The <for body> does not contain 
29741 \begin_inset Quotes eld
29742 \end_inset
29743
29744 continue
29745 \begin_inset Quotes erd
29746 \end_inset
29747
29748  or 'break
29749 \begin_inset Quotes erd
29750 \end_inset
29751
29752 .
29753
29754 \layout Itemize
29755 All goto's are contained within the loop.
29756
29757 \layout Itemize
29758 No function calls within the loop.
29759
29760 \layout Itemize
29761 The loop control variable <sym> is not assigned any value within the loop
29762
29763 \layout Itemize
29764 The loop control variable does NOT participate in any arithmetic operation
29765  within the loop.
29766
29767 \layout Itemize
29768 There are NO switch statements in the loop.
29769
29770 \layout Subsection
29771 Algebraic Simplifications
29772
29773 \layout Standard
29774 SDCC does numerous algebraic simplifications, the following is a small sub-set
29775  of these optimizations.
29776
29777 \layout Verse
29778
29779 \family typewriter
29780 i = j + 0;\SpecialChar ~
29781 \SpecialChar ~
29782 \SpecialChar ~
29783 \SpecialChar ~
29784  /* changed to: */\SpecialChar ~
29785 \SpecialChar ~
29786 \SpecialChar ~
29787 \SpecialChar ~
29788  i = j; 
29789 \newline
29790 i /= 2;\SpecialChar ~
29791 \SpecialChar ~
29792 \SpecialChar ~
29793 \SpecialChar ~
29794 \SpecialChar ~
29795 \SpecialChar ~
29796 \SpecialChar ~
29797  /* changed to: */\SpecialChar ~
29798 \SpecialChar ~
29799 \SpecialChar ~
29800 \SpecialChar ~
29801  i >>= 1; 
29802 \newline
29803 i
29804  = j - j;\SpecialChar ~
29805 \SpecialChar ~
29806 \SpecialChar ~
29807 \SpecialChar ~
29808  /* changed to: */\SpecialChar ~
29809 \SpecialChar ~
29810 \SpecialChar ~
29811 \SpecialChar ~
29812  i = 0; 
29813 \newline
29814 i = j / 1;\SpecialChar ~
29815 \SpecialChar ~
29816 \SpecialChar ~
29817 \SpecialChar ~
29818  /* changed to: */\SpecialChar ~
29819 \SpecialChar ~
29820 \SpecialChar ~
29821 \SpecialChar ~
29822  i = j;
29823
29824 \layout Standard
29825 Note the subexpressions
29826 \begin_inset LatexCommand \index{Subexpression}
29827
29828 \end_inset
29829
29830  given above are generally introduced by macro expansions or as a result
29831  of copy/constant propagation.
29832
29833 \layout Subsection
29834 'switch' Statements
29835 \begin_inset LatexCommand \label{sub:'switch'-Statements}
29836
29837 \end_inset
29838
29839
29840 \begin_inset LatexCommand \index{switch statement}
29841
29842 \end_inset
29843
29844
29845
29846 \layout Standard
29847 SDCC can optimize switch statements to jump tables
29848 \begin_inset LatexCommand \index{jump tables}
29849
29850 \end_inset
29851
29852 .
29853  It makes the decision based on an estimate of the generated code size.
29854  SDCC is quite liberal in the requirements for jump table generation: 
29855
29856 \layout Itemize
29857 The labels need not be in order, and the starting number need not be one
29858  or zero, the case labels are in numerical sequence or not too many case
29859  labels are missing.
29860
29861 \begin_deeper
29862 \layout Verse
29863
29864 \family typewriter
29865 switch(i) {\SpecialChar ~
29866 \SpecialChar ~
29867 \SpecialChar ~
29868 \SpecialChar ~
29869 \SpecialChar ~
29870 \SpecialChar ~
29871 \SpecialChar ~
29872 \SpecialChar ~
29873 \SpecialChar ~
29874 \SpecialChar ~
29875 \SpecialChar ~
29876 \SpecialChar ~
29877 \SpecialChar ~
29878 \SpecialChar ~
29879 \SpecialChar ~
29880 \SpecialChar ~
29881 \SpecialChar ~
29882 \SpecialChar ~
29883 \SpecialChar ~
29884 \SpecialChar ~
29885 \SpecialChar ~
29886 \SpecialChar ~
29887 \SpecialChar ~
29888 \SpecialChar ~
29889 \SpecialChar ~
29890 \SpecialChar ~
29891 switch (i) { 
29892 \newline
29893 \SpecialChar ~
29894 \SpecialChar ~
29895 \SpecialChar ~
29896 case 4: ...\SpecialChar ~
29897 \SpecialChar ~
29898 \SpecialChar ~
29899 \SpecialChar ~
29900 \SpecialChar ~
29901 \SpecialChar ~
29902 \SpecialChar ~
29903 \SpecialChar ~
29904 \SpecialChar ~
29905 \SpecialChar ~
29906 \SpecialChar ~
29907 \SpecialChar ~
29908 \SpecialChar ~
29909 \SpecialChar ~
29910 \SpecialChar ~
29911 \SpecialChar ~
29912 \SpecialChar ~
29913 \SpecialChar ~
29914 \SpecialChar ~
29915 \SpecialChar ~
29916 \SpecialChar ~
29917 \SpecialChar ~
29918 \SpecialChar ~
29919 \SpecialChar ~
29920 \SpecialChar ~
29921 \SpecialChar ~
29922 case 0: ...
29923  
29924 \newline
29925 \SpecialChar ~
29926 \SpecialChar ~
29927 \SpecialChar ~
29928 case 5: ...\SpecialChar ~
29929 \SpecialChar ~
29930 \SpecialChar ~
29931 \SpecialChar ~
29932 \SpecialChar ~
29933 \SpecialChar ~
29934 \SpecialChar ~
29935 \SpecialChar ~
29936 \SpecialChar ~
29937 \SpecialChar ~
29938 \SpecialChar ~
29939 \SpecialChar ~
29940 \SpecialChar ~
29941 \SpecialChar ~
29942 \SpecialChar ~
29943 \SpecialChar ~
29944 \SpecialChar ~
29945 \SpecialChar ~
29946 \SpecialChar ~
29947 \SpecialChar ~
29948 \SpecialChar ~
29949 \SpecialChar ~
29950 \SpecialChar ~
29951 \SpecialChar ~
29952 \SpecialChar ~
29953 \SpecialChar ~
29954 case 1: ...
29955  
29956 \newline
29957 \SpecialChar ~
29958 \SpecialChar ~
29959 \SpecialChar ~
29960 case 3: ...\SpecialChar ~
29961 \SpecialChar ~
29962 \SpecialChar ~
29963 \SpecialChar ~
29964 \SpecialChar ~
29965 \SpecialChar ~
29966 \SpecialChar ~
29967 \SpecialChar ~
29968 \SpecialChar ~
29969 \SpecialChar ~
29970 \SpecialChar ~
29971 \SpecialChar ~
29972 \SpecialChar ~
29973 \SpecialChar ~
29974 \SpecialChar ~
29975 \SpecialChar ~
29976 \SpecialChar ~
29977 \SpecialChar ~
29978 \SpecialChar ~
29979 \SpecialChar ~
29980 \SpecialChar ~
29981 \SpecialChar ~
29982 \SpecialChar ~
29983 \SpecialChar ~
29984 \SpecialChar ~
29985 \SpecialChar ~
29986
29987 \newline
29988 \SpecialChar ~
29989 \SpecialChar ~
29990 \SpecialChar ~
29991 case 6: ...\SpecialChar ~
29992 \SpecialChar ~
29993 \SpecialChar ~
29994 \SpecialChar ~
29995 \SpecialChar ~
29996 \SpecialChar ~
29997 \SpecialChar ~
29998 \SpecialChar ~
29999 \SpecialChar ~
30000 \SpecialChar ~
30001 \SpecialChar ~
30002 \SpecialChar ~
30003 \SpecialChar ~
30004 \SpecialChar ~
30005 \SpecialChar ~
30006 \SpecialChar ~
30007 \SpecialChar ~
30008 \SpecialChar ~
30009 \SpecialChar ~
30010 \SpecialChar ~
30011 \SpecialChar ~
30012 \SpecialChar ~
30013 \SpecialChar ~
30014 \SpecialChar ~
30015 \SpecialChar ~
30016 \SpecialChar ~
30017 case 3: ...
30018  
30019 \newline
30020 \SpecialChar ~
30021 \SpecialChar ~
30022 \SpecialChar ~
30023 case 7: ...\SpecialChar ~
30024 \SpecialChar ~
30025 \SpecialChar ~
30026 \SpecialChar ~
30027 \SpecialChar ~
30028 \SpecialChar ~
30029 \SpecialChar ~
30030 \SpecialChar ~
30031 \SpecialChar ~
30032 \SpecialChar ~
30033 \SpecialChar ~
30034 \SpecialChar ~
30035 \SpecialChar ~
30036 \SpecialChar ~
30037 \SpecialChar ~
30038 \SpecialChar ~
30039 \SpecialChar ~
30040 \SpecialChar ~
30041 \SpecialChar ~
30042 \SpecialChar ~
30043 \SpecialChar ~
30044 \SpecialChar ~
30045 \SpecialChar ~
30046 \SpecialChar ~
30047 \SpecialChar ~
30048 \SpecialChar ~
30049 case 4: ...
30050  
30051 \newline
30052 \SpecialChar ~
30053 \SpecialChar ~
30054 \SpecialChar ~
30055 case 8: ...\SpecialChar ~
30056 \SpecialChar ~
30057 \SpecialChar ~
30058 \SpecialChar ~
30059 \SpecialChar ~
30060 \SpecialChar ~
30061 \SpecialChar ~
30062 \SpecialChar ~
30063 \SpecialChar ~
30064 \SpecialChar ~
30065 \SpecialChar ~
30066 \SpecialChar ~
30067 \SpecialChar ~
30068 \SpecialChar ~
30069 \SpecialChar ~
30070 \SpecialChar ~
30071 \SpecialChar ~
30072 \SpecialChar ~
30073 \SpecialChar ~
30074 \SpecialChar ~
30075 \SpecialChar ~
30076 \SpecialChar ~
30077 \SpecialChar ~
30078 \SpecialChar ~
30079 \SpecialChar ~
30080 \SpecialChar ~
30081 case 5: ...
30082  
30083 \newline
30084 \SpecialChar ~
30085 \SpecialChar ~
30086 \SpecialChar ~
30087 case 9: ...\SpecialChar ~
30088 \SpecialChar ~
30089 \SpecialChar ~
30090 \SpecialChar ~
30091 \SpecialChar ~
30092 \SpecialChar ~
30093 \SpecialChar ~
30094 \SpecialChar ~
30095 \SpecialChar ~
30096 \SpecialChar ~
30097 \SpecialChar ~
30098 \SpecialChar ~
30099 \SpecialChar ~
30100 \SpecialChar ~
30101 \SpecialChar ~
30102 \SpecialChar ~
30103 \SpecialChar ~
30104 \SpecialChar ~
30105 \SpecialChar ~
30106 \SpecialChar ~
30107 \SpecialChar ~
30108 \SpecialChar ~
30109 \SpecialChar ~
30110 \SpecialChar ~
30111 \SpecialChar ~
30112 \SpecialChar ~
30113 case 6: ...
30114  
30115 \newline
30116 \SpecialChar ~
30117 \SpecialChar ~
30118 \SpecialChar ~
30119 case 10: ...\SpecialChar ~
30120 \SpecialChar ~
30121 \SpecialChar ~
30122 \SpecialChar ~
30123 \SpecialChar ~
30124 \SpecialChar ~
30125 \SpecialChar ~
30126 \SpecialChar ~
30127 \SpecialChar ~
30128 \SpecialChar ~
30129 \SpecialChar ~
30130 \SpecialChar ~
30131 \SpecialChar ~
30132 \SpecialChar ~
30133 \SpecialChar ~
30134 \SpecialChar ~
30135 \SpecialChar ~
30136 \SpecialChar ~
30137 \SpecialChar ~
30138 \SpecialChar ~
30139 \SpecialChar ~
30140 \SpecialChar ~
30141 \SpecialChar ~
30142 \SpecialChar ~
30143 \SpecialChar ~
30144 case 7: ...
30145  
30146 \newline
30147 \SpecialChar ~
30148 \SpecialChar ~
30149 \SpecialChar ~
30150 case 11: ...\SpecialChar ~
30151 \SpecialChar ~
30152 \SpecialChar ~
30153 \SpecialChar ~
30154 \SpecialChar ~
30155 \SpecialChar ~
30156 \SpecialChar ~
30157 \SpecialChar ~
30158 \SpecialChar ~
30159 \SpecialChar ~
30160 \SpecialChar ~
30161 \SpecialChar ~
30162 \SpecialChar ~
30163 \SpecialChar ~
30164 \SpecialChar ~
30165 \SpecialChar ~
30166 \SpecialChar ~
30167 \SpecialChar ~
30168 \SpecialChar ~
30169 \SpecialChar ~
30170 \SpecialChar ~
30171 \SpecialChar ~
30172 \SpecialChar ~
30173 \SpecialChar ~
30174 \SpecialChar ~
30175 case 8: ...
30176  
30177 \newline
30178 }\SpecialChar ~
30179 \SpecialChar ~
30180 \SpecialChar ~
30181 \SpecialChar ~
30182 \SpecialChar ~
30183 \SpecialChar ~
30184 \SpecialChar ~
30185 \SpecialChar ~
30186 \SpecialChar ~
30187 \SpecialChar ~
30188 \SpecialChar ~
30189 \SpecialChar ~
30190 \SpecialChar ~
30191 \SpecialChar ~
30192 \SpecialChar ~
30193 \SpecialChar ~
30194 \SpecialChar ~
30195 \SpecialChar ~
30196 \SpecialChar ~
30197 \SpecialChar ~
30198 \SpecialChar ~
30199 \SpecialChar ~
30200 \SpecialChar ~
30201 \SpecialChar ~
30202 \SpecialChar ~
30203 \SpecialChar ~
30204 \SpecialChar ~
30205 \SpecialChar ~
30206 \SpecialChar ~
30207 \SpecialChar ~
30208 \SpecialChar ~
30209 \SpecialChar ~
30210 \SpecialChar ~
30211 \SpecialChar ~
30212 \SpecialChar ~
30213 \SpecialChar ~
30214 }
30215
30216 \layout Standard
30217 Both the above switch statements will be implemented using a jump-table.
30218  The example to the right side is slightly more efficient as the check for
30219  the lower boundary of the jump-table is not needed.
30220
30221 \end_deeper
30222 \layout Itemize
30223 The number of case labels is not larger than supported by the target architectur
30224 e.
30225
30226 \layout Itemize
30227 If the case labels are not in numerical sequence ('gaps' between cases)
30228  SDCC checks whether a jump table with additionally inserted dummy cases
30229  is still attractive.
30230  
30231
30232 \layout Itemize
30233 If the starting number is not zero and a check for the lower boundary of
30234  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
30235  ...
30236  .
30237
30238 \layout Standard
30239 Switch statements which have large gaps in the numeric sequence or those
30240  that have too many case labels can be split into more than one switch statement
30241  for efficient code generation, e.g.:
30242
30243 \layout Verse
30244
30245 \family typewriter
30246 switch (i) { 
30247 \newline
30248 \SpecialChar ~
30249 \SpecialChar ~
30250 case 1: ...
30251  
30252 \newline
30253 \SpecialChar ~
30254 \SpecialChar ~
30255 case 2: ...
30256  
30257 \newline
30258 \SpecialChar ~
30259 \SpecialChar ~
30260 case 3: ...
30261  
30262 \newline
30263 \SpecialChar ~
30264 \SpecialChar ~
30265 case 4: ...
30266  
30267 \newline
30268 \SpecialChar ~
30269 \SpecialChar ~
30270 case 5: ...
30271  
30272 \newline
30273 \SpecialChar ~
30274 \SpecialChar ~
30275 case 6: ...
30276  
30277 \newline
30278 \SpecialChar ~
30279 \SpecialChar ~
30280 case 7: ...
30281  
30282 \newline
30283 \SpecialChar ~
30284 \SpecialChar ~
30285 case 101: ...
30286  
30287 \newline
30288 \SpecialChar ~
30289 \SpecialChar ~
30290 case 102: ...
30291  
30292 \newline
30293 \SpecialChar ~
30294 \SpecialChar ~
30295 case 103: ...
30296  
30297 \newline
30298 \SpecialChar ~
30299 \SpecialChar ~
30300 case 104: ...
30301  
30302 \newline
30303 \SpecialChar ~
30304 \SpecialChar ~
30305 case 105: ...
30306  
30307 \newline
30308 \SpecialChar ~
30309 \SpecialChar ~
30310 case 106: ...
30311  
30312 \newline
30313 \SpecialChar ~
30314 \SpecialChar ~
30315 case 107: ...
30316  
30317 \newline
30318 }
30319
30320 \layout Standard
30321 If the above switch statement is broken down into two switch statements
30322
30323 \layout Verse
30324
30325 \family typewriter
30326 switch (i) { 
30327 \newline
30328 \SpecialChar ~
30329 \SpecialChar ~
30330 case 1: ...
30331  
30332 \newline
30333 \SpecialChar ~
30334 \SpecialChar ~
30335 case 2: ...
30336  
30337 \newline
30338 \SpecialChar ~
30339 \SpecialChar ~
30340 case 3: ...
30341  
30342 \newline
30343 \SpecialChar ~
30344 \SpecialChar ~
30345 case 4: ...
30346  
30347 \newline
30348 \SpecialChar ~
30349 \SpecialChar ~
30350 case 5: ...
30351  
30352 \newline
30353 \SpecialChar ~
30354 \SpecialChar ~
30355 case 6: ...
30356  
30357 \newline
30358 \SpecialChar ~
30359 \SpecialChar ~
30360 case 7: ...
30361  
30362 \newline
30363 }
30364
30365 \layout Standard
30366 and
30367
30368 \layout Verse
30369
30370 \family typewriter
30371 switch (i) { 
30372 \newline
30373 \SpecialChar ~
30374 \SpecialChar ~
30375 case 101: ...
30376  
30377 \newline
30378 \SpecialChar ~
30379 \SpecialChar ~
30380 case 102: ...
30381  
30382 \newline
30383 \SpecialChar ~
30384 \SpecialChar ~
30385 case 103: ...
30386  
30387 \newline
30388 \SpecialChar ~
30389 \SpecialChar ~
30390 case 104: ...
30391  
30392 \newline
30393 \SpecialChar ~
30394 \SpecialChar ~
30395 case 105: ...
30396  
30397 \newline
30398 \SpecialChar ~
30399 \SpecialChar ~
30400 case 106: ...
30401  
30402 \newline
30403 \SpecialChar ~
30404 \SpecialChar ~
30405 case 107: ...
30406  
30407 \newline
30408 }
30409
30410 \layout Standard
30411 then both the switch statements will be implemented using jump-tables whereas
30412  the unmodified switch statement will not be.
30413
30414 \layout Standard
30415 \begin_inset Note
30416 collapsed true
30417
30418 \layout Standard
30419 There might be reasons which SDCC cannot know about to either favour or
30420  not favour jump tables.
30421  If the target system has to be as quick for the last switch case as for
30422  the first (pro jump table), or if the switch argument is known to be zero
30423  in the majority of the cases (contra jump table).
30424
30425 \end_inset
30426
30427
30428
30429 \layout Standard
30430 The pragma nojtbound
30431 \begin_inset LatexCommand \index{\#pragma nojtbound}
30432
30433 \end_inset
30434
30435  can be used to turn off checking the 
30436 \emph on
30437 j
30438 \emph default
30439 ump 
30440 \emph on
30441 t
30442 \emph default
30443 able 
30444 \emph on
30445 bound
30446 \emph default
30447 aries.
30448  It has no effect if a default label is supplied.
30449  Use of this pragma is dangerous: if the switch
30450 \begin_inset LatexCommand \index{switch statement}
30451
30452 \end_inset
30453
30454  argument is not matched by a case statement the processor will happily
30455  jump into Nirvana.
30456
30457 \layout Subsection
30458 Bit-shifting Operations
30459 \begin_inset LatexCommand \index{Bit shifting}
30460
30461 \end_inset
30462
30463 .
30464
30465 \layout Standard
30466 Bit shifting is one of the most frequently used operation in embedded programmin
30467 g.
30468  SDCC tries to implement bit-shift operations in the most efficient way
30469  possible, e.g.:
30470
30471 \layout Verse
30472
30473 \family typewriter
30474 unsigned char i;
30475 \newline
30476 ...
30477  
30478 \newline
30479 i >>= 4; 
30480 \newline
30481 ...
30482
30483 \layout Standard
30484 generates the following code:
30485
30486 \layout Verse
30487
30488 \family typewriter
30489 mov\SpecialChar ~
30490  a,_i 
30491 \newline
30492 swap a 
30493 \newline
30494 anl\SpecialChar ~
30495  a,#0x0f 
30496 \newline
30497 mov\SpecialChar ~
30498  _i,a
30499
30500 \layout Standard
30501 In general SDCC will never setup a loop if the shift count is known.
30502  Another example:
30503
30504 \layout Verse
30505
30506 \family typewriter
30507 unsigned int i; 
30508 \newline
30509 ...
30510  
30511 \newline
30512 i >>= 9; 
30513 \newline
30514 ...
30515
30516 \layout Standard
30517 will generate:
30518
30519 \layout Verse
30520
30521 \family typewriter
30522 mov\SpecialChar ~
30523 \SpecialChar ~
30524 a,(_i + 1) 
30525 \newline
30526 mov\SpecialChar ~
30527 \SpecialChar ~
30528 (_i + 1),#0x00 
30529 \newline
30530 clr\SpecialChar ~
30531 \SpecialChar ~
30532
30533 \newline
30534 rrc\SpecialChar ~
30535 \SpecialChar ~
30536
30537 \newline
30538 mov\SpecialChar ~
30539 \SpecialChar ~
30540 _i,a
30541
30542 \layout Subsection
30543 Bit-rotation
30544 \begin_inset LatexCommand \index{Bit rotation}
30545
30546 \end_inset
30547
30548
30549
30550 \layout Standard
30551 A special case of the bit-shift operation is bit rotation
30552 \begin_inset LatexCommand \index{rotating bits}
30553
30554 \end_inset
30555
30556 , SDCC recognizes the following expression to be a left bit-rotation:
30557
30558 \layout Verse
30559
30560 \family typewriter
30561 \series bold
30562 unsigned
30563 \series default
30564 \SpecialChar ~
30565 \SpecialChar ~
30566 char i;\SpecialChar ~
30567 \SpecialChar ~
30568 \SpecialChar ~
30569 \SpecialChar ~
30570 \SpecialChar ~
30571 \SpecialChar ~
30572 \SpecialChar ~
30573 \SpecialChar ~
30574 \SpecialChar ~
30575 \SpecialChar ~
30576 \SpecialChar ~
30577 /* unsigned is needed for rotation */ 
30578 \newline
30579 ...
30580  
30581 \newline
30582 i = ((i << 1) | (i >> 7)); 
30583 \family default
30584
30585 \newline
30586
30587 \family typewriter
30588 ...
30589
30590 \layout Standard
30591 will generate the following code:
30592
30593 \layout Verse
30594
30595 \family typewriter
30596 mov\SpecialChar ~
30597 \SpecialChar ~
30598 a,_i 
30599 \newline
30600 rl\SpecialChar ~
30601 \SpecialChar ~
30602 \SpecialChar ~
30603
30604 \newline
30605 mov\SpecialChar ~
30606 \SpecialChar ~
30607 _i,a
30608
30609 \layout Standard
30610 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
30611 ns of this case will also be recognized as bit-rotation, i.e.: 
30612
30613 \layout Verse
30614
30615 \family typewriter
30616 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
30617
30618 \layout Subsection
30619 Nibble and Byte Swapping
30620
30621 \layout Standard
30622 Other special cases of the bit-shift operations are nibble or byte swapping
30623 \begin_inset LatexCommand \index{swapping nibbles/bytes}
30624
30625 \end_inset
30626
30627 , SDCC recognizes the following expressions:
30628
30629 \layout Verse
30630
30631 \family typewriter
30632 \series bold
30633 unsigned
30634 \series default
30635 \SpecialChar ~
30636 \SpecialChar ~
30637 char i; 
30638 \newline
30639
30640 \series bold
30641 unsigned
30642 \series default
30643 \SpecialChar ~
30644 \SpecialChar ~
30645 int j; 
30646 \newline
30647 ...
30648  
30649 \newline
30650 i = ((i << 4) | (i >> 4)); 
30651 \family default
30652
30653 \newline
30654
30655 \family typewriter
30656 j = ((j << 8) | (j >> 8)); 
30657
30658 \layout Standard
30659 and generates a swap instruction for the nibble swapping
30660 \begin_inset LatexCommand \index{Nibble swapping}
30661
30662 \end_inset
30663
30664  or move instructions for the byte swapping
30665 \begin_inset LatexCommand \index{Byte swapping}
30666
30667 \end_inset
30668
30669 .
30670  The 
30671 \begin_inset Quotes sld
30672 \end_inset
30673
30674 j
30675 \begin_inset Quotes srd
30676 \end_inset
30677
30678  example can be used to convert from little to big-endian or vice versa.
30679  If you want to change the endianness of a 
30680 \emph on
30681 signed
30682 \emph default
30683  integer you have to cast to 
30684 \family typewriter
30685 (unsigned int)
30686 \family default
30687  first.
30688
30689 \layout Standard
30690 Note that SDCC stores numbers in little-endian
30691 \begin_inset Foot
30692 collapsed false
30693
30694 \layout Standard
30695 Usually 8-bit processors don't care much about endianness.
30696  This is not the case for the standard 8051 which only has an instruction
30697  to increment its 
30698 \emph on
30699 dptr
30700 \emph default
30701
30702 \begin_inset LatexCommand \index{DPTR}
30703
30704 \end_inset
30705
30706 -datapointer
30707 \emph on
30708  
30709 \emph default
30710 so little-endian is the more efficient byte order.
30711
30712 \end_inset
30713
30714
30715 \begin_inset LatexCommand \index{little-endian}
30716
30717 \end_inset
30718
30719
30720 \begin_inset LatexCommand \index{Endianness}
30721
30722 \end_inset
30723
30724  format (i.e.
30725  lowest order first).
30726
30727 \layout Subsection
30728 Highest Order Bit
30729 \begin_inset LatexCommand \index{Highest Order Bit}
30730
30731 \end_inset
30732
30733  / Any Order Bit
30734 \begin_inset LatexCommand \index{Any Order Bit}
30735
30736 \end_inset
30737
30738
30739
30740 \layout Standard
30741 It is frequently required to obtain the highest order bit of an integral
30742  type (long, int, short or char types).
30743  Also obtaining any other order bit is not uncommon.
30744  SDCC recognizes the following expressions to yield the highest order bit
30745  and generates optimized code for it, e.g.:
30746
30747 \layout Verse
30748
30749 \family typewriter
30750 unsigned int gint; 
30751 \newline
30752
30753 \newline
30754 foo () { 
30755 \newline
30756 \SpecialChar ~
30757 \SpecialChar ~
30758 unsigned char hob1, aob1; 
30759 \newline
30760 \SpecialChar ~
30761 \SpecialChar ~
30762 bit hob2, hob3, aob2,
30763  aob3; 
30764 \newline
30765 \SpecialChar ~
30766 \SpecialChar ~
30767 ...
30768  
30769 \newline
30770 \SpecialChar ~
30771 \SpecialChar ~
30772 hob1 = (gint >> 15) & 1; 
30773 \newline
30774 \SpecialChar ~
30775 \SpecialChar ~
30776 hob2 = (gint >> 15) & 1; 
30777 \newline
30778 \SpecialChar ~
30779 \SpecialChar ~
30780 hob3 = gint & 0x8000;
30781  
30782 \newline
30783 \SpecialChar ~
30784 \SpecialChar ~
30785 aob1 = (gint >> 9) & 1; 
30786 \newline
30787 \SpecialChar ~
30788 \SpecialChar ~
30789 aob2 = (gint >> 8) & 1; 
30790 \newline
30791 \SpecialChar ~
30792 \SpecialChar ~
30793 aob3 = gint & 0x0800; 
30794 \newline
30795 \SpecialChar ~
30796 \SpecialChar ~
30797 ..
30798  
30799 \newline
30800 }
30801
30802 \layout Standard
30803 will generate the following code:
30804
30805 \layout Verse
30806
30807 \family typewriter
30808 \SpecialChar ~
30809 \SpecialChar ~
30810 \SpecialChar ~
30811 \SpecialChar ~
30812 \SpecialChar ~
30813 \SpecialChar ~
30814 \SpecialChar ~
30815 \SpecialChar ~
30816 \SpecialChar ~
30817 \SpecialChar ~
30818 \SpecialChar ~
30819 \SpecialChar ~
30820 \SpecialChar ~
30821 \SpecialChar ~
30822 \SpecialChar ~
30823 \SpecialChar ~
30824 \SpecialChar ~
30825 \SpecialChar ~
30826 \SpecialChar ~
30827 \SpecialChar ~
30828 \SpecialChar ~
30829 \SpecialChar ~
30830 \SpecialChar ~
30831 \SpecialChar ~
30832 \SpecialChar ~
30833  61 ;\SpecialChar ~
30834  hob.c 7 
30835 \newline
30836 000A E5*01\SpecialChar ~
30837 \SpecialChar ~
30838 \SpecialChar ~
30839 \SpecialChar ~
30840 \SpecialChar ~
30841 \SpecialChar ~
30842 \SpecialChar ~
30843 \SpecialChar ~
30844 \SpecialChar ~
30845 \SpecialChar ~
30846 \SpecialChar ~
30847 \SpecialChar ~
30848 \SpecialChar ~
30849 \SpecialChar ~
30850 \SpecialChar ~
30851  62\SpecialChar ~
30852 \SpecialChar ~
30853 \SpecialChar ~
30854 \SpecialChar ~
30855 \SpecialChar ~
30856 \SpecialChar ~
30857 \SpecialChar ~
30858 \SpecialChar ~
30859  mov\SpecialChar ~
30860 \SpecialChar ~
30861  a,(_gint + 1) 
30862 \newline
30863 000C 23\SpecialChar ~
30864 \SpecialChar ~
30865 \SpecialChar ~
30866 \SpecialChar ~
30867 \SpecialChar ~
30868 \SpecialChar ~
30869 \SpecialChar ~
30870 \SpecialChar ~
30871 \SpecialChar ~
30872 \SpecialChar ~
30873 \SpecialChar ~
30874 \SpecialChar ~
30875 \SpecialChar ~
30876 \SpecialChar ~
30877 \SpecialChar ~
30878 \SpecialChar ~
30879 \SpecialChar ~
30880 \SpecialChar ~
30881  63\SpecialChar ~
30882 \SpecialChar ~
30883 \SpecialChar ~
30884 \SpecialChar ~
30885 \SpecialChar ~
30886 \SpecialChar ~
30887 \SpecialChar ~
30888 \SpecialChar ~
30889  rl\SpecialChar ~
30890 \SpecialChar ~
30891 \SpecialChar ~
30892  a 
30893 \newline
30894 000D 54 01\SpecialChar ~
30895 \SpecialChar ~
30896 \SpecialChar ~
30897 \SpecialChar ~
30898 \SpecialChar ~
30899 \SpecialChar ~
30900 \SpecialChar ~
30901 \SpecialChar ~
30902 \SpecialChar ~
30903 \SpecialChar ~
30904 \SpecialChar ~
30905 \SpecialChar ~
30906 \SpecialChar ~
30907 \SpecialChar ~
30908 \SpecialChar ~
30909
30910  64\SpecialChar ~
30911 \SpecialChar ~
30912 \SpecialChar ~
30913 \SpecialChar ~
30914 \SpecialChar ~
30915 \SpecialChar ~
30916 \SpecialChar ~
30917 \SpecialChar ~
30918  anl\SpecialChar ~
30919 \SpecialChar ~
30920  a,#0x01 
30921 \newline
30922 000F F5*02\SpecialChar ~
30923 \SpecialChar ~
30924 \SpecialChar ~
30925 \SpecialChar ~
30926 \SpecialChar ~
30927 \SpecialChar ~
30928 \SpecialChar ~
30929 \SpecialChar ~
30930 \SpecialChar ~
30931 \SpecialChar ~
30932 \SpecialChar ~
30933 \SpecialChar ~
30934 \SpecialChar ~
30935 \SpecialChar ~
30936 \SpecialChar ~
30937  65\SpecialChar ~
30938 \SpecialChar ~
30939 \SpecialChar ~
30940 \SpecialChar ~
30941 \SpecialChar ~
30942 \SpecialChar ~
30943 \SpecialChar ~
30944 \SpecialChar ~
30945  mov\SpecialChar ~
30946 \SpecialChar ~
30947  _foo_hob1_1_1,a 
30948 \newline
30949 \SpecialChar ~
30950 \SpecialChar ~
30951 \SpecialChar ~
30952 \SpecialChar ~
30953 \SpecialChar ~
30954 \SpecialChar ~
30955 \SpecialChar ~
30956 \SpecialChar ~
30957 \SpecialChar ~
30958 \SpecialChar ~
30959 \SpecialChar ~
30960 \SpecialChar ~
30961 \SpecialChar ~
30962 \SpecialChar ~
30963 \SpecialChar ~
30964 \SpecialChar ~
30965 \SpecialChar ~
30966 \SpecialChar ~
30967 \SpecialChar ~
30968 \SpecialChar ~
30969 \SpecialChar ~
30970 \SpecialChar ~
30971 \SpecialChar ~
30972 \SpecialChar ~
30973 \SpecialChar ~
30974  66 ;\SpecialChar ~
30975  hob.c 8 
30976 \newline
30977 0011 E5*01\SpecialChar ~
30978 \SpecialChar ~
30979 \SpecialChar ~
30980 \SpecialChar ~
30981 \SpecialChar ~
30982 \SpecialChar ~
30983 \SpecialChar ~
30984 \SpecialChar ~
30985 \SpecialChar ~
30986 \SpecialChar ~
30987 \SpecialChar ~
30988 \SpecialChar ~
30989 \SpecialChar ~
30990 \SpecialChar ~
30991 \SpecialChar ~
30992
30993  67\SpecialChar ~
30994 \SpecialChar ~
30995 \SpecialChar ~
30996 \SpecialChar ~
30997 \SpecialChar ~
30998 \SpecialChar ~
30999 \SpecialChar ~
31000 \SpecialChar ~
31001  mov\SpecialChar ~
31002 \SpecialChar ~
31003  a,(_gint + 1) 
31004 \newline
31005 0013 33\SpecialChar ~
31006 \SpecialChar ~
31007 \SpecialChar ~
31008 \SpecialChar ~
31009 \SpecialChar ~
31010 \SpecialChar ~
31011 \SpecialChar ~
31012 \SpecialChar ~
31013 \SpecialChar ~
31014 \SpecialChar ~
31015 \SpecialChar ~
31016 \SpecialChar ~
31017 \SpecialChar ~
31018 \SpecialChar ~
31019 \SpecialChar ~
31020 \SpecialChar ~
31021 \SpecialChar ~
31022 \SpecialChar ~
31023  68\SpecialChar ~
31024 \SpecialChar ~
31025 \SpecialChar ~
31026 \SpecialChar ~
31027 \SpecialChar ~
31028 \SpecialChar ~
31029 \SpecialChar ~
31030 \SpecialChar ~
31031  rlc\SpecialChar ~
31032 \SpecialChar ~
31033  a 
31034 \newline
31035 0014 92*00\SpecialChar ~
31036 \SpecialChar ~
31037 \SpecialChar ~
31038 \SpecialChar ~
31039 \SpecialChar ~
31040 \SpecialChar ~
31041 \SpecialChar ~
31042 \SpecialChar ~
31043 \SpecialChar ~
31044 \SpecialChar ~
31045 \SpecialChar ~
31046 \SpecialChar ~
31047 \SpecialChar ~
31048 \SpecialChar ~
31049 \SpecialChar ~
31050  69\SpecialChar ~
31051 \SpecialChar ~
31052 \SpecialChar ~
31053 \SpecialChar ~
31054 \SpecialChar ~
31055 \SpecialChar ~
31056 \SpecialChar ~
31057 \SpecialChar ~
31058  mov\SpecialChar ~
31059 \SpecialChar ~
31060  _foo_hob2_1_1,c
31061  
31062 \newline
31063 \SpecialChar ~
31064 \SpecialChar ~
31065 \SpecialChar ~
31066 \SpecialChar ~
31067 \SpecialChar ~
31068 \SpecialChar ~
31069 \SpecialChar ~
31070 \SpecialChar ~
31071 \SpecialChar ~
31072 \SpecialChar ~
31073 \SpecialChar ~
31074 \SpecialChar ~
31075 \SpecialChar ~
31076 \SpecialChar ~
31077 \SpecialChar ~
31078 \SpecialChar ~
31079 \SpecialChar ~
31080 \SpecialChar ~
31081 \SpecialChar ~
31082 \SpecialChar ~
31083 \SpecialChar ~
31084 \SpecialChar ~
31085 \SpecialChar ~
31086 \SpecialChar ~
31087 \SpecialChar ~
31088  66 ;\SpecialChar ~
31089  hob.c 9 
31090 \newline
31091 0016 E5*01\SpecialChar ~
31092 \SpecialChar ~
31093 \SpecialChar ~
31094 \SpecialChar ~
31095 \SpecialChar ~
31096 \SpecialChar ~
31097 \SpecialChar ~
31098 \SpecialChar ~
31099 \SpecialChar ~
31100 \SpecialChar ~
31101 \SpecialChar ~
31102 \SpecialChar ~
31103 \SpecialChar ~
31104 \SpecialChar ~
31105 \SpecialChar ~
31106  67\SpecialChar ~
31107 \SpecialChar ~
31108 \SpecialChar ~
31109 \SpecialChar ~
31110 \SpecialChar ~
31111 \SpecialChar ~
31112 \SpecialChar ~
31113 \SpecialChar ~
31114  mov\SpecialChar ~
31115 \SpecialChar ~
31116  a,(_gint + 1) 
31117 \newline
31118 0018 33\SpecialChar ~
31119 \SpecialChar ~
31120 \SpecialChar ~
31121 \SpecialChar ~
31122 \SpecialChar ~
31123 \SpecialChar ~
31124 \SpecialChar ~
31125 \SpecialChar ~
31126 \SpecialChar ~
31127 \SpecialChar ~
31128 \SpecialChar ~
31129 \SpecialChar ~
31130 \SpecialChar ~
31131 \SpecialChar ~
31132 \SpecialChar ~
31133 \SpecialChar ~
31134 \SpecialChar ~
31135 \SpecialChar ~
31136  68\SpecialChar ~
31137 \SpecialChar ~
31138 \SpecialChar ~
31139 \SpecialChar ~
31140 \SpecialChar ~
31141 \SpecialChar ~
31142 \SpecialChar ~
31143 \SpecialChar ~
31144  rlc\SpecialChar ~
31145 \SpecialChar ~
31146  a 
31147 \newline
31148 0019 92*01\SpecialChar ~
31149 \SpecialChar ~
31150 \SpecialChar ~
31151 \SpecialChar ~
31152 \SpecialChar ~
31153 \SpecialChar ~
31154 \SpecialChar ~
31155 \SpecialChar ~
31156 \SpecialChar ~
31157 \SpecialChar ~
31158 \SpecialChar ~
31159 \SpecialChar ~
31160 \SpecialChar ~
31161 \SpecialChar ~
31162 \SpecialChar ~
31163
31164  69\SpecialChar ~
31165 \SpecialChar ~
31166 \SpecialChar ~
31167 \SpecialChar ~
31168 \SpecialChar ~
31169 \SpecialChar ~
31170 \SpecialChar ~
31171 \SpecialChar ~
31172  mov\SpecialChar ~
31173 \SpecialChar ~
31174  _foo_hob3_1_1,c 
31175 \newline
31176 \SpecialChar ~
31177 \SpecialChar ~
31178 \SpecialChar ~
31179 \SpecialChar ~
31180 \SpecialChar ~
31181 \SpecialChar ~
31182 \SpecialChar ~
31183 \SpecialChar ~
31184 \SpecialChar ~
31185 \SpecialChar ~
31186 \SpecialChar ~
31187 \SpecialChar ~
31188 \SpecialChar ~
31189 \SpecialChar ~
31190 \SpecialChar ~
31191 \SpecialChar ~
31192 \SpecialChar ~
31193 \SpecialChar ~
31194 \SpecialChar ~
31195 \SpecialChar ~
31196 \SpecialChar ~
31197 \SpecialChar ~
31198 \SpecialChar ~
31199 \SpecialChar ~
31200 \SpecialChar ~
31201  70 ;\SpecialChar ~
31202  hob.c 10 
31203 \newline
31204 001B E5*01\SpecialChar ~
31205 \SpecialChar ~
31206 \SpecialChar ~
31207 \SpecialChar ~
31208 \SpecialChar ~
31209 \SpecialChar ~
31210 \SpecialChar ~
31211 \SpecialChar ~
31212 \SpecialChar ~
31213 \SpecialChar ~
31214 \SpecialChar ~
31215 \SpecialChar ~
31216 \SpecialChar ~
31217 \SpecialChar ~
31218 \SpecialChar ~
31219  71\SpecialChar ~
31220 \SpecialChar ~
31221 \SpecialChar ~
31222 \SpecialChar ~
31223 \SpecialChar ~
31224 \SpecialChar ~
31225 \SpecialChar ~
31226 \SpecialChar ~
31227  mov\SpecialChar ~
31228 \SpecialChar ~
31229  a,(_gint + 1) 
31230 \newline
31231 001D
31232  03\SpecialChar ~
31233 \SpecialChar ~
31234 \SpecialChar ~
31235 \SpecialChar ~
31236 \SpecialChar ~
31237 \SpecialChar ~
31238 \SpecialChar ~
31239 \SpecialChar ~
31240 \SpecialChar ~
31241 \SpecialChar ~
31242 \SpecialChar ~
31243 \SpecialChar ~
31244 \SpecialChar ~
31245 \SpecialChar ~
31246 \SpecialChar ~
31247 \SpecialChar ~
31248 \SpecialChar ~
31249 \SpecialChar ~
31250  72\SpecialChar ~
31251 \SpecialChar ~
31252 \SpecialChar ~
31253 \SpecialChar ~
31254 \SpecialChar ~
31255 \SpecialChar ~
31256 \SpecialChar ~
31257 \SpecialChar ~
31258  rr\SpecialChar ~
31259 \SpecialChar ~
31260 \SpecialChar ~
31261  a 
31262 \newline
31263 001E 54 01\SpecialChar ~
31264 \SpecialChar ~
31265 \SpecialChar ~
31266 \SpecialChar ~
31267 \SpecialChar ~
31268 \SpecialChar ~
31269 \SpecialChar ~
31270 \SpecialChar ~
31271 \SpecialChar ~
31272 \SpecialChar ~
31273 \SpecialChar ~
31274 \SpecialChar ~
31275 \SpecialChar ~
31276 \SpecialChar ~
31277 \SpecialChar ~
31278  73\SpecialChar ~
31279 \SpecialChar ~
31280 \SpecialChar ~
31281 \SpecialChar ~
31282 \SpecialChar ~
31283 \SpecialChar ~
31284 \SpecialChar ~
31285 \SpecialChar ~
31286  anl\SpecialChar ~
31287 \SpecialChar ~
31288  a,#0x01 
31289 \newline
31290 0020 F5*03\SpecialChar ~
31291 \SpecialChar ~
31292 \SpecialChar ~
31293 \SpecialChar ~
31294 \SpecialChar ~
31295 \SpecialChar ~
31296 \SpecialChar ~
31297 \SpecialChar ~
31298 \SpecialChar ~
31299 \SpecialChar ~
31300 \SpecialChar ~
31301 \SpecialChar ~
31302 \SpecialChar ~
31303 \SpecialChar ~
31304 \SpecialChar ~
31305  74\SpecialChar ~
31306 \SpecialChar ~
31307 \SpecialChar ~
31308 \SpecialChar ~
31309 \SpecialChar ~
31310 \SpecialChar ~
31311 \SpecialChar ~
31312 \SpecialChar ~
31313  mov\SpecialChar ~
31314 \SpecialChar ~
31315  _foo_aob1_1_1,a
31316  
31317 \newline
31318 \SpecialChar ~
31319 \SpecialChar ~
31320 \SpecialChar ~
31321 \SpecialChar ~
31322 \SpecialChar ~
31323 \SpecialChar ~
31324 \SpecialChar ~
31325 \SpecialChar ~
31326 \SpecialChar ~
31327 \SpecialChar ~
31328 \SpecialChar ~
31329 \SpecialChar ~
31330 \SpecialChar ~
31331 \SpecialChar ~
31332 \SpecialChar ~
31333 \SpecialChar ~
31334 \SpecialChar ~
31335 \SpecialChar ~
31336 \SpecialChar ~
31337 \SpecialChar ~
31338 \SpecialChar ~
31339 \SpecialChar ~
31340 \SpecialChar ~
31341 \SpecialChar ~
31342 \SpecialChar ~
31343  75 ;\SpecialChar ~
31344  hob.c 11 
31345 \newline
31346 0022 E5*01\SpecialChar ~
31347 \SpecialChar ~
31348 \SpecialChar ~
31349 \SpecialChar ~
31350 \SpecialChar ~
31351 \SpecialChar ~
31352 \SpecialChar ~
31353 \SpecialChar ~
31354 \SpecialChar ~
31355 \SpecialChar ~
31356 \SpecialChar ~
31357 \SpecialChar ~
31358 \SpecialChar ~
31359 \SpecialChar ~
31360 \SpecialChar ~
31361  76\SpecialChar ~
31362 \SpecialChar ~
31363 \SpecialChar ~
31364 \SpecialChar ~
31365 \SpecialChar ~
31366 \SpecialChar ~
31367 \SpecialChar ~
31368 \SpecialChar ~
31369  mov\SpecialChar ~
31370 \SpecialChar ~
31371  a,(_gint + 1) 
31372 \newline
31373 0024 13\SpecialChar ~
31374 \SpecialChar ~
31375 \SpecialChar ~
31376 \SpecialChar ~
31377 \SpecialChar ~
31378 \SpecialChar ~
31379 \SpecialChar ~
31380 \SpecialChar ~
31381 \SpecialChar ~
31382 \SpecialChar ~
31383 \SpecialChar ~
31384 \SpecialChar ~
31385 \SpecialChar ~
31386 \SpecialChar ~
31387 \SpecialChar ~
31388 \SpecialChar ~
31389 \SpecialChar ~
31390 \SpecialChar ~
31391  77\SpecialChar ~
31392 \SpecialChar ~
31393 \SpecialChar ~
31394 \SpecialChar ~
31395 \SpecialChar ~
31396 \SpecialChar ~
31397 \SpecialChar ~
31398 \SpecialChar ~
31399  rrc\SpecialChar ~
31400 \SpecialChar ~
31401  a 
31402 \newline
31403 0025 92*02\SpecialChar ~
31404 \SpecialChar ~
31405 \SpecialChar ~
31406 \SpecialChar ~
31407 \SpecialChar ~
31408 \SpecialChar ~
31409 \SpecialChar ~
31410 \SpecialChar ~
31411 \SpecialChar ~
31412 \SpecialChar ~
31413 \SpecialChar ~
31414 \SpecialChar ~
31415 \SpecialChar ~
31416 \SpecialChar ~
31417 \SpecialChar ~
31418
31419  78\SpecialChar ~
31420 \SpecialChar ~
31421 \SpecialChar ~
31422 \SpecialChar ~
31423 \SpecialChar ~
31424 \SpecialChar ~
31425 \SpecialChar ~
31426 \SpecialChar ~
31427  mov\SpecialChar ~
31428 \SpecialChar ~
31429  _foo_aob2_1_1,c 
31430 \newline
31431 \SpecialChar ~
31432 \SpecialChar ~
31433 \SpecialChar ~
31434 \SpecialChar ~
31435 \SpecialChar ~
31436 \SpecialChar ~
31437 \SpecialChar ~
31438 \SpecialChar ~
31439 \SpecialChar ~
31440 \SpecialChar ~
31441 \SpecialChar ~
31442 \SpecialChar ~
31443 \SpecialChar ~
31444 \SpecialChar ~
31445 \SpecialChar ~
31446 \SpecialChar ~
31447 \SpecialChar ~
31448 \SpecialChar ~
31449 \SpecialChar ~
31450 \SpecialChar ~
31451 \SpecialChar ~
31452 \SpecialChar ~
31453 \SpecialChar ~
31454 \SpecialChar ~
31455 \SpecialChar ~
31456  79 ;\SpecialChar ~
31457  hob.c 12 
31458 \newline
31459 0027 E5*01\SpecialChar ~
31460 \SpecialChar ~
31461 \SpecialChar ~
31462 \SpecialChar ~
31463 \SpecialChar ~
31464 \SpecialChar ~
31465 \SpecialChar ~
31466 \SpecialChar ~
31467 \SpecialChar ~
31468 \SpecialChar ~
31469 \SpecialChar ~
31470 \SpecialChar ~
31471 \SpecialChar ~
31472 \SpecialChar ~
31473 \SpecialChar ~
31474  80\SpecialChar ~
31475 \SpecialChar ~
31476 \SpecialChar ~
31477 \SpecialChar ~
31478 \SpecialChar ~
31479 \SpecialChar ~
31480 \SpecialChar ~
31481 \SpecialChar ~
31482  mov\SpecialChar ~
31483 \SpecialChar ~
31484  a,(_gint + 1) 
31485 \newline
31486 0029
31487  A2 E3\SpecialChar ~
31488 \SpecialChar ~
31489 \SpecialChar ~
31490 \SpecialChar ~
31491 \SpecialChar ~
31492 \SpecialChar ~
31493 \SpecialChar ~
31494 \SpecialChar ~
31495 \SpecialChar ~
31496 \SpecialChar ~
31497 \SpecialChar ~
31498 \SpecialChar ~
31499 \SpecialChar ~
31500 \SpecialChar ~
31501 \SpecialChar ~
31502  81\SpecialChar ~
31503 \SpecialChar ~
31504 \SpecialChar ~
31505 \SpecialChar ~
31506 \SpecialChar ~
31507 \SpecialChar ~
31508 \SpecialChar ~
31509 \SpecialChar ~
31510  mov\SpecialChar ~
31511 \SpecialChar ~
31512  c,acc[3] 
31513 \newline
31514 002B 92*03\SpecialChar ~
31515 \SpecialChar ~
31516 \SpecialChar ~
31517 \SpecialChar ~
31518 \SpecialChar ~
31519 \SpecialChar ~
31520 \SpecialChar ~
31521 \SpecialChar ~
31522 \SpecialChar ~
31523 \SpecialChar ~
31524 \SpecialChar ~
31525 \SpecialChar ~
31526 \SpecialChar ~
31527 \SpecialChar ~
31528 \SpecialChar ~
31529  82\SpecialChar ~
31530 \SpecialChar ~
31531 \SpecialChar ~
31532 \SpecialChar ~
31533 \SpecialChar ~
31534 \SpecialChar ~
31535 \SpecialChar ~
31536 \SpecialChar ~
31537  mov\SpecialChar ~
31538 \SpecialChar ~
31539  _foo_aob3_1_1,c 
31540
31541 \layout Standard
31542 Other variations of these cases however will 
31543 \emph on
31544 not
31545 \emph default
31546  be recognized.
31547  They are standard C expressions, so I heartily recommend these be the only
31548  way to get the highest order bit, (it is portable).
31549  Of course it will be recognized even if it is embedded in other expressions,
31550  e.g.:
31551
31552 \layout Verse
31553
31554 \family typewriter
31555 xyz = gint + ((gint >> 15) & 1);
31556
31557 \layout Standard
31558 will still be recognized.
31559
31560 \layout Subsection
31561 Higher Order Byte
31562 \begin_inset LatexCommand \index{Higher Order Byte}
31563
31564 \end_inset
31565
31566  / Higher Order Word
31567 \begin_inset LatexCommand \index{Higher Order Word}
31568
31569 \end_inset
31570
31571
31572
31573 \layout Standard
31574 It is also frequently required to obtain a higher order byte or word of
31575  a larger integral type (long, int or short types).
31576  SDCC recognizes the following expressions to yield the higher order byte
31577  or word and generates optimized code for it, e.g.:
31578
31579 \layout Verse
31580
31581 \family typewriter
31582 unsigned int gint; 
31583 \newline
31584 unsigned long int glong; 
31585 \newline
31586
31587 \newline
31588 foo () { 
31589 \newline
31590 \SpecialChar ~
31591 \SpecialChar ~
31592 unsigned char hob1,
31593  hob2; 
31594 \newline
31595 \SpecialChar ~
31596 \SpecialChar ~
31597 unsigned int how1, how2; 
31598 \newline
31599 \SpecialChar ~
31600 \SpecialChar ~
31601 ...
31602  
31603 \newline
31604 \SpecialChar ~
31605 \SpecialChar ~
31606 hob1 = (gint >> 8) & 0xFF; 
31607 \newline
31608 \SpecialChar ~
31609 \SpecialChar ~
31610 hob2 = glong >> 24; 
31611 \newline
31612 \SpecialChar ~
31613 \SpecialChar ~
31614 how1 = (glong >> 16) & 0xFFFF;
31615  
31616 \newline
31617 \SpecialChar ~
31618 \SpecialChar ~
31619 how2 = glong >> 8; 
31620 \newline
31621 \SpecialChar ~
31622 \SpecialChar ~
31623 ..
31624  
31625 \newline
31626 }
31627
31628 \layout Standard
31629 will generate the following code:
31630
31631 \layout Verse
31632
31633 \family typewriter
31634 \SpecialChar ~
31635 \SpecialChar ~
31636 \SpecialChar ~
31637 \SpecialChar ~
31638 \SpecialChar ~
31639 \SpecialChar ~
31640 \SpecialChar ~
31641 \SpecialChar ~
31642 \SpecialChar ~
31643 \SpecialChar ~
31644 \SpecialChar ~
31645 \SpecialChar ~
31646 \SpecialChar ~
31647 \SpecialChar ~
31648 \SpecialChar ~
31649 \SpecialChar ~
31650 \SpecialChar ~
31651 \SpecialChar ~
31652 \SpecialChar ~
31653 \SpecialChar ~
31654 \SpecialChar ~
31655 \SpecialChar ~
31656 \SpecialChar ~
31657 \SpecialChar ~
31658 \SpecialChar ~
31659  91 ;\SpecialChar ~
31660  hob.c 15 
31661 \newline
31662 0037 85*01*06\SpecialChar ~
31663 \SpecialChar ~
31664 \SpecialChar ~
31665 \SpecialChar ~
31666 \SpecialChar ~
31667 \SpecialChar ~
31668 \SpecialChar ~
31669 \SpecialChar ~
31670 \SpecialChar ~
31671 \SpecialChar ~
31672 \SpecialChar ~
31673 \SpecialChar ~
31674  92\SpecialChar ~
31675 \SpecialChar ~
31676 \SpecialChar ~
31677 \SpecialChar ~
31678 \SpecialChar ~
31679 \SpecialChar ~
31680 \SpecialChar ~
31681 \SpecialChar ~
31682  mov\SpecialChar ~
31683 \SpecialChar ~
31684  _foo_hob1_1_1,(_gint + 1) 
31685 \newline
31686 \SpecialChar ~
31687 \SpecialChar ~
31688 \SpecialChar ~
31689 \SpecialChar ~
31690 \SpecialChar ~
31691 \SpecialChar ~
31692 \SpecialChar ~
31693 \SpecialChar ~
31694 \SpecialChar ~
31695 \SpecialChar ~
31696 \SpecialChar ~
31697 \SpecialChar ~
31698 \SpecialChar ~
31699 \SpecialChar ~
31700 \SpecialChar ~
31701 \SpecialChar ~
31702 \SpecialChar ~
31703 \SpecialChar ~
31704 \SpecialChar ~
31705 \SpecialChar ~
31706 \SpecialChar ~
31707 \SpecialChar ~
31708 \SpecialChar ~
31709 \SpecialChar ~
31710 \SpecialChar ~
31711  93 ;\SpecialChar ~
31712  hob.c
31713  16 
31714 \newline
31715 003A 85*05*07\SpecialChar ~
31716 \SpecialChar ~
31717 \SpecialChar ~
31718 \SpecialChar ~
31719 \SpecialChar ~
31720 \SpecialChar ~
31721 \SpecialChar ~
31722 \SpecialChar ~
31723 \SpecialChar ~
31724 \SpecialChar ~
31725 \SpecialChar ~
31726 \SpecialChar ~
31727  94\SpecialChar ~
31728 \SpecialChar ~
31729 \SpecialChar ~
31730 \SpecialChar ~
31731 \SpecialChar ~
31732 \SpecialChar ~
31733 \SpecialChar ~
31734 \SpecialChar ~
31735  mov\SpecialChar ~
31736 \SpecialChar ~
31737  _foo_hob2_1_1,(_glong + 3) 
31738 \newline
31739 \SpecialChar ~
31740 \SpecialChar ~
31741 \SpecialChar ~
31742 \SpecialChar ~
31743 \SpecialChar ~
31744 \SpecialChar ~
31745 \SpecialChar ~
31746 \SpecialChar ~
31747 \SpecialChar ~
31748 \SpecialChar ~
31749 \SpecialChar ~
31750 \SpecialChar ~
31751 \SpecialChar ~
31752 \SpecialChar ~
31753 \SpecialChar ~
31754 \SpecialChar ~
31755 \SpecialChar ~
31756 \SpecialChar ~
31757 \SpecialChar ~
31758 \SpecialChar ~
31759 \SpecialChar ~
31760 \SpecialChar ~
31761 \SpecialChar ~
31762 \SpecialChar ~
31763 \SpecialChar ~
31764  95 ;\SpecialChar ~
31765  hob.c 17 
31766 \newline
31767 003D 85*04*08\SpecialChar ~
31768 \SpecialChar ~
31769 \SpecialChar ~
31770 \SpecialChar ~
31771 \SpecialChar ~
31772 \SpecialChar ~
31773 \SpecialChar ~
31774 \SpecialChar ~
31775 \SpecialChar ~
31776 \SpecialChar ~
31777 \SpecialChar ~
31778 \SpecialChar ~
31779
31780  96\SpecialChar ~
31781 \SpecialChar ~
31782 \SpecialChar ~
31783 \SpecialChar ~
31784 \SpecialChar ~
31785 \SpecialChar ~
31786 \SpecialChar ~
31787 \SpecialChar ~
31788  mov\SpecialChar ~
31789 \SpecialChar ~
31790  _foo_how1_1_1,(_glong + 2) 
31791 \newline
31792 0040 85*05*09\SpecialChar ~
31793 \SpecialChar ~
31794 \SpecialChar ~
31795 \SpecialChar ~
31796 \SpecialChar ~
31797 \SpecialChar ~
31798 \SpecialChar ~
31799 \SpecialChar ~
31800 \SpecialChar ~
31801 \SpecialChar ~
31802 \SpecialChar ~
31803 \SpecialChar ~
31804  97\SpecialChar ~
31805 \SpecialChar ~
31806 \SpecialChar ~
31807 \SpecialChar ~
31808 \SpecialChar ~
31809 \SpecialChar ~
31810 \SpecialChar ~
31811 \SpecialChar ~
31812  mov\SpecialChar ~
31813 \SpecialChar ~
31814  (_foo_how1_1_1 +
31815  1),(_glong + 3) 
31816 \newline
31817 0043 85*03*0A\SpecialChar ~
31818 \SpecialChar ~
31819 \SpecialChar ~
31820 \SpecialChar ~
31821 \SpecialChar ~
31822 \SpecialChar ~
31823 \SpecialChar ~
31824 \SpecialChar ~
31825 \SpecialChar ~
31826 \SpecialChar ~
31827 \SpecialChar ~
31828 \SpecialChar ~
31829  98\SpecialChar ~
31830 \SpecialChar ~
31831 \SpecialChar ~
31832 \SpecialChar ~
31833 \SpecialChar ~
31834 \SpecialChar ~
31835 \SpecialChar ~
31836 \SpecialChar ~
31837  mov\SpecialChar ~
31838 \SpecialChar ~
31839  _foo_how2_1_1,(_glong + 1) 
31840 \newline
31841 0046 85*04*0B\SpecialChar ~
31842 \SpecialChar ~
31843 \SpecialChar ~
31844 \SpecialChar ~
31845 \SpecialChar ~
31846 \SpecialChar ~
31847 \SpecialChar ~
31848 \SpecialChar ~
31849 \SpecialChar ~
31850 \SpecialChar ~
31851 \SpecialChar ~
31852 \SpecialChar ~
31853
31854  99\SpecialChar ~
31855 \SpecialChar ~
31856 \SpecialChar ~
31857 \SpecialChar ~
31858 \SpecialChar ~
31859 \SpecialChar ~
31860 \SpecialChar ~
31861 \SpecialChar ~
31862  mov\SpecialChar ~
31863 \SpecialChar ~
31864  (_foo_how2_1_1 + 1),(_glong + 2) 
31865
31866 \layout Standard
31867 Again, variations of these cases may 
31868 \emph on
31869 not
31870 \emph default
31871  be recognized.
31872  They are standard C expressions, so I heartily recommend these be the only
31873  way to get the higher order byte/word, (it is portable).
31874  Of course it will be recognized even if it is embedded in other expressions,
31875  e.g.:
31876
31877 \layout Verse
31878
31879 \family typewriter
31880 xyz = gint + ((gint >> 8) & 0xFF);
31881
31882 \layout Standard
31883 will still be recognized.
31884
31885 \layout Subsection
31886 Peephole Optimizer
31887 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31888
31889 \end_inset
31890
31891
31892 \begin_inset LatexCommand \index{Peephole optimizer}
31893
31894 \end_inset
31895
31896
31897
31898 \layout Standard
31899 The compiler uses a rule based, pattern matching and re-writing mechanism
31900  for peep-hole optimization.
31901  It is inspired by 
31902 \emph on
31903 copt
31904 \emph default
31905  a peep-hole optimizer by Christopher W.
31906  Fraser (cwfraser\SpecialChar ~
31907 @\SpecialChar ~
31908 microsoft.com).
31909  A default set of rules are compiled into the compiler, additional rules
31910  may be added with the 
31911 \emph on
31912 -
31913 \begin_inset ERT
31914 status Collapsed
31915
31916 \layout Standard
31917
31918
31919 \backslash
31920 /
31921
31922 \end_inset
31923
31924 -peep-file
31925 \begin_inset LatexCommand \index{-\/-peep-file}
31926
31927 \end_inset
31928
31929  <filename>
31930 \emph default
31931  option.
31932  The rule language is best illustrated with examples.
31933
31934 \layout Verse
31935
31936 \family typewriter
31937 replace { 
31938 \newline
31939 \SpecialChar ~
31940 \SpecialChar ~
31941 mov %1,a 
31942 \newline
31943 \SpecialChar ~
31944 \SpecialChar ~
31945 mov a,%1
31946 \newline
31947 } by {
31948 \newline
31949 \SpecialChar ~
31950 \SpecialChar ~
31951 mov %1,a
31952 \newline
31953 }
31954
31955 \layout Standard
31956 The above rule will change the following assembly
31957 \begin_inset LatexCommand \index{Assembler routines}
31958
31959 \end_inset
31960
31961  sequence:
31962
31963 \layout Verse
31964
31965 \family typewriter
31966 mov r1,a 
31967 \newline
31968 mov a,r1
31969
31970 \layout Standard
31971 to
31972
31973 \layout Verse
31974
31975 \family typewriter
31976 mov r1,a
31977
31978 \layout Standard
31979 Note: All occurrences of a 
31980 \emph on
31981 %n
31982 \emph default
31983  (pattern variable) must denote the same string.
31984  With the above rule, the assembly sequence:
31985
31986 \layout Verse
31987
31988 \family typewriter
31989 mov r1,a 
31990 \newline
31991 mov a,r2
31992
31993 \layout Standard
31994 will remain unmodified.
31995 \newline
31996
31997 \newline
31998 Other special case optimizations may be added by the
31999  user (via 
32000 \emph on
32001 -
32002 \begin_inset ERT
32003 status Collapsed
32004
32005 \layout Standard
32006
32007
32008 \backslash
32009 /
32010
32011 \end_inset
32012
32013 -peep-file option
32014 \emph default
32015 ).
32016  E.g.
32017  some variants of the 8051 MCU
32018 \begin_inset LatexCommand \index{MCS51 variants}
32019
32020 \end_inset
32021
32022  allow only 
32023 \family typewriter
32024 ajmp
32025 \family default
32026  and 
32027 \family typewriter
32028 acall
32029 \family default
32030 .
32031  The following two rules will change all 
32032 \family typewriter
32033 ljmp
32034 \family default
32035  and 
32036 \family typewriter
32037 lcall
32038 \family default
32039  to 
32040 \family typewriter
32041 ajmp
32042 \family default
32043  and 
32044 \family typewriter
32045 acall
32046
32047 \layout Verse
32048
32049 \family typewriter
32050 replace { lcall %1 } by { acall %1 } 
32051 \newline
32052 replace { ljmp %1 } by { ajmp %1 }
32053
32054 \layout Standard
32055 The 
32056 \emph on
32057 inline-assembler code
32058 \emph default
32059  is also passed through the peep hole optimizer, thus the peephole optimizer
32060  can also be used as an assembly level macro expander.
32061  The rules themselves are MCU dependent whereas the rule language infra-structur
32062 e is MCU independent.
32063  Peephole optimization rules for other MCU can be easily programmed using
32064  the rule language.
32065 \newline
32066
32067 \newline
32068 The syntax for a rule is as follows:
32069
32070 \layout Verse
32071
32072 \family typewriter
32073 rule := replace [ restart ] '{' <assembly sequence> '
32074 \backslash
32075 n' 
32076 \newline
32077 \SpecialChar ~
32078  \SpecialChar ~
32079  \SpecialChar ~
32080  \SpecialChar ~
32081  \SpecialChar ~
32082  \SpecialChar ~
32083  \SpecialChar ~
32084  \SpecialChar ~
32085  \SpecialChar ~
32086  \SpecialChar ~
32087  \SpecialChar ~
32088  \SpecialChar ~
32089  \SpecialChar ~
32090  \SpecialChar ~
32091  '}' by '{' '
32092 \backslash
32093 n' 
32094 \newline
32095 \SpecialChar ~
32096  \SpecialChar ~
32097  \SpecialChar ~
32098  \SpecialChar ~
32099  \SpecialChar ~
32100  \SpecialChar ~
32101  \SpecialChar ~
32102  \SpecialChar ~
32103  \SpecialChar ~
32104  \SpecialChar ~
32105  \SpecialChar ~
32106  \SpecialChar ~
32107  \SpecialChar ~
32108  \SpecialChar ~
32109  \SpecialChar ~
32110  \SpecialChar ~
32111  <assembly sequence> '
32112 \backslash
32113 n' 
32114 \newline
32115 \SpecialChar ~
32116  \SpecialChar ~
32117  \SpecialChar ~
32118  \SpecialChar ~
32119  \SpecialChar ~
32120  \SpecialChar ~
32121  \SpecialChar ~
32122  \SpecialChar ~
32123  \SpecialChar ~
32124  \SpecialChar ~
32125  \SpecialChar ~
32126  \SpecialChar ~
32127  \SpecialChar ~
32128  \SpecialChar ~
32129  '}' [if <functionName> ] '
32130 \backslash
32131 n' 
32132
32133 \layout Standard
32134 <assembly sequence> := assembly instruction (each instruction including
32135  labels must be on a separate line).
32136 \newline
32137
32138 \newline
32139 The optimizer will apply to the rules
32140  one by one from the top in the sequence of their appearance, it will terminate
32141  when all rules are exhausted.
32142  If the 'restart' option is specified, then the optimizer will start matching
32143  the rules again from the top, this option for a rule is expensive (performance)
32144 , it is intended to be used in situations where a transformation will trigger
32145  the same rule again.
32146  An example of this (not a good one, it has side effects) is the following
32147  rule:
32148
32149 \layout Verse
32150
32151 \family typewriter
32152 replace restart { 
32153 \newline
32154 \SpecialChar ~
32155 \SpecialChar ~
32156 pop %1 
32157 \newline
32158 \SpecialChar ~
32159 \SpecialChar ~
32160 push %1 } by { 
32161 \newline
32162 \SpecialChar ~
32163 \SpecialChar ~
32164 ; nop 
32165 \newline
32166 }
32167
32168 \layout Standard
32169 Note that the replace pattern cannot be a blank, but can be a comment line.
32170  Without the 'restart' option only the innermost 'pop' 'push' pair would
32171  be eliminated, i.e.:
32172
32173 \layout Verse
32174
32175 \family typewriter
32176 pop ar1 
32177 \newline
32178 pop ar2 
32179 \newline
32180 push ar2 
32181 \newline
32182 push ar1
32183
32184 \layout Standard
32185 would result in:
32186
32187 \layout Verse
32188
32189 \family typewriter
32190 pop ar1 
32191 \newline
32192 ; nop 
32193 \newline
32194 push ar1
32195
32196 \layout Standard
32197
32198 \emph on
32199 with
32200 \emph default
32201  the restart option the rule will be applied again to the resulting code
32202  and then all the pop-push pairs will be eliminated to yield:
32203
32204 \layout Verse
32205
32206 \family typewriter
32207 ; nop 
32208 \newline
32209 ; nop
32210
32211 \layout Standard
32212 A conditional function can be attached to a rule.
32213  Attaching rules are somewhat more involved, let me illustrate this with
32214  an example.
32215
32216 \layout Verse
32217
32218 \family typewriter
32219 replace { 
32220 \newline
32221 \SpecialChar ~
32222  \SpecialChar ~
32223  \SpecialChar ~
32224 ljmp %5 
32225 \newline
32226 %2:
32227 \newline
32228 } by { 
32229 \newline
32230 \SpecialChar ~
32231  \SpecialChar ~
32232  \SpecialChar ~
32233 sjmp %5 
32234 \newline
32235 %2:
32236 \newline
32237 } if labelInRange
32238
32239 \layout Standard
32240 The optimizer does a look-up of a function name table defined in function
32241  
32242 \emph on
32243 callFuncByName
32244 \emph default
32245  in the source file SDCCpeeph.c, with the name 
32246 \emph on
32247 labelInRange
32248 \emph default
32249 .
32250  If it finds a corresponding entry the function is called.
32251  Note there can be no parameters specified for these functions, in this
32252  case the use of 
32253 \emph on
32254 %5
32255 \emph default
32256  is crucial, since the function 
32257 \emph on
32258 labelInRange
32259 \emph default
32260  expects to find the label in that particular variable (the hash table containin
32261 g the variable bindings is passed as a parameter).
32262  If you want to code more such functions, take a close look at the function
32263  labelInRange and the calling mechanism in source file SDCCpeeph.c.
32264  Currently implemented are 
32265 \emph on
32266 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
32267  24bitMode, portIsDS390, 24bitModeAndPortDS390 
32268 \emph default
32269 and
32270 \emph on
32271  notVolatile
32272 \emph default
32273 .
32274
32275 \layout Standard
32276 I know this whole thing is a little kludgey, but maybe some day we will
32277  have some better means.
32278  If you are looking at this file, you will see the default rules that are
32279  compiled into the compiler, you can add your own rules in the default set
32280  there if you get tired of specifying the -
32281 \begin_inset ERT
32282 status Collapsed
32283
32284 \layout Standard
32285
32286
32287 \backslash
32288 /
32289
32290 \end_inset
32291
32292 -peep-file option.
32293
32294 \layout Section
32295 ANSI-Compliance
32296 \begin_inset LatexCommand \index{ANSI-compliance}
32297
32298 \end_inset
32299
32300
32301 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
32302
32303 \end_inset
32304
32305
32306
32307 \layout Standard
32308 The latest publically available version of the standard 
32309 \emph on
32310 ISO/IEC 9899 - Programming languages - C
32311 \emph default
32312  should be available at: 
32313 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32314
32315 \end_inset
32316
32317 .
32318 \newline
32319
32320
32321 \layout Standard
32322 Deviations from the compliance:
32323
32324 \layout Itemize
32325 functions are not reentrant
32326 \begin_inset LatexCommand \index{reentrant}
32327
32328 \end_inset
32329
32330  unless explicitly declared as such or the 
32331 \series bold
32332 -
32333 \begin_inset ERT
32334 status Collapsed
32335
32336 \layout Standard
32337
32338
32339 \backslash
32340 /
32341
32342 \end_inset
32343
32344 -stack-auto
32345 \begin_inset LatexCommand \index{-\/-stack-auto}
32346
32347 \end_inset
32348
32349
32350 \series default
32351  command line option is specified.
32352
32353 \layout Itemize
32354 structures
32355 \begin_inset LatexCommand \index{struct}
32356
32357 \end_inset
32358
32359  and unions
32360 \begin_inset LatexCommand \index{union}
32361
32362 \end_inset
32363
32364  cannot be assigned values directly, cannot be passed as function parameters
32365  or assigned to each other and cannot be a return value
32366 \begin_inset LatexCommand \index{return value}
32367
32368 \end_inset
32369
32370  from a function, e.g.:
32371
32372 \begin_deeper
32373 \layout Verse
32374
32375 \family typewriter
32376 struct s { ...
32377  }; 
32378 \newline
32379 struct s s1, s2; 
32380 \newline
32381 foo() 
32382 \newline
32383
32384 \newline
32385 \SpecialChar ~
32386 \SpecialChar ~
32387 \SpecialChar ~
32388 \SpecialChar ~
32389 ...
32390  
32391 \newline
32392 \SpecialChar ~
32393 \SpecialChar ~
32394 \SpecialChar ~
32395 \SpecialChar ~
32396 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
32397 \newline
32398 \SpecialChar ~
32399 \SpecialChar ~
32400 \SpecialChar ~
32401 \SpecialChar ~
32402 ...
32403  
32404 \newline
32405 }
32406 \newline
32407
32408 \series bold
32409 struct
32410 \series default
32411  s foo1 (
32412 \series bold
32413 struct
32414 \series default
32415  s parms) /* invalid in SDCC although allowed in ANSI */
32416 \newline
32417
32418 \newline
32419 \SpecialChar ~
32420 \SpecialChar ~
32421 \SpecialChar ~
32422 \SpecialChar ~
32423 struct s rets;
32424  
32425 \newline
32426 \SpecialChar ~
32427 \SpecialChar ~
32428 \SpecialChar ~
32429 \SpecialChar ~
32430 ...
32431  
32432 \newline
32433 \SpecialChar ~
32434 \SpecialChar ~
32435 \SpecialChar ~
32436 \SpecialChar ~
32437 return rets; /* is invalid in SDCC although allowed in ANSI */ 
32438 \newline
32439 }
32440
32441 \end_deeper
32442 \layout Itemize
32443 initialization of structure arrays must be fully braced.
32444
32445 \begin_deeper
32446 \layout Verse
32447
32448 \family typewriter
32449 struct s { char x } a[] = {1, 2};\SpecialChar ~
32450 \SpecialChar ~
32451 \SpecialChar ~
32452 \SpecialChar ~
32453 \SpecialChar ~
32454 /* invalid in SDCC */
32455 \newline
32456 struct s { char x
32457  } a[] = {{1}, {2}}; /* OK */
32458
32459 \end_deeper
32460 \layout Itemize
32461 'long long
32462 \begin_inset LatexCommand \index{long long (not supported)}
32463
32464 \end_inset
32465
32466 ' (64 bit integers
32467 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
32468
32469 \end_inset
32470
32471 ) not supported.
32472
32473 \layout Itemize
32474 'double
32475 \begin_inset LatexCommand \index{double (not supported)}
32476
32477 \end_inset
32478
32479 ' precision floating point 
32480 \begin_inset LatexCommand \index{Floating point support}
32481
32482 \end_inset
32483
32484 not supported.
32485
32486 \layout Itemize
32487 Old K&R style
32488 \begin_inset LatexCommand \index{K\&R style}
32489
32490 \end_inset
32491
32492  function declarations are NOT allowed.
32493
32494 \begin_deeper
32495 \layout Verse
32496
32497 \family typewriter
32498 foo(i,j) /* this old style of function declarations */ 
32499 \newline
32500 int i,j; /* are valid
32501  in ANSI but not valid in SDCC */ 
32502 \newline
32503
32504 \newline
32505 \SpecialChar ~
32506 \SpecialChar ~
32507 \SpecialChar ~
32508 \SpecialChar ~
32509 ...
32510  
32511 \newline
32512 }
32513
32514 \end_deeper
32515 \layout Itemize
32516 Most enhancements in C99 are not supported, f.e.:
32517
32518 \begin_deeper
32519 \layout Verse
32520
32521 \family typewriter
32522 \series bold
32523 inline
32524 \begin_inset LatexCommand \index{inline (not supported)}
32525
32526 \end_inset
32527
32528
32529 \series default
32530  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
32531  in C99.
32532  An empty define 
32533 \emph on
32534 #define inline
32535 \emph default
32536  can be used as a work around */
32537 \newline
32538
32539 \newline
32540 for (
32541 \series bold
32542 int
32543 \series default
32544  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
32545
32546 \end_deeper
32547 \layout Itemize
32548 Certain words that are valid identifiers in the standard may be reserved
32549  words in SDCC unless the 
32550 \series bold
32551 -
32552 \begin_inset ERT
32553 status Collapsed
32554
32555 \layout Standard
32556
32557
32558 \backslash
32559 /
32560
32561 \end_inset
32562
32563 -std-c89
32564 \begin_inset LatexCommand \index{-\/-std-c89}
32565
32566 \end_inset
32567
32568  or -
32569 \begin_inset ERT
32570 status Collapsed
32571
32572 \layout Standard
32573
32574
32575 \backslash
32576 /
32577
32578 \end_inset
32579
32580 -std-c99
32581 \begin_inset LatexCommand \index{-\/-std-c99}
32582
32583 \end_inset
32584
32585
32586 \series default
32587  command line options are used.
32588  These may include (depending on the selected processor): 'at', 'banked',
32589  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
32590 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
32591  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
32592  '_naked'.
32593  Compliant equivalents of these keywords are always available in a form
32594  that begin with two underscores
32595 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
32596
32597 \end_inset
32598
32599 , f.e.
32600  '__data' instead of 'data'.
32601
32602 \layout Section
32603 Cyclomatic Complexity
32604 \begin_inset LatexCommand \index{Cyclomatic complexity}
32605
32606 \end_inset
32607
32608
32609
32610 \layout Standard
32611 Cyclomatic complexity of a function is defined as the number of independent
32612  paths the program can take during execution of the function.
32613  This is an important number since it defines the number test cases you
32614  have to generate to validate the function.
32615  The accepted industry standard for complexity number is 10, if the cyclomatic
32616  complexity reported by SDCC exceeds 10 you should think about simplification
32617  of the function logic.
32618  Note that the complexity level is not related to the number of lines of
32619  code in a function.
32620  Large functions can have low complexity, and small functions can have large
32621  complexity levels.
32622  
32623 \newline
32624
32625 \newline
32626 SDCC uses the following formula to compute the complexity:
32627 \newline
32628
32629
32630 \layout Standard
32631 complexity = (number of edges in control flow graph) - (number of nodes
32632  in control flow graph) + 2;
32633 \newline
32634
32635 \newline
32636 Having said that the industry standard is 10,
32637  you should be aware that in some cases it be may unavoidable to have a
32638  complexity level of less than 10.
32639  For example if you have switch statement with more than 10 case labels,
32640  each case label adds one to the complexity level.
32641  The complexity level is by no means an absolute measure of the algorithmic
32642  complexity of the function, it does however provide a good starting point
32643  for which functions you might look at for further optimization.
32644
32645 \layout Section
32646 Retargetting for other Processors
32647
32648 \layout Standard
32649 The issues for retargetting the compiler are far too numerous to be covered
32650  by this document.
32651  What follows is a brief description of each of the seven phases of the
32652  compiler and its MCU dependency.
32653
32654 \layout Itemize
32655 Parsing the source and building the annotated parse tree.
32656  This phase is largely MCU independent (except for the language extensions).
32657  Syntax & semantic checks are also done in this phase, along with some initial
32658  optimizations like back patching labels and the pattern matching optimizations
32659  like bit-rotation etc.
32660
32661 \layout Itemize
32662 The second phase involves generating an intermediate code which can be easy
32663  manipulated during the later phases.
32664  This phase is entirely MCU independent.
32665  The intermediate code generation assumes the target machine has unlimited
32666  number of registers, and designates them with the name iTemp.
32667  The compiler can be made to dump a human readable form of the code generated
32668  by using the -
32669 \begin_inset ERT
32670 status Collapsed
32671
32672 \layout Standard
32673
32674
32675 \backslash
32676 /
32677
32678 \end_inset
32679
32680 -dumpraw option.
32681
32682 \layout Itemize
32683 This phase does the bulk of the standard optimizations and is also MCU independe
32684 nt.
32685  This phase can be broken down into several sub-phases:
32686 \newline
32687
32688 \newline
32689 Break down intermediate
32690  code (iCode) into basic blocks.
32691 \newline
32692 Do control flow & data flow analysis on the
32693  basic blocks.
32694 \newline
32695 Do local common subexpression elimination, then global subexpressio
32696 n elimination
32697 \newline
32698 Dead code elimination
32699 \newline
32700 Loop optimizations
32701 \newline
32702 If loop optimizations
32703  caused any changes then do 'global subexpression elimination' and 'dead
32704  code elimination' again.
32705
32706 \layout Itemize
32707 This phase determines the live-ranges; by live range I mean those iTemp
32708  variables defined by the compiler that still survive after all the optimization
32709 s.
32710  Live range analysis
32711 \begin_inset LatexCommand \index{Live range analysis}
32712
32713 \end_inset
32714
32715  is essential for register allocation, since these computation determines
32716  which of these iTemps will be assigned to registers, and for how long.
32717
32718 \layout Itemize
32719 Phase five is register allocation.
32720  There are two parts to this process.
32721 \newline
32722
32723 \newline
32724 The first part I call 'register packing'
32725  (for lack of a better term).
32726  In this case several MCU specific expression folding is done to reduce
32727  register pressure.
32728 \newline
32729
32730 \newline
32731 The second part is more MCU independent and deals with
32732  allocating registers to the remaining live ranges.
32733  A lot of MCU specific code does creep into this phase because of the limited
32734  number of index registers available in the 8051.
32735
32736 \layout Itemize
32737 The Code generation phase is (unhappily), entirely MCU dependent and very
32738  little (if any at all) of this code can be reused for other MCU.
32739  However the scheme for allocating a homogenized assembler operand for each
32740  iCode operand may be reused.
32741
32742 \layout Itemize
32743 As mentioned in the optimization section the peep-hole optimizer is rule
32744  based system, which can reprogrammed for other MCUs.
32745
32746 \layout Standard
32747 More information is available in a wiki
32748 \begin_inset LatexCommand \index{wiki}
32749
32750 \end_inset
32751
32752  (preliminary link 
32753 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
32754
32755 \end_inset
32756
32757 ) and in the thread 
32758 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
32759
32760 \end_inset
32761
32762  .
32763
32764 \layout Chapter
32765 Compiler internals
32766 \begin_inset LatexCommand \index{Compiler internals}
32767
32768 \end_inset
32769
32770
32771
32772 \layout Section
32773 The anatomy of the compiler
32774 \begin_inset LatexCommand \label{sub:The-anatomy-of}
32775
32776 \end_inset
32777
32778
32779
32780 \layout Standard
32781
32782 \shape italic
32783 This is an excerpt from an article published in Circuit Cellar Magazine
32784  in 
32785 \series bold
32786 August 2000
32787 \series default
32788 .
32789  It's a little outdated (the compiler is much more efficient now and user/develo
32790 per friendly), but pretty well exposes the guts of it all.
32791 \shape default
32792
32793 \newline
32794
32795 \newline
32796 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
32797  It is fairly easy to retarget for other 8-bit MCU.
32798  Here we take a look at some of the internals of the compiler.
32799  
32800
32801 \layout Paragraph*
32802 Parsing
32803 \begin_inset LatexCommand \index{Parsing}
32804
32805 \end_inset
32806
32807  
32808
32809 \layout Standard
32810 Parsing the input source file and creating an AST (Annotated Syntax Tree
32811 \begin_inset LatexCommand \index{Annotated syntax tree}
32812
32813 \end_inset
32814
32815 ).
32816  This phase also involves propagating types (annotating each node of the
32817  parse tree with type information) and semantic analysis.
32818  There are some MCU specific parsing rules.
32819  For example the storage classes, the extended storage classes are MCU specific
32820  while there may be a xdata storage class for 8051 there is no such storage
32821  class for z80 or Atmel AVR.
32822  SDCC allows MCU specific storage class extensions, i.e.
32823  xdata will be treated as a storage class specifier when parsing 8051 C
32824  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
32825  C code.
32826
32827 \layout Paragraph*
32828 Generating iCode
32829 \begin_inset LatexCommand \index{iCode}
32830
32831 \end_inset
32832
32833
32834
32835 \layout Standard
32836 Intermediate code generation.
32837  In this phase the AST is broken down into three-operand form (iCode).
32838  These three operand forms are represented as doubly linked lists.
32839  ICode is the term given to the intermediate form generated by the compiler.
32840  ICode example section shows some examples of iCode generated for some simple
32841  C source functions.
32842
32843 \layout Paragraph*
32844 Optimizations
32845 \begin_inset LatexCommand \index{Optimizations}
32846
32847 \end_inset
32848
32849 .
32850
32851 \layout Standard
32852 Bulk of the target independent optimizations is performed in this phase.
32853  The optimizations include constant propagation, common sub-expression eliminati
32854 on, loop invariant code movement, strength reduction of loop induction variables
32855  and dead-code elimination.
32856
32857 \layout Paragraph*
32858 Live range analysis
32859 \begin_inset LatexCommand \index{Live range analysis}
32860
32861 \end_inset
32862
32863
32864
32865 \layout Standard
32866 During intermediate code generation phase, the compiler assumes the target
32867  machine has infinite number of registers and generates a lot of temporary
32868  variables.
32869  The live range computation determines the lifetime of each of these compiler-ge
32870 nerated temporaries.
32871  A picture speaks a thousand words.
32872  ICode example sections show the live range annotations for each of the
32873  operand.
32874  It is important to note here, each iCode is assigned a number in the order
32875  of its execution in the function.
32876  The live ranges are computed in terms of these numbers.
32877  The from number is the number of the iCode which first defines the operand
32878  and the to number signifies the iCode which uses this operand last.
32879
32880 \layout Paragraph*
32881 Register Allocation
32882 \begin_inset LatexCommand \index{Register allocation}
32883
32884 \end_inset
32885
32886
32887
32888 \layout Standard
32889 The register allocation determines the type and number of registers needed
32890  by each operand.
32891  In most MCUs only a few registers can be used for indirect addressing.
32892  In case of 8051 for example the registers R0 & R1 can be used to indirectly
32893  address the internal ram and DPTR to indirectly address the external ram.
32894  The compiler will try to allocate the appropriate register to pointer variables
32895  if it can.
32896  ICode example section shows the operands annotated with the registers assigned
32897  to them.
32898  The compiler will try to keep operands in registers as much as possible;
32899  there are several schemes the compiler uses to do achieve this.
32900  When the compiler runs out of registers the compiler will check to see
32901  if there are any live operands which is not used or defined in the current
32902  basic block being processed, if there are any found then it will push that
32903  operand and use the registers in this block, the operand will then be popped
32904  at the end of the basic block.
32905  
32906
32907 \layout Standard
32908 There are other MCU specific considerations in this phase.
32909  Some MCUs have an accumulator; very short-lived operands could be assigned
32910  to the accumulator instead of a general-purpose register.
32911
32912 \layout Paragraph*
32913 Code generation
32914
32915 \layout Standard
32916 Figure II gives a table of iCode
32917 \begin_inset LatexCommand \index{iCode}
32918
32919 \end_inset
32920
32921  operations supported by the compiler.
32922  The code generation involves translating these operations into corresponding
32923  assembly code for the processor.
32924  This sounds overly simple but that is the essence of code generation.
32925  Some of the iCode operations are generated on a MCU specific manner for
32926  example, the z80 port does not use registers to pass parameters so the
32927  SEND and RECV iCode operations will not be generated, and it also does
32928  not support JUMPTABLES.
32929  
32930 \newline
32931
32932
32933 \layout Standard
32934
32935 \size footnotesize
32936 Figure II 
32937 \begin_inset Tabular
32938 <lyxtabular version="3" rows="39" columns="4">
32939 <features islongtable="true" headBottomDL="true">
32940 <column alignment="block" valignment="top" leftline="true" width="13col%">
32941 <column alignment="left" valignment="top" leftline="true" width="13col%">
32942 <column alignment="block" valignment="top" leftline="true" width="22col%">
32943 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32944 <row topline="true" bottomline="true" endhead="true">
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32946 \begin_inset Text
32947
32948 \layout Standard
32949
32950 \series bold
32951 iCode
32952 \series default
32953
32954 \begin_inset LatexCommand \index{iCode}
32955
32956 \end_inset
32957
32958
32959
32960 \end_inset
32961 </cell>
32962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32963 \begin_inset Text
32964
32965 \layout Standard
32966
32967 \series bold
32968 Operands
32969
32970 \end_inset
32971 </cell>
32972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32973 \begin_inset Text
32974
32975 \layout Standard
32976
32977 \series bold
32978 Description
32979
32980 \end_inset
32981 </cell>
32982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32983 \begin_inset Text
32984
32985 \layout Standard
32986
32987 \series bold
32988 C Equivalent
32989
32990 \end_inset
32991 </cell>
32992 </row>
32993 <row topline="true">
32994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32995 \begin_inset Text
32996
32997 \layout Standard
32998
32999 \size footnotesize
33000 '!'
33001
33002 \end_inset
33003 </cell>
33004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33005 \begin_inset Text
33006
33007 \layout Standard
33008
33009 \size footnotesize
33010 IC_LEFT() IC_RESULT()
33011
33012 \end_inset
33013 </cell>
33014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33015 \begin_inset Text
33016
33017 \layout Standard
33018
33019 \size footnotesize
33020 NOT operation 
33021
33022 \end_inset
33023 </cell>
33024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33025 \begin_inset Text
33026
33027 \layout Standard
33028
33029 \size footnotesize
33030 IC_RESULT = ! IC_LEFT;
33031
33032 \end_inset
33033 </cell>
33034 </row>
33035 <row topline="true">
33036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33037 \begin_inset Text
33038
33039 \layout Standard
33040
33041 \size footnotesize
33042 '~'
33043
33044 \end_inset
33045 </cell>
33046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33047 \begin_inset Text
33048
33049 \layout Standard
33050
33051 \size footnotesize
33052 IC_LEFT() IC_RESULT()
33053
33054 \end_inset
33055 </cell>
33056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33057 \begin_inset Text
33058
33059 \layout Standard
33060
33061 \size footnotesize
33062 Bitwise complement of 
33063
33064 \end_inset
33065 </cell>
33066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33067 \begin_inset Text
33068
33069 \layout Standard
33070
33071 \size footnotesize
33072 IC_RESULT = ~IC_LEFT;
33073
33074 \end_inset
33075 </cell>
33076 </row>
33077 <row topline="true">
33078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33079 \begin_inset Text
33080
33081 \layout Standard
33082
33083 \size footnotesize
33084 RRC
33085
33086 \end_inset
33087 </cell>
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33089 \begin_inset Text
33090
33091 \layout Standard
33092
33093 \size footnotesize
33094 IC_LEFT() IC_RESULT()
33095
33096 \end_inset
33097 </cell>
33098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33099 \begin_inset Text
33100
33101 \layout Standard
33102
33103 \size footnotesize
33104 Rotate right with carry
33105
33106 \end_inset
33107 </cell>
33108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33109 \begin_inset Text
33110
33111 \layout Standard
33112
33113 \size footnotesize
33114 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
33115
33116 \end_inset
33117 </cell>
33118 </row>
33119 <row topline="true">
33120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33121 \begin_inset Text
33122
33123 \layout Standard
33124
33125 \size footnotesize
33126 RLC
33127
33128 \end_inset
33129 </cell>
33130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33131 \begin_inset Text
33132
33133 \layout Standard
33134
33135 \size footnotesize
33136 IC_LEFT() IC_RESULT()
33137
33138 \end_inset
33139 </cell>
33140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33141 \begin_inset Text
33142
33143 \layout Standard
33144
33145 \size footnotesize
33146 Rotate left with carry
33147
33148 \end_inset
33149 </cell>
33150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33151 \begin_inset Text
33152
33153 \layout Standard
33154
33155 \size footnotesize
33156 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
33157
33158 \end_inset
33159 </cell>
33160 </row>
33161 <row topline="true">
33162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33163 \begin_inset Text
33164
33165 \layout Standard
33166
33167 \size footnotesize
33168 GETHBIT
33169
33170 \end_inset
33171 </cell>
33172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33173 \begin_inset Text
33174
33175 \layout Standard
33176
33177 \size footnotesize
33178 IC_LEFT() IC_RESULT()
33179
33180 \end_inset
33181 </cell>
33182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33183 \begin_inset Text
33184
33185 \layout Standard
33186
33187 \size footnotesize
33188 Get the highest order bit of IC_LEFT
33189
33190 \end_inset
33191 </cell>
33192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33193 \begin_inset Text
33194
33195 \layout Standard
33196
33197 \size footnotesize
33198 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
33199
33200 \end_inset
33201 </cell>
33202 </row>
33203 <row topline="true">
33204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33205 \begin_inset Text
33206
33207 \layout Standard
33208
33209 \size footnotesize
33210 UNARYMINUS
33211
33212 \end_inset
33213 </cell>
33214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33215 \begin_inset Text
33216
33217 \layout Standard
33218
33219 \size footnotesize
33220 IC_LEFT() IC_RESULT()
33221
33222 \end_inset
33223 </cell>
33224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33225 \begin_inset Text
33226
33227 \layout Standard
33228
33229 \size footnotesize
33230 Unary minus
33231
33232 \end_inset
33233 </cell>
33234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33235 \begin_inset Text
33236
33237 \layout Standard
33238
33239 \size footnotesize
33240 IC_RESULT = - IC_LEFT;
33241
33242 \end_inset
33243 </cell>
33244 </row>
33245 <row topline="true">
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33247 \begin_inset Text
33248
33249 \layout Standard
33250
33251 \size footnotesize
33252 IPUSH
33253
33254 \end_inset
33255 </cell>
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33257 \begin_inset Text
33258
33259 \layout Standard
33260
33261 \size footnotesize
33262 IC_LEFT()
33263
33264 \end_inset
33265 </cell>
33266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33267 \begin_inset Text
33268
33269 \layout Standard
33270
33271 \size footnotesize
33272 Push the operand into stack
33273
33274 \end_inset
33275 </cell>
33276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33277 \begin_inset Text
33278
33279 \layout Standard
33280
33281 \size footnotesize
33282 NONE
33283
33284 \end_inset
33285 </cell>
33286 </row>
33287 <row topline="true">
33288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33289 \begin_inset Text
33290
33291 \layout Standard
33292
33293 \size footnotesize
33294 IPOP
33295
33296 \end_inset
33297 </cell>
33298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33299 \begin_inset Text
33300
33301 \layout Standard
33302
33303 \size footnotesize
33304 IC_LEFT()
33305
33306 \end_inset
33307 </cell>
33308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33309 \begin_inset Text
33310
33311 \layout Standard
33312
33313 \size footnotesize
33314 Pop the operand from the stack 
33315
33316 \end_inset
33317 </cell>
33318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33319 \begin_inset Text
33320
33321 \layout Standard
33322
33323 \size footnotesize
33324 NONE
33325
33326 \end_inset
33327 </cell>
33328 </row>
33329 <row topline="true">
33330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33331 \begin_inset Text
33332
33333 \layout Standard
33334
33335 \size footnotesize
33336 CALL
33337
33338 \end_inset
33339 </cell>
33340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33341 \begin_inset Text
33342
33343 \layout Standard
33344
33345 \size footnotesize
33346 IC_LEFT() IC_RESULT()
33347
33348 \end_inset
33349 </cell>
33350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33351 \begin_inset Text
33352
33353 \layout Standard
33354
33355 \size footnotesize
33356 Call the function represented by IC_LEFT 
33357
33358 \end_inset
33359 </cell>
33360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33361 \begin_inset Text
33362
33363 \layout Standard
33364
33365 \size footnotesize
33366 IC_RESULT = IC_LEFT();
33367
33368 \end_inset
33369 </cell>
33370 </row>
33371 <row topline="true">
33372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33373 \begin_inset Text
33374
33375 \layout Standard
33376
33377 \size footnotesize
33378 PCALL
33379
33380 \end_inset
33381 </cell>
33382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33383 \begin_inset Text
33384
33385 \layout Standard
33386
33387 \size footnotesize
33388 IC_LEFT() IC_RESULT()
33389
33390 \end_inset
33391 </cell>
33392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33393 \begin_inset Text
33394
33395 \layout Standard
33396
33397 \size footnotesize
33398 Call via function pointer
33399
33400 \end_inset
33401 </cell>
33402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33403 \begin_inset Text
33404
33405 \layout Standard
33406
33407 \size footnotesize
33408 IC_RESULT = (*IC_LEFT)();
33409
33410 \end_inset
33411 </cell>
33412 </row>
33413 <row topline="true">
33414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33415 \begin_inset Text
33416
33417 \layout Standard
33418
33419 \size footnotesize
33420 RETURN
33421
33422 \end_inset
33423 </cell>
33424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33425 \begin_inset Text
33426
33427 \layout Standard
33428
33429 \size footnotesize
33430 IC_LEFT()
33431
33432 \end_inset
33433 </cell>
33434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33435 \begin_inset Text
33436
33437 \layout Standard
33438
33439 \size footnotesize
33440 Return the value in operand IC_LEFT 
33441
33442 \end_inset
33443 </cell>
33444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33445 \begin_inset Text
33446
33447 \layout Standard
33448
33449 \size footnotesize
33450 return IC_LEFT;
33451
33452 \end_inset
33453 </cell>
33454 </row>
33455 <row topline="true">
33456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33457 \begin_inset Text
33458
33459 \layout Standard
33460
33461 \size footnotesize
33462 LABEL
33463
33464 \end_inset
33465 </cell>
33466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33467 \begin_inset Text
33468
33469 \layout Standard
33470
33471 \size footnotesize
33472 IC_LABEL() 
33473
33474 \end_inset
33475 </cell>
33476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33477 \begin_inset Text
33478
33479 \layout Standard
33480
33481 \size footnotesize
33482 Label
33483
33484 \end_inset
33485 </cell>
33486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33487 \begin_inset Text
33488
33489 \layout Standard
33490
33491 \size footnotesize
33492 IC_LABEL:
33493
33494 \end_inset
33495 </cell>
33496 </row>
33497 <row topline="true">
33498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33499 \begin_inset Text
33500
33501 \layout Standard
33502
33503 \size footnotesize
33504 GOTO
33505
33506 \end_inset
33507 </cell>
33508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33509 \begin_inset Text
33510
33511 \layout Standard
33512
33513 \size footnotesize
33514 IC_LABEL() 
33515
33516 \end_inset
33517 </cell>
33518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33519 \begin_inset Text
33520
33521 \layout Standard
33522
33523 \size footnotesize
33524 Goto label
33525
33526 \end_inset
33527 </cell>
33528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33529 \begin_inset Text
33530
33531 \layout Standard
33532
33533 \size footnotesize
33534 goto IC_LABEL();
33535
33536 \end_inset
33537 </cell>
33538 </row>
33539 <row topline="true">
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33541 \begin_inset Text
33542
33543 \layout Standard
33544
33545 \size footnotesize
33546 '+'
33547
33548 \end_inset
33549 </cell>
33550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33551 \begin_inset Text
33552
33553 \layout Standard
33554
33555 \size footnotesize
33556 IC_LEFT() IC_RIGHT() IC_RESULT()
33557
33558 \end_inset
33559 </cell>
33560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33561 \begin_inset Text
33562
33563 \layout Standard
33564
33565 \size footnotesize
33566 Addition
33567
33568 \end_inset
33569 </cell>
33570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33571 \begin_inset Text
33572
33573 \layout Standard
33574
33575 \size footnotesize
33576 IC_RESULT = IC_LEFT + IC_RIGHT
33577
33578 \end_inset
33579 </cell>
33580 </row>
33581 <row topline="true">
33582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33583 \begin_inset Text
33584
33585 \layout Standard
33586
33587 \size footnotesize
33588 '-'
33589
33590 \end_inset
33591 </cell>
33592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33593 \begin_inset Text
33594
33595 \layout Standard
33596
33597 \size footnotesize
33598 IC_LEFT() IC_RIGHT() IC_RESULT()
33599
33600 \end_inset
33601 </cell>
33602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33603 \begin_inset Text
33604
33605 \layout Standard
33606
33607 \size footnotesize
33608 Subtraction
33609
33610 \end_inset
33611 </cell>
33612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33613 \begin_inset Text
33614
33615 \layout Standard
33616
33617 \size footnotesize
33618 IC_RESULT = IC_LEFT - IC_RIGHT 
33619
33620 \end_inset
33621 </cell>
33622 </row>
33623 <row topline="true">
33624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33625 \begin_inset Text
33626
33627 \layout Standard
33628
33629 \size footnotesize
33630 '*'
33631
33632 \end_inset
33633 </cell>
33634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33635 \begin_inset Text
33636
33637 \layout Standard
33638
33639 \size footnotesize
33640 IC_LEFT() IC_RIGHT() IC_RESULT()
33641
33642 \end_inset
33643 </cell>
33644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33645 \begin_inset Text
33646
33647 \layout Standard
33648
33649 \size footnotesize
33650 Multiplication 
33651
33652 \end_inset
33653 </cell>
33654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33655 \begin_inset Text
33656
33657 \layout Standard
33658
33659 \size footnotesize
33660 IC_RESULT = IC_LEFT * IC_RIGHT;
33661
33662 \end_inset
33663 </cell>
33664 </row>
33665 <row topline="true">
33666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33667 \begin_inset Text
33668
33669 \layout Standard
33670
33671 \size footnotesize
33672 '/'
33673
33674 \end_inset
33675 </cell>
33676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33677 \begin_inset Text
33678
33679 \layout Standard
33680
33681 \size footnotesize
33682 IC_LEFT() IC_RIGHT() IC_RESULT()
33683
33684 \end_inset
33685 </cell>
33686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33687 \begin_inset Text
33688
33689 \layout Standard
33690
33691 \size footnotesize
33692 Division
33693
33694 \end_inset
33695 </cell>
33696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33697 \begin_inset Text
33698
33699 \layout Standard
33700
33701 \size footnotesize
33702 IC_RESULT = IC_LEFT / IC_RIGHT;
33703
33704 \end_inset
33705 </cell>
33706 </row>
33707 <row topline="true">
33708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33709 \begin_inset Text
33710
33711 \layout Standard
33712
33713 \size footnotesize
33714 '%'
33715
33716 \end_inset
33717 </cell>
33718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33719 \begin_inset Text
33720
33721 \layout Standard
33722
33723 \size footnotesize
33724 IC_LEFT() IC_RIGHT() IC_RESULT()
33725
33726 \end_inset
33727 </cell>
33728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33729 \begin_inset Text
33730
33731 \layout Standard
33732
33733 \size footnotesize
33734 Modulus
33735
33736 \end_inset
33737 </cell>
33738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33739 \begin_inset Text
33740
33741 \layout Standard
33742
33743 \size footnotesize
33744 IC_RESULT = IC_LEFT % IC_RIGHT;
33745
33746 \end_inset
33747 </cell>
33748 </row>
33749 <row topline="true">
33750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33751 \begin_inset Text
33752
33753 \layout Standard
33754
33755 \size footnotesize
33756 '<'
33757
33758 \end_inset
33759 </cell>
33760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33761 \begin_inset Text
33762
33763 \layout Standard
33764
33765 \size footnotesize
33766 IC_LEFT() IC_RIGHT() IC_RESULT()
33767
33768 \end_inset
33769 </cell>
33770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33771 \begin_inset Text
33772
33773 \layout Standard
33774
33775 \size footnotesize
33776 Less than
33777
33778 \end_inset
33779 </cell>
33780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33781 \begin_inset Text
33782
33783 \layout Standard
33784
33785 \size footnotesize
33786 IC_RESULT = IC_LEFT < IC_RIGHT;
33787
33788 \end_inset
33789 </cell>
33790 </row>
33791 <row topline="true">
33792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33793 \begin_inset Text
33794
33795 \layout Standard
33796
33797 \size footnotesize
33798 '>'
33799
33800 \end_inset
33801 </cell>
33802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33803 \begin_inset Text
33804
33805 \layout Standard
33806
33807 \size footnotesize
33808 IC_LEFT() IC_RIGHT() IC_RESULT()
33809
33810 \end_inset
33811 </cell>
33812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33813 \begin_inset Text
33814
33815 \layout Standard
33816
33817 \size footnotesize
33818 Greater than 
33819
33820 \end_inset
33821 </cell>
33822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33823 \begin_inset Text
33824
33825 \layout Standard
33826
33827 \size footnotesize
33828 IC_RESULT = IC_LEFT > IC_RIGHT;
33829
33830 \end_inset
33831 </cell>
33832 </row>
33833 <row topline="true">
33834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33835 \begin_inset Text
33836
33837 \layout Standard
33838
33839 \size footnotesize
33840 EQ_OP
33841
33842 \end_inset
33843 </cell>
33844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33845 \begin_inset Text
33846
33847 \layout Standard
33848
33849 \size footnotesize
33850 IC_LEFT() IC_RIGHT() IC_RESULT()
33851
33852 \end_inset
33853 </cell>
33854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33855 \begin_inset Text
33856
33857 \layout Standard
33858
33859 \size footnotesize
33860 Equal to 
33861
33862 \end_inset
33863 </cell>
33864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33865 \begin_inset Text
33866
33867 \layout Standard
33868
33869 \size footnotesize
33870 IC_RESULT = IC_LEFT == IC_RIGHT;
33871
33872 \end_inset
33873 </cell>
33874 </row>
33875 <row topline="true">
33876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33877 \begin_inset Text
33878
33879 \layout Standard
33880
33881 \size footnotesize
33882 AND_OP
33883
33884 \end_inset
33885 </cell>
33886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33887 \begin_inset Text
33888
33889 \layout Standard
33890
33891 \size footnotesize
33892 IC_LEFT() IC_RIGHT() IC_RESULT() 
33893
33894 \end_inset
33895 </cell>
33896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33897 \begin_inset Text
33898
33899 \layout Standard
33900
33901 \size footnotesize
33902 Logical and operation
33903
33904 \end_inset
33905 </cell>
33906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33907 \begin_inset Text
33908
33909 \layout Standard
33910
33911 \size footnotesize
33912 IC_RESULT = IC_LEFT && IC_RIGHT; 
33913
33914 \end_inset
33915 </cell>
33916 </row>
33917 <row topline="true">
33918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33919 \begin_inset Text
33920
33921 \layout Standard
33922
33923 \size footnotesize
33924 OR_OP
33925
33926 \end_inset
33927 </cell>
33928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33929 \begin_inset Text
33930
33931 \layout Standard
33932
33933 \size footnotesize
33934 IC_LEFT() IC_RIGHT() IC_RESULT() 
33935
33936 \end_inset
33937 </cell>
33938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33939 \begin_inset Text
33940
33941 \layout Standard
33942
33943 \size footnotesize
33944 Logical or operation 
33945
33946 \end_inset
33947 </cell>
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33949 \begin_inset Text
33950
33951 \layout Standard
33952
33953 \size footnotesize
33954 IC_RESULT = IC_LEFT || IC_RIGHT; 
33955
33956 \end_inset
33957 </cell>
33958 </row>
33959 <row topline="true">
33960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33961 \begin_inset Text
33962
33963 \layout Standard
33964
33965 \size footnotesize
33966 '^'
33967
33968 \end_inset
33969 </cell>
33970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33971 \begin_inset Text
33972
33973 \layout Standard
33974
33975 \size footnotesize
33976 IC_LEFT() IC_RIGHT() IC_RESULT() 
33977
33978 \end_inset
33979 </cell>
33980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33981 \begin_inset Text
33982
33983 \layout Standard
33984
33985 \size footnotesize
33986 Exclusive OR
33987
33988 \end_inset
33989 </cell>
33990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33991 \begin_inset Text
33992
33993 \layout Standard
33994
33995 \size footnotesize
33996 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33997
33998 \end_inset
33999 </cell>
34000 </row>
34001 <row topline="true">
34002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34003 \begin_inset Text
34004
34005 \layout Standard
34006
34007 \size footnotesize
34008 '|'
34009
34010 \end_inset
34011 </cell>
34012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34013 \begin_inset Text
34014
34015 \layout Standard
34016
34017 \size footnotesize
34018 IC_LEFT() IC_RIGHT() IC_RESULT() 
34019
34020 \end_inset
34021 </cell>
34022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34023 \begin_inset Text
34024
34025 \layout Standard
34026
34027 \size footnotesize
34028 Bitwise OR 
34029
34030 \end_inset
34031 </cell>
34032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34033 \begin_inset Text
34034
34035 \layout Standard
34036
34037 \size footnotesize
34038 IC_RESULT = IC_LEFT | IC_RIGHT;
34039
34040 \end_inset
34041 </cell>
34042 </row>
34043 <row topline="true">
34044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34045 \begin_inset Text
34046
34047 \layout Standard
34048
34049 \size footnotesize
34050 BITWISEAND
34051
34052 \end_inset
34053 </cell>
34054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34055 \begin_inset Text
34056
34057 \layout Standard
34058
34059 \size footnotesize
34060 IC_LEFT() IC_RIGHT() IC_RESULT()
34061
34062 \end_inset
34063 </cell>
34064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34065 \begin_inset Text
34066
34067 \layout Standard
34068
34069 \size footnotesize
34070 Bitwise AND 
34071
34072 \end_inset
34073 </cell>
34074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34075 \begin_inset Text
34076
34077 \layout Standard
34078
34079 \size footnotesize
34080 IC_RESULT = IC_LEFT & IC_RIGHT;
34081
34082 \end_inset
34083 </cell>
34084 </row>
34085 <row topline="true">
34086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34087 \begin_inset Text
34088
34089 \layout Standard
34090
34091 \size footnotesize
34092 LEFT_OP
34093
34094 \end_inset
34095 </cell>
34096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34097 \begin_inset Text
34098
34099 \layout Standard
34100
34101 \size footnotesize
34102 IC_LEFT() IC_RIGHT() IC_RESULT()
34103
34104 \end_inset
34105 </cell>
34106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34107 \begin_inset Text
34108
34109 \layout Standard
34110
34111 \size footnotesize
34112 Left shift 
34113
34114 \end_inset
34115 </cell>
34116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34117 \begin_inset Text
34118
34119 \layout Standard
34120
34121 \size footnotesize
34122 IC_RESULT = IC_LEFT << IC_RIGHT 
34123
34124 \end_inset
34125 </cell>
34126 </row>
34127 <row topline="true">
34128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34129 \begin_inset Text
34130
34131 \layout Standard
34132
34133 \size footnotesize
34134 RIGHT_OP
34135
34136 \end_inset
34137 </cell>
34138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34139 \begin_inset Text
34140
34141 \layout Standard
34142
34143 \size footnotesize
34144 IC_LEFT() IC_RIGHT() IC_RESULT()
34145
34146 \end_inset
34147 </cell>
34148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34149 \begin_inset Text
34150
34151 \layout Standard
34152
34153 \size footnotesize
34154 Right shift
34155
34156 \end_inset
34157 </cell>
34158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34159 \begin_inset Text
34160
34161 \layout Standard
34162
34163 \size footnotesize
34164 IC_RESULT = IC_LEFT >> IC_RIGHT 
34165
34166 \end_inset
34167 </cell>
34168 </row>
34169 <row topline="true">
34170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34171 \begin_inset Text
34172
34173 \layout Standard
34174
34175 \size footnotesize
34176 GET_VALUE_
34177 \newline
34178 AT_ ADDRESS
34179
34180 \end_inset
34181 </cell>
34182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34183 \begin_inset Text
34184
34185 \layout Standard
34186
34187 \size footnotesize
34188 IC_LEFT() IC_RESULT()
34189
34190 \end_inset
34191 </cell>
34192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34193 \begin_inset Text
34194
34195 \layout Standard
34196
34197 \size footnotesize
34198 Indirect fetch 
34199
34200 \end_inset
34201 </cell>
34202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34203 \begin_inset Text
34204
34205 \layout Standard
34206
34207 \size footnotesize
34208 IC_RESULT = (*IC_LEFT);
34209
34210 \end_inset
34211 </cell>
34212 </row>
34213 <row topline="true">
34214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34215 \begin_inset Text
34216
34217 \layout Standard
34218
34219 \size footnotesize
34220 POINTER_SET
34221
34222 \end_inset
34223 </cell>
34224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34225 \begin_inset Text
34226
34227 \layout Standard
34228
34229 \size footnotesize
34230 IC_RIGHT() IC_RESULT() 
34231
34232 \end_inset
34233 </cell>
34234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34235 \begin_inset Text
34236
34237 \layout Standard
34238
34239 \size footnotesize
34240 Indirect set
34241
34242 \end_inset
34243 </cell>
34244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34245 \begin_inset Text
34246
34247 \layout Standard
34248
34249 \size footnotesize
34250 (*IC_RESULT) = IC_RIGHT;
34251
34252 \end_inset
34253 </cell>
34254 </row>
34255 <row topline="true">
34256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34257 \begin_inset Text
34258
34259 \layout Standard
34260
34261 \size footnotesize
34262 '='
34263
34264 \end_inset
34265 </cell>
34266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34267 \begin_inset Text
34268
34269 \layout Standard
34270
34271 \size footnotesize
34272 IC_RIGHT() IC_RESULT()
34273
34274 \end_inset
34275 </cell>
34276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34277 \begin_inset Text
34278
34279 \layout Standard
34280
34281 \size footnotesize
34282 Assignment
34283
34284 \end_inset
34285 </cell>
34286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34287 \begin_inset Text
34288
34289 \layout Standard
34290
34291 \size footnotesize
34292 IC_RESULT = IC_RIGHT;
34293
34294 \end_inset
34295 </cell>
34296 </row>
34297 <row topline="true">
34298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34299 \begin_inset Text
34300
34301 \layout Standard
34302
34303 \size footnotesize
34304 IFX
34305
34306 \end_inset
34307 </cell>
34308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34309 \begin_inset Text
34310
34311 \layout Standard
34312
34313 \size footnotesize
34314 IC_COND IC_TRUE IC_LABEL
34315
34316 \end_inset
34317 </cell>
34318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34319 \begin_inset Text
34320
34321 \layout Standard
34322
34323 \size footnotesize
34324 Conditional jump.
34325  If true label is present then jump to true label if condition is true else
34326  jump to false label if condition is false 
34327
34328 \end_inset
34329 </cell>
34330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34331 \begin_inset Text
34332
34333 \layout Standard
34334
34335 \size footnotesize
34336 if (IC_COND) goto IC_TRUE; 
34337 \newline
34338 \SpecialChar ~
34339 \SpecialChar ~
34340 Or 
34341 \newline
34342 If (!IC_COND) goto IC_FALSE;
34343
34344 \end_inset
34345 </cell>
34346 </row>
34347 <row topline="true">
34348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34349 \begin_inset Text
34350
34351 \layout Standard
34352
34353 \size footnotesize
34354 ADDRESS_OF
34355
34356 \end_inset
34357 </cell>
34358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34359 \begin_inset Text
34360
34361 \layout Standard
34362
34363 \size footnotesize
34364 IC_LEFT() IC_RESULT()
34365
34366 \end_inset
34367 </cell>
34368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34369 \begin_inset Text
34370
34371 \layout Standard
34372
34373 \size footnotesize
34374 Address of 
34375
34376 \end_inset
34377 </cell>
34378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34379 \begin_inset Text
34380
34381 \layout Standard
34382
34383 \size footnotesize
34384 IC_RESULT = &IC_LEFT();
34385
34386 \end_inset
34387 </cell>
34388 </row>
34389 <row topline="true">
34390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34391 \begin_inset Text
34392
34393 \layout Standard
34394
34395 \size footnotesize
34396 JUMPTABLE
34397
34398 \end_inset
34399 </cell>
34400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34401 \begin_inset Text
34402
34403 \layout Standard
34404
34405 \size footnotesize
34406 IC_JTCOND IC_JTLABELS
34407
34408 \end_inset
34409 </cell>
34410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34411 \begin_inset Text
34412
34413 \layout Standard
34414
34415 \size footnotesize
34416 Jump to list of labels depending on the value of JTCOND
34417
34418 \end_inset
34419 </cell>
34420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34421 \begin_inset Text
34422
34423 \layout Standard
34424
34425 \size footnotesize
34426 Switch statement
34427
34428 \end_inset
34429 </cell>
34430 </row>
34431 <row topline="true">
34432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34433 \begin_inset Text
34434
34435 \layout Standard
34436
34437 \size footnotesize
34438 CAST
34439
34440 \end_inset
34441 </cell>
34442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34443 \begin_inset Text
34444
34445 \layout Standard
34446
34447 \size footnotesize
34448 IC_RIGHT() IC_LEFT() IC_RESULT()
34449
34450 \end_inset
34451 </cell>
34452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34453 \begin_inset Text
34454
34455 \layout Standard
34456
34457 \size footnotesize
34458 Cast types 
34459
34460 \end_inset
34461 </cell>
34462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34463 \begin_inset Text
34464
34465 \layout Standard
34466
34467 \size footnotesize
34468 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
34469
34470 \end_inset
34471 </cell>
34472 </row>
34473 <row topline="true">
34474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34475 \begin_inset Text
34476
34477 \layout Standard
34478
34479 \size footnotesize
34480 SEND
34481
34482 \end_inset
34483 </cell>
34484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34485 \begin_inset Text
34486
34487 \layout Standard
34488
34489 \size footnotesize
34490 IC_LEFT()
34491
34492 \end_inset
34493 </cell>
34494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34495 \begin_inset Text
34496
34497 \layout Standard
34498
34499 \size footnotesize
34500 This is used for passing parameters in registers; 
34501 \newline
34502 move IC_LEFT to the next
34503  available parameter register.
34504
34505 \end_inset
34506 </cell>
34507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34508 \begin_inset Text
34509
34510 \layout Standard
34511
34512 \size footnotesize
34513 None
34514
34515 \end_inset
34516 </cell>
34517 </row>
34518 <row topline="true">
34519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34520 \begin_inset Text
34521
34522 \layout Standard
34523
34524 \size footnotesize
34525 RECV
34526
34527 \end_inset
34528 </cell>
34529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34530 \begin_inset Text
34531
34532 \layout Standard
34533
34534 \size footnotesize
34535 IC_RESULT()
34536
34537 \end_inset
34538 </cell>
34539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34540 \begin_inset Text
34541
34542 \layout Standard
34543
34544 \size footnotesize
34545 This is used for receiving parameters passed in registers;
34546 \newline
34547 Move the values
34548  in the next parameter register to IC_RESULT 
34549
34550 \end_inset
34551 </cell>
34552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34553 \begin_inset Text
34554
34555 \layout Standard
34556
34557 \size footnotesize
34558 None
34559
34560 \end_inset
34561 </cell>
34562 </row>
34563 <row topline="true" bottomline="true">
34564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34565 \begin_inset Text
34566
34567 \layout Standard
34568
34569 \shape slanted
34570 \size footnotesize
34571 (some more have been added)
34572
34573 \end_inset
34574 </cell>
34575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34576 \begin_inset Text
34577
34578 \layout Standard
34579
34580
34581 \end_inset
34582 </cell>
34583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34584 \begin_inset Text
34585
34586 \layout Standard
34587
34588
34589 \end_inset
34590 </cell>
34591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34592 \begin_inset Text
34593
34594 \layout Standard
34595
34596 \shape slanted
34597 \size footnotesize
34598 see f.e.
34599  
34600 \family typewriter
34601 gen51Code()
34602 \family default
34603  in 
34604 \family typewriter
34605 src/mcs51/gen.c
34606
34607 \end_inset
34608 </cell>
34609 </row>
34610 </lyxtabular>
34611
34612 \end_inset
34613
34614
34615
34616 \layout Standard
34617 \begin_inset Note
34618 collapsed true
34619
34620 \layout Standard
34621 In the original article Figure II was announced to be downloadable on 
34622 \shape italic
34623 Circuit Cellar
34624 \shape default
34625 's web site.
34626  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
34627
34628 \end_inset
34629
34630
34631
34632 \layout Paragraph*
34633 ICode Example
34634 \begin_inset LatexCommand \index{iCode}
34635
34636 \end_inset
34637
34638
34639
34640 \layout Standard
34641 This section shows some details of iCode.
34642  The example C code does not do anything useful; it is used as an example
34643  to illustrate the intermediate code generated by the compiler.
34644
34645 \layout Verse
34646
34647 \family typewriter
34648 1.\SpecialChar ~
34649 xdata int * p;
34650 \newline
34651 2.\SpecialChar ~
34652 int gint;
34653 \newline
34654 3.\SpecialChar ~
34655 /* This function does nothing useful.
34656  It is used
34657 \newline
34658 4.\SpecialChar ~
34659 \SpecialChar ~
34660 \SpecialChar ~
34661 \SpecialChar ~
34662 for the purpose of explaining iCode */
34663 \newline
34664 5.\SpecialChar ~
34665 short function (data
34666  int *x)
34667 \newline
34668 6.\SpecialChar ~
34669 {
34670 \newline
34671 7.\SpecialChar ~
34672 \SpecialChar ~
34673 \SpecialChar ~
34674 short i=10; \SpecialChar ~
34675 \SpecialChar ~
34676 /* dead initialization eliminated */
34677 \newline
34678 8.\SpecialChar ~
34679 \SpecialChar ~
34680 \SpecialChar ~
34681 short sum=10;
34682  /* dead initialization eliminated */
34683 \newline
34684 9.\SpecialChar ~
34685 \SpecialChar ~
34686 \SpecialChar ~
34687 short mul;
34688 \newline
34689 10.\SpecialChar ~
34690 \SpecialChar ~
34691 int j ;
34692 \newline
34693 11.\SpecialChar ~
34694 \SpecialChar ~
34695 while (*x) *x++
34696  = *p++; 
34697 \newline
34698 12.\SpecialChar ~
34699 \SpecialChar ~
34700 \SpecialChar ~
34701 \SpecialChar ~
34702 sum = 0 ; 
34703 \newline
34704 13.\SpecialChar ~
34705 \SpecialChar ~
34706 mul = 0;
34707 \newline
34708 14.\SpecialChar ~
34709 \SpecialChar ~
34710 /* compiler detects i,j to be induction
34711  variables */
34712 \newline
34713 15.\SpecialChar ~
34714 \SpecialChar ~
34715 for (i = 0, j = 10 ; i < 10 ; i++, j
34716 \family default
34717 -
34718 \begin_inset ERT
34719 status Collapsed
34720
34721 \layout Standard
34722
34723
34724 \backslash
34725 /
34726
34727 \end_inset
34728
34729 -
34730 \family typewriter
34731 ) {
34732 \newline
34733 16.\SpecialChar ~
34734 \SpecialChar ~
34735 \SpecialChar ~
34736 \SpecialChar ~
34737 sum += i;
34738 \newline
34739 17.\SpecialChar ~
34740 \SpecialChar ~
34741 \SpecialChar ~
34742 \SpecialChar ~
34743 mul += i * 3; \SpecialChar ~
34744 \SpecialChar ~
34745 /* this multiplication remains */
34746 \newline
34747 18.\SpecialChar ~
34748 \SpecialChar ~
34749 \SpecialChar ~
34750 \SpecialChar ~
34751 gint +=
34752  j * 3;\SpecialChar ~
34753 \SpecialChar ~
34754 /* this multiplication changed to addition */
34755 \newline
34756 19.\SpecialChar ~
34757 \SpecialChar ~
34758 }
34759 \newline
34760 20.\SpecialChar ~
34761 \SpecialChar ~
34762 return sum+mul;
34763 \newline
34764 21.\SpecialChar ~
34765 }
34766
34767 \layout Standard
34768 In addition to the operands each iCode contains information about the filename
34769  and line it corresponds to in the source file.
34770  The first field in the listing should be interpreted as follows:
34771 \newline
34772
34773 \shape italic
34774 \size footnotesize
34775 Filename(linenumber: iCode Execution sequence number : ICode hash table
34776  key : loop depth of the iCode).
34777 \shape default
34778 \size default
34779
34780 \newline
34781 Then follows the human readable form of the ICode operation.
34782  Each operand of this triplet form can be of three basic types a) compiler
34783  generated temporary b) user defined variable c) a constant value.
34784  Note that local variables and parameters are replaced by compiler generated
34785  temporaries.
34786  Live ranges
34787 \begin_inset LatexCommand \index{Live range analysis}
34788
34789 \end_inset
34790
34791  are computed only for temporaries (i.e.
34792  live ranges are not computed for global variables).
34793  Registers
34794 \begin_inset LatexCommand \index{Register allocation}
34795
34796 \end_inset
34797
34798  are allocated for temporaries only.
34799  Operands are formatted in the following manner:
34800 \newline
34801
34802 \shape italic
34803 \size footnotesize
34804 Operand Name [lr live-from : live-to ] { type information } [ registers
34805  allocated ].
34806 \shape default
34807 \size default
34808
34809 \newline
34810 As mentioned earlier the live ranges are computed in terms of the execution
34811  sequence number of the iCodes, for example 
34812 \newline
34813 the iTemp0 is live from (i.e.
34814  first defined in iCode with execution sequence number 3, and is last used
34815  in the iCode with sequence number 5).
34816  For induction variables such as iTemp21 the live range computation extends
34817  the lifetime from the start to the end of the loop.
34818 \newline
34819 The register allocator
34820  used the live range information to allocate registers, the same registers
34821  may be used for different temporaries if their live ranges do not overlap,
34822  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
34823  ranges do not overlap.
34824  In addition the allocator also takes into consideration the type and usage
34825  of a temporary, for example itemp6 is a pointer to near space and is used
34826  as to fetch data from (i.e.
34827  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
34828  Some short lived temporaries are allocated to special registers which have
34829  meaning to the code generator e.g.
34830  iTemp13 is allocated to a pseudo register CC which tells the back end that
34831  the temporary is used only for a conditional jump the code generation makes
34832  use of this information to optimize a compare and jump ICode.
34833 \newline
34834 There are several
34835  loop optimizations
34836 \begin_inset LatexCommand \index{Loop optimization}
34837
34838 \end_inset
34839
34840  performed by the compiler.
34841  It can detect induction variables iTemp21(i) and iTemp23(j).
34842  Also note the compiler does selective strength reduction
34843 \begin_inset LatexCommand \index{Strength reduction}
34844
34845 \end_inset
34846
34847 , i.e.
34848  the multiplication of an induction variable in line 18 (gint = j * 3) is
34849  changed to addition, a new temporary iTemp17 is allocated and assigned
34850  a initial value, a constant 3 is then added for each iteration of the loop.
34851  The compiler does not change the multiplication
34852 \begin_inset LatexCommand \index{Multiplication}
34853
34854 \end_inset
34855
34856  in line 17 however since the processor does support an 8 * 8 bit multiplication.
34857 \newline
34858
34859 Note the dead code elimination
34860 \begin_inset LatexCommand \index{Dead-code elimination}
34861
34862 \end_inset
34863
34864  optimization eliminated the dead assignments in line 7 & 8 to I and sum
34865  respectively.
34866 \newline
34867
34868
34869 \layout Standard
34870
34871 \size footnotesize
34872 Sample.c (5:1:0:0) _entry($9) :
34873
34874 \layout Standard
34875
34876 \size footnotesize
34877 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34878
34879 \layout Standard
34880
34881 \size footnotesize
34882 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
34883
34884 \layout Standard
34885
34886 \size footnotesize
34887 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34888
34889 \layout Standard
34890
34891 \size footnotesize
34892 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34893  * int}[r2]
34894
34895 \layout Standard
34896
34897 \size footnotesize
34898 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34899
34900 \layout Standard
34901
34902 \size footnotesize
34903 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34904  int}[r0]]
34905
34906 \layout Standard
34907
34908 \size footnotesize
34909 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34910
34911 \layout Standard
34912
34913 \size footnotesize
34914 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34915  * int}
34916
34917 \layout Standard
34918
34919 \size footnotesize
34920 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34921  {short}
34922
34923 \layout Standard
34924
34925 \size footnotesize
34926 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34927  * int}[DPTR]]
34928
34929 \layout Standard
34930
34931 \size footnotesize
34932 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34933 }[r2 r3]
34934
34935 \layout Standard
34936
34937 \size footnotesize
34938 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34939  * int}[r0] + 0x2 {short}
34940
34941 \layout Standard
34942
34943 \size footnotesize
34944 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34945
34946 \layout Standard
34947
34948 \size footnotesize
34949 Sample.c(11:17:21:0)_whilebreak_0($3) :
34950
34951 \layout Standard
34952
34953 \size footnotesize
34954 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34955
34956 \layout Standard
34957
34958 \size footnotesize
34959 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34960
34961 \layout Standard
34962
34963 \size footnotesize
34964 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34965
34966 \layout Standard
34967
34968 \size footnotesize
34969 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34970
34971 \layout Standard
34972
34973 \size footnotesize
34974 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34975
34976 \layout Standard
34977
34978 \size footnotesize
34979 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34980
34981 \layout Standard
34982
34983 \size footnotesize
34984 Sample.c(15:24:26:1)_forcond_0($4) :
34985
34986 \layout Standard
34987
34988 \size footnotesize
34989 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34990  < 0xa {short}
34991
34992 \layout Standard
34993
34994 \size footnotesize
34995 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34996
34997 \layout Standard
34998
34999 \size footnotesize
35000 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
35001  + ITemp21 [lr21:38]{short}[r4]
35002
35003 \layout Standard
35004
35005 \size footnotesize
35006 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
35007  * 0x3 {short}
35008
35009 \layout Standard
35010
35011 \size footnotesize
35012 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
35013  + iTemp15 [lr29:30]{short}[r1]
35014
35015 \layout Standard
35016
35017 \size footnotesize
35018 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
35019  r0]- 0x3 {short}
35020
35021 \layout Standard
35022
35023 \size footnotesize
35024 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
35025 int}[r7 r0]
35026
35027 \layout Standard
35028
35029 \size footnotesize
35030 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
35031  + 0x1 {short}
35032
35033 \layout Standard
35034
35035 \size footnotesize
35036 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
35037  r6]- 0x1 {short}
35038
35039 \layout Standard
35040
35041 \size footnotesize
35042 Sample.c(19:38:47:1) goto _forcond_0($4)
35043
35044 \layout Standard
35045
35046 \size footnotesize
35047 Sample.c(19:39:48:0)_forbreak_0($7) :
35048
35049 \layout Standard
35050
35051 \size footnotesize
35052 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
35053  + ITemp11 [lr19:40]{short}[r3]
35054
35055 \layout Standard
35056
35057 \size footnotesize
35058 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
35059
35060 \layout Standard
35061
35062 \size footnotesize
35063 Sample.c(20:42:51:0)_return($8) :
35064
35065 \layout Standard
35066
35067 \size footnotesize
35068 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
35069 \size default
35070
35071 \newline
35072
35073 \newline
35074 Finally the code generated for this function:
35075 \newline
35076
35077
35078 \layout Standard
35079
35080 \size footnotesize
35081 .area DSEG (DATA)
35082
35083 \layout Standard
35084
35085 \size footnotesize
35086 _p::
35087
35088 \layout Standard
35089
35090 \size footnotesize
35091 \SpecialChar ~
35092 \SpecialChar ~
35093 .ds 2
35094
35095 \layout Standard
35096
35097 \size footnotesize
35098 _gint::
35099
35100 \layout Standard
35101
35102 \size footnotesize
35103 \SpecialChar ~
35104 \SpecialChar ~
35105 .ds 2
35106
35107 \layout Standard
35108
35109 \size footnotesize
35110 ; sample.c 5
35111
35112 \layout Standard
35113
35114 \size footnotesize
35115 ; ----------------------------------------------
35116
35117 \layout Standard
35118
35119 \size footnotesize
35120 ; function function
35121
35122 \layout Standard
35123
35124 \size footnotesize
35125 ; ----------------------------------------------
35126
35127 \layout Standard
35128
35129 \size footnotesize
35130 _function:
35131
35132 \layout Standard
35133
35134 \size footnotesize
35135 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
35136
35137 \layout Standard
35138
35139 \size footnotesize
35140 \SpecialChar ~
35141 \SpecialChar ~
35142 mov r2,dpl
35143
35144 \layout Standard
35145
35146 \size footnotesize
35147 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
35148
35149 \layout Standard
35150
35151 \size footnotesize
35152 \SpecialChar ~
35153 \SpecialChar ~
35154 mov ar0,r2
35155
35156 \layout Standard
35157
35158 \size footnotesize
35159 ;_whilecontinue_0($1) :
35160
35161 \layout Standard
35162
35163 \size footnotesize
35164 00101$:
35165
35166 \layout Standard
35167
35168 \size footnotesize
35169 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
35170
35171 \layout Standard
35172
35173 \size footnotesize
35174 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
35175
35176 \layout Standard
35177
35178 \size footnotesize
35179 \SpecialChar ~
35180 \SpecialChar ~
35181 mov ar2,@r0
35182
35183 \layout Standard
35184
35185 \size footnotesize
35186 \SpecialChar ~
35187 \SpecialChar ~
35188 inc r0
35189
35190 \layout Standard
35191
35192 \size footnotesize
35193 \SpecialChar ~
35194 \SpecialChar ~
35195 mov ar3,@r0
35196
35197 \layout Standard
35198
35199 \size footnotesize
35200 \SpecialChar ~
35201 \SpecialChar ~
35202 dec r0
35203
35204 \layout Standard
35205
35206 \size footnotesize
35207 \SpecialChar ~
35208 \SpecialChar ~
35209 mov a,r2
35210
35211 \layout Standard
35212
35213 \size footnotesize
35214 \SpecialChar ~
35215 \SpecialChar ~
35216 orl a,r3
35217
35218 \layout Standard
35219
35220 \size footnotesize
35221 \SpecialChar ~
35222 \SpecialChar ~
35223 jz 00103$
35224
35225 \layout Standard
35226
35227 \size footnotesize
35228 00114$:
35229
35230 \layout Standard
35231
35232 \size footnotesize
35233 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
35234
35235 \layout Standard
35236
35237 \size footnotesize
35238 \SpecialChar ~
35239 \SpecialChar ~
35240 mov dpl,_p
35241
35242 \layout Standard
35243
35244 \size footnotesize
35245 \SpecialChar ~
35246 \SpecialChar ~
35247 mov dph,(_p + 1)
35248
35249 \layout Standard
35250
35251 \size footnotesize
35252 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
35253
35254 \layout Standard
35255
35256 \size footnotesize
35257 \SpecialChar ~
35258 \SpecialChar ~
35259 mov a,#0x02
35260
35261 \layout Standard
35262
35263 \size footnotesize
35264 \SpecialChar ~
35265 \SpecialChar ~
35266 add a,_p
35267
35268 \layout Standard
35269
35270 \size footnotesize
35271 \SpecialChar ~
35272 \SpecialChar ~
35273 mov _p,a
35274
35275 \layout Standard
35276
35277 \size footnotesize
35278 \SpecialChar ~
35279 \SpecialChar ~
35280 clr a
35281
35282 \layout Standard
35283
35284 \size footnotesize
35285 \SpecialChar ~
35286 \SpecialChar ~
35287 addc a,(_p + 1)
35288
35289 \layout Standard
35290
35291 \size footnotesize
35292 \SpecialChar ~
35293 \SpecialChar ~
35294 mov (_p + 1),a
35295
35296 \layout Standard
35297
35298 \size footnotesize
35299 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
35300
35301 \layout Standard
35302
35303 \size footnotesize
35304 \SpecialChar ~
35305 \SpecialChar ~
35306 movx a,@dptr
35307
35308 \layout Standard
35309
35310 \size footnotesize
35311 \SpecialChar ~
35312 \SpecialChar ~
35313 mov r2,a
35314
35315 \layout Standard
35316
35317 \size footnotesize
35318 \SpecialChar ~
35319 \SpecialChar ~
35320 inc dptr
35321
35322 \layout Standard
35323
35324 \size footnotesize
35325 \SpecialChar ~
35326 \SpecialChar ~
35327 movx a,@dptr
35328
35329 \layout Standard
35330
35331 \size footnotesize
35332 \SpecialChar ~
35333 \SpecialChar ~
35334 mov r3,a
35335
35336 \layout Standard
35337
35338 \size footnotesize
35339 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
35340
35341 \layout Standard
35342
35343 \size footnotesize
35344 \SpecialChar ~
35345 \SpecialChar ~
35346 mov @r0,ar2
35347
35348 \layout Standard
35349
35350 \size footnotesize
35351 \SpecialChar ~
35352 \SpecialChar ~
35353 inc r0
35354
35355 \layout Standard
35356
35357 \size footnotesize
35358 \SpecialChar ~
35359 \SpecialChar ~
35360 mov @r0,ar3
35361
35362 \layout Standard
35363
35364 \size footnotesize
35365 ; iTemp6 [lr5:16]{_near * int}[r0] = 
35366
35367 \layout Standard
35368
35369 \size footnotesize
35370 ; iTemp6 [lr5:16]{_near * int}[r0] + 
35371
35372 \layout Standard
35373
35374 \size footnotesize
35375 ; 0x2 {short}
35376
35377 \layout Standard
35378
35379 \size footnotesize
35380 \SpecialChar ~
35381 \SpecialChar ~
35382 inc r0
35383
35384 \layout Standard
35385
35386 \size footnotesize
35387 ; goto _whilecontinue_0($1)
35388
35389 \layout Standard
35390
35391 \size footnotesize
35392 \SpecialChar ~
35393 \SpecialChar ~
35394 sjmp 00101$
35395
35396 \layout Standard
35397
35398 \size footnotesize
35399 ; _whilebreak_0($3) :
35400
35401 \layout Standard
35402
35403 \size footnotesize
35404 00103$:
35405
35406 \layout Standard
35407
35408 \size footnotesize
35409 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
35410
35411 \layout Standard
35412
35413 \size footnotesize
35414 \SpecialChar ~
35415 \SpecialChar ~
35416 mov r2,#0x00
35417
35418 \layout Standard
35419
35420 \size footnotesize
35421 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
35422
35423 \layout Standard
35424
35425 \size footnotesize
35426 \SpecialChar ~
35427 \SpecialChar ~
35428 mov r3,#0x00
35429
35430 \layout Standard
35431
35432 \size footnotesize
35433 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
35434
35435 \layout Standard
35436
35437 \size footnotesize
35438 \SpecialChar ~
35439 \SpecialChar ~
35440 mov r4,#0x00
35441
35442 \layout Standard
35443
35444 \size footnotesize
35445 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
35446
35447 \layout Standard
35448
35449 \size footnotesize
35450 \SpecialChar ~
35451 \SpecialChar ~
35452 mov r5,#0x0A
35453
35454 \layout Standard
35455
35456 \size footnotesize
35457 \SpecialChar ~
35458 \SpecialChar ~
35459 mov r6,#0x00
35460
35461 \layout Standard
35462
35463 \size footnotesize
35464 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
35465
35466 \layout Standard
35467
35468 \size footnotesize
35469 \SpecialChar ~
35470 \SpecialChar ~
35471 mov r7,#0x1E
35472
35473 \layout Standard
35474
35475 \size footnotesize
35476 \SpecialChar ~
35477 \SpecialChar ~
35478 mov r0,#0x00
35479
35480 \layout Standard
35481
35482 \size footnotesize
35483 ; _forcond_0($4) :
35484
35485 \layout Standard
35486
35487 \size footnotesize
35488 00104$:
35489
35490 \layout Standard
35491
35492 \size footnotesize
35493 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
35494
35495 \layout Standard
35496
35497 \size footnotesize
35498 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
35499
35500 \layout Standard
35501
35502 \size footnotesize
35503 \SpecialChar ~
35504 \SpecialChar ~
35505 clr c
35506
35507 \layout Standard
35508
35509 \size footnotesize
35510 \SpecialChar ~
35511 \SpecialChar ~
35512 mov a,r4
35513
35514 \layout Standard
35515
35516 \size footnotesize
35517 \SpecialChar ~
35518 \SpecialChar ~
35519 xrl a,#0x80
35520
35521 \layout Standard
35522
35523 \size footnotesize
35524 \SpecialChar ~
35525 \SpecialChar ~
35526 subb a,#0x8a
35527
35528 \layout Standard
35529
35530 \size footnotesize
35531 \SpecialChar ~
35532 \SpecialChar ~
35533 jnc 00107$
35534
35535 \layout Standard
35536
35537 \size footnotesize
35538 00115$:
35539
35540 \layout Standard
35541
35542 \size footnotesize
35543 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
35544
35545 \layout Standard
35546
35547 \size footnotesize
35548 ; iTemp21 [lr21:38]{short}[r4]
35549
35550 \layout Standard
35551
35552 \size footnotesize
35553 \SpecialChar ~
35554 \SpecialChar ~
35555 mov a,r4
35556
35557 \layout Standard
35558
35559 \size footnotesize
35560 \SpecialChar ~
35561 \SpecialChar ~
35562 add a,r2
35563
35564 \layout Standard
35565
35566 \size footnotesize
35567 \SpecialChar ~
35568 \SpecialChar ~
35569 mov r2,a
35570
35571 \layout Standard
35572
35573 \size footnotesize
35574 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
35575
35576 \layout Standard
35577
35578 \size footnotesize
35579 \SpecialChar ~
35580 \SpecialChar ~
35581 mov b,#0x03
35582
35583 \layout Standard
35584
35585 \size footnotesize
35586 \SpecialChar ~
35587 \SpecialChar ~
35588 mov a,r4
35589
35590 \layout Standard
35591
35592 \size footnotesize
35593 \SpecialChar ~
35594 \SpecialChar ~
35595 mul ab
35596
35597 \layout Standard
35598
35599 \size footnotesize
35600 \SpecialChar ~
35601 \SpecialChar ~
35602 mov r1,a
35603
35604 \layout Standard
35605
35606 \size footnotesize
35607 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
35608
35609 \layout Standard
35610
35611 \size footnotesize
35612 ; iTemp15 [lr29:30]{short}[r1]
35613
35614 \layout Standard
35615
35616 \size footnotesize
35617 \SpecialChar ~
35618 \SpecialChar ~
35619 add a,r3
35620
35621 \layout Standard
35622
35623 \size footnotesize
35624 \SpecialChar ~
35625 \SpecialChar ~
35626 mov r3,a
35627
35628 \layout Standard
35629
35630 \size footnotesize
35631 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
35632
35633 \layout Standard
35634
35635 \size footnotesize
35636 \SpecialChar ~
35637 \SpecialChar ~
35638 mov a,r7
35639
35640 \layout Standard
35641
35642 \size footnotesize
35643 \SpecialChar ~
35644 \SpecialChar ~
35645 add a,#0xfd
35646
35647 \layout Standard
35648
35649 \size footnotesize
35650 \SpecialChar ~
35651 \SpecialChar ~
35652 mov r7,a
35653
35654 \layout Standard
35655
35656 \size footnotesize
35657 \SpecialChar ~
35658 \SpecialChar ~
35659 mov a,r0
35660
35661 \layout Standard
35662
35663 \size footnotesize
35664 \SpecialChar ~
35665 \SpecialChar ~
35666 addc a,#0xff
35667
35668 \layout Standard
35669
35670 \size footnotesize
35671 \SpecialChar ~
35672 \SpecialChar ~
35673 mov r0,a
35674
35675 \layout Standard
35676
35677 \size footnotesize
35678 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
35679
35680 \layout Standard
35681
35682 \size footnotesize
35683 \SpecialChar ~
35684 \SpecialChar ~
35685 mov a,r7
35686
35687 \layout Standard
35688
35689 \size footnotesize
35690 \SpecialChar ~
35691 \SpecialChar ~
35692 add a,_gint
35693
35694 \layout Standard
35695
35696 \size footnotesize
35697 \SpecialChar ~
35698 \SpecialChar ~
35699 mov _gint,a
35700
35701 \layout Standard
35702
35703 \size footnotesize
35704 \SpecialChar ~
35705 \SpecialChar ~
35706 mov a,r0
35707
35708 \layout Standard
35709
35710 \size footnotesize
35711 \SpecialChar ~
35712 \SpecialChar ~
35713 addc a,(_gint + 1)
35714
35715 \layout Standard
35716
35717 \size footnotesize
35718 \SpecialChar ~
35719 \SpecialChar ~
35720 mov (_gint + 1),a
35721
35722 \layout Standard
35723
35724 \size footnotesize
35725 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
35726
35727 \layout Standard
35728
35729 \size footnotesize
35730 \SpecialChar ~
35731 \SpecialChar ~
35732 inc r4
35733
35734 \layout Standard
35735
35736 \size footnotesize
35737 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
35738
35739 \layout Standard
35740
35741 \size footnotesize
35742 \SpecialChar ~
35743 \SpecialChar ~
35744 dec r5
35745
35746 \layout Standard
35747
35748 \size footnotesize
35749 \SpecialChar ~
35750 \SpecialChar ~
35751 cjne r5,#0xff,00104$
35752
35753 \layout Standard
35754
35755 \size footnotesize
35756 \SpecialChar ~
35757 \SpecialChar ~
35758 dec r6
35759
35760 \layout Standard
35761
35762 \size footnotesize
35763 ; goto _forcond_0($4)
35764
35765 \layout Standard
35766
35767 \size footnotesize
35768 \SpecialChar ~
35769 \SpecialChar ~
35770 sjmp 00104$
35771
35772 \layout Standard
35773
35774 \size footnotesize
35775 ; _forbreak_0($7) :
35776
35777 \layout Standard
35778
35779 \size footnotesize
35780 00107$:
35781
35782 \layout Standard
35783
35784 \size footnotesize
35785 ; ret iTemp24 [lr40:41]{short}
35786
35787 \layout Standard
35788
35789 \size footnotesize
35790 \SpecialChar ~
35791 \SpecialChar ~
35792 mov a,r3
35793
35794 \layout Standard
35795
35796 \size footnotesize
35797 \SpecialChar ~
35798 \SpecialChar ~
35799 add a,r2
35800
35801 \layout Standard
35802
35803 \size footnotesize
35804 \SpecialChar ~
35805 \SpecialChar ~
35806 mov dpl,a
35807
35808 \layout Standard
35809
35810 \size footnotesize
35811 ; _return($8) :
35812
35813 \layout Standard
35814
35815 \size footnotesize
35816 00108$:
35817
35818 \layout Standard
35819
35820 \size footnotesize
35821 \SpecialChar ~
35822 \SpecialChar ~
35823 ret
35824 \newline
35825
35826
35827 \layout Section
35828 A few words about basic block successors, predecessors and dominators
35829
35830 \layout Standard
35831 Successors are basic blocks
35832 \begin_inset LatexCommand \index{Basic blocks}
35833
35834 \end_inset
35835
35836  that might execute after this basic block.
35837 \newline
35838 Predecessors are basic blocks
35839  that might execute before reaching this basic block.
35840 \newline
35841 Dominators are basic
35842  blocks that WILL execute before reaching this basic block.
35843 \newline
35844
35845
35846 \layout Standard
35847 [basic block 1]
35848
35849 \layout Standard
35850 if (something)
35851
35852 \layout Standard
35853 \SpecialChar ~
35854 \SpecialChar ~
35855 \SpecialChar ~
35856 \SpecialChar ~
35857 [basic block 2]
35858
35859 \layout Standard
35860 else
35861
35862 \layout Standard
35863 \SpecialChar ~
35864 \SpecialChar ~
35865 \SpecialChar ~
35866 \SpecialChar ~
35867 [basic block 3]
35868
35869 \layout Standard
35870 [basic block 4]
35871 \newline
35872
35873
35874 \layout Standard
35875 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35876
35877 \layout Standard
35878 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35879
35880 \layout Standard
35881 c) domVect of [BB4] = BB1 ...
35882  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35883  was executed.
35884
35885 \layout Chapter
35886 Acknowledgments
35887
35888 \layout Standard
35889 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35890
35891 \end_inset
35892
35893
35894 \newline
35895
35896 \newline
35897
35898 \emph on
35899 Thanks to all the other volunteer developers who have helped with coding,
35900  testing, web-page creation, distribution sets, etc.
35901  You know who you are :-)
35902 \emph default
35903
35904 \newline
35905
35906 \newline
35907
35908 \emph on
35909 Also thanks to Sourceforge 
35910 \begin_inset LatexCommand \url{http://www.sf.net}
35911
35912 \end_inset
35913
35914  which has hosted the project since 1999 and donates significant download
35915  bandwidth and probably more than 
35916 \begin_inset ERT
35917 status Collapsed
35918
35919 \layout Standard
35920
35921 $10^{13}$
35922
35923 \end_inset
35924
35925 CPU cycles per day.
35926 \newline
35927  
35928 \begin_inset Note
35929 collapsed false
35930
35931 \layout Standard
35932 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35933  minutes for (configure+make+regression test), and there is (i386, amd64,
35934  alpha, ppc64, (mingw32), sparc, macosx).
35935  
35936
35937 \end_inset
35938
35939
35940
35941 \layout Standard
35942 This document was initially written by Sandeep Dutta
35943
35944 \layout Standard
35945 All product names mentioned herein may be trademarks
35946 \begin_inset LatexCommand \index{Trademarks}
35947
35948 \end_inset
35949
35950  of their respective companies.
35951  
35952
35953 \layout Section*
35954 Alphabetical index
35955
35956 \layout Standard
35957 To avoid confusion, the installation and building options for SDCC itself
35958  (chapter 2) are not part of the index.
35959
35960 \layout Standard
35961 \begin_inset LatexCommand \printindex{}
35962
35963 \end_inset
35964
35965
35966
35967 \the_end